diff --git a/adminSiteClient/ChartViewEditor.ts b/adminSiteClient/ChartViewEditor.ts index e35302eaba..cca20c2a25 100644 --- a/adminSiteClient/ChartViewEditor.ts +++ b/adminSiteClient/ChartViewEditor.ts @@ -14,6 +14,7 @@ export interface Chart { export interface ChartViewEditorManager extends AbstractChartEditorManager { chartViewId: number + parentChartId: number } export class ChartViewEditor extends AbstractChartEditor { @@ -40,6 +41,10 @@ export class ChartViewEditor extends AbstractChartEditor return false } + @computed get parentChartId(): number { + return this.manager.parentChartId + } + async saveGrapher({ onError, }: { onError?: () => void } = {}): Promise { diff --git a/adminSiteClient/SaveButtons.tsx b/adminSiteClient/SaveButtons.tsx index f7ae8aa8b6..e037fbedbd 100644 --- a/adminSiteClient/SaveButtons.tsx +++ b/adminSiteClient/SaveButtons.tsx @@ -12,6 +12,10 @@ import { ErrorMessagesForDimensions, } from "./ChartEditorTypes.js" import { AbstractChartEditor } from "./AbstractChartEditor.js" +import { + ChartViewEditor, + isChartViewEditorInstance, +} from "./ChartViewEditor.js" @observer export class SaveButtons< @@ -33,6 +37,13 @@ export class SaveButtons< {...passthroughProps} /> ) + else if (isChartViewEditorInstance(editor)) + return ( + + ) else return null } } @@ -166,3 +177,53 @@ class SaveButtonsForIndicatorChart extends React.Component<{ ) } } + +@observer +class SaveButtonsForChartView extends React.Component<{ + editor: ChartViewEditor + errorMessages: ErrorMessages + errorMessagesForDimensions: ErrorMessagesForDimensions +}> { + @action.bound onSaveChart() { + void this.props.editor.saveGrapher() + } + + @computed get hasEditingErrors(): boolean { + const { errorMessages, errorMessagesForDimensions } = this.props + + if (!isEmpty(errorMessages)) return true + + const allErrorMessagesForDimensions = Object.values( + errorMessagesForDimensions + ).flat() + return allErrorMessagesForDimensions.some((error) => error) + } + + render() { + const { hasEditingErrors } = this + const { editor } = this.props + const { grapher } = editor + + const isSavingDisabled = grapher.hasFatalErrors || hasEditingErrors + + return ( +
+ {" "} + + Go to parent chart + +
+ ) + } +}