Skip to content

Commit

Permalink
feat: Add layouting types
Browse files Browse the repository at this point in the history
...state that's only allowed if we have more than one chart config.
  • Loading branch information
bprusinowski committed Dec 5, 2023
1 parent 7e28592 commit 740637b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
17 changes: 17 additions & 0 deletions app/config-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,22 @@ export type ConfiguratorStateConfiguringChart = t.TypeOf<
typeof ConfiguratorStateConfiguringChart
>;

const ConfiguratorStateLayouting = t.intersection([
t.type({
state: t.literal("LAYOUTING"),
}),
Config,
]);
export type ConfiguratorStateLayouting = t.TypeOf<
typeof ConfiguratorStateLayouting
>;

export const enableLayouting = (
state: ConfiguratorStateConfiguringChart | ConfiguratorStatePublishing
) => {
return state.chartConfigs.length > 1;
};

const ConfiguratorStatePublishing = t.intersection([
t.type({
state: t.literal("PUBLISHING"),
Expand All @@ -1178,6 +1194,7 @@ const ConfiguratorState = t.union([
ConfiguratorStateInitial,
ConfiguratorStateSelectingDataSet,
ConfiguratorStateConfiguringChart,
ConfiguratorStateLayouting,
ConfiguratorStatePublishing,
ConfiguratorStatePublished,
]);
Expand Down
21 changes: 17 additions & 4 deletions app/configurator/configurator-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
ImputationType,
InteractiveFiltersConfig,
decodeConfiguratorState,
enableLayouting,
getChartConfig,
getChartConfigFilters,
isAreaConfig,
Expand Down Expand Up @@ -646,6 +647,11 @@ const transitionStepNext = (
}
break;
case "CONFIGURING_CHART":
return {
...draft,
state: enableLayouting(draft) ? "LAYOUTING" : "PUBLISHING",
};
case "LAYOUTING":
return {
...draft,
state: "PUBLISHING",
Expand All @@ -663,14 +669,20 @@ const transitionStepNext = (
};

const getPreviousState = (
state: ConfiguratorState["state"]
draft: ConfiguratorState
): Exclude<ConfiguratorState["state"], "INITIAL" | "PUBLISHING"> => {
switch (state) {
switch (draft.state) {
case "SELECTING_DATASET":
return state;
return draft.state;
case "CONFIGURING_CHART":
return "SELECTING_DATASET";
case "LAYOUTING":
return "CONFIGURING_CHART";
case "PUBLISHING":
if (enableLayouting(draft)) {
return "LAYOUTING";
}

return "CONFIGURING_CHART";
default:
return "SELECTING_DATASET";
Expand All @@ -681,7 +693,7 @@ const transitionStepPrevious = (
draft: ConfiguratorState,
to?: Exclude<ConfiguratorState["state"], "INITIAL" | "PUBLISHING">
): ConfiguratorState => {
const stepTo = to ?? getPreviousState(draft.state);
const stepTo = to ?? getPreviousState(draft);

// Special case when we're already at INITIAL
if (draft.state === "INITIAL" || draft.state === "SELECTING_DATASET") {
Expand All @@ -697,6 +709,7 @@ const transitionStepPrevious = (
state: stepTo,
};
case "CONFIGURING_CHART":
case "LAYOUTING":
return {
...draft,
state: stepTo,
Expand Down

0 comments on commit 740637b

Please sign in to comment.