import React from 'react'; import { useIntl } from 'react-intl'; import { Menu, MenuItem, SubmenuTrigger } from 'react-aria-components'; import { ChevronrightIcon } from '@plone/components'; import { Popover, type PopoverProps } from '../Popover'; interface Props extends Omit { indexes: { [index: string]: { label: string; sort_on?: string; }; }; sortItems: (index: string) => void; } const sortIndexes = [ // TODO "id" is a reserved key for table rows, so we cannot add the "ID" column at this time // 'id', 'sortable_title', 'EffectiveDate', 'CreationDate', 'ModificationDate', 'portal_type', ]; interface MenuItem { id: string; name: string; children?: MenuItem[]; } export function RearrangePopover({ indexes, sortItems, ...popoverProps }: Props) { const intl = useIntl(); const menuItems: MenuItem[] = sortIndexes.map((index) => ({ id: index, name: intl.formatMessage({ id: indexes[index].label }), children: [ { id: `${indexes[index].sort_on}|ascending`, name: intl.formatMessage({ id: 'Ascending' }), }, { id: `${indexes[index].sort_on}|descending`, name: intl.formatMessage({ id: 'Descending' }), }, ], })); return (

{intl.formatMessage({ id: 'Rearrange items by…' })}

{function renderSubmenu(item) { if (item.children) { return ( `react-aria-MenuItem rearrange-menu-item ${ isFocused ? 'focused' : '' } ${isOpen ? 'open' : ''}` } > {({ hasSubmenu }) => ( <> {item.name} {hasSubmenu && } )} { sortItems(id.toString()); }} > {(item) => renderSubmenu(item)} ); } else { return {item.name}; } }}
); }