Skip to content

Commit

Permalink
🔨 (grapher) remove DEFAULT_GRAPHER_CONFIG_SCHEMA
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann committed Aug 7, 2024
1 parent 33d7608 commit 5fbe835
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -76,21 +76,21 @@ 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)
})

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,
})
})

Expand Down
6 changes: 3 additions & 3 deletions packages/@ourworldindata/grapher/src/core/Grapher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ import {
BASE_FONT_SIZE,
CookieKey,
ThereWasAProblemLoadingThisChart,
DEFAULT_GRAPHER_CONFIG_SCHEMA,
DEFAULT_GRAPHER_WIDTH,
DEFAULT_GRAPHER_HEIGHT,
DEFAULT_GRAPHER_FRAME_PADDING,
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions packages/@ourworldindata/grapher/src/core/GrapherConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
3 changes: 1 addition & 2 deletions packages/@ourworldindata/grapher/src/schema/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 5fbe835

Please sign in to comment.