From ff311eee804af2e815b3eea0e761eb7ecb4de92f Mon Sep 17 00:00:00 2001 From: Daniel Bachler Date: Tue, 3 Dec 2024 10:06:36 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20incorporate=20PR=20feedback?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core-table/src/OwidTable.ts | 31 ++++++++----------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/packages/@ourworldindata/core-table/src/OwidTable.ts b/packages/@ourworldindata/core-table/src/OwidTable.ts index 7e2dbb3d851..529aff908b1 100644 --- a/packages/@ourworldindata/core-table/src/OwidTable.ts +++ b/packages/@ourworldindata/core-table/src/OwidTable.ts @@ -607,30 +607,25 @@ export class OwidTable extends CoreTable { // Give our users a clean CSV of each Grapher. Assumes an Owid Table with entityName. toPrettyCsv( - // useShortNames: boolean = false, activeColumnSlugs: string[] | undefined = undefined ): string { - const activeColumnsDiff: Set = activeColumnSlugs - ? differenceOfSets([ - new Set(this.columnSlugs), - new Set(activeColumnSlugs), - ]) - : new Set() - const columnSlugsToRemove = differenceOfSets([ - activeColumnsDiff, - new Set([ + let table + if (activeColumnSlugs?.length) { + table = this.select([ OwidTableSlugs.year, OwidTableSlugs.day, this.entityNameSlug, - ]), - ]) - return this.dropColumns([ - OwidTableSlugs.entityId, - OwidTableSlugs.time, - OwidTableSlugs.entityColor, - ...columnSlugsToRemove, - ]) + ...activeColumnSlugs, + ]) + } else { + table = this.dropColumns([ + OwidTableSlugs.entityId, + OwidTableSlugs.time, + OwidTableSlugs.entityColor, + ]) + } + return table .sortBy([this.entityNameSlug]) .toCsvWithColumnNames(useShortNames) }