From eab75c50d1b1c66e6d68014cdcae975161b72535 Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Tue, 13 Jan 2026 10:24:59 +0200 Subject: [PATCH 01/19] DataViews: Add overlay when loading to prevent flickering --- .../dataviews-bulk-actions/index.tsx | 4 ++- .../dataviews-layouts/table/index.tsx | 35 ++++++++++++++++--- .../dataviews-layouts/table/style.scss | 21 +++++++++++ .../src/components/post-list/index.js | 5 ++- 4 files changed, 58 insertions(+), 7 deletions(-) diff --git a/packages/dataviews/src/components/dataviews-bulk-actions/index.tsx b/packages/dataviews/src/components/dataviews-bulk-actions/index.tsx index 57c785b77d0ee3..14e8020842b401 100644 --- a/packages/dataviews/src/components/dataviews-bulk-actions/index.tsx +++ b/packages/dataviews/src/components/dataviews-bulk-actions/index.tsx @@ -118,7 +118,9 @@ export function BulkSelectionCheckbox< Item >( { selection.includes( getItemId( item ) ) && selectableItems.includes( item ) ); - const areAllSelected = selectedItems.length === selectableItems.length; + const areAllSelected = + !! selectedItems.length && + selectedItems.length === selectableItems.length; return ( ( { const headerMenuToFocusRef = useRef< HTMLButtonElement >( undefined ); const [ nextHeaderMenuToFocus, setNextHeaderMenuToFocus ] = useState< HTMLButtonElement >(); - const hasBulkActions = useSomeItemHasAPossibleBulkAction( actions, data ); const [ contextMenuAnchor, setContextMenuAnchor ] = useState< { getBoundingClientRect: () => DOMRect; } | null >( null ); @@ -312,6 +311,24 @@ function ViewTable< Item >( { enabled: !! actions?.length, } ); + // Preserve previous loaded data to show them blurred and + // avoid flickering. + const previousDataRef = useRef< Item[] >( data ); + useEffect( () => { + if ( ! isLoading ) { + previousDataRef.current = data; + } + }, [ data, isLoading ] ); + const displayData = + isLoading && previousDataRef.current?.length + ? previousDataRef.current + : data; + + const hasBulkActions = useSomeItemHasAPossibleBulkAction( + actions, + displayData + ); + if ( nextHeaderMenuToFocus ) { // If we need to force focus, we short-circuit rendering here // to prevent any additional work while we handle that. @@ -351,7 +368,7 @@ function ViewTable< Item >( { } ); }; - const hasData = !! data?.length; + const hasData = !! displayData?.length; const titleField = fields.find( ( field ) => field.id === view.titleField ); const mediaField = fields.find( ( field ) => field.id === view.mediaField ); @@ -362,7 +379,9 @@ function ViewTable< Item >( { const groupField = view.groupBy?.field ? fields.find( ( f ) => f.id === view.groupBy?.field ) : null; - const dataByGroup = groupField ? getDataByGroup( data, groupField ) : null; + const dataByGroup = groupField + ? getDataByGroup( displayData, groupField ) + : null; const { showTitle = true, showMedia = true, showDescription = true } = view; const hasPrimaryColumn = ( titleField && showTitle ) || @@ -383,6 +402,9 @@ function ViewTable< Item >( { const isInfiniteScroll = view.infiniteScrollEnabled && ! dataByGroup; const isRtl = isRTL(); + // If new data are loading but previous loaded data were empty, + // keep showing just the spinner. + const showOverlay = ! isInfiniteScroll && isLoading && hasData; return ( <> ( { view.layout.density ), 'has-bulk-actions': hasBulkActions, + 'has-overlay': showOverlay, } ) } aria-busy={ isLoading } aria-describedby={ tableNoticeId } role={ isInfiniteScroll ? 'feed' : undefined } + // @ts-ignore Reason: inert is a recent HTML attribute + inert={ showOverlay ? 'true' : undefined } > { hasBulkActions && ( @@ -599,7 +624,7 @@ function ViewTable< Item >( { ) : ( { hasData && - data.map( ( item, index ) => ( + displayData.map( ( item, index ) => ( ( { ) : ( empty ) ) } - { hasData && isLoading && ( + { isInfiniteScroll && hasData && isLoading && (

diff --git a/packages/dataviews/src/components/dataviews-layouts/table/style.scss b/packages/dataviews/src/components/dataviews-layouts/table/style.scss index 65303746c6fa7f..d41a40d28de638 100644 --- a/packages/dataviews/src/components/dataviews-layouts/table/style.scss +++ b/packages/dataviews/src/components/dataviews-layouts/table/style.scss @@ -309,3 +309,24 @@ .dataviews-view-table col[class^="dataviews-view-table__col-"]:not(.dataviews-view-table__col-first-data):not(.dataviews-view-table__col-expand) { width: 1%; } + +/* Loading overlay on existing rows */ +.dataviews-view-table.has-overlay { + tbody { + pointer-events: none; + position: relative; + } + + tbody td { + position: relative; + + &::after { + content: ""; + position: absolute; + inset: 0; + z-index: 1; + backdrop-filter: blur(2px); + pointer-events: none; + } + } +} diff --git a/packages/edit-site/src/components/post-list/index.js b/packages/edit-site/src/components/post-list/index.js index 6437609b859c45..c221500fe3aed9 100644 --- a/packages/edit-site/src/components/post-list/index.js +++ b/packages/edit-site/src/components/post-list/index.js @@ -170,6 +170,7 @@ export default function PostList( { postType } ) { isResolving: isLoadingData, totalItems, totalPages, + hasResolved, } = useEntityRecordsWithPermissions( 'postType', postType, queryArgs ); const postIds = useMemo( @@ -302,7 +303,9 @@ export default function PostList( { postType } ) { fields={ fields } actions={ actions } data={ data || EMPTY_ARRAY } - isLoading={ isLoadingData || isLoadingNotesCount } + isLoading={ + isLoadingData || isLoadingNotesCount || ! hasResolved + } view={ view } onChangeView={ onChangeView } selection={ selection } From 65a9af11e0500f81906b9e7b5359f783e866554f Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Tue, 13 Jan 2026 10:46:40 +0200 Subject: [PATCH 02/19] changelog entry --- packages/dataviews/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/dataviews/CHANGELOG.md b/packages/dataviews/CHANGELOG.md index c8a0ec4436a12e..60697c350c8a2b 100644 --- a/packages/dataviews/CHANGELOG.md +++ b/packages/dataviews/CHANGELOG.md @@ -100,6 +100,7 @@ - Fix sticky footer in DataViews grid view. [#73661](https://github.com/WordPress/gutenberg/pull/73661) - DataViews: Apply primary style to first column if there is no title field. [#73729](https://github.com/WordPress/gutenberg/pull/73729) - DataViews: Combined field alignment in table layout. [#73908](https://github.com/WordPress/gutenberg/pull/73908) +- DataViews: Add overlay to `table` layout when loading to prevent flickering. [#74572](https://github.com/WordPress/gutenberg/pull/74572) - DataViews: Fix table row multiselection in Firefox [#73945](https://github.com/WordPress/gutenberg/pull/73945) - DataViews: `filterSortAndPaginate()` will ignore sorting on non-sortable fields [#73950](https://github.com/WordPress/gutenberg/pull/73950) - DataViews: Fix locked fields order when toggling visibility in properties section. [#74326](https://github.com/WordPress/gutenberg/pull/74326) From fb003ea92b2480f1c42e1e0b55d237c3291b1d55 Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Thu, 15 Jan 2026 10:52:52 +0200 Subject: [PATCH 03/19] use pulse animaton --- .../dataviews-bulk-actions/index.tsx | 4 +--- .../dataviews-layouts/table/index.tsx | 12 +++++----- .../dataviews-layouts/table/style.scss | 24 +++++++++++++++---- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/packages/dataviews/src/components/dataviews-bulk-actions/index.tsx b/packages/dataviews/src/components/dataviews-bulk-actions/index.tsx index 14e8020842b401..57c785b77d0ee3 100644 --- a/packages/dataviews/src/components/dataviews-bulk-actions/index.tsx +++ b/packages/dataviews/src/components/dataviews-bulk-actions/index.tsx @@ -118,9 +118,7 @@ export function BulkSelectionCheckbox< Item >( { selection.includes( getItemId( item ) ) && selectableItems.includes( item ) ); - const areAllSelected = - !! selectedItems.length && - selectedItems.length === selectableItems.length; + const areAllSelected = selectedItems.length === selectableItems.length; return ( ( { enabled: !! actions?.length, } ); - // Preserve previous loaded data to show them blurred and - // avoid flickering. + // Preserve previous loaded data to apply loading pulse animation + // while refreshing to avoid flickering. const previousDataRef = useRef< Item[] >( data ); useEffect( () => { if ( ! isLoading ) { @@ -404,7 +404,7 @@ function ViewTable< Item >( { // If new data are loading but previous loaded data were empty, // keep showing just the spinner. - const showOverlay = ! isInfiniteScroll && isLoading && hasData; + const isRefreshing = ! isInfiniteScroll && isLoading && hasData; return ( <>
( { view.layout.density ), 'has-bulk-actions': hasBulkActions, - 'has-overlay': showOverlay, + 'is-refreshing': isRefreshing, } ) } aria-busy={ isLoading } aria-describedby={ tableNoticeId } role={ isInfiniteScroll ? 'feed' : undefined } // @ts-ignore Reason: inert is a recent HTML attribute - inert={ showOverlay ? 'true' : undefined } + inert={ isRefreshing ? 'true' : undefined } > { hasBulkActions && ( @@ -467,7 +467,7 @@ function ViewTable< Item >( { diff --git a/packages/dataviews/src/components/dataviews-layouts/table/style.scss b/packages/dataviews/src/components/dataviews-layouts/table/style.scss index d41a40d28de638..b7350ae44d02a2 100644 --- a/packages/dataviews/src/components/dataviews-layouts/table/style.scss +++ b/packages/dataviews/src/components/dataviews-layouts/table/style.scss @@ -310,23 +310,37 @@ width: 1%; } -/* Loading overlay on existing rows */ -.dataviews-view-table.has-overlay { +@keyframes loadingpulse { + 0% { + background-color: $gray-300; + } + 50% { + background-color: $gray-100; + } + 100% { + background-color: $gray-300; + } +} + +@mixin skeleton() { + animation: loadingpulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite; +} + +.dataviews-view-table.is-refreshing { tbody { pointer-events: none; position: relative; } - tbody td { + tbody td > *:first-child { position: relative; &::after { content: ""; position: absolute; inset: 0; - z-index: 1; - backdrop-filter: blur(2px); pointer-events: none; + @include skeleton(); } } } From 590b60be6592d4caea2940b00f421d29d1266c02 Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Thu, 15 Jan 2026 10:56:23 +0200 Subject: [PATCH 04/19] update changelog --- packages/dataviews/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/dataviews/CHANGELOG.md b/packages/dataviews/CHANGELOG.md index 60697c350c8a2b..10c5b4b54d5d64 100644 --- a/packages/dataviews/CHANGELOG.md +++ b/packages/dataviews/CHANGELOG.md @@ -100,7 +100,7 @@ - Fix sticky footer in DataViews grid view. [#73661](https://github.com/WordPress/gutenberg/pull/73661) - DataViews: Apply primary style to first column if there is no title field. [#73729](https://github.com/WordPress/gutenberg/pull/73729) - DataViews: Combined field alignment in table layout. [#73908](https://github.com/WordPress/gutenberg/pull/73908) -- DataViews: Add overlay to `table` layout when loading to prevent flickering. [#74572](https://github.com/WordPress/gutenberg/pull/74572) +- DataViews: Apply loading pulse animation while refreshing to avoid flickering. [#74572](https://github.com/WordPress/gutenberg/pull/74572) - DataViews: Fix table row multiselection in Firefox [#73945](https://github.com/WordPress/gutenberg/pull/73945) - DataViews: `filterSortAndPaginate()` will ignore sorting on non-sortable fields [#73950](https://github.com/WordPress/gutenberg/pull/73950) - DataViews: Fix locked fields order when toggling visibility in properties section. [#74326](https://github.com/WordPress/gutenberg/pull/74326) From 0b96de3f5bed961e17dc662bc5c0e876ac6c491f Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Thu, 15 Jan 2026 14:44:08 +0200 Subject: [PATCH 05/19] update inset --- .../components/dataviews-layouts/table/style.scss | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/packages/dataviews/src/components/dataviews-layouts/table/style.scss b/packages/dataviews/src/components/dataviews-layouts/table/style.scss index b7350ae44d02a2..d84e8619ee0e30 100644 --- a/packages/dataviews/src/components/dataviews-layouts/table/style.scss +++ b/packages/dataviews/src/components/dataviews-layouts/table/style.scss @@ -311,14 +311,8 @@ } @keyframes loadingpulse { - 0% { - background-color: $gray-300; - } 50% { - background-color: $gray-100; - } - 100% { - background-color: $gray-300; + opacity: 0.5; } } @@ -334,12 +328,15 @@ tbody td > *:first-child { position: relative; + visibility: hidden; &::after { content: ""; position: absolute; - inset: 0; + background-color: $gray-300; + inset: 4px 0; pointer-events: none; + visibility: visible; @include skeleton(); } } From be46510d4536a7e1cd20c2744edcec83621d8bf2 Mon Sep 17 00:00:00 2001 From: James Koster Date: Fri, 16 Jan 2026 18:04:31 +0000 Subject: [PATCH 06/19] Style adjustments --- .../dataviews-layouts/table/style.scss | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/dataviews/src/components/dataviews-layouts/table/style.scss b/packages/dataviews/src/components/dataviews-layouts/table/style.scss index d84e8619ee0e30..0bc78c119efa72 100644 --- a/packages/dataviews/src/components/dataviews-layouts/table/style.scss +++ b/packages/dataviews/src/components/dataviews-layouts/table/style.scss @@ -334,10 +334,27 @@ content: ""; position: absolute; background-color: $gray-300; - inset: 4px 0; + inset: 0; + height: $grid-unit-10; + margin: auto 0; + border-radius: var(--wpds-border-radius-surface-sm); pointer-events: none; visibility: visible; @include skeleton(); + max-width: 320px; + } + } + + tbody tr:nth-child(even) td > *:first-child { + &::after { + max-width: 480px; + } + } + + tbody td.dataviews-view-table__checkbox-column > *:first-child { + &::after { + width: $grid-unit-20; + height: $grid-unit-20; } } } From 377e043fcf5edd896cd4e3c1cc8843de5b872709 Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Mon, 2 Feb 2026 16:21:52 +0200 Subject: [PATCH 07/19] linter --- .../dataviews/src/components/dataviews-layouts/table/style.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/dataviews/src/components/dataviews-layouts/table/style.scss b/packages/dataviews/src/components/dataviews-layouts/table/style.scss index 0bc78c119efa72..9f2f77ec8dbb8c 100644 --- a/packages/dataviews/src/components/dataviews-layouts/table/style.scss +++ b/packages/dataviews/src/components/dataviews-layouts/table/style.scss @@ -337,7 +337,7 @@ inset: 0; height: $grid-unit-10; margin: auto 0; - border-radius: var(--wpds-border-radius-surface-sm); + border-radius: var(--wpds-border-radius-sm); pointer-events: none; visibility: visible; @include skeleton(); From ba2c3b109dcbf02751adb05ac7732f7cad81f189 Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Tue, 3 Feb 2026 09:31:04 +0200 Subject: [PATCH 08/19] hide table when no results or when showing loading spinner --- .../dataviews-layouts/table/index.tsx | 574 ++++++++++-------- 1 file changed, 314 insertions(+), 260 deletions(-) diff --git a/packages/dataviews/src/components/dataviews-layouts/table/index.tsx b/packages/dataviews/src/components/dataviews-layouts/table/index.tsx index 6beb062258c544..5208155c6ec170 100644 --- a/packages/dataviews/src/components/dataviews-layouts/table/index.tsx +++ b/packages/dataviews/src/components/dataviews-layouts/table/index.tsx @@ -405,281 +405,335 @@ function ViewTable< Item >( { // If new data are loading but previous loaded data were empty, // keep showing just the spinner. const isRefreshing = ! isInfiniteScroll && isLoading && hasData; + const noResults = ! hasData && ! isLoading; + // Determine if we should show loading spinner. Infinite scroll has + // different logic and spinner. + const showLoadingSpinner = ! hasData && isLoading; return ( <> -
- - { hasBulkActions && ( - - ) } - { hasPrimaryColumn && ( - - ) } - { columns.map( ( column, index ) => ( - - ) ) } - { !! actions?.length && ( - - ) } - - { contextMenuAnchor && ( - setContextMenuAnchor( null ) } - placement="bottom-start" + { ! noResults && ! showLoadingSpinner && ( + <> +
- - - ) } - - - { hasBulkActions && ( - + ) } + { hasPrimaryColumn && ( + + ) } + { columns.map( ( column, index ) => ( + - + ) ) } + { !! actions?.length && ( + + ) } + + { contextMenuAnchor && ( + setContextMenuAnchor( null ) } + placement="bottom-start" + > + + ) } - { hasPrimaryColumn && ( - + { hasBulkActions && ( + ) } - - ) } - { columns.map( ( column, index ) => { - // Explicit picks the supported styles. - const { width, maxWidth, minWidth, align } = - view.layout?.styles?.[ column ] ?? {}; - const canInsertOrMove = - view.layout?.enableMoving ?? true; - return ( - - ); - } ) } - { !! actions?.length && ( - ) } - > - - { __( 'Actions' ) } - - - ) } - - - { /* Render grouped data if groupBy is specified */ } - { hasData && groupField && dataByGroup ? ( - Array.from( dataByGroup.entries() ).map( - ( [ groupName, groupItems ] ) => ( - - - + ); + } ) } + { !! actions?.length && ( + - { groupItems.map( ( item, index ) => ( - - ) ) } + + { __( 'Actions' ) } + + + ) } + + + { /* Render grouped data if groupBy is specified */ } + { hasData && groupField && dataByGroup ? ( + Array.from( dataByGroup.entries() ).map( + ( [ groupName, groupItems ] ) => ( + + + + + { groupItems.map( ( item, index ) => ( + + ) ) } + + ) + ) + ) : ( + + { hasData && + displayData.map( ( item, index ) => ( + + ) ) } - ) - ) - ) : ( - - { hasData && - displayData.map( ( item, index ) => ( - - ) ) } - - ) } -
- + { hasBulkActions && ( +
- { titleField && ( - +
+ > + + - - + { titleField && ( + + ) } +
{ + // Explicit picks the supported styles. + const { width, maxWidth, minWidth, align } = + view.layout?.styles?.[ column ] ?? {}; + const canInsertOrMove = + view.layout?.enableMoving ?? true; + return ( + + + - { view.groupBy?.showLabel === false - ? groupName - : sprintf( - // translators: 1: The label of the field e.g. "Date". 2: The value of the field, e.g.: "May 2022". - __( '%1$s: %2$s' ), - groupField.label, - groupName - ) } - -
+ { view.groupBy?.showLabel === + false + ? groupName + : sprintf( + // translators: 1: The label of the field e.g. "Date". 2: The value of the field, e.g.: "May 2022". + __( '%1$s: %2$s' ), + groupField.label, + groupName + ) } +
-
- { ! hasData && - ( isLoading ? ( + ) } + + { isInfiniteScroll && hasData && isLoading && ( +
+

+ +

+
+ ) } + + ) } + { ( showLoadingSpinner || noResults ) && ( +
+ { showLoadingSpinner ? (

) : ( empty - ) ) } - { isInfiniteScroll && hasData && isLoading && ( -

- -

- ) } -
+ ) } +
+ ) } ); } From 05d14291a6c322bdfad2f9f9d2d43a713a50584a Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Mon, 9 Feb 2026 11:20:27 +0200 Subject: [PATCH 09/19] try progress bar --- packages/dataviews/CHANGELOG.md | 2 +- .../dataviews-layouts/grid/composite-grid.tsx | 4 ++ .../dataviews-layouts/grid/index.tsx | 38 +++++------- .../dataviews-layouts/grid/style.scss | 5 ++ .../dataviews-layouts/list/index.tsx | 62 +++++++++---------- .../dataviews-layouts/list/style.scss | 5 ++ .../dataviews-layouts/table/index.tsx | 42 +++---------- .../dataviews-layouts/table/style.scss | 45 +------------- .../utils/use-display-data.ts | 19 ++++++ packages/dataviews/src/dataviews/index.tsx | 4 ++ packages/dataviews/src/dataviews/style.scss | 12 ++++ 11 files changed, 108 insertions(+), 130 deletions(-) create mode 100644 packages/dataviews/src/components/dataviews-layouts/utils/use-display-data.ts diff --git a/packages/dataviews/CHANGELOG.md b/packages/dataviews/CHANGELOG.md index 10c5b4b54d5d64..e1cd99c92bad18 100644 --- a/packages/dataviews/CHANGELOG.md +++ b/packages/dataviews/CHANGELOG.md @@ -27,6 +27,7 @@ - DataForm: Fix text selection in panel layout summary rows by replacing `::after` overlay with accessible card pattern. [#75565](https://github.com/WordPress/gutenberg/pull/75565) - DataViews: Improve styling for filters when long values are in use. [#75369](https://github.com/WordPress/gutenberg/pull/75369) - DataForm: Fix label case for regular layout. [#75292](https://github.com/WordPress/gutenberg/pull/75292) +- DataViews: Apply loading pulse animation while refreshing to avoid flickering. [#74572](https://github.com/WordPress/gutenberg/pull/74572) - DataViews: Add title attribute in grid item title field. [#75085](https://github.com/WordPress/gutenberg/pull/75085) - DataViews: Fix title truncation in list layout. [#75063](https://github.com/WordPress/gutenberg/pull/75063) - DataViews: Fix fields async validation. [#74948](https://github.com/WordPress/gutenberg/pull/74948) @@ -100,7 +101,6 @@ - Fix sticky footer in DataViews grid view. [#73661](https://github.com/WordPress/gutenberg/pull/73661) - DataViews: Apply primary style to first column if there is no title field. [#73729](https://github.com/WordPress/gutenberg/pull/73729) - DataViews: Combined field alignment in table layout. [#73908](https://github.com/WordPress/gutenberg/pull/73908) -- DataViews: Apply loading pulse animation while refreshing to avoid flickering. [#74572](https://github.com/WordPress/gutenberg/pull/74572) - DataViews: Fix table row multiselection in Firefox [#73945](https://github.com/WordPress/gutenberg/pull/73945) - DataViews: `filterSortAndPaginate()` will ignore sorting on non-sortable fields [#73950](https://github.com/WordPress/gutenberg/pull/73950) - DataViews: Fix locked fields order when toggling visibility in properties section. [#74326](https://github.com/WordPress/gutenberg/pull/74326) diff --git a/packages/dataviews/src/components/dataviews-layouts/grid/composite-grid.tsx b/packages/dataviews/src/components/dataviews-layouts/grid/composite-grid.tsx index d25eb948e6da72..da872b590582c9 100644 --- a/packages/dataviews/src/components/dataviews-layouts/grid/composite-grid.tsx +++ b/packages/dataviews/src/components/dataviews-layouts/grid/composite-grid.tsx @@ -293,6 +293,7 @@ interface CompositeGridProps< Item > { data: Item[]; isInfiniteScroll: boolean; className?: string; + inert?: string; isLoading?: boolean; view: ViewGridType; fields: NormalizedField< Item >[]; @@ -313,6 +314,7 @@ export default function CompositeGrid< Item >( { data, isInfiniteScroll, className, + inert, isLoading, view, fields, @@ -375,6 +377,8 @@ export default function CompositeGrid< Item >( { aria-busy={ isLoading } aria-rowcount={ isInfiniteScroll ? undefined : totalRows } ref={ resizeObserverRef } + // @ts-ignore + inert={ inert } > { chunk( data, gridColumns ).map( ( row, i ) => ( ( { @@ -32,14 +33,22 @@ function ViewGrid< Item >( { className, empty, }: ViewGridProps< Item > ) { - const hasData = !! data?.length; + const displayData = useDisplayData( data, isLoading ); + + const hasData = !! displayData?.length; const groupField = view.groupBy?.field ? fields.find( ( f ) => f.id === view.groupBy?.field ) : null; - const dataByGroup = groupField ? getDataByGroup( data, groupField ) : null; + const dataByGroup = groupField + ? getDataByGroup( displayData, groupField ) + : null; const isInfiniteScroll = view.infiniteScrollEnabled && ! dataByGroup; + const noResults = ! hasData && ! isLoading; + const showGrid = hasData || ( isLoading && isInfiniteScroll ); + const isRefreshing = ! isInfiniteScroll && isLoading && hasData; const gridProps = { - className, + className: clsx( className, { 'is-refreshing': isRefreshing } ), + inert: isRefreshing ? 'true' : undefined, isLoading, view, fields, @@ -87,34 +96,21 @@ function ViewGrid< Item >( { } { // Render a single grid with all data. - hasData && ! dataByGroup && ( + showGrid && ! dataByGroup && ( ) } { // Render empty state. - ! hasData && ( -
- { isLoading ? ( -

- -

- ) : ( - empty - ) } -
+ noResults && ( +
{ empty }
) } - { hasData && isLoading && ( + { isInfiniteScroll && isLoading && (

diff --git a/packages/dataviews/src/components/dataviews-layouts/grid/style.scss b/packages/dataviews/src/components/dataviews-layouts/grid/style.scss index 706ce9c0783cab..0bf22fbe80a1bc 100644 --- a/packages/dataviews/src/components/dataviews-layouts/grid/style.scss +++ b/packages/dataviews/src/components/dataviews-layouts/grid/style.scss @@ -164,6 +164,11 @@ padding-bottom: $grid-unit-15; } } + + &.is-refreshing { + opacity: 0.5; + pointer-events: none; + } } .dataviews-view-grid__field-value:empty, diff --git a/packages/dataviews/src/components/dataviews-layouts/list/index.tsx b/packages/dataviews/src/components/dataviews-layouts/list/index.tsx index df1bcc5ae0d908..3f02902efe2c9b 100644 --- a/packages/dataviews/src/components/dataviews-layouts/list/index.tsx +++ b/packages/dataviews/src/components/dataviews-layouts/list/index.tsx @@ -41,6 +41,7 @@ import type { ActionModal as ActionModalType, } from '../../../types'; import getDataByGroup from '../utils/get-data-by-group'; +import useDisplayData from '../utils/use-display-data'; interface ListViewItemProps< Item > { view: ViewListType; @@ -390,7 +391,9 @@ export default function ViewList< Item >( props: ViewListProps< Item > ) { } = props; const baseId = useInstanceId( ViewList, 'view-list' ); - const selectedItem = data?.findLast( ( item ) => + const displayData = useDisplayData( data, isLoading ); + + const selectedItem = displayData?.findLast( ( item ) => selection.includes( getItemId( item ) ) ); const titleField = fields.find( ( field ) => field.id === view.titleField ); @@ -436,7 +439,7 @@ export default function ViewList< Item >( props: ViewListProps< Item > ) { } }, [ selectedItem, generateCompositeItemIdPrefix ] ); - const activeItemIndex = data.findIndex( ( item ) => + const activeItemIndex = displayData.findIndex( ( item ) => isActiveCompositeItem( item, activeCompositeId ?? '' ) ); const previousActiveItemIndex = usePrevious( activeItemIndex ); @@ -449,23 +452,23 @@ export default function ViewList< Item >( props: ViewListProps< Item > ) { // target composite item ID generateCompositeId: ( idPrefix: string ) => string ) => { - // Clamping between 0 and data.length - 1 to avoid out of bounds. + // Clamping between 0 and displayData.length - 1 to avoid out of bounds. const clampedIndex = Math.min( - data.length - 1, + displayData.length - 1, Math.max( 0, targetIndex ) ); - if ( ! data[ clampedIndex ] ) { + if ( ! displayData[ clampedIndex ] ) { return; } const itemIdPrefix = generateCompositeItemIdPrefix( - data[ clampedIndex ] + displayData[ clampedIndex ] ); const targetCompositeItemId = generateCompositeId( itemIdPrefix ); setActiveCompositeId( targetCompositeItemId ); document.getElementById( targetCompositeItemId )?.focus(); }, - [ data, generateCompositeItemIdPrefix ] + [ displayData, generateCompositeItemIdPrefix ] ); // Select a new active composite item when the current active item @@ -511,31 +514,25 @@ export default function ViewList< Item >( props: ViewListProps< Item > ) { [ selectCompositeItem, activeItemIndex ] ); - const hasData = data?.length; - if ( ! hasData ) { - return ( -
- { ! hasData && - ( isLoading ? ( -

- -

- ) : ( - empty - ) ) } -
- ); - } - + const hasData = !! displayData?.length; const groupField = view.groupBy?.field ? fields.find( ( field ) => field.id === view.groupBy?.field ) : null; - const dataByGroup = groupField ? getDataByGroup( data, groupField ) : null; + const dataByGroup = + hasData && groupField + ? getDataByGroup( displayData, groupField ) + : null; + const isInfiniteScroll = view.infiniteScrollEnabled && ! dataByGroup; + const noResults = ! hasData && ! isLoading; + const isRefreshing = ! isInfiniteScroll && isLoading && hasData; + + if ( noResults ) { + return
{ empty }
; + } + + if ( ! hasData && ! isInfiniteScroll ) { + return null; + } // Render data grouped by field if ( hasData && groupField && dataByGroup ) { @@ -614,12 +611,15 @@ export default function ViewList< Item >( props: ViewListProps< Item > ) { [ 'compact', 'comfortable' ].includes( view.layout.density ), + 'is-refreshing': isRefreshing, } ) } role={ view.infiniteScrollEnabled ? 'feed' : 'grid' } activeId={ activeCompositeId } setActiveId={ setActiveCompositeId } + // @ts-ignore + inert={ isRefreshing ? 'true' : undefined } > - { data.map( ( item, index ) => { + { displayData.map( ( item, index ) => { const id = generateCompositeItemIdPrefix( item ); return ( ( props: ViewListProps< Item > ) { ); } ) } - { hasData && isLoading && ( + { isInfiniteScroll && isLoading && (

diff --git a/packages/dataviews/src/components/dataviews-layouts/list/style.scss b/packages/dataviews/src/components/dataviews-layouts/list/style.scss index 5ea835ee248902..26fee0ecfaf05f 100644 --- a/packages/dataviews/src/components/dataviews-layouts/list/style.scss +++ b/packages/dataviews/src/components/dataviews-layouts/list/style.scss @@ -271,6 +271,11 @@ div.dataviews-view-list { } } } + + &.is-refreshing { + opacity: 0.5; + pointer-events: none; + } } .dataviews-view-list__group-header { diff --git a/packages/dataviews/src/components/dataviews-layouts/table/index.tsx b/packages/dataviews/src/components/dataviews-layouts/table/index.tsx index 5208155c6ec170..ac1f359e4d5a69 100644 --- a/packages/dataviews/src/components/dataviews-layouts/table/index.tsx +++ b/packages/dataviews/src/components/dataviews-layouts/table/index.tsx @@ -41,6 +41,7 @@ import ColumnHeaderMenu from './column-header-menu'; import ColumnPrimary from './column-primary'; import { useIsHorizontalScrollEnd } from './use-is-horizontal-scroll-end'; import getDataByGroup from '../utils/get-data-by-group'; +import useDisplayData from '../utils/use-display-data'; import { PropertiesSection } from '../../dataviews-view-config/properties-section'; interface TableColumnFieldProps< Item > { @@ -311,18 +312,7 @@ function ViewTable< Item >( { enabled: !! actions?.length, } ); - // Preserve previous loaded data to apply loading pulse animation - // while refreshing to avoid flickering. - const previousDataRef = useRef< Item[] >( data ); - useEffect( () => { - if ( ! isLoading ) { - previousDataRef.current = data; - } - }, [ data, isLoading ] ); - const displayData = - isLoading && previousDataRef.current?.length - ? previousDataRef.current - : data; + const displayData = useDisplayData( data, isLoading ); const hasBulkActions = useSomeItemHasAPossibleBulkAction( actions, @@ -402,16 +392,12 @@ function ViewTable< Item >( { const isInfiniteScroll = view.infiniteScrollEnabled && ! dataByGroup; const isRtl = isRTL(); - // If new data are loading but previous loaded data were empty, - // keep showing just the spinner. const isRefreshing = ! isInfiniteScroll && isLoading && hasData; const noResults = ! hasData && ! isLoading; - // Determine if we should show loading spinner. Infinite scroll has - // different logic and spinner. - const showLoadingSpinner = ! hasData && isLoading; + const showTable = hasData || ( isLoading && isInfiniteScroll ); return ( <> - { ! noResults && ! showLoadingSpinner && ( + { showTable && ( <> ( { ) }
- { isInfiniteScroll && hasData && isLoading && ( + { isInfiniteScroll && isLoading && (

@@ -717,21 +703,9 @@ function ViewTable< Item >( { ) } ) } - { ( showLoadingSpinner || noResults ) && ( -

- { showLoadingSpinner ? ( -

- -

- ) : ( - empty - ) } + { noResults && ( +
+ { empty }
) } diff --git a/packages/dataviews/src/components/dataviews-layouts/table/style.scss b/packages/dataviews/src/components/dataviews-layouts/table/style.scss index 9f2f77ec8dbb8c..72a998b81b955b 100644 --- a/packages/dataviews/src/components/dataviews-layouts/table/style.scss +++ b/packages/dataviews/src/components/dataviews-layouts/table/style.scss @@ -310,51 +310,10 @@ width: 1%; } -@keyframes loadingpulse { - 50% { - opacity: 0.5; - } -} - -@mixin skeleton() { - animation: loadingpulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite; -} - .dataviews-view-table.is-refreshing { + opacity: 0.5; + tbody { pointer-events: none; - position: relative; - } - - tbody td > *:first-child { - position: relative; - visibility: hidden; - - &::after { - content: ""; - position: absolute; - background-color: $gray-300; - inset: 0; - height: $grid-unit-10; - margin: auto 0; - border-radius: var(--wpds-border-radius-sm); - pointer-events: none; - visibility: visible; - @include skeleton(); - max-width: 320px; - } - } - - tbody tr:nth-child(even) td > *:first-child { - &::after { - max-width: 480px; - } - } - - tbody td.dataviews-view-table__checkbox-column > *:first-child { - &::after { - width: $grid-unit-20; - height: $grid-unit-20; - } } } diff --git a/packages/dataviews/src/components/dataviews-layouts/utils/use-display-data.ts b/packages/dataviews/src/components/dataviews-layouts/utils/use-display-data.ts new file mode 100644 index 00000000000000..9418f28938aff0 --- /dev/null +++ b/packages/dataviews/src/components/dataviews-layouts/utils/use-display-data.ts @@ -0,0 +1,19 @@ +/** + * WordPress dependencies + */ +import { useEffect, useRef } from '@wordpress/element'; + +export default function useDisplayData< Item >( + data: Item[], + isLoading: boolean | undefined +): Item[] { + const previousDataRef = useRef< Item[] >( data ); + useEffect( () => { + if ( ! isLoading ) { + previousDataRef.current = data; + } + }, [ data, isLoading ] ); + return isLoading && previousDataRef.current?.length + ? previousDataRef.current + : data; +} diff --git a/packages/dataviews/src/dataviews/index.tsx b/packages/dataviews/src/dataviews/index.tsx index f946b7d5dff271..c34b0ba5a52d3b 100644 --- a/packages/dataviews/src/dataviews/index.tsx +++ b/packages/dataviews/src/dataviews/index.tsx @@ -8,6 +8,7 @@ import type { ReactNode, ComponentProps, ReactElement } from 'react'; */ import { useEffect, useMemo, useRef, useState } from '@wordpress/element'; import { useResizeObserver, throttle } from '@wordpress/compose'; +import { ProgressBar } from '@wordpress/components'; import { Stack } from '@wordpress/ui'; /** @@ -273,6 +274,9 @@ function DataViews< Item >( { } } >
+ { isLoading && ! infiniteScrollHandler && ( + + ) } { children ?? ( Date: Mon, 9 Feb 2026 14:06:32 +0200 Subject: [PATCH 10/19] fixed position --- packages/dataviews/src/dataviews/style.scss | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/dataviews/src/dataviews/style.scss b/packages/dataviews/src/dataviews/style.scss index 6c8adf92050b58..b7dfb5169d0bc4 100644 --- a/packages/dataviews/src/dataviews/style.scss +++ b/packages/dataviews/src/dataviews/style.scss @@ -19,12 +19,12 @@ } .dataviews-wrapper .dataviews-wrapper__loading-progress { - position: absolute; + position: fixed; top: 0; left: 0; right: 0; width: 100%; - z-index: 10; + z-index: 1000; border-radius: 0; --wp-components-color-foreground: var(--wp-admin-theme-color); } From 11df5420926447cefaa4609704402f0d3c6314af Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Mon, 16 Feb 2026 11:53:36 +0200 Subject: [PATCH 11/19] show delayed loader --- packages/dataviews/src/dataviews/index.tsx | 24 +++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/packages/dataviews/src/dataviews/index.tsx b/packages/dataviews/src/dataviews/index.tsx index c34b0ba5a52d3b..369f1eb5461bec 100644 --- a/packages/dataviews/src/dataviews/index.tsx +++ b/packages/dataviews/src/dataviews/index.tsx @@ -120,6 +120,26 @@ function DefaultUI( { ); } +function useDelayedLoading( + isLoading: boolean, + options: { delay: number } = { delay: 400 } +): boolean { + const [ showLoader, setShowLoader ] = useState( false ); + useEffect( () => { + if ( ! isLoading ) { + return; + } + const timeout = setTimeout( () => { + setShowLoader( true ); + }, options.delay ); + return () => { + clearTimeout( timeout ); + setShowLoader( false ); + }; + }, [ isLoading, options.delay ] ); + return showLoader; +} + function DataViews< Item >( { view, onChangeView, @@ -237,6 +257,8 @@ function DataViews< Item >( { [ defaultLayoutsProperty ] ); + const showLoader = useDelayedLoading( isLoading ); + if ( ! defaultLayouts[ view.type ] ) { return null; } @@ -274,7 +296,7 @@ function DataViews< Item >( { } } >
- { isLoading && ! infiniteScrollHandler && ( + { showLoader && ! infiniteScrollHandler && ( ) } { children ?? ( From 3e8b3619599676341b7c4edda6f1015c430c0e1b Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Fri, 20 Feb 2026 13:32:18 +0200 Subject: [PATCH 12/19] useData hook and pass them to all layouts --- packages/dataviews/CHANGELOG.md | 2 +- .../src/components/dataviews-context/index.ts | 2 + .../src/components/dataviews-footer/index.tsx | 18 +- .../src/components/dataviews-layout/index.tsx | 2 + .../dataviews-layouts/activity/index.tsx | 64 +- .../dataviews-layouts/activity/style.scss | 4 + .../dataviews-layouts/grid/index.tsx | 39 +- .../dataviews-layouts/list/index.tsx | 36 +- .../dataviews-layouts/table/index.tsx | 580 ++++++++---------- .../utils/use-display-data.ts | 19 - .../dataviews/src/dataviews-picker/index.tsx | 3 + packages/dataviews/src/dataviews/index.tsx | 15 +- packages/dataviews/src/hooks/use-data.ts | 27 + packages/dataviews/src/types/dataviews.ts | 1 + 14 files changed, 401 insertions(+), 411 deletions(-) delete mode 100644 packages/dataviews/src/components/dataviews-layouts/utils/use-display-data.ts create mode 100644 packages/dataviews/src/hooks/use-data.ts diff --git a/packages/dataviews/CHANGELOG.md b/packages/dataviews/CHANGELOG.md index e1cd99c92bad18..36d703de30e409 100644 --- a/packages/dataviews/CHANGELOG.md +++ b/packages/dataviews/CHANGELOG.md @@ -5,6 +5,7 @@ ### Bug Fixes - DataForm: Fix focus loss when collapsing in Card view. [#75689](https://github.com/WordPress/gutenberg/pull/75689) +- DataViews: Move loading UI outside of layouts to avoid flickering while refreshing. [#74572](https://github.com/WordPress/gutenberg/pull/74572) - DataViews: Fix spacing in first column. [#75693](https://github.com/WordPress/gutenberg/pull/75693) - DataViews: Fix search input losing characters during debounce when externally synced. [#75810](https://github.com/WordPress/gutenberg/pull/75810) - DataForm: Fix vertical alignment of summary fields in card layout. [#75864](https://github.com/WordPress/gutenberg/pull/75864) @@ -27,7 +28,6 @@ - DataForm: Fix text selection in panel layout summary rows by replacing `::after` overlay with accessible card pattern. [#75565](https://github.com/WordPress/gutenberg/pull/75565) - DataViews: Improve styling for filters when long values are in use. [#75369](https://github.com/WordPress/gutenberg/pull/75369) - DataForm: Fix label case for regular layout. [#75292](https://github.com/WordPress/gutenberg/pull/75292) -- DataViews: Apply loading pulse animation while refreshing to avoid flickering. [#74572](https://github.com/WordPress/gutenberg/pull/74572) - DataViews: Add title attribute in grid item title field. [#75085](https://github.com/WordPress/gutenberg/pull/75085) - DataViews: Fix title truncation in list layout. [#75063](https://github.com/WordPress/gutenberg/pull/75063) - DataViews: Fix fields async validation. [#74948](https://github.com/WordPress/gutenberg/pull/74948) diff --git a/packages/dataviews/src/components/dataviews-context/index.ts b/packages/dataviews/src/components/dataviews-context/index.ts index 9061d9ba66c348..b59c9bf3361b01 100644 --- a/packages/dataviews/src/components/dataviews-context/index.ts +++ b/packages/dataviews/src/components/dataviews-context/index.ts @@ -56,6 +56,7 @@ type DataViewsContextType< Item > = { setIsShowingFilter: ( value: boolean ) => void; config: { perPageSizes: number[] }; empty?: ReactNode; + hasInitiallyLoaded: boolean; hasInfiniteScrollHandler: boolean; itemListLabel?: string; onReset?: ( () => void ) | false; @@ -84,6 +85,7 @@ const DataViewsContext = createContext< DataViewsContextType< any > >( { filters: [], isShowingFilter: false, setIsShowingFilter: () => {}, + hasInitiallyLoaded: false, hasInfiniteScrollHandler: false, config: { perPageSizes: [], diff --git a/packages/dataviews/src/components/dataviews-footer/index.tsx b/packages/dataviews/src/components/dataviews-footer/index.tsx index 5a84ea7b05a779..1b629013d1eccf 100644 --- a/packages/dataviews/src/components/dataviews-footer/index.tsx +++ b/packages/dataviews/src/components/dataviews-footer/index.tsx @@ -23,26 +23,36 @@ export default function DataViewsFooter() { paginationInfo: { totalItems = 0, totalPages }, data, actions = EMPTY_ARRAY, + isLoading, + hasInitiallyLoaded, + hasInfiniteScrollHandler, } = useContext( DataViewsContext ); + + const isRefreshing = + !! isLoading && hasInitiallyLoaded && ! hasInfiniteScrollHandler; + const hasBulkActions = useSomeItemHasAPossibleBulkAction( actions, data ) && [ LAYOUT_TABLE, LAYOUT_GRID ].includes( view.type ); if ( - ! totalItems || - ! totalPages || - ( totalPages <= 1 && ! hasBulkActions ) + ! isRefreshing && + ( ! totalItems || + ! totalPages || + ( totalPages <= 1 && ! hasBulkActions ) ) ) { return null; } return ( - !! totalItems && ( + ( !! totalItems || isRefreshing ) && ( { hasBulkActions && } diff --git a/packages/dataviews/src/components/dataviews-layout/index.tsx b/packages/dataviews/src/components/dataviews-layout/index.tsx index 73f92ed363c18c..bc7694f05c2796 100644 --- a/packages/dataviews/src/components/dataviews-layout/index.tsx +++ b/packages/dataviews/src/components/dataviews-layout/index.tsx @@ -38,6 +38,7 @@ export default function DataViewsLayout( { className }: DataViewsLayoutProps ) { renderItemLink, defaultLayouts, empty =

{ __( 'No results' ) }

, + hasInitiallyLoaded, } = useContext( DataViewsContext ); const ViewComponent = VIEW_LAYOUTS.find( @@ -62,6 +63,7 @@ export default function DataViewsLayout( { className }: DataViewsLayoutProps ) { isItemClickable={ isItemClickable } view={ view } empty={ empty } + hasInitiallyLoaded={ hasInitiallyLoaded } /> ); } diff --git a/packages/dataviews/src/components/dataviews-layouts/activity/index.tsx b/packages/dataviews/src/components/dataviews-layouts/activity/index.tsx index d731a89f33fdd1..17a2555bb9fbeb 100644 --- a/packages/dataviews/src/components/dataviews-layouts/activity/index.tsx +++ b/packages/dataviews/src/components/dataviews-layouts/activity/index.tsx @@ -20,37 +20,39 @@ import ActivityItems from './activity-items'; export default function ViewActivity< Item >( props: ViewActivityProps< Item > ) { - const { empty, data, fields, isLoading, view, className } = props; + const { + empty, + data, + fields, + isLoading, + hasInitiallyLoaded, + view, + className, + } = props; - // Handle empty/loading states - const hasData = data?.length; - if ( ! hasData ) { - return ( -
- { ! hasData && - ( isLoading ? ( -

- -

- ) : ( - empty - ) ) } -
- ); - } - - const wrapperClassName = clsx( 'dataviews-view-activity', className ); + const hasData = !! data?.length; // Check if data should be grouped const groupField = view.groupBy?.field ? fields.find( ( field ) => field.id === view.groupBy?.field ) : null; - const dataByGroup = groupField ? getDataByGroup( data, groupField ) : null; + const dataByGroup = + hasData && groupField ? getDataByGroup( data, groupField ) : null; + + const isInfiniteScroll = view.infiniteScrollEnabled && ! dataByGroup; + const noResults = ! hasData && hasInitiallyLoaded; + + if ( noResults ) { + return
{ empty }
; + } + if ( ! hasData && ! isInfiniteScroll ) { + return null; + } + + const isRefreshing = ! isInfiniteScroll && isLoading; + const wrapperClassName = clsx( 'dataviews-view-activity', className, { + 'is-refreshing': isRefreshing, + } ); // Convert dataByGroup entries into array. const groupedEntries = dataByGroup @@ -60,7 +62,13 @@ export default function ViewActivity< Item >( // Render grouped activity if ( hasData && groupField && dataByGroup ) { return ( - + { groupedEntries.map( ( [ groupName, groupData ]: [ string, Item[] ] ) => ( @@ -87,10 +95,12 @@ export default function ViewActivity< Item >(
{ ...props } />
- { hasData && isLoading && ( + { isInfiniteScroll && isLoading && hasInitiallyLoaded && (

diff --git a/packages/dataviews/src/components/dataviews-layouts/activity/style.scss b/packages/dataviews/src/components/dataviews-layouts/activity/style.scss index 4a9f1ff26b5dc1..716b2134222112 100644 --- a/packages/dataviews/src/components/dataviews-layouts/activity/style.scss +++ b/packages/dataviews/src/components/dataviews-layouts/activity/style.scss @@ -211,6 +211,10 @@ } } + &.is-refreshing { + opacity: 0.5; + } + & + .dataviews-pagination { justify-content: space-between; } diff --git a/packages/dataviews/src/components/dataviews-layouts/grid/index.tsx b/packages/dataviews/src/components/dataviews-layouts/grid/index.tsx index 7e17921aef5972..1f24b385bd201e 100644 --- a/packages/dataviews/src/components/dataviews-layouts/grid/index.tsx +++ b/packages/dataviews/src/components/dataviews-layouts/grid/index.tsx @@ -15,7 +15,6 @@ import { Stack } from '@wordpress/ui'; */ import type { ViewGridProps } from '../../../types'; import getDataByGroup from '../utils/get-data-by-group'; -import useDisplayData from '../utils/use-display-data'; import CompositeGrid from './composite-grid'; function ViewGrid< Item >( { @@ -32,23 +31,27 @@ function ViewGrid< Item >( { view, className, empty, + hasInitiallyLoaded, }: ViewGridProps< Item > ) { - const displayData = useDisplayData( data, isLoading ); - - const hasData = !! displayData?.length; + const hasData = !! data?.length; const groupField = view.groupBy?.field ? fields.find( ( f ) => f.id === view.groupBy?.field ) : null; - const dataByGroup = groupField - ? getDataByGroup( displayData, groupField ) - : null; + const dataByGroup = groupField ? getDataByGroup( data, groupField ) : null; const isInfiniteScroll = view.infiniteScrollEnabled && ! dataByGroup; - const noResults = ! hasData && ! isLoading; - const showGrid = hasData || ( isLoading && isInfiniteScroll ); - const isRefreshing = ! isInfiniteScroll && isLoading && hasData; + const noResults = ! hasData && hasInitiallyLoaded; + + if ( noResults ) { + return
{ empty }
; + } + if ( ! hasData && ! isInfiniteScroll ) { + return null; + } const gridProps = { - className: clsx( className, { 'is-refreshing': isRefreshing } ), - inert: isRefreshing ? 'true' : undefined, + className: clsx( className, { + 'is-refreshing': ! isInfiniteScroll && isLoading, + } ), + inert: ! isInfiniteScroll && isLoading ? 'true' : undefined, isLoading, view, fields, @@ -96,21 +99,15 @@ function ViewGrid< Item >( { } { // Render a single grid with all data. - showGrid && ! dataByGroup && ( + ! dataByGroup && ( ) } - { - // Render empty state. - noResults && ( -
{ empty }
- ) - } - { isInfiniteScroll && isLoading && ( + { isInfiniteScroll && isLoading && hasInitiallyLoaded && (

diff --git a/packages/dataviews/src/components/dataviews-layouts/list/index.tsx b/packages/dataviews/src/components/dataviews-layouts/list/index.tsx index 3f02902efe2c9b..23930b7665f318 100644 --- a/packages/dataviews/src/components/dataviews-layouts/list/index.tsx +++ b/packages/dataviews/src/components/dataviews-layouts/list/index.tsx @@ -41,7 +41,6 @@ import type { ActionModal as ActionModalType, } from '../../../types'; import getDataByGroup from '../utils/get-data-by-group'; -import useDisplayData from '../utils/use-display-data'; interface ListViewItemProps< Item > { view: ViewListType; @@ -388,12 +387,11 @@ export default function ViewList< Item >( props: ViewListProps< Item > ) { view, className, empty, + hasInitiallyLoaded, } = props; const baseId = useInstanceId( ViewList, 'view-list' ); - const displayData = useDisplayData( data, isLoading ); - - const selectedItem = displayData?.findLast( ( item ) => + const selectedItem = data?.findLast( ( item ) => selection.includes( getItemId( item ) ) ); const titleField = fields.find( ( field ) => field.id === view.titleField ); @@ -439,7 +437,7 @@ export default function ViewList< Item >( props: ViewListProps< Item > ) { } }, [ selectedItem, generateCompositeItemIdPrefix ] ); - const activeItemIndex = displayData.findIndex( ( item ) => + const activeItemIndex = data.findIndex( ( item ) => isActiveCompositeItem( item, activeCompositeId ?? '' ) ); const previousActiveItemIndex = usePrevious( activeItemIndex ); @@ -452,23 +450,23 @@ export default function ViewList< Item >( props: ViewListProps< Item > ) { // target composite item ID generateCompositeId: ( idPrefix: string ) => string ) => { - // Clamping between 0 and displayData.length - 1 to avoid out of bounds. + // Clamping between 0 and data.length - 1 to avoid out of bounds. const clampedIndex = Math.min( - displayData.length - 1, + data.length - 1, Math.max( 0, targetIndex ) ); - if ( ! displayData[ clampedIndex ] ) { + if ( ! data[ clampedIndex ] ) { return; } const itemIdPrefix = generateCompositeItemIdPrefix( - displayData[ clampedIndex ] + data[ clampedIndex ] ); const targetCompositeItemId = generateCompositeId( itemIdPrefix ); setActiveCompositeId( targetCompositeItemId ); document.getElementById( targetCompositeItemId )?.focus(); }, - [ displayData, generateCompositeItemIdPrefix ] + [ data, generateCompositeItemIdPrefix ] ); // Select a new active composite item when the current active item @@ -514,22 +512,18 @@ export default function ViewList< Item >( props: ViewListProps< Item > ) { [ selectCompositeItem, activeItemIndex ] ); - const hasData = !! displayData?.length; + const hasData = !! data?.length; const groupField = view.groupBy?.field ? fields.find( ( field ) => field.id === view.groupBy?.field ) : null; const dataByGroup = - hasData && groupField - ? getDataByGroup( displayData, groupField ) - : null; + hasData && groupField ? getDataByGroup( data, groupField ) : null; const isInfiniteScroll = view.infiniteScrollEnabled && ! dataByGroup; - const noResults = ! hasData && ! isLoading; - const isRefreshing = ! isInfiniteScroll && isLoading && hasData; + const noResults = ! hasData && hasInitiallyLoaded; if ( noResults ) { return
{ empty }
; } - if ( ! hasData && ! isInfiniteScroll ) { return null; } @@ -611,15 +605,15 @@ export default function ViewList< Item >( props: ViewListProps< Item > ) { [ 'compact', 'comfortable' ].includes( view.layout.density ), - 'is-refreshing': isRefreshing, + 'is-refreshing': ! isInfiniteScroll && isLoading, } ) } role={ view.infiniteScrollEnabled ? 'feed' : 'grid' } activeId={ activeCompositeId } setActiveId={ setActiveCompositeId } // @ts-ignore - inert={ isRefreshing ? 'true' : undefined } + inert={ ! isInfiniteScroll && isLoading ? 'true' : undefined } > - { displayData.map( ( item, index ) => { + { data.map( ( item, index ) => { const id = generateCompositeItemIdPrefix( item ); return ( ( props: ViewListProps< Item > ) { ); } ) } - { isInfiniteScroll && isLoading && ( + { isInfiniteScroll && isLoading && hasInitiallyLoaded && (

diff --git a/packages/dataviews/src/components/dataviews-layouts/table/index.tsx b/packages/dataviews/src/components/dataviews-layouts/table/index.tsx index ac1f359e4d5a69..e34d87859f3263 100644 --- a/packages/dataviews/src/components/dataviews-layouts/table/index.tsx +++ b/packages/dataviews/src/components/dataviews-layouts/table/index.tsx @@ -41,7 +41,6 @@ import ColumnHeaderMenu from './column-header-menu'; import ColumnPrimary from './column-primary'; import { useIsHorizontalScrollEnd } from './use-is-horizontal-scroll-end'; import getDataByGroup from '../utils/get-data-by-group'; -import useDisplayData from '../utils/use-display-data'; import { PropertiesSection } from '../../dataviews-view-config/properties-section'; interface TableColumnFieldProps< Item > { @@ -286,6 +285,7 @@ function ViewTable< Item >( { view, className, empty, + hasInitiallyLoaded, }: ViewTableProps< Item > ) { const { containerRef } = useContext( DataViewsContext ); const headerMenuRefs = useRef< @@ -312,12 +312,7 @@ function ViewTable< Item >( { enabled: !! actions?.length, } ); - const displayData = useDisplayData( data, isLoading ); - - const hasBulkActions = useSomeItemHasAPossibleBulkAction( - actions, - displayData - ); + const hasBulkActions = useSomeItemHasAPossibleBulkAction( actions, data ); if ( nextHeaderMenuToFocus ) { // If we need to force focus, we short-circuit rendering here @@ -358,7 +353,7 @@ function ViewTable< Item >( { } ); }; - const hasData = !! displayData?.length; + const hasData = !! data?.length; const titleField = fields.find( ( field ) => field.id === view.titleField ); const mediaField = fields.find( ( field ) => field.id === view.mediaField ); @@ -369,9 +364,7 @@ function ViewTable< Item >( { const groupField = view.groupBy?.field ? fields.find( ( f ) => f.id === view.groupBy?.field ) : null; - const dataByGroup = groupField - ? getDataByGroup( displayData, groupField ) - : null; + const dataByGroup = groupField ? getDataByGroup( data, groupField ) : null; const { showTitle = true, showMedia = true, showDescription = true } = view; const hasPrimaryColumn = ( titleField && showTitle ) || @@ -391,321 +384,278 @@ function ViewTable< Item >( { }; const isInfiniteScroll = view.infiniteScrollEnabled && ! dataByGroup; const isRtl = isRTL(); + const noResults = ! hasData && hasInitiallyLoaded; + + if ( noResults ) { + return ( +
+ { empty } +
+ ); + } + if ( ! hasData && ! isInfiniteScroll ) { + return null; + } - const isRefreshing = ! isInfiniteScroll && isLoading && hasData; - const noResults = ! hasData && ! isLoading; - const showTable = hasData || ( isLoading && isInfiniteScroll ); return ( <> - { showTable && ( - <> - - - { hasBulkActions && ( - - ) } - { hasPrimaryColumn && ( - - ) } - { columns.map( ( column, index ) => ( - - ) ) } - { !! actions?.length && ( - +
+ + { hasBulkActions && ( + + ) } + { hasPrimaryColumn && ( + + ) } + { columns.map( ( column, index ) => ( + - { contextMenuAnchor && ( - setContextMenuAnchor( null ) } - placement="bottom-start" + /> + ) ) } + { !! actions?.length && ( + + ) } + + { contextMenuAnchor && ( + setContextMenuAnchor( null ) } + placement="bottom-start" + > + + + ) } + + + { hasBulkActions && ( + ) } - - - { hasBulkActions && ( - + canInsertRight={ + isRtl + ? false + : view.layout?.enableMoving ?? + true + } + /> ) } - { hasPrimaryColumn && ( - + + ) } + { columns.map( ( column, index ) => { + // Explicit picks the supported styles. + const { width, maxWidth, minWidth, align } = + view.layout?.styles?.[ column ] ?? {}; + const canInsertOrMove = + view.layout?.enableMoving ?? true; + return ( + + ); + } ) } + { !! actions?.length && ( + - ); - } ) } - { !! actions?.length && ( - + ) } + + + { /* Render grouped data if groupBy is specified */ } + { hasData && groupField && dataByGroup ? ( + Array.from( dataByGroup.entries() ).map( + ( [ groupName, groupItems ] ) => ( + + + - - { /* Render grouped data if groupBy is specified */ } - { hasData && groupField && dataByGroup ? ( - Array.from( dataByGroup.entries() ).map( - ( [ groupName, groupItems ] ) => ( - - - - - { groupItems.map( ( item, index ) => ( - - ) ) } - - ) - ) - ) : ( - - { hasData && - displayData.map( ( item, index ) => ( - - ) ) } + { view.groupBy?.showLabel === false + ? groupName + : sprintf( + // translators: 1: The label of the field e.g. "Date". 2: The value of the field, e.g.: "May 2022". + __( '%1$s: %2$s' ), + groupField.label, + groupName + ) } + + + { groupItems.map( ( item, index ) => ( + + ) ) } - ) } -
- - + +
+ { titleField && ( + - - - { titleField && ( - - ) } - + + { - // Explicit picks the supported styles. - const { width, maxWidth, minWidth, align } = - view.layout?.styles?.[ column ] ?? {}; - const canInsertOrMove = - view.layout?.enableMoving ?? true; - return ( - - - + + { __( 'Actions' ) } + +
- - { __( 'Actions' ) } - - - ) } -
- { view.groupBy?.showLabel === - false - ? groupName - : sprintf( - // translators: 1: The label of the field e.g. "Date". 2: The value of the field, e.g.: "May 2022". - __( '%1$s: %2$s' ), - groupField.label, - groupName - ) } -
- { isInfiniteScroll && isLoading && ( -
-

- -

-
- ) } - - ) } - { noResults && ( -
- { empty } + ) + ) + ) : ( + + { hasData && + data.map( ( item, index ) => ( + + ) ) } + + ) } + + { isInfiniteScroll && isLoading && hasInitiallyLoaded && ( +
+

+ +

) } diff --git a/packages/dataviews/src/components/dataviews-layouts/utils/use-display-data.ts b/packages/dataviews/src/components/dataviews-layouts/utils/use-display-data.ts deleted file mode 100644 index 9418f28938aff0..00000000000000 --- a/packages/dataviews/src/components/dataviews-layouts/utils/use-display-data.ts +++ /dev/null @@ -1,19 +0,0 @@ -/** - * WordPress dependencies - */ -import { useEffect, useRef } from '@wordpress/element'; - -export default function useDisplayData< Item >( - data: Item[], - isLoading: boolean | undefined -): Item[] { - const previousDataRef = useRef< Item[] >( data ); - useEffect( () => { - if ( ! isLoading ) { - previousDataRef.current = data; - } - }, [ data, isLoading ] ); - return isLoading && previousDataRef.current?.length - ? previousDataRef.current - : data; -} diff --git a/packages/dataviews/src/dataviews-picker/index.tsx b/packages/dataviews/src/dataviews-picker/index.tsx index a4b787a05a1352..929517f1f20221 100644 --- a/packages/dataviews/src/dataviews-picker/index.tsx +++ b/packages/dataviews/src/dataviews-picker/index.tsx @@ -32,6 +32,7 @@ import DataViewsViewConfig, { import normalizeFields from '../field-types'; import type { ActionButton, Field, View, SupportedLayouts } from '../types'; import type { SelectionOrUpdater } from '../types/private'; +import useData from '../hooks/use-data'; type ItemWithId = { id: string }; const isItemClickable = () => false; @@ -146,6 +147,7 @@ function DataViewsPicker< Item >( { onChangeSelection( newValue ); } } + const { hasInitiallyLoaded } = useData( data, isLoading ); const _fields = useMemo( () => normalizeFields( fields ), [ fields ] ); const filters = useFilters( _fields, view ); const hasPrimaryOrLockedFilters = useMemo( @@ -220,6 +222,7 @@ function DataViewsPicker< Item >( { actions, data, isLoading, + hasInitiallyLoaded, paginationInfo, isItemClickable, selection, diff --git a/packages/dataviews/src/dataviews/index.tsx b/packages/dataviews/src/dataviews/index.tsx index 369f1eb5461bec..1b4150f30d928c 100644 --- a/packages/dataviews/src/dataviews/index.tsx +++ b/packages/dataviews/src/dataviews/index.tsx @@ -32,6 +32,7 @@ import DataViewsViewConfig, { ViewTypeMenu, } from '../components/dataviews-view-config'; import normalizeFields from '../field-types'; +import useData from '../hooks/use-data'; import type { Action, Field, View, SupportedLayouts } from '../types'; import type { SelectionOrUpdater } from '../types/private'; type ItemWithId = { id: string }; @@ -257,7 +258,14 @@ function DataViews< Item >( { [ defaultLayoutsProperty ] ); - const showLoader = useDelayedLoading( isLoading ); + const { data: displayData, hasInitiallyLoaded } = useData( + data, + isLoading + ); + + const isDelayedLoading = useDelayedLoading( isLoading ); + const showLoader = + isDelayedLoading && ( ! infiniteScrollHandler || ! hasInitiallyLoaded ); if ( ! defaultLayouts[ view.type ] ) { return null; @@ -270,8 +278,9 @@ function DataViews< Item >( { onChangeView, fields: _fields, actions, - data, + data: displayData, isLoading, + hasInitiallyLoaded, paginationInfo, selection: _selection, onChangeSelection: setSelectionWithChange, @@ -296,7 +305,7 @@ function DataViews< Item >( { } } >
- { showLoader && ! infiniteScrollHandler && ( + { showLoader && ( ) } { children ?? ( diff --git a/packages/dataviews/src/hooks/use-data.ts b/packages/dataviews/src/hooks/use-data.ts new file mode 100644 index 00000000000000..6a5f318fdb8fd4 --- /dev/null +++ b/packages/dataviews/src/hooks/use-data.ts @@ -0,0 +1,27 @@ +/** + * WordPress dependencies + */ +import { useEffect, useRef, useState } from '@wordpress/element'; + +export default function useData< Item >( + data: Item[], + isLoading: boolean | undefined +): { data: Item[]; hasInitiallyLoaded: boolean } { + const previousDataRef = useRef< Item[] >( data ); + const [ hasInitiallyLoaded, setHasInitiallyLoaded ] = useState( + ! isLoading + ); + useEffect( () => { + if ( ! isLoading ) { + previousDataRef.current = data; + setHasInitiallyLoaded( true ); + } + }, [ data, isLoading ] ); + return { + data: + isLoading && previousDataRef.current?.length + ? previousDataRef.current + : data, + hasInitiallyLoaded, + }; +} diff --git a/packages/dataviews/src/types/dataviews.ts b/packages/dataviews/src/types/dataviews.ts index bd3616160c9531..838101a45ecd79 100644 --- a/packages/dataviews/src/types/dataviews.ts +++ b/packages/dataviews/src/types/dataviews.ts @@ -457,6 +457,7 @@ export interface ViewBaseProps< Item > { isItemClickable: ( item: Item ) => boolean; view: View; empty: ReactNode; + hasInitiallyLoaded?: boolean; } export type ViewPickerBaseProps< Item > = Omit< From 07dbf7c1d0511454a34e7cd53666847ff476e189 Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Fri, 20 Feb 2026 13:43:28 +0200 Subject: [PATCH 13/19] fix layout shift with empty footer --- packages/dataviews/src/components/dataviews-footer/index.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/dataviews/src/components/dataviews-footer/index.tsx b/packages/dataviews/src/components/dataviews-footer/index.tsx index 1b629013d1eccf..949be3ad9d0181 100644 --- a/packages/dataviews/src/components/dataviews-footer/index.tsx +++ b/packages/dataviews/src/components/dataviews-footer/index.tsx @@ -29,7 +29,10 @@ export default function DataViewsFooter() { } = useContext( DataViewsContext ); const isRefreshing = - !! isLoading && hasInitiallyLoaded && ! hasInfiniteScrollHandler; + !! isLoading && + hasInitiallyLoaded && + ! hasInfiniteScrollHandler && + !! data?.length; const hasBulkActions = useSomeItemHasAPossibleBulkAction( actions, data ) && From a4a8fd9ac567fd6d259d7c0b46c956586f801422 Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Tue, 24 Feb 2026 18:41:51 +0200 Subject: [PATCH 14/19] remove loader and fade out (delayed) no results too --- packages/dataviews/CHANGELOG.md | 2 +- .../src/components/dataviews-context/index.ts | 2 +- .../dataviews-layouts/activity/index.tsx | 19 ++++++++++--- .../dataviews-layouts/grid/index.tsx | 16 +++++++++-- .../dataviews-layouts/list/index.tsx | 18 ++++++++++-- .../dataviews-layouts/table/index.tsx | 11 ++++++-- .../dataviews/src/dataviews-picker/index.tsx | 3 -- packages/dataviews/src/dataviews/index.tsx | 28 ------------------- packages/dataviews/src/dataviews/style.scss | 16 +++-------- .../src/hooks/use-delayed-loading.ts | 21 ++++++++++++++ 10 files changed, 79 insertions(+), 57 deletions(-) create mode 100644 packages/dataviews/src/hooks/use-delayed-loading.ts diff --git a/packages/dataviews/CHANGELOG.md b/packages/dataviews/CHANGELOG.md index 36d703de30e409..ba17fa229ab773 100644 --- a/packages/dataviews/CHANGELOG.md +++ b/packages/dataviews/CHANGELOG.md @@ -5,7 +5,7 @@ ### Bug Fixes - DataForm: Fix focus loss when collapsing in Card view. [#75689](https://github.com/WordPress/gutenberg/pull/75689) -- DataViews: Move loading UI outside of layouts to avoid flickering while refreshing. [#74572](https://github.com/WordPress/gutenberg/pull/74572) +- DataViews: Avoid flickering while refreshing. [#74572](https://github.com/WordPress/gutenberg/pull/74572) - DataViews: Fix spacing in first column. [#75693](https://github.com/WordPress/gutenberg/pull/75693) - DataViews: Fix search input losing characters during debounce when externally synced. [#75810](https://github.com/WordPress/gutenberg/pull/75810) - DataForm: Fix vertical alignment of summary fields in card layout. [#75864](https://github.com/WordPress/gutenberg/pull/75864) diff --git a/packages/dataviews/src/components/dataviews-context/index.ts b/packages/dataviews/src/components/dataviews-context/index.ts index b59c9bf3361b01..03a506282f2ef8 100644 --- a/packages/dataviews/src/components/dataviews-context/index.ts +++ b/packages/dataviews/src/components/dataviews-context/index.ts @@ -56,7 +56,7 @@ type DataViewsContextType< Item > = { setIsShowingFilter: ( value: boolean ) => void; config: { perPageSizes: number[] }; empty?: ReactNode; - hasInitiallyLoaded: boolean; + hasInitiallyLoaded?: boolean; hasInfiniteScrollHandler: boolean; itemListLabel?: string; onReset?: ( () => void ) | false; diff --git a/packages/dataviews/src/components/dataviews-layouts/activity/index.tsx b/packages/dataviews/src/components/dataviews-layouts/activity/index.tsx index 17a2555bb9fbeb..c6869eeb8286d5 100644 --- a/packages/dataviews/src/components/dataviews-layouts/activity/index.tsx +++ b/packages/dataviews/src/components/dataviews-layouts/activity/index.tsx @@ -16,6 +16,7 @@ import type { ViewActivityProps } from '../../../types'; import getDataByGroup from '../utils/get-data-by-group'; import ActivityGroup from './activity-group'; import ActivityItems from './activity-items'; +import { useDelayedLoading } from '../../../hooks/use-delayed-loading'; export default function ViewActivity< Item >( props: ViewActivityProps< Item > @@ -30,6 +31,7 @@ export default function ViewActivity< Item >( className, } = props; + const isDelayedLoading = useDelayedLoading( !! isLoading ); const hasData = !! data?.length; // Check if data should be grouped @@ -43,13 +45,22 @@ export default function ViewActivity< Item >( const noResults = ! hasData && hasInitiallyLoaded; if ( noResults ) { - return
{ empty }
; + return ( +
+ { empty } +
+ ); } if ( ! hasData && ! isInfiniteScroll ) { return null; } - const isRefreshing = ! isInfiniteScroll && isLoading; + const isRefreshing = ! isInfiniteScroll && isDelayedLoading; + const isInert = ! isInfiniteScroll && !! isLoading; const wrapperClassName = clsx( 'dataviews-view-activity', className, { 'is-refreshing': isRefreshing, } ); @@ -67,7 +78,7 @@ export default function ViewActivity< Item >( gap="sm" className={ wrapperClassName } // @ts-ignore - inert={ isRefreshing ? 'true' : undefined } + inert={ isInert ? 'true' : undefined } > { groupedEntries.map( ( [ groupName, groupData ]: [ string, Item[] ] ) => ( @@ -96,7 +107,7 @@ export default function ViewActivity< Item >( className={ wrapperClassName } role={ view.infiniteScrollEnabled ? 'feed' : undefined } // @ts-ignore - inert={ isRefreshing ? 'true' : undefined } + inert={ isInert ? 'true' : undefined } > { ...props } />
diff --git a/packages/dataviews/src/components/dataviews-layouts/grid/index.tsx b/packages/dataviews/src/components/dataviews-layouts/grid/index.tsx index 1f24b385bd201e..5858b4b008dabd 100644 --- a/packages/dataviews/src/components/dataviews-layouts/grid/index.tsx +++ b/packages/dataviews/src/components/dataviews-layouts/grid/index.tsx @@ -16,6 +16,7 @@ import { Stack } from '@wordpress/ui'; import type { ViewGridProps } from '../../../types'; import getDataByGroup from '../utils/get-data-by-group'; import CompositeGrid from './composite-grid'; +import { useDelayedLoading } from '../../../hooks/use-delayed-loading'; function ViewGrid< Item >( { actions, @@ -33,6 +34,7 @@ function ViewGrid< Item >( { empty, hasInitiallyLoaded, }: ViewGridProps< Item > ) { + const isDelayedLoading = useDelayedLoading( !! isLoading ); const hasData = !! data?.length; const groupField = view.groupBy?.field ? fields.find( ( f ) => f.id === view.groupBy?.field ) @@ -42,16 +44,24 @@ function ViewGrid< Item >( { const noResults = ! hasData && hasInitiallyLoaded; if ( noResults ) { - return
{ empty }
; + return ( +
+ { empty } +
+ ); } if ( ! hasData && ! isInfiniteScroll ) { return null; } const gridProps = { className: clsx( className, { - 'is-refreshing': ! isInfiniteScroll && isLoading, + 'is-refreshing': ! isInfiniteScroll && isDelayedLoading, } ), - inert: ! isInfiniteScroll && isLoading ? 'true' : undefined, + inert: ! isInfiniteScroll && !! isLoading ? 'true' : undefined, isLoading, view, fields, diff --git a/packages/dataviews/src/components/dataviews-layouts/list/index.tsx b/packages/dataviews/src/components/dataviews-layouts/list/index.tsx index 23930b7665f318..afb6ca18ca9e91 100644 --- a/packages/dataviews/src/components/dataviews-layouts/list/index.tsx +++ b/packages/dataviews/src/components/dataviews-layouts/list/index.tsx @@ -33,6 +33,7 @@ import { Stack } from '@wordpress/ui'; import { unlock } from '../../../lock-unlock'; import { ActionsMenuGroup, ActionModal } from '../../dataviews-item-actions'; import DataViewsContext from '../../dataviews-context'; +import { useDelayedLoading } from '../../../hooks/use-delayed-loading'; import type { Action, NormalizedField, @@ -390,6 +391,7 @@ export default function ViewList< Item >( props: ViewListProps< Item > ) { hasInitiallyLoaded, } = props; const baseId = useInstanceId( ViewList, 'view-list' ); + const isDelayedLoading = useDelayedLoading( !! isLoading ); const selectedItem = data?.findLast( ( item ) => selection.includes( getItemId( item ) ) @@ -522,7 +524,15 @@ export default function ViewList< Item >( props: ViewListProps< Item > ) { const noResults = ! hasData && hasInitiallyLoaded; if ( noResults ) { - return
{ empty }
; + return ( +
+ { empty } +
+ ); } if ( ! hasData && ! isInfiniteScroll ) { return null; @@ -605,13 +615,15 @@ export default function ViewList< Item >( props: ViewListProps< Item > ) { [ 'compact', 'comfortable' ].includes( view.layout.density ), - 'is-refreshing': ! isInfiniteScroll && isLoading, + 'is-refreshing': ! isInfiniteScroll && isDelayedLoading, } ) } role={ view.infiniteScrollEnabled ? 'feed' : 'grid' } activeId={ activeCompositeId } setActiveId={ setActiveCompositeId } // @ts-ignore - inert={ ! isInfiniteScroll && isLoading ? 'true' : undefined } + inert={ + ! isInfiniteScroll && !! isLoading ? 'true' : undefined + } > { data.map( ( item, index ) => { const id = generateCompositeItemIdPrefix( item ); diff --git a/packages/dataviews/src/components/dataviews-layouts/table/index.tsx b/packages/dataviews/src/components/dataviews-layouts/table/index.tsx index e34d87859f3263..ad6aa3f432d022 100644 --- a/packages/dataviews/src/components/dataviews-layouts/table/index.tsx +++ b/packages/dataviews/src/components/dataviews-layouts/table/index.tsx @@ -42,6 +42,7 @@ import ColumnPrimary from './column-primary'; import { useIsHorizontalScrollEnd } from './use-is-horizontal-scroll-end'; import getDataByGroup from '../utils/get-data-by-group'; import { PropertiesSection } from '../../dataviews-view-config/properties-section'; +import { useDelayedLoading } from '../../../hooks/use-delayed-loading'; interface TableColumnFieldProps< Item > { fields: NormalizedField< Item >[]; @@ -288,6 +289,7 @@ function ViewTable< Item >( { hasInitiallyLoaded, }: ViewTableProps< Item > ) { const { containerRef } = useContext( DataViewsContext ); + const isDelayedLoading = useDelayedLoading( isLoading ); const headerMenuRefs = useRef< Map< string, { node: HTMLButtonElement; fallback: string } > >( new Map() ); @@ -388,7 +390,12 @@ function ViewTable< Item >( { if ( noResults ) { return ( -
+
{ empty }
); @@ -407,7 +414,7 @@ function ViewTable< Item >( { view.layout.density ), 'has-bulk-actions': hasBulkActions, - 'is-refreshing': ! isInfiniteScroll && isLoading, + 'is-refreshing': ! isInfiniteScroll && isDelayedLoading, } ) } aria-busy={ isLoading } aria-describedby={ tableNoticeId } diff --git a/packages/dataviews/src/dataviews-picker/index.tsx b/packages/dataviews/src/dataviews-picker/index.tsx index 929517f1f20221..a4b787a05a1352 100644 --- a/packages/dataviews/src/dataviews-picker/index.tsx +++ b/packages/dataviews/src/dataviews-picker/index.tsx @@ -32,7 +32,6 @@ import DataViewsViewConfig, { import normalizeFields from '../field-types'; import type { ActionButton, Field, View, SupportedLayouts } from '../types'; import type { SelectionOrUpdater } from '../types/private'; -import useData from '../hooks/use-data'; type ItemWithId = { id: string }; const isItemClickable = () => false; @@ -147,7 +146,6 @@ function DataViewsPicker< Item >( { onChangeSelection( newValue ); } } - const { hasInitiallyLoaded } = useData( data, isLoading ); const _fields = useMemo( () => normalizeFields( fields ), [ fields ] ); const filters = useFilters( _fields, view ); const hasPrimaryOrLockedFilters = useMemo( @@ -222,7 +220,6 @@ function DataViewsPicker< Item >( { actions, data, isLoading, - hasInitiallyLoaded, paginationInfo, isItemClickable, selection, diff --git a/packages/dataviews/src/dataviews/index.tsx b/packages/dataviews/src/dataviews/index.tsx index 1b4150f30d928c..1dcf06b1e60846 100644 --- a/packages/dataviews/src/dataviews/index.tsx +++ b/packages/dataviews/src/dataviews/index.tsx @@ -8,7 +8,6 @@ import type { ReactNode, ComponentProps, ReactElement } from 'react'; */ import { useEffect, useMemo, useRef, useState } from '@wordpress/element'; import { useResizeObserver, throttle } from '@wordpress/compose'; -import { ProgressBar } from '@wordpress/components'; import { Stack } from '@wordpress/ui'; /** @@ -121,26 +120,6 @@ function DefaultUI( { ); } -function useDelayedLoading( - isLoading: boolean, - options: { delay: number } = { delay: 400 } -): boolean { - const [ showLoader, setShowLoader ] = useState( false ); - useEffect( () => { - if ( ! isLoading ) { - return; - } - const timeout = setTimeout( () => { - setShowLoader( true ); - }, options.delay ); - return () => { - clearTimeout( timeout ); - setShowLoader( false ); - }; - }, [ isLoading, options.delay ] ); - return showLoader; -} - function DataViews< Item >( { view, onChangeView, @@ -263,10 +242,6 @@ function DataViews< Item >( { isLoading ); - const isDelayedLoading = useDelayedLoading( isLoading ); - const showLoader = - isDelayedLoading && ( ! infiniteScrollHandler || ! hasInitiallyLoaded ); - if ( ! defaultLayouts[ view.type ] ) { return null; } @@ -305,9 +280,6 @@ function DataViews< Item >( { } } >
- { showLoader && ( - - ) } { children ?? ( { + if ( ! isLoading ) { + return; + } + const timeout = setTimeout( () => { + setShowLoader( true ); + }, options.delay ); + return () => { + clearTimeout( timeout ); + setShowLoader( false ); + }; + }, [ isLoading, options.delay ] ); + return showLoader; +} From b81d692e968d4c25652eab5e108ee6519506e57d Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Wed, 25 Feb 2026 14:24:33 +0200 Subject: [PATCH 15/19] feedback --- .../src/components/dataviews-layout/index.tsx | 7 +++++-- .../dataviews-layouts/activity/index.tsx | 19 +++---------------- .../dataviews-layouts/grid/index.tsx | 10 ++-------- .../dataviews-layouts/list/index.tsx | 10 ++-------- .../dataviews-layouts/table/index.tsx | 10 ++-------- packages/dataviews/src/dataviews/index.tsx | 2 +- packages/dataviews/src/types/dataviews.ts | 1 - 7 files changed, 15 insertions(+), 44 deletions(-) diff --git a/packages/dataviews/src/components/dataviews-layout/index.tsx b/packages/dataviews/src/components/dataviews-layout/index.tsx index bc7694f05c2796..e7406bcbea4d6c 100644 --- a/packages/dataviews/src/components/dataviews-layout/index.tsx +++ b/packages/dataviews/src/components/dataviews-layout/index.tsx @@ -27,6 +27,7 @@ export default function DataViewsLayout( { className }: DataViewsLayoutProps ) { fields, getItemId, getItemLevel, + hasInitiallyLoaded, isLoading, view, onChangeView, @@ -38,9 +39,12 @@ export default function DataViewsLayout( { className }: DataViewsLayoutProps ) { renderItemLink, defaultLayouts, empty =

{ __( 'No results' ) }

, - hasInitiallyLoaded, } = useContext( DataViewsContext ); + if ( ! hasInitiallyLoaded ) { + return null; + } + const ViewComponent = VIEW_LAYOUTS.find( ( v ) => v.type === view.type && defaultLayouts[ v.type ] )?.component as ComponentType< ViewBaseProps< any > >; @@ -63,7 +67,6 @@ export default function DataViewsLayout( { className }: DataViewsLayoutProps ) { isItemClickable={ isItemClickable } view={ view } empty={ empty } - hasInitiallyLoaded={ hasInitiallyLoaded } /> ); } diff --git a/packages/dataviews/src/components/dataviews-layouts/activity/index.tsx b/packages/dataviews/src/components/dataviews-layouts/activity/index.tsx index c6869eeb8286d5..1c3f3d28a7db75 100644 --- a/packages/dataviews/src/components/dataviews-layouts/activity/index.tsx +++ b/packages/dataviews/src/components/dataviews-layouts/activity/index.tsx @@ -21,15 +21,7 @@ import { useDelayedLoading } from '../../../hooks/use-delayed-loading'; export default function ViewActivity< Item >( props: ViewActivityProps< Item > ) { - const { - empty, - data, - fields, - isLoading, - hasInitiallyLoaded, - view, - className, - } = props; + const { empty, data, fields, isLoading, view, className } = props; const isDelayedLoading = useDelayedLoading( !! isLoading ); const hasData = !! data?.length; @@ -42,9 +34,7 @@ export default function ViewActivity< Item >( hasData && groupField ? getDataByGroup( data, groupField ) : null; const isInfiniteScroll = view.infiniteScrollEnabled && ! dataByGroup; - const noResults = ! hasData && hasInitiallyLoaded; - - if ( noResults ) { + if ( ! hasData ) { return (
(
); } - if ( ! hasData && ! isInfiniteScroll ) { - return null; - } const isRefreshing = ! isInfiniteScroll && isDelayedLoading; const isInert = ! isInfiniteScroll && !! isLoading; @@ -111,7 +98,7 @@ export default function ViewActivity< Item >( > { ...props } />
- { isInfiniteScroll && isLoading && hasInitiallyLoaded && ( + { isInfiniteScroll && isLoading && (

diff --git a/packages/dataviews/src/components/dataviews-layouts/grid/index.tsx b/packages/dataviews/src/components/dataviews-layouts/grid/index.tsx index 5858b4b008dabd..cf6a8407a4d594 100644 --- a/packages/dataviews/src/components/dataviews-layouts/grid/index.tsx +++ b/packages/dataviews/src/components/dataviews-layouts/grid/index.tsx @@ -32,7 +32,6 @@ function ViewGrid< Item >( { view, className, empty, - hasInitiallyLoaded, }: ViewGridProps< Item > ) { const isDelayedLoading = useDelayedLoading( !! isLoading ); const hasData = !! data?.length; @@ -41,9 +40,7 @@ function ViewGrid< Item >( { : null; const dataByGroup = groupField ? getDataByGroup( data, groupField ) : null; const isInfiniteScroll = view.infiniteScrollEnabled && ! dataByGroup; - const noResults = ! hasData && hasInitiallyLoaded; - - if ( noResults ) { + if ( ! hasData ) { return (
( {
); } - if ( ! hasData && ! isInfiniteScroll ) { - return null; - } const gridProps = { className: clsx( className, { 'is-refreshing': ! isInfiniteScroll && isDelayedLoading, @@ -117,7 +111,7 @@ function ViewGrid< Item >( { /> ) } - { isInfiniteScroll && isLoading && hasInitiallyLoaded && ( + { isInfiniteScroll && isLoading && (

diff --git a/packages/dataviews/src/components/dataviews-layouts/list/index.tsx b/packages/dataviews/src/components/dataviews-layouts/list/index.tsx index afb6ca18ca9e91..457afb1e00cd0e 100644 --- a/packages/dataviews/src/components/dataviews-layouts/list/index.tsx +++ b/packages/dataviews/src/components/dataviews-layouts/list/index.tsx @@ -388,7 +388,6 @@ export default function ViewList< Item >( props: ViewListProps< Item > ) { view, className, empty, - hasInitiallyLoaded, } = props; const baseId = useInstanceId( ViewList, 'view-list' ); const isDelayedLoading = useDelayedLoading( !! isLoading ); @@ -521,9 +520,7 @@ export default function ViewList< Item >( props: ViewListProps< Item > ) { const dataByGroup = hasData && groupField ? getDataByGroup( data, groupField ) : null; const isInfiniteScroll = view.infiniteScrollEnabled && ! dataByGroup; - const noResults = ! hasData && hasInitiallyLoaded; - - if ( noResults ) { + if ( ! hasData ) { return (
( props: ViewListProps< Item > ) {
); } - if ( ! hasData && ! isInfiniteScroll ) { - return null; - } // Render data grouped by field if ( hasData && groupField && dataByGroup ) { @@ -652,7 +646,7 @@ export default function ViewList< Item >( props: ViewListProps< Item > ) { ); } ) } - { isInfiniteScroll && isLoading && hasInitiallyLoaded && ( + { isInfiniteScroll && isLoading && (

diff --git a/packages/dataviews/src/components/dataviews-layouts/table/index.tsx b/packages/dataviews/src/components/dataviews-layouts/table/index.tsx index ad6aa3f432d022..f9f8fcacdca217 100644 --- a/packages/dataviews/src/components/dataviews-layouts/table/index.tsx +++ b/packages/dataviews/src/components/dataviews-layouts/table/index.tsx @@ -286,7 +286,6 @@ function ViewTable< Item >( { view, className, empty, - hasInitiallyLoaded, }: ViewTableProps< Item > ) { const { containerRef } = useContext( DataViewsContext ); const isDelayedLoading = useDelayedLoading( isLoading ); @@ -386,9 +385,7 @@ function ViewTable< Item >( { }; const isInfiniteScroll = view.infiniteScrollEnabled && ! dataByGroup; const isRtl = isRTL(); - const noResults = ! hasData && hasInitiallyLoaded; - - if ( noResults ) { + if ( ! hasData ) { return (
( {
); } - if ( ! hasData && ! isInfiniteScroll ) { - return null; - } return ( <> @@ -658,7 +652,7 @@ function ViewTable< Item >( { ) } - { isInfiniteScroll && isLoading && hasInitiallyLoaded && ( + { isInfiniteScroll && isLoading && (

diff --git a/packages/dataviews/src/dataviews/index.tsx b/packages/dataviews/src/dataviews/index.tsx index 1dcf06b1e60846..f5852648cf37e7 100644 --- a/packages/dataviews/src/dataviews/index.tsx +++ b/packages/dataviews/src/dataviews/index.tsx @@ -255,7 +255,6 @@ function DataViews< Item >( { actions, data: displayData, isLoading, - hasInitiallyLoaded, paginationInfo, selection: _selection, onChangeSelection: setSelectionWithChange, @@ -275,6 +274,7 @@ function DataViews< Item >( { setIsShowingFilter, config, empty, + hasInitiallyLoaded, hasInfiniteScrollHandler: !! infiniteScrollHandler, onReset, } } diff --git a/packages/dataviews/src/types/dataviews.ts b/packages/dataviews/src/types/dataviews.ts index 838101a45ecd79..bd3616160c9531 100644 --- a/packages/dataviews/src/types/dataviews.ts +++ b/packages/dataviews/src/types/dataviews.ts @@ -457,7 +457,6 @@ export interface ViewBaseProps< Item > { isItemClickable: ( item: Item ) => boolean; view: View; empty: ReactNode; - hasInitiallyLoaded?: boolean; } export type ViewPickerBaseProps< Item > = Omit< From 2c3fccd4772dbc4b0f2087bb80d73d9398a26b0c Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Wed, 25 Feb 2026 14:53:20 +0200 Subject: [PATCH 16/19] add `hasInitiallyLoaded` context to picker --- .../dataviews/src/components/dataviews-layouts/table/index.tsx | 2 +- packages/dataviews/src/dataviews-picker/index.tsx | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/dataviews/src/components/dataviews-layouts/table/index.tsx b/packages/dataviews/src/components/dataviews-layouts/table/index.tsx index f9f8fcacdca217..e894abe275ab91 100644 --- a/packages/dataviews/src/components/dataviews-layouts/table/index.tsx +++ b/packages/dataviews/src/components/dataviews-layouts/table/index.tsx @@ -429,7 +429,7 @@ function ViewTable< Item >( { className={ clsx( `dataviews-view-table__col-${ column }`, { - 'dataviews-view-table__col-first-data': + 'dataviews-view-table__col-first-expand': ! hasPrimaryColumn && index === columns.length - 1, } diff --git a/packages/dataviews/src/dataviews-picker/index.tsx b/packages/dataviews/src/dataviews-picker/index.tsx index a4b787a05a1352..1ac4e94a27f871 100644 --- a/packages/dataviews/src/dataviews-picker/index.tsx +++ b/packages/dataviews/src/dataviews-picker/index.tsx @@ -237,6 +237,7 @@ function DataViewsPicker< Item >( { config, itemListLabel, empty, + hasInitiallyLoaded: true, hasInfiniteScrollHandler: !! infiniteScrollHandler, } } > From 5981c0a74fe7cedc732f2dcad4f0c17f7b8c3662 Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Wed, 25 Feb 2026 15:07:33 +0200 Subject: [PATCH 17/19] also preserve pagination info --- packages/dataviews/src/dataviews/index.tsx | 11 +++++----- packages/dataviews/src/hooks/use-data.ts | 24 +++++++++++++++++++--- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/packages/dataviews/src/dataviews/index.tsx b/packages/dataviews/src/dataviews/index.tsx index f5852648cf37e7..cf5363816eeaec 100644 --- a/packages/dataviews/src/dataviews/index.tsx +++ b/packages/dataviews/src/dataviews/index.tsx @@ -237,10 +237,11 @@ function DataViews< Item >( { [ defaultLayoutsProperty ] ); - const { data: displayData, hasInitiallyLoaded } = useData( - data, - isLoading - ); + const { + data: displayData, + paginationInfo: displayPaginationInfo, + hasInitiallyLoaded, + } = useData( data, isLoading, paginationInfo ); if ( ! defaultLayouts[ view.type ] ) { return null; @@ -255,7 +256,7 @@ function DataViews< Item >( { actions, data: displayData, isLoading, - paginationInfo, + paginationInfo: displayPaginationInfo, selection: _selection, onChangeSelection: setSelectionWithChange, openedFilter, diff --git a/packages/dataviews/src/hooks/use-data.ts b/packages/dataviews/src/hooks/use-data.ts index 6a5f318fdb8fd4..a096434bc768c0 100644 --- a/packages/dataviews/src/hooks/use-data.ts +++ b/packages/dataviews/src/hooks/use-data.ts @@ -3,25 +3,43 @@ */ import { useEffect, useRef, useState } from '@wordpress/element'; +type PaginationInfo = { + totalItems: number; + totalPages: number; + infiniteScrollHandler?: () => void; +}; + export default function useData< Item >( data: Item[], - isLoading: boolean | undefined -): { data: Item[]; hasInitiallyLoaded: boolean } { + isLoading: boolean | undefined, + paginationInfo: PaginationInfo +): { + data: Item[]; + paginationInfo: PaginationInfo; + hasInitiallyLoaded: boolean; +} { const previousDataRef = useRef< Item[] >( data ); + const previousPaginationInfoRef = + useRef< PaginationInfo >( paginationInfo ); const [ hasInitiallyLoaded, setHasInitiallyLoaded ] = useState( ! isLoading ); useEffect( () => { if ( ! isLoading ) { previousDataRef.current = data; + previousPaginationInfoRef.current = paginationInfo; setHasInitiallyLoaded( true ); } - }, [ data, isLoading ] ); + }, [ data, isLoading, paginationInfo ] ); return { data: isLoading && previousDataRef.current?.length ? previousDataRef.current : data, + paginationInfo: + isLoading && previousDataRef.current?.length + ? previousPaginationInfoRef.current + : paginationInfo, hasInitiallyLoaded, }; } From ac391a93795ac148e2b41984ee4cbf7c60c7d1a5 Mon Sep 17 00:00:00 2001 From: James Koster Date: Wed, 25 Feb 2026 13:27:50 +0000 Subject: [PATCH 18/19] Animate --- .../dataviews-layouts/activity/style.scss | 5 +++++ .../components/dataviews-layouts/grid/style.scss | 5 +++++ .../components/dataviews-layouts/list/style.scss | 5 +++++ .../dataviews-layouts/table/style.scss | 5 +++++ packages/dataviews/src/dataviews/style.scss | 16 ++++++++++++++++ 5 files changed, 36 insertions(+) diff --git a/packages/dataviews/src/components/dataviews-layouts/activity/style.scss b/packages/dataviews/src/components/dataviews-layouts/activity/style.scss index 716b2134222112..826bc40dcb8494 100644 --- a/packages/dataviews/src/components/dataviews-layouts/activity/style.scss +++ b/packages/dataviews/src/components/dataviews-layouts/activity/style.scss @@ -213,6 +213,11 @@ &.is-refreshing { opacity: 0.5; + + @media not (prefers-reduced-motion) { + opacity: 1; + animation: dataviews-pulse 1s ease-in-out infinite; + } } & + .dataviews-pagination { diff --git a/packages/dataviews/src/components/dataviews-layouts/grid/style.scss b/packages/dataviews/src/components/dataviews-layouts/grid/style.scss index 0bf22fbe80a1bc..1adcaeb1f7cace 100644 --- a/packages/dataviews/src/components/dataviews-layouts/grid/style.scss +++ b/packages/dataviews/src/components/dataviews-layouts/grid/style.scss @@ -168,6 +168,11 @@ &.is-refreshing { opacity: 0.5; pointer-events: none; + + @media not (prefers-reduced-motion) { + opacity: 1; + animation: dataviews-pulse 1s ease-in-out infinite; + } } } diff --git a/packages/dataviews/src/components/dataviews-layouts/list/style.scss b/packages/dataviews/src/components/dataviews-layouts/list/style.scss index 26fee0ecfaf05f..0d126cf369e3fe 100644 --- a/packages/dataviews/src/components/dataviews-layouts/list/style.scss +++ b/packages/dataviews/src/components/dataviews-layouts/list/style.scss @@ -275,6 +275,11 @@ div.dataviews-view-list { &.is-refreshing { opacity: 0.5; pointer-events: none; + + @media not (prefers-reduced-motion) { + opacity: 1; + animation: dataviews-pulse 1s ease-in-out infinite; + } } } diff --git a/packages/dataviews/src/components/dataviews-layouts/table/style.scss b/packages/dataviews/src/components/dataviews-layouts/table/style.scss index 72a998b81b955b..ebc942411150b2 100644 --- a/packages/dataviews/src/components/dataviews-layouts/table/style.scss +++ b/packages/dataviews/src/components/dataviews-layouts/table/style.scss @@ -313,6 +313,11 @@ .dataviews-view-table.is-refreshing { opacity: 0.5; + @media not (prefers-reduced-motion) { + opacity: 1; + animation: dataviews-pulse 1s ease-in-out infinite; + } + tbody { pointer-events: none; } diff --git a/packages/dataviews/src/dataviews/style.scss b/packages/dataviews/src/dataviews/style.scss index e0878e5594718b..0d30928ec49b6a 100644 --- a/packages/dataviews/src/dataviews/style.scss +++ b/packages/dataviews/src/dataviews/style.scss @@ -46,6 +46,22 @@ .dataviews-no-results.is-refreshing { opacity: 0.5; + + @media not (prefers-reduced-motion) { + opacity: 1; + animation: dataviews-pulse 1s ease-in-out infinite; + } +} + +@keyframes dataviews-pulse { + 0%, + 100% { + opacity: 1; + } + + 50% { + opacity: 0.5; + } } .dataviews-loading-more { From 834fc4df0d7920b6b39cff184e67113602d7a8fa Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Thu, 26 Feb 2026 12:57:31 +0200 Subject: [PATCH 19/19] add loading styles to footer too --- .../src/components/dataviews-footer/index.tsx | 30 ++++++++++++++----- .../components/dataviews-footer/style.scss | 7 ++++- .../dataviews-layouts/activity/index.tsx | 3 +- .../dataviews-layouts/activity/style.scss | 8 ++--- .../dataviews-layouts/grid/style.scss | 9 ++---- .../dataviews-layouts/list/style.scss | 9 ++---- .../dataviews-layouts/table/style.scss | 12 ++------ packages/dataviews/src/dataviews/style.scss | 17 +++++++---- 8 files changed, 48 insertions(+), 47 deletions(-) diff --git a/packages/dataviews/src/components/dataviews-footer/index.tsx b/packages/dataviews/src/components/dataviews-footer/index.tsx index 949be3ad9d0181..516b6a7dab7d78 100644 --- a/packages/dataviews/src/components/dataviews-footer/index.tsx +++ b/packages/dataviews/src/components/dataviews-footer/index.tsx @@ -1,3 +1,8 @@ +/** + * External dependencies + */ +import clsx from 'clsx'; + /** * WordPress dependencies */ @@ -14,6 +19,7 @@ import { useSomeItemHasAPossibleBulkAction, } from '../dataviews-bulk-actions'; import { LAYOUT_GRID, LAYOUT_TABLE } from '../../constants'; +import { useDelayedLoading } from '../../hooks/use-delayed-loading'; const EMPTY_ARRAY: [] = []; @@ -34,6 +40,8 @@ export default function DataViewsFooter() { ! hasInfiniteScrollHandler && !! data?.length; + const isDelayedRefreshing = useDelayedLoading( !! isRefreshing ); + const hasBulkActions = useSomeItemHasAPossibleBulkAction( actions, data ) && [ LAYOUT_TABLE, LAYOUT_GRID ].includes( view.type ); @@ -48,18 +56,24 @@ export default function DataViewsFooter() { } return ( ( !! totalItems || isRefreshing ) && ( - - { hasBulkActions && } - - + + { hasBulkActions && } + + +

) ); } diff --git a/packages/dataviews/src/components/dataviews-footer/style.scss b/packages/dataviews/src/components/dataviews-footer/style.scss index 75478854c37119..ec1582134d95e4 100644 --- a/packages/dataviews/src/components/dataviews-footer/style.scss +++ b/packages/dataviews/src/components/dataviews-footer/style.scss @@ -1,6 +1,7 @@ @use "@wordpress/base-styles/colors" as *; @use "@wordpress/base-styles/variables" as *; @use "@wordpress/base-styles/z-index" as *; +@use "../../dataviews/style" as *; .dataviews-footer { position: sticky; @@ -16,10 +17,14 @@ } z-index: z-index(".dataviews-footer"); + + .is-refreshing { + @include dataviews-refreshing(); + } } @container (max-width: 560px) { - .dataviews-footer { + .dataviews-footer__content { flex-direction: column !important; .dataviews-bulk-actions-footer__container { diff --git a/packages/dataviews/src/components/dataviews-layouts/activity/index.tsx b/packages/dataviews/src/components/dataviews-layouts/activity/index.tsx index 1c3f3d28a7db75..8b7f5069a5d06b 100644 --- a/packages/dataviews/src/components/dataviews-layouts/activity/index.tsx +++ b/packages/dataviews/src/components/dataviews-layouts/activity/index.tsx @@ -46,10 +46,9 @@ export default function ViewActivity< Item >( ); } - const isRefreshing = ! isInfiniteScroll && isDelayedLoading; const isInert = ! isInfiniteScroll && !! isLoading; const wrapperClassName = clsx( 'dataviews-view-activity', className, { - 'is-refreshing': isRefreshing, + 'is-refreshing': ! isInfiniteScroll && isDelayedLoading, } ); // Convert dataByGroup entries into array. diff --git a/packages/dataviews/src/components/dataviews-layouts/activity/style.scss b/packages/dataviews/src/components/dataviews-layouts/activity/style.scss index 826bc40dcb8494..2672685c099f5b 100644 --- a/packages/dataviews/src/components/dataviews-layouts/activity/style.scss +++ b/packages/dataviews/src/components/dataviews-layouts/activity/style.scss @@ -1,5 +1,6 @@ @use "@wordpress/base-styles/colors" as *; @use "@wordpress/base-styles/variables" as *; +@use "../../../dataviews/style" as *; .dataviews-view-activity { margin: 0 0 auto; @@ -212,12 +213,7 @@ } &.is-refreshing { - opacity: 0.5; - - @media not (prefers-reduced-motion) { - opacity: 1; - animation: dataviews-pulse 1s ease-in-out infinite; - } + @include dataviews-refreshing(); } & + .dataviews-pagination { diff --git a/packages/dataviews/src/components/dataviews-layouts/grid/style.scss b/packages/dataviews/src/components/dataviews-layouts/grid/style.scss index 1adcaeb1f7cace..76355e9ca57c80 100644 --- a/packages/dataviews/src/components/dataviews-layouts/grid/style.scss +++ b/packages/dataviews/src/components/dataviews-layouts/grid/style.scss @@ -3,6 +3,7 @@ @use "@wordpress/base-styles/variables" as *; @use "@wordpress/base-styles/z-index" as *; @use "../utils/grid-items.scss" as *; +@use "../../../dataviews/style" as *; .dataviews-view-grid { padding: 0 $grid-unit-30 $grid-unit-30; @@ -166,13 +167,7 @@ } &.is-refreshing { - opacity: 0.5; - pointer-events: none; - - @media not (prefers-reduced-motion) { - opacity: 1; - animation: dataviews-pulse 1s ease-in-out infinite; - } + @include dataviews-refreshing(); } } diff --git a/packages/dataviews/src/components/dataviews-layouts/list/style.scss b/packages/dataviews/src/components/dataviews-layouts/list/style.scss index 0d126cf369e3fe..c2a95c7157132e 100644 --- a/packages/dataviews/src/components/dataviews-layouts/list/style.scss +++ b/packages/dataviews/src/components/dataviews-layouts/list/style.scss @@ -1,5 +1,6 @@ @use "@wordpress/base-styles/colors" as *; @use "@wordpress/base-styles/variables" as *; +@use "../../../dataviews/style" as *; div.dataviews-view-list { list-style-type: none; @@ -273,13 +274,7 @@ div.dataviews-view-list { } &.is-refreshing { - opacity: 0.5; - pointer-events: none; - - @media not (prefers-reduced-motion) { - opacity: 1; - animation: dataviews-pulse 1s ease-in-out infinite; - } + @include dataviews-refreshing(); } } diff --git a/packages/dataviews/src/components/dataviews-layouts/table/style.scss b/packages/dataviews/src/components/dataviews-layouts/table/style.scss index ebc942411150b2..b5046949ef23b3 100644 --- a/packages/dataviews/src/components/dataviews-layouts/table/style.scss +++ b/packages/dataviews/src/components/dataviews-layouts/table/style.scss @@ -2,6 +2,7 @@ @use "@wordpress/base-styles/mixins" as *; @use "@wordpress/base-styles/variables" as *; @use "@wordpress/base-styles/z-index" as *; +@use "../../../dataviews/style" as *; .dataviews-view-table { width: 100%; @@ -311,14 +312,5 @@ } .dataviews-view-table.is-refreshing { - opacity: 0.5; - - @media not (prefers-reduced-motion) { - opacity: 1; - animation: dataviews-pulse 1s ease-in-out infinite; - } - - tbody { - pointer-events: none; - } + @include dataviews-refreshing(); } diff --git a/packages/dataviews/src/dataviews/style.scss b/packages/dataviews/src/dataviews/style.scss index 0d30928ec49b6a..928766ac95e3af 100644 --- a/packages/dataviews/src/dataviews/style.scss +++ b/packages/dataviews/src/dataviews/style.scss @@ -2,6 +2,16 @@ @use "@wordpress/base-styles/variables" as *; @use "@wordpress/base-styles/mixins" as *; +@mixin dataviews-refreshing { + opacity: 0.5; + pointer-events: none; + + @media not (prefers-reduced-motion) { + opacity: 1; + animation: dataviews-pulse 1s ease-in-out infinite; + } +} + .dataviews-wrapper, .dataviews-picker-wrapper { height: 100%; @@ -45,12 +55,7 @@ } .dataviews-no-results.is-refreshing { - opacity: 0.5; - - @media not (prefers-reduced-motion) { - opacity: 1; - animation: dataviews-pulse 1s ease-in-out infinite; - } + @include dataviews-refreshing(); } @keyframes dataviews-pulse {