-
-
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
✨ Filter for only active columns in grapher data download #4242
Conversation
Quick links (staging server):
Login:
SVG tester:Number of differences (default views): 0 ✅ Edited: 2024-12-02 16:28:20 UTC |
@@ -606,11 +606,30 @@ export class OwidTable extends CoreTable<OwidRow, OwidColumnDef> { | |||
} | |||
|
|||
// Give our users a clean CSV of each Grapher. Assumes an Owid Table with entityName. | |||
toPrettyCsv(useShortNames: boolean = false): string { | |||
toPrettyCsv( | |||
// |
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.
nit: empty comment
const activeColumnsDiff: Set<string> = activeColumnSlugs | ||
? differenceOfSets([ | ||
new Set(this.columnSlugs), | ||
new Set(activeColumnSlugs), | ||
]) | ||
: new Set() | ||
const columnSlugsToRemove = differenceOfSets([ | ||
activeColumnsDiff, | ||
new Set([ | ||
OwidTableSlugs.year, | ||
OwidTableSlugs.day, | ||
this.entityNameSlug, | ||
]), | ||
]) |
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.
I think this all would be a bit cleaner and easier to follow if it was using this.select()
instead. The two diffs after one another are hard to reason about, after all.
I.e. something like:
if (activeColumnSlugs?.length) {
this.select([year, day, entityName, ...activeColumnSlugs])
} else {
this.dropColumns(...)
}
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.
Ah very nice! I looked a bit to see if we had the inverse of drop and was looking for pick or keep but didn't think of select. Much nicer, thanks!
Filter data downloads in grapher to only the actively used columns. Not doing this was a problem for csv based explorers that can have a huge number of columns.