From 4ca5e20f9ed781c1f9be3feb542db37138993963 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 | 2 +- 4 files changed, 10 insertions(+), 16 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 f7ed8158aca..529b9f86da1 100644 --- a/packages/@ourworldindata/grapher/src/core/Grapher.tsx +++ b/packages/@ourworldindata/grapher/src/core/Grapher.tsx @@ -1516,14 +1516,15 @@ export class Grapher @computed private get defaultSourcesLine(): string { const attributions = this.columnsWithSourcesCondensed.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 066bae2144e..1e39b54b6e6 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 3c7f4fffadc..d19a2f918ad 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 =