Skip to content

Commit

Permalink
refactor: Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
bprusinowski committed Nov 25, 2024
1 parent a343e18 commit b51e4f7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 34 deletions.
12 changes: 5 additions & 7 deletions app/components/chart-panel-layout-grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ const decodeLayouts = (layouts: Layouts) => {
);
};

const ChartPanelLayoutCanvas = (props: ChartPanelLayoutTypeProps) => {
const { chartConfigs } = props;
export const ChartPanelLayoutCanvas = (props: ChartPanelLayoutTypeProps) => {
const { chartConfigs, renderChart, className } = props;
const [state, dispatch] = useConfiguratorState(hasChartConfigs);
const [layouts, setLayouts] = useState<Layouts>(() => {
assert(
Expand Down Expand Up @@ -69,16 +69,14 @@ const ChartPanelLayoutCanvas = (props: ChartPanelLayoutTypeProps) => {
return (
<ChartGridLayout
key={state.state}
className={clsx(chartPanelLayoutGridClasses.root, props.className)}
className={clsx(chartPanelLayoutGridClasses.root, className)}
layouts={layouts}
resize={state.state === "LAYOUTING"}
draggableHandle={`.${chartPanelLayoutGridClasses.dragHandle}`}
onLayoutChange={(_l, allLayouts) => handleChangeLayouts(allLayouts)}
onLayoutChange={(_, allLayouts) => handleChangeLayouts(allLayouts)}
breakpoints={FREE_CANVAS_BREAKPOINTS}
>
{chartConfigs.map((chartConfig) => props.renderChart(chartConfig))}
{chartConfigs.map(renderChart)}
</ChartGridLayout>
);
};

export default ChartPanelLayoutCanvas;
3 changes: 2 additions & 1 deletion app/components/chart-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { makeStyles } from "@mui/styles";
import clsx from "clsx";
import React, { HTMLProps, forwardRef } from "react";

import ChartPanelLayoutCanvas, {
import {
ChartPanelLayoutCanvas,
chartPanelLayoutGridClasses,
} from "@/components/chart-panel-layout-grid";
import { ChartPanelLayoutTall } from "@/components/chart-panel-layout-tall";
Expand Down
5 changes: 2 additions & 3 deletions app/components/react-grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { getChartWrapperId } from "@/components/chart-panel";
import {
hasChartConfigs,
isLayouting,
LayoutDashboardFreeCanvas,
ReactGridLayoutType,
} from "@/configurator";
import { useTimeout } from "@/hooks/use-timeout";
Expand Down Expand Up @@ -227,11 +226,11 @@ export const ChartGridLayout = ({
} & ComponentProps<typeof ResponsiveReactGridLayout>) => {
const classes = useStyles();
const [state, dispatch] = useConfiguratorState(hasChartConfigs);
const configLayout = state.layout;
assert(
state.layout.type === "dashboard" && state.layout.layout === "canvas",
configLayout.type === "dashboard" && configLayout.layout === "canvas",
"ChartGridLayout can only be used in a canvas layout!"
);
const configLayout = state.layout as LayoutDashboardFreeCanvas;
const allowHeightInitialization = isLayouting(state);
const [mounted, setMounted] = useState(false);
const mountedForSomeTime = useTimeout(500, mounted);
Expand Down
41 changes: 18 additions & 23 deletions app/configurator/components/layout-configurator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ const LayoutSharedFiltersConfigurator = () => {
{/* TODO: allow TemporalOrdinalDimensions to work here */}
{timeRange && combinedTemporalDimension.values.length ? (
<>
<Box
sx={{
<div
style={{
display: "flex",
justifyContent: "space-between",
alignItems: "center",
Expand All @@ -258,7 +258,7 @@ const LayoutSharedFiltersConfigurator = () => {
checked={timeRange.active}
onChange={handleTimeRangeFilterToggle}
/>
</Box>
</div>
{timeRange.active ? (
<DashboardFiltersOptions
timeRangeFilter={timeRange}
Expand All @@ -270,51 +270,46 @@ const LayoutSharedFiltersConfigurator = () => {
{dataFilters ? (
<>
{potentialDataFilterIds.map((id, i) => {
const dimension = dimensions.find(
(dimension) => dimension.id === id
);
if (!dimension) {
const dim = dimensions.find((d) => d.id === id);

if (!dim) {
return null;
}
const checked = dataFilters.componentIds.includes(
dimension.id
);

const checked = dataFilters.componentIds.includes(dim.id);

return (
<Box
key={dimension.id}
sx={{ display: "flex", flexDirection: "column" }}
<div
key={dim.id}
style={{ display: "flex", flexDirection: "column" }}
>
<Box
sx={{
<div
style={{
display: "flex",
justifyContent: "space-between",
alignItems: "center",
}}
>
<Typography variant="body2">
{dimension.label}
</Typography>
<Typography variant="body2">{dim.label}</Typography>
<Switch
checked={checked}
onChange={(_, checked) => {
handleDataFiltersToggle(checked, dimension.id);
handleDataFiltersToggle(checked, dim.id);
}}
/>
</Box>
</div>
{checked ? (
<Box sx={{ mb: 1 }}>
<DataFilterSelectGeneric
key={dimension.id}
rawDimension={dimension}
rawDimension={dim}
filterDimensionIds={[]}
index={i}
disabled={fetching}
disableLabel
/>
</Box>
) : null}
</Box>
</div>
);
})}
</>
Expand Down

0 comments on commit b51e4f7

Please sign in to comment.