Skip to content

Commit

Permalink
feat: add scenario_id to heatmap tools
Browse files Browse the repository at this point in the history
  • Loading branch information
majkshkurti committed Jul 30, 2024
1 parent b8d7913 commit be35935
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -78,16 +78,23 @@ const HeatmapContainer = ({
return isValid;
}, [isValid, selectedRouting]);

// const [selectedScenario, setSelectedScenario] = useState<SelectorItem | undefined>(undefined);

const { mutate } = useJobs({
read: false,
});
const dispatch = useAppDispatch();
const runningJobIds = useAppSelector((state) => state.jobs.runningJobIds);
const { projectId } = useParams();

// Scenario
const { scenarioItems } = useScenarioItems(projectId as string);
const [selectedScenario, setSelectedScenario] = useState<SelectorItem | undefined>(undefined);

const _handleReset = () => {
dispatch(setMaskLayer(undefined));
setSelectedRouting(undefined);
setSelectedScenario(undefined);
handleConfigurationReset && handleConfigurationReset();
handleReset && handleReset();
};
Expand All @@ -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`;
Expand Down Expand Up @@ -203,6 +214,32 @@ const HeatmapContainer = ({
<SectionOptions active={_isValid} baseOptions={<>{opportunitiesChildren}</>} />
</>
)}

{/* SCENARIO */}
<SectionHeader
active={_isValid}
alwaysActive={true}
label={t("scenario")}
icon={ICON_NAME.SCENARIO}
disableAdvanceOptions={true}
/>
<SectionOptions
active={_isValid}
baseOptions={
<>
<Selector
selectedItems={selectedScenario}
setSelectedItems={(item: SelectorItem[] | SelectorItem | undefined) => {
setSelectedScenario(item as SelectorItem);
}}
items={scenarioItems}
label={t("scenario")}
placeholder={t("select_scenario")}
tooltip={t("choose_scenario")}
/>
</>
}
/>
</Box>
</>
}
Expand Down
4 changes: 4 additions & 0 deletions apps/web/lib/validations/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof nearbyStationsSchema>;
Expand All @@ -248,6 +249,7 @@ export const heatmapGravitySchema = z.object({
})
),
routing_type: HeatmapRoutingTypeEnum,
scenario_id: z.string().optional(),
});

export type PostHeatmapGravity = z.infer<typeof heatmapGravitySchema>;
Expand All @@ -262,6 +264,7 @@ export const heatmapClosestAverageSchema = z.object({
})
),
routing_type: HeatmapRoutingTypeEnum,
scenario_id: z.string().optional()
});

export type PostHeatmapClosestAverage = z.infer<typeof heatmapClosestAverageSchema>;
Expand All @@ -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<typeof heatmapConnectivitySchema>;

0 comments on commit be35935

Please sign in to comment.