diff --git a/frontend/src/app/pages/DashBoardPage/actions/widgetAction.ts b/frontend/src/app/pages/DashBoardPage/actions/widgetAction.ts index 4769db87d..4915b631b 100644 --- a/frontend/src/app/pages/DashBoardPage/actions/widgetAction.ts +++ b/frontend/src/app/pages/DashBoardPage/actions/widgetAction.ts @@ -225,13 +225,12 @@ export const widgetLinkEventAction = widgetMap: widgetMap, params: undefined, }); - const boardLinkWidgets = Object.entries(widgetMapMap || {}) - .filter(([k, v]) => { - return targetLinkDataChartIds.includes(v.datachartId); - }) - .map(([k, v]) => v); + const boardLinkWidgets = Object.values(widgetMapMap || {}).filter(w => + targetLinkDataChartIds.includes(w.datachartId), + ); boardLinkWidgets.forEach(targetWidget => { - const dataChart = dataChartMap?.[targetWidget.datachartId]; + const dataChart = + dataChartMap[widget.dashboardId]?.[targetWidget.datachartId]; const dimensionNames = dataChart?.config?.chartConfig?.datas?.flatMap( d => { if ( @@ -503,14 +502,19 @@ export const showJumpErrorAction = } }; export const setWidgetSampleDataAction = - (args: { boardEditing: boolean; datachartId: string; wid: string }) => + (args: { + boardId: string; + boardEditing: boolean; + datachartId: string; + wid: string; + }) => (dispatch, getState) => { - const { boardEditing, datachartId, wid } = args; + const { boardId, boardEditing, datachartId, wid } = args; const rootState = getState() as RootState; const viewBoardState = rootState.board as BoardState; const editBoardState = rootState.editBoard as EditBoardState; const dataChartMap = viewBoardState.dataChartMap; - const curChart = dataChartMap[datachartId]; + const curChart = dataChartMap[boardId][datachartId]; if (!curChart) return; if (curChart.viewId) return; if (!curChart.config.sampleData) return; diff --git a/frontend/src/app/pages/DashBoardPage/components/ActionProvider/WidgetActionProvider.tsx b/frontend/src/app/pages/DashBoardPage/components/ActionProvider/WidgetActionProvider.tsx index e77c59fd0..0a523d9c9 100644 --- a/frontend/src/app/pages/DashBoardPage/components/ActionProvider/WidgetActionProvider.tsx +++ b/frontend/src/app/pages/DashBoardPage/components/ActionProvider/WidgetActionProvider.tsx @@ -240,6 +240,7 @@ export const WidgetActionProvider: FC<{ dispatch( editChartInWidgetAction({ orgId, + dashboardId: widget.dashboardId, widgetId: widget.id, chartName: widget.config.name, dataChartId: widget.datachartId, @@ -270,17 +271,24 @@ export const WidgetActionProvider: FC<{ onEditWidgetUnLock: (id: string) => { dispatch(editBoardStackActions.toggleLockWidget({ id, lock: false })); }, - onWidgetDataUpdate: ({ computedFields, payload, widgetId }) => { + onWidgetChartDataConfigUpdate: ({ + dashboardId, + datachartId, + computedFields, + options, + }) => { dispatch( - boardActions.updateDataChartGroup({ - id: widgetId, - payload, + boardActions.updateDataChartDataConfigGroupRows({ + dashboardId, + datachartId, + options, }), ); dispatch( - boardActions.updateDataChartComputedFields({ - id: widgetId, + boardActions.updateDataChartDataConfigComputedFields({ + dashboardId, + datachartId, computedFields, }), ); @@ -323,14 +331,16 @@ export interface WidgetActionContextProps { onWidgetLinkEvent: (widget: Widget) => (params) => void; onUpdateWidgetSelectedItems: (widget: Widget, selectedItems) => void; - onWidgetDataUpdate: ({ + onWidgetChartDataConfigUpdate: ({ + dashboardId, + datachartId, computedFields, - payload, - widgetId, + options, }: { + dashboardId: string; + datachartId: string; computedFields: any; - payload: ChartConfig; - widgetId: string; + options: ChartConfig; }) => void; // read diff --git a/frontend/src/app/pages/DashBoardPage/components/MockDataPanel/utils.ts b/frontend/src/app/pages/DashBoardPage/components/MockDataPanel/utils.ts index af327e34b..b870d4d22 100644 --- a/frontend/src/app/pages/DashBoardPage/components/MockDataPanel/utils.ts +++ b/frontend/src/app/pages/DashBoardPage/components/MockDataPanel/utils.ts @@ -16,34 +16,15 @@ * limitations under the License. */ import { ORIGINAL_TYPE_MAP } from '../../constants'; -import { - BoardState, - Dashboard, - DataChart, -} from '../../pages/Board/slice/types'; +import { Dashboard, DataChart } from '../../pages/Board/slice/types'; import { Widget } from '../../types/widgetTypes'; -const emptyWidgets = []; -export const getChartWidgets = ( - state: { board: BoardState }, - boardId: string, -) => { - const widgetMap = state.board.widgetRecord; - - if (!widgetMap[boardId]) { - return emptyWidgets; - } - let chartWidgets = Object.values(widgetMap[boardId]).filter( - widget => widget.config.type === 'chart', - ); - return chartWidgets; -}; export const getBoardTplData = ( dataMap: Record, boardTplData: { board: Dashboard; widgetMap: Record; - dataChartMap: Record; + dataChartMap: Record>; }, ) => { const { board, widgetMap, dataChartMap } = boardTplData; @@ -59,7 +40,7 @@ export const getBoardTplData = ( }; if (newWidgetConf.type === 'chart') { newWidgetConf.originalType = ORIGINAL_TYPE_MAP.ownedChart; - const datachart = dataChartMap[w.datachartId || '']; + const datachart = dataChartMap[board.id][w.datachartId || '']; if (datachart) { let newChart = { diff --git a/frontend/src/app/pages/DashBoardPage/components/WidgetProvider/WidgetChartProvider.tsx b/frontend/src/app/pages/DashBoardPage/components/WidgetProvider/WidgetChartProvider.tsx index c18c978d0..d851c94f7 100644 --- a/frontend/src/app/pages/DashBoardPage/components/WidgetProvider/WidgetChartProvider.tsx +++ b/frontend/src/app/pages/DashBoardPage/components/WidgetProvider/WidgetChartProvider.tsx @@ -63,20 +63,26 @@ export const WidgetChartContext = createContext<{ }); export const WidgetChartProvider: FC<{ + boardId: string; boardEditing: boolean; widgetId: string; -}> = memo(({ boardEditing, widgetId, children }) => { +}> = memo(({ boardId, boardEditing, widgetId, children }) => { const { datachartId } = useContext(WidgetContext); const dispatch = useDispatch(); useEffect(() => { if (!datachartId) return; if (!widgetId) return; dispatch( - setWidgetSampleDataAction({ boardEditing, datachartId, wid: widgetId }), + setWidgetSampleDataAction({ + boardId, + boardEditing, + datachartId, + wid: widgetId, + }), ); - }, [boardEditing, datachartId, dispatch, widgetId]); + }, [boardId, boardEditing, datachartId, dispatch, widgetId]); const dataChart = useSelector((state: { board: BoardState }) => - selectDataChartById(state, datachartId), + selectDataChartById(state, boardId, datachartId), ); const availableSourceFunctionsMap = useSelector( selectAvailableSourceFunctionsMap, diff --git a/frontend/src/app/pages/DashBoardPage/components/WidgetProvider/WidgetWrapProvider.tsx b/frontend/src/app/pages/DashBoardPage/components/WidgetProvider/WidgetWrapProvider.tsx index c6815aeef..86346cb02 100644 --- a/frontend/src/app/pages/DashBoardPage/components/WidgetProvider/WidgetWrapProvider.tsx +++ b/frontend/src/app/pages/DashBoardPage/components/WidgetProvider/WidgetWrapProvider.tsx @@ -35,7 +35,11 @@ export const WidgetWrapProvider: FC<{ widgetId={id} > - + {children} diff --git a/frontend/src/app/pages/DashBoardPage/components/Widgets/DataChartWidget/DataChartWidgetCore.tsx b/frontend/src/app/pages/DashBoardPage/components/Widgets/DataChartWidget/DataChartWidgetCore.tsx index 80e10c276..f6bb5c3ae 100644 --- a/frontend/src/app/pages/DashBoardPage/components/Widgets/DataChartWidget/DataChartWidgetCore.tsx +++ b/frontend/src/app/pages/DashBoardPage/components/Widgets/DataChartWidget/DataChartWidgetCore.tsx @@ -83,7 +83,8 @@ export const DataChartWidgetCore: React.FC<{}> = memo(() => { const dispatch = useDispatch(); const scale = useContext(BoardScaleContext); const { data: dataset } = useContext(WidgetDataContext); - const { renderMode, orgId, queryVariables } = useContext(BoardContext); + const { boardId, renderMode, orgId, queryVariables } = + useContext(BoardContext); const selectedItems = useContext(WidgetSelectionContext); const executeTokenMap = useSelector(selectShareExecuteTokenMap); const widget = useContext(WidgetContext); @@ -101,7 +102,7 @@ export const DataChartWidgetCore: React.FC<{}> = memo(() => { onWidgetChartClick, onWidgetLinkEvent, onWidgetGetData, - onWidgetDataUpdate, + onWidgetChartDataConfigUpdate, onUpdateWidgetSelectedItems, } = useContext(WidgetActionContext); const { cacheWhRef, cacheW, cacheH } = useCacheWidthHeight(); @@ -171,12 +172,12 @@ export const DataChartWidgetCore: React.FC<{}> = memo(() => { }, [widget]); const handleDateLevelChange = useCallback( - (type, payload) => { - const rows = getRuntimeDateLevelFields(payload.value?.rows); + (type, options) => { + const rows = getRuntimeDateLevelFields(options.value?.rows); const dateLevelComputedFields = rows.filter( v => v.category === ChartDataViewFieldCategory.DateLevelComputedField, ); - const replacedConfig = payload.value.replacedConfig; + const replacedConfig = options.value.replacedConfig; // TODO delete computedFields, const computedFields = getRuntimeComputedFields( dateLevelComputedFields, @@ -185,18 +186,20 @@ export const DataChartWidgetCore: React.FC<{}> = memo(() => { true, ); if (dataChart?.id) { - onWidgetDataUpdate({ + onWidgetChartDataConfigUpdate({ + dashboardId: boardId, + datachartId: dataChart.id, computedFields, - payload, - widgetId: dataChart.id, + options, }); } onWidgetGetData(widgetRef.current); }, [ - onWidgetDataUpdate, + boardId, dataChart?.config?.computedFields, dataChart?.id, + onWidgetChartDataConfigUpdate, onWidgetGetData, ], ); diff --git a/frontend/src/app/pages/DashBoardPage/pages/Board/slice/asyncActions.ts b/frontend/src/app/pages/DashBoardPage/pages/Board/slice/asyncActions.ts index 5bfd1b8cd..0f5a2407b 100644 --- a/frontend/src/app/pages/DashBoardPage/pages/Board/slice/asyncActions.ts +++ b/frontend/src/app/pages/DashBoardPage/pages/Board/slice/asyncActions.ts @@ -115,7 +115,12 @@ export const handleServerBoardAction = }), ); dispatch(boardActions.setViewMap(viewViews)); - dispatch(boardActions.setDataChartToMap(allDataCharts)); + dispatch( + boardActions.setDataChartToMap({ + dashboardId: dashboard.id, + dataCharts: allDataCharts, + }), + ); dispatch( boardActions.setWidgetMapState({ boardId: dashboard.id, @@ -207,7 +212,7 @@ export const getBoardDownloadParams = let requestParams = getBoardChartRequests({ widgetMap, viewMap, - dataChartMap, + dashboardDataChartMap: dataChartMap[boardId], }) as ChartDataRequest[]; return { requestParams, fileName }; diff --git a/frontend/src/app/pages/DashBoardPage/pages/Board/slice/index.ts b/frontend/src/app/pages/DashBoardPage/pages/Board/slice/index.ts index 6e7f67143..3cdd28863 100644 --- a/frontend/src/app/pages/DashBoardPage/pages/Board/slice/index.ts +++ b/frontend/src/app/pages/DashBoardPage/pages/Board/slice/index.ts @@ -49,15 +49,15 @@ import { import { BoardInfo, BoardState } from './types'; export const boardInit: BoardState = { - boardRecord: {} as Record, - boardInfoRecord: {} as Record, - widgetRecord: {} as Record>, - widgetInfoRecord: {} as Record>, - widgetDataMap: {} as Record, - dataChartMap: {} as Record, - viewMap: {} as Record, // View - availableSourceFunctionsMap: {} as Record, - selectedItems: {} as Record, + boardRecord: {}, + boardInfoRecord: {}, + widgetRecord: {}, + widgetInfoRecord: {}, + widgetDataMap: {}, + dataChartMap: {}, + viewMap: {}, + availableSourceFunctionsMap: {}, + selectedItems: {}, }; // boardActions const boardSlice = createSlice({ @@ -94,10 +94,17 @@ const boardSlice = createSlice({ } state.widgetInfoRecord[boardId] = widgetInfoMap; }, - setDataChartToMap(state, action: PayloadAction) { - const dataCharts = action.payload; + setDataChartToMap( + state, + { + payload: { dashboardId, dataCharts }, + }: PayloadAction<{ dashboardId: string; dataCharts: DataChart[] }>, + ) { dataCharts.forEach(dc => { - state.dataChartMap[dc.id] = dc; + if (!state.dataChartMap[dashboardId]) { + state.dataChartMap[dashboardId] = {}; + } + state.dataChartMap[dashboardId][dc.id] = dc; }); }, @@ -109,12 +116,13 @@ const boardSlice = createSlice({ }, clearBoardStateById(state, action: PayloadAction) { - const boardId = action.payload; - delete state.boardRecord[boardId]; - delete state.boardInfoRecord[boardId]; - delete state.widgetRecord[boardId]; - delete state.widgetInfoRecord[boardId]; - // can not del :dataCharts、views + const dashboardId = action.payload; + delete state.boardRecord[dashboardId]; + delete state.boardInfoRecord[dashboardId]; + delete state.widgetRecord[dashboardId]; + delete state.widgetInfoRecord[dashboardId]; + delete state.dataChartMap[dashboardId]; + // can't del: views }, setGroupWidgetsById( state, @@ -371,35 +379,43 @@ const boardSlice = createSlice({ state.widgetRecord[boardId][widget.id] = widget; }); }, - updateDataChartGroup( + updateDataChartDataConfigGroupRows( state, - action: PayloadAction<{ id: string; payload }>, + { + payload: { dashboardId, datachartId, options }, + }: PayloadAction<{ dashboardId: string; datachartId: string; options }>, ) { - const dataChart = state.dataChartMap[action.payload.id]; + const dataChart = state.dataChartMap[dashboardId][datachartId]; if (dataChart?.config) { const index = dataChart?.config?.chartConfig?.datas?.findIndex( section => section.type === ChartDataSectionType.Group, ); - if (index !== undefined && dataChart.config.chartConfig.datas) { - dataChart.config.chartConfig.datas[index].rows = - action.payload.payload?.value?.rows; + if ( + index !== undefined && + index >= 0 && + dataChart.config.chartConfig.datas + ) { + dataChart.config.chartConfig.datas[index].rows = options?.value?.rows; } - state.dataChartMap[action.payload.id] = dataChart; + state.dataChartMap[dashboardId][datachartId] = dataChart; } }, - updateDataChartComputedFields( + updateDataChartDataConfigComputedFields( state, - action: PayloadAction<{ - id: string; + { + payload: { dashboardId, datachartId, computedFields }, + }: PayloadAction<{ + dashboardId: string; + datachartId: string; computedFields: any; }>, ) { - const dataChart = state.dataChartMap[action.payload.id]; + const dataChart = state.dataChartMap[dashboardId][datachartId]; if (dataChart?.config) { - dataChart.config.computedFields = action.payload.computedFields; - state.dataChartMap[action.payload.id] = dataChart; + dataChart.config.computedFields = computedFields; + state.dataChartMap[dashboardId][datachartId] = dataChart; } }, changeSelectedItems( diff --git a/frontend/src/app/pages/DashBoardPage/pages/Board/slice/selector.ts b/frontend/src/app/pages/DashBoardPage/pages/Board/slice/selector.ts index 9abf1b261..a44bef975 100644 --- a/frontend/src/app/pages/DashBoardPage/pages/Board/slice/selector.ts +++ b/frontend/src/app/pages/DashBoardPage/pages/Board/slice/selector.ts @@ -21,7 +21,6 @@ import { Widget } from 'app/pages/DashBoardPage/types/widgetTypes'; import { RootState } from 'types'; import { boardInit } from '.'; import { getLayoutWidgets } from '../../../utils/widget'; -import { WidgetInfo } from './types'; const DefaultObject = {}; export const selectPropsId = (_: unknown, id: string) => id; @@ -119,24 +118,6 @@ export const selectWidgetInfoBy2Id = createSelector( } }, ); -export const selectLayoutWidgetInfoMapById = createSelector( - selectBoardWidgetMap, - selectWidgetInfoGroupMap, - selectPropsId, - (allWidgetMap, allWidgetInfoMap, id) => { - if (!allWidgetMap[id]) return DefaultObject; - if (!allWidgetInfoMap[id]) return DefaultObject; - - const layoutWidgets = getLayoutWidgets(allWidgetMap[id]); - const widgetInfoMap = allWidgetInfoMap[id]; - const layoutWidgetsInfo: Record = DefaultObject; - - layoutWidgets.forEach(w => { - layoutWidgetsInfo[w.id] = widgetInfoMap[w.id]; - }); - return layoutWidgetsInfo; - }, -); export const makeSelectBoardConfigById = () => createSelector(selectBoardRecord, selectPropsId, (boardRecord, id) => { @@ -160,8 +141,13 @@ export const selectDataChartMap = createSelector( ); export const selectDataChartById = createSelector( - [selectDataChartMap, (_, chartId: string) => chartId], - (dataChartMap, id) => dataChartMap[id] || undefined, + [ + selectDataChartMap, + (_, dashboardId: string) => dashboardId, + (_, __, datachartId: string) => datachartId, + ], + (dataChartMap, dashboardId, datachartId) => + dataChartMap[dashboardId]?.[datachartId], ); export const selectViewMap = createSelector( @@ -174,7 +160,6 @@ export const selectAvailableSourceFunctionsMap = createSelector( state => state.availableSourceFunctionsMap, ); -// dataChartMap export const selectWidgetDataById = createSelector( [boardState, selectPropsId], (state, wid) => state.widgetDataMap[wid] || DefaultWidgetData, diff --git a/frontend/src/app/pages/DashBoardPage/pages/Board/slice/thunk.ts b/frontend/src/app/pages/DashBoardPage/pages/Board/slice/thunk.ts index 8b7f5040a..dfba26aec 100644 --- a/frontend/src/app/pages/DashBoardPage/pages/Board/slice/thunk.ts +++ b/frontend/src/app/pages/DashBoardPage/pages/Board/slice/thunk.ts @@ -258,7 +258,7 @@ export const syncBoardWidgetChartDataAsync = createAsyncThunk< bid: curWidget.dashboardId, wid: widgetId, }); - const dataChart = dataChartMap?.[curWidget.datachartId]; + const dataChart = dataChartMap[boardId][curWidget.datachartId]; const chartDataView = viewMap?.[dataChart?.viewId]; const requestParams = new ChartDataRequestBuilder( { @@ -380,7 +380,7 @@ export const getChartWidgetDataAsync = createAsyncThunk< viewMap, option, widgetInfo, - dataChartMap, + dashboardDataChartMap: dataChartMap[boardId], boardLinkFilters, drillOption, }); @@ -401,7 +401,7 @@ export const getChartWidgetDataAsync = createAsyncThunk< const executeTokenMap = (getState() as RootState)?.share ?.executeTokenMap; - const dataChart = dataChartMap[curWidget.datachartId]; + const dataChart = dataChartMap[boardId][curWidget.datachartId]; const viewId = viewMap[dataChart.viewId].id; const executeToken = executeTokenMap?.[viewId]; const { data } = await request2({ diff --git a/frontend/src/app/pages/DashBoardPage/pages/Board/slice/types.ts b/frontend/src/app/pages/DashBoardPage/pages/Board/slice/types.ts index c1a8fa7f5..301ffae13 100644 --- a/frontend/src/app/pages/DashBoardPage/pages/Board/slice/types.ts +++ b/frontend/src/app/pages/DashBoardPage/pages/Board/slice/types.ts @@ -48,7 +48,7 @@ export interface BoardState { boardInfoRecord: Record; widgetRecord: Record>; widgetInfoRecord: Record>; - dataChartMap: Record; + dataChartMap: Record>; viewMap: Record; // View widgetDataMap: Record; availableSourceFunctionsMap: Record; diff --git a/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/slice/actions/actions.ts b/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/slice/actions/actions.ts index 4610f26e8..333c338cb 100644 --- a/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/slice/actions/actions.ts +++ b/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/slice/actions/actions.ts @@ -224,7 +224,7 @@ export const copyWidgetsAction = (wIds?: string[]) => (dispatch, getState) => { export const pasteWidgetsAction = () => (dispatch, getState) => { const state = getState(); const { - boardInfo: { clipboardWidgetMap }, + boardInfo: { id, clipboardWidgetMap }, } = state.editBoard as EditBoardState; const boardState = state.board as BoardState; @@ -243,14 +243,19 @@ export const pasteWidgetsAction = () => (dispatch, getState) => { const { newDataCharts, newWidgets } = cloneWidgets({ widgets: clipboardWidgetList, - dataChartMap, + dashboardDataChartMap: dataChartMap[id], newWidgetMapping, }); const widgetInfos = newWidgets.map(widget => { const widgetInfo = createWidgetInfo(widget.id); return widgetInfo; }); - dispatch(boardActions.setDataChartToMap(newDataCharts)); + dispatch( + boardActions.setDataChartToMap({ + dashboardId: id, + dataCharts: newDataCharts, + }), + ); dispatch(editWidgetInfoActions.addWidgetInfos(widgetInfos)); dispatch(editBoardStackActions.addWidgets(newWidgets)); }; @@ -258,6 +263,7 @@ export const pasteWidgetsAction = () => (dispatch, getState) => { export const editChartInWidgetAction = (props: { orgId: string; + dashboardId: string; widgetId: string; chartName?: string; dataChartId: string; @@ -266,6 +272,7 @@ export const editChartInWidgetAction = async (dispatch, getState) => { const { orgId, + dashboardId, widgetId, dataChartId, chartType, @@ -274,7 +281,7 @@ export const editChartInWidgetAction = const board = (getState() as RootState).board!; const dataChartMap = board.dataChartMap; - const dataChart = dataChartMap[dataChartId]; + const dataChart = dataChartMap[dashboardId][dataChartId]; const viewMap = board?.viewMap; const withViewDataChart = produce(dataChart, draft => { draft.view = viewMap[draft.viewId]; @@ -301,10 +308,13 @@ export const editHasChartWidget = draft.viewIds = [dataChart.viewId]; }); dispatch(editBoardStackActions.updateWidget(nextWidget)); - const dataCharts = [dataChart]; - const viewViews = [view]; - dispatch(boardActions.setDataChartToMap(dataCharts)); - dispatch(boardActions.setViewMap(viewViews)); + dispatch( + boardActions.setDataChartToMap({ + dashboardId: curWidget.dashboardId, + dataCharts: [dataChart], + }), + ); + dispatch(boardActions.setViewMap([view])); dispatch(getEditChartWidgetDataAsync({ widgetId: curWidget.id })); }; diff --git a/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/slice/selectors.ts b/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/slice/selectors.ts index 7398487d0..9c9fd6602 100644 --- a/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/slice/selectors.ts +++ b/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/slice/selectors.ts @@ -43,12 +43,7 @@ export const editBoardStackState = (state: { editBoard: HistoryEditBoard }) => export const selectEditBoard = createSelector([editBoardStackState], state => { return state.dashBoard; }); -export const selectEditWidgetRecord = createSelector( - [editBoardStackState], - state => { - return state.widgetRecord; - }, -); + export const selectAllWidgetMap = createSelector( [editBoardStackState], state => state.widgetRecord || DefaultObject, diff --git a/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/slice/thunk.ts b/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/slice/thunk.ts index 8344087b1..3fc4fc831 100644 --- a/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/slice/thunk.ts +++ b/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/slice/thunk.ts @@ -50,7 +50,6 @@ import { editWidgetSelectedItemsActions, } from '.'; import { BoardInfo, BoardType, ServerDashboard } from '../../Board/slice/types'; -import { getDataChartMap } from './../../../utils/board'; import { adjustWidgetsToBoard } from './../../../utils/widget'; import { addVariablesToBoard } from './actions/actions'; import { @@ -134,7 +133,12 @@ export const fetchEditBoardDetail = createAsyncThunk< // datacharts const allDataCharts: DataChart[] = dataCharts.concat(wrappedDataCharts); - dispatch(boardActions.setDataChartToMap(allDataCharts)); + dispatch( + boardActions.setDataChartToMap({ + dashboardId: dashboard.id, + dataCharts: allDataCharts, + }), + ); const viewViews = getChartDataView(serverViews, allDataCharts); dispatch(boardActions.updateViewMap(viewViews)); @@ -177,7 +181,7 @@ export const toUpdateDashboard = createAsyncThunk< const { dataChartMap, viewMap } = boardState.board; const widgets = convertWrapChartWidget({ widgetMap: widgetRecord, - dataChartMap, + dashboardDataChartMap: dataChartMap[boardId], viewMap, }); @@ -275,20 +279,27 @@ export const addDataChartWidgets = createAsyncThunk< method: 'get', }); const dataCharts: DataChart[] = getDataChartsByServer(datacharts, views); - const dataChartMap = getDataChartMap(dataCharts); + const dashboardDataChartMap = datacharts.reduce< + Record + >((acc, cur) => { + acc[cur.id] = cur; + return acc; + }, {}); const viewViews = getChartDataView(views, dataCharts); - dispatch(boardActions.setDataChartToMap(dataCharts)); + dispatch( + boardActions.setDataChartToMap({ dashboardId: boardId, dataCharts }), + ); dispatch(boardActions.setViewMap(viewViews)); const widgets = chartIds.map(dcId => { - const dataChart = dataChartMap[dcId]; + const dataChart = dashboardDataChartMap[dcId]; const viewIds = dataChart.viewId ? [dataChart.viewId] : []; let widget = widgetManager.toolkit(ORIGINAL_TYPE_MAP.linkedChart).create({ boardType: boardType, datachartId: dcId, relations: [], name: dataChart.name, - content: dataChartMap[dcId], + content: dashboardDataChartMap[dcId], viewIds: viewIds, }); return widget; @@ -321,7 +332,9 @@ export const addWrapChartWidget = createAsyncThunk< ) => { const dataCharts = [dataChart]; const viewViews = view ? [view] : []; - dispatch(boardActions.setDataChartToMap(dataCharts)); + dispatch( + boardActions.setDataChartToMap({ dashboardId: boardId, dataCharts }), + ); dispatch(boardActions.setViewMap(viewViews)); let widget = widgetManager.toolkit(ORIGINAL_TYPE_MAP.ownedChart).create({ boardType: boardType, @@ -357,7 +370,9 @@ export const addChartWidget = createAsyncThunk< ) => { const dataCharts = [dataChart]; const viewViews = [view]; - dispatch(boardActions.setDataChartToMap(dataCharts)); + dispatch( + boardActions.setDataChartToMap({ dashboardId: boardId, dataCharts }), + ); dispatch(boardActions.setViewMap(viewViews)); const originalType = @@ -484,7 +499,7 @@ export const syncEditBoardWidgetChartDataAsync = createAsyncThunk< bid: curWidget.dashboardId, wid: widgetId, }); - const dataChart = dataChartMap?.[curWidget.datachartId]; + const dataChart = dataChartMap[boardId]?.[curWidget.datachartId]; const chartDataView = viewMap?.[dataChart?.viewId]; const requestParams = new ChartDataRequestBuilder( { @@ -603,7 +618,7 @@ export const getEditChartWidgetDataAsync = createAsyncThunk< viewMap, option, widgetInfo, - dataChartMap, + dashboardDataChartMap: dataChartMap[curWidget.dashboardId], boardLinkFilters, drillOption, }); diff --git a/frontend/src/app/pages/DashBoardPage/utils/board.ts b/frontend/src/app/pages/DashBoardPage/utils/board.ts index e681607ee..1bffaca09 100644 --- a/frontend/src/app/pages/DashBoardPage/utils/board.ts +++ b/frontend/src/app/pages/DashBoardPage/utils/board.ts @@ -192,12 +192,6 @@ export const getDataChartsByServer = ( return dataCharts; }; -export const getDataChartMap = (dataCharts: DataChart[]) => { - return dataCharts.reduce((acc, cur) => { - acc[cur.id] = cur; - return acc; - }, {} as Record); -}; export const getChartDataView = (views: View[], dataCharts: DataChart[]) => { const viewViews: ChartDataView[] = []; diff --git a/frontend/src/app/pages/DashBoardPage/utils/index.ts b/frontend/src/app/pages/DashBoardPage/utils/index.ts index 0806fc97f..da75d5432 100644 --- a/frontend/src/app/pages/DashBoardPage/utils/index.ts +++ b/frontend/src/app/pages/DashBoardPage/utils/index.ts @@ -407,7 +407,7 @@ export const getChartWidgetRequestParams = (obj: { widgetInfo: WidgetInfo | undefined; option: getDataOption | undefined; viewMap: Record; - dataChartMap: Record; + dashboardDataChartMap: Record; boardLinkFilters?: BoardLinkFilter[]; drillOption: ChartDrillOption | undefined; }) => { @@ -416,7 +416,7 @@ export const getChartWidgetRequestParams = (obj: { widgetMap, viewMap, widgetInfo, - dataChartMap, + dashboardDataChartMap, option, boardLinkFilters, drillOption, @@ -426,7 +426,7 @@ export const getChartWidgetRequestParams = (obj: { if (!curWidget) return null; if (curWidget.config.type !== 'chart') return null; if (!curWidget.datachartId) return null; - const dataChart = dataChartMap[curWidget.datachartId]; + const dataChart = dashboardDataChartMap[curWidget.datachartId]; if (!dataChart) { // errorHandle(`can\`t find Chart ${curWidget.datachartId}`); return null; @@ -502,9 +502,9 @@ export const getChartWidgetRequestParams = (obj: { export const getBoardChartRequests = (params: { widgetMap: Record; viewMap: Record; - dataChartMap: Record; + dashboardDataChartMap: Record; }) => { - const { widgetMap, viewMap, dataChartMap } = params; + const { widgetMap, viewMap, dashboardDataChartMap } = params; const chartWidgetIds = Object.values(widgetMap) .filter(w => w.config.type === 'chart') .map(w => w.id); @@ -524,7 +524,7 @@ export const getBoardChartRequests = (params: { viewMap, option: undefined, widgetInfo: undefined, - dataChartMap, + dashboardDataChartMap, drillOption, }), ...{ diff --git a/frontend/src/app/pages/DashBoardPage/utils/widget.ts b/frontend/src/app/pages/DashBoardPage/utils/widget.ts index b76bec1f1..4a46330ba 100644 --- a/frontend/src/app/pages/DashBoardPage/utils/widget.ts +++ b/frontend/src/app/pages/DashBoardPage/utils/widget.ts @@ -317,16 +317,16 @@ export const createWidgetInfoMap = (widgets: Widget[]) => { export const convertWrapChartWidget = (params: { widgetMap: Record; - dataChartMap: Record; + dashboardDataChartMap: Record; viewMap: Record; }) => { - const { widgetMap, dataChartMap } = params; + const { widgetMap, dashboardDataChartMap } = params; const widgets = Object.values(widgetMap).map(widget => { if (widget.config.originalType !== ORIGINAL_TYPE_MAP.ownedChart) { return widget; } // widgetChart wrapChartWidget - const dataChart = dataChartMap[widget.datachartId]; + const dataChart = dashboardDataChartMap[widget.datachartId]; const newWidget = produce(widget, draft => { draft.datachartId = ''; (draft.config.content as ChartWidgetContent).dataChart = dataChart; @@ -539,13 +539,13 @@ export const getWidgetMap = ( ) => { const filterSearchParams = filterSearchParamsMap?.params, isMatchByName = filterSearchParamsMap?.isMatchByName; - const dataChartMap = dataCharts.reduce((acc, cur) => { + const dashboardDataChartMap = dataCharts.reduce((acc, cur) => { acc[cur.id] = cur; return acc; }, {} as Record); const widgetMap = widgets.reduce((acc, cur) => { // issues #601 - const chartViewId = dataChartMap[cur.datachartId]?.viewId; + const chartViewId = dashboardDataChartMap[cur.datachartId]?.viewId; const viewIds = chartViewId ? [chartViewId] : cur.viewIds; const viewComputerFields = JSON.parse(serverViews.find(v => v.id === viewIds[0])?.model || '{}') @@ -722,12 +722,12 @@ export const getValueByRowData = ( export function cloneWidgets(args: { widgets: WidgetOfCopy[]; - dataChartMap: Record; + dashboardDataChartMap: Record; newWidgetMapping: WidgetMapping; }) { const newDataCharts: DataChart[] = []; const newWidgets: Widget[] = []; - const { widgets, dataChartMap, newWidgetMapping } = args; + const { widgets, dashboardDataChartMap, newWidgetMapping } = args; widgets.forEach(widget => { const newWidget = CloneValueDeep(widget); delete newWidget.selectedCopy; @@ -760,7 +760,7 @@ export function cloneWidgets(args: { } //chart if (newWidget.config.type === 'chart') { - let dataChart = dataChartMap[newWidget.datachartId]; + let dataChart = dashboardDataChartMap[newWidget.datachartId]; const newDataChart: DataChart = CloneValueDeep({ ...dataChart, id: dataChart.id + Date.now() + BOARD_COPY_CHART_SUFFIX, diff --git a/frontend/src/task.ts b/frontend/src/task.ts index be79799f4..0784ea96d 100644 --- a/frontend/src/task.ts +++ b/frontend/src/task.ts @@ -71,14 +71,14 @@ const getBoardQueryData = (dataStr: string) => { return obj; }, {}); - const dataChartMap = allDataCharts.reduce((obj, dataChart) => { + const dashboardDataChartMap = allDataCharts.reduce((obj, dataChart) => { obj[dataChart.id] = dataChart; return obj; }, {}); let downloadParams = getBoardChartRequests({ widgetMap, viewMap, - dataChartMap, + dashboardDataChartMap, }); let fileName = dashboard.name; return JSON.stringify({ downloadParams, fileName });