import { useState } from 'react'; import type { ReactNode } from 'react'; import { mergeToPreviousGroup, RecastScene, useRecastBlockScene, useRecastKanbanGroupBy, } from '@toeverything/components/editor-core'; import { Popover, useTheme, Tooltip } from '@toeverything/components/ui'; import type { AsyncBlock, BlockEditor } from '@toeverything/framework/virgo'; import { Filter } from './components/filter'; import { Sorter } from './components/sorter'; import { GroupPanel } from './components/group-panel/GroupPanel'; import { IconButton } from './components/IconButton'; import { Line } from './components/Line'; import { TodoListIcon, KanBanIcon, TableIcon, FilterIcon, SortIcon, FullScreenIcon, GroupIcon, GroupByIcon, } from '@toeverything/components/icons'; import { PANEL_CONFIG, SCENE_CONFIG } from './config'; import type { ActivePanel } from './types'; import { useFlag } from '@toeverything/datasource/feature-flags'; import { GroupBy } from './components/group-by/GroupBy'; const GroupMenuWrapper = ({ block, editor, children, }: { block: AsyncBlock; editor: BlockEditor; children: ReactNode; }) => { /* feature flag: sprint14 close Filter、Sort feature */ const filterSorterFlag = useFlag('FilterSorter', false); const { scene, setPage, setKanban, setTable } = useRecastBlockScene(); const { groupBy } = useRecastKanbanGroupBy(); const theme = useTheme(); /* state: add active-style */ const [activePanel, setActivePanel] = useState( PANEL_CONFIG.GROUP_BY ); /* state: open panel */ const [openPanel, setOpenPanel] = useState(null); /** * close panel state/active state */ const closePanel = () => { if (!groupBy?.id) { setActivePanel(null); } setOpenPanel(null); }; /** * change open panel: if target is current, close panel; else change * update active panel * @param panel */ const onPanelChange = (panel: ActivePanel) => { if (openPanel === panel) { return closePanel(); } setActivePanel(panel); setOpenPanel(panel); }; return ( Text View Kanban { // // Closed beta period temporarily // filterSorterFlag && ( // // // Table View // // ) Table } Calendar Timeline BI { // Closed beta period temporarily filterSorterFlag && ( onPanelChange(PANEL_CONFIG.FILTER) } > Filter {openPanel === PANEL_CONFIG.FILTER && ( )} ) } { // Closed beta period temporarily filterSorterFlag && currentView.type === RecastScene.Kanban && ( onPanelChange(PANEL_CONFIG.SORTER) } > Sort {openPanel === PANEL_CONFIG.SORTER && ( )} ) } {scene === RecastScene.Kanban && ( onPanelChange(PANEL_CONFIG.GROUP_BY)} > GroupBy {openPanel === PANEL_CONFIG.GROUP_BY && ( )} )} {filterSorterFlag && } { // Closed beta period temporarily filterSorterFlag && ( ) } { // Closed beta period temporarily filterSorterFlag && ( { await mergeToPreviousGroup(block); }} > ) } } > {children} ); }; export { GroupMenuWrapper };