Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
406d3a4
de-emphasise pattern filters in inserter
SaxonF Sep 21, 2023
97b0644
Remove obsolete props from PatternListHeader
aaronrobertshaw Sep 21, 2023
8c2a7ab
Remove unnecessary dependencies comment
aaronrobertshaw Sep 21, 2023
e9b5006
Remove unused pattern source filters
aaronrobertshaw Sep 21, 2023
979d9be
Fix pattern filtering logic
aaronrobertshaw Sep 21, 2023
34293bc
Split theme patterns from core and directory sourced ones
aaronrobertshaw Sep 21, 2023
32f7a31
Allow theme and directory patterns as unsynced
aaronrobertshaw Sep 21, 2023
d4ec9c6
Disable the sync filter options if the pattern source is not user
glendaviesnz Sep 21, 2023
1f0ed2a
Add constants for different all values
glendaviesnz Sep 21, 2023
14f6acd
Keep the menu open while toggling options
glendaviesnz Sep 21, 2023
b55d967
Add sticky header
glendaviesnz Sep 22, 2023
3a2afce
Fix padding and move pagination
glendaviesnz Sep 22, 2023
f42cbc7
Fix pagination scroll to top
glendaviesnz Sep 22, 2023
42e8aa1
Reset pagination if filter changes
glendaviesnz Sep 22, 2023
a75cccf
Revert the update to paging scroll to top
glendaviesnz Sep 22, 2023
b6d5df8
Fix scrolling-to-top after page changes
kevin940726 Sep 22, 2023
cf60dac
Fix scrolling-to-top after filter changes
kevin940726 Sep 22, 2023
023e034
Scroll to top on category change
kevin940726 Sep 22, 2023
74188d4
Fix scroll-to-top on category change
kevin940726 Sep 22, 2023
d00e6f8
Derive pattern sync menu options
kevin940726 Sep 22, 2023
f9c7827
Update the translators comment
kevin940726 Sep 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Disable the sync filter options if the pattern source is not user
  • Loading branch information
glendaviesnz committed Sep 22, 2023
commit d4ec9c60be50a1a118699d91f902ec24c278e6b4
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { Icon } from '@wordpress/icons';
import { useState } from '@wordpress/element';

export const PATTERN_TYPES = {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: I'm not sure if we want to reuse the same constants in edit-site or patterns? That might not be trivial as the block-editor might not be able to depend on those packages. I wonder if tree-shaking helps here, but I doubt it since we have side effects in both packages 🤔 . c.c. @ramonjd if you have any feedback!

Copy link
Contributor

Choose a reason for hiding this comment

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

The plan when we added the new constants to the patterns package was to then tidy up the block editor to use the same constants, but it is the editor that currently depends on the patterns package rather than the block editor so not sure if this will be possible - it would be good to try and work out how all the pattern related constants can be centralised somehow.

Copy link
Member

Choose a reason for hiding this comment

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

That might not be trivial as the block-editor might not be able to depend on those packages.

Yeah, that's the reason I didn't touch these either. 😄

To be honest, my only motivation was to clean up the site editor package. There were some constants being used, others duplicated etc. I think it's okay to have some dupes across packages, but the site editor needed some spring cleaning IMO

synced: 'synced',
Expand Down Expand Up @@ -63,6 +64,31 @@ export function BlockPatternsSyncFilter( {
patternSyncFilter,
patternSourceFilter,
} ) {
const [ patternSyncMenuOptions, setPatternSyncMenuOptions ] =
useState( patternSyncOptions );

function handleSetSourceFilterChange( newSourceFilter ) {
setPatternSourceFilter( newSourceFilter );
// We need to disable the sync filter option if the source filter is not 'all' or 'user'
// otherwise applying them will just result in no patterns being shown.
if (
newSourceFilter !== 'all' &&
newSourceFilter !== PATTERN_TYPES.user
) {
setPatternSyncMenuOptions(
patternSyncOptions.map( ( item ) => {
if ( item.value !== 'all' ) {
return { ...item, disabled: true };
}
return item;
} )
);
setPatternSyncFilter( 'all' );
return;
}
setPatternSyncMenuOptions( patternSyncOptions );
}

return (
<>
<DropdownMenu
Expand Down Expand Up @@ -92,18 +118,18 @@ export function BlockPatternsSyncFilter( {
<MenuItemsChoice
choices={ patternSourceOptions }
onSelect={ ( value ) => {
handleSetSourceFilterChange( value );
onClose();
setPatternSourceFilter( value );
} }
value={ patternSourceFilter }
/>
</MenuGroup>
<MenuGroup label={ __( 'Type' ) }>
<MenuItemsChoice
choices={ patternSyncOptions }
choices={ patternSyncMenuOptions }
onSelect={ ( value ) => {
onClose();
setPatternSyncFilter( value );
onClose();
} }
value={ patternSyncFilter }
/>
Expand Down