Skip to content

Feature: Native Block Editor Interface #94

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

Open
wants to merge 29 commits into
base: feature/rest-api-endpoint
Choose a base branch
from

Conversation

fabiankaegy
Copy link
Member

@fabiankaegy fabiankaegy commented Feb 18, 2025

Warning

This PR is based on top of #91

Description of the Change

Adds a WordPress Data store to more easily interface with the Content Connect REST API from within the Block Editor.

Closes #45

How to test the Change

  1. Ensure you have a test environment with a few connections configured (For example using the demo plugin: https://github.com/fabiankaegy/wp-content-connect-example-data)
  2. Use the browser console on a post that has connections (in the editor) to run wp.data.select('wp-content-connect').getRelationships(xxx) where xxx is the current post id
  3. This will resolve an empty object at first but if you run it again it will show you the relationships (this is expected since to begin with the relationships are not preloaded. useSelect will smooth this experience)
  4. Now that you have the relationship you can get some actually related posts by running: wp.data.select('wp-content-connect').getRelatedPosts(xxx, 'university_city_university_to_city')
  5. You can also update the relationships by running: wp.data.dispatch('wp-content-connect').updateRelatedPosts( xxx, 'university_city_university_to_city', [ yyy, zzz ] )

Note

This PR is still very much in progress and subject to change :)

Changelog Entry

Added - WordPress Data API store for interacting with the wp-content-connect plugin
Added - Block editor UI

Credits

Props @fabiankaegy @s3rgiosan

@fabiankaegy fabiankaegy self-assigned this Feb 18, 2025
@fabiankaegy fabiankaegy changed the base branch from develop to feature/rest-api-endpoint February 18, 2025 10:16
@fabiankaegy fabiankaegy force-pushed the feature/data-api-backbone branch from 4608980 to 621e135 Compare February 18, 2025 10:55
@fabiankaegy fabiankaegy changed the title Feature: data api backbone Feature: Native Block Editor Interface Feb 18, 2025
@s3rgiosan
Copy link
Member

Hi @fabiankaegy I went ahead and updated the UI to use the new ContentPicker, along with some fixes and improvements for post-to-user relationship support and bi-directional panels in post-to-post relationships. Ready for your review when you can.

@s3rgiosan
Copy link
Member

I've created a try/block-editor-ui all-in-one branch to make it easier to test the features in both the block and classic editors, as well as the Query Loop integration.

@jeffpaul jeffpaul added this to the 1.7.0 milestone Mar 21, 2025
@jeffpaul jeffpaul moved this to QA Testing in Open Source Practice Mar 21, 2025
Copy link

@ocean90 ocean90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking pretty good already! Thanks for the try/block-editor-ui branch. Two things I noticed while doing some basic testing:

  • If sortable is enabled sorting is a bit laggy. Sometimes the item positions are not changed.I think this happens because the sorting is directly saved via a POST request and directly followed by a GET request. There seems to be a race-condition where the second runs to early? Should saving maybe delayed until the post is saved?
  • The second one is related to enable_ui which is simply ignored in the block editor, meaning the UI is always there.

@s3rgiosan
Copy link
Member

This is looking pretty good already! Thanks for the try/block-editor-ui branch. Two things I noticed while doing some basic testing:

  • If sortable is enabled sorting is a bit laggy. Sometimes the item positions are not changed.I think this happens because the sorting is directly saved via a POST request and directly followed by a GET request. There seems to be a race-condition where the second runs to early? Should saving maybe delayed until the post is saved?
  • The second one is related to enable_ui which is simply ignored in the block editor, meaning the UI is always there.

Thanks for testing this @ocean90. I'll review the issues you pointed out ASAP.

@s3rgiosan
Copy link
Member

The second one is related to enable_ui which is simply ignored in the block editor, meaning the UI is always there.

@ocean90 this was resolved in the latest commit.

@s3rgiosan
Copy link
Member

If sortable is enabled sorting is a bit laggy. Sometimes the item positions are not changed.I think this happens because the sorting is directly saved via a POST request and directly followed by a GET request. There seems to be a race-condition where the second runs to early? Should saving maybe delayed until the post is saved?

Hi @ocean90,

I haven't been able to replicate this same issue on my end, but I did notice that was missing an await when calling updateRelatedEntities. I added the await and it should help avoid timing issues.

Can you try again when you have a chance to see if the problem still persists?

If so, it would be really helpful to get a bit more context about your setup:

  • For the post type, how many relationships are defined?
  • How many related entities are there in each relationship (especially the one creating the problem), roughly speaking?

Once again, thank you!

@s3rgiosan s3rgiosan marked this pull request as ready for review April 30, 2025 10:24
@s3rgiosan s3rgiosan requested a review from rickalee as a code owner April 30, 2025 10:24
@s3rgiosan
Copy link
Member

@fabiankaegy Is there a way to improve this experience? Maybe by using an internal state and syncing changes to the REST API afterward?

Screen.Recording.2025-04-30.at.11.23.10.AM.mp4

@fabiankaegy
Copy link
Member Author

fabiankaegy commented Apr 30, 2025

@s3rgiosan yeah we really should improve that. I though that the way we handle the rest API communication in the custom Data store would have already taken care of this but apparently not.

I will try and see if I can find some time at the end of this week for this. Feel free to explore either adjusting the logic in the datastore to not persist on change directly but rather only queueing up the changes in the datastore as local changes that are in memory only and then only persist the relationships when we actually save the post 🤔

Alternatively, we could look at using something like useOptimistic in the actual component

@s3rgiosan
Copy link
Member

@s3rgiosan yeah we really should improve that. I though that the way we handle the rest API communication in the custom Data store would have already taken care of this but apparently not.

I will try and see if I can find some time at the end of this week for this. Feel free to explore either adjusting the logic in the datastore to not persist on change directly but rather only queueing up the changes in the datastore as local changes that are in memory only and then only persist the relationships when we actually save the post 🤔

Alternatively, we could look at using something like useOptimistic in the actual component

I'll explore some options and take a look into useOptimistic. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: QA Testing
Development

Successfully merging this pull request may close these issues.

5 participants