Skip to content

Commit

Permalink
🚧 wip barebones inheritance tab
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann committed Aug 9, 2024
1 parent 8605344 commit 652296c
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 25 deletions.
1 change: 1 addition & 0 deletions adminSiteClient/AbstractChartEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type EditorTab =
| "revisions"
| "refs"
| "export"
| "inheritance"

export interface AbstractChartEditorManager {
admin: Admin
Expand Down
1 change: 1 addition & 0 deletions adminSiteClient/ChartEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export class ChartEditor extends AbstractChartEditor<ChartEditorManager> {
if (this.grapher.isMarimekko) tabs.push("marimekko")
tabs.push("revisions")
tabs.push("refs")
if (this.parentConfig) tabs.push("inheritance")
tabs.push("export")
return tabs
}
Expand Down
4 changes: 4 additions & 0 deletions adminSiteClient/ChartEditorView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { EditorScatterTab } from "./EditorScatterTab.js"
import { EditorMapTab } from "./EditorMapTab.js"
import { EditorHistoryTab } from "./EditorHistoryTab.js"
import { EditorReferencesTab } from "./EditorReferencesTab.js"
import { EditorInheritanceTab } from "./EditorInheritanceTab.js"
import {
SaveButtonsForChart,
SaveButtonsForIndicatorChart,
Expand Down Expand Up @@ -463,6 +464,9 @@ export class ChartEditorView<
{chartEditor && chartEditor.tab === "refs" && (
<EditorReferencesTab editor={chartEditor} />
)}
{editor.tab === "inheritance" && (
<EditorInheritanceTab editor={editor} />
)}
{editor.tab === "export" && (
<EditorExportTab editor={editor} />
)}
Expand Down
27 changes: 2 additions & 25 deletions adminSiteClient/EditorHistoryTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@ import { observer } from "mobx-react"
import { ChartEditor, Log } from "./ChartEditor.js"
import { Section, Timeago } from "./Forms.js"
import { computed, action, observable } from "mobx"
import {
Json,
copyToClipboard,
diffGrapherConfigs,
} from "@ourworldindata/utils"
import { Json, copyToClipboard } from "@ourworldindata/utils"
import YAML from "yaml"
import { notification, Modal } from "antd"
import ReactDiffViewer, { DiffMethod } from "react-diff-viewer-continued"
import { defaultGrapherConfig } from "@ourworldindata/grapher"

function LogCompareModal({
log,
Expand Down Expand Up @@ -151,7 +146,7 @@ export class EditorHistoryTab extends React.Component<{ editor: ChartEditor }> {
}

render() {
const { patchConfig, fullConfig, parentConfig } = this.props.editor
const { patchConfig, fullConfig } = this.props.editor

Check warning on line 149 in adminSiteClient/EditorHistoryTab.tsx

View workflow job for this annotation

GitHub Actions / eslint

'fullConfig' is assigned a value but never used. Allowed unused vars must match /^_/u

Check warning on line 149 in adminSiteClient/EditorHistoryTab.tsx

View workflow job for this annotation

GitHub Actions / eslint

'fullConfig' is assigned a value but never used. Allowed unused vars must match /^_/u
return (
<div>
{this.logs.map((log, i) => (
Expand Down Expand Up @@ -182,24 +177,6 @@ export class EditorHistoryTab extends React.Component<{ editor: ChartEditor }> {
value={JSON.stringify(patchConfig, undefined, 2)}
/>
</Section>
<Section name="Full Config">
<textarea
rows={7}
readOnly
className="form-control"
value={JSON.stringify(fullConfig, undefined, 2)}
/>
</Section>
{parentConfig && (
<Section name="Parent Config">
<textarea
rows={7}
readOnly
className="form-control"
value={JSON.stringify(parentConfig, undefined, 2)}
/>
</Section>
)}
</div>
)
}
Expand Down
63 changes: 63 additions & 0 deletions adminSiteClient/EditorInheritanceTab.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import React from "react"
import { observer } from "mobx-react"
import { AbstractChartEditor } from "./AbstractChartEditor.js"
import { Section } from "./Forms.js"

@observer
export class EditorInheritanceTab<
Editor extends AbstractChartEditor,
> extends React.Component<{ editor: Editor }> {
render() {
const { parentConfig, fullConfig, grapher } = this.props.editor

if (!parentConfig)
return (
<div className="InheritanceTab">
Doesn't inherit settings from any indicator
</div>
)

const parentIndicatorId = parentConfig.dimensions?.[0].variableId

if (!parentIndicatorId)
return (
<div className="InheritanceTab">
Does inherit settings from any indicator but can't find the
indicator's id (shouldn't happen, please report this bug!)
</div>
)

const column = grapher.inputTable.get(parentIndicatorId.toString())

return (
<div className="InheritanceTab">
<Section name="Parent indicator">
Inherits settings from indicator{" "}
<a
href={`/admin/variables/${parentIndicatorId}`}
target="_blank"
rel="noopener"
>
{column.name}.
</a>
</Section>
<Section name="Inherited Config">
<textarea
rows={7}
readOnly
className="form-control"
value={JSON.stringify(parentConfig, undefined, 2)}
/>
</Section>
<Section name="Full Config">
<textarea
rows={7}
readOnly
className="form-control"
value={JSON.stringify(fullConfig, undefined, 2)}
/>
</Section>
</div>
)
}
}

0 comments on commit 652296c

Please sign in to comment.