Skip to content

Commit

Permalink
Retain field formats
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Jul 5, 2024
1 parent 0f1a06e commit c2b563b
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/dataviews/src/view-actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ interface FieldsVisibilityMenuProps< Item > {
view: View;
onChangeView: ( view: View ) => void;
fields: NormalizedField< Item >[];
defaultFields?: Record< string, FieldRenderConfig[] >;
}

interface SortMenuProps< Item > {
Expand Down Expand Up @@ -171,6 +172,7 @@ function FieldsVisibilityMenu< Item >( {
view,
onChangeView,
fields,
defaultFields,
}: FieldsVisibilityMenuProps< Item > ) {
const fieldRenderConfigs = normalizeFieldRenderConfigs(
view.fields,
Expand All @@ -185,6 +187,10 @@ function FieldsVisibilityMenu< Item >( {
if ( ! hidableFields?.length ) {
return null;
}
const normalizedDefaultFields = normalizeFieldRenderConfigs(
defaultFields?.[ view.type ],
[]
);
return (
<DropdownMenu
trigger={
Expand All @@ -205,14 +211,20 @@ function FieldsVisibilityMenu< Item >( {
value={ field.id }
checked={ isVisible }
onChange={ () => {
const fieldFormat = normalizedDefaultFields.find(
( f ) => f.field === field.id
);
onChangeView( {
...view,
fields: isVisible
? fieldRenderConfigs.filter(
( fieldRender ) =>
fieldRender.field !== field.id
)
: [ ...fieldRenderConfigs, field.id ],
: [
...fieldRenderConfigs,
fieldFormat ?? field.id,
],
} );
} }
>
Expand Down Expand Up @@ -347,6 +359,7 @@ function _ViewActions< Item >( {
fields={ fields }
view={ view }
onChangeView={ onChangeView }
defaultFields={ defaultFields }
/>
<PageSizeMenu view={ view } onChangeView={ onChangeView } />
</DropdownMenuGroup>
Expand Down

0 comments on commit c2b563b

Please sign in to comment.