diff --git a/CHANGELOG.md b/CHANGELOG.md index 33e12f9f3..1082e13b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -59,6 +59,9 @@ introduced since v4.0.0 🎉 - % mode toggle no longer overlaps with the Y axis title - Merging of cubes beta tag has been removed - Dual line Chart Tooltip indicators are now fixed for smaller screens + - Fixes Tooltip position for Pie Charts for smaller screens + - Ensures undefined / unavailable data is represent as "-" for exported Data + files # [4.9.4] - 2024-11-06 diff --git a/app/components/data-download.tsx b/app/components/data-download.tsx index e8e8eface..0830b3ae6 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..4d35325bc 100644 --- a/app/formatters.ts +++ b/app/formatters.ts @@ -21,6 +21,7 @@ import { parseDate } from "./configurator/components/ui-helpers"; import { getD3FormatLocale, getD3TimeFormatLocale } from "./locales/locales"; const DIMENSION_VALUE_UNDEFINED = "https://cube.link/Undefined"; +const NO_AVAILABLE_VALUE_RETURN_REPLACEMENT = "–"; export type DateFormatter = (d: string | Date | null) => string; @@ -117,8 +118,10 @@ 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}` + : NO_AVAILABLE_VALUE_RETURN_REPLACEMENT; }; const decimalFormatter = (dim: NumericalMeasure, formatNumber: Formatter) => {