Skip to content

Commit

Permalink
feat: Add initial layout prop to configurator schema
Browse files Browse the repository at this point in the history
  • Loading branch information
bprusinowski committed Dec 6, 2023
1 parent afefce6 commit abcb0b1
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
7 changes: 7 additions & 0 deletions app/config-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1103,11 +1103,18 @@ const DataSource = t.type({
});
export type DataSource = t.TypeOf<typeof DataSource>;

const Layout = t.type({
type: t.literal("tab"),
});
export type Layout = t.TypeOf<typeof Layout>;
export type LayoutType = Layout["type"];

const Config = t.type(
{
version: t.string,
dataSource: DataSource,
meta: Meta,
layout: Layout,
chartConfigs: t.array(ChartConfig),
activeChartKey: t.string,
},
Expand Down
12 changes: 11 additions & 1 deletion app/configurator/components/configurator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,17 @@ const LayoutingStep = () => {
mx: "auto",
}}
>
<IconButton label="layoutTab" onClick={() => {}} />
<IconButton
label="layoutTab"
checked={state.layout.type === "tab"}
onClick={() => {
if (state.layout.type === "tab") {
return;
}

dispatch({ type: "LAYOUT_CHANGED", value: { type: "tab" } });
}}
/>
</PanelHeaderWrapper>
<PanelHeaderWrapper
type="R"
Expand Down
15 changes: 15 additions & 0 deletions app/configurator/configurator-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
GenericFields,
ImputationType,
InteractiveFiltersConfig,
LayoutType,
decodeConfiguratorState,
enableLayouting,
getChartConfig,
Expand Down Expand Up @@ -292,6 +293,12 @@ export type ConfiguratorStateAction =
| {
type: "SWITCH_ACTIVE_CHART";
value: string;
}
| {
type: "LAYOUT_CHANGED";
value: {
type: LayoutType;
};
};

const LOCALSTORAGE_PREFIX = "vizualize-configurator-state";
Expand Down Expand Up @@ -642,6 +649,7 @@ const transitionStepNext = (
state: "CONFIGURING_CHART",
dataSource: draft.dataSource,
meta: draft.meta,
layout: { type: "tab" },
chartConfigs: [chartConfig],
activeChartKey: chartConfig.key,
};
Expand Down Expand Up @@ -1359,6 +1367,13 @@ const reducer: Reducer<ConfiguratorState, ConfiguratorStateAction> = (

return draft;

case "LAYOUT_CHANGED":
if (draft.state === "LAYOUTING") {
draft.layout = action.value;
}

return draft;

default:
throw unreachableError(action);
}
Expand Down
21 changes: 20 additions & 1 deletion app/utils/chart-config/versioning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ export const migrateChartConfig = makeMigrate(chartConfigMigrations, {
defaultToVersion: CHART_CONFIG_VERSION,
});

export const CONFIGURATOR_STATE_VERSION = "3.0.1";
export const CONFIGURATOR_STATE_VERSION = "3.1.0";

const configuratorStateMigrations: Migration[] = [
{
Expand Down Expand Up @@ -940,6 +940,25 @@ const configuratorStateMigrations: Migration[] = [
});
},
},
{
description: "ALL + layout",
from: "3.0.1",
to: "3.1.0",
up: (config) => {
const newConfig = { ...config, version: "3.1.0" };

return produce(newConfig, (draft: any) => {
draft.layout = { type: "tab" };
});
},
down: (config) => {
const newConfig = { ...config, version: "3.0.1" };

return produce(newConfig, (draft: any) => {
delete draft.layout;
});
},
},
];

export const migrateConfiguratorState = makeMigrate(
Expand Down

0 comments on commit abcb0b1

Please sign in to comment.