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 direct R2 bindings #3856

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ca9f71e
🔨 Add wrangler.toml file
danyx23 Aug 5, 2024
225316b
🔨 move more settings to wrangler.toml and upgrade wrangler
danyx23 Aug 5, 2024
f61425d
🐝 clean up wrangler.toml
danyx23 Aug 6, 2024
4b4f046
🔨 (db) add chart_configs table
sophiamersmann Jul 15, 2024
9227938
🔨 switch to client side UUID v7 with text serialization
danyx23 Aug 2, 2024
41d8ed3
🔨 (grapher) let charts inherit defaults
sophiamersmann Jul 16, 2024
9b17581
🐛 (admin) do not show loading animation when the chart has no data
sophiamersmann Jul 23, 2024
dc4f6f9
🐛 (grapher) strip empty objects when diffing configs
sophiamersmann Jul 23, 2024
f2f1b52
🐛 (grapher) keep required keys when diffing configs
sophiamersmann Jul 23, 2024
3ccf76d
✨ (grapher) ignore empty objects when merging configs
sophiamersmann Jul 24, 2024
ee5aba9
🔨 (grapher) remove DEFAULT_GRAPHER_CONFIG_SCHEMA
sophiamersmann Aug 7, 2024
fda9095
🐝 add github action to check default grapher config
sophiamersmann Aug 7, 2024
37608e3
✨ store patches in chart_revisions
sophiamersmann Aug 7, 2024
5f6bdef
🔨 rename R2 settings to generic names
danyx23 Jul 30, 2024
d581cf2
🐛 undo accidental rename
danyx23 Aug 1, 2024
8fbf354
✨ add saving chart configs to R2
danyx23 Aug 2, 2024
e622a05
🚧 WIP tool to sync grapher configs to R2
danyx23 Aug 5, 2024
a428233
🔨 switch from sha1 to md5 and implement remaining sync logic
danyx23 Aug 5, 2024
c4a08bd
💄 add progress bar
danyx23 Aug 5, 2024
66f7ce5
🐝 fix prettier issue
danyx23 Aug 7, 2024
6b9b5b5
🐝 fix minor issues
danyx23 Aug 7, 2024
ff63d5d
🔨 remove SHA-1 functions
danyx23 Aug 7, 2024
f0b4e7e
🔨 add tests for base64/hex conversion
danyx23 Aug 8, 2024
56adc65
💄 minor improvements
danyx23 Aug 8, 2024
2750831
🖊️ document env vars
danyx23 Aug 8, 2024
799a43f
🔨 fix compile errors
danyx23 Aug 8, 2024
ef40191
🔨 configure r2 bindings
danyx23 Aug 5, 2024
d7a8903
🚧 start work on fetching grapher configs for pages functions from R2
danyx23 Aug 6, 2024
ce4a785
✨ finish cf functions fetching from R2
danyx23 Aug 6, 2024
76d65b2
🔨 add fallback to branch name as directory in R2
danyx23 Aug 7, 2024
16a7623
🚧 remove direct R2 bindings
danyx23 Aug 6, 2024
3b7e265
🚧 work on fetching from R2
danyx23 Aug 6, 2024
819aa91
🚧 attempt to use s3client sdk
danyx23 Aug 6, 2024
4370382
🚧 s3client doesn't work inside worker, removing it
danyx23 Aug 6, 2024
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
6 changes: 3 additions & 3 deletions .env.devcontainer
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ GDOCS_CLIENT_ID=''
GDOCS_BASIC_ARTICLE_TEMPLATE_URL=''
GDOCS_SHARED_DRIVE_ID=''

IMAGE_HOSTING_R2_ENDPOINT=''
R2_ENDPOINT=''
IMAGE_HOSTING_R2_CDN_URL=''
IMAGE_HOSTING_R2_BUCKET_PATH=''
IMAGE_HOSTING_R2_ACCESS_KEY_ID=''
IMAGE_HOSTING_R2_SECRET_ACCESS_KEY=''
R2_ACCESS_KEY_ID=''
R2_SECRET_ACCESS_KEY=''
12 changes: 9 additions & 3 deletions .env.example-full
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@ GDOCS_BASIC_ARTICLE_TEMPLATE_URL=
GDOCS_SHARED_DRIVE_ID=
GDOCS_DONATE_FAQS_DOCUMENT_ID= # optional

IMAGE_HOSTING_R2_ENDPOINT= # optional
R2_ENDPOINT= # optional
IMAGE_HOSTING_R2_CDN_URL=
IMAGE_HOSTING_R2_BUCKET_PATH=
IMAGE_HOSTING_R2_ACCESS_KEY_ID= # optional
IMAGE_HOSTING_R2_SECRET_ACCESS_KEY= # optional
R2_ACCESS_KEY_ID= # optional
R2_SECRET_ACCESS_KEY= # optional
# These two GRAPHER_CONFIG_ settings are used to store grapher configs in an R2 bucket.
# The cloudflare workers for thumbnail rendering etc use these settings to fetch the grapher configs.
# This means that for most local dev it is not necessary to set these.
GRAPHER_CONFIG_R2_BUCKET= # optional - for local dev set it to "owid-grapher-configs-staging"
GRAPHER_CONFIG_R2_BUCKET_PATH= # optional - for local dev set it to "devs/YOURNAME"


OPENAI_API_KEY=

Expand Down
53 changes: 53 additions & 0 deletions .github/workflows/check-default-grapher-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Check default grapher config
on:
push:
branches:
- "**"
- "!master"
paths:
- "packages/@ourworldindata/grapher/src/schema/**"

jobs:
commit-default-config:
runs-on: ubuntu-latest

steps:
- name: Clone repository
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- uses: ./.github/actions/setup-node-yarn-deps
- uses: ./.github/actions/build-tsc

- uses: hustcer/setup-nu@v3
with:
version: "0.80" # Don't use 0.80 here, as it was a float number and will be convert to 0.8, you can use v0.80/0.80.0 or '0.80'

# Turn all yaml files in the schema directory into json (should only be one)
- name: Convert yaml schema to json
run: |
(ls packages/@ourworldindata/grapher/src/schema/*.yaml
| each {|yaml|
open $yaml.name
| to json
| save -f ($yaml.name
| path parse
| upsert extension "json"
| path join) })
shell: nu {0}

# Construct default config objects for all grapher schemas in the schema directory (should only be one)
- name: Generate default grapher config
run: |
(ls packages/@ourworldindata/grapher/src/schema/grapher-schema.*.json
| each {|json|
node itsJustJavascript/devTools/schema/generate-default-object-from-schema.js $json.name --save-ts packages/@ourworldindata/grapher/src/schema/defaultGrapherConfig.ts })
shell: nu {0}

- name: Run prettier
run: yarn fixPrettierAll

- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "🤖 update default grapher config"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ dist/
.nx/workspace-data
.dev.vars
**/tsup.config.bundled*.mjs
cfstorage
30 changes: 24 additions & 6 deletions adminSiteClient/ChartEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import {
ChartRedirect,
DimensionProperty,
Json,
GrapherInterface,
diffGrapherConfigs,
isEqual,
omit,
} from "@ourworldindata/utils"
import { computed, observable, runInAction, when } from "mobx"
import { BAKED_GRAPHER_URL } from "../settings/clientSettings.js"
Expand Down Expand Up @@ -97,6 +101,7 @@ export interface ChartEditorManager {
admin: Admin
grapher: Grapher
database: EditorDatabase
parentGrapherConfig: GrapherInterface
logs: Log[]
references: References | undefined
redirects: ChartRedirect[]
Expand Down Expand Up @@ -124,7 +129,7 @@ export class ChartEditor {
@observable.ref errorMessage?: { title: string; content: string }
@observable.ref previewMode: "mobile" | "desktop"
@observable.ref showStaticPreview = false
@observable.ref savedGrapherJson: string = ""
@observable.ref savedPatchConfig: GrapherInterface = {}

// This gets set when we save a new chart for the first time
// so the page knows to update the url
Expand All @@ -137,13 +142,26 @@ export class ChartEditor {
? "mobile"
: "desktop"
when(
() => this.grapher.isReady,
() => (this.savedGrapherJson = JSON.stringify(this.grapher.object))
() => this.grapher.hasData && this.grapher.isReady,
() => (this.savedPatchConfig = this.patchConfig)
)
}

@computed get fullConfig(): GrapherInterface {
return this.grapher.object
}

@computed get patchConfig(): GrapherInterface {
const { parentGrapherConfig } = this.manager
if (!parentGrapherConfig) return this.fullConfig
return diffGrapherConfigs(this.fullConfig, parentGrapherConfig)
}

@computed get isModified(): boolean {
return JSON.stringify(this.grapher.object) !== this.savedGrapherJson
return !isEqual(
omit(this.patchConfig, "version"),
omit(this.savedPatchConfig, "version")
)
}

@computed get grapher() {
Expand Down Expand Up @@ -238,12 +256,12 @@ export class ChartEditor {
if (isNewGrapher) {
this.newChartId = json.chartId
this.grapher.id = json.chartId
this.savedGrapherJson = JSON.stringify(this.grapher.object)
this.savedPatchConfig = json.savedPatch
} else {
runInAction(() => {
grapher.version += 1
this.logs.unshift(json.newLog)
this.savedGrapherJson = JSON.stringify(currentGrapherObject)
this.savedPatchConfig = json.savedPatch
})
}
} else onError?.()
Expand Down
8 changes: 5 additions & 3 deletions adminSiteClient/ChartEditorPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
ChartRedirect,
DimensionProperty,
} from "@ourworldindata/types"
import { Grapher } from "@ourworldindata/grapher"
import { defaultGrapherConfig, Grapher } from "@ourworldindata/grapher"
import { Admin } from "./Admin.js"
import {
ChartEditor,
Expand Down Expand Up @@ -104,7 +104,7 @@ export class ChartEditorPage
extends React.Component<{
grapherId?: number
newGrapherIndex?: number
grapherConfig?: any
grapherConfig?: GrapherInterface
}>
implements ChartEditorManager
{
Expand All @@ -124,7 +124,9 @@ export class ChartEditorPage

@observable simulateVisionDeficiency?: VisionDeficiency

fetchedGrapherConfig?: any
fetchedGrapherConfig?: GrapherInterface
// for now, every chart's parent config is the default layer
parentGrapherConfig = defaultGrapherConfig

async fetchGrapher(): Promise<void> {
const { grapherId } = this.props
Expand Down
11 changes: 8 additions & 3 deletions adminSiteClient/EditorHistoryTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export class EditorHistoryTab extends React.Component<{ editor: ChartEditor }> {
@action.bound copyYamlToClipboard() {
// Use the Clipboard API to copy the config into the users clipboard
const chartConfigObject = {
...this.props.editor.grapher.object,
...this.props.editor.patchConfig,
}
delete chartConfigObject.id
delete chartConfigObject.dimensions
Expand All @@ -149,15 +149,20 @@ export class EditorHistoryTab extends React.Component<{ editor: ChartEditor }> {
// Avoid modifying the original JSON object
// Due to mobx memoizing computed values, the JSON can be mutated.
const chartConfigObject = {
...this.props.editor.grapher.object,
...this.props.editor.patchConfig,
}
return (
<div>
{this.logs.map((log, i) => (
<ul key={i} className="list-group">
<LogRenderer
log={log}
previousLog={this.logs[i + 1]} // Needed for comparison, might be undefined
// Needed for comparison, might be undefined
previousLog={
i + 1 < this.logs.length
? this.logs[i + 1]
: undefined
}
applyConfig={this.applyConfig}
></LogRenderer>
</ul>
Expand Down
1 change: 1 addition & 0 deletions adminSiteClient/GrapherConfigGridEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ export class GrapherConfigGridEditor extends React.Component<GrapherConfigGridEd
selectedRowContent.id
)

// TODO(inheritance): use mergeGrapherConfigs instead
const mergedConfig = merge(grapherConfig, finalConfigLayer)
this.loadGrapherJson(mergedConfig)
}
Expand Down
Loading
Loading