refactor(view): migrate group menu
This commit is contained in:
@@ -3,8 +3,7 @@ import {
|
|||||||
mergeToPreviousGroup,
|
mergeToPreviousGroup,
|
||||||
RecastScene,
|
RecastScene,
|
||||||
RecastView,
|
RecastView,
|
||||||
useRecastBlockScene,
|
useCurrentView,
|
||||||
useRecastKanbanGroupBy,
|
|
||||||
useRecastView,
|
useRecastView,
|
||||||
} from '@toeverything/components/editor-core';
|
} from '@toeverything/components/editor-core';
|
||||||
import {
|
import {
|
||||||
@@ -29,7 +28,7 @@ import { GroupPanel } from './components/group-panel/GroupPanel';
|
|||||||
import { IconButton } from './components/IconButton';
|
import { IconButton } from './components/IconButton';
|
||||||
import { Line } from './components/Line';
|
import { Line } from './components/Line';
|
||||||
import { Sorter } from './components/sorter';
|
import { Sorter } from './components/sorter';
|
||||||
import { PANEL_CONFIG, SCENE_CONFIG } from './config';
|
import { PANEL_CONFIG } from './config';
|
||||||
import type { ActivePanel } from './types';
|
import type { ActivePanel } from './types';
|
||||||
|
|
||||||
const VIEW_ICON_MAP: Record<RecastView['type'], ReactElement> = {
|
const VIEW_ICON_MAP: Record<RecastView['type'], ReactElement> = {
|
||||||
@@ -39,14 +38,14 @@ const VIEW_ICON_MAP: Record<RecastView['type'], ReactElement> = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const ViewsMenu = () => {
|
const ViewsMenu = () => {
|
||||||
const { currentView, recastViews, changeView } = useRecastView();
|
const { currentView, recastViews, setCurrentView } = useRecastView();
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{recastViews.map(view => (
|
{recastViews.map(view => (
|
||||||
<IconButton
|
<IconButton
|
||||||
key={view.id}
|
key={view.id}
|
||||||
active={view.id === currentView.id}
|
active={view.id === currentView.id}
|
||||||
onClick={() => changeView(view)}
|
onClick={() => setCurrentView(view)}
|
||||||
>
|
>
|
||||||
{VIEW_ICON_MAP[view.type]}
|
{VIEW_ICON_MAP[view.type]}
|
||||||
{view.name}
|
{view.name}
|
||||||
@@ -67,24 +66,21 @@ const GroupMenuWrapper = ({
|
|||||||
}) => {
|
}) => {
|
||||||
/* feature flag: sprint14 close Filter、Sort feature */
|
/* feature flag: sprint14 close Filter、Sort feature */
|
||||||
const filterSorterFlag = useFlag('FilterSorter', false);
|
const filterSorterFlag = useFlag('FilterSorter', false);
|
||||||
const { scene, setPage, setKanban, setTable } = useRecastBlockScene();
|
const [currentView] = useCurrentView();
|
||||||
const { groupBy } = useRecastKanbanGroupBy();
|
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
||||||
/* state: add active-style */
|
/* state: add active-style */
|
||||||
const [activePanel, setActivePanel] = useState<ActivePanel>(
|
const [activePanel, setActivePanel] = useState<ActivePanel | null>(
|
||||||
PANEL_CONFIG.GROUP_BY
|
PANEL_CONFIG.GROUP_BY
|
||||||
);
|
);
|
||||||
/* state: open panel */
|
/* state: open panel */
|
||||||
const [openPanel, setOpenPanel] = useState<ActivePanel>(null);
|
const [openPanel, setOpenPanel] = useState<ActivePanel | null>(null);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* close panel state/active state
|
* close panel state/active state
|
||||||
*/
|
*/
|
||||||
const closePanel = () => {
|
const closePanel = () => {
|
||||||
if (!groupBy?.id) {
|
setActivePanel(null);
|
||||||
setActivePanel(null);
|
|
||||||
}
|
|
||||||
setOpenPanel(null);
|
setOpenPanel(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -108,21 +104,6 @@ const GroupMenuWrapper = ({
|
|||||||
zIndex={theme.affine.zIndex.header - 1}
|
zIndex={theme.affine.zIndex.header - 1}
|
||||||
content={
|
content={
|
||||||
<GroupPanel>
|
<GroupPanel>
|
||||||
<IconButton
|
|
||||||
active={scene === SCENE_CONFIG.PAGE}
|
|
||||||
onClick={setPage}
|
|
||||||
>
|
|
||||||
<TodoListIcon fontSize="small" />
|
|
||||||
<span>Text View</span>
|
|
||||||
</IconButton>
|
|
||||||
<IconButton
|
|
||||||
active={scene === SCENE_CONFIG.KANBAN}
|
|
||||||
onClick={setKanban}
|
|
||||||
>
|
|
||||||
<KanBanIcon fontSize="small" />
|
|
||||||
Kanban
|
|
||||||
</IconButton>
|
|
||||||
|
|
||||||
<ViewsMenu />
|
<ViewsMenu />
|
||||||
<IconButton
|
<IconButton
|
||||||
active={activePanel === PANEL_CONFIG.ADD_VIEW}
|
active={activePanel === PANEL_CONFIG.ADD_VIEW}
|
||||||
@@ -146,38 +127,26 @@ const GroupMenuWrapper = ({
|
|||||||
// </IconButton>
|
// </IconButton>
|
||||||
// )
|
// )
|
||||||
<CommingSoon>
|
<CommingSoon>
|
||||||
<IconButton
|
<IconButton style={{ cursor: 'not-allowed' }}>
|
||||||
active={scene === SCENE_CONFIG.TABLE}
|
|
||||||
style={{ cursor: 'not-allowed' }}
|
|
||||||
>
|
|
||||||
<TableIcon fontSize="small" />
|
<TableIcon fontSize="small" />
|
||||||
Table
|
Table
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</CommingSoon>
|
</CommingSoon>
|
||||||
}
|
}
|
||||||
<CommingSoon>
|
<CommingSoon>
|
||||||
<IconButton
|
<IconButton style={{ cursor: 'not-allowed' }}>
|
||||||
active={scene === SCENE_CONFIG.TABLE}
|
|
||||||
style={{ cursor: 'not-allowed' }}
|
|
||||||
>
|
|
||||||
<KanBanIcon fontSize="small" />
|
<KanBanIcon fontSize="small" />
|
||||||
Calendar
|
Calendar
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</CommingSoon>
|
</CommingSoon>
|
||||||
<CommingSoon>
|
<CommingSoon>
|
||||||
<IconButton
|
<IconButton style={{ cursor: 'not-allowed' }}>
|
||||||
active={scene === SCENE_CONFIG.TABLE}
|
|
||||||
style={{ cursor: 'not-allowed' }}
|
|
||||||
>
|
|
||||||
<TableIcon fontSize="small" />
|
<TableIcon fontSize="small" />
|
||||||
Timeline
|
Timeline
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</CommingSoon>
|
</CommingSoon>
|
||||||
<CommingSoon>
|
<CommingSoon>
|
||||||
<IconButton
|
<IconButton style={{ cursor: 'not-allowed' }}>
|
||||||
active={scene === SCENE_CONFIG.TABLE}
|
|
||||||
style={{ cursor: 'not-allowed' }}
|
|
||||||
>
|
|
||||||
<KanBanIcon fontSize="small" />
|
<KanBanIcon fontSize="small" />
|
||||||
BI
|
BI
|
||||||
</IconButton>
|
</IconButton>
|
||||||
@@ -227,9 +196,9 @@ const GroupMenuWrapper = ({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
{scene === RecastScene.Kanban && (
|
{currentView.type === RecastScene.Kanban && (
|
||||||
<IconButton
|
<IconButton
|
||||||
active={activePanel === PANEL_CONFIG.GROUP_BY}
|
active={true}
|
||||||
onClick={() => onPanelChange(PANEL_CONFIG.GROUP_BY)}
|
onClick={() => onPanelChange(PANEL_CONFIG.GROUP_BY)}
|
||||||
>
|
>
|
||||||
<GroupByIcon fontSize="small" />
|
<GroupByIcon fontSize="small" />
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
import {
|
import {
|
||||||
addNewGroup,
|
addNewGroup,
|
||||||
RecastScene,
|
RecastScene,
|
||||||
|
useCurrentView,
|
||||||
useOnSelect,
|
useOnSelect,
|
||||||
useRecastBlockScene,
|
|
||||||
} from '@toeverything/components/editor-core';
|
} from '@toeverything/components/editor-core';
|
||||||
|
import { styled } from '@toeverything/components/ui';
|
||||||
|
import type { CreateView } from '@toeverything/framework/virgo';
|
||||||
|
import type { ComponentType, FC } from 'react';
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { GroupMenuWrapper } from './GroupMenu';
|
||||||
import { SceneKanban } from './scene-kanban';
|
import { SceneKanban } from './scene-kanban';
|
||||||
import { ScenePage } from './ScenePage';
|
import { ScenePage } from './ScenePage';
|
||||||
import { SceneTable } from './SceneTable';
|
import { SceneTable } from './SceneTable';
|
||||||
import { GroupMenuWrapper } from './GroupMenu';
|
|
||||||
import { styled } from '@toeverything/components/ui';
|
|
||||||
import { useState } from 'react';
|
|
||||||
import type { FC, ComponentType } from 'react';
|
|
||||||
import type { CreateView } from '@toeverything/framework/virgo';
|
|
||||||
|
|
||||||
const SceneMap: Record<RecastScene, ComponentType<CreateView>> = {
|
const SceneMap: Record<RecastScene, ComponentType<CreateView>> = {
|
||||||
page: ScenePage,
|
page: ScenePage,
|
||||||
@@ -78,7 +78,7 @@ const GroupContainer = styled('div')<{ isSelect?: boolean }>(
|
|||||||
|
|
||||||
export const GroupView: FC<CreateView> = props => {
|
export const GroupView: FC<CreateView> = props => {
|
||||||
const { block, editor } = props;
|
const { block, editor } = props;
|
||||||
const { scene } = useRecastBlockScene();
|
const [currentView] = useCurrentView();
|
||||||
const [groupIsSelect, setGroupIsSelect] = useState(false);
|
const [groupIsSelect, setGroupIsSelect] = useState(false);
|
||||||
|
|
||||||
useOnSelect(block.id, (groupIsSelect: boolean) => {
|
useOnSelect(block.id, (groupIsSelect: boolean) => {
|
||||||
@@ -89,9 +89,9 @@ export const GroupView: FC<CreateView> = props => {
|
|||||||
addNewGroup(editor, block, true);
|
addNewGroup(editor, block, true);
|
||||||
};
|
};
|
||||||
|
|
||||||
const View = SceneMap[scene];
|
const View = SceneMap[currentView.type];
|
||||||
if (!View) {
|
if (!View) {
|
||||||
return <>Group scene not found: {scene}!</>;
|
return <>Group scene not found: {currentView.type}!</>;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user