From 74034eb33e7f7c6fe53510b7d4223c147f49497d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Thu, 8 Feb 2024 16:05:10 +0100 Subject: [PATCH 1/2] Fix dataviews storybook --- packages/dataviews/src/stories/index.story.js | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/packages/dataviews/src/stories/index.story.js b/packages/dataviews/src/stories/index.story.js index e0bea0c92c2b2..2071335f69073 100644 --- a/packages/dataviews/src/stories/index.story.js +++ b/packages/dataviews/src/stories/index.story.js @@ -6,10 +6,12 @@ import { useState, useMemo, useCallback } from '@wordpress/element'; /** * Internal dependencies */ -import { DataViews, LAYOUT_GRID, LAYOUT_TABLE } from '../index'; - +import { DataViews } from '../index'; import { DEFAULT_VIEW, actions, data } from './fixtures'; +const LAYOUT_GRID = 'grid'; +const LAYOUT_TABLE = 'table'; + const meta = { title: 'DataViews (Experimental)/DataViews', component: DataViews, @@ -17,7 +19,9 @@ const meta = { export default meta; const defaultConfigPerViewType = { - [ LAYOUT_TABLE ]: {}, + [ LAYOUT_TABLE ]: { + primaryField: 'title', + }, [ LAYOUT_GRID ]: { mediaField: 'image', primaryField: 'title', @@ -100,23 +104,19 @@ export const Default = ( props ) => { }; }, [ view ] ); const onChangeView = useCallback( - ( viewUpdater ) => { - let updatedView = - typeof viewUpdater === 'function' - ? viewUpdater( view ) - : viewUpdater; - if ( updatedView.type !== view.type ) { - updatedView = { - ...updatedView, + ( newView ) => { + if ( newView.type !== view.type ) { + newView = { + ...newView, layout: { - ...defaultConfigPerViewType[ updatedView.type ], + ...defaultConfigPerViewType[ newView.type ], }, }; } - setView( updatedView ); + setView( newView ); }, - [ view, setView ] + [ view.type, setView ] ); return ( { }; Default.args = { actions, - getItemId: ( item ) => item.id, - isLoading: false, supportedLayouts: [ LAYOUT_TABLE, LAYOUT_GRID ], }; From f088e32572f3bdb238a8bdde03403c396347c1d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Thu, 8 Feb 2024 16:08:52 +0100 Subject: [PATCH 2/2] Import from constants --- packages/dataviews/src/stories/index.story.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/dataviews/src/stories/index.story.js b/packages/dataviews/src/stories/index.story.js index 2071335f69073..e7fbfbbe554b0 100644 --- a/packages/dataviews/src/stories/index.story.js +++ b/packages/dataviews/src/stories/index.story.js @@ -8,9 +8,7 @@ import { useState, useMemo, useCallback } from '@wordpress/element'; */ import { DataViews } from '../index'; import { DEFAULT_VIEW, actions, data } from './fixtures'; - -const LAYOUT_GRID = 'grid'; -const LAYOUT_TABLE = 'table'; +import { LAYOUT_GRID, LAYOUT_TABLE } from '../constants'; const meta = { title: 'DataViews (Experimental)/DataViews',