Skip to content

Commit

Permalink
refactor: Move configurator title to layout
Browse files Browse the repository at this point in the history
  • Loading branch information
bprusinowski committed Dec 7, 2023
1 parent 8e0e2cd commit ab660e4
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 71 deletions.
13 changes: 5 additions & 8 deletions app/config-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1110,9 +1110,11 @@ const Layout = t.intersection([
t.union([
t.type({
type: t.literal("tab"),
meta: Meta,
}),
t.type({
type: t.literal("dashboard"),
meta: Meta,
}),
]),
]);
Expand All @@ -1123,7 +1125,6 @@ const Config = t.type(
{
version: t.string,
dataSource: DataSource,
meta: Meta,
layout: Layout,
chartConfigs: t.array(ChartConfig),
activeChartKey: t.string,
Expand Down Expand Up @@ -1153,28 +1154,24 @@ const ConfiguratorStateSelectingDataSet = t.type({
version: t.string,
state: t.literal("SELECTING_DATASET"),
dataSource: DataSource,
meta: Meta,
chartConfigs: t.undefined,
layout: t.undefined,
activeChartKey: t.undefined,
});
export type ConfiguratorStateSelectingDataSet = t.TypeOf<
typeof ConfiguratorStateSelectingDataSet
>;

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

const ConfiguratorStateLayouting = t.intersection([
t.type({
state: t.literal("LAYOUTING"),
}),
t.type({ state: t.literal("LAYOUTING") }),
Config,
]);
export type ConfiguratorStateLayouting = t.TypeOf<
Expand Down
2 changes: 1 addition & 1 deletion app/configurator/components/annotators.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export const ChartAnnotator = () => {
export const LayoutAnnotator = () => {
const locale = useLocale();
const [state] = useConfiguratorState(isLayouting);
const { title, description } = state.meta;
const { title, description } = state.layout.meta;
const disabled = !(title[locale] && description[locale]);

return (
Expand Down
6 changes: 4 additions & 2 deletions app/configurator/components/configurator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ const LayoutingStep = () => {
type: "LAYOUT_CHANGED",
value: {
type: "tab",
meta: state.layout.meta,
activeField: undefined,
},
});
Expand All @@ -265,6 +266,7 @@ const LayoutingStep = () => {
type: "LAYOUT_CHANGED",
value: {
type: "dashboard",
meta: state.layout.meta,
activeField: undefined,
},
});
Expand Down Expand Up @@ -295,9 +297,9 @@ const LayoutingStep = () => {
mb: 4,
}}
>
<Title text={state.meta.title[locale]} onClick={() => {}} />
<Title text={state.layout.meta.title[locale]} onClick={() => {}} />
<Description
text={state.meta.description[locale]}
text={state.layout.meta.description[locale]}
onClick={() => {}}
/>
</Box>
Expand Down
5 changes: 3 additions & 2 deletions app/configurator/components/field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -513,11 +513,12 @@ export const ChartAnnotatorTabField = ({
} & Omit<AnnotatorTabProps, "onClick">) => {
const fieldProps = useActiveFieldField({ value });
const [state] = useConfiguratorState(isConfiguring);
const chartConfig = getChartConfig(state);
const locale = useLocale();
const hasText = useMemo(() => {
const key = value as "title" | "description";
return state.meta[key]?.[locale] !== "";
}, [state.meta, value, locale]);
return chartConfig.meta[key]?.[locale] !== "";
}, [chartConfig, value, locale]);

return (
<AnnotatorTab
Expand Down
33 changes: 18 additions & 15 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,
LayoutType,
Meta,
decodeConfiguratorState,
enableLayouting,
getChartConfig,
Expand Down Expand Up @@ -297,6 +298,7 @@ export type ConfiguratorStateAction =
type: "LAYOUT_CHANGED";
value: {
type: LayoutType;
meta: Meta;
activeField: string | undefined;
};
};
Expand Down Expand Up @@ -326,20 +328,7 @@ const EMPTY_STATE: ConfiguratorStateSelectingDataSet = {
state: "SELECTING_DATASET",
dataSource: DEFAULT_DATA_SOURCE,
chartConfigs: undefined,
meta: {
title: {
de: "",
fr: "",
it: "",
en: "",
},
description: {
de: "",
fr: "",
it: "",
en: "",
},
},
layout: undefined,
activeChartKey: undefined,
};

Expand Down Expand Up @@ -648,9 +637,22 @@ const transitionStepNext = (
version: CONFIGURATOR_STATE_VERSION,
state: "CONFIGURING_CHART",
dataSource: draft.dataSource,
meta: draft.meta,
layout: {
type: "tab",
meta: {
title: {
de: "",
en: "",
fr: "",
it: "",
},
description: {
de: "",
en: "",
fr: "",
it: "",
},
},
activeField: undefined,
},
chartConfigs: [chartConfig],
Expand Down Expand Up @@ -716,6 +718,7 @@ const transitionStepPrevious = (
case "SELECTING_DATASET":
return {
...draft,
layout: undefined,
chartConfigs: undefined,
activeChartKey: undefined,
state: stepTo,
Expand Down
11 changes: 7 additions & 4 deletions app/docs/columns.docs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ ${(
version: CONFIGURATOR_STATE_VERSION,
state: "PUBLISHED",
dataSource: { type: "sparql", url: "" },
meta: {
title: { en: "", de: "", fr: "", it: "" },
description: { en: "", de: "", fr: "", it: "" },
layout: {
type: "tab",
meta: {
title: { en: "", de: "", fr: "", it: "" },
description: { en: "", de: "", fr: "", it: "" },
},
activeField: undefined,
},
layout: { type: "tab" },
chartConfigs: [chartConfig],
activeChartKey: "scatterplot",
}}
Expand Down
34 changes: 7 additions & 27 deletions app/docs/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,21 @@ export const states: ConfiguratorState[] = [
version: CONFIGURATOR_STATE_VERSION,
dataSource: DEFAULT_DATA_SOURCE,
chartConfigs: undefined,
meta: {
title: {
de: "",
fr: "",
it: "",
en: "",
},
description: {
de: "",
fr: "",
it: "",
en: "",
},
},
layout: undefined,
activeChartKey: undefined,
},
{
state: "CONFIGURING_CHART",
version: CONFIGURATOR_STATE_VERSION,
dataSource: DEFAULT_DATA_SOURCE,
meta: {
title: {
de: "",
fr: "",
it: "",
en: "",
},
description: {
de: "",
fr: "",
it: "",
en: "",
layout: {
type: "tab",
meta: {
title: { en: "", de: "", fr: "", it: "" },
description: { en: "", de: "", fr: "", it: "" },
},
activeField: undefined,
},
layout: { type: "tab" },
chartConfigs: [
{
key: "column",
Expand Down
11 changes: 7 additions & 4 deletions app/docs/lines.docs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@ ${(
version: CONFIGURATOR_STATE_VERSION,
state: "PUBLISHED",
dataSource: { type: "sparql", url: "" },
meta: {
title: { en: "", de: "", fr: "", it: "" },
description: { en: "", de: "", fr: "", it: "" },
layout: {
type: "tab",
meta: {
title: { en: "", de: "", fr: "", it: "" },
description: { en: "", de: "", fr: "", it: "" },
},
activeField: undefined,
},
layout: { type: "tab" },
chartConfigs: [chartConfig],
activeChartKey: "line",
}}
Expand Down
11 changes: 7 additions & 4 deletions app/docs/scatterplot.docs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,14 @@ ${(
version: CONFIGURATOR_STATE_VERSION,
state: "PUBLISHED",
dataSource: { type: "sparql", url: "" },
meta: {
title: { en: "", de: "", fr: "", it: "" },
description: { en: "", de: "", fr: "", it: "" },
layout: {
type: "tab",
meta: {
title: { en: "", de: "", fr: "", it: "" },
description: { en: "", de: "", fr: "", it: "" },
},
activeField: undefined,
},
layout: { type: "tab" },
chartConfigs: [chartConfig],
activeChartKey: "scatterplot",
}}
Expand Down
4 changes: 2 additions & 2 deletions app/pages/v/[chartId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ const VisualizationPage = (props: Serialized<PageProps>) => {
<meta name="twitter:card" content="summary_large_image" />
{/* FIXME: possibly we'll need to copy the content of first chart when migrating / saving to db
or have additional annotator for dashboards / compositions. */}
<meta property="og:title" content={state.meta.title[locale]} />
<meta property="og:title" content={state.layout.meta.title[locale]} />
<meta
property="og:description"
content={state.meta.description[locale]}
content={state.layout.meta.description[locale]}
/>
{/* og:url is set in _app.tsx */}
</Head>
Expand Down
4 changes: 2 additions & 2 deletions app/utils/chart-config/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const createConfig = async (state: ConfiguratorStatePublishing) => {
key: createChartId(),
version: state.version,
dataSource: state.dataSource,
meta: state.meta,
layout: state.layout,
chartConfigs: state.chartConfigs,
activeChartKey: state.activeChartKey,
},
Expand Down Expand Up @@ -51,7 +51,7 @@ export const updateConfig = async (
key,
version: state.version,
dataSource: state.dataSource,
meta: state.meta,
layout: state.layout,
chartConfigs: state.chartConfigs,
activeChartKey: state.activeChartKey,
},
Expand Down
16 changes: 16 additions & 0 deletions app/utils/chart-config/versioning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -950,14 +950,30 @@ const configuratorStateMigrations: Migration[] = [
return produce(newConfig, (draft: any) => {
draft.layout = {
type: "tab",
meta: draft.meta,
activeField: undefined,
};
delete draft.meta;
});
},
down: (config) => {
const newConfig = { ...config, version: "3.0.1" };

return produce(newConfig, (draft: any) => {
draft.meta = draft.layout.meta ?? {
title: {
de: "",
fr: "",
it: "",
en: "",
},
description: {
de: "",
fr: "",
it: "",
en: "",
},
};
delete draft.layout;
});
},
Expand Down

0 comments on commit ab660e4

Please sign in to comment.