Skip to content

Commit

Permalink
🐛 take table filter toggle into account
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann committed Jan 10, 2025
1 parent f7260ed commit 525b08c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
8 changes: 5 additions & 3 deletions functions/_common/downloadFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
29 changes: 18 additions & 11 deletions packages/@ourworldindata/grapher/src/modal/DownloadModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ export interface DownloadModalManager {
queryStr?: string
table?: OwidTable
transformedTable?: OwidTable
tableForDisplay?: OwidTable
yColumnsFromDimensionsOrSlugsOrAuto?: CoreColumn[]
shouldIncludeDetailsInStaticExport?: boolean
detailsOrderedByReference?: string[]
isDownloadModalOpen?: boolean
frameBounds?: Bounds
captionedChartBounds?: Bounds
isOnChartOrMapTab?: boolean
isOnTableTab?: boolean
showAdminControls?: boolean
isSocialMediaExport?: boolean
isPublished?: boolean
Expand Down Expand Up @@ -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" })
}
Expand Down Expand Up @@ -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,
]
)
Expand Down

0 comments on commit 525b08c

Please sign in to comment.