Skip to content

Commit

Permalink
refactor: move phrase for procssing level into utils folder
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann committed Oct 30, 2023
1 parent 4270549 commit 1d93632
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 15 deletions.
4 changes: 3 additions & 1 deletion datapage/Datapage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
getAttributionFragmentsFromVariable,
getLastUpdatedFromVariable,
getNextUpdateFromVariable,
OwidProcessingLevel,
} from "@ourworldindata/utils"
import { ExplorerProgram } from "../explorer/ExplorerProgram.js"
import { Gdoc } from "../db/model/Gdoc/Gdoc.js"
Expand All @@ -28,7 +29,8 @@ export const getDatapageDataV2 = async (
partialGrapherConfig: GrapherInterface
): Promise<DataPageDataV2> => {
{
const processingLevel = variableMetadata.processingLevel ?? "minor"
const processingLevel =
variableMetadata.processingLevel ?? OwidProcessingLevel.minor
const lastUpdated = getLastUpdatedFromVariable(variableMetadata) ?? ""
const nextUpdate = getNextUpdateFromVariable(variableMetadata)
const datapageJson: DataPageDataV2 = {
Expand Down
3 changes: 2 additions & 1 deletion db/model/Variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
OwidVariableId,
retryPromise,
OwidLicense,
OwidProcessingLevel,
} from "@ourworldindata/utils"
import {
GrapherInterface,
Expand Down Expand Up @@ -41,7 +42,7 @@ export interface VariableRow {
catalogPath?: string
dimensions?: Dimensions
schemaVersion?: number
processingLevel?: "minor" | "major"
processingLevel?: OwidProcessingLevel
titlePublic?: string
titleVariant?: string
attributionShort?: string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import React from "react"
import { dayjs } from "@ourworldindata/utils"
import {
dayjs,
OwidProcessingLevel,
getPhraseForProcessingLevel,
} from "@ourworldindata/utils"
import { DATAPAGE_SOURCES_AND_PROCESSING_SECTION_ID } from "../SharedDataPageConstants.js"

interface IndicatorKeyDataProps {
Expand All @@ -8,16 +12,15 @@ interface IndicatorKeyDataProps {
lastUpdated: string
nextUpdate?: string
unit?: string
owidProcessingLevel?: "minor" | "major"
owidProcessingLevel?: OwidProcessingLevel
canonicalUrl?: string
}

export const IndicatorKeyData = (props: IndicatorKeyDataProps) => {
const canonicalUrl = props.canonicalUrl ?? ""
const processedAdapted =
props.owidProcessingLevel === "minor"
? `minor processing`
: `major adaptations`
const processedAdapted = getPhraseForProcessingLevel(
props.owidProcessingLevel ?? OwidProcessingLevel.minor
)
const dateRange = getDateRange(props.dateRange)
const lastUpdated = dayjs(props.lastUpdated, ["YYYY", "YYYY-MM-DD"])
const keyDataCount = 3 + (props.nextUpdate ? 1 : 0) + (props.unit ? 1 : 0)
Expand Down
7 changes: 6 additions & 1 deletion packages/@ourworldindata/utils/src/OwidVariable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export interface OwidVariableWithSource {
source?: OwidSource
origins?: OwidOrigin[]
schemaVersion?: number
processingLevel?: "minor" | "major"
processingLevel?: OwidProcessingLevel
presentation?: OwidVariablePresentation
shortName?: string
timespan?: string
Expand Down Expand Up @@ -100,6 +100,11 @@ export interface OwidVariablePresentation {
faqs?: FaqLink[]
}

export enum OwidProcessingLevel {
minor = "minor",
major = "major",
}

export interface FaqLink {
gdocId: string
fragmentId: string
Expand Down
2 changes: 2 additions & 0 deletions packages/@ourworldindata/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ export {
formatAuthors,
getLastUpdatedFromVariable,
getNextUpdateFromVariable,
getPhraseForProcessingLevel,
} from "./metadataHelpers.js"

export {
Expand Down Expand Up @@ -496,6 +497,7 @@ export {
type OwidVariablePresentation,
type OwidEntityKey,
type OwidLicense,
OwidProcessingLevel,
} from "./OwidVariable.js"

export {
Expand Down
6 changes: 5 additions & 1 deletion packages/@ourworldindata/utils/src/metadataHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { OwidOrigin } from "./OwidOrigin"
import { OwidVariableWithSource } from "./OwidVariable"
import { OwidProcessingLevel, OwidVariableWithSource } from "./OwidVariable"
import { compact, uniq, last } from "./Util"
import dayjs from "./dayjs.js"

Expand Down Expand Up @@ -101,3 +101,7 @@ export const getNextUpdateFromVariable = (
}
return nextUpdate
}

export const getPhraseForProcessingLevel = (
processingLevel: OwidProcessingLevel
) => (processingLevel === "major" ? "major adaptations" : "minor processing")
3 changes: 2 additions & 1 deletion packages/@ourworldindata/utils/src/owidTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Static, Type } from "@sinclair/typebox"
import { gdocUrlRegex } from "./GdocsConstants.js"
import { OwidOrigin } from "./OwidOrigin.js"
import { OwidSource } from "./OwidSource.js"
import { OwidProcessingLevel } from "./OwidVariable.js"

// todo: remove when we ditch Year and YearIsDay
export const EPOCH_DATE = "2020-01-21"
Expand Down Expand Up @@ -1482,7 +1483,7 @@ export interface DataPageDataV2 {
faqs: FaqLink[] // Todo: resolve these at this level to the point where we can preview them
descriptionKey: string[]
descriptionProcessing?: string
owidProcessingLevel: "minor" | "major"
owidProcessingLevel: OwidProcessingLevel
dateRange: string
lastUpdated: string
nextUpdate?: string
Expand Down
8 changes: 4 additions & 4 deletions site/DataPageV2Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
uniq,
pick,
formatAuthors,
getPhraseForProcessingLevel,
} from "@ourworldindata/utils"
import { AttachmentsContext, DocumentContext } from "./gdocs/OwidGdoc.js"
import StickyNav from "./blocks/StickyNav.js"
Expand Down Expand Up @@ -120,10 +121,9 @@ export const DataPageV2Content = ({
? `${attributionFragments[0]} and other sources`
: attributionFragments.join(", ")
const attributionUnshortened = attributionFragments.join(", ")
const processedAdapted =
datapageData.owidProcessingLevel === "minor"
? `minor processing`
: `major adaptations`
const processedAdapted = getPhraseForProcessingLevel(
datapageData.owidProcessingLevel
)
const lastUpdated = dayjs(datapageData.lastUpdated, ["YYYY", "YYYY-MM-DD"])
const yearOfUpdate = lastUpdated.year()
const citationShort = `${attributionPotentiallyShortened} – with ${processedAdapted} by Our World In Data (${yearOfUpdate})`
Expand Down

0 comments on commit 1d93632

Please sign in to comment.