@@ -22,7 +22,6 @@ import { DownloadFileType } from 'app/constants';
2222import useI18NPrefix from 'app/hooks/useI18NPrefix' ;
2323import useMount from 'app/hooks/useMount' ;
2424import { ChartDataRequestBuilder } from 'app/models/ChartDataRequestBuilder' ;
25- import { ChartDrillOption } from 'app/models/ChartDrillOption' ;
2625import ChartManager from 'app/models/ChartManager' ;
2726import workbenchSlice , {
2827 useWorkbenchSlice ,
@@ -52,9 +51,11 @@ import {
5251import { IChart } from 'app/types/Chart' ;
5352import { IChartDrillOption } from 'app/types/ChartDrillOption' ;
5453import { ChartDTO } from 'app/types/ChartDTO' ;
55- import { getDrillPaths } from 'app/utils/chartHelper' ;
5654import { makeDownloadDataTask } from 'app/utils/fetch' ;
57- import { transferChartConfigs } from 'app/utils/internalChartHelper' ;
55+ import {
56+ getChartDrillOption ,
57+ transferChartConfigs ,
58+ } from 'app/utils/internalChartHelper' ;
5859import { CommonFormTypes } from 'globalConstants' ;
5960import { FC , useCallback , useEffect , useMemo , useRef , useState } from 'react' ;
6061import { useDispatch , useSelector } from 'react-redux' ;
@@ -200,12 +201,8 @@ export const ChartEditor: FC<ChartEditorProps> = ({
200201 } , [ backendChart ?. config ?. chartGraphId ] ) ;
201202
202203 useEffect ( ( ) => {
203- const drillPaths = getDrillPaths ( chartConfig ?. datas ) ;
204- if ( isEmptyArray ( drillPaths ) ) {
205- drillOptionRef . current = undefined ;
206- }
207- if ( ! isEmptyArray ( drillPaths ) && ! drillOptionRef . current ) {
208- drillOptionRef . current = new ChartDrillOption ( drillPaths ) ;
204+ if ( ! isEmptyArray ( chartConfig ?. datas ) && ! drillOptionRef . current ) {
205+ drillOptionRef . current = getChartDrillOption ( chartConfig ?. datas ) ;
209206 }
210207 } , [ chartConfig ?. datas , drillOptionRef ] ) ;
211208
@@ -219,7 +216,7 @@ export const ChartEditor: FC<ChartEditorProps> = ({
219216 const option = drillOptionRef . current ;
220217 option . drillDown ( param . data . rowData ) ;
221218 drillOptionRef . current = option ;
222- handleDrillOptionChange ( option ) ;
219+ handleDrillOptionChange ?. ( option ) ;
223220 return ;
224221 }
225222 if (
@@ -273,6 +270,10 @@ export const ChartEditor: FC<ChartEditorProps> = ({
273270 } ,
274271 } ) ,
275272 ) ;
273+ drillOptionRef . current = getChartDrillOption (
274+ chartConfig ?. datas ,
275+ drillOptionRef . current ,
276+ ) ;
276277 } , [ dispatch , chart ?. meta ?. id , registerChartEvents ] ) ;
277278
278279 const handleChartChange = ( c : IChart ) => {
@@ -292,6 +293,10 @@ export const ChartEditor: FC<ChartEditorProps> = ({
292293 } ,
293294 } ) ,
294295 ) ;
296+ drillOptionRef . current = getChartDrillOption (
297+ chartConfig ?. datas ,
298+ drillOptionRef . current ,
299+ ) ;
295300 if ( ! expensiveQuery ) {
296301 dispatch ( refreshDatasetAction ( { drillOption : drillOptionRef ?. current } ) ) ;
297302 } else {
@@ -301,20 +306,6 @@ export const ChartEditor: FC<ChartEditorProps> = ({
301306
302307 const handleChartConfigChange = useCallback (
303308 ( type , payload ) => {
304- const drillPaths = getDrillPaths ( chartConfig ?. datas ) ;
305- if ( isEmptyArray ( drillPaths ) ) {
306- drillOptionRef . current = undefined ;
307- }
308- if (
309- ! isEmptyArray ( drillPaths ) &&
310- drillOptionRef . current
311- ?. getAllFields ( )
312- ?. map ( p => p . uid )
313- . join ( '-' ) !== drillPaths . map ( p => p . uid ) . join ( '-' )
314- ) {
315- drillOptionRef . current = new ChartDrillOption ( drillPaths ) ;
316- }
317-
318309 if ( expensiveQuery ) {
319310 dispatch (
320311 workbenchSlice . actions . updateChartConfig ( {
@@ -332,11 +323,17 @@ export const ChartEditor: FC<ChartEditorProps> = ({
332323 type,
333324 payload,
334325 needRefresh : payload . needRefresh ,
335- drillOption : drillOptionRef ?. current ,
326+ updateDrillOption : config => {
327+ drillOptionRef . current = getChartDrillOption (
328+ config ?. datas ,
329+ drillOptionRef . current ,
330+ ) ;
331+ return drillOptionRef . current ;
332+ } ,
336333 } ) ,
337334 ) ;
338335 } ,
339- [ chartConfig ?. datas , dispatch , expensiveQuery ] ,
336+ [ dispatch , expensiveQuery ] ,
340337 ) ;
341338
342339 const handleDataViewChanged = useCallback ( ( ) => {
0 commit comments