Skip to content

Commit efce237

Browse files
committed
refactor: getChartDrillOption in widget
1 parent 9d48082 commit efce237

File tree

1 file changed

+13
-31
lines changed

1 file changed

+13
-31
lines changed

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

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { ChartConfig } from 'app/types/ChartConfig';
2929
import { ChartDetailConfigDTO } from 'app/types/ChartConfigDTO';
3030
import { IChartDrillOption } from 'app/types/ChartDrillOption';
3131
import { mergeToChartConfig } from 'app/utils/ChartDtoHelper';
32-
import { getDrillPaths } from 'app/utils/chartHelper';
32+
import { getChartDrillOption } from 'app/utils/internalChartHelper';
3333
import produce from 'immer';
3434
import React, {
3535
memo,
@@ -41,7 +41,6 @@ import React, {
4141
} from 'react';
4242
import styled from 'styled-components/macro';
4343
import { BORDER_RADIUS } from 'styles/StyleConstants';
44-
import { isEmptyArray } from 'utils/object';
4544
import { WidgetActionContext } from '../../ActionProvider/WidgetActionProvider';
4645
import {
4746
boardDrillManager,
@@ -174,33 +173,16 @@ export const DataChartWidgetCore: React.FC<{}> = memo(() => {
174173
}, [chart?.config, dataChart?.config]);
175174

176175
useEffect(() => {
177-
let drillOption;
178-
const drillPaths = getDrillPaths(config?.datas);
179-
if (isEmptyArray(drillPaths)) {
180-
drillOption = undefined;
181-
drillOptionRef.current = drillOption;
182-
boardDrillManager.setWidgetDrill({
183-
bid,
184-
wid,
185-
drillOption,
186-
});
187-
return;
188-
}
189-
const preRefIds = drillOptionRef.current
190-
?.getAllFields()
191-
?.map(p => p.uid)
192-
.join('-');
193-
const pathIds = drillPaths.map(p => p.uid).join('-');
194-
195-
if (preRefIds !== pathIds) {
196-
drillOption = new ChartDrillOption(drillPaths);
197-
drillOptionRef.current = drillOption;
198-
boardDrillManager.setWidgetDrill({
199-
bid,
200-
wid,
201-
drillOption,
202-
});
203-
}
176+
let drillOption = getChartDrillOption(
177+
config?.datas,
178+
drillOptionRef.current,
179+
) as ChartDrillOption;
180+
drillOptionRef.current = drillOption;
181+
boardDrillManager.setWidgetDrill({
182+
bid,
183+
wid,
184+
drillOption,
185+
});
204186
}, [bid, config?.datas, wid]);
205187

206188
const errText = useMemo(() => {
@@ -223,7 +205,6 @@ export const DataChartWidgetCore: React.FC<{}> = memo(() => {
223205
if (cacheH <= 1 || cacheW <= 1) return null;
224206
if (errText) return errText;
225207
const drillOption = drillOptionRef.current;
226-
227208
return (
228209
<ChartIFrameContainer
229210
dataset={dataset}
@@ -247,8 +228,9 @@ export const DataChartWidgetCore: React.FC<{}> = memo(() => {
247228
chart,
248229
widgetSpecialConfig,
249230
]);
231+
250232
return (
251-
<Wrapper className="widget-chart" ref={ref}>
233+
<Wrapper id={renderMode + wid} className="widget-chart" ref={ref}>
252234
<ChartFrameBox>
253235
<PreviewBlock>
254236
<ChartDrillContext.Provider

0 commit comments

Comments
 (0)