Skip to content

Commit

Permalink
front: initialize stdcm new interface
Browse files Browse the repository at this point in the history
  • Loading branch information
kmer2016 committed May 31, 2024
1 parent 9549537 commit 23ed3c3
Show file tree
Hide file tree
Showing 62 changed files with 1,720 additions and 559 deletions.
4 changes: 2 additions & 2 deletions front/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"@nivo/line": "^0.80.0",
"@nivo/tooltip": "^0.80.0",
"@openapi-contrib/openapi-schema-to-json-schema": "^5.1.0",
"@osrd-project/ui-core": "^0.0.21",
"@osrd-project/ui-icons": "^0.0.21",
"@osrd-project/ui-core": "^0.0.24",
"@osrd-project/ui-icons": "^0.0.24",
"@react-pdf/renderer": "^3.4.2",
"@redux-devtools/extension": "^3.3.0",
"@reduxjs/toolkit": "^2.1.0",
Expand Down
1 change: 1 addition & 0 deletions front/public/locales/en/home/navbar.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
},
"safeWord": "Safety keyword",
"safeWordHelp": "The \"security keyword\" allows you to transparently filter the list of projects with the word you enter, used as a label. Choose a complicated word so that no-one uses it inadvertently. Add it as a label to a project; it will be automatically added when the project is created if the word is entered here.",
"stdcmToggle": "STDCM New interface",
"userSettings": "User settings",
"yourSafeWord": "Type in your word"
}
24 changes: 23 additions & 1 deletion front/public/locales/en/stdcm.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
{
"apply": "Apply",
"cancelRequest": "Cancel request",
"consist": {
"consist": "Consist",
"tractionEngine": "Traction engine"
},
"loaderImageLegend": "The TGV Nord line",
"notificationTitle": "Phase 1: from D-7 to D-1 5pm, on the Perrigny-Miramas axis.",
"pleaseWait": "Please wait…",
"simulation":{
"averageRequestTime": "For your request, the time required is generally 90 seconds.",
"calculatingSimulation": "Calculation in progress...",
"getSimulation": "Get the simulation",
"pendingSimulation": "Simulation in progress",
"stopCalculation" : "Stop calculation"
},
"spaceSpeedGraphic": "Space-Velocity graph",
"spaceTimeGraphic": "Space-Time graph",
"stdcmComputation": "Search for a train path",
"stdcmError": "Calculation error for last minute train path.",
"stdcmErrorNoPaths": "Incompatibility with other train paths.",
"stdcmNoResults": "No path found",
"stdcmResults": "Results",
"stdcmSimulationReport": "Path simulation report"
"stdcmSimulationReport": "Path simulation report",
"trainPath": {
"asSoonAsPossible": "As soon as possible",
"ch": "CH",
"ci": "CI",
"date": "Date",
"destination": "Destination",
"origin": "Origin",
"time": "Time"
}
}
1 change: 1 addition & 0 deletions front/public/locales/fr/home/navbar.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
},
"safeWord": "Mot clé de sécurité",
"safeWordHelp": "Le « mot-clé de sécurité » permet de filtrer de manière transparente la liste des projets avec le mot renseigné, utilisé comme une étiquette. Préférez un mot compliqué dans l'idée que personne ne l'utilise par inadvertance. Ajoutez-le comme une étiquette à un projet ; il sera automatiquement ajouté à la création de projet si le mot est renseigné ici.",
"stdcmToggle": "STDCM Nouvelle interface",
"userSettings": "Paramètres utilisateur",
"yourSafeWord": "Tapez votre mot"
}
24 changes: 23 additions & 1 deletion front/public/locales/fr/stdcm.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
{
"apply": "Appliquer",
"cancelRequest": "Annuler la requête",
"consist": {
"consist": "Convoi",
"tractionEngine": "Engin de traction"
},
"loaderImageLegend": "La ligne TGV Nord",
"notificationTitle": "Phase 1 : de J-7 à J-1 17h, sur l’axe Perrigny—Miramas.",
"pleaseWait": "Veuillez patientez…",
"simulation":{
"averageRequestTime": "Pour votre demande, le temps nécessaire est généralement de 90 secondes.",
"calculatingSimulation": "Calcul en cours...",
"getSimulation": "Obtenir la simulation",
"pendingSimulation": "simulation en cours",
"stopCalculation" : "Arrêter le calcul"
},
"spaceSpeedGraphic": "Graphique Espace-Vitesse",
"spaceTimeGraphic": "Graphique Espace-Temps",
"stdcmComputation": "Recherche de sillon",
"stdcmError": "Erreur de calcul Sillon de dernière minute",
"stdcmErrorNoPaths": "Incompatibilité avec d'autres sillons.",
"stdcmNoResults": "Aucun sillon trouvé",
"stdcmResults": "Résultats",
"stdcmSimulationReport": "Fiche simulation"
"stdcmSimulationReport": "Fiche simulation",
"trainPath": {
"asSoonAsPossible": "Dès que possible",
"ch": "CH",
"ci": "CI",
"date": "Date",
"destination": "Destination",
"origin": "Origine",
"time": "Heure"
}
}
1 change: 1 addition & 0 deletions front/src/applications/operationalStudies/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export interface PointOnMap {
path_offset?: number;
uic?: number | null;
ch?: string | null;
ci?: number | null;
location?: {
track_section?: string;
offset?: number;
Expand Down
6 changes: 4 additions & 2 deletions front/src/applications/operationalStudies/views/Scenario.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import React from 'react';

import { useSelector } from 'react-redux';

import { getTrainScheduleV2Activated } from 'reducers/user/userSelectors';
import { getStdcmV2Activated, getTrainScheduleV2Activated } from 'reducers/user/userSelectors';

import ScenarioV1 from './ScenarioV1';
import ScenarioV2 from './v2/ScenarioV2';

export default function Scenario() {
const trainScheduleV2Activated = useSelector(getTrainScheduleV2Activated);
return trainScheduleV2Activated ? <ScenarioV2 /> : <ScenarioV1 />;
const stdcmV2Activated = useSelector(getStdcmV2Activated);
const useTrainScheduleV2 = trainScheduleV2Activated || stdcmV2Activated;
return useTrainScheduleV2 ? <ScenarioV2 /> : <ScenarioV1 />;
}
8 changes: 5 additions & 3 deletions front/src/applications/operationalStudies/views/Study.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { Loader, Spinner } from 'common/Loaders';
import ScenarioCard from 'modules/scenario/components/ScenarioCard';
import ScenarioCardEmpty from 'modules/scenario/components/ScenarioCardEmpty';
import AddOrEditStudyModal from 'modules/study/components/AddOrEditStudyModal';
import { getTrainScheduleV2Activated } from 'reducers/user/userSelectors';
import { getStdcmV2Activated, getTrainScheduleV2Activated } from 'reducers/user/userSelectors';
import { budgetFormat } from 'utils/numbers';

type SortOptions =
Expand All @@ -44,6 +44,8 @@ export default function Study() {
const { openModal } = useModal();
const { projectId: urlProjectId, studyId: urlStudyId } = useParams() as studyParams;
const trainScheduleV2Activated = useSelector(getTrainScheduleV2Activated);
const stdcmV2Activated = useSelector(getStdcmV2Activated);
const useTrainScheduleV2 = trainScheduleV2Activated || stdcmV2Activated;

const [scenariosList, setScenariosList] = useState<ScenarioWithCountTrains[]>([]);
const [filter, setFilter] = useState('');
Expand Down Expand Up @@ -154,7 +156,7 @@ export default function Study() {
console.error(error);
}
} else {
const scenarios = trainScheduleV2Activated ? scenariosV2?.results : scenariosV1?.results;
const scenarios = useTrainScheduleV2 ? scenariosV2?.results : scenariosV1?.results;
setScenariosList(scenarios || []);
}
setIsLoading(false);
Expand Down Expand Up @@ -186,7 +188,7 @@ export default function Study() {

useEffect(() => {
getScenarioList();
}, [sortOption, filter, scenariosV1, scenariosV2, trainScheduleV2Activated]);
}, [sortOption, filter, scenariosV1, scenariosV2, useTrainScheduleV2]);

return (
<>
Expand Down
8 changes: 1 addition & 7 deletions front/src/applications/rollingStockEditor/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { type FC } from 'react';

import { useTranslation } from 'react-i18next';

import { enhancedEditoastApi } from 'common/api/enhancedEditoastApi';
import { ModalProvider } from 'common/BootstrapSNCF/ModalSNCF/ModalProvider';
import NavBarSNCF from 'common/BootstrapSNCF/NavBarSNCF';

Expand All @@ -11,15 +10,10 @@ import RollingStockEditor from './views/RollingStockEditor';
const HomeRollingStockEditor: FC = () => {
const { t } = useTranslation(['home/home', 'referenceMap']);

const { data: { results: rollingStocks } = { results: [] } } =
enhancedEditoastApi.endpoints.getLightRollingStock.useQuery({
pageSize: 1000,
});

return (
<ModalProvider>
<NavBarSNCF appName={<>{t('rollingStockEditor')}</>} />
<RollingStockEditor rollingStocks={rollingStocks} />
<RollingStockEditor />
</ModalProvider>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React, { useEffect, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';

import { osrdEditoastApi } from 'common/api/osrdEditoastApi';
import type { LightRollingStockWithLiveries } from 'common/api/osrdEditoastApi';
import { useModal } from 'common/BootstrapSNCF/ModalSNCF';
import { Loader } from 'common/Loaders/Loader';
import { RollingStockCard } from 'modules/rollingStock/components/RollingStockCard';
Expand All @@ -12,19 +11,13 @@ import RollingStockEditorButtons from 'modules/rollingStock/components/RollingSt
import RollingStockEditorFormModal from 'modules/rollingStock/components/RollingStockEditor/RollingStockEditorFormModal';
import RollingStockInformationPanel from 'modules/rollingStock/components/RollingStockEditor/RollingStockInformationPanel';
import { SearchRollingStock } from 'modules/rollingStock/components/RollingStockSelector';
import useFilterRollingStock from 'modules/rollingStock/hooks/useFilterRollingStock';

type RollingStockEditorProps = {
rollingStocks: LightRollingStockWithLiveries[];
};

export default function RollingStockEditor({ rollingStocks }: RollingStockEditorProps) {
const RollingStockEditor = () => {
const { t } = useTranslation('rollingstock');
const ref2scroll: React.RefObject<HTMLInputElement> = useRef<HTMLInputElement>(null);
const [filteredRollingStockList, setFilteredRollingStockList] = useState(rollingStocks);
const [isLoading, setIsLoading] = useState(true);
const [isEditing, setIsEditing] = useState(false);
const [isAdding, setIsAdding] = useState(false);
const [isDuplicating, setIsDuplicating] = useState(false);
const { openModal } = useModal();

const [openedRollingStockCardId, setOpenedRollingStockCardId] = useState<number>();
Expand All @@ -39,7 +32,14 @@ export default function RollingStockEditor({ rollingStocks }: RollingStockEditor
}
);

useEffect(() => setFilteredRollingStockList(rollingStocks), []);
const {
filteredRollingStockList,
filters,
searchMateriel,
toggleFilter,
searchIsLoading,
resetFilters,
} = useFilterRollingStock();

const rollingStocksList = (
<div className="rollingstock-editor-list pr-1" data-testid="rollingstock-editor-list">
Expand Down Expand Up @@ -72,7 +72,7 @@ export default function RollingStockEditor({ rollingStocks }: RollingStockEditor
isCondensed
rollingStock={selectedRollingStock}
setIsEditing={setIsEditing}
setIsDuplicating={setIsDuplicating}
resetFilters={resetFilters}
isRollingStockLocked={selectedRollingStock.locked as boolean}
/>
</div>
Expand Down Expand Up @@ -102,7 +102,7 @@ export default function RollingStockEditor({ rollingStocks }: RollingStockEditor
);

function displayList() {
if (isLoading) {
if (searchIsLoading) {
return <Loader msg={t('waitingLoader')} />;
}
if (filteredRollingStockList.length === 0) {
Expand Down Expand Up @@ -171,12 +171,10 @@ export default function RollingStockEditor({ rollingStocks }: RollingStockEditor
</div>
)}
<SearchRollingStock
rollingStocks={rollingStocks}
setFilteredRollingStockList={setFilteredRollingStockList}
filteredRollingStockList={filteredRollingStockList}
setIsLoading={setIsLoading}
mustResetFilters={isDuplicating}
setMustResetFilters={setIsDuplicating}
filters={filters}
searchMateriel={searchMateriel}
toggleFilter={toggleFilter}
hasWhiteBackground
/>
{displayList()}
Expand All @@ -186,4 +184,6 @@ export default function RollingStockEditor({ rollingStocks }: RollingStockEditor
)}
</div>
);
}
};

export default RollingStockEditor;
17 changes: 14 additions & 3 deletions front/src/applications/stdcm/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
import React from 'react';

import { useTranslation } from 'react-i18next';
import { useSelector } from 'react-redux';
import { Route, Routes } from 'react-router-dom';

import StdcmViewV1 from 'applications/stdcm/views/StdcmViewV1';
import StdcmViewV2 from 'applications/stdcmV2/views/StdcmViewV2';
import NavBarSNCF from 'common/BootstrapSNCF/NavBarSNCF';

import StdcmView from './views/StdcmView';
import { getStdcmV2Activated } from 'reducers/user/userSelectors';

export default function HomeStdcm() {
const stdcmV2Activated = useSelector(getStdcmV2Activated);
const { t } = useTranslation('home/home');
if (stdcmV2Activated) {
return (
<Routes>
<Route path="" element={<StdcmViewV2 />} />
</Routes>
);
}

return (
<>
<NavBarSNCF appName={t('stdcm')} />
<Routes>
<Route path="" element={<StdcmView />} />
<Route path="" element={<StdcmViewV1 />} />
</Routes>
</>
);
Expand Down
Loading

0 comments on commit 23ed3c3

Please sign in to comment.