diff --git a/packages/dataviews/src/components/dataviews-view-config/index.tsx b/packages/dataviews/src/components/dataviews-view-config/index.tsx index ccc6a49efa9261..54edf0e8a6e045 100644 --- a/packages/dataviews/src/components/dataviews-view-config/index.tsx +++ b/packages/dataviews/src/components/dataviews-view-config/index.tsx @@ -255,42 +255,84 @@ function ItemsPerPageControl() { ); } -function BaseFieldItem( { - identifier, +function PreviewOptions( { + previewOptions, + onChangePreviewOption, + onMenuOpenChange, + activeOption, +}: { + previewOptions?: Array< { label: string; id: string } >; + onChangePreviewOption?: ( newPreviewOption: string ) => void; + onMenuOpenChange: ( isOpen: boolean ) => void; + activeOption?: string; +} ) { + return ( +
+ ); +} +function FieldItem( { + field, label, description, isVisible, isFirst, isLast, canMove = true, - canHide = true, - isInteracting = false, onToggleVisibility, onMoveUp, onMoveDown, - children, + previewOptions, + onChangePreviewOption, }: { - identifier: string; - label: string; + field: NormalizedField< any >; + label?: string; description?: string; isVisible: boolean; isFirst?: boolean; isLast?: boolean; canMove?: boolean; - canHide?: boolean; - isInteracting?: boolean; onToggleVisibility?: () => void; onMoveUp?: () => void; onMoveDown?: () => void; - children?: ReactNode; + previewOptions?: Array< { label: string; id: string } >; + onChangePreviewOption?: ( newPreviewOption: string ) => void; } ) { + const [ isChangingPreviewOption, setIsChangingPreviewOption ] = + useState< boolean >( false ); + const focusVisibilityField = () => { // Focus the visibility button to avoid focus loss. // Our code is safe against the component being unmounted, so we don't need to worry about cleaning the timeout. // eslint-disable-next-line @wordpress/react-no-unsafe-timeout setTimeout( () => { const element = document.querySelector( - `.dataviews-field-control__field-${ identifier } .dataviews-field-control__field-visibility-button` + `.dataviews-field-control__field-${ field.id } .dataviews-field-control__field-visibility-button` ); if ( element instanceof HTMLElement ) { element.focus(); @@ -304,23 +346,25 @@ function BaseFieldItem( { expanded className={ clsx( 'dataviews-field-control__field', - `dataviews-field-control__field-${ identifier }`, + `dataviews-field-control__field-${ field.id }`, // The actions are hidden when the mouse is not hovering the item, or focus // is outside the item. // For actions that require a popover, a menu etc, that would mean that when the interactive element // opens and the focus goes there the actions would be hidden. // To avoid that we add a class to the item, that makes sure actions are visible while there is some // interaction with the item. - { 'is-interacting': isInteracting } + { 'is-interacting': isChangingPreviewOption } ) } justify="flex-start" > - { ! canMove && ! canHide &&