Skip to content

Commit

Permalink
front: fix typing of TrainScheduleImportConfig.{from,to}
Browse files Browse the repository at this point in the history
These are defined as strings, but we were passing ImportStation
objects. The type error was silenced with a "as" keyword.

We need to move the ImportStation type from StationCard to
src/applications/operationalStudies/types.ts to use it in
TrainScheduleImportConfig.

No functional change - only typing changes.

Signed-off-by: Simon Ser <[email protected]>
  • Loading branch information
emersion authored and clarani committed Nov 22, 2024
1 parent 9ad9e0c commit 3422531
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 20 deletions.
17 changes: 15 additions & 2 deletions front/src/applications/operationalStudies/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,22 @@ export type ImportedTrainSchedule = {
transilienName?: string;
};

export type ImportStation = {
trigram?: string;
name?: string;
yardname?: string;
town?: string;
department?: string;
region?: string;
uic?: number;
linename?: string;
pk?: string;
linecode?: string;
};

export type TrainScheduleImportConfig = {
from: string;
to: string;
from: ImportStation;
to: ImportStation;
date: string;
startTime: string;
endTime: string;
Expand Down
14 changes: 1 addition & 13 deletions front/src/common/StationCard.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
import cx from 'classnames';

import type { ImportStation } from 'applications/operationalStudies/types';
import { formatUicToCi } from 'utils/strings';

export interface ImportStation {
trigram?: string;
name?: string;
yardname?: string;
town?: string;
department?: string;
region?: string;
uic?: number;
linename?: string;
pk?: string;
linecode?: string;
}

type Props = {
station: ImportStation;
onClick?: () => void;
Expand Down
6 changes: 4 additions & 2 deletions front/src/common/api/graouApi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { TrainScheduleImportConfig } from 'applications/operationalStudies/types';
import type { ImportStation } from 'common/StationCard';
import type {
ImportStation,
TrainScheduleImportConfig,
} from 'applications/operationalStudies/types';

export const GRAOU_URL = 'https://graou.info';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useTranslation } from 'react-i18next';
import nextId from 'react-id-generator';

import type {
ImportStation,
ImportedTrainSchedule,
TrainScheduleImportConfig,
Step,
Expand All @@ -15,7 +16,7 @@ import { getGraouTrainSchedules } from 'common/api/graouApi';
import { type TrainScheduleBase } from 'common/api/osrdEditoastApi';
import InputSNCF from 'common/BootstrapSNCF/InputSNCF';
import { ModalContext } from 'common/BootstrapSNCF/ModalSNCF/ModalProvider';
import StationCard, { type ImportStation } from 'common/StationCard';
import StationCard from 'common/StationCard';
import UploadFileModal from 'common/uploadFileModal';
import StationSelector from 'modules/trainschedule/components/ImportTrainSchedule/ImportTrainScheduleStationSelector';
import { setFailure } from 'reducers/main';
Expand Down Expand Up @@ -154,7 +155,7 @@ const ImportTrainScheduleConfig = ({
date,
startTime,
endTime,
} as TrainScheduleImportConfig);
});
}
}
// EXTRACT-CI-CH-CODE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import React, { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import nextId from 'react-id-generator';

import type { ImportStation } from 'applications/operationalStudies/types';
import { searchGraouStations } from 'common/api/graouApi';
import InputSNCF from 'common/BootstrapSNCF/InputSNCF';
import { Loader } from 'common/Loaders';
import StationCard, { type ImportStation } from 'common/StationCard';
import StationCard from 'common/StationCard';
import { useDebounce } from 'utils/helpers';

interface ImportTrainScheduleStationSelectorProps {
Expand Down

0 comments on commit 3422531

Please sign in to comment.