-
-
Notifications
You must be signed in to change notification settings - Fork 229
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
🧹 Restructure CF functions code into smaller files #4054
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
4b4c21d
to
e08b424
Compare
305f9a8
to
8a50281
Compare
8a50281
to
7bf20b8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lords work! Thank you 🙏
functions/grapher/by-uuid/[uuid].ts
Outdated
import { Env } from "../../_common/env.js" | ||
import { | ||
extensions, | ||
fetchGrapherConfig, | ||
} from "../../_common/grapherRenderer.js" | ||
import { extensions } from "../../_common/env.js" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Multiple imports of the same file
functions/grapher/[slug].ts
Outdated
@@ -1,17 +1,18 @@ | |||
import { Env } from "../_common/env.js" | |||
import { Env, extensions } from "../_common/env.js" | |||
import { Etag } from "../_common/grapherRenderer.js" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seeing that this is just a type alias, it could possibly also go into env.ts
functions/_common/metadataTools.ts
Outdated
|
||
const metadataCols = getColumnsForMetadata(grapher) | ||
|
||
const columns: [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also extract this (very long!) type definition to someplace else - possibly simply at the top of this file?
Also, VS Code is telling me about a type error here, so maybe double-check that it is actually correct?
import { Grapher } from "@ourworldindata/grapher" | ||
import { OwidColumnDef } from "@ourworldindata/types" | ||
import { StatusError } from "itty-router" | ||
import { createZip } from "littlezipper" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import { createZip } from "littlezipper" | |
import { createZip, File } from "littlezipper" |
7bf20b8
to
f585721
Compare
f585721
to
19e2195
Compare
19e2195
to
7220fe7
Compare
Hi @marcelgerber! I just polished and rebased this - I think it's good to merge from my side. Can you give it a last look to see if you are happy with the changes? There is one changeset with everything since your first review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always difficult to review these sorts of PRs with high confidence that I caught everything, but I tested each route locally with 2 slugs/uuids each and they all worked (except the human trafficking one) so I think we should be good?
functions/_common/metadataTools.ts
Outdated
searchParams: URLSearchParams | ||
) { | ||
const useShortNames = searchParams.get("useColumnShortNames") === "true" | ||
console.log("useShortNames", useShortNames) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. Just an observation: there's lots of logging throughout these files which makes it hard to evaluate when they're meant to be included and when they're debugging leftovers (which is what this one feels like)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, removed this one and another one.
return Response.json(fullMetadata) | ||
} | ||
|
||
export async function fetchZipForGrapher( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not related to this change as it also happens in master, but in my random testing with URLs in my address bar history, I discovered that http://localhost:8788/grapher/human-trafficking-victims-under-18-years-old-male-vs-female.zip
404s:
Handling error TypeError: Cannot read properties of undefined (reading 'map') at getCitationShort
Should I make a ticket?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A good catch. I fixed this (wrong handling of origins in one place).
This PR restructures the by now pretty large grapherRenderer.ts file into a few smaller files that roughly group similar functionality.