From 3e318bbdda45e6edef2ceaafc5e55886dae08531 Mon Sep 17 00:00:00 2001 From: Bartosz Prusinowski Date: Wed, 1 Nov 2023 13:05:34 +0100 Subject: [PATCH] feat: Add date formatting for temporal dimension values in metadata panel --- app/components/metadata-panel.tsx | 34 ++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/app/components/metadata-panel.tsx b/app/components/metadata-panel.tsx index 2c2c0ecaf..517712ad7 100644 --- a/app/components/metadata-panel.tsx +++ b/app/components/metadata-panel.tsx @@ -28,6 +28,7 @@ import { MotionBox } from "@/components/presence"; import { BackButton, DataSource } from "@/configurator"; import { DRAWER_WIDTH } from "@/configurator/components/drawer"; import { DimensionValue, isStandardErrorDimension } from "@/domain/data"; +import { useDimensionFormatters } from "@/formatters"; import { DimensionMetadataFragment } from "@/graphql/query-hooks"; import { Icon } from "@/icons"; import SvgIcArrowRight from "@/icons/components/IcArrowRight"; @@ -631,11 +632,12 @@ const DimensionValues = ({ dim }: { dim: DimensionMetadataFragment }) => { case "GeoShapesDimension": return ; case "NumericalMeasure": - case "TemporalDimension": case "StandardErrorDimension": return sortedValues.length > 0 ? ( ) : null; + case "TemporalDimension": + return ; default: const _exhaustiveCheck: never = dim; return _exhaustiveCheck; @@ -646,7 +648,7 @@ const DimensionValuesNominal = ({ values }: { values: DimensionValue[] }) => { return ( <> {values.map((d) => - !d.label ? null : ( + d.label ? ( {d.label}{" "} @@ -660,20 +662,38 @@ const DimensionValuesNominal = ({ values }: { values: DimensionValue[] }) => { {d.description} ) : null} - ) + ) : null )} ); }; const DimensionValuesNumeric = ({ values }: { values: DimensionValue[] }) => { - const min = values[0]; - const max = values[values.length - 1]; + const [min, max] = [values[0].value, values[values.length - 1].value]; + + return ( + <> + Min: {min} + Max: {max} + + ); +}; + +const DimensionValuesTemporal = ({ + dim, + values, +}: { + dim: DimensionMetadataFragment; + values: DimensionValue[]; +}) => { + const formatters = useDimensionFormatters([dim]); + const format = formatters[dim.iri]; + const [min, max] = [values[0].value, values[values.length - 1].value]; return ( <> - Min: {min.value} - Max: {max.value} + Min: {format(min)} + Max: {format(max)} ); };