@@ -200,12 +200,8 @@ export const ChartEditor: FC<ChartEditorProps> = ({
200200 } , [ backendChart ?. config ?. chartGraphId ] ) ;
201201
202202 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 ) ;
203+ if ( ! drillOptionRef . current ) {
204+ initChartDrillOption ( chartConfig ?. datas ) ;
209205 }
210206 } , [ chartConfig ?. datas , drillOptionRef ] ) ;
211207
@@ -219,7 +215,7 @@ export const ChartEditor: FC<ChartEditorProps> = ({
219215 const option = drillOptionRef . current ;
220216 option . drillDown ( param . data . rowData ) ;
221217 drillOptionRef . current = option ;
222- handleDrillOptionChange ( option ) ;
218+ handleDrillOptionChange ?. ( option ) ;
223219 return ;
224220 }
225221 if (
@@ -273,6 +269,7 @@ export const ChartEditor: FC<ChartEditorProps> = ({
273269 } ,
274270 } ) ,
275271 ) ;
272+ initChartDrillOption ( finalChartConfig ?. datas ) ;
276273 } , [ dispatch , chart ?. meta ?. id , registerChartEvents ] ) ;
277274
278275 const handleChartChange = ( c : IChart ) => {
@@ -292,29 +289,16 @@ export const ChartEditor: FC<ChartEditorProps> = ({
292289 } ,
293290 } ) ,
294291 ) ;
292+ const drillOpt = initChartDrillOption ( finalChartConfig ?. datas ) ;
295293 if ( ! expensiveQuery ) {
296- dispatch ( refreshDatasetAction ( { drillOption : drillOptionRef ?. current } ) ) ;
294+ dispatch ( refreshDatasetAction ( { drillOption : drillOpt } ) ) ;
297295 } else {
298296 setAllowQuery ( true ) ;
299297 }
300298 } ;
301299
302300 const handleChartConfigChange = useCallback (
303301 ( 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-
318302 if ( expensiveQuery ) {
319303 dispatch (
320304 workbenchSlice . actions . updateChartConfig ( {
@@ -332,11 +316,11 @@ export const ChartEditor: FC<ChartEditorProps> = ({
332316 type,
333317 payload,
334318 needRefresh : payload . needRefresh ,
335- drillOption : drillOptionRef ?. current ,
319+ updateDrillOption : config => initChartDrillOption ( config ?. datas ) ,
336320 } ) ,
337321 ) ;
338322 } ,
339- [ chartConfig ?. datas , dispatch , expensiveQuery ] ,
323+ [ dispatch , expensiveQuery ] ,
340324 ) ;
341325
342326 const handleDataViewChanged = useCallback ( ( ) => {
@@ -545,6 +529,25 @@ export const ChartEditor: FC<ChartEditorProps> = ({
545529 dispatch ( refreshDatasetAction ( { drillOption : option } ) ) ;
546530 } ;
547531
532+ const initChartDrillOption = (
533+ datas ?: any [ ] ,
534+ ) : IChartDrillOption | undefined => {
535+ const drillPaths = getDrillPaths ( datas ) ;
536+ if ( isEmptyArray ( drillPaths ) ) {
537+ drillOptionRef . current = undefined ;
538+ }
539+ if (
540+ ! isEmptyArray ( drillPaths ) &&
541+ drillOptionRef . current
542+ ?. getAllFields ( )
543+ ?. map ( p => p . uid )
544+ . join ( '-' ) !== drillPaths . map ( p => p . uid ) . join ( '-' )
545+ ) {
546+ drillOptionRef . current = new ChartDrillOption ( drillPaths ) ;
547+ }
548+ return drillOptionRef . current ;
549+ } ;
550+
548551 return (
549552 < StyledChartWorkbenchPage >
550553 < SaveFormContext . Provider value = { saveFormContextValue } >
0 commit comments