From 698e3809a6bf7244149ee846dc72d0fd845f6d81 Mon Sep 17 00:00:00 2001 From: sophiamersmann Date: Wed, 7 Aug 2024 09:39:32 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20(grapher)=20remove=20DEFAULT=5FG?= =?UTF-8?q?RAPHER=5FCONFIG=5FSCHEMA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../grapher/src/core/Grapher.jsdom.test.ts | 8 ++++---- packages/@ourworldindata/grapher/src/core/Grapher.tsx | 6 +++--- .../@ourworldindata/grapher/src/core/GrapherConstants.ts | 3 --- packages/@ourworldindata/grapher/src/schema/README.md | 3 +-- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/packages/@ourworldindata/grapher/src/core/Grapher.jsdom.test.ts b/packages/@ourworldindata/grapher/src/core/Grapher.jsdom.test.ts index 1b7d4400b71..96ff4d3a4df 100755 --- a/packages/@ourworldindata/grapher/src/core/Grapher.jsdom.test.ts +++ b/packages/@ourworldindata/grapher/src/core/Grapher.jsdom.test.ts @@ -1,6 +1,6 @@ #! /usr/bin/env jest import { Grapher, GrapherProgrammaticInterface } from "../core/Grapher" -import { DEFAULT_GRAPHER_CONFIG_SCHEMA } from "./GrapherConstants" +import { defaultGrapherConfig } from "../schema/defaultGrapherConfig" import { ChartTypeName, EntitySelectionMode, @@ -76,13 +76,13 @@ it("can get dimension slots", () => { it("an empty Grapher serializes to an object that includes only the schema", () => { expect(new Grapher().toObject()).toEqual({ - $schema: DEFAULT_GRAPHER_CONFIG_SCHEMA, + $schema: defaultGrapherConfig.$schema, }) }) it("a bad chart type does not crash grapher", () => { const input = { - $schema: DEFAULT_GRAPHER_CONFIG_SCHEMA, + $schema: defaultGrapherConfig.$schema, type: "fff" as any, } expect(new Grapher(input).toObject()).toEqual(input) @@ -90,7 +90,7 @@ it("a bad chart type does not crash grapher", () => { it("does not preserve defaults in the object (except for the schema)", () => { expect(new Grapher({ tab: GrapherTabOption.chart }).toObject()).toEqual({ - $schema: DEFAULT_GRAPHER_CONFIG_SCHEMA, + $schema: defaultGrapherConfig.$schema, }) }) diff --git a/packages/@ourworldindata/grapher/src/core/Grapher.tsx b/packages/@ourworldindata/grapher/src/core/Grapher.tsx index 5f34a1fb81c..8a46e74a5ae 100644 --- a/packages/@ourworldindata/grapher/src/core/Grapher.tsx +++ b/packages/@ourworldindata/grapher/src/core/Grapher.tsx @@ -114,7 +114,6 @@ import { BASE_FONT_SIZE, CookieKey, ThereWasAProblemLoadingThisChart, - DEFAULT_GRAPHER_CONFIG_SCHEMA, DEFAULT_GRAPHER_WIDTH, DEFAULT_GRAPHER_HEIGHT, DEFAULT_GRAPHER_FRAME_PADDING, @@ -127,6 +126,7 @@ import { isContinentsVariableId, isPopulationVariableETLPath, } from "../core/GrapherConstants" +import { defaultGrapherConfig } from "../schema/defaultGrapherConfig" import { loadVariableDataAndMetadata } from "./loadVariable" import Cookies from "js-cookie" import { @@ -344,7 +344,7 @@ export class Grapher MapChartManager, SlopeChartManager { - @observable.ref $schema = DEFAULT_GRAPHER_CONFIG_SCHEMA + @observable.ref $schema = defaultGrapherConfig.$schema @observable.ref type = ChartTypeName.LineChart @observable.ref id?: number = undefined @observable.ref version = 1 @@ -527,7 +527,7 @@ export class Grapher deleteRuntimeAndUnchangedProps(obj, defaultObject) // always include the schema, even if it's the default - obj.$schema = this.$schema || DEFAULT_GRAPHER_CONFIG_SCHEMA + obj.$schema = this.$schema || defaultGrapherConfig.$schema // todo: nulls got into the DB for this one. we can remove after moving Graphers from DB. if (obj.stackMode === null) delete obj.stackMode diff --git a/packages/@ourworldindata/grapher/src/core/GrapherConstants.ts b/packages/@ourworldindata/grapher/src/core/GrapherConstants.ts index 35f47981580..820811a58b5 100644 --- a/packages/@ourworldindata/grapher/src/core/GrapherConstants.ts +++ b/packages/@ourworldindata/grapher/src/core/GrapherConstants.ts @@ -9,9 +9,6 @@ export const GRAPHER_TIMELINE_CLASS = "timeline-component" export const GRAPHER_SIDE_PANEL_CLASS = "side-panel" export const GRAPHER_SETTINGS_CLASS = "settings-menu-contents" -export const DEFAULT_GRAPHER_CONFIG_SCHEMA = - "https://files.ourworldindata.org/schemas/grapher-schema.004.json" - export const DEFAULT_GRAPHER_ENTITY_TYPE = "country or region" export const DEFAULT_GRAPHER_ENTITY_TYPE_PLURAL = "countries and regions" diff --git a/packages/@ourworldindata/grapher/src/schema/README.md b/packages/@ourworldindata/grapher/src/schema/README.md index 76baa75ef77..cad2a6eb595 100644 --- a/packages/@ourworldindata/grapher/src/schema/README.md +++ b/packages/@ourworldindata/grapher/src/schema/README.md @@ -10,14 +10,13 @@ If you update the default value of an existing property or you add a new propert Breaking changes should be done by renaming the schema file to an increased version number. Make sure to also rename the authorative url inside the schema file (the "$id" field at the top level) to point to the new version number json. Then write the migrations from the last to -the current version of the schema, including the migration of pointing to the URL of the new schema version. Also update `DEFAULT_GRAPHER_CONFIG_SCHEMA` in `GrapherConstants.ts` to point to the new schema version number url. +the current version of the schema, including the migration of pointing to the URL of the new schema version.s Checklist for breaking changes: - Rename the schema file to an increased version number - Rename the authorative url inside the schema file to point to the new version number json - Write the migrations from the last to the current version of the schema, including the migration of pointing to the URL of the new schema version -- Update `DEFAULT_GRAPHER_CONFIG_SCHEMA` in `GrapherConstants.ts` to point to the new schema version number url - Regenerate the default object from the schema and save it to `defaultGrapherConfig.ts` (see below) - Write a migration to update the `chart_configs.full` column in the database for all stand-alone charts