-
-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2b84012
commit 4cc1e3c
Showing
14 changed files
with
1,563 additions
and
304 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { Grapher } from "@ourworldindata/grapher" | ||
import { computed, observable, runInAction, when } from "mobx" | ||
Check warning on line 2 in adminSiteClient/AbstractChartEditor.ts GitHub Actions / eslint
Check warning on line 2 in adminSiteClient/AbstractChartEditor.ts GitHub Actions / eslint
|
||
import { Admin } from "./Admin.js" | ||
import { EditorFeatures } from "./EditorFeatures.js" | ||
|
||
type EditorTab = string | ||
|
||
interface Variable { | ||
id: number | ||
name: string | ||
} | ||
|
||
export interface Dataset { | ||
id: number | ||
name: string | ||
namespace: string | ||
version: string | undefined | ||
variables: Variable[] | ||
isPrivate: boolean | ||
nonRedistributable: boolean | ||
} | ||
|
||
export interface Namespace { | ||
name: string | ||
description?: string | ||
isArchived: boolean | ||
} | ||
|
||
// This contains the dataset/variable metadata for the entire database | ||
// Used for variable selector interface | ||
|
||
export interface NamespaceData { | ||
datasets: Dataset[] | ||
} | ||
|
||
export class EditorDatabase { | ||
@observable.ref namespaces: Namespace[] | ||
@observable.ref variableUsageCounts: Map<number, number> = new Map() | ||
@observable dataByNamespace: Map<string, NamespaceData> = new Map() | ||
|
||
constructor(json: any) { | ||
this.namespaces = json.namespaces | ||
} | ||
} | ||
|
||
export interface AbstractChartEditorManager { | ||
admin: Admin | ||
grapher: Grapher | ||
database: EditorDatabase | ||
} | ||
|
||
export abstract class AbstractChartEditor< | ||
Manager extends AbstractChartEditorManager = AbstractChartEditorManager, | ||
> { | ||
manager: Manager | ||
// Whether the current chart state is saved or not | ||
@observable.ref currentRequest: Promise<any> | undefined | ||
@observable.ref tab: EditorTab = "basic" | ||
@observable.ref errorMessage?: { title: string; content: string } | ||
@observable.ref previewMode: "mobile" | "desktop" | ||
@observable.ref showStaticPreview = false | ||
@observable.ref savedGrapherJson: string = "" | ||
|
||
constructor(props: { manager: Manager }) { | ||
this.manager = props.manager | ||
this.previewMode = | ||
localStorage.getItem("editorPreviewMode") === "mobile" | ||
? "mobile" | ||
: "desktop" | ||
when( | ||
() => this.grapher.isReady, | ||
() => (this.savedGrapherJson = JSON.stringify(this.grapher.object)) | ||
) | ||
} | ||
|
||
@computed get isModified(): boolean { | ||
return JSON.stringify(this.grapher.object) !== this.savedGrapherJson | ||
} | ||
|
||
@computed get grapher() { | ||
return this.manager.grapher | ||
} | ||
|
||
@computed get database() { | ||
return this.manager.database | ||
} | ||
|
||
@computed get features() { | ||
return new EditorFeatures(this) | ||
} | ||
|
||
abstract saveGrapher(props: { onError?: () => void }): Promise<void> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.