-
Notifications
You must be signed in to change notification settings - Fork 178
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
Implement Post Locking MVP #3126
Comments
This comment has been minimized.
This comment has been minimized.
might need a seperate ticket to update the story list to indicate that there is a edit in progress similar to how wp currently does it. |
This comment has been minimized.
This comment has been minimized.
It is also worth noting that a locked post appears in the list page as above. If we implement locking, then will likely need to implement this message in dashboard as well. Part of the point of the lock is so you can see if before you into it.
If it is implement in the dashboard, WordPress heartbeat api will need to be used to refresh the locks every 60 seconds, how it works on the lst page. You think that this functionality is part locking @o-fernandez ? |
Implementation ProposalInitial Edit Story Page LoadWhen the edit story page is accessed by the end-user, the story (post) will be checked whether or not it is locked by another user. The results of this check are then localized into the JS config object ( Example:
Heartbeat API UsageUtilizing the Heartbeat API, we can send the Example (jQuery will not be used in actual implementation):
Example of server-side handling:
The Example (jQuery will not be used in actual implementation):
|
I have two questions here. I am wondering here, if we even need to use heartbeat library at all here. For some so simple, could we have use a our own timer ( like setTimeout) to call check lock every 60 seconds? What benefit does the heart beat add here? How does a story get unlocked? If a user navigates away from the story, how is a unlock story unlocked? I am wondering, if we could do something simpler. Create a new REST API with three endpoints.
Get endpoint GET - POST - DELETE - With these endpoints, we could call a If not lock is set, call the POST endpoint, to set lock, if one is not set already. If user navigates away from editor, call remove lock DELETE endpoint. That seems a little simpler to me and doesn't require loading jquery and heartbeat on the page. I will admit to not knowing how heartbeat really works and if we need it here. |
Thanks both for your comments! Certainly a start, although it sounds like we need to reach some consensus on some of the more fundamental parts of the implementation. Feel free to kick off some discussion on Slack or some meeting for this. Also, we need to keep the ACs in mind. There's more to this than just reading and writing a lock.
FWIW this can be simplified a bit. No need for
Here's what I suggested in the ticket description originally: Post locking/unlocking state in the editor could be handled in story context provider (is locked, is taken over, release lock, etc.)
Don't think we need that part.
The Heartbeat API can also be used by other plugins that might modify data that is sent and received, and the heartbeat interval can be changed by users as well. Using this existing platform would ensure greater compatibility. We can of course also try doing this directly, but for a first MVP solution it seems safest to just use this pre-existing solution
One needs to hook into the
Not sure I would call that simpler per se :-) This significantly increases complexity & required estimate. Not to mention that it doesn't cover all aspects:
Not even in WordPress core was there agreement on what such a REST API could look like. If we can come up with a sound API design for a next iteration of this, then great.
Nobody suggests using jQuery. To listen to Heartbeat events, Aside: this requirement of using |
After meeting with @spacedmonkey and discussing options, I feel that we should revisit the REST API endpoints approach instead of using the Heartbeat API. I say this because the Heartbeat API uses admin-ajax and has been known to be a performance bottleneck for some hosting providers. While my initial intuition has been to do things the "WordPress way", I feel like the Heartbeat API is likely going to be refactored in core to utilize the WP REST API instead. Following this approach and writing our own post locking endpoints allows us to have better control of what gets processed server-side. It also opens the door for expanding the plugin outside of the WordPress space by not making it too WordPress dependent. |
If you both are confident that it makes sense, we can certainly give it a try. But this would need a clear proposal for the REST API design (needs to cover all use cases, as I already mentioned), and then a design brief brief for the actual implementation in the editor leveraging said API. |
Doing a little research these seem to be the functions related post locking wp_check_post_lock With a crud api, I think we could cover these use cases.
@allan23 Can you draw up a REST API design document ( in google docs ), with endpoints, params and responses. Then write up how you plan to map core functionality like refreshes to the endpoints. From there, we should able to spot things missing / not yet mapped. We have two options with post locking. If can either be part of the existing post type endpoint, I also believe that this endpoint, should using embedding. So a get endpoint could look like this.
Meaning you don't have to pick and choose fields for the user object, just embed it. |
Regarding preview links, you might want to take a look at this PR - #6037 |
I already linked to it above, but in case you've missed it: https://core.trac.wordpress.org/ticket/44862 |
This doesn't seem that different from what I suggested.
The big difference is the base is different, but I like basing the web-stories endpoint. So it would result in GET - It would mean just need endpoints and not a new router, which is pretty neat. |
Implementation BriefInitial Edit Story Page LoadWhen the edit story page is accessed by the end-user, the story (post) will be checked whether or not it is locked by another user. The results of this check are then localized into the JS config object ( WP REST API UsageUtilizing a custom endpoint ( React ComponentThe Additional actions, similar to WordPress core, such as Go Back, Preview, and Take Over are to be added. |
@swissspidy Do you have any recommendations on how to delete the lock on existing editor.
Using This is not an expected behaviour. The only time we really know a user is navigating away the editor is when the press this button. Seems a little pointless to delete the lock at this point. |
useEffect(() => {
function releasePostLock() {
// ...
}
window.addEventListener('beforeunload', releasePostLock);
return () => {
window.removeEventListener('beforeunload', releasePostLock);
};
}); |
Do the issue with this is, that we trigger an async call to the REST API. But the issue is, if we dont want around for the reason / even wait for the request to be made, the page navigates away before the request is made. If the request is not made, then the lock is deleted. I am not sure that is this possible using |
If you want to see the code in action. https://github.com/google/web-stories-wp/tree/try/post-locking-with-delete |
Maybe I'm missing some context, but this sounds like we may want to wait for some async action to occur before an action that results in an update to the component tree. Maybe something like:
Also looking into the implementation a bit, might be nice to set some safeguards to prevent state updates from happening in the scenario that a component has unmounted before a promise has resolved |
The issue here is about removing the lock when the user navigates away. The releasePostLock is not called unless you navigation from away from the editor. At this point, all we care about it that request is fired and completed and not about the rest of the app. |
Oh, then you'd want See https://github.com/WordPress/gutenberg/blob/a42aeea340acf58fcb3e91da0e1c77b1cddf4986/packages/editor/src/components/post-locked-modal/index.js#L106-L127 for comparison (ignore the |
Moving back to in progress, as need to add tests. |
I posted on WordPress core trac ticket, with the offer to port this change to core. |
Feature Description
The story editor does not support editing a story at the same time by multiple authors. In order to avoid collisions, only one author should be able to edit a story at a time.
WordPress has this useful feature called Post Locking forr that.
As soon as you start editing a post/story, it will be marked as "locked". Anyone else trying to edit the story after you will get a warning like this:
Context
Alternatives Considered
Additional Context
Original implementation in Gutenberg:
WordPress/gutenberg#4217
WordPress/gutenberg#4331
WordPress/gutenberg#11781
Screenshots:
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance Criteria
Discovery around feasibility of e2e tests is enough depending on complexity, perhaps laying some groundwork (e.g. write mock plugin). We could always add these tests later.
show_post_locked_dialog
filter is applied/respeted (as used in e.g.wp-admin/edit-form-blocks.php
)Implementation Brief
Story_Post_Type.php
so it's available to editor (e.g. lock status)addAction
from@wordpress/data
instead of jQueryConsiderations:
The text was updated successfully, but these errors were encountered: