From 72bee4d457e1285c46b46991708b8182ba2229b7 Mon Sep 17 00:00:00 2001 From: lyp000119 <2319460338@qq.com> Date: Tue, 17 Oct 2023 15:16:19 +0800 Subject: [PATCH 1/2] i18n: Add translation for StoryPageAddModal --- frontend/src/locales/en/translation.json | 1 + frontend/src/locales/zh/translation.json | 1 + 2 files changed, 2 insertions(+) diff --git a/frontend/src/locales/en/translation.json b/frontend/src/locales/en/translation.json index eefa32b46..0e44a92c7 100644 --- a/frontend/src/locales/en/translation.json +++ b/frontend/src/locales/en/translation.json @@ -1030,6 +1030,7 @@ "enterHere": "Enter here", "storyName": "Name", "storyDescription": "Description", + "addStoryPage": "Add Story Page", "format": "Format", "interval": "Interval", "requiredWidgetName": "Widget name cannot be empty, please input a name", diff --git a/frontend/src/locales/zh/translation.json b/frontend/src/locales/zh/translation.json index 546d7fddc..725b2c255 100644 --- a/frontend/src/locales/zh/translation.json +++ b/frontend/src/locales/zh/translation.json @@ -1028,6 +1028,7 @@ "enterHere": "请输入", "storyName": "名称", "storyDescription": "描述", + "addStoryPage": "添加故事页面", "format": "格式", "interval": "间隔", "requiredWidgetName": "组件名称不允许为空,请修改", From 0faca75ea799bebf8c239fce5e35c7e8a28aa88d Mon Sep 17 00:00:00 2001 From: lyp000119 <2319460338@qq.com> Date: Tue, 17 Oct 2023 15:19:13 +0800 Subject: [PATCH 2/2] feat: Display the added page in the StoryPageAddModal --- .../StoryBoardPage/Editor/StoryToolBar.tsx | 93 ++++++++++--------- .../app/pages/StoryBoardPage/Editor/index.tsx | 5 +- .../components/StoryPageAddModal.tsx | 76 +++++++++------ 3 files changed, 101 insertions(+), 73 deletions(-) diff --git a/frontend/src/app/pages/StoryBoardPage/Editor/StoryToolBar.tsx b/frontend/src/app/pages/StoryBoardPage/Editor/StoryToolBar.tsx index 12f238b42..3ba9290a9 100644 --- a/frontend/src/app/pages/StoryBoardPage/Editor/StoryToolBar.tsx +++ b/frontend/src/app/pages/StoryBoardPage/Editor/StoryToolBar.tsx @@ -32,56 +32,59 @@ import { import StoryPageAddModal from '../components/StoryPageAddModal'; import { StoryContext } from '../contexts/StoryContext'; import { addStoryPages } from '../slice/thunks'; +import { StoryPage } from '../slice/types'; import { StoryPageSetting } from './StoryPageSetting'; import { StorySetting } from './StorySetting'; -export const StoryToolBar: React.FC<{ onCloseEditor?: () => void }> = memo( - ({ onCloseEditor }) => { - const dispatch = useDispatch(); +export const StoryToolBar: React.FC<{ + onCloseEditor?: () => void; + sortedPages: StoryPage[]; +}> = memo(({ onCloseEditor, sortedPages }) => { + const dispatch = useDispatch(); - const closeEditor = useCallback(() => { - onCloseEditor?.(); - }, [onCloseEditor]); - const { storyId, name } = useContext(StoryContext); - const [visible, setVisible] = useState(false); - const chartOptionsMock = useSelector(selectVizs); - const chartOptions = chartOptionsMock.filter( - item => item.relType === 'DASHBOARD', - ); + const closeEditor = useCallback(() => { + onCloseEditor?.(); + }, [onCloseEditor]); + const { storyId, name } = useContext(StoryContext); + const [visible, setVisible] = useState(false); + const chartOptionsMock = useSelector(selectVizs); + const chartOptions = chartOptionsMock.filter( + item => item.relType === 'DASHBOARD', + ); - const onSelectedPages = useCallback( - (relIds: string[]) => { - dispatch(addStoryPages({ storyId, relIds })); - setVisible(false); - }, - [storyId, dispatch], - ); - return ( - - - {name} - } - onClick={() => setVisible(true)} - /> - - - - - setVisible(false)} - /> - - ); - }, -); + const onSelectedPages = useCallback( + (relIds: string[]) => { + dispatch(addStoryPages({ storyId, relIds })); + setVisible(false); + }, + [storyId, dispatch], + ); + return ( + + + {name} + } + onClick={() => setVisible(true)} + /> + + + + + setVisible(false)} + /> + + ); +}); const Wrapper = styled.div` display: flex; diff --git a/frontend/src/app/pages/StoryBoardPage/Editor/index.tsx b/frontend/src/app/pages/StoryBoardPage/Editor/index.tsx index 404cdbb59..6258310e2 100644 --- a/frontend/src/app/pages/StoryBoardPage/Editor/index.tsx +++ b/frontend/src/app/pages/StoryBoardPage/Editor/index.tsx @@ -263,7 +263,10 @@ export const StoryEditor: React.FC<{}> = memo(() => { }} > - + void; onCancel: () => void; + sortedPages: StoryPage[]; } const StoryPageAddModal: React.FC = props => { @@ -35,41 +37,61 @@ const StoryPageAddModal: React.FC = props => { onSelectedPages, onCancel, pageContents: dataCharts, + sortedPages, } = props; const [selectedDataChartIds, setSelectedDataChartIds] = useState( [], ); - const onOk = () => { - onSelectedPages(selectedDataChartIds); - }; + const onOk = useCallback(() => { + onSelectedPages( + difference( + selectedDataChartIds, + sortedPages.map(v => v.relId), + ), + ); + }, [onSelectedPages, sortedPages, selectedDataChartIds]); + useEffect(() => { if (!visible) { - setSelectedDataChartIds([]); + const defaultSelectedIds = sortedPages.map(v => v.relId); + setSelectedDataChartIds(defaultSelectedIds); } - }, [visible]); - const columns = [ - { - title: i18next.t('viz.board.setting.storyName'), - dataIndex: 'name', - render: (text: string) => text, - }, - { - title: i18next.t('viz.board.setting.storyDescription'), - dataIndex: 'description', - render: (text: string) => text, - }, - ]; - const rowSelection = { - type: 'checkbox' as RowSelectionType, - selectedRowKeys: selectedDataChartIds, - onChange: (keys: React.Key[]) => { - setSelectedDataChartIds(keys as string[]); - }, - }; + }, [visible, sortedPages]); + + const columns = useMemo( + () => [ + { + title: i18next.t('viz.board.setting.storyName'), + dataIndex: 'name', + render: (text: string) => text, + }, + { + title: i18next.t('viz.board.setting.storyDescription'), + dataIndex: 'description', + render: (text: string) => text, + }, + ], + [], + ); + const rowSelection = useMemo( + () => ({ + type: 'checkbox' as RowSelectionType, + selectedRowKeys: selectedDataChartIds, + getCheckboxProps: record => { + return { + disabled: !!sortedPages.find(page => page.relId === record.relId), + }; + }, + onChange: (keys: React.Key[]) => { + setSelectedDataChartIds(keys as string[]); + }, + }), + [selectedDataChartIds, sortedPages], + ); return (