- {((showChartOnInteraction && selectedFeature) ||
- (!showChartOnInteraction &&
- selectedDate !== undefined &&
- selectedLayerId !== undefined)) && (
-
-
-
-
-
- Save chart data
-
-
- )}
- {!!selectedLayer?.attributes!.download_link && (
-
-
-
-
-
- Download dataset
-
-
+ {isChartDownloadVisible && (
+
)}
- {!!metadata && (
-
+ {selectedLayer !== undefined && !!selectedLayer.attributes!.download_link && (
+
)}
+ {!!metadata &&
}
{(!!selectedLayer?.attributes!.download_link || !!metadata) && (
)}
@@ -409,12 +355,17 @@ const DatasetCard = ({
)}
- {isDatasetActive && selectedLayer !== undefined && !!showChartOnInteraction && (
+ {isDatasetActive && showChartOnInteraction && selectedLayer !== undefined && (
Select a point on the map for details.
)}
+ {showChartOnInteraction && selectedLayer !== undefined && !!selectedFeature && (
+
+
+
+ )}
{selectedDate !== undefined && selectedLayerId !== undefined && (
)}
- {selectedLayer !== undefined && !!showChartOnInteraction && !!selectedFeature && (
-
-
-
- )}
{isDatasetActive && selectedLayer !== undefined && selectedDate !== undefined && (
)}
diff --git a/client/src/components/dataset-card/metadata-button.tsx b/client/src/components/dataset-card/metadata-button.tsx
new file mode 100644
index 0000000..f49558a
--- /dev/null
+++ b/client/src/components/dataset-card/metadata-button.tsx
@@ -0,0 +1,39 @@
+import DatasetMetadata from "@/components/dataset-metadata";
+import { Button } from "@/components/ui/button";
+import { Dialog, DialogContent, DialogTrigger } from "@/components/ui/dialog";
+import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
+import QuestionMarkIcon from "@/svgs/question-mark.svg";
+import { MetadataItemComponent } from "@/types/generated/strapi.schemas";
+
+interface MetadataButtonProps {
+ datasetName: string;
+ metadata: MetadataItemComponent;
+}
+
+const MetadataButton = ({ datasetName, metadata }: MetadataButtonProps) => {
+ return (
+
+ );
+};
+
+export default MetadataButton;
From 512cab238af616dd7d99d73c8c49e67e366c7956 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20Prod=27homme?=
Date: Wed, 27 Nov 2024 17:26:06 +0100
Subject: [PATCH 10/10] feat(client): Add chart sentence
---
.../dataset-card/chart-sentence.tsx | 30 +++++++++++++++++++
client/src/components/dataset-card/index.tsx | 28 +++++++++++++++--
.../src/components/panels/drought/index.tsx | 2 +-
client/src/components/panels/flood/index.tsx | 2 +-
.../panels/hydrometeorological/index.tsx | 2 +-
5 files changed, 58 insertions(+), 6 deletions(-)
create mode 100644 client/src/components/dataset-card/chart-sentence.tsx
diff --git a/client/src/components/dataset-card/chart-sentence.tsx b/client/src/components/dataset-card/chart-sentence.tsx
new file mode 100644
index 0000000..ed8d3ad
--- /dev/null
+++ b/client/src/components/dataset-card/chart-sentence.tsx
@@ -0,0 +1,30 @@
+import { GeoJsonProperties } from "geojson";
+import { useMemo } from "react";
+
+interface ChartSentenceprops {
+ sentence: string;
+ feature?: GeoJsonProperties;
+}
+
+const ChartSentence = ({ sentence, feature }: ChartSentenceprops) => {
+ const resolvedSentence = useMemo(() => {
+ let res = `${sentence}`; // Creating a copy
+
+ if (!!feature) {
+ Object.entries(feature).forEach(([key, value]) => {
+ res = res.replace(`{${key}}`, value);
+ });
+ }
+
+ return res;
+ }, [sentence, feature]);
+
+ return (
+
+ {!!feature &&
Selected point
}
+
{resolvedSentence}
+
+ );
+};
+
+export default ChartSentence;
diff --git a/client/src/components/dataset-card/index.tsx b/client/src/components/dataset-card/index.tsx
index 488e8de..d9b23e8 100644
--- a/client/src/components/dataset-card/index.tsx
+++ b/client/src/components/dataset-card/index.tsx
@@ -25,6 +25,7 @@ import useYearChartData from "@/hooks/use-year-chart-data";
import CursorArrowRaysIcon from "@/svgs/cursor-arrow-rays.svg";
import { DatasetLayersDataItem, MetadataItemComponent } from "@/types/generated/strapi.schemas";
+import ChartSentence from "./chart-sentence";
import DateControls from "./date-controls";
import DownloadChartButton from "./download-chart-button";
import DownloadLayerButton from "./download-layer-button";
@@ -194,6 +195,16 @@ const DatasetCard = ({
return `${name}${!showChartOnInteraction ? ` - ${locationData![0].name}` : ""}.json`;
}, [isChartDownloadDisabled, locationData, name, showChartOnInteraction]);
+ const isInteractionChartVisible = useMemo(
+ () => showChartOnInteraction && selectedLayer !== undefined && !!selectedFeature,
+ [selectedFeature, selectedLayer, showChartOnInteraction],
+ );
+
+ const isYearChartVisible = useMemo(
+ () => selectedDate !== undefined && selectedLayerId !== undefined,
+ [selectedDate, selectedLayerId],
+ );
+
const onToggleDataset = useCallback(
(active: boolean) => {
if (selectedLayerId === undefined) {
@@ -361,21 +372,32 @@ const DatasetCard = ({
Select a point on the map for details.
)}
- {showChartOnInteraction && selectedLayer !== undefined && !!selectedFeature && (
+ {isInteractionChartVisible && (