-
Notifications
You must be signed in to change notification settings - Fork 4.7k
DataViews: Add sync filter in patterns page #57532
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,7 +9,7 @@ import { | |||||||||||||||||||||||||
| Flex, | ||||||||||||||||||||||||||
| } from '@wordpress/components'; | ||||||||||||||||||||||||||
| import { getQueryArgs } from '@wordpress/url'; | ||||||||||||||||||||||||||
| import { __ } from '@wordpress/i18n'; | ||||||||||||||||||||||||||
| import { __, _x } from '@wordpress/i18n'; | ||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||
| useState, | ||||||||||||||||||||||||||
| useMemo, | ||||||||||||||||||||||||||
|
|
@@ -46,6 +46,8 @@ import { | |||||||||||||||||||||||||
| TEMPLATE_PART_POST_TYPE, | ||||||||||||||||||||||||||
| PATTERN_SYNC_TYPES, | ||||||||||||||||||||||||||
| PATTERN_DEFAULT_CATEGORY, | ||||||||||||||||||||||||||
| ENUMERATION_TYPE, | ||||||||||||||||||||||||||
| OPERATOR_IN, | ||||||||||||||||||||||||||
| } from '../../utils/constants'; | ||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||
| exportJSONaction, | ||||||||||||||||||||||||||
|
|
@@ -76,13 +78,31 @@ const DEFAULT_VIEW = { | |||||||||||||||||||||||||
| search: '', | ||||||||||||||||||||||||||
| page: 1, | ||||||||||||||||||||||||||
| perPage: 20, | ||||||||||||||||||||||||||
| hiddenFields: [], | ||||||||||||||||||||||||||
| hiddenFields: [ 'sync-status' ], | ||||||||||||||||||||||||||
| layout: { | ||||||||||||||||||||||||||
| ...defaultConfigPerViewType[ LAYOUT_GRID ], | ||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||
| filters: [], | ||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const SYNC_FILTERS = [ | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| value: PATTERN_SYNC_TYPES.full, | ||||||||||||||||||||||||||
| label: _x( 'Synced', 'Option that shows all synchronized patterns' ), | ||||||||||||||||||||||||||
| description: __( 'Patterns that are kept in sync across the site.' ), | ||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| value: PATTERN_SYNC_TYPES.unsynced, | ||||||||||||||||||||||||||
| label: _x( | ||||||||||||||||||||||||||
| 'Not synced', | ||||||||||||||||||||||||||
| 'Option that shows all patterns that are not synchronized' | ||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||
| description: __( | ||||||||||||||||||||||||||
| 'Patterns that can be changed freely without affecting the site.' | ||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| function Preview( { item, viewType } ) { | ||||||||||||||||||||||||||
| const descriptionId = useId(); | ||||||||||||||||||||||||||
| const isUserPattern = item.type === PATTERN_TYPES.user; | ||||||||||||||||||||||||||
|
|
@@ -204,27 +224,25 @@ export default function DataviewsPatterns() { | |||||||||||||||||||||||||
| const isUncategorizedThemePatterns = | ||||||||||||||||||||||||||
| type === PATTERN_TYPES.theme && categoryId === 'uncategorized'; | ||||||||||||||||||||||||||
| const previousCategoryId = usePrevious( categoryId ); | ||||||||||||||||||||||||||
| const viewSyncStatus = view.filters?.find( | ||||||||||||||||||||||||||
| ( { field } ) => field === 'sync-status' | ||||||||||||||||||||||||||
| )?.value; | ||||||||||||||||||||||||||
| const { patterns, isResolving } = usePatterns( | ||||||||||||||||||||||||||
| type, | ||||||||||||||||||||||||||
| isUncategorizedThemePatterns ? '' : categoryId, | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| search: view.search, | ||||||||||||||||||||||||||
| // syncStatus: | ||||||||||||||||||||||||||
| // deferredSyncedFilter === 'all' | ||||||||||||||||||||||||||
| // ? undefined | ||||||||||||||||||||||||||
| // : deferredSyncedFilter, | ||||||||||||||||||||||||||
| syncStatus: viewSyncStatus, | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||
| const fields = useMemo( | ||||||||||||||||||||||||||
| () => [ | ||||||||||||||||||||||||||
| const fields = useMemo( () => { | ||||||||||||||||||||||||||
| const _fields = [ | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| header: __( 'Preview' ), | ||||||||||||||||||||||||||
| id: 'preview', | ||||||||||||||||||||||||||
| render: ( { item } ) => ( | ||||||||||||||||||||||||||
| <Preview item={ item } viewType={ view.type } /> | ||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||
| minWidth: 120, | ||||||||||||||||||||||||||
| maxWidth: 120, | ||||||||||||||||||||||||||
| enableSorting: false, | ||||||||||||||||||||||||||
| enableHiding: false, | ||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||
|
|
@@ -235,12 +253,36 @@ export default function DataviewsPatterns() { | |||||||||||||||||||||||||
| render: ( { item } ) => ( | ||||||||||||||||||||||||||
| <Title item={ item } categoryId={ categoryId } /> | ||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||
| maxWidth: 400, | ||||||||||||||||||||||||||
| enableHiding: false, | ||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||
| [ view.type, categoryId ] | ||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||
| if ( type === PATTERN_TYPES.theme ) { | ||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do I trigger a situation in which the category type is
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To test
I see this new category is listed in the patterns page, though it works as any other: Gravacao.do.ecra.2024-01-04.as.14.27.03.movShould I do anything differently?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is for later, but making Gravacao.do.ecra.2024-01-04.as.14.32.12.movThough, this makes me think that I wouldn't want the
What happens when the user visits a user-provided category and then a theme provided category? The consequences are that 1) visual jumps in the layout and 2) the user preferences (hiddenFields and filter statuses) are cleared once they visit a user-provided category. It sounds it's to always render the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Did you encountered something unexpected that is different from the old patterns page?
We discussed this a bit with Riad here and for now we reset the whole view. It does resemble the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't know, because I don't know how to trigger a situation where type is not From what I gathered, my suggestion here is to always render the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Taking a look. What's confusing is there are two One is used in the inserter for inserter items: gutenberg/packages/block-editor/src/components/inserter/block-patterns-tab/utils.js Lines 7 to 14 in 6f61d8b
One is used by most of the other patterns code: gutenberg/packages/patterns/src/constants.js Lines 6 to 9 in 6f61d8b
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It seems you're using the second variable where
Ignore that, my assumption was wrong. This definitely needs some improvement!
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I've started looking into improving the code quality. First PR here - Rename patternBlock to patternPost I've made another PR that renames the inserter constants to better indicate that they're for inserter items - Code Quality: Improve inserter pattern constants. I think the goal should be to have a single normalized pattern item data structure (even if the data is sourced from different places) with consistent values, then hopefully we'll be able to tidy up the constants.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I have a full understanding of what the code is doing now. There's a I'll follow up with another PR that improves this, but it'll be next week.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice, thanks for looking into this, Dan. |
||||||||||||||||||||||||||
| _fields.push( { | ||||||||||||||||||||||||||
| header: __( 'Sync Status' ), | ||||||||||||||||||||||||||
| id: 'sync-status', | ||||||||||||||||||||||||||
| render: ( { item } ) => { | ||||||||||||||||||||||||||
| // User patterns can have their sync statuses checked directly. | ||||||||||||||||||||||||||
| // Non-user patterns are all unsynced for the time being. | ||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||
| SYNC_FILTERS.find( | ||||||||||||||||||||||||||
| ( { value } ) => value === item.syncStatus | ||||||||||||||||||||||||||
| )?.label || | ||||||||||||||||||||||||||
| SYNC_FILTERS.find( | ||||||||||||||||||||||||||
| ( { value } ) => | ||||||||||||||||||||||||||
| value === PATTERN_SYNC_TYPES.unsynced | ||||||||||||||||||||||||||
| ).label | ||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||
| type: ENUMERATION_TYPE, | ||||||||||||||||||||||||||
| elements: SYNC_FILTERS, | ||||||||||||||||||||||||||
| filterBy: { | ||||||||||||||||||||||||||
| operators: [ OPERATOR_IN ], | ||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||
| enableSorting: false, | ||||||||||||||||||||||||||
| } ); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| return _fields; | ||||||||||||||||||||||||||
| }, [ view.type, categoryId, type ] ); | ||||||||||||||||||||||||||
| // Reset the page number when the category changes. | ||||||||||||||||||||||||||
| useEffect( () => { | ||||||||||||||||||||||||||
| if ( previousCategoryId !== categoryId ) { | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||

Uh oh!
There was an error while loading. Please reload this page.