From f86e5ac4a236ea720381c071a1306285ac9b1549 Mon Sep 17 00:00:00 2001 From: majkshkurti Date: Thu, 8 Aug 2024 11:49:41 +0200 Subject: [PATCH] feat: add scenario to aggregate --- .../toolbox/tools/aggregate/Aggregate.tsx | 42 ++++++++++++++++++- apps/web/lib/validations/tools.ts | 2 + 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/apps/web/components/map/panels/toolbox/tools/aggregate/Aggregate.tsx b/apps/web/components/map/panels/toolbox/tools/aggregate/Aggregate.tsx index bc5836c8..fbfc8a7f 100644 --- a/apps/web/components/map/panels/toolbox/tools/aggregate/Aggregate.tsx +++ b/apps/web/components/map/panels/toolbox/tools/aggregate/Aggregate.tsx @@ -17,7 +17,12 @@ import type { SelectorItem } from "@/types/map/common"; import type { IndicatorBaseProps } from "@/types/map/toolbox"; import useLayerFields from "@/hooks/map/CommonHooks"; -import { useLayerByGeomType, useLayerDatasetId, useStatisticValues } from "@/hooks/map/ToolsHooks"; +import { + useLayerByGeomType, + useLayerDatasetId, + useScenarioItems, + useStatisticValues, +} from "@/hooks/map/ToolsHooks"; import { useAppDispatch, useAppSelector } from "@/hooks/store/ContextHooks"; import FormLabelHelper from "@/components/common/FormLabelHelper"; @@ -67,6 +72,10 @@ const Aggregate = ({ onBack, onClose, type }: AggregateProps) => { const [fieldGroup, setFieldGroup] = useState([]); + // Scenario + const { scenarioItems } = useScenarioItems(projectId as string); + const [selectedScenario, setSelectedScenario] = useState(undefined); + const areaTypes: SelectorItem[] = useMemo(() => { return [ { @@ -120,6 +129,10 @@ const Aggregate = ({ onBack, onClose, type }: AggregateProps) => { payload["source_group_by_field"] = fieldGroup.map((field) => field.name); } + if (selectedScenario) { + payload["scenario_id"] = selectedScenario.value; + } + const schema = type === "point" ? aggregatePointSchema : aggregatePolygonSchema; const computeApi = type === "point" ? computeAggregatePoint : computeAggregatePolygon; try { @@ -150,6 +163,7 @@ const Aggregate = ({ onBack, onClose, type }: AggregateProps) => { setStatisticAdvancedOptions(true); setWeightPolygonByIntersectingArea(false); setFieldGroup([]); + setSelectedScenario(undefined); }; return ( @@ -335,6 +349,32 @@ const Aggregate = ({ onBack, onClose, type }: AggregateProps) => { } /> + + {/* SCENARIO */} + + + { + setSelectedScenario(item as SelectorItem); + }} + items={scenarioItems} + label={t("scenario")} + placeholder={t("select_scenario")} + tooltip={t("choose_scenario")} + /> + + } + /> } diff --git a/apps/web/lib/validations/tools.ts b/apps/web/lib/validations/tools.ts index 2fd701e1..b55af2e9 100644 --- a/apps/web/lib/validations/tools.ts +++ b/apps/web/lib/validations/tools.ts @@ -184,6 +184,7 @@ export const bufferSchema = z.object({ distance_step: z.number(), polygon_union: z.boolean(), polygon_difference: z.boolean(), + scenario_id: z.string().optional(), }); export type PostBuffer = z.infer; @@ -201,6 +202,7 @@ export const aggregatePointSchema = z.object({ field: z.string(), }), source_group_by_field: z.string().array().optional(), + scenario_id: z.string().optional(), }); export const aggregatePolygonSchema = aggregatePointSchema.extend({