diff --git a/packages/dataviews/src/components/dataviews-view-config/index.tsx b/packages/dataviews/src/components/dataviews-view-config/index.tsx index 3fb182ff0f4c7..b360979c144b8 100644 --- a/packages/dataviews/src/components/dataviews-view-config/index.tsx +++ b/packages/dataviews/src/components/dataviews-view-config/index.tsx @@ -11,7 +11,7 @@ import { __experimentalDropdownContentWrapper as DropdownContentWrapper, Dropdown, __experimentalToggleGroupControl as ToggleGroupControl, - // __experimentalToggleGroupControlOption as ToggleGroupControlOption, + __experimentalToggleGroupControlOption as ToggleGroupControlOption, __experimentalToggleGroupControlOptionIcon as ToggleGroupControlOptionIcon, SelectControl, __experimentalItemGroup as ItemGroup, @@ -200,92 +200,84 @@ function SortDirectionControl() { ); } -const PAGE_SIZE_VALUES = [ '10', '20', '50', '100' ]; +const PAGE_SIZE_VALUES = [ 10, 20, 50, 100 ]; function ItemsPerPageControl() { const { view, onChangeView } = useContext( DataViewsContext ); return ( - ( { - value, - label: value, - } ) ) } + value={ view.perPage || 10 } + disabled={ ! view?.sort?.field } onChange={ ( newItemsPerPage ) => { + const newItemsPerPageNumber = + typeof newItemsPerPage === 'number' || + newItemsPerPage === undefined + ? newItemsPerPage + : parseInt( newItemsPerPage, 10 ); onChangeView( { ...view, - perPage: parseInt( newItemsPerPage, 10 ), + perPage: newItemsPerPageNumber, page: 1, } ); } } - /> + > + { PAGE_SIZE_VALUES.map( ( value ) => { + return ( + + ); + } ) } + ); - // return ( - // { - // const newItemsPerPageNumber = - // typeof newItemsPerPage === 'number' || - // newItemsPerPage === undefined - // ? newItemsPerPage - // : parseInt( newItemsPerPage, 10 ); - // onChangeView( { - // ...view, - // perPage: newItemsPerPageNumber, - // page: 1, - // } ); - // } } - // > - // { PAGE_SIZE_VALUES.map( ( value ) => { - // return ( - // - // ); - // } ) } - // - // ); } -const densityPickerOptions = [ - { - value: 'comfortable', - label: _x( 'Comfortable', 'Density option for DataView layout' ), - }, - { - value: 'balanced', - label: _x( 'Balanced', 'Density option for DataView layout' ), - }, - { - value: 'compact', - label: _x( 'Compact', 'Density option for DataView layout' ), - }, -]; function DensityPicker() { const { view, onChangeView } = useContext( DataViewsContext ); + if ( + ! VIEW_LAYOUTS.find( ( layout ) => layout.type === view.type ) + ?.supportsDensity + ) { + return null; + } return ( - { onChangeView( { ...view, density: value as Density, } ); } } - /> + isBlock + > + + + + ); } @@ -567,10 +559,6 @@ function DataviewsViewConfigDropdown() { _DataViewsViewConfig, 'dataviews-view-config-dropdown' ); - const { view } = useContext( DataViewsContext ); - const layoutSupportsDensity = !! VIEW_LAYOUTS.find( - ( layout ) => layout.type === view.type - )?.supportsDensity; return ( - { ! layoutSupportsDensity ? ( - - ) : ( - - - - - ) } + +