1616 * limitations under the License.
1717 */
1818
19+ import ChartDrillContextMenu from 'app/components/ChartDrill/ChartDrillContextMenu' ;
20+ import ChartDrillPaths from 'app/components/ChartDrill/ChartDrillPaths' ;
1921import { ChartIFrameContainer } from 'app/components/ChartIFrameContainer' ;
2022import useMount from 'app/hooks/useMount' ;
2123import useResizeObserver from 'app/hooks/useResizeObserver' ;
24+ import { ChartDrillOption } from 'app/models/ChartDrillOption' ;
2225import ChartManager from 'app/models/ChartManager' ;
2326import { IChart } from 'app/types/Chart' ;
24- import { FC , memo , useState } from 'react' ;
27+ import { IChartDrillOption } from 'app/types/ChartDrillOption' ;
28+ import { getDrillPaths } from 'app/utils/chartHelper' ;
29+ import { FC , memo , useRef , useState } from 'react' ;
2530import { useDispatch , useSelector } from 'react-redux' ;
2631import styled from 'styled-components/macro' ;
32+ import { isEmptyArray } from 'utils/object' ;
33+ import ChartDrillContext from '../ChartWorkbenchPage/contexts/ChartDrillContext' ;
2734import ControllerPanel from '../MainPage/pages/VizPage/ChartPreview/components/ControllerPanel' ;
2835import {
2936 ChartPreview ,
@@ -43,6 +50,7 @@ const ChartForShare: FC<{
4350 filterSearchParams ?: FilterSearchParams ;
4451} > = memo ( ( { chartPreview } ) => {
4552 const dispatch = useDispatch ( ) ;
53+ const drillOptionRef = useRef < IChartDrillOption > ( ) ;
4654 const [ chart ] = useState < IChart | undefined > ( ( ) => {
4755 const currentChart = ChartManager . instance ( ) . getById (
4856 chartPreview ?. backendChart ?. config ?. chartGraphId ,
@@ -69,6 +77,19 @@ const ChartForShare: FC<{
6977 if ( ! chartPreview ) {
7078 return ;
7179 }
80+ const drillPaths = getDrillPaths ( chartPreview ?. chartConfig ?. datas ) ;
81+ if ( isEmptyArray ( drillPaths ) ) {
82+ drillOptionRef . current = undefined ;
83+ }
84+ if (
85+ ! isEmptyArray ( drillPaths ) &&
86+ drillOptionRef . current
87+ ?. getAllFields ( )
88+ ?. map ( p => p . uid )
89+ . join ( '-' ) !== drillPaths . map ( p => p . uid ) . join ( '-' )
90+ ) {
91+ drillOptionRef . current = new ChartDrillOption ( drillPaths ) ;
92+ }
7293 dispatch ( fetchShareDataSetByPreviewChartAction ( { preview : chartPreview } ) ) ;
7394 registerChartEvents ( chart ) ;
7495 } ) ;
@@ -78,6 +99,13 @@ const ChartForShare: FC<{
7899 {
79100 name : 'click' ,
80101 callback : param => {
102+ if ( drillOptionRef . current ?. isSelectedDrill ) {
103+ const option = drillOptionRef . current ;
104+ option . drillDown ( param . data . rowData ) ;
105+ drillOptionRef . current = option ;
106+ handleDrillOptionChange ( option ) ;
107+ return ;
108+ }
81109 if (
82110 param . componentType === 'table' &&
83111 param . seriesType === 'paging-sort-filter'
@@ -108,6 +136,19 @@ const ChartForShare: FC<{
108136 backendChartId : chartPreview ?. backendChart ?. id ! ,
109137 chartPreview,
110138 payload,
139+ drillOption : drillOptionRef ?. current ,
140+ } ) ,
141+ ) ;
142+ } ;
143+
144+ const handleDrillOptionChange = ( option : IChartDrillOption ) => {
145+ drillOptionRef . current = option ;
146+ dispatch (
147+ updateFilterAndFetchDatasetForShare ( {
148+ backendChartId : chartPreview ?. backendChart ?. id ! ,
149+ chartPreview,
150+ payload : null ,
151+ drillOption : drillOptionRef ?. current ,
111152 } ) ,
112153 ) ;
113154 } ;
@@ -121,18 +162,28 @@ const ChartForShare: FC<{
121162 onChange = { handleFilterChange }
122163 />
123164 </ div >
124-
125- < div style = { { width : '100%' , height : '100%' } } ref = { ref } >
126- < ChartIFrameContainer
127- key = { chartPreview ?. backendChart ?. id ! }
128- containerId = { chartPreview ?. backendChart ?. id ! }
129- dataset = { chartPreview ?. dataset }
130- chart = { chart ! }
131- config = { chartPreview ?. chartConfig ! }
132- width = { width }
133- height = { height }
134- />
135- </ div >
165+ < ChartDrillContext . Provider
166+ value = { {
167+ drillOption : drillOptionRef . current ,
168+ onDrillOptionChange : handleDrillOptionChange ,
169+ } }
170+ >
171+ < div style = { { width : '100%' , height : '100%' } } ref = { ref } >
172+ < ChartDrillContextMenu >
173+ < ChartIFrameContainer
174+ key = { chartPreview ?. backendChart ?. id ! }
175+ containerId = { chartPreview ?. backendChart ?. id ! }
176+ dataset = { chartPreview ?. dataset }
177+ chart = { chart ! }
178+ config = { chartPreview ?. chartConfig ! }
179+ width = { width }
180+ height = { height }
181+ />
182+ </ ChartDrillContextMenu >
183+ </ div >
184+ < ChartDrillPaths />
185+ </ ChartDrillContext . Provider >
186+ < ChartDrillPaths /> x
136187 < HeadlessBrowserIdentifier
137188 renderSign = { headlessBrowserRenderSign }
138189 width = { Number ( width ) || 0 }
@@ -150,6 +201,10 @@ const StyledChartPreviewBoard = styled.div`
150201 width: 100%;
151202 height: 100%;
152203
204+ .chart-drill-menu-container {
205+ height: 100%;
206+ }
207+
153208 iframe {
154209 flex-grow: 1000;
155210 }
0 commit comments