Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔨 Convert SuggestedChartRevision db access to knex #3074

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 0 additions & 48 deletions adminSiteClient/SuggestedChartRevision.ts

This file was deleted.

15 changes: 7 additions & 8 deletions adminSiteClient/SuggestedChartRevisionApproverPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
Tippy,
uniqBy,
} from "@ourworldindata/utils"
import { SuggestedChartRevision } from "@ourworldindata/types"
import { Grapher } from "@ourworldindata/grapher"
import {
TextAreaField,
Expand Down Expand Up @@ -44,7 +45,6 @@ import {
VisionDeficiencyDropdown,
VisionDeficiencyEntity,
} from "./VisionDeficiencies.js"
import { SuggestedChartRevisionSerialized } from "./SuggestedChartRevision.js"
import { match } from "ts-pattern"
import { ReferencesSection } from "./EditorReferencesTab.js"

Expand All @@ -57,7 +57,7 @@ interface UserSelectOption {
export class SuggestedChartRevisionApproverPage extends React.Component<{
suggestedChartRevisionId?: number
}> {
@observable.ref suggestedChartRevisions?: SuggestedChartRevisionSerialized[]
@observable.ref suggestedChartRevisions?: SuggestedChartRevision[]
@observable currentlyActiveUserId?: number
@observable.ref originalGrapherElement?: JSX.Element
@observable.ref suggestedGrapherElement?: JSX.Element
Expand Down Expand Up @@ -205,7 +205,7 @@ export class SuggestedChartRevisionApproverPage extends React.Component<{
console.log("fetchGraphers 2")
runInAction(() => {
this.suggestedChartRevisions =
json.suggestedChartRevisions as SuggestedChartRevisionSerialized[]
json.suggestedChartRevisions as SuggestedChartRevision[]
})
console.log("fetchGraphers 3")
this.decisionReasonInput = this.currentSuggestedChartRevision
Expand Down Expand Up @@ -289,9 +289,8 @@ export class SuggestedChartRevisionApproverPage extends React.Component<{
if (this.currentSuggestedChartRevision) {
// Get suggestions
const suggestions =
this.currentSuggestedChartRevision?.experimental?.["gpt"]?.[
"suggestions"
]
this.currentSuggestedChartRevision?.experimental?.gpt
?.suggestions
if (suggestions !== undefined) {
// Set title
const title = suggestions?.[this.gptNum]?.["title"]
Expand Down Expand Up @@ -498,7 +497,7 @@ export class SuggestedChartRevisionApproverPage extends React.Component<{
@computed get availableUsers(): UserSelectOption[] {
const availableUserAccordingToRevisions =
this.suggestedChartRevisions?.map((revision) => ({
userId: revision.createdById,
userId: revision.createdBy,
userName: revision.createdByFullName,
})) ?? []

Expand All @@ -518,7 +517,7 @@ export class SuggestedChartRevisionApproverPage extends React.Component<{
if (this.currentlyActiveUserId === undefined)
return this.suggestedChartRevisions
return this.suggestedChartRevisions?.filter(
(revision) => revision.createdById === this.currentlyActiveUserId
(revision) => revision.createdBy === this.currentlyActiveUserId
)
}

Expand Down
24 changes: 14 additions & 10 deletions adminSiteServer/adminRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ adminRouter.get("/datasets/:datasetId.csv", async (req, res) => {
callback(null)
},
})
await Dataset.writeCSV(datasetId, writeStream)
await Dataset.writeCSV(datasetId, writeStream, db.knexInstance())
res.end()
})

Expand All @@ -167,13 +167,13 @@ adminRouter.get("/datasets/:datasetId/downloadZip", async (req, res) => {
adminRouter.get("/posts/preview/:postId", async (req, res) => {
const postId = expectInt(req.params.postId)

res.send(await renderPreview(postId))
res.send(await renderPreview(postId, db.knexInstance()))
})

adminRouter.get("/posts/compare/:postId", async (req, res) => {
const postId = expectInt(req.params.postId)

const wpPage = await renderPreview(postId)
const wpPage = await renderPreview(postId, db.knexInstance())
const archieMlText = await Post.select(
"archieml",
"archieml_update_statistics"
Expand Down Expand Up @@ -279,13 +279,16 @@ adminRouter.get("/datapage-preview/:id", async (req, res) => {
await explorerAdminServer.getAllPublishedExplorersBySlugCached()

res.send(
await renderDataPageV2({
variableId,
variableMetadata,
isPreviewing: true,
useIndicatorGrapherConfigs: true,
publishedExplorersBySlug,
})
await renderDataPageV2(
{
variableId,
variableMetadata,
isPreviewing: true,
useIndicatorGrapherConfigs: true,
publishedExplorersBySlug,
},
db.knexInstance()
)
)
})

Expand All @@ -300,6 +303,7 @@ adminRouter.get("/grapher/:slug", async (req, res) => {
res.send(
await renderPreviewDataPageOrGrapherPage(
entity.config,
db.knexInstance(),
publishedExplorersBySlug
)
)
Expand Down
Loading
Loading