From ebb4d0b8ec83efd227519e0c076f261a448eece7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Wed, 26 Jun 2024 16:27:23 +0200 Subject: [PATCH 1/3] Make hiddenFields optional --- packages/dataviews/src/types.ts | 2 +- packages/dataviews/src/view-grid.tsx | 2 +- packages/dataviews/src/view-list.tsx | 2 +- packages/dataviews/src/view-table.tsx | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/dataviews/src/types.ts b/packages/dataviews/src/types.ts index 8c1819b3a7c67..b01394c7f846a 100644 --- a/packages/dataviews/src/types.ts +++ b/packages/dataviews/src/types.ts @@ -216,7 +216,7 @@ interface ViewBase { /** * The hidden fields. */ - hiddenFields: string[]; + hiddenFields?: string[]; } export interface ViewTable extends ViewBase { diff --git a/packages/dataviews/src/view-grid.tsx b/packages/dataviews/src/view-grid.tsx index 77ac3c9273852..4538ab145d213 100644 --- a/packages/dataviews/src/view-grid.tsx +++ b/packages/dataviews/src/view-grid.tsx @@ -206,7 +206,7 @@ export default function ViewGrid< Item extends AnyItem >( { const { visibleFields, badgeFields } = fields.reduce( ( accumulator: Record< string, NormalizedField< Item >[] >, field ) => { if ( - view.hiddenFields.includes( field.id ) || + view.hiddenFields?.includes( field.id ) || [ view.layout.mediaField, view.layout.primaryField ].includes( field.id ) diff --git a/packages/dataviews/src/view-list.tsx b/packages/dataviews/src/view-list.tsx index 295c3d28856eb..eb2b9c6c077a6 100644 --- a/packages/dataviews/src/view-list.tsx +++ b/packages/dataviews/src/view-list.tsx @@ -329,7 +329,7 @@ export default function ViewList< Item extends AnyItem >( ); const visibleFields = fields.filter( ( field ) => - ! view.hiddenFields.includes( field.id ) && + ! view.hiddenFields?.includes( field.id ) && ! [ view.layout.primaryField, view.layout.mediaField ].includes( field.id ) diff --git a/packages/dataviews/src/view-table.tsx b/packages/dataviews/src/view-table.tsx index 2ddb09e2640a0..ae6d48e2df3ca 100644 --- a/packages/dataviews/src/view-table.tsx +++ b/packages/dataviews/src/view-table.tsx @@ -223,7 +223,7 @@ const _HeaderMenu = forwardRef( function HeaderMenu< Item extends AnyItem >( onHide( field ); onChangeView( { ...view, - hiddenFields: view.hiddenFields.concat( + hiddenFields: view.hiddenFields?.concat( field.id ), } ); @@ -473,7 +473,7 @@ function ViewTable< Item extends AnyItem >( { }; const visibleFields = fields.filter( ( field ) => - ! view.hiddenFields.includes( field.id ) && + ! view.hiddenFields?.includes( field.id ) && ! [ view.layout.mediaField ].includes( field.id ) ); const hasData = !! data?.length; From 468c294f6668d8835b4af652b9a0cfc8c376e3f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Wed, 26 Jun 2024 16:47:57 +0200 Subject: [PATCH 2/3] Remove empty hiddenFields array, as it is no longer necessary --- packages/edit-site/src/components/page-patterns/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/edit-site/src/components/page-patterns/index.js b/packages/edit-site/src/components/page-patterns/index.js index 7080ff8f185f4..0a6a4469cef4e 100644 --- a/packages/edit-site/src/components/page-patterns/index.js +++ b/packages/edit-site/src/components/page-patterns/index.js @@ -76,7 +76,6 @@ const DEFAULT_VIEW = { search: '', page: 1, perPage: 20, - hiddenFields: [], layout: { ...defaultConfigPerViewType[ LAYOUT_GRID ], }, From 03ef404f206c274e6ea4e36b2aa7808e68963820 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Wed, 26 Jun 2024 18:19:15 +0200 Subject: [PATCH 3/3] Fix concat --- packages/dataviews/src/view-table.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/dataviews/src/view-table.tsx b/packages/dataviews/src/view-table.tsx index ae6d48e2df3ca..66e59a8ebb423 100644 --- a/packages/dataviews/src/view-table.tsx +++ b/packages/dataviews/src/view-table.tsx @@ -223,9 +223,9 @@ const _HeaderMenu = forwardRef( function HeaderMenu< Item extends AnyItem >( onHide( field ); onChangeView( { ...view, - hiddenFields: view.hiddenFields?.concat( - field.id - ), + hiddenFields: ( + view.hiddenFields ?? [] + ).concat( field.id ), } ); } } >