Skip to content

Commit

Permalink
Merge pull request #757 from visualize-admin/fix/embed-config-migrations
Browse files Browse the repository at this point in the history
fix: Migrate chart config in embed mode
  • Loading branch information
bprusinowski authored Oct 4, 2022
2 parents e622aae + 186c152 commit 07b666d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 15 additions & 1 deletion app/db/config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { migrateChartConfig } from "@/utils/chart-config/versioning";

import { createChartId } from "../utils/create-chart-id";

import { pool } from "./pg-pool";
Expand Down Expand Up @@ -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;
};

/**
Expand Down
14 changes: 1 addition & 13 deletions app/pages/v/[chartId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
| {
Expand All @@ -37,18 +36,7 @@ export const getServerSideProps: GetServerSideProps<PageProps> = 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;
Expand Down

1 comment on commit 07b666d

@vercel
Copy link

@vercel vercel bot commented on 07b666d Oct 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

visualization-tool – ./

visualization-tool-git-main-ixt1.vercel.app
visualization-tool-alpha.vercel.app
visualization-tool-ixt1.vercel.app

Please sign in to comment.