diff --git a/app/components/data-download.tsx b/app/components/data-download.tsx index 6d7ae8bc6..a52cbfcc1 100644 --- a/app/components/data-download.tsx +++ b/app/components/data-download.tsx @@ -35,6 +35,7 @@ import { } from "@/domain/data"; import { dateFormatterFromDimension, + formatIdentity, getFormatFullDateAuto, getFormattersForLocale, } from "@/formatters"; @@ -105,6 +106,7 @@ const prepareData = ({ sortingType: "byAuto", sortingOrder: "asc", }; + const sorters = sortedComponents.map< [string, ReturnType] >((d) => { @@ -126,23 +128,39 @@ const prepareData = ({ } } } - return 0; }); const parsedData = sortedData.map((obs) => { - return Object.keys(obs).reduce((acc, key) => { + const formattedObs = Object.keys(obs).reduce((acc, key) => { + return { + ...acc, + [key]: formatIdentity(obs[key]), + }; + }, {}); + + return Object.keys(formattedObs).reduce((acc, key) => { const col = columns[key]; const parser = dimensionParsers[key]; - return col - ? { - ...acc, - ...{ [makeColumnLabel(col)]: parser(obs[key] as string) }, - } - : acc; + if (!col) return acc; + + const value = formattedObs[key]; + let parsedValue; + + if (value?.toString() === "–") { + parsedValue = "-"; + } else { + parsedValue = parser(value as string); + } + + return { + ...acc, + [makeColumnLabel(col)]: parsedValue, + }; }, {}); }); + const columnKeys = Object.values(columns).map(makeColumnLabel); return { @@ -343,6 +361,7 @@ const DownloadMenuItem = ({ const components = [...dimensions, ...measures]; const dimensionParsers = getDimensionParsers(components, { locale }); const observations = observationsData.dataCubesObservations.data; + const { columnKeys, data } = prepareData({ components, observations, diff --git a/app/formatters.ts b/app/formatters.ts index 50abd1e82..98ad6d01f 100644 --- a/app/formatters.ts +++ b/app/formatters.ts @@ -117,8 +117,8 @@ export const dateFormatterFromDimension = ( type Formatter = (x: string) => string; -const formatIdentity = (x: string | Date | null) => { - return x !== DIMENSION_VALUE_UNDEFINED ? `${x}` : "–"; +export const formatIdentity = (x: string | number | Date | null) => { + return x !== DIMENSION_VALUE_UNDEFINED && x !== null ? `${x}` : "–"; }; const decimalFormatter = (dim: NumericalMeasure, formatNumber: Formatter) => {