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

Site Editor: Move page switcher to navigation panel #25620

Merged
merged 22 commits into from
Oct 14, 2020

Conversation

david-szabo97
Copy link
Member

@david-szabo97 david-szabo97 commented Sep 24, 2020

Related: #25262 #25255

Description

This change replicates the page switcher from the header in the Navigation sidebar.

How has this been tested?

  • yarn wp-env start
  • Enable FSE
  • Open Site Editor
  • Click site logo to toggle the navigation sidebar

Screenshots

ezgif com-gif-maker (1)

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.

@david-szabo97 david-szabo97 added [Feature] Full Site Editing [Feature] Navigation Component A navigational waterfall component for hierarchy of items. labels Sep 24, 2020
@github-actions
Copy link

github-actions bot commented Sep 24, 2020

Size Change: -4.78 kB (0%)

Total Size: 1.19 MB

Filename Size Change
build/a11y/index.js 1.14 kB +1 B
build/annotations/index.js 3.54 kB +23 B (0%)
build/autop/index.js 2.72 kB -1 B
build/blob/index.js 668 B +1 B
build/block-directory/index.js 8.61 kB +40 B (0%)
build/block-editor/index.js 130 kB -6 B (0%)
build/block-library/index.js 143 kB -1.42 kB (0%)
build/blocks/index.js 47.6 kB -5 B (0%)
build/components/index.js 169 kB +35 B (0%)
build/compose/index.js 9.63 kB -6 B (0%)
build/core-data/index.js 12.1 kB +13 B (0%)
build/data-controls/index.js 684 B -1 B
build/data/index.js 8.63 kB -5 B (0%)
build/date/index.js 31.9 kB -3 B (0%)
build/dom-ready/index.js 569 B +1 B
build/dom/index.js 4.43 kB +2 B (0%)
build/edit-navigation/index.js 10.6 kB +1 B
build/edit-post/index.js 306 kB +26 B (0%)
build/edit-site/index.js 20.9 kB -372 B (1%)
build/edit-site/style-rtl.css 3.77 kB -91 B (2%)
build/edit-site/style.css 3.77 kB -92 B (2%)
build/edit-widgets/index.js 21.3 kB +7 B (0%)
build/editor/index.js 42.5 kB -2.95 kB (6%)
build/element/index.js 4.45 kB +1 B
build/escape-html/index.js 733 B -1 B
build/i18n/index.js 3.54 kB +1 B
build/is-shallow-equal/index.js 709 B -1 B
build/keyboard-shortcuts/index.js 2.39 kB -1 B
build/list-reusable-blocks/index.js 3.02 kB +2 B (0%)
build/media-utils/index.js 5.12 kB -1 B
build/notices/index.js 1.69 kB +2 B (0%)
build/nux/index.js 3.27 kB +6 B (0%)
build/plugins/index.js 2.44 kB +1 B
build/primitives/index.js 1.34 kB +1 B
build/priority-queue/index.js 789 B -1 B
build/redux-routine/index.js 2.85 kB +2 B (0%)
build/rich-text/index.js 13 kB +6 B (0%)
build/shortcode/index.js 1.7 kB +1 B
build/url/index.js 4.07 kB +3 B (0%)
build/viewport/index.js 1.75 kB -1 B
ℹ️ View Unchanged
Filename Size Change
build/api-fetch/index.js 3.35 kB 0 B
build/block-directory/style-rtl.css 943 B 0 B
build/block-directory/style.css 942 B 0 B
build/block-editor/style-rtl.css 10.9 kB 0 B
build/block-editor/style.css 10.9 kB 0 B
build/block-library/editor-rtl.css 8.65 kB 0 B
build/block-library/editor.css 8.65 kB 0 B
build/block-library/style-rtl.css 7.71 kB 0 B
build/block-library/style.css 7.71 kB 0 B
build/block-library/theme-rtl.css 741 B 0 B
build/block-library/theme.css 741 B 0 B
build/block-serialization-default-parser/index.js 1.78 kB 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/components/style-rtl.css 15.5 kB 0 B
build/components/style.css 15.5 kB 0 B
build/deprecated/index.js 772 B 0 B
build/edit-navigation/style-rtl.css 868 B 0 B
build/edit-navigation/style.css 871 B 0 B
build/edit-post/style-rtl.css 6.3 kB 0 B
build/edit-post/style.css 6.29 kB 0 B
build/edit-widgets/style-rtl.css 2.97 kB 0 B
build/edit-widgets/style.css 2.97 kB 0 B
build/editor/editor-styles-rtl.css 480 B 0 B
build/editor/editor-styles.css 482 B 0 B
build/editor/style-rtl.css 3.85 kB 0 B
build/editor/style.css 3.84 kB 0 B
build/format-library/index.js 7.49 kB 0 B
build/format-library/style-rtl.css 547 B 0 B
build/format-library/style.css 548 B 0 B
build/hooks/index.js 1.74 kB 0 B
build/html-entities/index.js 622 B 0 B
build/keycodes/index.js 1.85 kB 0 B
build/list-reusable-blocks/style-rtl.css 476 B 0 B
build/list-reusable-blocks/style.css 476 B 0 B
build/nux/style-rtl.css 671 B 0 B
build/nux/style.css 668 B 0 B
build/reusable-blocks/index.js 3.04 kB 0 B
build/server-side-render/index.js 2.6 kB 0 B
build/token-list/index.js 1.24 kB 0 B
build/warning/index.js 1.13 kB 0 B
build/wordcount/index.js 1.17 kB 0 B

compressed-size-action

@Copons Copons added the [Status] In Progress Tracking issues with work in progress label Sep 26, 2020
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.

It looks like we won't be showing content selection options in the sidebar for now, only the templates and template parts. The actual content to be viewed or edited might be provided through Preview or in some other way. Taking that into account I think we should close this out for now, and reopen it later if needed.

@vindl
Copy link
Member

vindl commented Oct 8, 2020

... and reopen it later if needed.

The time has come. 😄

@david-szabo97 @Copons I think we should place this in a separate submenu Content (or some other name) and remove the pages selector in the same PR.

@vindl vindl reopened this Oct 8, 2020
@david-szabo97 david-szabo97 force-pushed the add/navigation-panel-page-switcher branch from 1fd55ff to f4c819f Compare October 9, 2020 07:59
@david-szabo97 david-szabo97 changed the title [WIP] Site Editor: Add page switcher Site Editor: Move page switcher to navigation panel Oct 9, 2020
Copy link
Contributor

@Copons Copons 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 shaping up nicely! ✨

It works as expected, but I've left a few comments about the code organization, as I think we should be able to simplify the content menu a little bit.

It's a bit of a bummer that we are losing LinkControl (the search post function), but it seems more appropriate to take care of it in a follow up, rather than cluttering this PR with a possibly large amount of CSS changes. 🙂

onClick={ () => onPageSelect( entity, item ) }
/>
) }
/>
Copy link
Contributor

Choose a reason for hiding this comment

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

By now you might have noticed that I'm not very into render props. 😄

In this specific case I don't really see the need for it.
How about just passing kind and name (and query), and let the NavigationEntityItems do all the heavy lifting?

E.g.

function NavigationEntityItems( { kind, name, query } ) {
  const entities = useSelect( /* ... */ );
  const { setPage } = useDispatch( 'core/edit-site' );

  if ( ! entities ) {
    return;
  }

  const onSelectItem = ( { type, slug, link, id }, item ) => {
    setPage( { /* ... */ } );
  };

  return ( <Fragment> { entities.map( ( entity ) => {
    const key = `content-${ kind }-${ name }-${ entity.slug }`;
    return ( <NavigationItem
      key={ key }
      item={ key }
      title={ entity.title.rendered }
      onClick={ () => onSelectItem( entity, key ) }
    /> );
  } ) } </Fragment> );
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

settings={ {} }
noDirectEntry
showInitialSuggestions
/>
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd have loved to have this in the sidebar as well, but its style is very opinionated, and I guess it would require a beefy effort.
Let's make sure we follow up on this though!


const {
setTemplate,
setTemplatePart,
setNavigationPanelActiveMenu,
setPage,
Copy link
Contributor

Choose a reason for hiding this comment

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

I've just realized this, and I've implicitly mentioned it in another comment, but I kinda feel like we could move some of these actions closer to where they are used, because, I might be wrong, it doesn't look like they are needed here.

So, setPage could live directly in the content menu (content.js).

setTemplate and setTemplatePart could be moved in their corresponding menus (template.js and template-part.js), or even both into template-navigation-items.js (using entityType to determine which to use).

(Note: if we agree on this move, we can take care of template and template part elsewhere)

Copy link
Member Author

Choose a reason for hiding this comment

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

This sounds good to me! Probably template-navigation-items.js is the best place for it. It will make the component pretty smart though 😬

const { show_on_front: _showOnFront } = getEditedEntityRecord(
'root',
'site'
);
Copy link
Contributor

Choose a reason for hiding this comment

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

I've just noticed that we are losing all the "show on front" logic from the page switcher. 🤔

if ( showOnFront === 'posts' )
pageGroups.posts.unshift( {
label: (
<>
{ __( 'All Posts' ) }
<Tooltip text={ __( 'Home' ) }>
<div>
<Icon icon={ home } />
</div>
</Tooltip>
</>
),
value: '/',
context: {
query: { categoryIds: [] },
queryContext: { page: 1 },
},
} );
return pageGroups;
},

Am I missing something?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oooops 😄 Pushed a commit which re-adds it.

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 is working well in my testing. 👍

@vindl
Copy link
Member

vindl commented Oct 9, 2020

After some thought, I think it would be better if we exposed the Content as a separate navigation in the top level, similar to Theme now. In it we could expose Pages, Posts, and Categories as separate submenus. Something like this:

Screenshot 2020-10-09 at 20 14 00

@Copons
Copy link
Contributor

Copons commented Oct 9, 2020

After some thought, I think it would be better if we exposed the Content as a separate navigation in the top level, similar to Theme now. In it we could expose Pages, Posts, and Categories as separate submenus. Something like this:

Screenshot 2020-10-09 at 20 14 00

I don't have a strong opinion either way, but that should be fairly easy by simply adding a separate Navigation below the template one.

@vindl
Copy link
Member

vindl commented Oct 9, 2020

I don't have a strong opinion either way, but that should be fairly easy by simply adding a separate Navigation below the template one.

I have a preference for it. The content is independent of the theme, so it doesn't make much sense to nest content under it. It allows us to get to pages and posts with one less click. We don't get into lack of space issues when trying to show them all in one menu (or at least not as early), and the search will probably be better contained.

@david-szabo97
Copy link
Member Author

david-szabo97 commented Oct 12, 2020

@vindl @Copons Reworked Content as a separate Navigation

NOTE: E2E tests are going to fail. Once we agreed on the changes and it's ready to be merged, I'll fix up the tests.

@@ -3,6 +3,7 @@
height: 100%;
position: relative;
width: $nav-sidebar-width;
background: #1e1e1e;
Copy link
Member Author

Choose a reason for hiding this comment

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

It would be great to put this somewhere as a variable. Like we did with nav-sidebar-width. Which file would be the place for it?

Copy link
Member

Choose a reason for hiding this comment

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

Don't we already have a base variable for this in darkGray.primary and $gray-900?

Copy link
Member Author

Choose a reason for hiding this comment

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

We do, but if we change the Navigation component's background color, then we need to change it everywhere else. That's why a variable would be handy. This background should match the Navigation's component background all the time.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point, but I'm not sure we have an established way to do it. 🤔
I'd say let's go with $gray-900 here for now, and maybe we can circle back in the future to have a single variable for all sidebar backgrounds.

import ContentPostsMenu from './menus/content-posts';

export default function ContentNavigation() {
const [ activeMenu, setActiveMenu ] = useState( 'root' );
Copy link
Member Author

Choose a reason for hiding this comment

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

Having two Navigation components make things interesting. Should we store this in the store as well?

Copy link
Member

Choose a reason for hiding this comment

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

cc @Copons on this since he was advertising the ability to have multiple navigations in one view 😄

Copy link
Member

Choose a reason for hiding this comment

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

If it's working fine for now I'd defer the store migration for a separate PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

advertising

😆
Well, I mean, the Navigation component is one part of the sidebar, so there are literally no reasons why a sidebar can't have more than one!

Also, IIRC the component's storybook used to have multiple Navigation in the same example (but this might have been just some WIP code on my machine, never released to the general public).

Copy link
Contributor

Choose a reason for hiding this comment

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

About the migration to Redux: let's do it in a follow up once #26003 is merged, so that we can nest it inside navigationPanel.

@vindl
Copy link
Member

vindl commented Oct 12, 2020

NOTE: E2E tests are going to fail. Once we agreed on the changes and it's ready to be merged, I'll fix up the tests.

I think this is fine for the first pass. As far as I'm concerned we can merge this once the tests are fixed.

@david-szabo97 david-szabo97 force-pushed the add/navigation-panel-page-switcher branch from eafc013 to 137340b Compare October 13, 2020 08:34
Copy link
Contributor

@Copons Copons left a comment

Choose a reason for hiding this comment

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

Looking good @david-szabo97!

I've left a few requests, but they should be very straightforward!

@@ -3,6 +3,7 @@
height: 100%;
position: relative;
width: $nav-sidebar-width;
background: #1e1e1e;
Copy link
Contributor

Choose a reason for hiding this comment

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

Good point, but I'm not sure we have an established way to do it. 🤔
I'd say let's go with $gray-900 here for now, and maybe we can circle back in the future to have a single variable for all sidebar backgrounds.

@vindl
Copy link
Member

vindl commented Oct 14, 2020

I tested this a bit more with the latest update. One unexpected consequence of introducing the Content like this is that two Navigation menus are independent now. Content will remain in view while navigating templates. It's also awkwardly changing its position all the time depending on the number of items in the menu above.

I think it would be better to hide the Content menu once we drill down into Templates and vice versa, but retain the way it looks now if that makes sense. What do you all think?

@david-szabo97 david-szabo97 force-pushed the add/navigation-panel-page-switcher branch from 137340b to 45e658c Compare October 14, 2020 07:23
@david-szabo97
Copy link
Member Author

Made the changes requested by @Copons and

I think it would be better to hide the Content menu once we drill down into Templates and vice versa, but retain the way it looks now

is done as well

@vindl
Copy link
Member

vindl commented Oct 14, 2020

Awesome ✨ this looks good to me now. 👍

Copy link
Contributor

@Copons Copons left a comment

Choose a reason for hiding this comment

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

LGTM! ✨

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.

LGTM! :shipit:

@vindl vindl merged commit 0bf25d7 into master Oct 14, 2020
@vindl vindl deleted the add/navigation-panel-page-switcher branch October 14, 2020 15:30
@github-actions github-actions bot added this to the Gutenberg 9.2 milestone Oct 14, 2020
sirreal pushed a commit that referenced this pull request Oct 14, 2020
Move page selection dropdown from the header to the navigation sidebar.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Navigation Component A navigational waterfall component for hierarchy of items. [Status] In Progress Tracking issues with work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants