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

Move Entities Saved States from Modal to Sidebar #21522

Merged
merged 61 commits into from
May 1, 2020

Conversation

Addison-Stavlo
Copy link
Contributor

@Addison-Stavlo Addison-Stavlo commented Apr 9, 2020

Description

This PR explores moving the entitiy-saved-states component from a Modal to a Sidebar as discussed in issue #20421 .

This also enables applicable entities to be selected in the editor through the sidebar.

sidebar-preview


Notes on design parity (or lack thereof) and future goals:

  • Checkbox Controls - the Sidebar designs in the issue have gotten rid of the checkbox controls. We have kept them in this iteration since it would not make sense to remove them before its replacement functionality (such as a "discard changes" for each entity) has been implemented. I am having problems figuring out how to do this with the current tools available in core data, and this will be the next step to look into following this PR.
  • "Select Entity" Button - Similarly, once we are able to get rid of the Checkbox controls, the 'Select Entity' button would be removed and its functionality would be added to the entity Title as shown in the design figmas.
  • Panel Body / dropdowns - Temporary solution to keep things decently styled and well organized. These would be removed and refactored to match the designs once the functionality for other options shown is available ( 'discard changes', 'save as', etc.)
  • Icons - A handful of Icons shown in the Figma designs are not yet available in our Icons package. I have temporarily made a 'best guess' using available icons as placeholders until these can be updated.

How has this been tested?

Tested on local docker setup in the various post editors and site editor.

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.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

@github-actions
Copy link

github-actions bot commented Apr 9, 2020

Size Change: +9.19 kB (1%)

Total Size: 825 kB

Filename Size Change
build/annotations/index.js 3.62 kB -2 B (0%)
build/api-fetch/index.js 4.08 kB -2 B (0%)
build/autop/index.js 2.82 kB +2 B (0%)
build/block-directory/index.js 6.6 kB +373 B (5%) 🔍
build/block-editor/index.js 107 kB +870 B (0%)
build/block-editor/style-rtl.css 10.2 kB +2 B (0%)
build/block-editor/style.css 10.2 kB +2 B (0%)
build/block-library/editor-rtl.css 7.11 kB +81 B (1%)
build/block-library/editor.css 7.11 kB +82 B (1%)
build/block-library/index.js 115 kB +1.2 kB (1%)
build/block-library/style-rtl.css 7.22 kB +77 B (1%)
build/block-library/style.css 7.23 kB +81 B (1%)
build/block-serialization-spec-parser/index.js 3.1 kB +1 B
build/blocks/index.js 48.1 kB -3 B (0%)
build/components/index.js 179 kB -13 B (0%)
build/components/style-rtl.css 16.9 kB -8 B (0%)
build/components/style.css 16.9 kB -8 B (0%)
build/compose/index.js 6.66 kB +1 B
build/core-data/index.js 11.4 kB -1 B
build/data/index.js 8.44 kB +14 B (0%)
build/edit-navigation/index.js 4.05 kB +512 B (12%) ⚠️
build/edit-post/index.js 28.1 kB +545 B (1%)
build/edit-post/style-rtl.css 12.2 kB +26 B (0%)
build/edit-post/style.css 12.2 kB +27 B (0%)
build/edit-site/index.js 11.4 kB +496 B (4%)
build/edit-site/style-rtl.css 5.18 kB +74 B (1%)
build/edit-site/style.css 5.18 kB +75 B (1%)
build/edit-widgets/index.js 7.76 kB +270 B (3%)
build/editor/index.js 44.3 kB +919 B (2%)
build/editor/style-rtl.css 5.07 kB +1.8 kB (35%) 🚨
build/editor/style.css 5.08 kB +1.81 kB (35%) 🚨
build/element/index.js 4.65 kB +1 B
build/format-library/index.js 7.63 kB -2 B (0%)
build/list-reusable-blocks/index.js 3.12 kB +1 B
build/media-utils/index.js 5.29 kB -2 B (0%)
build/notices/index.js 1.79 kB -1 B
build/nux/index.js 3.4 kB +1 B
build/plugins/index.js 2.56 kB -116 B (4%)
build/primitives/index.js 1.5 kB +1 B
build/redux-routine/index.js 2.85 kB +7 B (0%)
build/server-side-render/index.js 2.68 kB -2 B (0%)
build/shortcode/index.js 1.69 kB -1 B
build/token-list/index.js 1.28 kB -1 B
build/url/index.js 4.02 kB -1 B
build/warning/index.js 1.14 kB +1 B
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.02 kB 0 B
build/blob/index.js 620 B 0 B
build/block-directory/style-rtl.css 760 B 0 B
build/block-directory/style.css 761 B 0 B
build/block-library/theme-rtl.css 683 B 0 B
build/block-library/theme.css 685 B 0 B
build/block-serialization-default-parser/index.js 1.88 kB 0 B
build/data-controls/index.js 1.29 kB 0 B
build/date/index.js 5.47 kB 0 B
build/deprecated/index.js 772 B 0 B
build/dom-ready/index.js 568 B 0 B
build/dom/index.js 3.1 kB 0 B
build/edit-navigation/style-rtl.css 485 B 0 B
build/edit-navigation/style.css 485 B 0 B
build/edit-widgets/style-rtl.css 4.67 kB 0 B
build/edit-widgets/style.css 4.66 kB 0 B
build/editor/editor-styles-rtl.css 428 B 0 B
build/editor/editor-styles.css 431 B 0 B
build/escape-html/index.js 733 B 0 B
build/format-library/style-rtl.css 502 B 0 B
build/format-library/style.css 502 B 0 B
build/hooks/index.js 2.13 kB 0 B
build/html-entities/index.js 622 B 0 B
build/i18n/index.js 3.56 kB 0 B
build/is-shallow-equal/index.js 710 B 0 B
build/keyboard-shortcuts/index.js 2.51 kB 0 B
build/keycodes/index.js 1.94 kB 0 B
build/list-reusable-blocks/style-rtl.css 226 B 0 B
build/list-reusable-blocks/style.css 226 B 0 B
build/nux/style-rtl.css 616 B 0 B
build/nux/style.css 613 B 0 B
build/priority-queue/index.js 789 B 0 B
build/rich-text/index.js 14.8 kB 0 B
build/viewport/index.js 1.84 kB 0 B
build/wordcount/index.js 1.18 kB 0 B

compressed-size-action

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

Feature wise, this makes sense and I'd love to land an iteration of this but from the code perspective, I have some concerns, the main ones are:

We shouldn't be relying on the "editor" package ini "edit-site". The editor package is a post-specific one. We might need some refactoring to achieve this though.

The "edit-post" package also has the concept of "pre-publish" panel, I'm not sure we can share code (at least as is) with the "edit-site" package since the logic for that panel is buried somewhere in the editor package, but they should at lease behave closely. I wonder if there are some generic components to extract while leaving the specifics to each top level package (edit-*).

@Addison-Stavlo
Copy link
Contributor Author

Addison-Stavlo commented Apr 14, 2020

@youknowriad thanks for taking a look!

We shouldn't be relying on the "editor" package ini "edit-site". The editor package is a post-specific one. We might need some refactoring to achieve this though.

Ah I see! entities-saved-states and its associates store are all setup in editor and is then used inside both edit-post and edit-site, which is why I was assuming it wasn't edit-post specific. Do you think refactoring all of this over to block-editor package would make the most sense?

the logic for that panel is buried somewhere in the editor package, but they should at lease behave closely.

Thats essentially what this is modeled after (mostly from the scss) with a +1 on the z-index so it plays well with the publish panel inside the post editor as well.

@youknowriad
Copy link
Contributor

Just noticed that "EntitiesSavedState" is on Editor which doesn't make a lot of sense to me. I think it should probably be in "core-data" since it's related to "entities". That said I'm fine with keeping it there in this PR and solving that part separately.

What I'd recommend is to try to build this PR without introducing any editor specific things (core/editor store or components) into EntitiesSavedState, potentially, by using props for the component.

It's going to be a challenge to try to reuse things between edit-site and edit-post. block-editor is not going to be the right place for these when they deal with WordPress specifics and APIs.

@Addison-Stavlo
Copy link
Contributor Author

Addison-Stavlo commented Apr 14, 2020

What I'd recommend is to try to build this PR without introducing any editor specific things (core/editor store or components) into EntitiesSavedState,

It looks like the only core/editor store the entities-saved-states is currently using are the actions/selectors I just added for controlling the open/closed state. If we were to move this to core-data, these would go along with it and Im assuming that would be fine? Or is there some other issue here?

Then our edit-site would call core-data instead of the editor package and we wouldn't be conflicted there. And the edit-post package would continue to call editor for editPost/savePost where it does and would move to using core-data for the saved states sidebar.

Does the above sound good? Or is there some other conflicting piece I am missing with this?

@youknowriad
Copy link
Contributor

If we were to move this to core-data, these would go along with it and Im assuming that would be fine? Or is there some other issue here?

We shouldn't move UI related state to core-data. UI related things should stay in the UI related packages (edit-post, edit-site). I think we should use props. onSelectEntity or things like that..

@Addison-Stavlo
Copy link
Contributor Author

We shouldn't move UI related state to core-data. UI related things should stay in the UI related packages (edit-post, edit-site). I think we should use props. onSelectEntity or things like that..

Gotcha. For the Modal, we were using props and passing down to entities-saved-states as a child component of the save/publish buttons. This works well for a modal being fixed position across the entire screen, but for a sidebar we need to place the component elsewhere for proper dom hierarchy and styles.

Modeling functionality around how the publish panel works, instead of entities-saved-states being a child of the top-bar buttons, it has been moved to the actions prop of the layout. ( layout->index.js in edit-post, and editor->index.js of edit-site). For us to pass the correct props in this location it seems like the simplest thing to do would be to use the store to bridge that gap? In which case, do we want 1 copy of these actions/selectors in 1 edit-post store and another copy of essentially the same thing in the edit-site store? Is there not any package where we could use these same actions/selectors for both uses?

@youknowriad
Copy link
Contributor

do we want 1 copy of these actions/selectors in 1 edit-post store and another copy of essentially the same thing in the edit-site store?

I think that's totally fine, we shouldn't be afraid of duplicating code. Sometimes I feel early abstractions do more harm than good. Now later, if we want to reuse more stuff, maybe the "interface" package is a good fit since it's a "WPAdmin UI" package but I'm still not sure about the APIs at this point so better to start simple.

@Addison-Stavlo
Copy link
Contributor Author

@youknowriad - That makes sense to me. I removed the store stuff from the editor package and moved them to edit-post and edit-site instead. The entities-saved-states component now receives these as props instead of relying on one specific store.

After taking a quick look at moving entities-saved-states over to core/data package: it looks like the package doesn't currently have any components exported. Would it make sense to add a components directory and the required dependencies to export components from this package, or maybe it will make more sense to find a home for it elsewhere? (we can move it later as you suggested, but I wanted to take a quick look).

maybe the "interface" package is a good fit since it's a "WPAdmin UI" package but I'm still not sure about the APIs at this point so better to start simple.

Maybe "interface" would make sense as the home for both the saved states component and its associated store in the end? 🤔 Once we are more sure about the APIs and want to consolidate/refactor this around more.

@Addison-Stavlo
Copy link
Contributor Author

I added some updates on the post-editor side so that:

  • actions panels will never overlap.
  • a tab accessible "open save panel" button appears when applicable
  • 'hidden' a11y buttons will not overlap or show when panels are open
  • default behavior on the 'open publish panel' button remains the same.

And on the site-editor side, I added the "open save panel" a11y button.

@youknowriad
Copy link
Contributor

Just noting that I'm not be able to review this on the next couple days. @epiqueras you might be interested in this PR too.

Copy link
Contributor

@epiqueras epiqueras 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 😄

packages/edit-post/src/components/layout/actions-panel.js Outdated Show resolved Hide resolved
packages/edit-post/src/components/layout/index.js Outdated Show resolved Hide resolved
packages/edit-post/src/components/layout/index.js Outdated Show resolved Hide resolved
packages/edit-site/src/components/editor/index.js Outdated Show resolved Hide resolved
@chrisvanpatten
Copy link
Contributor

This is so sweet. It would be cool to see reusable blocks move to a similar saving approach. Nice work here, can't wait to use it! 🙌

@noahtallen
Copy link
Member

It would be cool to see reusable blocks move to a similar saving approach

Conveniently, #21368 sets us up for something like that 👀

Copy link
Member

@noahtallen noahtallen left a comment

Choose a reason for hiding this comment

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

Let's do it! :shipit:

I noticed a thing where an edit to a template part after an initial save did not make the editor think that the TP had changes. so it doesn't persist the change to the DB when you click save. I'm going to assume that this will be fixed by #21368, since we already know that dirty states aren't being computed correctly. 😁 But I thought I'd point it out because I didn't think this was a bug on master

Screen Shot 2020-04-30 at 9 27 04 AM

@Addison-Stavlo
Copy link
Contributor Author

Addison-Stavlo commented Apr 30, 2020

I noticed a thing where an edit to a template part after an initial save did not make the editor think that the TP had changes.

@noahtallen, I'm not able to reproduce this. I tried both inserting an existing TP as well as creating a new one. The TP always seems to come up as 'dirty' after changes are made to it on my end. I've tried edits to them w/ w/o / before / after an initial save.

Maybe I am not going through the same flow?

@noahtallen
Copy link
Member

no worries :) I don't think it should affect this PR then. If it comes up again, it would probably be related to the code that I'm working on anyways rather than the UI aspect of displaying it

@Addison-Stavlo
Copy link
Contributor Author

I think all the requested changes have been addressed. Are we in a good state to move forward with this now?

Copy link
Member

@vindl vindl left a comment

Choose a reason for hiding this comment

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

This worked as expected in my testing. Nice work @Addison-Stavlo! 🎉

I noticed a minor issue with Select functionality. Clicking it for the second time will de-select the template part, and consecutive clicks won't toggle it back. However I don't think it's a blocker and it can be addressed in follow-up PR if needed.

@Addison-Stavlo Addison-Stavlo merged commit 4830c2c into master May 1, 2020
@Addison-Stavlo Addison-Stavlo deleted the update/multi-entity-save-flow branch May 1, 2020 00:11
@github-actions github-actions bot added this to the Gutenberg 8.1 milestone May 1, 2020
font-size: 18px;
margin: 20px 0 10px;
.entities-saved-states__panel {
@include reset;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you recall why we need a "reset" here. Seems weird since this is meant for global resets.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally, components don't depend on global resets though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It may not be necessary. I think I added it b/c post-publish-panel was using it at the time as well and I was trying to ensure the styles were the same between the two. It looks like it's not there anymore either.

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

Successfully merging this pull request may close these issues.

8 participants