Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

front: editor - avoid API calls when no infra is selected #6734

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions front/src/applications/editor/Map.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useContext, useMemo, useState, type PropsWithChildren } from 'react';
import ReactMapGL, { AttributionControl, ScaleControl, type MapRef } from 'react-map-gl/maplibre';
import { isEmpty, isEqual } from 'lodash';
import { isEmpty, isEqual, isNil } from 'lodash';
import { TFunction } from 'i18next';
import { useSelector } from 'react-redux';
import { withTranslation } from 'react-i18next';
Expand Down Expand Up @@ -329,7 +329,7 @@ const MapUnplugged = ({
/>

{/* Tool specific layers */}
{activeTool.layersComponent && mapRef.current && (
{!isNil(infraID) && activeTool.layersComponent && mapRef.current && (
<activeTool.layersComponent map={mapRef.current.getMap()} />
)}
{mapSearchMarker && <SearchMarker data={mapSearchMarker} colors={colors[mapStyle]} />}
Expand Down
9 changes: 5 additions & 4 deletions front/src/applications/editor/components/LayersModal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { FC, useEffect, useMemo, useState } from 'react';
import { useSelector } from 'react-redux';
import { groupBy, mapKeys, mapValues, sum, isString, isArray, uniq } from 'lodash';
import { groupBy, mapKeys, mapValues, sum, isString, isArray, uniq, isNil } from 'lodash';
import { useTranslation } from 'react-i18next';
import { MdSpeed } from 'react-icons/md';
import { GiElectric } from 'react-icons/gi';
Expand Down Expand Up @@ -62,9 +62,10 @@ const LayersModal: FC<LayersModalProps> = ({
const [selectedLayers, setSelectedLayers] = useState<Set<Layer>>(initialLayers);
const infraID = useInfraID();

const { data: speedLimitTags } = osrdEditoastApi.endpoints.getInfraByIdSpeedLimitTags.useQuery({
id: infraID as number,
});
const { data: speedLimitTags } = osrdEditoastApi.endpoints.getInfraByIdSpeedLimitTags.useQuery(
{ id: infraID as number },
{ skip: isNil(infraID) }
);
const DEFAULT_SPEED_LIMIT_TAG = useMemo(() => t('map-settings:noSpeedLimitByTag'), [t]);
const selectionCounts = useMemo(
() =>
Expand Down
Loading