-
Notifications
You must be signed in to change notification settings - Fork 3
Support editing posts of custom post types #299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Conversation
dcalhoun
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This tested well for me. I noted the correct post type is provided to the WebView configuration. I was unable to verify the correct post type is loaded due to the issue with the Preload Editor button noted in an inline comment.
We might should address the inline comments before merging.
| var body: some View { | ||
| Group { | ||
| if viewModel.isLoading && viewModel.posts.isEmpty { | ||
| ProgressView("Loading Posts...") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May not be worth the effort given this is a demo app, but we might changes this and other static "Posts" references to be "\(viewModel.postTypeDetails.name) entries" or simply "entries".
| } | ||
| self.posts = loadedPosts | ||
| } catch { | ||
| self.error = error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| restBase: post?.restBase || 'posts', | ||
| restNamespace: post?.restNamespace || 'wp/v2', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to update the JavaScript tests to address the current failures. Something like the following.
Example diff
diff --git a/src/utils/bridge.test.js b/src/utils/bridge.test.js
index 6928581..5c2175b 100644
--- a/src/utils/bridge.test.js
+++ b/src/utils/bridge.test.js
@@ -236,6 +236,8 @@ describe( 'getPost', () => {
expect( result ).toEqual( {
id: 123,
type: 'page',
+ restBase: 'posts',
+ restNamespace: 'wp/v2',
status: 'draft',
title: { raw: 'Host Title' },
content: { raw: 'Host Content' },
@@ -299,6 +301,8 @@ describe( 'getPost', () => {
expect( result ).toEqual( {
id: 789,
type: 'post',
+ restBase: 'posts',
+ restNamespace: 'wp/v2',
status: 'draft',
title: { raw: 'GBKit Title' },
content: { raw: 'GBKit Content' },
@@ -322,6 +326,8 @@ describe( 'getPost', () => {
expect( result ).toEqual( {
id: 101,
type: 'page',
+ restBase: 'posts',
+ restNamespace: 'wp/v2',
status: 'publish',
title: { raw: 'Fallback Title' },
content: { raw: 'Fallback Content' },
@@ -338,6 +344,8 @@ describe( 'getPost', () => {
expect( result ).toEqual( {
id: -1,
type: 'post',
+ restBase: 'posts',
+ restNamespace: 'wp/v2',
status: 'draft',
title: { raw: '' },
content: { raw: '' },
@@ -364,6 +372,8 @@ describe( 'getPost', () => {
expect( result ).toEqual( {
id: -1,
type: 'post',
+ restBase: 'posts',
+ restNamespace: 'wp/v2',
status: 'draft',
title: { raw: 'Title' },
content: { raw: 'Content' },
| content: String = "", | ||
| postID: Int? = nil, | ||
| postType: String, | ||
| postType: PostTypeDetails, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are Swift test failures that seem to relate to this change and the one in EditorPreloadList. We need to update the automated tests.
Example diff
diff --git a/ios/Tests/GutenbergKitTests/Model/GBKitGlobalTests.swift b/ios/Tests/GutenbergKitTests/Model/GBKitGlobalTests.swift
index e1fcd1a..e32a2d3 100644
--- a/ios/Tests/GutenbergKitTests/Model/GBKitGlobalTests.swift
+++ b/ios/Tests/GutenbergKitTests/Model/GBKitGlobalTests.swift
@@ -20,7 +20,7 @@ struct GBKitGlobalTests: MakesTestFixtures {
private func makePreloadList() -> EditorPreloadList {
EditorPreloadList(
- postType: "post",
+ postType: .post,
postTypeData: EditorURLResponse(data: Data(), responseHeaders: [:]),
postTypesData: EditorURLResponse(data: Data(), responseHeaders: [:]),
activeThemeData: EditorURLResponse(data: Data(), responseHeaders: [:]),
@@ -97,8 +97,8 @@ struct GBKitGlobalTests: MakesTestFixtures {
@Test("maps postType to post.type")
func mapsPostType() throws {
- let postConfig = makeConfiguration(postType: "post")
- let pageConfig = makeConfiguration(postType: "page")
+ let postConfig = makeConfiguration(postType: .post)
+ let pageConfig = makeConfiguration(postType: .page)
let postGlobal = try GBKitGlobal(configuration: postConfig, dependencies: makeDependencies())
let pageGlobal = try GBKitGlobal(configuration: pageConfig, dependencies: makeDependencies())
diff --git a/ios/Tests/GutenbergKitTests/Stores/EditorAssetLibraryTests.swift b/ios/Tests/GutenbergKitTests/Stores/EditorAssetLibraryTests.swift
index 0e354a4..eec81ee 100644
--- a/ios/Tests/GutenbergKitTests/Stores/EditorAssetLibraryTests.swift
+++ b/ios/Tests/GutenbergKitTests/Stores/EditorAssetLibraryTests.swift
@@ -9,7 +9,7 @@ struct EditorAssetLibraryTests {
static var testConfiguration: EditorConfiguration {
EditorConfigurationBuilder(
- postType: "post",
+ postType: .post,
siteURL: URL(string: "https://example.com")!,
siteApiRoot: URL(string: "https://example.com/wp-json")!,
)
@@ -20,7 +20,7 @@ struct EditorAssetLibraryTests {
static var minimalConfiguration: EditorConfiguration {
EditorConfigurationBuilder(
- postType: "post",
+ postType: .post,
siteURL: URL(string: "https://example.com")!,
siteApiRoot: URL(string: "https://example.com/wp-json")!
)
| Picker("Post Type", selection: $viewModel.selectedPostTypeDetails) { | ||
| ForEach(viewModel.postTypes, id: \.self) { postType in | ||
| Text(postType.name).tag(postType) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This appears to be a pre-existing issue, but the Prepare Editor button does not take this selection into consideration. So, it always preloads the post type rather than the selected type.
We might should fix this so that we can further validate the correct data is preloaded.

There are two issues in loading custom posts from the editor
wp/v2/post/<id>is sent out when preparing editor. This URL is hard-coded.This PR adds
restBaseandrestNamespacetoEditorConfiguration. The values will be used to fix the hard-codedwp/v2/postrequest. They are passed to the JS library and are added to the "post entities" list.The second commit of this PR updates the Demo project to browse custom posts and allows opening them in the GBK editor. You can checkout this commit to reproduce the issue locally.