Skip to content

Commit

Permalink
front: fix power restriction selector when rs does not handle electri…
Browse files Browse the repository at this point in the history
…fication mode
  • Loading branch information
clarani committed Jun 20, 2024
1 parent 0a4a81d commit c57458e
Show file tree
Hide file tree
Showing 13 changed files with 283 additions and 167 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
"inconsistent_other": "The intervals below contain inconsistencies. The default speed effort curves will be used for these.",
"powerRestrictionInvalidCombination": "- {{powerRestrictionCode}} is incompatible with electrification {{electrification}} of the path between {{begin}}m and {{end}}m",
"missingPowerRestriction": "- Missing power restriction between {{begin}}m and {{end}}m.",
"modeNotHandled": "- No power restriction should be given between {{begin}}m and {{end}}m since the electrification mode {{electrification}} is not handled.",
"pathfindingChange": "Pathfinding changed",
"marginsAndPowerRestrictionsReset": "Margins and power restrictions have been reset."
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
"inconsistent_other": "Plusieurs intervalles comportent des incohérences. Les courbes effort vitesse par défaut seront utilisées pour ceux-ci.",
"powerRestrictionInvalidCombination": "- Code {{powerRestrictionCode}} incompatible avec l'électrification à {{electrification}} de l'itinéraire entre {{begin}}m et {{end}}m. ",
"missingPowerRestriction": "- Restriction de puissance manquante entre {{begin}}m et {{end}}m.",
"modeNotHandled": "- Aucune restriction de puissance ne devrait être renseignée entre {{begin}}m and {{end}}m comme le matériel roulant ne supporte pas l'électrification {{electrification}}.",
"pathfindingChange": "Changement de chemin",
"marginsAndPowerRestrictionsReset": "Les marges et les restrictions de puissance ont été réinitialisées."
}
Expand Down
13 changes: 7 additions & 6 deletions front/src/applications/operationalStudies/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import type {

/**
* Transform datas received with boundaries / values format :
* - boundaries : List of `n` boundaries of the ranges. A boundary is a distance
* from the beginning of the path in mm.
* - boundaries : List of `n` boundaries of the ranges. A boundary is a distance
* from the beginning of the path in mm.
- values : List of `n+1` values associated to the ranges.
@returns an array of PositionData with the position in meters and the associated value
depending on the kind of data provided. As the boundaries don't include the path's origin and destination
Expand Down Expand Up @@ -62,10 +62,10 @@ export const transformBoundariesDataToPositionDataArray = <T extends 'gradient'

/**
* Transform electrifications received with boundaries / values format :
* - boundaries : List of `n` boundaries of the ranges. A boundary is a distance
* from the beginning of the path in mm.
* - boundaries : List of `n` boundaries of the ranges. A boundary is a distance
* from the beginning of the path in mm.
- values : List of `n+1` values associated to the ranges.
@returns an array of electrifications ranges with the start and stop of the range in meters and
@returns an array of electrifications ranges with the start and stop of the range in meters and
the associated value. As the boundaries don't include the path's origin and destination
positions, we add them manually.
*/
Expand Down Expand Up @@ -240,7 +240,8 @@ export const formatPowerRestrictionRangesWithHandled = (
let isHandled = false;
if (
foundElectrificationRange &&
foundElectrificationRange.electrificationUsage.type === 'electrification'
foundElectrificationRange.electrificationUsage.type === 'electrification' &&
powerRestrictionsByMode[foundElectrificationRange.electrificationUsage.voltage]
) {
isHandled = powerRestrictionsByMode[
foundElectrificationRange.electrificationUsage.voltage
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect, useMemo } from 'react';

import { Alert } from '@osrd-project/ui-icons';
import { isEmpty, last, type Dictionary } from 'lodash';
import { isEmpty, last } from 'lodash';
import { useTranslation } from 'react-i18next';
import { useSelector } from 'react-redux';

Expand All @@ -12,13 +12,12 @@ import IntervalsEditor from 'common/IntervalsEditor/IntervalsEditor';
import { INTERVAL_TYPES } from 'common/IntervalsEditor/types';
import type { IntervalItem } from 'common/IntervalsEditor/types';
import { useOsrdConfActions, useOsrdConfSelectors } from 'common/osrdContext';
import NO_POWER_RESTRICTION from 'modules/powerRestriction/consts';
import { NO_POWER_RESTRICTION } from 'modules/powerRestriction/consts';
import displayPowerRestrictionIntervals from 'modules/powerRestriction/helpers/displayPowerRestrictionIntervals';
import {
countWarnings,
getPowerRestrictionsWarnings,
} from 'modules/powerRestriction/helpers/powerRestrictionSelector';
import type { PowerRestrictionWarning } from 'modules/powerRestriction/types';
} from 'modules/powerRestriction/helpers/powerRestrictionWarnings';
import { useAppDispatch } from 'store';

/** Arbitrairy default segment length (1km) */
Expand Down Expand Up @@ -57,16 +56,15 @@ const PowerRestrictionsSelector = ({
return specialPoints;
}, [pathElectrificationRanges]);

/** Format the electrification ranges to display them on the interval editor */
const formattedPathElectrificationRanges = useMemo(
() =>
pathElectrificationRanges.map((electrificationRange) => ({
begin: electrificationRange.begin,
end: electrificationRange.end,
value: `${electrificationRange.value}`,
})),
[pathElectrificationRanges]
);
/** Format the electrification ranges to display them on the interval editor. */
const formattedPathElectrificationRanges = useMemo(() => {
const handledModes = Object.keys(rollingStockModes);
return pathElectrificationRanges.map(({ begin, end, value: mode }) => ({
begin,
end,
value: handledModes.includes(mode) ? mode : '',
}));
}, [pathElectrificationRanges]);

/** Set up the powerRestrictionRanges with the electrificationChangePoints */
useEffect(() => {
Expand Down Expand Up @@ -117,7 +115,7 @@ const PowerRestrictionsSelector = ({
pathElectrificationRanges,
rollingStockModes
)
: ({} as Dictionary<PowerRestrictionWarning[]>),
: undefined,
[powerRestrictionRanges]
);

Expand All @@ -142,7 +140,7 @@ const PowerRestrictionsSelector = ({
{!isEmpty(rollingStockPowerRestrictions) ? (
<>
<p className="mb-1 mt-1">{t('powerRestrictionExplanationText')}</p>
{totalPowerRestrictionWarnings > 0 && (
{powerRestrictionsWarnings && totalPowerRestrictionWarnings > 0 && (
<div className="border border-warning rounded p-3 my-3">
<div className="d-flex align-items-center mb-2">
<div className="d-flex align-items-center text-warning">
Expand All @@ -152,29 +150,37 @@ const PowerRestrictionsSelector = ({
{t('warningMessages.inconsistent', { count: totalPowerRestrictionWarnings })}
</span>
</div>
{Object.entries(powerRestrictionsWarnings).map(
([warningCategory, warningsByCategory]) => (
<div className="d-flex flex-column" key={warningCategory}>
{warningsByCategory.map(
({ powerRestrictionCode, electrification, begin, end }) => (
<span key={`${powerRestrictionCode}-${begin}-${end}`}>
{warningCategory !== NO_POWER_RESTRICTION
? t('warningMessages.powerRestrictionInvalidCombination', {
powerRestrictionCode,
electrification,
begin,
end,
})
: t('warningMessages.missingPowerRestriction', {
begin,
end,
})}
</span>
)
)}
</div>
)
)}
<div className="d-flex flex-column">
{powerRestrictionsWarnings.modeNotSupportedWarnings.map(
({ begin, end, electrification }) => (
<span key={`not-handled-mode-${begin}-${end}`}>
{t('warningMessages.modeNotHandled', { begin, end, electrification })}
</span>
)
)}
{Object.values(powerRestrictionsWarnings.invalidCombinationWarnings).map(
({ powerRestrictionCode, electrification, begin, end }) => (
<span key={`${powerRestrictionCode}-${begin}-${end}`}>
{t('warningMessages.powerRestrictionInvalidCombination', {
powerRestrictionCode,
electrification,
begin,
end,
})}
</span>
)
)}
{powerRestrictionsWarnings.missingPowerRestrictionWarnings.map(
({ begin, end }) => (
<span key={`missing-power-restriction-${begin}-${end}`}>
{t('warningMessages.missingPowerRestriction', {
begin,
end,
})}
</span>
)
)}
</div>
</div>
)}
<IntervalsEditor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect, useMemo } from 'react';

import { Alert } from '@osrd-project/ui-icons';
import { isEmpty, last, type Dictionary } from 'lodash';
import { isEmpty, last } from 'lodash';
import { useTranslation } from 'react-i18next';
import { useSelector } from 'react-redux';

Expand All @@ -12,13 +12,12 @@ import IntervalsEditor from 'common/IntervalsEditor/IntervalsEditor';
import { INTERVAL_TYPES } from 'common/IntervalsEditor/types';
import type { IntervalItem } from 'common/IntervalsEditor/types';
import { useOsrdConfActions, useOsrdConfSelectors } from 'common/osrdContext';
import NO_POWER_RESTRICTION from 'modules/powerRestriction/consts';
import { NO_POWER_RESTRICTION } from 'modules/powerRestriction/consts';
import displayPowerRestrictionIntervals from 'modules/powerRestriction/helpers/displayPowerRestrictionIntervals';
import {
countWarnings,
getPowerRestrictionsWarnings,
} from 'modules/powerRestriction/helpers/powerRestrictionSelector';
import type { PowerRestrictionWarning } from 'modules/powerRestriction/types';
} from 'modules/powerRestriction/helpers/powerRestrictionWarnings';
import { useAppDispatch } from 'store';

/** Arbitrairy default segment length (1km) */
Expand Down Expand Up @@ -117,7 +116,7 @@ const PowerRestrictionsSelectorV2 = ({
pathElectrificationRanges,
rollingStockModes
)
: ({} as Dictionary<PowerRestrictionWarning[]>),
: undefined,
[powerRestrictionRanges]
);

Expand All @@ -142,7 +141,7 @@ const PowerRestrictionsSelectorV2 = ({
{!isEmpty(rollingStockPowerRestrictions) ? (
<>
<p className="mb-1 mt-1">{t('powerRestrictionExplanationText')}</p>
{totalPowerRestrictionWarnings > 0 && (
{powerRestrictionsWarnings && totalPowerRestrictionWarnings > 0 && (
<div className="border border-warning rounded p-3 my-3">
<div className="d-flex align-items-center mb-2">
<div className="d-flex align-items-center text-warning">
Expand All @@ -152,29 +151,37 @@ const PowerRestrictionsSelectorV2 = ({
{t('warningMessages.inconsistent', { count: totalPowerRestrictionWarnings })}
</span>
</div>
{Object.entries(powerRestrictionsWarnings).map(
([warningCategory, warningsByCategory]) => (
<div className="d-flex flex-column" key={warningCategory}>
{warningsByCategory.map(
({ powerRestrictionCode, electrification, begin, end }) => (
<span key={`${powerRestrictionCode}-${begin}-${end}`}>
{warningCategory !== NO_POWER_RESTRICTION
? t('warningMessages.powerRestrictionInvalidCombination', {
powerRestrictionCode,
electrification,
begin,
end,
})
: t('warningMessages.missingPowerRestriction', {
begin,
end,
})}
</span>
)
)}
</div>
)
)}
<div className="d-flex flex-column">
{powerRestrictionsWarnings.modeNotSupportedWarnings.map(
({ begin, end, electrification }) => (
<span key={`not-handled-mode-${begin}-${end}`}>
{t('warningMessages.modeNotHandled', { begin, end, electrification })}
</span>
)
)}
{Object.values(powerRestrictionsWarnings.invalidCombinationWarnings).map(
({ powerRestrictionCode, electrification, begin, end }) => (
<span key={`${powerRestrictionCode}-${begin}-${end}`}>
{t('warningMessages.powerRestrictionInvalidCombination', {
powerRestrictionCode,
electrification,
begin,
end,
})}
</span>
)
)}
{powerRestrictionsWarnings.missingPowerRestrictionWarnings.map(
({ begin, end }) => (
<span key={`missing-power-restriction-${begin}-${end}`}>
{t('warningMessages.missingPowerRestriction', {
begin,
end,
})}
</span>
)
)}
</div>
</div>
)}
<IntervalsEditor
Expand Down
5 changes: 2 additions & 3 deletions front/src/modules/powerRestriction/consts.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
const NO_POWER_RESTRICTION = 'NO_POWER_RESTRICTION';

export default NO_POWER_RESTRICTION;
// eslint-disable-next-line import/prefer-default-export
export const NO_POWER_RESTRICTION = 'NO_POWER_RESTRICTION';
Loading

0 comments on commit c57458e

Please sign in to comment.