Skip to content

Commit

Permalink
Refactor dataviews view config menu (#67637)
Browse files Browse the repository at this point in the history
  • Loading branch information
ciampo authored Dec 11, 2024
1 parent 6078c61 commit 13e1f6c
Showing 1 changed file with 45 additions and 38 deletions.
83 changes: 45 additions & 38 deletions packages/dataviews/src/components/dataviews-view-config/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,45 +67,52 @@ function ViewTypeMenu( {
}
const activeView = VIEW_LAYOUTS.find( ( v ) => view.type === v.type );
return (
<Menu
trigger={
<Button
size="compact"
icon={ activeView?.icon }
label={ __( 'Layout' ) }
/>
}
>
{ availableLayouts.map( ( layout ) => {
const config = VIEW_LAYOUTS.find( ( v ) => v.type === layout );
if ( ! config ) {
return null;
<Menu>
<Menu.TriggerButton
render={
<Button
size="compact"
icon={ activeView?.icon }
label={ __( 'Layout' ) }
/>
}
return (
<Menu.RadioItem
key={ layout }
value={ layout }
name="view-actions-available-view"
checked={ layout === view.type }
hideOnClick
onChange={ ( e: ChangeEvent< HTMLInputElement > ) => {
switch ( e.target.value ) {
case 'list':
case 'grid':
case 'table':
return onChangeView( {
...view,
type: e.target.value,
...defaultLayouts[ e.target.value ],
} );
}
warning( 'Invalid dataview' );
} }
>
<Menu.ItemLabel>{ config.label }</Menu.ItemLabel>
</Menu.RadioItem>
);
} ) }
/>
<Menu.Popover>
{ availableLayouts.map( ( layout ) => {
const config = VIEW_LAYOUTS.find(
( v ) => v.type === layout
);
if ( ! config ) {
return null;
}
return (
<Menu.RadioItem
key={ layout }
value={ layout }
name="view-actions-available-view"
checked={ layout === view.type }
hideOnClick
onChange={ (
e: ChangeEvent< HTMLInputElement >
) => {
switch ( e.target.value ) {
case 'list':
case 'grid':
case 'table':
return onChangeView( {
...view,
type: e.target.value,
...defaultLayouts[ e.target.value ],
} );
}
warning( 'Invalid dataview' );
} }
>
<Menu.ItemLabel>{ config.label }</Menu.ItemLabel>
</Menu.RadioItem>
);
} ) }
</Menu.Popover>
</Menu>
);
}
Expand Down

0 comments on commit 13e1f6c

Please sign in to comment.