Skip to content

Commit

Permalink
fix: edge_project_layer_id for scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
majkshkurti committed Sep 20, 2024
1 parent 8a5764d commit 88ec710
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
computePTCatchmentArea,
} from "@/lib/api/catchmentArea";
import { useJobs } from "@/lib/api/jobs";
import { useProjectLayers } from "@/lib/api/projects";
import { STREET_NETWORK_LAYER_ID } from "@/lib/constants";
import { setRunningJobIds } from "@/lib/store/jobs/slice";
import {
Expand Down Expand Up @@ -71,6 +72,8 @@ const CatchmentArea = ({ onBack, onClose }: IndicatorBaseProps) => {
const runningJobIds = useAppSelector((state) => state.jobs.runningJobIds);
const [isBusy, setIsBusy] = useState(false);

const { layers: projectLayers } = useProjectLayers((projectId as string) || "");

// Routing
const { routingTypes, selectedRouting, setSelectedRouting } = useRoutingTypes();

Expand Down Expand Up @@ -216,6 +219,12 @@ const CatchmentArea = ({ onBack, onClose }: IndicatorBaseProps) => {
// Scenario
const { scenarioItems } = useScenarioItems(projectId as string);
const [selectedScenario, setSelectedScenario] = useState<SelectorItem | undefined>(undefined);
const scenarioNetworkSystemLayer = useMemo(() => {
if (projectLayers) {
return projectLayers.find((layer) => layer.layer_id === STREET_NETWORK_LAYER_ID);
}
return undefined;
}, [projectLayers]);

const handleReset = () => {
dispatch(setMaskLayer(undefined));
Expand All @@ -230,14 +239,13 @@ const CatchmentArea = ({ onBack, onClose }: IndicatorBaseProps) => {
const payload = {
catchment_area_type: catchmentAreaShapeType.value,
};

if (selectedScenario?.value) {
payload["scenario_id"] = selectedScenario?.value;
// todo: Set street network layer for scenario.
// At the moment this is hardcoded.
// Eventually, users should be able to upload their own street network layer which can be used for scenarios.
payload["street_network"] = {
edge_layer_project_id: STREET_NETWORK_LAYER_ID,
edge_layer_project_id: scenarioNetworkSystemLayer?.id,
};
}

Expand Down Expand Up @@ -555,7 +563,7 @@ const CatchmentArea = ({ onBack, onClose }: IndicatorBaseProps) => {
/>
{/* SCENARIO */}
<SectionHeader
active={isRoutingValid}
active={isRoutingValid && !!scenarioNetworkSystemLayer}
alwaysActive={true}
label={t("scenario")}
icon={ICON_NAME.SCENARIO}
Expand All @@ -566,6 +574,7 @@ const CatchmentArea = ({ onBack, onClose }: IndicatorBaseProps) => {
baseOptions={
<>
<Selector
disabled={!scenarioNetworkSystemLayer}
selectedItems={selectedScenario}
setSelectedItems={(item: SelectorItem[] | SelectorItem | undefined) => {
setSelectedScenario(item as SelectorItem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ICON_NAME } from "@p4b/ui/components/Icon";
import { useTranslation } from "@/i18n/client";

import { useJobs } from "@/lib/api/jobs";
import { useProjectLayers } from "@/lib/api/projects";
import { computeNearbyStations } from "@/lib/api/tools";
import { STREET_NETWORK_LAYER_ID } from "@/lib/constants";
import { setRunningJobIds } from "@/lib/store/jobs/slice";
Expand Down Expand Up @@ -52,6 +53,7 @@ const NearbyStations = ({ onBack, onClose }: IndicatorBaseProps) => {
const startingPoints = useAppSelector((state) => state.map.toolboxStartingPoints);
const runningJobIds = useAppSelector((state) => state.jobs.runningJobIds);
const { projectId } = useParams();
const { layers: projectLayers } = useProjectLayers((projectId as string) || "");

useEffect(() => {
if (projectId) {
Expand Down Expand Up @@ -121,6 +123,12 @@ const NearbyStations = ({ onBack, onClose }: IndicatorBaseProps) => {
// Scenario
const { scenarioItems } = useScenarioItems(projectId as string);
const [selectedScenario, setSelectedScenario] = useState<SelectorItem | undefined>(undefined);
const scenarioNetworkSystemLayer = useMemo(() => {
if (projectLayers) {
return projectLayers.find((layer) => layer.layer_id === STREET_NETWORK_LAYER_ID);
}
return undefined;
}, [projectLayers]);

const handleRun = async () => {
const payload = {
Expand All @@ -140,7 +148,7 @@ const NearbyStations = ({ onBack, onClose }: IndicatorBaseProps) => {
// At the moment this is hardcoded.
// Eventually, users should be able to upload their own street network layer which can be used for scenarios.
payload["street_network"] = {
edge_layer_project_id: STREET_NETWORK_LAYER_ID,
edge_layer_project_id: scenarioNetworkSystemLayer?.id,
};
}
if (startingPointMethod.value === "map") {
Expand Down Expand Up @@ -321,7 +329,7 @@ const NearbyStations = ({ onBack, onClose }: IndicatorBaseProps) => {

{/* SCENARIO */}
<SectionHeader
active={isValid}
active={isValid && !!scenarioNetworkSystemLayer}
alwaysActive={true}
label={t("scenario")}
icon={ICON_NAME.SCENARIO}
Expand All @@ -333,6 +341,7 @@ const NearbyStations = ({ onBack, onClose }: IndicatorBaseProps) => {
<>
<Selector
selectedItems={selectedScenario}
disabled={!scenarioNetworkSystemLayer}
setSelectedItems={(item: SelectorItem[] | SelectorItem | undefined) => {
setSelectedScenario(item as SelectorItem);
}}
Expand Down

0 comments on commit 88ec710

Please sign in to comment.