Skip to content

Commit cbf00b7

Browse files
authored
Merge pull request #996 from xieliuduo/fix-viewId
hotfix: handle view model by transformMeta and fix chart with no view eg richTextChart
2 parents cc67d3d + f5c4a54 commit cbf00b7

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

frontend/src/app/pages/DashBoardPage/pages/BoardEditor/components/ControllerWidgetPanel/ControllerConfig/ValuesSetter/ValuesOptionsSetter/ValuesOptionsSetter.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import ChartDataView from 'app/types/ChartDataView';
2828
import { ControllerFacadeTypes } from 'app/types/FilterControlPanel';
2929
import { View } from 'app/types/View';
3030
import { getDistinctFields } from 'app/utils/fetch';
31+
import { transformMeta } from 'app/utils/internalChartHelper';
3132
import { FC, memo, useCallback, useEffect, useMemo, useState } from 'react';
3233
import styled from 'styled-components/macro';
3334
import { request2 } from 'utils/request';
@@ -69,11 +70,12 @@ const ValuesOptionsSetter: FC<{
6970
if (!viewId) return [];
7071
try {
7172
const { data } = await request2<View>(`/views/${viewId}`);
72-
const model = JSON.parse(data.model);
73-
const option: CascaderOptionType[] = Object.keys(model).map(key => {
73+
let meta = transformMeta(data?.model);
74+
if (!meta) return [];
75+
const option: CascaderOptionType[] = meta.map(item => {
7476
return {
75-
value: key,
76-
label: key,
77+
value: item.id,
78+
label: item.id,
7779
};
7880
});
7981
return option;

frontend/src/app/pages/DashBoardPage/pages/BoardEditor/slice/thunk.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,19 +279,20 @@ export const addWrapChartWidget = createAsyncThunk<
279279
{ getState, dispatch },
280280
) => {
281281
const dataCharts = [dataChart];
282-
const viewViews = [view];
282+
const viewViews = view ? [view] : [];
283283
dispatch(boardActions.setDataChartToMap(dataCharts));
284284
dispatch(boardActions.setViewMap(viewViews));
285285
let widget = widgetToolKit.chart.create({
286286
dashboardId: boardId,
287287
boardType: boardType,
288288
dataChartId: chartId,
289-
viewId: view.id,
289+
viewId: view?.id || '',
290290
dataChartConfig: dataChart,
291291
subType: 'widgetChart',
292292
});
293293
dispatch(addWidgetsToEditBoard([widget]));
294-
dispatch(addVariablesToBoard(view.variables));
294+
dispatch(addVariablesToBoard(view?.variables));
295+
295296
return null;
296297
},
297298
);

frontend/src/app/pages/DashBoardPage/utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ export const getChartWidgetRequestParams = (obj: {
420420
// errorHandle(`can\`t find Chart ${curWidget.datachartId}`);
421421
return null;
422422
}
423+
if (!dataChart.viewId) return null;
423424
const chartDataView = viewMap[dataChart?.viewId];
424425

425426
if (!chartDataView) {

0 commit comments

Comments
 (0)