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

🚧 remove typeorm annotations from GDocs classes #3299

Merged
merged 1 commit into from
Mar 26, 2024
Merged
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
7 changes: 5 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@
"javascript.preferences.importModuleSpecifierEnding": "js",
"[sql]": {
"editor.defaultFormatter": "inferrinizzard.prettier-sql-vscode"
}
}
},
"Prettier-SQL.keywordCase": "upper",
"Prettier-SQL.SQLFlavourOverride": "mysql",
"Prettier-SQL.expressionWidth": 80
}
2 changes: 1 addition & 1 deletion adminSiteClient/GdocsBreadcrumbsInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const GdocsBreadcrumbsInput = ({
breadcrumbs[breadcrumbs.length - 1].href = undefined
} else breadcrumbs = undefined

setCurrentGdoc({ ...gdoc, breadcrumbs })
setCurrentGdoc({ ...gdoc, breadcrumbs: breadcrumbs ?? null })
}

const setItemAtIndex = (item: BreadcrumbItem, i: number) => {
Expand Down
36 changes: 17 additions & 19 deletions adminSiteClient/GdocsIndexPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ import {
} from "@fortawesome/free-solid-svg-icons"
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome/index.js"
import {
Tag,
DbChartTagJoin,
OwidGdocType,
SearchWord,
buildSearchWordsFromSearchString,
filterFunctionForSearchWords,
spansToUnformattedPlainText,
OwidGdoc,
checkIsGdocPost,
OwidGdocIndexItem,
} from "@ourworldindata/utils"
import { Route, RouteComponentProps } from "react-router-dom"
import { Link } from "./Link.js"
Expand Down Expand Up @@ -139,11 +139,11 @@ export class GdocsIndexPage extends React.Component<GdocsMatchProps> {
}

@computed
get tags(): Tag[] {
get tags(): DbChartTagJoin[] {
return this.context?.availableTags || []
}

@computed get allGdocsToShow(): OwidGdoc[] {
@computed get allGdocsToShow(): OwidGdocIndexItem[] {
const { searchWords, context } = this
if (!context) return []

Expand All @@ -156,18 +156,18 @@ export class GdocsIndexPage extends React.Component<GdocsMatchProps> {
? context.gdocs.filter(
(gdoc) =>
// don't filter docs with no type set
!gdoc.content.type || !!this.filters[gdoc.content.type]
!gdoc.type || !!this.filters[gdoc.type]
)
: context.gdocs

if (searchWords.length > 0) {
const filterFn = filterFunctionForSearchWords(
searchWords,
(gdoc: OwidGdoc) => {
(gdoc: OwidGdocIndexItem) => {
const properties = [
gdoc.content.title,
gdoc.title,
gdoc.slug,
gdoc.content.authors?.join(" "),
gdoc.authors?.join(" "),
gdoc.tags?.map(({ name }) => name).join(" "),
gdoc.id,
]
Expand Down Expand Up @@ -232,17 +232,16 @@ export class GdocsIndexPage extends React.Component<GdocsMatchProps> {
<div
key={gdoc.id}
className={cx(`gdoc-index-item`, {
[`gdoc-index-item__${gdoc.content.type}`]:
gdoc.content.type,
[`gdoc-index-item__${gdoc.type}`]: gdoc.type,
})}
>
<div className="gdoc-index-item__content">
{gdoc.content.type ? (
{gdoc.type ? (
<span
className="gdoc-index-item__type-icon"
title={gdoc.content.type}
title={gdoc.type}
>
{iconGdocTypeMap[gdoc.content.type]}
{iconGdocTypeMap[gdoc.type]}
</span>
) : null}
<Link
Expand All @@ -252,19 +251,19 @@ export class GdocsIndexPage extends React.Component<GdocsMatchProps> {
className="gdoc-index-item__title"
title="Preview article"
>
{gdoc.content.title || "Untitled"}
{gdoc.title || "Untitled"}
</h5>
</Link>
<GdocsEditLink gdocId={gdoc.id} />
<p className="gdoc-index-item__byline">
{gdoc.content.authors?.join(", ")}
{gdoc.authors?.join(", ")}
</p>
<span className="gdoc-index-item__tags">
{gdoc.content.type &&
{gdoc.type &&
![
OwidGdocType.Fragment,
OwidGdocType.AboutPage,
].includes(gdoc.content.type) &&
].includes(gdoc.type) &&
gdoc.tags ? (
<EditableTags
tags={gdoc.tags}
Expand All @@ -290,8 +289,7 @@ export class GdocsIndexPage extends React.Component<GdocsMatchProps> {
: undefined
}
href={
gdoc.content.type !==
OwidGdocType.Fragment
gdoc.type !== OwidGdocType.Fragment
? `${BAKED_BASE_URL}/${gdoc.slug}`
: undefined
}
Expand Down
21 changes: 15 additions & 6 deletions adminSiteClient/GdocsStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ import { action, observable } from "mobx"
import {
getOwidGdocFromJSON,
OwidGdocJSON,
Tag,
DbChartTagJoin,
OwidGdoc,
DbPlainTag,
OwidGdocIndexItem,
} from "@ourworldindata/utils"
import { AdminAppContext } from "./AdminAppContext.js"
import { Admin } from "./Admin.js"
import { extractGdocIndexItem } from "@ourworldindata/types"

/**
* This was originally a MobX data domain store (see
Expand All @@ -17,8 +20,8 @@ import { Admin } from "./Admin.js"
* Today, this store acts as CRUD proxy for requests to API endpoints.
*/
export class GdocsStore {
@observable gdocs: OwidGdoc[] = []
@observable availableTags: Tag[] = []
@observable gdocs: OwidGdocIndexItem[] = []
@observable availableTags: DbChartTagJoin[] = []
admin: Admin

constructor(admin: Admin) {
Expand All @@ -32,9 +35,13 @@ export class GdocsStore {

@action
async update(gdoc: OwidGdoc): Promise<OwidGdoc> {
return this.admin
const item: OwidGdoc = await this.admin
.requestJSON<OwidGdocJSON>(`/api/gdocs/${gdoc.id}`, gdoc, "PUT")
.then(getOwidGdocFromJSON)
const indexItem = extractGdocIndexItem(gdoc)
const gdocToUpdateIndex = this.gdocs.findIndex((g) => g.id === gdoc.id)
if (gdocToUpdateIndex >= 0) this.gdocs[gdocToUpdateIndex] = indexItem
Comment on lines +41 to +43
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is definitely more correct, but is it ever actually used? Whenever you load the index page it refetches all gdocs anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah probably not but it just seems like the right thing to do - maybe we change the behaviour in the future and then it's nice if this part already does what you would expect.

return item
}

@action
Expand All @@ -61,7 +68,9 @@ export class GdocsStore {

@action
async fetchGdocs() {
const gdocs = (await this.admin.getJSON("/api/gdocs")) as OwidGdoc[]
const gdocs = (await this.admin.getJSON(
"/api/gdocs"
)) as OwidGdocIndexItem[]
this.gdocs = gdocs
}

Expand All @@ -72,7 +81,7 @@ export class GdocsStore {
}

@action
async updateTags(gdoc: OwidGdoc, tags: Tag[]) {
async updateTags(gdoc: OwidGdocIndexItem, tags: DbPlainTag[]) {
const json = await this.admin.requestJSON(
`/api/gdocs/${gdoc.id}/setTags`,
{ tagIds: tags.map((t) => t.id) },
Expand Down
7 changes: 3 additions & 4 deletions adminSiteClient/PostsIndexPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ import { observer } from "mobx-react"
import { observable, computed, action, runInAction } from "mobx"

import {
DbChartTagJoin,
Tag,
buildSearchWordsFromSearchString,
filterFunctionForSearchWords,
SearchWord,
uniq,
DbChartTagJoin,
} from "@ourworldindata/utils"
import { AdminLayout } from "./AdminLayout.js"
import { SearchField, FieldsRow, Timeago } from "./Forms.js"
Expand Down Expand Up @@ -52,7 +51,7 @@ enum GdocStatus {

interface PostRowProps {
post: PostIndexMeta
availableTags: Tag[]
availableTags: DbChartTagJoin[]
}

@observer
Expand Down Expand Up @@ -257,7 +256,7 @@ export class PostsIndexPage extends React.Component {
@observable posts: PostIndexMeta[] = []
@observable maxVisibleRows = 50
@observable searchInput?: string
@observable availableTags: Tag[] = []
@observable availableTags: DbChartTagJoin[] = []

@computed get searchWords(): SearchWord[] {
const { searchInput } = this
Expand Down
7 changes: 5 additions & 2 deletions adminSiteClient/TagsIndexPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as lodash from "lodash"
import { Redirect } from "react-router-dom"
import { AdminLayout } from "./AdminLayout.js"
import { FieldsRow, Modal, TextField } from "./Forms.js"
import { Tag, DbChartTagJoin } from "@ourworldindata/utils"
import { DbChartTagJoin } from "@ourworldindata/utils"
import { TagBadge } from "./TagBadge.js"
import { AdminAppContext, AdminAppContextType } from "./AdminAppContext.js"

Expand Down Expand Up @@ -166,7 +166,10 @@ export class TagsIndexPage extends React.Component {
</p>
)}
{parent.children.map((tag) => (
<TagBadge key={tag.id} tag={tag as Tag} />
<TagBadge
key={tag.id}
tag={tag as DbChartTagJoin}
/>
))}
<button
className="btn btn-default"
Expand Down
6 changes: 4 additions & 2 deletions adminSiteClient/gdocsDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import {
OwidGdocDataInsightContent,
OwidGdocType,
OwidGdocHomepageContent,
DbEnrichedPostGdoc,
OwidGdocAuthorContent,
} from "@ourworldindata/types"
import { GDOC_DIFF_OMITTABLE_PROPERTIES } from "./GdocsDiff.js"
import { GDOCS_DETAILS_ON_DEMAND_ID } from "../settings/clientSettings.js"

export const checkFullDeployFallback = (
prevGdoc: OwidGdoc,
nextGdoc: OwidGdoc,
prevGdoc: DbEnrichedPostGdoc,
nextGdoc: DbEnrichedPostGdoc,
hasChanges: boolean
) => {
return hasChanges && (prevGdoc.published || nextGdoc.published)
Expand Down Expand Up @@ -58,6 +59,7 @@ export const checkIsLightningUpdate = (
relatedCharts: true,
revisionId: true,
updatedAt: true,
markdown: true,
createdAt: false, // weird case - can't be updated
id: false, // weird case - can't be updated
tags: false, // could require updating datapages, though it's currently not possible to have a difference between prevGdoc.tags and nextGdoc.tags
Expand Down
Loading
Loading