From be35935ed709c03c1225eb04b1dea79b060f2c7f Mon Sep 17 00:00:00 2001 From: majkshkurti Date: Tue, 30 Jul 2024 13:28:21 +0200 Subject: [PATCH] feat: add scenario_id to heatmap tools --- .../toolbox/common/HeatmapContainer.tsx | 39 ++++++++++++++++++- apps/web/lib/validations/tools.ts | 4 ++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/apps/web/components/map/panels/toolbox/common/HeatmapContainer.tsx b/apps/web/components/map/panels/toolbox/common/HeatmapContainer.tsx index c0212309..175559a1 100644 --- a/apps/web/components/map/panels/toolbox/common/HeatmapContainer.tsx +++ b/apps/web/components/map/panels/toolbox/common/HeatmapContainer.tsx @@ -16,7 +16,7 @@ import { HeatmapRoutingTypeEnum, catchmentAreaMaskLayerNames } from "@/lib/valid import type { SelectorItem } from "@/types/map/common"; import type { IndicatorBaseProps } from "@/types/map/toolbox"; -import { useRoutingTypes } from "@/hooks/map/ToolsHooks"; +import { useRoutingTypes, useScenarioItems } from "@/hooks/map/ToolsHooks"; import { useAppDispatch, useAppSelector } from "@/hooks/store/ContextHooks"; import Container from "@/components/map/panels/Container"; @@ -78,6 +78,8 @@ const HeatmapContainer = ({ return isValid; }, [isValid, selectedRouting]); + // const [selectedScenario, setSelectedScenario] = useState(undefined); + const { mutate } = useJobs({ read: false, }); @@ -85,9 +87,14 @@ const HeatmapContainer = ({ const runningJobIds = useAppSelector((state) => state.jobs.runningJobIds); const { projectId } = useParams(); + // Scenario + const { scenarioItems } = useScenarioItems(projectId as string); + const [selectedScenario, setSelectedScenario] = useState(undefined); + const _handleReset = () => { dispatch(setMaskLayer(undefined)); setSelectedRouting(undefined); + setSelectedScenario(undefined); handleConfigurationReset && handleConfigurationReset(); handleReset && handleReset(); }; @@ -102,6 +109,10 @@ const HeatmapContainer = ({ routing_type: selectedRouting?.value, ...payload, }; + if (selectedScenario) { + _payload.scenario_id = selectedScenario.value; + } + let heatmap_type = `${type}_active_mobility`; if (selectedRouting?.value === HeatmapRoutingTypeEnum.Enum.public_transport) { heatmap_type = `${type}_pt`; @@ -203,6 +214,32 @@ const HeatmapContainer = ({ {opportunitiesChildren}} /> )} + + {/* 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 d8162509..62e1c9f3 100644 --- a/apps/web/lib/validations/tools.ts +++ b/apps/web/lib/validations/tools.ts @@ -231,6 +231,7 @@ export const nearbyStationsSchema = z.object({ max_traveltime: z.number().min(1).max(15), mode: z.array(PTRoutingModes), time_window: ptTimeWindow, + scenario_id: z.string().optional(), }); export type PostNearbyStations = z.infer; @@ -248,6 +249,7 @@ export const heatmapGravitySchema = z.object({ }) ), routing_type: HeatmapRoutingTypeEnum, + scenario_id: z.string().optional(), }); export type PostHeatmapGravity = z.infer; @@ -262,6 +264,7 @@ export const heatmapClosestAverageSchema = z.object({ }) ), routing_type: HeatmapRoutingTypeEnum, + scenario_id: z.string().optional() }); export type PostHeatmapClosestAverage = z.infer; @@ -271,6 +274,7 @@ export const heatmapConnectivitySchema = z.object({ reference_area_layer_project_id: z.number(), max_traveltime: z.number().min(1).max(60), routing_type: HeatmapRoutingTypeEnum, + scenario_id: z.string().optional() }); export type PostHeatmapConnectivity = z.infer;