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..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 ), } ); } } > @@ -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; 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 ], },