Skip to content

Commit

Permalink
🔨 keep admin as is for now
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann authored and danyx23 committed Aug 13, 2024
1 parent a0c5d39 commit 86ea70c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 37 deletions.
30 changes: 6 additions & 24 deletions adminSiteClient/ChartEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -101,7 +97,6 @@ export interface ChartEditorManager {
admin: Admin
grapher: Grapher
database: EditorDatabase
parentGrapherConfig: GrapherInterface
logs: Log[]
references: References | undefined
redirects: ChartRedirect[]
Expand Down Expand Up @@ -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
Expand All @@ -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() {
Expand Down Expand Up @@ -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?.()
Expand Down
8 changes: 3 additions & 5 deletions adminSiteClient/ChartEditorPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -104,7 +104,7 @@ export class ChartEditorPage
extends React.Component<{
grapherId?: number
newGrapherIndex?: number
grapherConfig?: GrapherInterface
grapherConfig?: any
}>
implements ChartEditorManager
{
Expand All @@ -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<void> {
const { grapherId } = this.props
Expand Down
11 changes: 3 additions & 8 deletions adminSiteClient/EditorHistoryTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -149,20 +149,15 @@ 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 (
<div>
{this.logs.map((log, i) => (
<ul key={i} className="list-group">
<LogRenderer
log={log}
// Needed for comparison, might be undefined
previousLog={
i + 1 < this.logs.length
? this.logs[i + 1]
: undefined
}
previousLog={this.logs[i + 1]} // Needed for comparison, might be undefined
applyConfig={this.applyConfig}
></LogRenderer>
</ul>
Expand Down

0 comments on commit 86ea70c

Please sign in to comment.