diff --git a/adminSiteClient/ChartEditor.ts b/adminSiteClient/ChartEditor.ts index d79c9dee9fa..d13047ff5e0 100644 --- a/adminSiteClient/ChartEditor.ts +++ b/adminSiteClient/ChartEditor.ts @@ -14,10 +14,6 @@ import { ChartRedirect, DimensionProperty, Json, - GrapherInterface, - diffGrapherConfigs, - isEqual, - omit, } from "@ourworldindata/utils" import { computed, observable, runInAction, when } from "mobx" import { BAKED_GRAPHER_URL } from "../settings/clientSettings.js" @@ -101,7 +97,6 @@ export interface ChartEditorManager { admin: Admin grapher: Grapher database: EditorDatabase - parentGrapherConfig: GrapherInterface logs: Log[] references: References | undefined redirects: ChartRedirect[] @@ -129,7 +124,7 @@ export class ChartEditor { @observable.ref errorMessage?: { title: string; content: string } @observable.ref previewMode: "mobile" | "desktop" @observable.ref showStaticPreview = false - @observable.ref savedPatchConfig: GrapherInterface = {} + @observable.ref savedGrapherJson: string = "" // This gets set when we save a new chart for the first time // so the page knows to update the url @@ -142,26 +137,13 @@ export class ChartEditor { ? "mobile" : "desktop" when( - () => this.grapher.hasData && this.grapher.isReady, - () => (this.savedPatchConfig = this.patchConfig) + () => this.grapher.isReady, + () => (this.savedGrapherJson = JSON.stringify(this.grapher.object)) ) } - @computed get fullConfig(): GrapherInterface { - return this.grapher.object - } - - @computed get patchConfig(): GrapherInterface { - const { parentGrapherConfig } = this.manager - if (!parentGrapherConfig) return this.fullConfig - return diffGrapherConfigs(this.fullConfig, parentGrapherConfig) - } - @computed get isModified(): boolean { - return !isEqual( - omit(this.patchConfig, "version"), - omit(this.savedPatchConfig, "version") - ) + return JSON.stringify(this.grapher.object) !== this.savedGrapherJson } @computed get grapher() { @@ -256,12 +238,12 @@ export class ChartEditor { if (isNewGrapher) { this.newChartId = json.chartId this.grapher.id = json.chartId - this.savedPatchConfig = json.savedPatch + this.savedGrapherJson = JSON.stringify(this.grapher.object) } else { runInAction(() => { grapher.version += 1 this.logs.unshift(json.newLog) - this.savedPatchConfig = json.savedPatch + this.savedGrapherJson = JSON.stringify(currentGrapherObject) }) } } else onError?.() diff --git a/adminSiteClient/ChartEditorPage.tsx b/adminSiteClient/ChartEditorPage.tsx index b16eeac4229..e1d1a49fc82 100644 --- a/adminSiteClient/ChartEditorPage.tsx +++ b/adminSiteClient/ChartEditorPage.tsx @@ -28,7 +28,7 @@ import { ChartRedirect, DimensionProperty, } from "@ourworldindata/types" -import { defaultGrapherConfig, Grapher } from "@ourworldindata/grapher" +import { Grapher } from "@ourworldindata/grapher" import { Admin } from "./Admin.js" import { ChartEditor, @@ -104,7 +104,7 @@ export class ChartEditorPage extends React.Component<{ grapherId?: number newGrapherIndex?: number - grapherConfig?: GrapherInterface + grapherConfig?: any }> implements ChartEditorManager { @@ -124,9 +124,7 @@ export class ChartEditorPage @observable simulateVisionDeficiency?: VisionDeficiency - fetchedGrapherConfig?: GrapherInterface - // for now, every chart's parent config is the default layer - parentGrapherConfig = defaultGrapherConfig + fetchedGrapherConfig?: any async fetchGrapher(): Promise { const { grapherId } = this.props diff --git a/adminSiteClient/EditorHistoryTab.tsx b/adminSiteClient/EditorHistoryTab.tsx index 4c0e8baf5f8..0fa832b4acf 100644 --- a/adminSiteClient/EditorHistoryTab.tsx +++ b/adminSiteClient/EditorHistoryTab.tsx @@ -129,7 +129,7 @@ export class EditorHistoryTab extends React.Component<{ editor: ChartEditor }> { @action.bound copyYamlToClipboard() { // Use the Clipboard API to copy the config into the users clipboard const chartConfigObject = { - ...this.props.editor.patchConfig, + ...this.props.editor.grapher.object, } delete chartConfigObject.id delete chartConfigObject.dimensions @@ -149,7 +149,7 @@ export class EditorHistoryTab extends React.Component<{ editor: ChartEditor }> { // Avoid modifying the original JSON object // Due to mobx memoizing computed values, the JSON can be mutated. const chartConfigObject = { - ...this.props.editor.patchConfig, + ...this.props.editor.grapher.object, } return (
@@ -157,12 +157,7 @@ export class EditorHistoryTab extends React.Component<{ editor: ChartEditor }> {