Skip to content

Commit

Permalink
✨ add new types package. For testing, move SubNavid and FormattingOpt…
Browse files Browse the repository at this point in the history
…ions there.
  • Loading branch information
danyx23 committed Dec 27, 2023
1 parent f4ab296 commit 0424618
Show file tree
Hide file tree
Showing 27 changed files with 87 additions and 63 deletions.
2 changes: 1 addition & 1 deletion baker/formatWordpressPost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import { getTables } from "../db/wpdb.js"
import Tablepress from "../site/Tablepress.js"
import { GrapherExports } from "../baker/GrapherBakingUtils.js"
import { AllCharts, renderAllCharts } from "../site/blocks/AllCharts.js"
import { FormattingOptions } from "@ourworldindata/types"
import {
BLOCK_WRAPPER_DATATYPE,
DataValueProps,
FormattedPost,
FormattingOptions,
FullPost,
JsonError,
TocHeading,
Expand Down
8 changes: 2 additions & 6 deletions baker/pageOverrides.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { PageOverrides } from "../site/LongFormPage.js"
import { BAKED_BASE_URL } from "../settings/serverSettings.js"
import {
urlToSlug,
FormattingOptions,
FullPost,
JsonError,
} from "@ourworldindata/utils"
import { urlToSlug, FullPost, JsonError } from "@ourworldindata/utils"
import { FormattingOptions } from "@ourworldindata/types"
import { getPostBySlug, isPostCitable } from "../db/wpdb.js"
import { getTopSubnavigationParentItem } from "../site/SiteSubnavigation.js"
import { logErrorAndMaybeSendToBugsnag } from "../serverUtils/errorLog.js"
Expand Down
2 changes: 1 addition & 1 deletion baker/siteRenderers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import {
Country,
memoize,
FormattedPost,
FormattingOptions,
FullPost,
JsonError,
KeyInsight,
Expand All @@ -57,6 +56,7 @@ import {
extractFormattingOptions,
PostRowRaw,
} from "@ourworldindata/utils"
import { FormattingOptions } from "@ourworldindata/types"
import { CountryProfileSpec } from "../site/countryProfileProjects.js"
import { formatPost } from "./formatWordpressPost.js"
import {
Expand Down
2 changes: 1 addition & 1 deletion explorer/ExplorerGrammar.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SubNavId } from "@ourworldindata/utils"
import { SubNavId } from "@ourworldindata/types"
import {
CellDef,
BooleanCellDef,
Expand Down
2 changes: 1 addition & 1 deletion explorer/ExplorerProgram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import {
GitCommit,
PromiseCache,
SerializedGridProgram,
SubNavId,
trimObject,
omit,
} from "@ourworldindata/utils"
import { SubNavId } from "@ourworldindata/types"
import {
CellDef,
Grammar,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"@ourworldindata/components": "workspace:^",
"@ourworldindata/core-table": "workspace:^",
"@ourworldindata/grapher": "workspace:^",
"@ourworldindata/types": "workspace:^",
"@ourworldindata/utils": "workspace:^",
"@react-awesome-query-builder/antd": "^6.1.1",
"@sinclair/typebox": "^0.28.5",
Expand Down
1 change: 1 addition & 0 deletions packages/@ourworldindata/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@fortawesome/free-brands-svg-icons": "^6.4.2",
"@fortawesome/free-solid-svg-icons": "^6.4.2",
"@fortawesome/react-fontawesome": "^0.2.0",
"@ourworldindata/types": "workspace:^",
"@ourworldindata/utils": "workspace:^",
"mobx": "^5.15.7",
"mobx-formatters": "^1.0.2",
Expand Down
1 change: 1 addition & 0 deletions packages/@ourworldindata/core-table/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"keywords": [],
"author": "",
"dependencies": {
"@ourworldindata/types": "workspace:^",
"@ourworldindata/utils": "workspace:^",
"d3": "^6.1.1",
"dayjs": "^1.11.5"
Expand Down
1 change: 1 addition & 0 deletions packages/@ourworldindata/grapher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@fortawesome/react-fontawesome": "^0.2.0",
"@ourworldindata/components": "workspace:^",
"@ourworldindata/core-table": "workspace:^",
"@ourworldindata/types": "workspace:^",
"@ourworldindata/utils": "workspace:^",
"@tippyjs/react": "^4.2.6",
"classnames": "^2.3.1",
Expand Down
3 changes: 0 additions & 3 deletions packages/@ourworldindata/types/index.d.ts

This file was deleted.

23 changes: 23 additions & 0 deletions packages/@ourworldindata/types/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "@ourworldindata/types",
"version": "0.0.0",
"description": "",
"main": "dist/index.js",
"directories": {
"lib": "src"
},
"types": "dist",
"scripts": {
"build": "rm -rf ./dist && tsc --build",
"watch": "tsc --watch"
},
"keywords": [],
"author": "",
"devDependencies": {
"eslint": "^8.53.0",
"eslint-plugin-react-hooks": "^4.6.0",
"jest": "^29.7.0",
"typescript": "~5.2.2"
},
"license": "MIT"
}
21 changes: 21 additions & 0 deletions packages/@ourworldindata/types/src/Wordpress.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export interface FormattingOptions {
toc?: boolean
hideAuthors?: boolean
bodyClassName?: string
subnavId?: SubNavId
subnavCurrentId?: string
raw?: boolean

hideDonateFooter?: boolean
footnotes?: boolean
}
export enum SubNavId {
about = "about",
biodiversity = "biodiversity",
coronavirus = "coronavirus",
co2 = "co2",
energy = "energy",
forests = "forests",
water = "water",
explorers = "explorers",
}
1 change: 1 addition & 0 deletions packages/@ourworldindata/types/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { type FormattingOptions, SubNavId } from "./Wordpress.js"
16 changes: 3 additions & 13 deletions packages/@ourworldindata/types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
{
"files": ["index.d.ts"],
"extends": "../../../devTools/tsconfigs/tsconfig.base.json",
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"lib": ["es6"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": ["../"],
"noEmit": true,
"types": [],
"forceConsistentCasingInFileNames": true
"composite": false,
"outDir": "./dist"
}
}
1 change: 1 addition & 0 deletions packages/@ourworldindata/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"keywords": [],
"author": "",
"dependencies": {
"@ourworldindata/types": "workspace:^",
"@tippyjs/react": "^4.2.6",
"d3": "^6.1.1",
"dayjs": "^1.11.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/@ourworldindata/utils/src/dbTypes/Posts.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
FormattingOptions,
OwidArticleBackportingStatistics,
OwidGdocInterface,
WP_PostType,
} from "../owidTypes.js"
import { FormattingOptions } from "@ourworldindata/types"

export interface PostRowPlainFields {
id: number
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FormattingOptions } from "../owidTypes.js"
import { FormattingOptions } from "@ourworldindata/types"
import { PostRowEnriched, PostRowRaw } from "./Posts.js"

export function parsePostFormattingOptions(
Expand Down
2 changes: 0 additions & 2 deletions packages/@ourworldindata/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ export {
EPOCH_DATE,
type FilterFnPostRestApi,
type FormattedPost,
type FormattingOptions,
type FullPost,
GdocsContentSource,
type GitCommit,
Expand Down Expand Up @@ -194,7 +193,6 @@ export {
type SpanSubscript,
type SpanSuperscript,
type SpanUnderline,
SubNavId,
SuggestedChartRevisionStatus,
type ChartTag,
type ChartTagJoin,
Expand Down
22 changes: 0 additions & 22 deletions packages/@ourworldindata/utils/src/owidTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,28 +87,6 @@ export interface FormattedPost extends FullPost {
pageDesc: string
}

export enum SubNavId {
about = "about",
biodiversity = "biodiversity",
coronavirus = "coronavirus",
co2 = "co2",
energy = "energy",
forests = "forests",
water = "water",
explorers = "explorers",
}

export interface FormattingOptions {
toc?: boolean
hideAuthors?: boolean
bodyClassName?: string
subnavId?: SubNavId
subnavCurrentId?: string
raw?: boolean
hideDonateFooter?: boolean
footnotes?: boolean
}

export interface BreadcrumbItem {
label: string
href?: string
Expand Down
3 changes: 2 additions & 1 deletion packages/@ourworldindata/utils/src/wordpressUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { FormattingOptions, KeyValueProps } from "./owidTypes.js"
import { KeyValueProps } from "./owidTypes.js"
import { FormattingOptions } from "@ourworldindata/types"

export const extractFormattingOptions = (html: string): FormattingOptions => {
const formattingOptionsMatch = html.match(
Expand Down
2 changes: 1 addition & 1 deletion site/BackToTopic.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react"
import { SubNavId } from "@ourworldindata/utils"
import { SubNavId } from "@ourworldindata/types"
import { getSubnavItem, subnavs } from "./SiteSubnavigation.js"
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome/index.js"
import { faArrowLeft } from "@fortawesome/free-solid-svg-icons"
Expand Down
3 changes: 2 additions & 1 deletion site/Breadcrumb/Breadcrumb.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from "react"
import { SubNavId, BreadcrumbItem } from "@ourworldindata/utils"
import { BreadcrumbItem } from "@ourworldindata/utils"
import { SubNavId } from "@ourworldindata/types"
import { getSubnavItem, SubnavItem, subnavs } from "../SiteSubnavigation.js"
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome/index.js"
import { faAngleRight } from "@fortawesome/free-solid-svg-icons"
Expand Down
8 changes: 2 additions & 6 deletions site/LongFormPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome/index.js"
import { faBook, faSync } from "@fortawesome/free-solid-svg-icons"
import { faCreativeCommons } from "@fortawesome/free-brands-svg-icons"
import { TableOfContents } from "../site/TableOfContents.js"
import {
FormattedPost,
FormattingOptions,
TocHeading,
omit,
} from "@ourworldindata/utils"
import { FormattedPost, TocHeading, omit } from "@ourworldindata/utils"
import { FormattingOptions } from "@ourworldindata/types"
import { BreadcrumbsFromSubnav } from "./Breadcrumb/Breadcrumb.js"
import { Byline } from "./Byline.js"
import { PageInfo } from "./PageInfo.js"
Expand Down
2 changes: 1 addition & 1 deletion site/SiteSubnavigation.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react"
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome/index.js"
import { faChevronLeft } from "@fortawesome/free-solid-svg-icons"
import { SubNavId } from "@ourworldindata/utils"
import { SubNavId } from "@ourworldindata/types"

export interface SubnavItem {
label: string
Expand Down
2 changes: 1 addition & 1 deletion site/formatting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import * as lodash from "lodash"
import ReactDOMServer from "react-dom/server.js"
import {
FormattedPost,
FormattingOptions,
TocHeading,
WP_BlockClass,
WP_ColumnStyle,
Expand All @@ -25,6 +24,7 @@ import {
import { PROMINENT_LINK_CLASSNAME } from "./blocks/ProminentLink.js"
import { Byline } from "./Byline.js"
import { SectionHeading } from "./SectionHeading.js"
import { FormattingOptions } from "@ourworldindata/types"

export const GRAPHER_PREVIEW_CLASS = "grapherPreview"
export const SUMMARY_CLASSNAME = "wp-block-owid-summary"
Expand Down
1 change: 1 addition & 0 deletions vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default defineConfig({
// Idea from https://github.com/LinusBorg/vue-lib-template/blob/3775e49b20a7c3349dd49321cad2ed7f9d575057/packages/playground/vite.config.ts
"@ourworldindata/grapher": "@ourworldindata/grapher/src/index.ts",
"@ourworldindata/utils": "@ourworldindata/utils/src/index.ts",
"@ourworldindata/types": "@ourworldindata/types/src/index.ts",
"@ourworldindata/core-table":
"@ourworldindata/core-table/src/index.ts",
"@ourworldindata/components":
Expand Down
16 changes: 16 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3361,6 +3361,7 @@ __metadata:
"@fortawesome/free-brands-svg-icons": "npm:^6.4.2"
"@fortawesome/free-solid-svg-icons": "npm:^6.4.2"
"@fortawesome/react-fontawesome": "npm:^0.2.0"
"@ourworldindata/types": "workspace:^"
"@ourworldindata/utils": "workspace:^"
"@types/react": "npm:^17.0.69"
"@types/react-dom": "npm:^17.0.22"
Expand All @@ -3381,6 +3382,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@ourworldindata/core-table@workspace:packages/@ourworldindata/core-table"
dependencies:
"@ourworldindata/types": "workspace:^"
"@ourworldindata/utils": "workspace:^"
"@types/d3": "npm:^6"
d3: "npm:^6.1.1"
Expand All @@ -3403,6 +3405,7 @@ __metadata:
"@fortawesome/react-fontawesome": "npm:^0.2.0"
"@ourworldindata/components": "workspace:^"
"@ourworldindata/core-table": "workspace:^"
"@ourworldindata/types": "workspace:^"
"@ourworldindata/utils": "workspace:^"
"@tippyjs/react": "npm:^4.2.6"
"@types/colorbrewer": "npm:^1.0.29"
Expand Down Expand Up @@ -3448,10 +3451,22 @@ __metadata:
languageName: unknown
linkType: soft

"@ourworldindata/types@workspace:^, @ourworldindata/types@workspace:packages/@ourworldindata/types":
version: 0.0.0-use.local
resolution: "@ourworldindata/types@workspace:packages/@ourworldindata/types"
dependencies:
eslint: "npm:^8.53.0"
eslint-plugin-react-hooks: "npm:^4.6.0"
jest: "npm:^29.7.0"
typescript: "npm:~5.2.2"
languageName: unknown
linkType: soft

"@ourworldindata/utils@workspace:^, @ourworldindata/utils@workspace:packages/@ourworldindata/utils":
version: 0.0.0-use.local
resolution: "@ourworldindata/utils@workspace:packages/@ourworldindata/utils"
dependencies:
"@ourworldindata/types": "workspace:^"
"@tippyjs/react": "npm:^4.2.6"
"@types/d3": "npm:^6"
"@types/d3-format": "npm:^2"
Expand Down Expand Up @@ -10340,6 +10355,7 @@ __metadata:
"@ourworldindata/components": "workspace:^"
"@ourworldindata/core-table": "workspace:^"
"@ourworldindata/grapher": "workspace:^"
"@ourworldindata/types": "workspace:^"
"@ourworldindata/utils": "workspace:^"
"@react-awesome-query-builder/antd": "npm:^6.1.1"
"@sinclair/typebox": "npm:^0.28.5"
Expand Down

0 comments on commit 0424618

Please sign in to comment.