Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Akctarus committed Jul 5, 2024
1 parent 78875fd commit 7f1244d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
2 changes: 1 addition & 1 deletion front/src/applications/stdcmV2/components/StdcmConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const StdcmConfig = ({
disabled={isPending}
setCurrentSimulationInputs={setCurrentSimulationInputs}
/>
<StdcmVias disabled={isPending} />
<StdcmVias disabled={isPending} setCurrentSimulationInputs={setCurrentSimulationInputs} />
<StdcmDestination
disabled={isPending}
setCurrentSimulationInputs={setCurrentSimulationInputs}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ const StcdmTableResults = ({
>
<Button
label={t('downloadSimulationSheet')}
/* TODO: make the button clickable again when the simulation sheet is modified*/
/* TODO: make the button clickable again when the simulation sheet is modified */
isDisabled
/>
</PDFDownloadLink>
Expand Down
42 changes: 23 additions & 19 deletions front/src/applications/stdcmV2/components/StdcmVias.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo } from 'react';
import React, { useEffect, useMemo } from 'react';

import { Location } from '@osrd-project/ui-icons';
import { useTranslation } from 'react-i18next';
Expand All @@ -13,14 +13,18 @@ import { addElementAtIndex, replaceElementAtIndex } from 'utils/array';
import { formatDurationAsISO8601 } from 'utils/timeManipulation';

import StdcmCard from './StdcmCard';
import StdcmDefaultCard from './StdcmDefaultCard';
import StdcmInputVia from './StdcmInputVia';
import StdcmOperationalPoint from './StdcmOperationalPoint';
import type { StdcmConfigCardProps } from '../types';

const StdcmVias = ({ disabled = false }: { disabled?: boolean }) => {
const StdcmVias = ({ disabled = false, setCurrentSimulationInputs }: StdcmConfigCardProps) => {
const { t } = useTranslation('stdcm');
const dispatch = useAppDispatch();
const { getPathSteps } = useOsrdConfSelectors();
const { updatePathSteps, updateViaStopTimeV2 } = useOsrdConfActions() as StdcmConfSliceActions;
const { deleteViaV2, updatePathSteps, updateViaStopTimeV2 } =
useOsrdConfActions() as StdcmConfSliceActions;
useOsrdConfActions() as StdcmConfSliceActions;
const pathSteps = useSelector(getPathSteps);

const intermediatePoints = useMemo(() => pathSteps.slice(1, -1), [pathSteps]);
Expand All @@ -41,14 +45,18 @@ const StdcmVias = ({ disabled = false }: { disabled?: boolean }) => {
);
};

useEffect(() => {
setCurrentSimulationInputs((prevState) => ({
...prevState,
pathSteps,
}));
}, [pathSteps]);

return (
<div className="stdcm-v2-vias-list">
{intermediatePoints.length > 0 &&
intermediatePoints.map((pathStep, index) => {
const pathStepId = index + 1;
function deleteViaV2(index: number): any {
throw new Error('Function not implemented.');
}

return (
<StdcmCard
Expand Down Expand Up @@ -83,19 +91,15 @@ const StdcmVias = ({ disabled = false }: { disabled?: boolean }) => {
</StdcmCard>
);
})}
<StdcmCard hasTip disabled={disabled}>
<button
type="button"
onClick={() => {
dispatch(updatePathSteps(addElementAtIndex(pathSteps, pathSteps.length - 1, null)));
}}
>
<span className="stdcm-v2-add-via-icon">
<Location size="lg" variant="base" />
</span>
<span className="stdcm-v2-add-via__button pl-3">{t('trainPath.addVia')}</span>
</button>
</StdcmCard>
<StdcmDefaultCard
hasTip
text={t('trainPath.addVia')}
Icon={<Location size="lg" variant="base" />}
onClick={() => {
const newPathSteps = addElementAtIndex(pathSteps, pathSteps.length - 1, null);
dispatch(updatePathSteps(newPathSteps));
}}
/>
</div>
);
};
Expand Down

0 comments on commit 7f1244d

Please sign in to comment.