Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann authored and danyx23 committed Aug 23, 2024
1 parent 5f4b213 commit 7fd998a
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 27 deletions.
24 changes: 4 additions & 20 deletions adminSiteServer/apiRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,16 +300,6 @@ const saveNewChart = async (
shouldInherit = false,
}: { config: GrapherInterface; user: DbPlainUser; shouldInherit?: boolean }
): Promise<GrapherInterface> => {
// if the schema version is missing, assume it's the latest
if (!config.$schema) {
config.$schema = defaultGrapherConfig.$schema
}

// if isPublished is missing, add it
if (!config.isPublished) {
config.isPublished = false
}

// grab the parent of the chart if inheritance should be enabled
const parent = shouldInherit
? await getParentByChartConfig(knex, config)
Expand Down Expand Up @@ -380,16 +370,6 @@ const updateExistingChart = async (
// make sure that the id of the incoming config matches the chart id
config.id = chartId

// if the schema version is missing, assume it's the latest
if (!config.$schema) {
config.$schema = defaultGrapherConfig.$schema
}

// if isPublished is missing, add it
if (!config.isPublished) {
config.isPublished = false
}

// if inheritance is enabled, grab the parent from its config
const shouldInherit =
params.shouldInherit ??
Expand Down Expand Up @@ -531,6 +511,10 @@ const saveGrapher = async (
existingConfig?.$schema ??
defaultGrapherConfig.$schema

// add the isPublished field if is missing
newConfig.isPublished =
newConfig.isPublished ?? existingConfig?.isPublished ?? false

// Execute the actual database update or creation
let chartId: number
if (existingConfig) {
Expand Down
2 changes: 1 addition & 1 deletion db/model/ChartConfigs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export async function updateExistingFullConfig(
await updateExistingConfig(knex, { ...params, column: "full" })
}

export async function updateExistingConfig(
async function updateExistingConfig(
knex: db.KnexReadWriteTransaction,
{
column,
Expand Down
16 changes: 11 additions & 5 deletions db/model/Variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ export async function updateGrapherConfigAdminOfVariable(
trx: db.KnexReadWriteTransaction,
variable: VariableWithGrapherConfigs,
config: GrapherInterface
): Promise<void> {
): Promise<{ chartId: number; isPublished: boolean }[]> {
const { variableId } = variable

const patchConfigAdmin = makeConfigValidForIndicator({
Expand Down Expand Up @@ -347,10 +347,16 @@ export async function updateGrapherConfigAdminOfVariable(
})
}

await updateAllChartsThatInheritFromIndicator(trx, variableId, {
patchConfigETL: variable.etl?.patchConfig ?? {},
patchConfigAdmin: patchConfigAdmin,
})
const updatedCharts = await updateAllChartsThatInheritFromIndicator(
trx,
variableId,
{
patchConfigETL: variable.etl?.patchConfig ?? {},
patchConfigAdmin: patchConfigAdmin,
}
)

return updatedCharts
}

// TODO: these are domain functions and should live somewhere else
Expand Down
3 changes: 3 additions & 0 deletions packages/@ourworldindata/grapher/src/core/Grapher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,9 @@ export class Grapher

updatePersistables(this, obj)

// Regression fix: some legacies have this set to Null. Todo: clean DB.
if (obj.originUrl === null) this.originUrl = ""

// update selection
if (obj.selectedEntityNames)
this.selection.setSelectedEntities(obj.selectedEntityNames)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ properties:
description: Url of the concrete schema version to use to validate this document
format: uri
default: "https://files.ourworldindata.org/schemas/grapher-schema.004.json"
# for now, we only use the schema to validate configs in our database.
# for now, we only validate configs in our database using this schema.
# since we expect all configs in our database to be valid against the latest schema,
# we restrict the $schema field to a single value, the latest schema version.
# if we ever need to validate configs against multiple schema versions,
Expand Down

0 comments on commit 7fd998a

Please sign in to comment.