Skip to content
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

Plugin sorting via priority property in registerPlugin #16384

Open
wants to merge 30 commits into
base: trunk
Choose a base branch
from

Conversation

ryanwelcher
Copy link
Contributor

@ryanwelcher ryanwelcher commented Jul 2, 2019

Description

As is stands now, there is no way to control the order of the items being rendered in Slots. This PR adds a new priority property to the settings object that is passed to registerPlugin. This property is optional and has a default value of 10. I chose 10 as that is the default priority for Hooks and familiar to most WordPress developers and so that we can move items ahead of the default position without using negative numbers.

The approach adds the priority property when the plugin is being registered and then uses sortBy to sort the plugins before they are rendered inside the <PluginArea /> component.

How has this been tested?

This has been tested locally and using the unit and e2e tests.

Types of changes

New feature (non-breaking change which adds functionality)

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.

@ryanwelcher
Copy link
Contributor Author

ryanwelcher commented Jul 2, 2019

This was broken out based on comments from @youknowriad on #13361

@ryanwelcher
Copy link
Contributor Author

@youknowriad have you had a chance to think on this any further? Happy to make any changes as needed.

@ryanwelcher ryanwelcher added the [Feature] Extensibility The ability to extend blocks or the editing experience label Aug 27, 2019
@paaljoachim
Copy link
Contributor

Adding in what @youknowriad mentioned during the core editor meeting on the 11th September:
"To be honest, I'm not entirely sold on this because it's very tied to the implementation of the Slot. (not a fully semantic API).
I don't have a better alternative at the moment.
I know @matias have some thoughts about that as well."

@ryanwelcher ryanwelcher changed the title SlotFill sorting with a priority property Plugin sorting via priority property in registerPlugin Oct 22, 2019
@ryanwelcher
Copy link
Contributor Author

ryanwelcher commented Oct 22, 2019

Based on comments in the last #core-editor meeting, I feel I need to better explain this PR. I have created a new issue #18064 to track the intent.

@mcsf commented:

It seems that priority and order are very visually focused, in stark contrast with how Gutenberg has tried to use SlotFill so far.

The items that would be affected by this change are very much visually based. They appear in a certain locations of the admin - ie. Menu Items and sidebar panels

In Gutenberg, we talk about advanced settings, inspector, etc., instead of the visual element sidebar. Coming back to priority, what does it mean for SlotFill as far as selective rendering goes? how is a sequence determined semantically? etc.Why does this matter? Well, the bridging of different platforms and environments under Gutenberg is an important factor. If a codebase needs to work transparently across Web and Mobile, for example, its semantics needs to be clear and independent of a particular visual expression (e.g. Web on Desktop)

I want to make it clear, that this PR does not affect how a SlotFill is rendered and it doesn't interact with the SlotFill system in any way. It simply controls the order in which plugins( that contain SlotFIlls ) are rendered inside the PluginAreacomponent.

@gziolo gziolo added the [Feature] Plugins API Extending the Gutenberg project with plugins via the Plugins API label Oct 23, 2019
@jeffpaul
Copy link
Member

@ryanwelcher care to resolve the merge conflicts so @etoledom could smoke test this on mobile?

@ryanwelcher
Copy link
Contributor Author

@jeffpaul @etoledom Sorry for the delay on this! I have resolved the conflicts with latest trunk and made a couple of changes to reflect updates since this PR was created.

@jeffpaul
Copy link
Member

jeffpaul commented Jun 1, 2021

@etoledom will you please smoke test this on mobile and report back your findings?

@jeffpaul
Copy link
Member

jeffpaul commented Feb 2, 2022

@etoledom any chance you've been able to smoke test this on mobile?

@SiobhyB
Copy link
Contributor

SiobhyB commented Jan 5, 2023

@ryanwelcher, @jeffpaul, apologies for the delay here! @etoledom isn't working on Gutenberg Mobile at the moment but has asked those of us currently on the team to take a look. I plan to take a look tomorrow.

As the PR hasn't been updated since May 2021, I'd be grateful if you had a chance to update with the latest changes from trunk first, but not a blocker to me mobile testing tomorrow if you don't get a chance. :)

@SiobhyB
Copy link
Contributor

SiobhyB commented Jan 6, 2023

@ryanwelcher, @jeffpaul, I tested this locally on mobile by going through some of the main writing flows e.g. adding and editing multiple third-party blocks, uploading images, general formatting, etc. I didn't spot any regressions, and wouldn't expect any as we don't appear to use the registerPlugin function on the native side.

To test this, I had to update from trunk locally and made some assumptions about the way the merge conflicts with plugin-area/index.js would be resolved. I'll follow along with this PR and would be happy to test again after it's 'officially' updated from trunk.

@ryanwelcher
Copy link
Contributor Author

@SiobhyB thanks for following up, I've been AFK for the holidays but will take a look at this shortly!

@michaelmcandrew
Copy link

I came looking for this functionality as a way to present a PluginDocumentSettingPanel directly after the 'Featured image' panel, though I would settle for anywhere after the Featured image panel if I couldn't get it to sit directly after.

My reading of the code and the default 10 makes me think positioning within current panels would not be possible. Thought it was worth mentioning it now in case it can be added to this PR / there is anythning that can be changed in this PR to make it easier to implement in the future.

@ndiego
Copy link
Member

ndiego commented Dec 13, 2023

@ryanwelcher would you be able to update this PR with the last changes from trunk whenever you a sec? I would love to restart this discussion.

@emeaguiar
Copy link

Does anyone know if there's a workaround for this?

@ndiego
Copy link
Member

ndiego commented Jan 1, 2024

Does anyone know if there's a workaround for this?

Not that I am aware of.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Extensibility The ability to extend blocks or the editing experience [Feature] Plugins API Extending the Gutenberg project with plugins via the Plugins API
Projects
Status: PR needs review
Development

Successfully merging this pull request may close these issues.

Provide way to control render order of plugins registered via registerPlugin