-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathchart-panel.tsx
More file actions
114 lines (106 loc) · 3.35 KB
/
chart-panel.tsx
File metadata and controls
114 lines (106 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import { Box, BoxProps, Theme } from "@mui/material";
import { makeStyles } from "@mui/styles";
import clsx from "clsx";
import React, { HTMLProps, forwardRef } from "react";
import ChartPanelLayoutCanvas, {
chartPanelLayoutGridClasses,
} from "@/components/chart-panel-layout-grid";
import { ChartPanelLayoutTall } from "@/components/chart-panel-layout-tall";
import { ChartPanelLayoutVertical } from "@/components/chart-panel-layout-vertical";
import { ChartSelectionTabs } from "@/components/chart-selection-tabs";
import { DashboardInteractiveFilters } from "@/components/dashboard-interactive-filters";
import { ChartConfig, Layout, LayoutDashboard } from "@/config-types";
import { hasChartConfigs } from "@/configurator";
import { useConfiguratorState } from "@/src";
const useStyles = makeStyles((theme: Theme) => ({
panelLayout: {
display: "flex",
flexDirection: "column",
gap: theme.spacing(4),
},
chartWrapper: {
[`.${chartPanelLayoutGridClasses.root} &`]: {
transition: theme.transitions.create(["box-shadow"], {
duration: theme.transitions.duration.shortest,
}),
},
[`.${chartPanelLayoutGridClasses.root} &:has(.${chartPanelLayoutGridClasses.dragHandle}:hover)`]:
{
boxShadow: theme.shadows[6],
},
},
chartWrapperInner: {
display: "contents",
overflow: "hidden",
width: "auto",
height: "100%",
},
}));
export type ChartWrapperProps = BoxProps & {
editing?: boolean;
layoutType?: Layout["type"];
};
export const ChartWrapper = forwardRef<HTMLDivElement, ChartWrapperProps>(
(props, ref) => {
const { children, editing, layoutType, ...rest } = props;
const classes = useStyles();
return (
<Box
ref={ref}
{...rest}
className={clsx(classes.chartWrapper, props.className, "chart-wrapper")}
>
{(editing || layoutType === "tab") && <ChartSelectionTabs />}
<Box
className={classes.chartWrapperInner}
sx={{ minHeight: [150, 300, 500] }}
>
{children}
</Box>
</Box>
);
}
);
type ChartPanelLayoutProps = React.PropsWithChildren<{
layoutType: LayoutDashboard["layout"];
chartConfigs: ChartConfig[];
renderChart: (chartConfig: ChartConfig) => JSX.Element;
}> &
HTMLProps<HTMLDivElement>;
export type ChartPanelLayoutTypeProps = {
chartConfigs: ChartConfig[];
renderChart: (chartConfig: ChartConfig) => JSX.Element;
className?: string;
};
const Wrappers: Record<
LayoutDashboard["layout"],
(props: ChartPanelLayoutTypeProps) => JSX.Element
> = {
vertical: ChartPanelLayoutVertical,
tall: ChartPanelLayoutTall,
canvas: ChartPanelLayoutCanvas,
};
export const ChartPanelLayout = (props: ChartPanelLayoutProps) => {
const {
children,
renderChart,
chartConfigs,
className,
layoutType,
...rest
} = props;
const classes = useStyles();
const Wrapper = Wrappers[layoutType];
const [state] = useConfiguratorState(hasChartConfigs);
return (
<div className={clsx(classes.panelLayout, className)} {...rest}>
{/** We want to completely remount this component if chartConfigs change */}
{state.layout.type === "dashboard" ? (
<DashboardInteractiveFilters
key={chartConfigs.map((x) => x.key).join(",")}
/>
) : null}
<Wrapper chartConfigs={chartConfigs} renderChart={renderChart} />
</div>
);
};