-
-
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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( | ||
// | ||
useShortNames: boolean = false, | ||
activeColumnSlugs: string[] | undefined = undefined | ||
): string { | ||
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 commentThe 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 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 commentThe 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! |
||
return this.dropColumns([ | ||
OwidTableSlugs.entityId, | ||
OwidTableSlugs.time, | ||
OwidTableSlugs.entityColor, | ||
...columnSlugsToRemove, | ||
]) | ||
.sortBy([this.entityNameSlug]) | ||
.toCsvWithColumnNames(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.
nit: empty comment