Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change StoryPageAddModal #2261

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 48 additions & 45 deletions frontend/src/app/pages/StoryBoardPage/Editor/StoryToolBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Wrapper>
<LeftOutlined
onClick={closeEditor}
style={{ marginRight: '10px', fontSize: '1.2rem' }}
/>
<Title>{name}</Title>
<AddButton
type="primary"
icon={<PlusOutlined />}
onClick={() => setVisible(true)}
/>
<Settings>
<StoryPageSetting />
<StorySetting />
</Settings>
<StoryPageAddModal
pageContents={chartOptions}
visible={visible}
onSelectedPages={onSelectedPages}
onCancel={() => setVisible(false)}
/>
</Wrapper>
);
},
);
const onSelectedPages = useCallback(
(relIds: string[]) => {
dispatch(addStoryPages({ storyId, relIds }));
setVisible(false);
},
[storyId, dispatch],
);
return (
<Wrapper>
<LeftOutlined
onClick={closeEditor}
style={{ marginRight: '10px', fontSize: '1.2rem' }}
/>
<Title>{name}</Title>
<AddButton
type="primary"
icon={<PlusOutlined />}
onClick={() => setVisible(true)}
/>
<Settings>
<StoryPageSetting />
<StorySetting />
</Settings>
<StoryPageAddModal
sortedPages={sortedPages}
pageContents={chartOptions}
visible={visible}
onSelectedPages={onSelectedPages}
onCancel={() => setVisible(false)}
/>
</Wrapper>
);
});

const Wrapper = styled.div`
display: flex;
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/app/pages/StoryBoardPage/Editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,10 @@ export const StoryEditor: React.FC<{}> = memo(() => {
}}
>
<Wrapper>
<StoryToolBar onCloseEditor={onCloseEditor} />
<StoryToolBar
onCloseEditor={onCloseEditor}
sortedPages={sortedPages}
/>
<Container
sizes={sizes}
minSize={[256, 0]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ import { Modal, Table } from 'antd';
import { RowSelectionType } from 'antd/lib/table/interface';
import { Folder } from 'app/pages/MainPage/pages/VizPage/slice/types';
import i18next from 'i18next';
import React, { useEffect, useState } from 'react';

import difference from 'lodash/difference';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { StoryPage } from '../slice/types';
export interface IProps {
// dataCharts: DataChart[];
pageContents: Folder[];
visible: boolean;
onSelectedPages: (selectedIds: string[]) => void;
onCancel: () => void;
sortedPages: StoryPage[];
}

const StoryPageAddModal: React.FC<IProps> = props => {
Expand All @@ -35,41 +37,61 @@ const StoryPageAddModal: React.FC<IProps> = props => {
onSelectedPages,
onCancel,
pageContents: dataCharts,
sortedPages,
} = props;
const [selectedDataChartIds, setSelectedDataChartIds] = useState<string[]>(
[],
);
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 (
<Modal
title="Add Story Page"
title={i18next.t('viz.board.setting.addStoryPage')}
visible={visible}
onOk={onOk}
centered
Expand Down
1 change: 1 addition & 0 deletions frontend/src/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/locales/zh/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,7 @@
"enterHere": "请输入",
"storyName": "名称",
"storyDescription": "描述",
"addStoryPage": "添加故事页面",
"format": "格式",
"interval": "间隔",
"requiredWidgetName": "组件名称不允许为空,请修改",
Expand Down