Skip to content

Commit

Permalink
DataViews: make view.hiddenFields optional (#62876)
Browse files Browse the repository at this point in the history
Co-authored-by: oandregal <oandregal@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
  • Loading branch information
3 people authored Jun 26, 2024
1 parent 4ef2a62 commit 4b49d83
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/dataviews/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ interface ViewBase {
/**
* The hidden fields.
*/
hiddenFields: string[];
hiddenFields?: string[];
}

export interface ViewTable extends ViewBase {
Expand Down
2 changes: 1 addition & 1 deletion packages/dataviews/src/view-grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
2 changes: 1 addition & 1 deletion packages/dataviews/src/view-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
8 changes: 4 additions & 4 deletions packages/dataviews/src/view-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 ),
} );
} }
>
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion packages/edit-site/src/components/page-patterns/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ const DEFAULT_VIEW = {
search: '',
page: 1,
perPage: 20,
hiddenFields: [],
layout: {
...defaultConfigPerViewType[ LAYOUT_GRID ],
},
Expand Down

1 comment on commit 4b49d83

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 4b49d83.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/9683681097
📝 Reported issues:

Please sign in to comment.