Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataViews: make view.hiddenFields optional #62876

Merged
merged 3 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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[];
Copy link
Contributor

Choose a reason for hiding this comment

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

I've been reading our types lately and this one actually stood out to me :P

I think it makes more sense to have "visibleFields" rather than "hiddenFields" as we move forward. I'm pretty sure most entities will have a lot more fields that what we currently have and an allow list would be better.

Omitting it could have the same effect as today when you omit hiddenFields.

Not a concern for this PR though, just a thought that I had.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that's a good point: post types have a lot of metadata and if we aim to share the field definition between a view and a form (e.g.: details panel), a lot of the fields would be hidden in the view.

}

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
4 changes: 2 additions & 2 deletions packages/dataviews/src/view-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ const _HeaderMenu = forwardRef( function HeaderMenu< Item extends AnyItem >(
onHide( field );
onChangeView( {
...view,
hiddenFields: view.hiddenFields.concat(
hiddenFields: view.hiddenFields?.concat(
oandregal marked this conversation as resolved.
Show resolved Hide resolved
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
Loading