Skip to content

Commit

Permalink
front: fix errors after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
RomainValls committed Jun 24, 2024
1 parent 0ca3a64 commit de1e59c
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 61 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useMemo, useState } from 'react';

import { compact } from 'lodash';
import { useTranslation } from 'react-i18next';
import { useSelector } from 'react-redux';

Expand Down Expand Up @@ -100,22 +99,6 @@ const ManageTrainScheduleV2 = () => {
}));
}, [pathProperties]);

// const trackSections = pathProperties?.trackSectionRanges || [];

// const [cumulativeSums, setCumulativeSums] = useState<number[]>([]);

// useEffect(() => {
// if (trackSections.length > 0) {
// const cumulative = trackSections.reduce((acc, section) => {
// const lastSum = acc.length > 0 ? acc[acc.length - 1] : 0;
// acc.push(lastSum + section.end);
// return acc;
// }, []);

// setCumulativeSums(cumulative);
// }
// }, [trackSections]);

// TODO TS2 : test this hook in simulation results issue
// useSetupItineraryForTrainUpdate(setPathProperties);

Expand Down Expand Up @@ -217,14 +200,15 @@ const ManageTrainScheduleV2 = () => {
/>
</div>
</div>
*/}
{rollingStock && isElectric(rollingStock.effort_curves.modes) && (
<PowerRestrictionsSelectorV2
rollingStockModes={rollingStock.effort_curves.modes}
rollingStockPowerRestrictions={rollingStock.power_restrictions}
pathElectrificationRanges={initialPowerRestrictions}
pathProperties={pathProperties}
/>
)} */}
)}
</div>
),
};
Expand Down
1 change: 1 addition & 0 deletions front/src/applications/stdcm/views/StdcmViewV1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const StdcmViewV1 = () => {
suggestedOperationalPoints: updatedSuggestedOPs,
allVias: updatedSuggestedOPs,
length: path.length,
trackSectionRanges: path.track_section_ranges,
});
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect, useReducer, useMemo } from 'react';
import React, { useState, useEffect, useReducer } from 'react';

import { Alert, CheckCircle, Stop } from '@osrd-project/ui-icons';
import cx from 'classnames';
Expand Down Expand Up @@ -150,15 +150,13 @@ const Pathfinding = ({ pathProperties, setPathProperties }: PathfindingProps) =>
getInfraID,
getOriginV2,
getDestinationV2,
getViasV2,
getPathSteps,
// getPowerRestrictionRanges,
// getAllowances,
} = useOsrdConfSelectors();
const infraId = useSelector(getInfraID, isEqual);
const origin = useSelector(getOriginV2, isEqual);
const destination = useSelector(getDestinationV2, isEqual);
const vias = useSelector(getViasV2(), isEqual);
const pathSteps = useSelector(getPathSteps);
const { rollingStock } = useStoreDataForRollingStockSelector();
// TODO TS2 : update this parts in margins and powerrestriction issues
Expand Down Expand Up @@ -190,7 +188,6 @@ const Pathfinding = ({ pathProperties, setPathProperties }: PathfindingProps) =>
pollingInterval: !isInfraLoaded ? 1000 : undefined,
}
);
const pathfindingAlReadyInitialized = useMemo(() => infra?.state === 'CACHED', []);

const [reloadInfra] = osrdEditoastApi.endpoints.postInfraByInfraIdLoad.useMutation();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect, useMemo, useState } from 'react';

import { Alert } from '@osrd-project/ui-icons';
import { compact, isEmpty, keyBy, last, type Dictionary } from 'lodash';
import { compact, isEmpty, keyBy, last } from 'lodash';
import { useTranslation } from 'react-i18next';
import nextId from 'react-id-generator';
import { useSelector } from 'react-redux';
Expand All @@ -14,15 +14,14 @@ 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 type { PowerRestrictionWarning } from 'modules/powerRestriction/types';
// import type { PathStep } from 'reducers/osrdconf/types';
import { useAppDispatch } from 'store';
import { getPointCoordinates } from 'utils/geometry';

import { NO_POWER_RESTRICTION } from '../consts';
import createPathStep from '../helpers/createPathStep';
import formatPowerRestrictions from '../helpers/formatPowerRestrictions';
import { getPowerRestrictionsWarnings, countWarnings } from '../helpers/powerRestrictionSelector';
import { getPowerRestrictionsWarnings, countWarnings } from '../helpers/powerRestrictionWarnings';

const DEFAULT_SEGMENT_LENGTH = 1000;

Expand Down Expand Up @@ -199,7 +198,6 @@ const PowerRestrictionsSelectorV2 = ({
dispatch(deletePowerRestrictionRangesV2({ from: fromPathStep, to: toPathStep }));
}
};
console.log('test');
const formatElectricalRanges = (
ranges: PowerRestrictionV2[]
): { begin: number; end: number; value: string }[] => {
Expand Down Expand Up @@ -233,7 +231,7 @@ const PowerRestrictionsSelectorV2 = ({
pathElectrificationRanges,
rollingStockModes
)
: ({} as Dictionary<PowerRestrictionWarning[]>),
: undefined,
[powerRestrictionRanges]
);

Expand Down Expand Up @@ -273,35 +271,39 @@ const PowerRestrictionsSelectorV2 = ({
</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>
)
)} */}
{powerRestrictionsWarnings &&
powerRestrictionsWarnings.modeNotSupportedWarnings.map(
({ begin, end, electrification }) => (
<span key={`not-handled-mode-${begin}-${end}`}>
{t('warningMessages.modeNotHandled', { begin, end, electrification })}
</span>
)
)}

{powerRestrictionsWarnings &&
Object.values(powerRestrictionsWarnings.invalidCombinationWarnings).map(
({ powerRestrictionCode, electrification, begin, end }) => (
<span key={`${powerRestrictionCode}-${begin}-${end}`}>
{t('warningMessages.powerRestrictionInvalidCombination', {
powerRestrictionCode,
electrification,
begin,
end,
})}
</span>
)
)}
{powerRestrictionsWarnings &&
powerRestrictionsWarnings.missingPowerRestrictionWarnings.map(
({ begin, end }) => (
<span key={`missing-power-restriction-${begin}-${end}`}>
{t('warningMessages.missingPowerRestriction', {
begin,
end,
})}
</span>
)
)}
</div>
</div>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable import/prefer-default-export */
import { isEmpty, keyBy, sortBy } from 'lodash';

import type { PowerRestrictionV2 } from 'applications/operationalStudies/consts';
import type { IntervalItem } from 'common/IntervalsEditor/types';
import { isEmpty, keyBy, sortBy } from 'lodash';
import type { PathStep } from 'reducers/osrdconf/types';

const formatPowerRestrictions = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ export default function commonConfBuilder() {
suggestedOperationalPoints: [],
allVias: [],
length: 1169926000,
trackSectionRanges: [],
}),
};
}
6 changes: 2 additions & 4 deletions front/src/reducers/osrdconf/osrdConfCommon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import nextId from 'react-id-generator';
import type { PointOnMap, PowerRestrictionV2 } from 'applications/operationalStudies/consts';
import type { ManageTrainSchedulePathProperties } from 'applications/operationalStudies/types';
import { isVia } from 'modules/pathfinding/utils';
import { NO_POWER_RESTRICTION } from 'modules/powerRestriction/consts';
import type { SuggestedOP } from 'modules/trainschedule/components/ManageTrainSchedule/types';
import { type InfraStateReducers, buildInfraStateReducers, infraState } from 'reducers/infra';
import { computeLinkedOriginTimes, insertVia, insertViaFromMap } from 'reducers/osrdconf/helpers';
Expand All @@ -20,7 +21,6 @@ import type { OsrdConfState, PathStep } from 'reducers/osrdconf/types';
import { addElementAtIndex, removeElementAtIndex, replaceElementAtIndex } from 'utils/array';
import { formatIsoDate } from 'utils/date';
import type { ArrayElement } from 'utils/types';
import NO_POWER_RESTRICTION from 'modules/powerRestriction/consts';

export const defaultCommonConf: OsrdConfState = {
constraintDistribution: 'MARECO',
Expand Down Expand Up @@ -361,9 +361,7 @@ export function buildCommonConfReducers<S extends OsrdConfState>(): CommonConfRe
) {
const { from, to, code } = action.payload;
let newPathSteps = [...state.pathSteps];
console.log(newPathSteps, 'newPathSteps');
const pathIds = compact(state.pathSteps).map((step) => step.id);
console.log(pathIds, 'pathIds');

// verifier que to.id est dans pathIds et pareil pour le from.
if (!pathIds.includes(from.id)) {
Expand Down Expand Up @@ -453,7 +451,7 @@ export function buildCommonConfReducers<S extends OsrdConfState>(): CommonConfRe
);

const checkValidPathStep = (pathStep: PathStep) => {
if (!pathStep || pathStep.locked || pathStep.arrival || pathStep.stop_for) return false;
if (!pathStep || pathStep.locked || pathStep.arrival || pathStep.stopFor) return false;
return true;
};

Expand Down

0 comments on commit de1e59c

Please sign in to comment.