Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import type { ExtendedEditorContextType, PartialOrReducer } from 'applications/e
import { osrdEditoastApi } from 'common/api/osrdEditoastApi';
import CheckboxRadioSNCF from 'common/BootstrapSNCF/CheckboxRadioSNCF';
import { useInfraID } from 'common/osrdContext';
import useSpeedLimitTags from 'common/SpeedLimitByTagSelector/useSpeedLimitTags';
import useSpeedLimitTags from 'common/SpeedLimitTagSelector/useSpeedLimitTags';
import { isEmptyArray, toggleElement } from 'utils/array';

import SwitchList from './SwitchList';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type {
TrainCategory,
} from 'common/api/osrdEditoastApi';
import { useOsrdConfActions } from 'common/osrdContext';
import useSpeedLimitTags from 'common/SpeedLimitByTagSelector/useSpeedLimitTags';
import useSpeedLimitTags from 'common/SpeedLimitTagSelector/useSpeedLimitTags';
import useStoreDataForRollingStockSelector from 'modules/rollingStock/components/RollingStockSelector/useStoreDataForRollingStockSelector';
import isMainCategory from 'modules/rollingStock/helpers/category';
import useCategoryOptions from 'modules/rollingStock/hooks/useCategoryOptions';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import simulationSettings from 'assets/pictures/components/simulationSettings.sv
import rollingStockPic from 'assets/pictures/components/train.svg';
import { type Comfort } from 'common/api/osrdEditoastApi';
import { useOsrdConfActions } from 'common/osrdContext';
import useSpeedLimitTags from 'common/SpeedLimitByTagSelector/useSpeedLimitTags';
import useSpeedLimitTags from 'common/SpeedLimitTagSelector/useSpeedLimitTags';
import { useSubCategoryContext } from 'common/SubCategoryContext';
import Tabs from 'common/Tabs';
import IncompatibleConstraints from 'modules/pathfinding/components/IncompatibleConstraints';
Expand Down Expand Up @@ -62,7 +62,7 @@ const ManageTimetableItem = () => {
const origin = useSelector(getOrigin);
const destination = useSelector(getDestination);
const pathSteps = useSelector(getPathSteps);
const speedLimitByTag = useSelector(getOperationalStudiesSpeedLimitByTag);
const selectedSpeedLimitTag = useSelector(getOperationalStudiesSpeedLimitByTag);
const rollingStockId = useSelector(getOperationalStudiesRollingStockID);
const currentCategory = useSelector(getCategory);

Expand Down Expand Up @@ -214,9 +214,9 @@ const ManageTimetableItem = () => {
content: (
<div>
<SimulationSettings
selectedSpeedLimitByTag={speedLimitByTag}
selectedSpeedLimitTag={selectedSpeedLimitTag}
speedLimitTags={speedLimitTags}
dispatchUpdateSpeedLimitByTag={onSelectSpeedLimitTag}
updateSpeedLimitTag={onSelectSpeedLimitTag}
constraintDistribution={constraintDistribution}
/>
{rollingStock && isElectric(rollingStock.effort_curves.modes) && pathProperties && (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import type { Distribution } from 'common/api/osrdEditoastApi';
import SpeedLimitByTagSelector from 'common/SpeedLimitByTagSelector';
import SpeedLimitTagSelector from 'common/SpeedLimitTagSelector';

import ConstraintDistributionSwitch from './ConstraintDistributionSwitch';
import ElectricalProfiles from './ElectricalProfiles';

type Props = {
selectedSpeedLimitByTag?: string;
selectedSpeedLimitTag?: string;
speedLimitTags: string[];
dispatchUpdateSpeedLimitByTag: (newTag: string | null) => void;
updateSpeedLimitTag: (newTag: string | null) => void;
constraintDistribution: Distribution;
};

const SimulationSettings = ({
selectedSpeedLimitByTag: speedLimitByTag,
selectedSpeedLimitTag,
speedLimitTags,
dispatchUpdateSpeedLimitByTag,
updateSpeedLimitTag,
constraintDistribution,
}: Props) => (
<div className="simulation-settings">
Expand All @@ -23,10 +23,10 @@ const SimulationSettings = ({
<ConstraintDistributionSwitch constraintDistribution={constraintDistribution} />
</div>
<div className="second-row">
<SpeedLimitByTagSelector
selectedSpeedLimitByTag={speedLimitByTag}
<SpeedLimitTagSelector
selectedSpeedLimitTag={selectedSpeedLimitTag}
speedLimitTags={speedLimitTags}
dispatchUpdateSpeedLimitByTag={dispatchUpdateSpeedLimitByTag}
updateSpeedLimitTag={updateSpeedLimitTag}
showPlaceHolder
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import type {
LoadingGaugeType,
} from 'common/api/osrdEditoastApi';
import { useOsrdConfActions } from 'common/osrdContext';
import SpeedLimitByTagSelector from 'common/SpeedLimitByTagSelector';
import SpeedLimitTagSelector from 'common/SpeedLimitTagSelector';
import RollingStock2Img from 'modules/rollingStock/components/RollingStock2Img';
import { useStoreDataForRollingStockSelector } from 'modules/rollingStock/components/RollingStockSelector/useStoreDataForRollingStockSelector';
import useFilterRollingStock from 'modules/rollingStock/hooks/useFilterRollingStock';
Expand Down Expand Up @@ -83,11 +83,11 @@ const StdcmConsist = ({
}: StdcmConsistProps) => {
const { t } = useTranslation('stdcm');

const speedLimitByTag = useSelector(getStdcmSpeedLimitByTag);
const selectedSpeedLimitTag = useSelector(getStdcmSpeedLimitByTag);
const speedLimitsByTag = useSelector(getStdcmSpeedLimitsByTag);
const speedLimitTags = useMemo(
() => removeDuplicates(Object.keys(speedLimitsByTag)).sort(),
[speedLimitByTag]
[speedLimitsByTag]
);
const trackSectionIdsByLoadingGauge = useSelector(getTrackSectionIdsByLoadingGauge);
const loadingGauges = trackSectionIdsByLoadingGauge
Expand Down Expand Up @@ -160,7 +160,7 @@ const StdcmConsist = ({
);

const handleRollingStockSelect = (option?: LightRollingStockWithLiveries) => {
prefillConsist(option, towedRollingStock, speedLimitByTag);
prefillConsist(option, towedRollingStock, selectedSpeedLimitTag);
dispatch(updateRollingStockID(option?.id));
setStatusMessagesVisible({
mass: true,
Expand All @@ -169,7 +169,7 @@ const StdcmConsist = ({
});
};

const onSpeedLimitByTagChange = (newTag: string | null) => {
const onSpeedLimitTagChange = (newTag: string | null) => {
dispatch(
updateMaxSpeed(
calculateConsistMaxSpeed(
Expand Down Expand Up @@ -277,7 +277,7 @@ const StdcmConsist = ({
value={towedRollingStock}
getSuggestionLabel={(suggestion: TowedRollingStock) => suggestion.name}
onSelectSuggestion={(towed) => {
prefillConsist(rollingStock, towed, speedLimitByTag);
prefillConsist(rollingStock, towed, selectedSpeedLimitTag);
dispatch(updateTowedRollingStockID(towed?.id));
}}
{...towedRollingStockComboBoxDefaultProps}
Expand Down Expand Up @@ -342,11 +342,11 @@ const StdcmConsist = ({
/>
</div>
<div className="stdcm-consist__properties">
<SpeedLimitByTagSelector
<SpeedLimitTagSelector
disabled={disabled}
selectedSpeedLimitByTag={speedLimitByTag}
selectedSpeedLimitTag={selectedSpeedLimitTag}
speedLimitTags={speedLimitTags}
dispatchUpdateSpeedLimitByTag={onSpeedLimitByTagChange}
updateSpeedLimitTag={onSpeedLimitTagChange}
showPlaceHolder={isDebugMode}
narrow
/>
Expand Down
2 changes: 1 addition & 1 deletion front/src/common/Map/components/LayersModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import SwitchSNCF from 'common/BootstrapSNCF/SwitchSNCF/SwitchSNCF';
import MapSettingsBackgroundSwitches from 'common/Map/Settings/MapSettingsBackgroundSwitches';
import { Icon2SVG } from 'common/Map/Settings/MapSettingsLayers';
import MapSettingsMapStyle from 'common/Map/Settings/MapSettingsMapStyle';
import useSpeedLimitTags from 'common/SpeedLimitByTagSelector/useSpeedLimitTags';
import useSpeedLimitTags from 'common/SpeedLimitTagSelector/useSpeedLimitTags';
import type { LayersSettings } from 'reducers/commonMap/types';

import { useMapContext } from '../useMapContext';
Expand Down
3 changes: 0 additions & 3 deletions front/src/common/SpeedLimitByTagSelector/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,41 +1,33 @@
import { useMemo } from 'react';

import { Select } from '@osrd-project/ui-core';
import cx from 'classnames';
import { isEmpty } from 'lodash';
import { useTranslation } from 'react-i18next';

import { createStandardSelectOptions } from 'utils/uiCoreHelpers';

type SpeedLimitByTagSelectorProps = {
type SpeedLimitTagSelectorProps = {
condensed?: boolean;
disabled?: boolean;
selectedSpeedLimitByTag?: string;
selectedSpeedLimitTag?: string;
speedLimitTags: string[];
dispatchUpdateSpeedLimitByTag: (newTag: string | null) => void;
updateSpeedLimitTag: (newTag: string | null) => void;
className?: string;
showPlaceHolder?: boolean;
narrow?: boolean;
};

export default function SpeedLimitByTagSelector({
const SpeedLimitTagSelector = ({
condensed = false,
disabled = false,
selectedSpeedLimitByTag: speedLimitByTag,
selectedSpeedLimitTag: speedLimitTag,
speedLimitTags,
dispatchUpdateSpeedLimitByTag,
updateSpeedLimitTag,
className = '',
showPlaceHolder = false,
narrow = false,
}: SpeedLimitByTagSelectorProps) {
}: SpeedLimitTagSelectorProps) => {
const { t } = useTranslation('operational-studies', { keyPrefix: 'manageTimetableItem' });

const speedLimitsTagsList = useMemo(
() => (!isEmpty(speedLimitTags) ? speedLimitTags : []),
[speedLimitTags]
);

if (!speedLimitsTagsList.length) return null;
if (!speedLimitTags.length) return null;
return (
<div className="osrd-config-item">
<div
Expand All @@ -49,21 +41,23 @@ export default function SpeedLimitByTagSelector({
<Select
disabled={disabled}
id="speed-limit-by-tag-selector"
value={speedLimitByTag || ''}
value={speedLimitTag || ''}
label={t('speedLimitByTagAbbrev')}
// The placeHolder is only displayed in operationalStudies and in debug mode in stdcm
placeholder={showPlaceHolder ? t('noSpeedLimitByTag') : undefined}
onChange={(e) => {
if (e) {
dispatchUpdateSpeedLimitByTag(e);
updateSpeedLimitTag(e);
} else {
dispatchUpdateSpeedLimitByTag(null);
updateSpeedLimitTag(null);
}
}}
{...createStandardSelectOptions(speedLimitsTagsList)}
{...createStandardSelectOptions(speedLimitTags)}
narrow={narrow}
/>
</div>
</div>
);
}
};

export default SpeedLimitTagSelector;
3 changes: 3 additions & 0 deletions front/src/common/SpeedLimitTagSelector/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import SpeedLimitTagSelector from './SpeedLimitTagSelector';

export default SpeedLimitTagSelector;
2 changes: 1 addition & 1 deletion front/src/common/common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
@use './Loaders/Loader.scss';
@use './Map/MapKey.scss';
@use './Notifications/Notifications.scss';
@use './SpeedLimitByTagSelector/SpeedLimitByTagSelector.scss';
@use './SpeedLimitTagSelector/SpeedLimitTagSelector.scss';