diff --git a/adminSiteClient/ChartList.tsx b/adminSiteClient/ChartList.tsx index 157ba0c896a..521d71aa992 100644 --- a/adminSiteClient/ChartList.tsx +++ b/adminSiteClient/ChartList.tsx @@ -27,6 +27,9 @@ export interface ChartListItem { publishedAt: string publishedBy: string + hasParentIndicator?: boolean + isInheritanceEnabled?: boolean + tags: DbChartTagJoin[] } @@ -101,6 +104,11 @@ export class ChartList extends React.Component<{ render() { const { charts, searchHighlight } = this.props const { availableTags } = this + + // if the first chart has inheritance information, we assume all charts have it + const showInheritanceColumn = + charts[0]?.isInheritanceEnabled !== undefined + return ( @@ -109,6 +117,7 @@ export class ChartList extends React.Component<{ + {showInheritanceColumn && } @@ -124,6 +133,7 @@ export class ChartList extends React.Component<{ availableTags={availableTags} searchHighlight={searchHighlight} onDelete={this.onDeleteChart} + showInheritanceColumn={showInheritanceColumn} /> ))} diff --git a/adminSiteClient/ChartRow.tsx b/adminSiteClient/ChartRow.tsx index ef1ba985090..e3fcefb6c01 100644 --- a/adminSiteClient/ChartRow.tsx +++ b/adminSiteClient/ChartRow.tsx @@ -19,6 +19,7 @@ export class ChartRow extends React.Component<{ searchHighlight?: (text: string) => string | React.ReactElement availableTags: DbChartTagJoin[] onDelete: (chart: ChartListItem) => void + showInheritanceColumn?: boolean }> { static contextType = AdminAppContext context!: AdminAppContextType @@ -40,7 +41,8 @@ export class ChartRow extends React.Component<{ } render() { - const { chart, searchHighlight, availableTags } = this.props + const { chart, searchHighlight, availableTags, showInheritanceColumn } = + this.props const highlight = searchHighlight || lodash.identity @@ -80,6 +82,7 @@ export class ChartRow extends React.Component<{ + {showInheritanceColumn && } + + // if the chart doesn't have a parent, inheritance doesn't apply + if (!chart.hasParentIndicator) return + + return chart.isInheritanceEnabled ? : +} diff --git a/adminSiteServer/apiRouter.ts b/adminSiteServer/apiRouter.ts index b14ce09592c..4f0be5575bd 100644 --- a/adminSiteServer/apiRouter.ts +++ b/adminSiteServer/apiRouter.ts @@ -56,6 +56,8 @@ import { mergeGrapherConfigs, diffGrapherConfigs, omitUndefinedValues, + getParentVariableIdFromChartConfig, + omit, } from "@ourworldindata/utils" import { applyPatch } from "../adminShared/patchHelper.js" import { @@ -94,6 +96,7 @@ import { DbInsertUser, FlatTagGraph, DbRawChartConfig, + parseChartConfig, } from "@ourworldindata/types" import { uuidv7 } from "uuidv7" import { @@ -1408,10 +1411,15 @@ getRouteWithROTransaction( variable.catalogPath += `#${variable.shortName}` } - const charts = await db.knexRaw( + const rawCharts = await db.knexRaw< + OldChartFieldList & { + isInheritanceEnabled: DbPlainChart["isInheritanceEnabled"] + config: DbRawChartConfig["full"] + } + >( trx, `-- sql - SELECT ${oldChartFieldList} + SELECT ${oldChartFieldList}, charts.isInheritanceEnabled, chart_configs.full AS config FROM charts JOIN chart_configs ON chart_configs.id = charts.configId JOIN users lastEditedByUser ON lastEditedByUser.id = charts.lastEditedByUserId @@ -1423,6 +1431,15 @@ getRouteWithROTransaction( [variableId] ) + // check for parent indicators + const charts = rawCharts.map((chart) => { + const parentIndicatorId = getParentVariableIdFromChartConfig( + parseChartConfig(chart.config) + ) + const hasParentIndicator = parentIndicatorId !== undefined + return omit({ ...chart, hasParentIndicator }, "config") + }) + await assignTagsForCharts(trx, charts) const variableWithConfigs = await getGrapherConfigsForVariable(
Chart Id TypeInheritanceTags Published Last Updated {chart.id} {showChartType(chart)} n/aenableddisabled