From 525b08c8030b61937b7f0bd96df92c7ceb666315 Mon Sep 17 00:00:00 2001 From: Sophia Mersmann Date: Fri, 10 Jan 2025 11:37:57 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20take=20table=20filter=20toggle?= =?UTF-8?q?=20into=20account?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- functions/_common/downloadFunctions.ts | 8 +++-- .../grapher/src/modal/DownloadModal.tsx | 29 ++++++++++++------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/functions/_common/downloadFunctions.ts b/functions/_common/downloadFunctions.ts index 390cb0bd7b..ea384793fa 100644 --- a/functions/_common/downloadFunctions.ts +++ b/functions/_common/downloadFunctions.ts @@ -68,10 +68,12 @@ export async function fetchZipForGrapher( } function assembleCsv(grapher: Grapher, searchParams: URLSearchParams): string { const useShortNames = searchParams.get("useColumnShortNames") === "true" + const fullTable = grapher.inputTable // TODO: should this be table? + const filteredTable = grapher.isOnTableTab + ? grapher.tableForDisplay + : grapher.transformedTable const table = - searchParams.get("csvType") === "filtered" - ? grapher.transformedTable - : grapher.inputTable + searchParams.get("csvType") === "filtered" ? filteredTable : fullTable return table.toPrettyCsv(useShortNames) } diff --git a/packages/@ourworldindata/grapher/src/modal/DownloadModal.tsx b/packages/@ourworldindata/grapher/src/modal/DownloadModal.tsx index b89031653b..d8ffaa1060 100644 --- a/packages/@ourworldindata/grapher/src/modal/DownloadModal.tsx +++ b/packages/@ourworldindata/grapher/src/modal/DownloadModal.tsx @@ -56,6 +56,7 @@ export interface DownloadModalManager { queryStr?: string table?: OwidTable transformedTable?: OwidTable + tableForDisplay?: OwidTable yColumnsFromDimensionsOrSlugsOrAuto?: CoreColumn[] shouldIncludeDetailsInStaticExport?: boolean detailsOrderedByReference?: string[] @@ -63,6 +64,7 @@ export interface DownloadModalManager { frameBounds?: Bounds captionedChartBounds?: Bounds isOnChartOrMapTab?: boolean + isOnTableTab?: boolean showAdminControls?: boolean isSocialMediaExport?: boolean isPublished?: boolean @@ -432,19 +434,20 @@ interface DataDownloadContextClientSide extends DataDownloadContextBase { shortColNames: boolean // Only needed for local CSV generation - table: OwidTable - transformedTable: OwidTable + fullTable: OwidTable + filteredTable: OwidTable activeColumnSlugs: string[] | undefined } const createCsvBlobLocally = async (ctx: DataDownloadContextClientSide) => { - const csv = + const downloadTable = ctx.csvDownloadType === CsvDownloadType.Full - ? ctx.table.toPrettyCsv(ctx.shortColNames, ctx.activeColumnSlugs) - : ctx.transformedTable.toPrettyCsv( - ctx.shortColNames, - ctx.activeColumnSlugs - ) + ? ctx.fullTable + : ctx.filteredTable + const csv = downloadTable.toPrettyCsv( + ctx.shortColNames, + ctx.activeColumnSlugs + ) return new Blob([csv], { type: "text/csv;charset=utf-8" }) } @@ -768,17 +771,21 @@ export const DownloadModalDataTab = (props: DownloadModalProps) => { props.manager.baseUrl ?? `/grapher/${props.manager.displaySlug}`, - table: props.manager.table ?? BlankOwidTable(), - transformedTable: - props.manager.transformedTable ?? BlankOwidTable(), + fullTable: props.manager.table ?? BlankOwidTable(), + filteredTable: + (props.manager.isOnTableTab + ? props.manager.tableForDisplay + : props.manager.transformedTable) ?? BlankOwidTable(), activeColumnSlugs: props.manager.activeColumnSlugs, }), [ props.manager.baseUrl, props.manager.displaySlug, props.manager.queryStr, + props.manager.isOnTableTab, props.manager.table, props.manager.transformedTable, + props.manager.tableForDisplay, props.manager.activeColumnSlugs, ] )