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 (