Skip to content

Commit

Permalink
🔨 migrate charts from typeorm to knex
Browse files Browse the repository at this point in the history
  • Loading branch information
danyx23 committed Mar 18, 2024
1 parent bf9c363 commit 34d125e
Show file tree
Hide file tree
Showing 28 changed files with 1,211 additions and 777 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,4 @@
"port": 9000
}
]
}
}
7 changes: 1 addition & 6 deletions adminSiteClient/ChartEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
type RawPageview,
Topic,
PostReference,
ChartRedirect,
DimensionProperty,
} from "@ourworldindata/utils"
import { computed, observable, runInAction, when } from "mobx"
Expand Down Expand Up @@ -56,12 +57,6 @@ export const getFullReferencesCount = (references: References): number => {
)
}

export interface ChartRedirect {
id: number
slug: string
chartId: number
}

export interface Namespace {
name: string
description?: string
Expand Down
2 changes: 1 addition & 1 deletion adminSiteClient/ChartEditorPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
Topic,
GrapherInterface,
GrapherStaticFormat,
ChartRedirect,
DimensionProperty,
} from "@ourworldindata/types"
import { Grapher } from "@ourworldindata/grapher"
Expand All @@ -34,7 +35,6 @@ import {
EditorDatabase,
Log,
References,
ChartRedirect,
ChartEditorManager,
Dataset,
getFullReferencesCount,
Expand Down
7 changes: 5 additions & 2 deletions adminSiteClient/EditorReferencesTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ import React from "react"
import { observer } from "mobx-react"
import {
ChartEditor,
ChartRedirect,
References,
getFullReferencesCount,
} from "./ChartEditor.js"
import { computed, action, observable, runInAction } from "mobx"
import { BAKED_GRAPHER_URL } from "../settings/clientSettings.js"
import { AdminAppContext, AdminAppContextType } from "./AdminAppContext.js"
import { stringifyUnknownError, formatValue } from "@ourworldindata/utils"
import {
stringifyUnknownError,
formatValue,
ChartRedirect,
} from "@ourworldindata/utils"

const BASE_URL = BAKED_GRAPHER_URL.replace(/^https?:\/\//, "")

Expand Down
11 changes: 6 additions & 5 deletions adminSiteServer/adminRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import {
renderDataPageV2,
renderPreviewDataPageOrGrapherPage,
} from "../baker/GrapherBaker.js"
import { Chart } from "../db/model/Chart.js"
import { getChartConfigBySlug } from "../db/model/Chart.js"
import { getVariableMetadata } from "../db/model/Variable.js"
import { DbPlainDatasetFile, DbPlainDataset } from "@ourworldindata/types"

Expand Down Expand Up @@ -324,11 +324,12 @@ adminRouter.get("/datapage-preview/:id", async (req, res) => {
})

adminRouter.get("/grapher/:slug", async (req, res) => {
const entity = await Chart.getBySlug(req.params.slug)
if (!entity) throw new JsonError("No such chart", 404)

const previewDataPageOrGrapherPage = db.knexReadonlyTransaction(
async (knex) => renderPreviewDataPageOrGrapherPage(entity.config, knex)
async (knex) => {
const entity = await getChartConfigBySlug(knex, req.params.slug)
if (!entity) throw new JsonError("No such chart", 404)
return renderPreviewDataPageOrGrapherPage(entity.config, knex)
}
)
res.send(previewDataPageOrGrapherPage)
})
Expand Down
Loading

0 comments on commit 34d125e

Please sign in to comment.