Skip to content

Commit

Permalink
refactor(grapher): add presentation property to CoreColumnDef
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann committed Oct 25, 2023
1 parent f61ca9d commit 4ca5e20
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 16 deletions.
8 changes: 3 additions & 5 deletions packages/@ourworldindata/core-table/src/CoreColumnDef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ToleranceStrategy,
OwidOrigin,
OwidSource,
OwidVariablePresentation,
} from "@ourworldindata/utils"
import { CoreValueType, Color } from "./CoreTableConstants.js"

Expand Down Expand Up @@ -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
Expand All @@ -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<OwidVariablePresentation, "topicTagsLinks">

// Dataset information
datasetId?: number
Expand Down
7 changes: 4 additions & 3 deletions packages/@ourworldindata/grapher/src/core/Grapher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -591,10 +589,7 @@ const columnDefFromOwidVariable = (
source,
timespanFromMetadata: timespan,
origins,
attribution,
titlePublic,
titleVariant,
attributionShort,
presentation,
owidVariableId: variable.id,
type: isContinent
? ColumnTypeNames.Continent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check warning on line 66 in packages/@ourworldindata/grapher/src/modal/SourcesModal.tsx

View workflow job for this annotation

GitHub Actions / eslint

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

Check warning on line 66 in packages/@ourworldindata/grapher/src/modal/SourcesModal.tsx

View workflow job for this annotation

GitHub Actions / eslint

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

// there will not be a datasetId for explorers that define the FASTT in TSV
const editUrl =
Expand Down

0 comments on commit 4ca5e20

Please sign in to comment.