Skip to content

Commit

Permalink
refactor: use consistent names -- chart views & narrative charts
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelgerber committed Dec 19, 2024
1 parent ee1042f commit 952c6e2
Show file tree
Hide file tree
Showing 19 changed files with 78 additions and 79 deletions.
2 changes: 1 addition & 1 deletion adminSiteClient/AdminSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const AdminSidebar = (): React.ReactElement => (
{chartViewsFeatureEnabled && (
<li>
<Link to="/chartViews">
<FontAwesomeIcon icon={faPanorama} /> Narrative views
<FontAwesomeIcon icon={faPanorama} /> Narrative charts
</Link>
</li>
)}
Expand Down
4 changes: 2 additions & 2 deletions adminSiteClient/ChartEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,15 @@ export class ChartEditor extends AbstractChartEditor<ChartEditorManager> {
)
}

async saveAsNarrativeView(): Promise<void> {
async saveAsChartView(): Promise<void> {
const { patchConfig, grapher } = this

const chartJson = omit(patchConfig, CHART_VIEW_PROPS_TO_OMIT)

const suggestedName = grapher.title ? slugify(grapher.title) : undefined

const name = prompt(
"Please enter a programmatic name for the narrative view. Note that this name cannot be changed later.",
"Please enter a programmatic name for the narrative chart. Note that this name cannot be changed later.",
suggestedName
)

Expand Down
2 changes: 1 addition & 1 deletion adminSiteClient/ChartViewIndexPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export function ChartViewIndexPage() {
}, [admin])

return (
<AdminLayout title="Narrative views">
<AdminLayout title="Narrative charts">
<main className="ChartViewIndexPage">
<Flex justify="space-between">
<Input
Expand Down
2 changes: 1 addition & 1 deletion adminSiteClient/EditorReferencesTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export const ReferencesSection = (props: {

const chartViews = !!props.references?.chartViews?.length && (
<>
<p>Narrative views based on this chart</p>
<p>Narrative charts based on this chart</p>
<ul className="list-group">
{props.references.chartViews.map((chartView) => (
<li key={chartView.id} className="list-group-item">
Expand Down
8 changes: 4 additions & 4 deletions adminSiteClient/SaveButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ class SaveButtonsForChart extends React.Component<{
void this.props.editor.saveAsNewGrapher()
}

@action.bound onSaveAsNarrativeView() {
void this.props.editor.saveAsNarrativeView()
@action.bound onSaveAsChartView() {
void this.props.editor.saveAsChartView()
}

@action.bound onPublishToggle() {
Expand Down Expand Up @@ -122,10 +122,10 @@ class SaveButtonsForChart extends React.Component<{
<div className="mt-2">
<button
className="btn btn-primary"
onClick={this.onSaveAsNarrativeView}
onClick={this.onSaveAsChartView}
disabled={isSavingDisabled}
>
Save as narrative view
Save as narrative chart
</button>
</div>
)}
Expand Down
30 changes: 15 additions & 15 deletions baker/SiteBaker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import {
grabMetadataForGdocLinkedIndicator,
TombstonePageData,
gdocUrlRegex,
NarrativeViewInfo,
ChartViewInfo,
} from "@ourworldindata/utils"
import { execWrapper } from "../db/execWrapper.js"
import { countryProfileSpecs } from "../site/countryProfileProjects.js"
Expand Down Expand Up @@ -110,7 +110,7 @@ import { getTombstones } from "../db/model/GdocTombstone.js"
import { bakeAllMultiDimDataPages } from "./MultiDimBaker.js"
import { getAllLinkedPublishedMultiDimDataPages } from "../db/model/MultiDimDataPage.js"
import { getPublicDonorNames } from "../db/model/Donor.js"
import { getNarrativeViewsInfo } from "../db/model/ChartView.js"
import { getChartViewsInfo } from "../db/model/ChartView.js"

type PrefetchedAttachments = {
donors: string[]
Expand All @@ -122,7 +122,7 @@ type PrefetchedAttachments = {
explorers: Record<string, LinkedChart>
}
linkedIndicators: Record<number, LinkedIndicator>
narrativeViewsInfo: Record<string, NarrativeViewInfo>
linkedChartViews: Record<string, ChartViewInfo>
}

// These aren't all "wordpress" steps
Expand Down Expand Up @@ -462,10 +462,10 @@ export class SiteBaker {
name: `✅ Prefetched ${publishedAuthors.length} authors`,
})

const narrativeViewsInfo = await getNarrativeViewsInfo(knex)
const narrativeViewsInfoByName = keyBy(narrativeViewsInfo, "name")
const chartViewsInfo = await getChartViewsInfo(knex)
const chartViewsInfoByName = keyBy(chartViewsInfo, "name")
this.progressBar.tick({
name: `✅ Prefetched ${narrativeViewsInfo.length} chart views`,
name: `✅ Prefetched ${chartViewsInfo.length} chart views`,
})

const prefetchedAttachments = {
Expand All @@ -478,7 +478,7 @@ export class SiteBaker {
graphers: publishedChartsBySlug,
},
linkedIndicators: datapageIndicatorsById,
narrativeViewsInfo: narrativeViewsInfoByName,
linkedChartViews: chartViewsInfoByName,
}
this.progressBar.tick({ name: "✅ Prefetched attachments" })
this._prefetchedAttachmentsCache = prefetchedAttachments
Expand All @@ -490,7 +490,7 @@ export class SiteBaker {
imageFilenames,
linkedGrapherSlugs,
linkedExplorerSlugs,
linkedNarrativeChartNames,
linkedChartViewNames,
] = picks
const linkedDocuments = pick(
this._prefetchedAttachmentsCache.linkedDocuments,
Expand Down Expand Up @@ -539,9 +539,9 @@ export class SiteBaker {
this._prefetchedAttachmentsCache.linkedAuthors.filter(
(author) => authorNames.includes(author.name)
),
narrativeViewsInfo: pick(
this._prefetchedAttachmentsCache.narrativeViewsInfo,
linkedNarrativeChartNames
linkedChartViews: pick(
this._prefetchedAttachmentsCache.linkedChartViews,
linkedChartViewNames
),
}
}
Expand Down Expand Up @@ -634,7 +634,7 @@ export class SiteBaker {
publishedGdoc.linkedImageFilenames,
publishedGdoc.linkedChartSlugs.grapher,
publishedGdoc.linkedChartSlugs.explorer,
publishedGdoc.linkedNarrativeChartNames,
publishedGdoc.linkedChartViewNames,
])
publishedGdoc.donors = attachments.donors
publishedGdoc.linkedAuthors = attachments.linkedAuthors
Expand All @@ -645,7 +645,7 @@ export class SiteBaker {
...attachments.linkedCharts.explorers,
}
publishedGdoc.linkedIndicators = attachments.linkedIndicators
publishedGdoc.narrativeViewsInfo = attachments.narrativeViewsInfo
publishedGdoc.linkedChartViews = attachments.linkedChartViews

// this is a no-op if the gdoc doesn't have an all-chart block
if ("loadRelatedCharts" in publishedGdoc) {
Expand Down Expand Up @@ -893,7 +893,7 @@ export class SiteBaker {
dataInsight.linkedImageFilenames,
dataInsight.linkedChartSlugs.grapher,
dataInsight.linkedChartSlugs.explorer,
dataInsight.linkedNarrativeChartNames,
dataInsight.linkedChartViewNames,
])
dataInsight.linkedDocuments = attachments.linkedDocuments
dataInsight.imageMetadata = {
Expand Down Expand Up @@ -967,7 +967,7 @@ export class SiteBaker {
publishedAuthor.linkedImageFilenames,
publishedAuthor.linkedChartSlugs.grapher,
publishedAuthor.linkedChartSlugs.explorer,
publishedAuthor.linkedNarrativeChartNames,
publishedAuthor.linkedChartViewNames,
])

// We don't need these to be attached to the gdoc in the current
Expand Down
2 changes: 1 addition & 1 deletion baker/siteRenderers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ ${dataInsights
latestDataInsights: get(post, "latestDataInsights", []),
homepageMetadata: get(post, "homepageMetadata", {}),
latestWorkLinks: get(post, "latestWorkLinks", []),
narrativeViewsInfo: get(post, "narrativeViewsInfo", {}),
linkedChartViews: get(post, "linkedChartViews", {}),
}}
>
<AtomArticleBlocks blocks={post.content.body} />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { MigrationInterface, QueryRunner } from "typeorm"

export class PostsGdocsLinksAddNarrativeCharts1734454799588
export class PostsGdocsLinksAddChartViews1734454799588
implements MigrationInterface
{
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
ALTER TABLE posts_gdocs_links
MODIFY linkType ENUM ('gdoc', 'url', 'grapher', 'explorer', 'narrative-chart') NULL`)
MODIFY linkType ENUM ('gdoc', 'url', 'grapher', 'explorer', 'chart-view') NULL`)
}

public async down(queryRunner: QueryRunner): Promise<void> {
Expand Down
8 changes: 4 additions & 4 deletions db/model/ChartView.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { NarrativeViewInfo, JsonString } from "@ourworldindata/types"
import { ChartViewInfo, JsonString } from "@ourworldindata/types"
import * as db from "../db.js"

export const getNarrativeViewsInfo = async (
export const getChartViewsInfo = async (
knex: db.KnexReadonlyTransaction,
names?: string[]
): Promise<NarrativeViewInfo[]> => {
type RawRow = Omit<NarrativeViewInfo, "queryParamsForParentChart"> & {
): Promise<ChartViewInfo[]> => {
type RawRow = Omit<ChartViewInfo, "queryParamsForParentChart"> & {
queryParamsForParentChart: JsonString
}
let rows: RawRow[]
Expand Down
27 changes: 11 additions & 16 deletions db/model/Gdoc/GdocBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ import {
getVariableMetadata,
getVariableOfDatapageIfApplicable,
} from "../Variable.js"
import { createLinkForNarrativeChart, createLinkFromUrl } from "../Link.js"
import { createLinkForChartView, createLinkFromUrl } from "../Link.js"
import {
getMultiDimDataPageBySlug,
isMultiDimDataPagePublished,
} from "../MultiDimDataPage.js"
import {
ARCHVED_THUMBNAIL_FILENAME,
ChartConfigType,
NarrativeViewInfo,
ChartViewInfo,
DEFAULT_THUMBNAIL_FILENAME,
GrapherInterface,
LatestDataInsight,
Expand All @@ -67,7 +67,7 @@ import {
OwidGdocLinkType,
OwidGdocType,
} from "@ourworldindata/types"
import { getNarrativeViewsInfo } from "../ChartView.js"
import { getChartViewsInfo } from "../ChartView.js"

export class GdocBase implements OwidGdocBaseInterface {
id!: string
Expand All @@ -91,7 +91,7 @@ export class GdocBase implements OwidGdocBaseInterface {
linkedIndicators: Record<number, LinkedIndicator> = {}
linkedDocuments: Record<string, OwidGdocMinimalPostInterface> = {}
latestDataInsights: LatestDataInsight[] = []
narrativeViewsInfo?: Record<string, NarrativeViewInfo> = {}
linkedChartViews?: Record<string, ChartViewInfo> = {}
_omittableFields: string[] = []

constructor(id?: string) {
Expand Down Expand Up @@ -295,9 +295,9 @@ export class GdocBase implements OwidGdocBaseInterface {
return { grapher: [...grapher], explorer: [...explorer] }
}

get linkedNarrativeChartNames(): string[] {
get linkedChartViewNames(): string[] {
const filteredLinks = this.links
.filter((link) => link.linkType === "narrative-chart")
.filter((link) => link.linkType === OwidGdocLinkType.ChartView)
.map((link) => link.target)

return filteredLinks
Expand Down Expand Up @@ -339,7 +339,7 @@ export class GdocBase implements OwidGdocBaseInterface {
}),
])
.with({ type: "narrative-chart" }, (block) => [
createLinkForNarrativeChart({
createLinkForChartView({
name: block.name,
source: this,
componentType: block.type,
Expand Down Expand Up @@ -708,14 +708,9 @@ export class GdocBase implements OwidGdocBaseInterface {
}
}

async loadNarrativeViewsInfo(
knex: db.KnexReadonlyTransaction
): Promise<void> {
const result = await getNarrativeViewsInfo(
knex,
this.linkedNarrativeChartNames
)
this.narrativeViewsInfo = keyBy(result, "name")
async loadChartViewsInfo(knex: db.KnexReadonlyTransaction): Promise<void> {
const result = await getChartViewsInfo(knex, this.linkedChartViewNames)
this.linkedChartViews = keyBy(result, "name")
}

async fetchAndEnrichGdoc(): Promise<void> {
Expand Down Expand Up @@ -863,7 +858,7 @@ export class GdocBase implements OwidGdocBaseInterface {
await this.loadImageMetadataFromDB(knex)
await this.loadLinkedCharts(knex)
await this.loadLinkedIndicators() // depends on linked charts
await this.loadNarrativeViewsInfo(knex)
await this.loadChartViewsInfo(knex)
await this._loadSubclassAttachments(knex)
await this.validate(knex)
}
Expand Down
4 changes: 2 additions & 2 deletions db/model/Link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function createLinkFromUrl({
} satisfies DbInsertPostGdocLink
}

export function createLinkForNarrativeChart({
export function createLinkForChartView({
name,
source,
componentType,
Expand All @@ -74,7 +74,7 @@ export function createLinkForNarrativeChart({
}): DbInsertPostGdocLink {
return {
target: name,
linkType: OwidGdocLinkType.NarrativeChart,
linkType: OwidGdocLinkType.ChartView,
queryString: "",
hash: "",
text: "",
Expand Down
4 changes: 2 additions & 2 deletions packages/@ourworldindata/grapher/src/core/GrapherConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import type { GrapherProgrammaticInterface } from "./Grapher"
export const GRAPHER_EMBEDDED_FIGURE_ATTR = "data-grapher-src"
export const GRAPHER_EMBEDDED_FIGURE_CONFIG_ATTR = "data-grapher-config"

export const GRAPHER_VIEW_EMBEDDED_FIGURE_CONFIG_ATTR =
"data-grapher-view-config"
export const GRAPHER_CHART_VIEW_EMBEDDED_FIGURE_CONFIG_ATTR =
"data-grapher-chart-view-config"

export const GRAPHER_PAGE_BODY_CLASS = "StandaloneGrapherOrExplorerPage"
export const GRAPHER_IS_IN_IFRAME_CLASS = "IsInIframe"
Expand Down
2 changes: 1 addition & 1 deletion packages/@ourworldindata/grapher/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export { ChartDimension } from "./chart/ChartDimension"
export {
GRAPHER_EMBEDDED_FIGURE_ATTR,
GRAPHER_EMBEDDED_FIGURE_CONFIG_ATTR,
GRAPHER_VIEW_EMBEDDED_FIGURE_CONFIG_ATTR,
GRAPHER_CHART_VIEW_EMBEDDED_FIGURE_CONFIG_ATTR,
GRAPHER_PAGE_BODY_CLASS,
GRAPHER_IS_IN_IFRAME_CLASS,
DEFAULT_GRAPHER_WIDTH,
Expand Down
4 changes: 2 additions & 2 deletions packages/@ourworldindata/types/src/gdocTypes/Gdoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export interface LinkedChart {
}

// An object containing metadata needed for embedded narrative charts
export interface NarrativeViewInfo {
export interface ChartViewInfo {
name: string
title: string
chartConfigId: string
Expand Down Expand Up @@ -281,7 +281,7 @@ export enum OwidGdocLinkType {
Url = "url",
Grapher = "grapher",
Explorer = "explorer",
NarrativeChart = "narrative-chart",
ChartView = "chart-view",
}

export interface OwidGdocLinkJSON {
Expand Down
2 changes: 1 addition & 1 deletion packages/@ourworldindata/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ export {
type OwidGdocContent,
type OwidGdocIndexItem,
extractGdocIndexItem,
type NarrativeViewInfo,
type ChartViewInfo,
} from "./gdocTypes/Gdoc.js"

export {
Expand Down
Loading

0 comments on commit 952c6e2

Please sign in to comment.