Skip to content

Commit 26829bb

Browse files
committed
fix: Incorrect rendering of copied dashboard charts
1 parent f71c1be commit 26829bb

File tree

18 files changed

+190
-162
lines changed

18 files changed

+190
-162
lines changed

frontend/src/app/pages/DashBoardPage/actions/widgetAction.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,12 @@ export const widgetLinkEventAction =
225225
widgetMap: widgetMap,
226226
params: undefined,
227227
});
228-
const boardLinkWidgets = Object.entries(widgetMapMap || {})
229-
.filter(([k, v]) => {
230-
return targetLinkDataChartIds.includes(v.datachartId);
231-
})
232-
.map(([k, v]) => v);
228+
const boardLinkWidgets = Object.values(widgetMapMap || {}).filter(w =>
229+
targetLinkDataChartIds.includes(w.datachartId),
230+
);
233231
boardLinkWidgets.forEach(targetWidget => {
234-
const dataChart = dataChartMap?.[targetWidget.datachartId];
232+
const dataChart =
233+
dataChartMap[widget.dashboardId]?.[targetWidget.datachartId];
235234
const dimensionNames = dataChart?.config?.chartConfig?.datas?.flatMap(
236235
d => {
237236
if (
@@ -503,14 +502,19 @@ export const showJumpErrorAction =
503502
}
504503
};
505504
export const setWidgetSampleDataAction =
506-
(args: { boardEditing: boolean; datachartId: string; wid: string }) =>
505+
(args: {
506+
boardId: string;
507+
boardEditing: boolean;
508+
datachartId: string;
509+
wid: string;
510+
}) =>
507511
(dispatch, getState) => {
508-
const { boardEditing, datachartId, wid } = args;
512+
const { boardId, boardEditing, datachartId, wid } = args;
509513
const rootState = getState() as RootState;
510514
const viewBoardState = rootState.board as BoardState;
511515
const editBoardState = rootState.editBoard as EditBoardState;
512516
const dataChartMap = viewBoardState.dataChartMap;
513-
const curChart = dataChartMap[datachartId];
517+
const curChart = dataChartMap[boardId][datachartId];
514518
if (!curChart) return;
515519
if (curChart.viewId) return;
516520
if (!curChart.config.sampleData) return;

frontend/src/app/pages/DashBoardPage/components/ActionProvider/WidgetActionProvider.tsx

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ export const WidgetActionProvider: FC<{
240240
dispatch(
241241
editChartInWidgetAction({
242242
orgId,
243+
dashboardId: widget.dashboardId,
243244
widgetId: widget.id,
244245
chartName: widget.config.name,
245246
dataChartId: widget.datachartId,
@@ -270,17 +271,24 @@ export const WidgetActionProvider: FC<{
270271
onEditWidgetUnLock: (id: string) => {
271272
dispatch(editBoardStackActions.toggleLockWidget({ id, lock: false }));
272273
},
273-
onWidgetDataUpdate: ({ computedFields, payload, widgetId }) => {
274+
onWidgetChartDataConfigUpdate: ({
275+
dashboardId,
276+
datachartId,
277+
computedFields,
278+
options,
279+
}) => {
274280
dispatch(
275-
boardActions.updateDataChartGroup({
276-
id: widgetId,
277-
payload,
281+
boardActions.updateDataChartDataConfigGroupRows({
282+
dashboardId,
283+
datachartId,
284+
options,
278285
}),
279286
);
280287

281288
dispatch(
282-
boardActions.updateDataChartComputedFields({
283-
id: widgetId,
289+
boardActions.updateDataChartDataConfigComputedFields({
290+
dashboardId,
291+
datachartId,
284292
computedFields,
285293
}),
286294
);
@@ -323,14 +331,16 @@ export interface WidgetActionContextProps {
323331
onWidgetLinkEvent: (widget: Widget) => (params) => void;
324332
onUpdateWidgetSelectedItems: (widget: Widget, selectedItems) => void;
325333

326-
onWidgetDataUpdate: ({
334+
onWidgetChartDataConfigUpdate: ({
335+
dashboardId,
336+
datachartId,
327337
computedFields,
328-
payload,
329-
widgetId,
338+
options,
330339
}: {
340+
dashboardId: string;
341+
datachartId: string;
331342
computedFields: any;
332-
payload: ChartConfig;
333-
widgetId: string;
343+
options: ChartConfig;
334344
}) => void;
335345

336346
// read

frontend/src/app/pages/DashBoardPage/components/MockDataPanel/utils.ts

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,15 @@
1616
* limitations under the License.
1717
*/
1818
import { ORIGINAL_TYPE_MAP } from '../../constants';
19-
import {
20-
BoardState,
21-
Dashboard,
22-
DataChart,
23-
} from '../../pages/Board/slice/types';
19+
import { Dashboard, DataChart } from '../../pages/Board/slice/types';
2420
import { Widget } from '../../types/widgetTypes';
25-
const emptyWidgets = [];
26-
export const getChartWidgets = (
27-
state: { board: BoardState },
28-
boardId: string,
29-
) => {
30-
const widgetMap = state.board.widgetRecord;
31-
32-
if (!widgetMap[boardId]) {
33-
return emptyWidgets;
34-
}
35-
let chartWidgets = Object.values(widgetMap[boardId]).filter(
36-
widget => widget.config.type === 'chart',
37-
);
38-
return chartWidgets;
39-
};
4021

4122
export const getBoardTplData = (
4223
dataMap: Record<string, { id: string; name: string; data }>,
4324
boardTplData: {
4425
board: Dashboard;
4526
widgetMap: Record<string, Widget>;
46-
dataChartMap: Record<string, DataChart>;
27+
dataChartMap: Record<string, Record<string, DataChart>>;
4728
},
4829
) => {
4930
const { board, widgetMap, dataChartMap } = boardTplData;
@@ -59,7 +40,7 @@ export const getBoardTplData = (
5940
};
6041
if (newWidgetConf.type === 'chart') {
6142
newWidgetConf.originalType = ORIGINAL_TYPE_MAP.ownedChart;
62-
const datachart = dataChartMap[w.datachartId || ''];
43+
const datachart = dataChartMap[board.id][w.datachartId || ''];
6344

6445
if (datachart) {
6546
let newChart = {

frontend/src/app/pages/DashBoardPage/components/WidgetProvider/WidgetChartProvider.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,26 @@ export const WidgetChartContext = createContext<{
6363
});
6464

6565
export const WidgetChartProvider: FC<{
66+
boardId: string;
6667
boardEditing: boolean;
6768
widgetId: string;
68-
}> = memo(({ boardEditing, widgetId, children }) => {
69+
}> = memo(({ boardId, boardEditing, widgetId, children }) => {
6970
const { datachartId } = useContext(WidgetContext);
7071
const dispatch = useDispatch();
7172
useEffect(() => {
7273
if (!datachartId) return;
7374
if (!widgetId) return;
7475
dispatch(
75-
setWidgetSampleDataAction({ boardEditing, datachartId, wid: widgetId }),
76+
setWidgetSampleDataAction({
77+
boardId,
78+
boardEditing,
79+
datachartId,
80+
wid: widgetId,
81+
}),
7682
);
77-
}, [boardEditing, datachartId, dispatch, widgetId]);
83+
}, [boardId, boardEditing, datachartId, dispatch, widgetId]);
7884
const dataChart = useSelector((state: { board: BoardState }) =>
79-
selectDataChartById(state, datachartId),
85+
selectDataChartById(state, boardId, datachartId),
8086
);
8187
const availableSourceFunctionsMap = useSelector(
8288
selectAvailableSourceFunctionsMap,

frontend/src/app/pages/DashBoardPage/components/WidgetProvider/WidgetWrapProvider.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ export const WidgetWrapProvider: FC<{
3535
widgetId={id}
3636
>
3737
<WidgetSelectionProvider boardEditing={boardEditing} widgetId={id}>
38-
<WidgetChartProvider boardEditing={boardEditing} widgetId={id}>
38+
<WidgetChartProvider
39+
boardId={boardId}
40+
boardEditing={boardEditing}
41+
widgetId={id}
42+
>
3943
{children}
4044
</WidgetChartProvider>
4145
</WidgetSelectionProvider>

frontend/src/app/pages/DashBoardPage/components/Widgets/DataChartWidget/DataChartWidgetCore.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ export const DataChartWidgetCore: React.FC<{}> = memo(() => {
8383
const dispatch = useDispatch();
8484
const scale = useContext(BoardScaleContext);
8585
const { data: dataset } = useContext(WidgetDataContext);
86-
const { renderMode, orgId, queryVariables } = useContext(BoardContext);
86+
const { boardId, renderMode, orgId, queryVariables } =
87+
useContext(BoardContext);
8788
const selectedItems = useContext(WidgetSelectionContext);
8889
const executeTokenMap = useSelector(selectShareExecuteTokenMap);
8990
const widget = useContext(WidgetContext);
@@ -101,7 +102,7 @@ export const DataChartWidgetCore: React.FC<{}> = memo(() => {
101102
onWidgetChartClick,
102103
onWidgetLinkEvent,
103104
onWidgetGetData,
104-
onWidgetDataUpdate,
105+
onWidgetChartDataConfigUpdate,
105106
onUpdateWidgetSelectedItems,
106107
} = useContext(WidgetActionContext);
107108
const { cacheWhRef, cacheW, cacheH } = useCacheWidthHeight();
@@ -171,12 +172,12 @@ export const DataChartWidgetCore: React.FC<{}> = memo(() => {
171172
}, [widget]);
172173

173174
const handleDateLevelChange = useCallback(
174-
(type, payload) => {
175-
const rows = getRuntimeDateLevelFields(payload.value?.rows);
175+
(type, options) => {
176+
const rows = getRuntimeDateLevelFields(options.value?.rows);
176177
const dateLevelComputedFields = rows.filter(
177178
v => v.category === ChartDataViewFieldCategory.DateLevelComputedField,
178179
);
179-
const replacedConfig = payload.value.replacedConfig;
180+
const replacedConfig = options.value.replacedConfig;
180181
// TODO delete computedFields,
181182
const computedFields = getRuntimeComputedFields(
182183
dateLevelComputedFields,
@@ -185,18 +186,20 @@ export const DataChartWidgetCore: React.FC<{}> = memo(() => {
185186
true,
186187
);
187188
if (dataChart?.id) {
188-
onWidgetDataUpdate({
189+
onWidgetChartDataConfigUpdate({
190+
dashboardId: boardId,
191+
datachartId: dataChart.id,
189192
computedFields,
190-
payload,
191-
widgetId: dataChart.id,
193+
options,
192194
});
193195
}
194196
onWidgetGetData(widgetRef.current);
195197
},
196198
[
197-
onWidgetDataUpdate,
199+
boardId,
198200
dataChart?.config?.computedFields,
199201
dataChart?.id,
202+
onWidgetChartDataConfigUpdate,
200203
onWidgetGetData,
201204
],
202205
);

frontend/src/app/pages/DashBoardPage/pages/Board/slice/asyncActions.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,12 @@ export const handleServerBoardAction =
115115
}),
116116
);
117117
dispatch(boardActions.setViewMap(viewViews));
118-
dispatch(boardActions.setDataChartToMap(allDataCharts));
118+
dispatch(
119+
boardActions.setDataChartToMap({
120+
dashboardId: dashboard.id,
121+
dataCharts: allDataCharts,
122+
}),
123+
);
119124
dispatch(
120125
boardActions.setWidgetMapState({
121126
boardId: dashboard.id,
@@ -207,7 +212,7 @@ export const getBoardDownloadParams =
207212
let requestParams = getBoardChartRequests({
208213
widgetMap,
209214
viewMap,
210-
dataChartMap,
215+
dashboardDataChartMap: dataChartMap[boardId],
211216
}) as ChartDataRequest[];
212217

213218
return { requestParams, fileName };

frontend/src/app/pages/DashBoardPage/pages/Board/slice/index.ts

Lines changed: 47 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ import {
4949
import { BoardInfo, BoardState } from './types';
5050

5151
export const boardInit: BoardState = {
52-
boardRecord: {} as Record<string, Dashboard>,
53-
boardInfoRecord: {} as Record<string, BoardInfo>,
54-
widgetRecord: {} as Record<string, Record<string, Widget>>,
55-
widgetInfoRecord: {} as Record<string, Record<string, WidgetInfo>>,
56-
widgetDataMap: {} as Record<string, WidgetData | undefined>,
57-
dataChartMap: {} as Record<string, DataChart>,
58-
viewMap: {} as Record<string, ChartDataView>, // View
59-
availableSourceFunctionsMap: {} as Record<string, string[]>,
60-
selectedItems: {} as Record<string, SelectedItem[]>,
52+
boardRecord: {},
53+
boardInfoRecord: {},
54+
widgetRecord: {},
55+
widgetInfoRecord: {},
56+
widgetDataMap: {},
57+
dataChartMap: {},
58+
viewMap: {},
59+
availableSourceFunctionsMap: {},
60+
selectedItems: {},
6161
};
6262
// boardActions
6363
const boardSlice = createSlice({
@@ -94,10 +94,17 @@ const boardSlice = createSlice({
9494
}
9595
state.widgetInfoRecord[boardId] = widgetInfoMap;
9696
},
97-
setDataChartToMap(state, action: PayloadAction<DataChart[]>) {
98-
const dataCharts = action.payload;
97+
setDataChartToMap(
98+
state,
99+
{
100+
payload: { dashboardId, dataCharts },
101+
}: PayloadAction<{ dashboardId: string; dataCharts: DataChart[] }>,
102+
) {
99103
dataCharts.forEach(dc => {
100-
state.dataChartMap[dc.id] = dc;
104+
if (!state.dataChartMap[dashboardId]) {
105+
state.dataChartMap[dashboardId] = {};
106+
}
107+
state.dataChartMap[dashboardId][dc.id] = dc;
101108
});
102109
},
103110

@@ -109,12 +116,13 @@ const boardSlice = createSlice({
109116
},
110117

111118
clearBoardStateById(state, action: PayloadAction<string>) {
112-
const boardId = action.payload;
113-
delete state.boardRecord[boardId];
114-
delete state.boardInfoRecord[boardId];
115-
delete state.widgetRecord[boardId];
116-
delete state.widgetInfoRecord[boardId];
117-
// can not del :dataCharts、views
119+
const dashboardId = action.payload;
120+
delete state.boardRecord[dashboardId];
121+
delete state.boardInfoRecord[dashboardId];
122+
delete state.widgetRecord[dashboardId];
123+
delete state.widgetInfoRecord[dashboardId];
124+
delete state.dataChartMap[dashboardId];
125+
// can't del: views
118126
},
119127
setGroupWidgetsById(
120128
state,
@@ -371,35 +379,43 @@ const boardSlice = createSlice({
371379
state.widgetRecord[boardId][widget.id] = widget;
372380
});
373381
},
374-
updateDataChartGroup(
382+
updateDataChartDataConfigGroupRows(
375383
state,
376-
action: PayloadAction<{ id: string; payload }>,
384+
{
385+
payload: { dashboardId, datachartId, options },
386+
}: PayloadAction<{ dashboardId: string; datachartId: string; options }>,
377387
) {
378-
const dataChart = state.dataChartMap[action.payload.id];
388+
const dataChart = state.dataChartMap[dashboardId][datachartId];
379389

380390
if (dataChart?.config) {
381391
const index = dataChart?.config?.chartConfig?.datas?.findIndex(
382392
section => section.type === ChartDataSectionType.Group,
383393
);
384-
if (index !== undefined && dataChart.config.chartConfig.datas) {
385-
dataChart.config.chartConfig.datas[index].rows =
386-
action.payload.payload?.value?.rows;
394+
if (
395+
index !== undefined &&
396+
index >= 0 &&
397+
dataChart.config.chartConfig.datas
398+
) {
399+
dataChart.config.chartConfig.datas[index].rows = options?.value?.rows;
387400
}
388-
state.dataChartMap[action.payload.id] = dataChart;
401+
state.dataChartMap[dashboardId][datachartId] = dataChart;
389402
}
390403
},
391-
updateDataChartComputedFields(
404+
updateDataChartDataConfigComputedFields(
392405
state,
393-
action: PayloadAction<{
394-
id: string;
406+
{
407+
payload: { dashboardId, datachartId, computedFields },
408+
}: PayloadAction<{
409+
dashboardId: string;
410+
datachartId: string;
395411
computedFields: any;
396412
}>,
397413
) {
398-
const dataChart = state.dataChartMap[action.payload.id];
414+
const dataChart = state.dataChartMap[dashboardId][datachartId];
399415

400416
if (dataChart?.config) {
401-
dataChart.config.computedFields = action.payload.computedFields;
402-
state.dataChartMap[action.payload.id] = dataChart;
417+
dataChart.config.computedFields = computedFields;
418+
state.dataChartMap[dashboardId][datachartId] = dataChart;
403419
}
404420
},
405421
changeSelectedItems(

0 commit comments

Comments
 (0)