From 50902bb791b14640a57693f56ca617ffa76b10c3 Mon Sep 17 00:00:00 2001 From: sophiamersmann Date: Tue, 17 Oct 2023 06:53:54 +0000 Subject: [PATCH] refactor(grapher): add presentation property to CoreColumnDef --- packages/@ourworldindata/core-table/src/CoreColumnDef.ts | 8 +++----- packages/@ourworldindata/grapher/src/core/Grapher.tsx | 7 ++++--- .../grapher/src/core/LegacyToOwidTable.ts | 9 ++------- .../@ourworldindata/grapher/src/modal/SourcesModal.tsx | 8 +++++--- 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/packages/@ourworldindata/core-table/src/CoreColumnDef.ts b/packages/@ourworldindata/core-table/src/CoreColumnDef.ts index ccccb0a21f5..dcd2570352c 100644 --- a/packages/@ourworldindata/core-table/src/CoreColumnDef.ts +++ b/packages/@ourworldindata/core-table/src/CoreColumnDef.ts @@ -4,6 +4,7 @@ import { ToleranceStrategy, OwidOrigin, OwidSource, + OwidVariablePresentation, } from "@ourworldindata/utils" import { CoreValueType, Color } from "./CoreTableConstants.js" @@ -63,9 +64,6 @@ export interface CoreColumnDef extends ColumnColorScale { // Column information used for display only name?: string // The display name for the column - titlePublic?: string // The Metadata V2 display title for the variable - titleVariant?: string // The Metadata V2 title disambiguation fragment for the variant (e.g. "projected") - attributionShort?: string // The Metadata V2 title disambiguation fragment for the producer description?: string descriptionShort?: string descriptionProcessing?: string @@ -78,11 +76,11 @@ export interface CoreColumnDef extends ColumnColorScale { // Source information used for display only source?: OwidSource - attribution?: string timespanFromMetadata?: string - // Origins + // Metadata v2 origins?: OwidOrigin[] + presentation?: Omit // Dataset information datasetId?: number diff --git a/packages/@ourworldindata/grapher/src/core/Grapher.tsx b/packages/@ourworldindata/grapher/src/core/Grapher.tsx index 3bffd7ed4cc..19a65495578 100644 --- a/packages/@ourworldindata/grapher/src/core/Grapher.tsx +++ b/packages/@ourworldindata/grapher/src/core/Grapher.tsx @@ -1490,14 +1490,15 @@ export class Grapher @computed private get defaultSourcesLine(): string { const attributions = this.columnsWithSources.flatMap((column) => { + const { presentation = {} } = column.def // if the variable metadata specifies an attribution on the // variable level then this is preferred over assembling it from // the source and origins if ( - column.def.attribution !== undefined && - column.def.attribution !== "" + presentation.attribution !== undefined && + presentation.attribution !== "" ) - return [column.def.attribution] + return [presentation.attribution] else { const originFragments = getOriginAttributionFragments( column.def.origins diff --git a/packages/@ourworldindata/grapher/src/core/LegacyToOwidTable.ts b/packages/@ourworldindata/grapher/src/core/LegacyToOwidTable.ts index d93e80c56c9..1a4c27b9903 100644 --- a/packages/@ourworldindata/grapher/src/core/LegacyToOwidTable.ts +++ b/packages/@ourworldindata/grapher/src/core/LegacyToOwidTable.ts @@ -563,11 +563,9 @@ const columnDefFromOwidVariable = ( display, timespan, nonRedistributable, + presentation, } = variable - const { attribution, titlePublic, titleVariant, attributionShort } = - variable.presentation || {} - // Without this the much used var 123 appears as "Countries Continent". We could rename in Grapher but not sure the effects of that. const isContinent = variable.id === 123 const name = isContinent ? "Continent" : variable.name @@ -591,10 +589,7 @@ const columnDefFromOwidVariable = ( source, timespanFromMetadata: timespan, origins, - attribution, - titlePublic, - titleVariant, - attributionShort, + presentation, owidVariableId: variable.id, type: isContinent ? ColumnTypeNames.Continent diff --git a/packages/@ourworldindata/grapher/src/modal/SourcesModal.tsx b/packages/@ourworldindata/grapher/src/modal/SourcesModal.tsx index d79d641756f..b36545ca964 100644 --- a/packages/@ourworldindata/grapher/src/modal/SourcesModal.tsx +++ b/packages/@ourworldindata/grapher/src/modal/SourcesModal.tsx @@ -63,7 +63,7 @@ export class SourcesModal extends React.Component<{ // made when the CoreColumn is filled from the Variable metadata // in columnDefFromOwidVariable in packages/@ourworldindata/grapher/src/core/LegacyToOwidTable.ts const { slug, source, def } = column - const { datasetId, coverage } = def as OwidColumnDef + const { datasetId, coverage, presentation } = def as OwidColumnDef // there will not be a datasetId for explorers that define the FASTT in TSV const editUrl = @@ -83,8 +83,10 @@ export class SourcesModal extends React.Component<{ )}` const title = - column.def.titlePublic && column.def.titlePublic !== "" - ? column.def.titlePublic + presentation && + presentation.titlePublic && + presentation.titlePublic !== "" + ? presentation.titlePublic : column.name const retrievedDate =