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: drop ViaStopDurationSelector #10195

Merged
merged 1 commit into from
Dec 30, 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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { useState } from 'react';

import { XCircle } from '@osrd-project/ui-icons';
import cx from 'classnames';
import type { Position } from 'geojson';
Expand All @@ -13,20 +11,16 @@ import { isPathStepInvalid } from 'modules/pathfinding/utils';
import { moveElement, removeElementAtIndex } from 'utils/array';
import { formatUicToCi } from 'utils/strings';

import ViaStopDurationSelector from './ViaStopDurationSelector';

type ViasProps = {
shouldManageStopDuration?: boolean;
zoomToFeaturePoint: (lngLat?: Position, id?: string) => void;
};

const Vias = ({ zoomToFeaturePoint, shouldManageStopDuration }: ViasProps) => {
const Vias = ({ zoomToFeaturePoint }: ViasProps) => {
const { t } = useTranslation('operationalStudies/manageTrainSchedule');
const { getVias, getPathSteps } = useOsrdConfSelectors();
const vias = useSelector(getVias());
const pathSteps = useSelector(getPathSteps);
const { launchPathfinding } = useManageTrainScheduleContext();
const [focusedViaId, setFocusedViaId] = useState<string>();

return (
<DragDropContext
Expand Down Expand Up @@ -80,13 +74,6 @@ const Vias = ({ zoomToFeaturePoint, shouldManageStopDuration }: ViasProps) => {
</small>
)}
</div>
{shouldManageStopDuration && (
<ViaStopDurationSelector
via={via}
focusedViaId={focusedViaId}
setFocusedViaId={setFocusedViaId}
/>
)}
<button
data-testid="delete-via-button"
className="btn btn-sm btn-only-icon btn-white ml-auto"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ import Origin from './DisplayItinerary/Origin';
import Vias from './DisplayItinerary/Vias';
import ModalSuggestedVias from './ModalSuggestedVias';

type ItineraryProps = {
shouldManageStopDuration?: boolean;
};

const Itinerary = ({ shouldManageStopDuration }: ItineraryProps) => {
const Itinerary = () => {
const { getPathSteps, getOrigin, getDestination, getPowerRestriction } = useOsrdConfSelectors();
const origin = useSelector(getOrigin);
const destination = useSelector(getDestination);
Expand Down Expand Up @@ -168,10 +164,7 @@ const Itinerary = ({ shouldManageStopDuration }: ItineraryProps) => {
<Origin zoomToFeaturePoint={zoomToFeaturePoint} />
<div className="vias-list mb-2" data-testid="itinerary-vias">
{pathSteps.length > 2 ? (
<Vias
zoomToFeaturePoint={zoomToFeaturePoint}
shouldManageStopDuration={shouldManageStopDuration}
/>
<Vias zoomToFeaturePoint={zoomToFeaturePoint} />
) : (
<small data-testid="no-waypoint-chosen-text" className="ml-4">
{t('noPlaceChosen')}
Expand Down
20 changes: 0 additions & 20 deletions front/src/reducers/osrdconf/osrdConfCommon/__tests__/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { describe, beforeEach, it, expect } from 'vitest';

import { StdcmStopTypes } from 'applications/stdcm/types';
import type { Distribution, Infra, TrainScheduleBase } from 'common/api/osrdEditoastApi';
import type { OperationalStudiesConfSlice } from 'reducers/osrdconf/operationalStudiesConf';
import { defaultCommonConf } from 'reducers/osrdconf/osrdConfCommon';
Expand Down Expand Up @@ -187,25 +186,6 @@ const testCommonConfReducers = (slice: OperationalStudiesConfSlice | StdcmConfSl
expect(state.initialSpeed).toBe(newInitialSpeed);
});

it('should handle updateViaStopTime', () => {
const pathSteps = testDataBuilder.buildPathSteps();
const via = pathSteps[1];
const store = createStore(slice, {
pathSteps,
});

store.dispatch(
slice.actions.updateViaStopTime({
via,
duration: 'PT60S',
stopType: StdcmStopTypes.SERVICE_STOP,
})
);
const state = store.getState()[slice.name];
expect(state.pathSteps[1]?.stopFor).toEqual('PT60S');
expect(state.pathSteps[1]?.stopType).toEqual('serviceStop');
});

it('should handle updateGridMarginBefore', () => {
const newGridMarginBefore = 5;
defaultStore.dispatch(slice.actions.updateGridMarginBefore(newGridMarginBefore));
Expand Down
23 changes: 1 addition & 22 deletions front/src/reducers/osrdconf/osrdConfCommon/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { CaseReducer, PayloadAction } from '@reduxjs/toolkit';
import type { Draft } from 'immer';

import { type StdcmStopTypes } from 'applications/stdcm/types';
import { type InfraStateReducers, buildInfraStateReducers, infraState } from 'reducers/infra';
import type {
OperationalStudiesConfSlice,
Expand All @@ -10,7 +9,7 @@ import type {
import type { OperationalStudiesConfSelectors } from 'reducers/osrdconf/operationalStudiesConf/selectors';
import type { StdcmConfSlice, StdcmConfSliceActions } from 'reducers/osrdconf/stdcmConf';
import type { StdcmConfSelectors } from 'reducers/osrdconf/stdcmConf/selectors';
import type { OsrdConfState, PathStep } from 'reducers/osrdconf/types';
import type { OsrdConfState } from 'reducers/osrdconf/types';

export const defaultCommonConf: OsrdConfState = {
constraintDistribution: 'MARECO',
Expand Down Expand Up @@ -54,10 +53,6 @@ interface CommonConfReducers<S extends OsrdConfState> extends InfraStateReducers
['updateRollingStockID']: CaseReducer<S, PayloadAction<S['rollingStockID']>>;
['updateSpeedLimitByTag']: CaseReducer<S, PayloadAction<S['speedLimitByTag'] | null>>;
['updateInitialSpeed']: CaseReducer<S, PayloadAction<S['initialSpeed']>>;
['updateViaStopTime']: CaseReducer<
S,
PayloadAction<{ via: PathStep; duration: string; stopType?: StdcmStopTypes }>
>;
['updateGridMarginBefore']: CaseReducer<S, PayloadAction<S['gridMarginBefore']>>;
['updateGridMarginAfter']: CaseReducer<S, PayloadAction<S['gridMarginAfter']>>;
['updatePathSteps']: CaseReducer<S, PayloadAction<S['pathSteps']>>;
Expand Down Expand Up @@ -121,22 +116,6 @@ export function buildCommonConfReducers<S extends OsrdConfState>(): CommonConfRe
updateInitialSpeed(state: Draft<S>, action: PayloadAction<S['initialSpeed']>) {
state.initialSpeed = action.payload;
},
// TODO: Change the type of duration to number. It is preferable to keep this value in seconds in the store
//* to avoid multiple conversions between seconds and ISO8601 format across the front.
updateViaStopTime(
state: Draft<S>,
action: PayloadAction<{ via: PathStep; duration: string; stopType?: StdcmStopTypes }>
) {
const {
payload: { via, duration, stopType },
} = action;
state.pathSteps = state.pathSteps.map((pathStep) => {
if (pathStep && pathStep.id === via.id) {
return { ...pathStep, stopFor: duration, stopType };
}
return pathStep;
});
},
updateGridMarginBefore(state: Draft<S>, action: PayloadAction<S['gridMarginBefore']>) {
state.gridMarginBefore = action.payload;
},
Expand Down
Loading