From 49bec03bc1f7165f46841d347bea620437aacd8c Mon Sep 17 00:00:00 2001 From: Bartosz Prusinowski Date: Tue, 4 Oct 2022 10:21:52 +0200 Subject: [PATCH 1/2] fix: Migrate chart config in getConfig to also include embed mode --- app/db/config.ts | 16 +++++++++++++++- app/pages/v/[chartId].tsx | 14 +------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/app/db/config.ts b/app/db/config.ts index 559822a2c..79825ed7b 100644 --- a/app/db/config.ts +++ b/app/db/config.ts @@ -1,3 +1,5 @@ +import { migrateChartConfig } from "@/utils/chart-config/versioning"; + import { createChartId } from "../utils/create-chart-id"; import { pool } from "./pg-pool"; @@ -37,7 +39,19 @@ export const getConfig = async ( [key] ); - return result.rows[0]; + const config = result.rows[0]; + + if (config && config.data) { + return { + ...config, + data: { + ...config.data, + chartConfig: migrateChartConfig(config.data.chartConfig), + }, + }; + } + + return config; }; /** diff --git a/app/pages/v/[chartId].tsx b/app/pages/v/[chartId].tsx index bd2668032..34f093fbb 100644 --- a/app/pages/v/[chartId].tsx +++ b/app/pages/v/[chartId].tsx @@ -15,7 +15,6 @@ import { PublishActions } from "@/components/publish-actions"; import { Config } from "@/configurator"; import { getConfig } from "@/db/config"; import { useLocale } from "@/locales/use-locale"; -import { migrateChartConfig } from "@/utils/chart-config/versioning"; type PageProps = | { @@ -37,18 +36,7 @@ export const getServerSideProps: GetServerSideProps = async ({ if (config && config.data) { // TODO validate configuration - return { - props: { - status: "found", - config: { - ...config, - data: { - ...config.data, - chartConfig: migrateChartConfig(config.data.chartConfig), - }, - }, - }, - }; + return { props: { status: "found", config } }; } res.statusCode = 404; From 186c1528a089339cc3ef590e451ff06babc44ca7 Mon Sep 17 00:00:00 2001 From: Bartosz Prusinowski Date: Tue, 4 Oct 2022 10:48:28 +0200 Subject: [PATCH 2/2] chore: Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 70d11a248..4f90f9c35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ You can also check the [release page](https://github.com/visualize-admin/visuali ## Unreleased - Charts: fix bugs that caused scatterplot and pie charts to crash in case no categorical dimensions were present in a dataset +- Embed: introduce chart config migrations to embed mode ## [3.9.4] - 2022-09-29