6
6
useDraggable ,
7
7
useDroppable ,
8
8
} from "@dnd-kit/core" ;
9
- import { Trans } from "@lingui/macro" ;
10
- import { Box } from "@mui/material" ;
9
+ import { t , Trans } from "@lingui/macro" ;
10
+ import { Box , IconButton , useEventCallback } from "@mui/material" ;
11
11
import Head from "next/head" ;
12
12
import React , {
13
13
forwardRef ,
@@ -20,6 +20,7 @@ import React, {
20
20
import { DataSetTable } from "@/browse/datatable" ;
21
21
import { ChartDataFilters } from "@/charts/shared/chart-data-filters" ;
22
22
import { LoadingStateProvider } from "@/charts/shared/chart-loading-state" ;
23
+ import { ArrowMenu } from "@/components/arrow-menu" ;
23
24
import { ChartErrorBoundary } from "@/components/chart-error-boundary" ;
24
25
import { ChartFootnotes } from "@/components/chart-footnotes" ;
25
26
import {
@@ -35,10 +36,11 @@ import {
35
36
import { useChartStyles } from "@/components/chart-utils" ;
36
37
import { ChartWithFilters } from "@/components/chart-with-filters" ;
37
38
import DebugPanel from "@/components/debug-panel" ;
38
- import { DragHandle } from "@/components/drag-handle" ;
39
+ import { DragHandle , DragHandleProps } from "@/components/drag-handle" ;
39
40
import Flex from "@/components/flex" ;
40
41
import { Checkbox } from "@/components/form" ;
41
42
import { HintYellow } from "@/components/hint" ;
43
+ import { MenuActionItem } from "@/components/menu-action-item" ;
42
44
import { MetadataPanel } from "@/components/metadata-panel" ;
43
45
import { BANNER_MARGIN_TOP } from "@/components/presence" ;
44
46
import {
@@ -56,6 +58,7 @@ import {
56
58
useDataCubesMetadataQuery ,
57
59
} from "@/graphql/hooks" ;
58
60
import { DataCubePublicationStatus } from "@/graphql/resolver-types" ;
61
+ import SvgIcMore from "@/icons/components/IcMore" ;
59
62
import { useLocale } from "@/locales/use-locale" ;
60
63
import { InteractiveFiltersChartProvider } from "@/stores/interactive-filters" ;
61
64
import { useTransitionStore } from "@/stores/transition" ;
@@ -109,7 +112,7 @@ const DashboardPreview = (props: DashboardPreviewProps) => {
109
112
const [ over , setOver ] = useState < Over | null > ( null ) ;
110
113
const renderChart = useCallback (
111
114
( chartConfig : ChartConfig ) => {
112
- return layoutType === "tiles " ? (
115
+ return layoutType === "canvas " ? (
113
116
< ReactGridChartPreview
114
117
key = { chartConfig . key }
115
118
chartKey = { chartConfig . key }
@@ -129,7 +132,7 @@ const DashboardPreview = (props: DashboardPreviewProps) => {
129
132
[ dataSource , editing , layoutType , state . layout . type ]
130
133
) ;
131
134
132
- if ( layoutType === "tiles " ) {
135
+ if ( layoutType === "canvas " ) {
133
136
return (
134
137
< ChartPanelLayout
135
138
chartConfigs = { state . chartConfigs }
@@ -206,19 +209,86 @@ const DashboardPreview = (props: DashboardPreviewProps) => {
206
209
) ;
207
210
} ;
208
211
209
- type DndChartPreviewProps = ChartWrapperProps & {
212
+ type CommonChartPreviewProps = ChartWrapperProps & {
210
213
chartKey : string ;
211
214
dataSource : DataSource ;
212
215
} ;
213
216
214
- type ReactGridChartPreviewProps = ChartWrapperProps & {
217
+ const ChartPreviewChartMoreButton = ( { chartKey } : { chartKey : string } ) => {
218
+ const [ anchor , setAnchor ] = useState < HTMLElement | null > ( null ) ;
219
+ const handleClose = useEventCallback ( ( ) => setAnchor ( null ) ) ;
220
+ const [ state , dispatch ] = useConfiguratorState ( hasChartConfigs ) ;
221
+ return (
222
+ < >
223
+ < IconButton onClick = { ( ev ) => setAnchor ( ev . currentTarget ) } >
224
+ < SvgIcMore />
225
+ </ IconButton >
226
+ < ArrowMenu
227
+ open = { ! ! anchor }
228
+ anchorEl = { anchor }
229
+ onClose = { handleClose }
230
+ anchorOrigin = { { horizontal : "center" , vertical : "bottom" } }
231
+ transformOrigin = { { horizontal : "center" , vertical : "top" } }
232
+ >
233
+ < MenuActionItem
234
+ type = "button"
235
+ as = "menuitem"
236
+ onClick = { ( ) => {
237
+ dispatch ( { type : "CONFIGURE_CHART" , value : { chartKey } } ) ;
238
+ handleClose ( ) ;
239
+ } }
240
+ iconName = "edit"
241
+ label = { < Trans id = "chart-controls.edit" > Edit</ Trans > }
242
+ />
243
+ { state . chartConfigs . length > 1 ? (
244
+ < MenuActionItem
245
+ type = "button"
246
+ as = "menuitem"
247
+ color = "error"
248
+ requireConfirmation
249
+ confirmationTitle = { t ( {
250
+ id : "chart-controls.delete.title" ,
251
+ message : "Delete chart?" ,
252
+ } ) }
253
+ confirmationText = { t ( {
254
+ id : "chart-controls.delete.confirmation" ,
255
+ message : "Are you sure you want to delete this chart?" ,
256
+ } ) }
257
+ onClick = { ( ) => {
258
+ dispatch ( { type : "CHART_CONFIG_REMOVE" , value : { chartKey } } ) ;
259
+ handleClose ( ) ;
260
+ } }
261
+ iconName = "trash"
262
+ label = { < Trans id = "chart-controls.delete" > Delete</ Trans > }
263
+ />
264
+ ) : null }
265
+ </ ArrowMenu >
266
+ </ >
267
+ ) ;
268
+ } ;
269
+
270
+ const ChartTopRightControls = ( {
271
+ chartKey,
272
+ dragHandleProps,
273
+ } : {
215
274
chartKey : string ;
216
- dataSource : DataSource ;
275
+ dragHandleProps ?: DragHandleProps ;
276
+ } ) => {
277
+ return (
278
+ < >
279
+ < ChartPreviewChartMoreButton chartKey = { chartKey } />
280
+ < DragHandle
281
+ dragging
282
+ className = { chartPanelLayoutGridClasses . dragHandle }
283
+ { ...dragHandleProps }
284
+ />
285
+ </ >
286
+ ) ;
217
287
} ;
218
288
219
289
const ReactGridChartPreview = forwardRef <
220
290
HTMLDivElement ,
221
- ReactGridChartPreviewProps
291
+ CommonChartPreviewProps
222
292
> ( ( props , ref ) => {
223
293
const { children, chartKey, dataSource, ...rest } = props ;
224
294
return (
@@ -227,12 +297,7 @@ const ReactGridChartPreview = forwardRef<
227
297
< ChartPreviewInner
228
298
dataSource = { dataSource }
229
299
chartKey = { chartKey }
230
- actionElementSlot = {
231
- < DragHandle
232
- dragging
233
- className = { chartPanelLayoutGridClasses . dragHandle }
234
- />
235
- }
300
+ actionElementSlot = { < ChartTopRightControls chartKey = { chartKey } /> }
236
301
>
237
302
{ children }
238
303
</ ChartPreviewInner >
@@ -241,7 +306,7 @@ const ReactGridChartPreview = forwardRef<
241
306
) ;
242
307
} ) ;
243
308
244
- const DndChartPreview = ( props : DndChartPreviewProps ) => {
309
+ const DndChartPreview = ( props : CommonChartPreviewProps ) => {
245
310
const { children, chartKey, dataSource, ...rest } = props ;
246
311
const theme = useTheme ( ) ;
247
312
const {
@@ -285,10 +350,13 @@ const DndChartPreview = (props: DndChartPreviewProps) => {
285
350
dataSource = { dataSource }
286
351
chartKey = { chartKey }
287
352
actionElementSlot = {
288
- < DragHandle
289
- { ...listeners }
290
- ref = { setActivatorNodeRef }
291
- dragging = { isDragging }
353
+ < ChartTopRightControls
354
+ chartKey = { chartKey }
355
+ dragHandleProps = { {
356
+ ...listeners ,
357
+ ref : setActivatorNodeRef ,
358
+ dragging : isDragging ,
359
+ } }
292
360
/>
293
361
}
294
362
/>
@@ -317,24 +385,27 @@ const SingleURLsPreview = (props: SingleURLsPreviewProps) => {
317
385
dataSource = { dataSource }
318
386
chartKey = { chartConfig . key }
319
387
actionElementSlot = {
320
- < Checkbox
321
- checked = { checked }
322
- disabled = { keys . length === 1 && checked }
323
- onChange = { ( ) => {
324
- dispatch ( {
325
- type : "LAYOUT_CHANGED" ,
326
- value : {
327
- ...layout ,
328
- publishableChartKeys : checked
329
- ? keys . filter ( ( k ) => k !== key )
330
- : state . chartConfigs
331
- . map ( ( c ) => c . key )
332
- . filter ( ( k ) => keys . includes ( k ) || k === key ) ,
333
- } ,
334
- } ) ;
335
- } }
336
- label = ""
337
- />
388
+ < >
389
+ < ChartPreviewChartMoreButton chartKey = { key } />
390
+ < Checkbox
391
+ checked = { checked }
392
+ disabled = { keys . length === 1 && checked }
393
+ onChange = { ( ) => {
394
+ dispatch ( {
395
+ type : "LAYOUT_CHANGED" ,
396
+ value : {
397
+ ...layout ,
398
+ publishableChartKeys : checked
399
+ ? keys . filter ( ( k ) => k !== key )
400
+ : state . chartConfigs
401
+ . map ( ( c ) => c . key )
402
+ . filter ( ( k ) => keys . includes ( k ) || k === key ) ,
403
+ } ,
404
+ } ) ;
405
+ } }
406
+ label = ""
407
+ />
408
+ </ >
338
409
}
339
410
/>
340
411
</ ChartWrapper >
0 commit comments