- {
- question.text = value
- })}
- placeholder="e.g. How did countries respond to the pandemic?"
- helpText="Short question promoting exploration of related content"
- softCharacterLimit={50}
- />
- {question.text && (
- {
- question.url = value
- })}
- placeholder="e.g. https://ourworldindata.org/coronavirus"
- helpText="Page or section of a page where the answer to the previous question can be found."
- errorMessage={getErrorMessageRelatedQuestionUrl(
- question
- )}
- />
- )}
-
{
+ await queryRunner.query(
+ `
+ -- sql
+ UPDATE chart_configs cc
+ SET cc.patch = JSON_SET(cc.patch, '$.$schema', ?),
+ cc.full = JSON_SET(cc.full, '$.$schema', ?)
+ `,
+ [newSchema, newSchema]
+ )
+ }
+
+ private async turnRelatedQuestionIntoObject(
+ queryRunner: QueryRunner,
+ config: "patch" | "full"
+ ): Promise {
+ await queryRunner.query(
+ `
+ -- sql
+ UPDATE chart_configs
+ SET
+ ?? = JSON_REMOVE(
+ JSON_SET(
+ ??,
+ '$.relatedQuestion',
+ ??->'$.relatedQuestions[0]'
+ ),
+ '$.relatedQuestions'
+ )
+ WHERE ?? ->> '$.relatedQuestions' is not null
+ `,
+ [config, config, config, config]
+ )
+ }
+
+ private async turnRelatedQuestionIntoArray(
+ queryRunner: QueryRunner,
+ config: "patch" | "full"
+ ): Promise {
+ await queryRunner.query(
+ `
+ -- sql
+ UPDATE chart_configs
+ SET
+ ?? = JSON_REMOVE(
+ JSON_SET(
+ ??,
+ '$.relatedQuestions',
+ JSON_ARRAY(
+ JSON_OBJECT(
+ 'url', ?? ->> '$.relatedQuestion.url',
+ 'text', ?? ->> '$.relatedQuestion.text'
+ )
+ )
+ ),
+ '$.relatedQuestion'
+ )
+ WHERE ?? ->> '$.relatedQuestion' IS NOT NULL
+ `,
+ [config, config, config, config, config]
+ )
+ }
+
+ public async up(queryRunner: QueryRunner): Promise {
+ await this.turnRelatedQuestionIntoObject(queryRunner, "patch")
+ await this.turnRelatedQuestionIntoObject(queryRunner, "full")
+
+ await this.updateSchema(
+ queryRunner,
+ "https://files.ourworldindata.org/schemas/grapher-schema.006.json"
+ )
+ }
+
+ public async down(queryRunner: QueryRunner): Promise {
+ await this.turnRelatedQuestionIntoArray(queryRunner, "patch")
+ await this.turnRelatedQuestionIntoArray(queryRunner, "full")
+
+ await this.updateSchema(
+ queryRunner,
+ "https://files.ourworldindata.org/schemas/grapher-schema.005.json"
+ )
+ }
+}
diff --git a/devTools/schemaProcessor/columns.json b/devTools/schemaProcessor/columns.json
index 75a5b3579a4..223f8944f22 100644
--- a/devTools/schemaProcessor/columns.json
+++ b/devTools/schemaProcessor/columns.json
@@ -617,12 +617,12 @@
},
{
"type": "string",
- "pointer": "/relatedQuestions/0/url",
+ "pointer": "/relatedQuestion/url",
"editor": "textfield"
},
{
"type": "string",
- "pointer": "/relatedQuestions/0/text",
+ "pointer": "/relatedQuestion/text",
"editor": "textfield"
},
{
diff --git a/explorer/ExplorerProgram.ts b/explorer/ExplorerProgram.ts
index ee906f5b26c..bf0b4f1e1cf 100644
--- a/explorer/ExplorerProgram.ts
+++ b/explorer/ExplorerProgram.ts
@@ -400,15 +400,6 @@ export class ExplorerProgram extends GridProgram {
// assume config is valid against the latest schema
mergedConfig.$schema = defaultGrapherConfig.$schema
- // TODO: can be removed once relatedQuestions is refactored
- const { relatedQuestionUrl, relatedQuestionText } =
- this.explorerGrapherConfig
- if (relatedQuestionUrl && relatedQuestionText) {
- mergedConfig.relatedQuestions = [
- { url: relatedQuestionUrl, text: relatedQuestionText },
- ]
- }
-
return mergedConfig
}
diff --git a/explorer/GrapherGrammar.ts b/explorer/GrapherGrammar.ts
index 1daefb2ce37..a0055c14605 100644
--- a/explorer/GrapherGrammar.ts
+++ b/explorer/GrapherGrammar.ts
@@ -284,13 +284,13 @@ export const GrapherGrammar: Grammar = {
keyword: "relatedQuestionText",
description:
"The text used for the related question (at the very bottom of the chart)",
- toGrapherObject: () => ({}), // handled in code (can be done properly once the relatedQuestion field is refactored)
+ toGrapherObject: (value) => ({ relatedQuestion: { text: value } }),
},
relatedQuestionUrl: {
...UrlCellDef,
keyword: "relatedQuestionUrl",
description: "The link of the related question text",
- toGrapherObject: () => ({}), // handled in code (can be done properly once the relatedQuestion field is refactored)
+ toGrapherObject: (value) => ({ relatedQuestion: { url: value } }),
},
mapTargetTime: {
...IntegerCellDef,
diff --git a/packages/@ourworldindata/grapher/src/captionedChart/CaptionedChart.tsx b/packages/@ourworldindata/grapher/src/captionedChart/CaptionedChart.tsx
index 9aaffebffd6..e45ffc41ea9 100644
--- a/packages/@ourworldindata/grapher/src/captionedChart/CaptionedChart.tsx
+++ b/packages/@ourworldindata/grapher/src/captionedChart/CaptionedChart.tsx
@@ -94,7 +94,7 @@ export interface CaptionedChartManager
detailRenderers: MarkdownTextWrap[]
// related question
- relatedQuestions?: RelatedQuestionsConfig[]
+ relatedQuestion?: RelatedQuestionsConfig
showRelatedQuestion?: boolean
}
@@ -271,7 +271,7 @@ export class CaptionedChart extends React.Component {
}
private renderRelatedQuestion(): React.ReactElement {
- const { relatedQuestions } = this.manager
+ const { relatedQuestion } = this.manager
return (