From 338940a77d5b9152f276e5ec31db01b4ba2d7332 Mon Sep 17 00:00:00 2001 From: Ramon Date: Wed, 18 Sep 2024 15:23:46 +1000 Subject: [PATCH 01/52] DataViews Sidebar: Display item count on DataViews sidebar (#65223) This PR pulls across @Souptik2001's work from https://github.com/WordPress/gutenberg/pull/62028 and using useEntityRecords to get record counts. It also: - Adds a `navigationItemSuffix` prop to DataViewItem so that consumers can pass a suffix to the SidebarNavigationItem component. - Refactors custom count hook to include default dataviews that it doesn't affect other components Reduce RHS padding Co-authored-by: ramonjd Co-authored-by: Souptik2001 Co-authored-by: jameskoster Co-authored-by: ramonjd Co-authored-by: DaniGuardiola Co-authored-by: youknowriad Co-authored-by: ellatrix Co-authored-by: jasmussen Unlinked contributors: finitelydope, jarekmorawski. --- .../sidebar-dataviews/dataview-item.js | 2 + .../sidebar-dataviews/default-views.js | 46 ++++++++++++++++++- .../src/components/sidebar-dataviews/index.js | 9 +++- .../components/sidebar-dataviews/style.scss | 4 ++ 4 files changed, 58 insertions(+), 3 deletions(-) diff --git a/packages/edit-site/src/components/sidebar-dataviews/dataview-item.js b/packages/edit-site/src/components/sidebar-dataviews/dataview-item.js index 1e12d6706d81b..1a96fdc059143 100644 --- a/packages/edit-site/src/components/sidebar-dataviews/dataview-item.js +++ b/packages/edit-site/src/components/sidebar-dataviews/dataview-item.js @@ -27,6 +27,7 @@ export default function DataViewItem( { isActive, isCustom, suffix, + navigationItemSuffix, } ) { const { params: { postType }, @@ -55,6 +56,7 @@ export default function DataViewItem( { { title } diff --git a/packages/edit-site/src/components/sidebar-dataviews/default-views.js b/packages/edit-site/src/components/sidebar-dataviews/default-views.js index 658fa319e9c66..20f61e451b21f 100644 --- a/packages/edit-site/src/components/sidebar-dataviews/default-views.js +++ b/packages/edit-site/src/components/sidebar-dataviews/default-views.js @@ -13,7 +13,7 @@ import { notAllowed, } from '@wordpress/icons'; import { useSelect } from '@wordpress/data'; -import { store as coreStore } from '@wordpress/core-data'; +import { store as coreStore, useEntityRecords } from '@wordpress/core-data'; import { useMemo } from '@wordpress/element'; /** @@ -68,6 +68,50 @@ const DEFAULT_POST_BASE = { layout: defaultLayouts[ LAYOUT_LIST ].layout, }; +export function useDefaultViewsWithItemCounts( { postType } ) { + const defaultViews = useDefaultViews( { postType } ); + const { records, totalItems } = useEntityRecords( 'postType', postType, { + per_page: -1, + status: [ 'any', 'trash' ], + } ); + + return useMemo( () => { + if ( ! defaultViews ) { + return []; + } + + // If there are no records, return the default views with no counts. + if ( ! records ) { + return defaultViews; + } + + const counts = { + drafts: records.filter( ( record ) => record.status === 'draft' ) + .length, + future: records.filter( ( record ) => record.status === 'future' ) + .length, + pending: records.filter( ( record ) => record.status === 'pending' ) + .length, + private: records.filter( ( record ) => record.status === 'private' ) + .length, + published: records.filter( + ( record ) => record.status === 'publish' + ).length, + trash: records.filter( ( record ) => record.status === 'trash' ) + .length, + }; + + // All items excluding trashed items as per the default "all" status query. + counts.all = totalItems ? totalItems - counts.trash : 0; + + // Filter out views with > 0 item counts. + return defaultViews.map( ( _view ) => { + _view.count = counts[ _view.slug ]; + return _view; + } ); + }, [ defaultViews, records, totalItems ] ); +} + export function useDefaultViews( { postType } ) { const labels = useSelect( ( select ) => { diff --git a/packages/edit-site/src/components/sidebar-dataviews/index.js b/packages/edit-site/src/components/sidebar-dataviews/index.js index 86420c4eec1d1..3f7f5b965fce7 100644 --- a/packages/edit-site/src/components/sidebar-dataviews/index.js +++ b/packages/edit-site/src/components/sidebar-dataviews/index.js @@ -7,7 +7,7 @@ import { privateApis as routerPrivateApis } from '@wordpress/router'; /** * Internal dependencies */ -import { useDefaultViews } from './default-views'; +import { useDefaultViewsWithItemCounts } from './default-views'; import { unlock } from '../../lock-unlock'; import DataViewItem from './dataview-item'; import CustomDataViewsList from './custom-dataviews-list'; @@ -18,7 +18,9 @@ export default function DataViewsSidebarContent() { const { params: { postType, activeView = 'all', isCustom = 'false' }, } = useLocation(); - const defaultViews = useDefaultViews( { postType } ); + + const defaultViews = useDefaultViewsWithItemCounts( { postType } ); + if ( ! postType ) { return null; } @@ -34,6 +36,9 @@ export default function DataViewsSidebarContent() { slug={ dataview.slug } title={ dataview.title } icon={ dataview.icon } + navigationItemSuffix={ + { dataview.count } + } type={ dataview.view.type } isActive={ ! isCustomBoolean && diff --git a/packages/edit-site/src/components/sidebar-dataviews/style.scss b/packages/edit-site/src/components/sidebar-dataviews/style.scss index 14e6bf1d03fca..3473c8e20e1a4 100644 --- a/packages/edit-site/src/components/sidebar-dataviews/style.scss +++ b/packages/edit-site/src/components/sidebar-dataviews/style.scss @@ -15,6 +15,10 @@ min-width: initial; } + .edit-site-sidebar-navigation-item.with-suffix { + padding-right: $grid-unit-10; + } + &:hover, &:focus, &[aria-current] { From 5f77458225b0ce1d4e5fdb2b1113a374d8bed189 Mon Sep 17 00:00:00 2001 From: Madhu Dollu Date: Wed, 18 Sep 2024 13:09:52 +0530 Subject: [PATCH 02/52] fix the issue where block spacing control not shown when only one side is set (#65371) --- .../spacing-sizes-control/test/utils.js | 43 ++++++++----------- .../components/spacing-sizes-control/utils.js | 27 +++++++++--- 2 files changed, 40 insertions(+), 30 deletions(-) diff --git a/packages/block-editor/src/components/spacing-sizes-control/test/utils.js b/packages/block-editor/src/components/spacing-sizes-control/test/utils.js index 22191b4e1a8de..a8440bb5be8ca 100644 --- a/packages/block-editor/src/components/spacing-sizes-control/test/utils.js +++ b/packages/block-editor/src/components/spacing-sizes-control/test/utils.js @@ -378,41 +378,34 @@ describe( 'getInitialView', () => { VIEWS.custom ); } ); - } ); - - describe( 'Single side view', () => { - it( 'should return single side when only single side supported', () => { + it( 'should return custom view even if only single side supported', () => { expect( getInitialView( { top: '1em' }, [ 'top' ] ) ).toBe( - VIEWS.top + VIEWS.custom + ); + expect( getInitialView( { right: '1em' }, [ 'right' ] ) ).toBe( + VIEWS.custom + ); + expect( getInitialView( { bottom: '1em' }, [ 'bottom' ] ) ).toBe( + VIEWS.custom + ); + expect( getInitialView( { left: '1em' }, [ 'left' ] ) ).toBe( + VIEWS.custom ); } ); + } ); + describe( 'Single side view', () => { it( 'should return single side when only single side supported and no value defined', () => { expect( getInitialView( {}, [ 'top' ] ) ).toBe( VIEWS.top ); } ); - it( 'should return single side when only single side supported and all values defined', () => { + it( 'should return single side when only single side supported and has only axial sides', () => { expect( - getInitialView( - { top: '1em', right: '2em', bottom: '1em', left: '2em' }, - [ 'top' ] - ) + getInitialView( { top: '1em' }, [ 'horizontal', 'vertical' ] ) ).toBe( VIEWS.top ); - } ); - - it( 'should return single side view when only one side is supported', () => { - expect( getInitialView( { top: '1em' }, [ 'top' ] ) ).toBe( - VIEWS.top - ); - expect( getInitialView( { right: '1em' }, [ 'right' ] ) ).toBe( - VIEWS.right - ); - expect( getInitialView( { bottom: '1em' }, [ 'bottom' ] ) ).toBe( - VIEWS.bottom - ); - expect( getInitialView( { left: '1em' }, [ 'left' ] ) ).toBe( - VIEWS.left - ); + expect( + getInitialView( { left: '4em' }, [ 'horizontal', 'vertical' ] ) + ).toBe( VIEWS.left ); } ); } ); } ); diff --git a/packages/block-editor/src/components/spacing-sizes-control/utils.js b/packages/block-editor/src/components/spacing-sizes-control/utils.js index df2da0d93d060..046bee98761bf 100644 --- a/packages/block-editor/src/components/spacing-sizes-control/utils.js +++ b/packages/block-editor/src/components/spacing-sizes-control/utils.js @@ -363,11 +363,10 @@ export function getInitialView( values = {}, sides ) { top === bottom && left === right && ( !! top || !! left ); const hasNoValuesAndBalancedSides = ! sideValues.length && hasBalancedSidesSupport( sides ); - - // Only single side supported and no value defined. - if ( sides?.length === 1 ) { - return sides[ 0 ]; - } + const hasOnlyAxialSides = + sides?.includes( 'horizontal' ) && + sides?.includes( 'vertical' ) && + sides?.length === 2; if ( hasAxisSupport( sides ) && @@ -376,6 +375,24 @@ export function getInitialView( values = {}, sides ) { return VIEWS.axial; } + // Only axial sides are supported and single value defined. + // - Ensure the side returned is the first side that has a value. + if ( hasOnlyAxialSides && sideValues.length === 1 ) { + let side; + + Object.entries( values ).some( ( [ key, value ] ) => { + side = key; + return value !== undefined; + } ); + + return side; + } + + // Only single side supported and no value defined. + if ( sides?.length === 1 && ! sideValues.length ) { + return sides[ 0 ]; + } + // Default to the Custom (separated sides) view. return VIEWS.custom; } From b818be2eb208072b6b0a2d0fe63e9c7cef5c3cb5 Mon Sep 17 00:00:00 2001 From: Maggie Date: Wed, 18 Sep 2024 09:59:27 +0100 Subject: [PATCH 03/52] remove zoom out experiment (#65404) --- lib/experimental/editor-settings.php | 3 --- lib/experiments-page.php | 11 ----------- packages/editor/src/components/header/index.js | 5 +---- 3 files changed, 1 insertion(+), 18 deletions(-) diff --git a/lib/experimental/editor-settings.php b/lib/experimental/editor-settings.php index 919be2e6e34a4..126382f85a513 100644 --- a/lib/experimental/editor-settings.php +++ b/lib/experimental/editor-settings.php @@ -34,9 +34,6 @@ function gutenberg_enable_experiments() { if ( $gutenberg_experiments && array_key_exists( 'gutenberg-media-processing', $gutenberg_experiments ) ) { wp_add_inline_script( 'wp-block-editor', 'window.__experimentalMediaProcessing = true', 'before' ); } - if ( $gutenberg_experiments && array_key_exists( 'gutenberg-zoom-out-experiment', $gutenberg_experiments ) ) { - wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnableZoomOutExperiment = true', 'before' ); - } } add_action( 'admin_init', 'gutenberg_enable_experiments' ); diff --git a/lib/experiments-page.php b/lib/experiments-page.php index 5acd5f0f19236..27a54b920f4d5 100644 --- a/lib/experiments-page.php +++ b/lib/experiments-page.php @@ -175,17 +175,6 @@ function gutenberg_initialize_experiments_settings() { ) ); - add_settings_field( - 'gutenberg-zoom-out-experiment', - __( 'Zoom out experiments', 'gutenberg' ), - 'gutenberg_display_experiment_field', - 'gutenberg-experiments', - 'gutenberg_experiments_section', - array( - 'label' => __( 'Enable zoom out experiments; shows zoom out in the device preview and other zoom out experiments.', 'gutenberg' ), - 'id' => 'gutenberg-zoom-out-experiment', - ) - ); register_setting( 'gutenberg-experiments', 'gutenberg-experiments' diff --git a/packages/editor/src/components/header/index.js b/packages/editor/src/components/header/index.js index b1b8f2fc1ee32..8f9d130c8b717 100644 --- a/packages/editor/src/components/header/index.js +++ b/packages/editor/src/components/header/index.js @@ -48,9 +48,6 @@ function Header( { setEntitiesSavedStatesCallback, title, } ) { - const zoomOutExperimentEnabled = - window.__experimentalEnableZoomOutExperiment; - const isWideViewport = useViewportMatch( 'large' ); const isLargeViewport = useViewportMatch( 'medium' ); const isTooNarrowForDocumentBar = useMediaQuery( '(max-width: 403px)' ); @@ -146,7 +143,7 @@ function Header( { /> - { zoomOutExperimentEnabled && } + { ( isWideViewport || ! showIconLabels ) && ( From 98b8d415830fa9ebf7b4b0a2b95d65b9fd1e813a Mon Sep 17 00:00:00 2001 From: Vipul Gupta <55375170+vipul0425@users.noreply.github.com> Date: Wed, 18 Sep 2024 14:39:59 +0530 Subject: [PATCH 04/52] Fix: Button Replace remaining 40px default size violations [Block Editor 4] (#65257) * fix: Inserter lightbox's button to use 40px default size. * fix: Pattern Explorer Sidebar's button to use 40px default size. * fix: Block Pattern's button to use 40px default size. * fix: Media Preview's button to use 40px default size. * fix: Media Tab's button to use 40px default size. * fix: Quick Inserter's button to use 40px default size. Co-authored-by: vipul0425 Co-authored-by: mirka <0mirka00@git.wordpress.org> --- .../block-editor/src/components/inserter-listbox/item.js | 6 +----- .../block-patterns-explorer/pattern-explorer-sidebar.js | 3 +-- .../src/components/inserter/block-patterns-tab/index.js | 3 +-- .../src/components/inserter/media-tab/media-preview.js | 6 ++---- .../src/components/inserter/media-tab/media-tab.js | 3 +-- .../block-editor/src/components/inserter/quick-inserter.js | 3 +-- packages/block-editor/src/components/inserter/style.scss | 1 - 7 files changed, 7 insertions(+), 18 deletions(-) diff --git a/packages/block-editor/src/components/inserter-listbox/item.js b/packages/block-editor/src/components/inserter-listbox/item.js index 69c316bdbbcce..06c266d793d2f 100644 --- a/packages/block-editor/src/components/inserter-listbox/item.js +++ b/packages/block-editor/src/components/inserter-listbox/item.js @@ -33,11 +33,7 @@ function InserterListboxItem( return children( propsWithTabIndex ); } return ( - ); diff --git a/packages/block-editor/src/components/inserter/block-patterns-explorer/pattern-explorer-sidebar.js b/packages/block-editor/src/components/inserter/block-patterns-explorer/pattern-explorer-sidebar.js index 95de775e48eef..d258c24da10cf 100644 --- a/packages/block-editor/src/components/inserter/block-patterns-explorer/pattern-explorer-sidebar.js +++ b/packages/block-editor/src/components/inserter/block-patterns-explorer/pattern-explorer-sidebar.js @@ -15,8 +15,7 @@ function PatternCategoriesList( { { patternCategories.map( ( { name, label } ) => { return (