Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into cloudflare-images
Browse files Browse the repository at this point in the history
  • Loading branch information
ikesau committed Dec 10, 2024
2 parents 24576e2 + 0f5903e commit bccff52
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 14 deletions.
42 changes: 28 additions & 14 deletions adminSiteServer/apiRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,15 @@ import {
CHART_VIEW_PROPS_TO_PERSIST,
CHART_VIEW_PROPS_TO_OMIT,
DbEnrichedImage,
JsonString,
} from "@ourworldindata/types"
import { uuidv7 } from "uuidv7"
import {
migrateGrapherConfigToLatestVersion,
getVariableDataRoute,
getVariableMetadataRoute,
defaultGrapherConfig,
grapherConfigToQueryParams,
} from "@ourworldindata/grapher"
import { getDatasetById, setTagsForDataset } from "../db/model/Dataset.js"
import { getUserById, insertUser, updateUser } from "../db/model/User.js"
Expand Down Expand Up @@ -3567,7 +3569,7 @@ postRouteWithRWTransaction(apiRouter, "/tagGraph", async (req, res, trx) => {
res.send({ success: true })
})

const createPatchConfigAndFullConfigForChartView = async (
const createPatchConfigAndQueryParamsForChartView = async (
knex: db.KnexReadonlyTransaction,
parentChartId: number,
config: GrapherInterface
Expand All @@ -3592,8 +3594,10 @@ const createPatchConfigAndFullConfigForChartView = async (
...pick(fullConfigIncludingDefaults, CHART_VIEW_PROPS_TO_PERSIST),
}

const queryParams = grapherConfigToQueryParams(config)

const fullConfig = mergeGrapherConfigs(parentChartConfig, patchConfigToSave)
return { patchConfig: patchConfigToSave, fullConfig }
return { patchConfig: patchConfigToSave, fullConfig, queryParams }
}

getRouteWithROTransaction(apiRouter, "/chartViews", async (req, res, trx) => {
Expand Down Expand Up @@ -3654,10 +3658,11 @@ getRouteWithROTransaction(
> & {
lastEditedByUser: string
chartConfigId: string
configFull: string
configPatch: string
configFull: JsonString
configPatch: JsonString
parentChartId: number
parentConfigFull: string
parentConfigFull: JsonString
queryParamsForParentChart: JsonString
}

const row = await db.knexRawFirst<ChartViewRow>(
Expand All @@ -3672,7 +3677,8 @@ getRouteWithROTransaction(
cc.full as configFull,
cc.patch as configPatch,
cv.parentChartId,
pcc.full as parentConfigFull
pcc.full as parentConfigFull,
cv.queryParamsForParentChart
FROM chart_views cv
JOIN chart_configs cc ON cv.chartConfigId = cc.id
JOIN charts pc ON cv.parentChartId = pc.id
Expand All @@ -3692,6 +3698,9 @@ getRouteWithROTransaction(
configFull: parseChartConfig(row.configFull),
configPatch: parseChartConfig(row.configPatch),
parentConfigFull: parseChartConfig(row.parentConfigFull),
queryParamsForParentChart: JSON.parse(
row.queryParamsForParentChart
),
}

return chartView
Expand All @@ -3708,8 +3717,8 @@ postRouteWithRWTransaction(apiRouter, "/chartViews", async (req, res, trx) => {
throw new JsonError("Invalid request", 400)
}

const { patchConfig, fullConfig } =
await createPatchConfigAndFullConfigForChartView(
const { patchConfig, fullConfig, queryParams } =
await createPatchConfigAndQueryParamsForChartView(
trx,
parentChartId,
rawConfig
Expand All @@ -3728,6 +3737,7 @@ postRouteWithRWTransaction(apiRouter, "/chartViews", async (req, res, trx) => {
parentChartId,
lastEditedByUserId: res.locals.user.id,
chartConfigId: chartConfigId,
queryParamsForParentChart: JSON.stringify(queryParams),
}
const result = await trx.table(ChartViewsTableName).insert(insertRow)
const [resultId] = result
Expand Down Expand Up @@ -3757,8 +3767,8 @@ putRouteWithRWTransaction(
throw new JsonError(`No chart view found for id ${id}`, 404)
}

const { patchConfig, fullConfig } =
await createPatchConfigAndFullConfigForChartView(
const { patchConfig, fullConfig, queryParams } =
await createPatchConfigAndQueryParamsForChartView(
trx,
existingRow.parentChartId,
rawConfig
Expand All @@ -3772,10 +3782,14 @@ putRouteWithRWTransaction(
)

// update chart_views
await trx.table(ChartViewsTableName).where({ id }).update({
updatedAt: new Date(),
lastEditedByUserId: res.locals.user.id,
})
await trx
.table(ChartViewsTableName)
.where({ id })
.update({
updatedAt: new Date(),
lastEditedByUserId: res.locals.user.id,
queryParamsForParentChart: JSON.stringify(queryParams),
})

return { success: true }
}
Expand Down
17 changes: 17 additions & 0 deletions db/migration/1733151294656-ChartViewsAddQueryParam.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { MigrationInterface, QueryRunner } from "typeorm"

export class ChartViewsAddQueryParam1733151294656
implements MigrationInterface
{
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`-- sql
ALTER TABLE chart_views ADD COLUMN queryParamsForParentChart JSON NULL AFTER parentChartId;
`)
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`-- sql
ALTER TABLE chart_views DROP COLUMN queryParamsForParentChart;
`)
}
}
2 changes: 2 additions & 0 deletions packages/@ourworldindata/grapher/src/dataTable/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,8 @@ export class DataTable extends React.Component<{

@computed private get tableCaption(): React.ReactElement | null {
if (this.hasDimensionHeaders) return null
if (this.displayDimensions.length === 0) return null

const singleDimension = this.displayDimensions[0]
const titleFragments = (singleDimension.display.columnName
.attributionShort ||
Expand Down
1 change: 1 addition & 0 deletions packages/@ourworldindata/grapher/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export {
getSelectedEntityNamesParam,
generateSelectedEntityNamesParam,
} from "./core/EntityUrlBuilder"
export { grapherConfigToQueryParams } from "./core/GrapherUrl.js"
export {
type SlideShowManager,
SlideShowController,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ export class AbstractStackedChart

@computed
private get entitiesAsSeries(): readonly StackedRawSeries<number>[] {
if (!this.yColumns.length) return []

const { isProjection, owidRowsByEntityName } = this.yColumns[0]
return this.selectionArray.selectedEntityNames
.map((seriesName) => {
Expand Down
2 changes: 2 additions & 0 deletions packages/@ourworldindata/types/src/dbTypes/ChartViews.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { JsonString } from "../domainTypes/Various.js"
import { GrapherInterface } from "../grapherTypes/GrapherTypes.js"

export const ChartViewsTableName = "chart_views"
Expand All @@ -6,6 +7,7 @@ export interface DbInsertChartView {
name: string
chartConfigId: string
parentChartId: number
queryParamsForParentChart?: JsonString | null
createdAt?: Date | null
updatedAt?: Date | null
lastEditedByUserId: number
Expand Down

0 comments on commit bccff52

Please sign in to comment.