Skip to content

Edit Widgets: save lock control via actions #69984

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

Merged
merged 4 commits into from
May 1, 2025

Conversation

Infinite-Null
Copy link
Contributor

@Infinite-Null Infinite-Null commented Apr 25, 2025

What?

Add a widget save locking feature. Plugins can add and remove locks and when any locks are present, the update button is disabled.
Closes #33756

Why?

There was no API for developers to lock widget saving, like there was for post saving.

How?

  • Add actions for lock and unlock widget saving
  • Add an isWidgetSavingLocked selector
  • Check isWidgetSavingLocked in the widget update button

Testing Instructions

  • Load edit widgets and make some edits. In the console, type:
  • wp.data.dispatch( 'core/edit-widget' ).lockWidgetSaving( 'mylock' );
  • Note: The update button becomes disabled.
  • Remove the widget lock with:
  • wp.data.dispatch( 'core/edit-widget' ).unlockWidgetSaving( 'mylock' );
    • Test adding multiple locks: the button will remain disabled until all locks are removed.

Screencast:

Screen.Recording.2025-04-30.at.12.32.59.PM.mov

@t-hamano t-hamano added [Type] Enhancement A suggestion for improvement. [Package] Edit Widgets /packages/edit-widgets [Type] New API New API to be used by plugin developers or package users. labels Apr 28, 2025
Copy link

github-actions bot commented Apr 30, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: Infinite-Null <ankitkumarshah@git.wordpress.org>
Co-authored-by: adamsilverstein <adamsilverstein@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: jorostoyanov <stoyanovgs@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@adamsilverstein adamsilverstein added [Type] New API New API to be used by plugin developers or package users. [Type] Feature New feature to highlight in changelogs. and removed [Type] New API New API to be used by plugin developers or package users. labels Apr 30, 2025
@adamsilverstein
Copy link
Member

@Infinite-Null overall this looks really good.

I had some trouble testing, I was getting JavaScript errors on the edit widget screen preventing updates from working, so I couldn't test the actions directly. I am going to try resetting my local (I see the same error on trunk).

Copy link
Member

@adamsilverstein adamsilverstein left a comment

Choose a reason for hiding this comment

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

Nice work!

@adamsilverstein
Copy link
Member

adamsilverstein commented Apr 30, 2025

wp.data.dispatch( 'core/edit-widget' ).lockWidgetSaving( 'mylock' );

@Infinite-Null The PR description appears to have an error that threw me off in testing. This should be wp.data.dispatch( 'core/edit-widgets' ).lockWidgetSaving( 'mylock' ); - the "edit-widgets" part is plural. can you please update that?!

@Mamaduka Mamaduka removed [Type] Enhancement A suggestion for improvement. [Type] Feature New feature to highlight in changelogs. labels May 1, 2025
Copy link
Member

@Mamaduka Mamaduka left a comment

Choose a reason for hiding this comment

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

Thank you, @Infinite-Null!

@Mamaduka Mamaduka added the props-bot Adding this label triggers the Props Bot workflow for a PR. label May 1, 2025
@github-actions github-actions bot removed the props-bot Adding this label triggers the Props Bot workflow for a PR. label May 1, 2025
@Mamaduka Mamaduka merged commit 7d3fafc into WordPress:trunk May 1, 2025
72 of 82 checks passed
@github-actions github-actions bot added this to the Gutenberg 20.8 milestone May 1, 2025
@adamsilverstein
Copy link
Member

I was getting JavaScript errors on the edit widget screen preventing updates from working

This was related to an experiment I had enabled for testing. Once I disabled that, the errors went away and the locking mechanism worked as expected.

@Mamaduka
Copy link
Member

Mamaduka commented May 1, 2025

Thanks for the update, @adamsilverstein!

chriszarate pushed a commit to chriszarate/gutenberg that referenced this pull request Jul 1, 2025
Co-authored-by: Infinite-Null <ankitkumarshah@git.wordpress.org>
Co-authored-by: adamsilverstein <adamsilverstein@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: jorostoyanov <stoyanovgs@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Edit Widgets /packages/edit-widgets [Type] New API New API to be used by plugin developers or package users.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Introduce lockWidgetsSaving as equivalent to lockPostSaving
4 participants