Skip to content

Commit

Permalink
front: refacto stdcm linked train search props
Browse files Browse the repository at this point in the history
Signed-off-by: SarahBellaha <[email protected]>
  • Loading branch information
SarahBellaha committed Nov 5, 2024
1 parent 5c8674c commit 5b48a87
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 56 deletions.
12 changes: 8 additions & 4 deletions front/public/locales/en/stdcm.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
"invalidDate": "Select a date between {{startDate}} and {{endDate}}"
}
},
"indicateAnteriorPath": "Indicate anterior path",
"indicatePosteriorPath": "Indicate posterior path",
"leaveAt": "Leave at {{ time }}",
"linkedTrainDefaultCard": {
"anterior": "Indicate anterior path",
"posterior": "Indicate posterior path"
},
"loaderImageLegend": "Morning view of the locomotive shed at Le Bourget depot",
"noConfigurationFound": {
"title": "A configuration problem prevents you from performing a search",
Expand Down Expand Up @@ -98,14 +100,16 @@
"stdcmSimulationReport": "Path simulation report",
"trainPath": {
"addVia": "Add intermediate OP",
"anteriorPath": "Anterior path",
"asSoonAsPossible": "as soon as possible",
"ch": "CH",
"ci": "CI",
"date": "Date",
"destination": "Destination",
"linkedTrain": {
"anterior": "Anterior path",
"posterior": "Posterior path"
},
"origin": "Origin",
"posteriorPath": "Posterior path",
"preciseTime": "precise time",
"stopFor": "Minimum stop time",
"stopType": {
Expand Down
10 changes: 8 additions & 2 deletions front/public/locales/fr/stdcm.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
"indicateAnteriorPath": "Indiquer le sillon antérieur",
"indicatePosteriorPath": "Indiquer le sillon postérieur",
"leaveAt": "Partir à {{ time }}",
"linkedTrainDefaultCard": {
"anterior": "Indiquer le sillon antérieur",
"posterior": "Indiquer le sillon postérieur"
},
"loaderImageLegend": "Vue matinale du relais de locomotives du dépôt du Bourget",
"noConfigurationFound": {
"title": "Un problème de configuration vous empêche de faire une recherche",
Expand Down Expand Up @@ -98,14 +102,16 @@
"stdcmSimulationReport": "Fiche simulation",
"trainPath": {
"addVia": "Ajouter un PR intermédiaire",
"anteriorPath": "Sillon antérieur",
"asSoonAsPossible": "dès que possible",
"ch": "CH",
"ci": "CI",
"date": "Date",
"destination": "Destination",
"linkedTrain": {
"anterior": "Sillon antérieur",
"posterior": "Sillon postérieur"
},
"origin": "Origine",
"posteriorPath": "Sillon postérieur",
"preciseTime": "horaire précis",
"stopFor": "Temps d'arrêt minimum",
"stopType": {
Expand Down
15 changes: 4 additions & 11 deletions front/src/applications/stdcm/components/StdcmForm/StdcmConfig.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useEffect, useState } from 'react';

import { Button } from '@osrd-project/ui-core';
import { ArrowDown, ArrowUp } from '@osrd-project/ui-icons';
import cx from 'classnames';
import { compact } from 'lodash';
import { useTranslation } from 'react-i18next';
Expand Down Expand Up @@ -145,11 +144,8 @@ const StdcmConfig = ({
<div className="d-flex flex-column">
<StdcmLinkedTrainSearch
disabled={disabled}
defaultCardText={t('indicateAnteriorPath')}
cardName={t('trainPath.anteriorPath')}
cardIcon={<ArrowUp size="lg" />}
className="anterior-linked-path"
linkedOp={{ extremityType: 'destination', id: origin.id }}
linkedTrainType="anterior"
linkedOpId={origin.id}
/>
<div className="stdcm-simulation-inputs">
<div className="stdcm-consist-container">
Expand All @@ -162,11 +158,8 @@ const StdcmConfig = ({
<StdcmDestination disabled={disabled} />
<StdcmLinkedTrainSearch
disabled={disabled}
defaultCardText={t('indicatePosteriorPath')}
cardName={t('trainPath.posteriorPath')}
cardIcon={<ArrowDown size="lg" />}
className="posterior-linked-path"
linkedOp={{ extremityType: 'origin', id: destination.id }}
linkedTrainType="posterior"
linkedOpId={destination.id}
/>
<div
className={cx('stdcm-launch-request', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ const StdcmLinkedTrainResults = ({
const dispatch = useDispatch();
const { updateLinkedPathStep } = useOsrdConfActions() as StdcmConfSliceActions;
return (
<div className="stdcm-linked-path-results">
<div className="stdcm-linked-train-results">
{linkedTrainResults.map(({ trainName, origin, destination }, index) => (
<button
key={`linked-path-${index}`}
key={`linked-train-${index}`}
tabIndex={0}
type="button"
className="linked-path-result-infos"
className="linked-train-result-infos"
onClick={() => {
if (linkedTrainResults.length === 1)
dispatch(
Expand All @@ -43,7 +43,7 @@ const StdcmLinkedTrainResults = ({
label={trainName}
id={`${extremityType}-${index}`}
value={`${index}`}
name={`linked-path-radio-buttons-${extremityType}`}
name={`linked-train-radio-buttons-${extremityType}`}
onClick={({ target }) => {
const resultIndex = Number((target as HTMLInputElement).value);
dispatch(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
import { useState, type ReactNode } from 'react';
import { useState } from 'react';

import { DatePicker, Input } from '@osrd-project/ui-core';
import { Gear } from '@osrd-project/ui-icons';
import { ArrowDown, ArrowUp, Gear } from '@osrd-project/ui-icons';
import { useTranslation } from 'react-i18next';

import useLinkedTrainSearch from 'applications/stdcm/hooks/useLinkedTrainSearch';

import StdcmCard from './StdcmCard';
import StdcmDefaultCard from './StdcmDefaultCard';
import StdcmLinkedTrainResults from './StdcmLinkedTrainResults';
import type { ExtremityPathStepType } from '../../types';
import type { LinkedTrainType } from '../../types';

type StdcmLinkedTrainSearchProps = {
disabled: boolean;
cardIcon: ReactNode;
cardName: string;
className?: string;
defaultCardText: string;
linkedOp: { extremityType: ExtremityPathStepType; id: string };
linkedTrainType: LinkedTrainType;
linkedOpId: string;
};

const StdcmLinkedTrainSearch = ({
disabled,
cardIcon,
cardName,
className = '',
defaultCardText,
linkedOp,
linkedTrainType,
linkedOpId,
}: StdcmLinkedTrainSearchProps) => {
const { t } = useTranslation('stdcm');
const [displayLinkedTrainSearch, setShowLinkedTrainSearch] = useState(false);
Expand All @@ -45,30 +39,30 @@ const StdcmLinkedTrainSearch = ({
} = useLinkedTrainSearch();

return (
<div className={`stdcm-linked-path-search-container ${className}`}>
<div className={`stdcm-linked-train-search-container ${linkedTrainType}-linked-train`}>
{!displayLinkedTrainSearch ? (
<div tabIndex={0} role="button" onClick={() => setShowLinkedTrainSearch(true)}>
<StdcmDefaultCard
disabled={disabled}
text={defaultCardText}
Icon={cardIcon}
className="add-linked-path"
text={t(`linkedTrainDefaultCard.${linkedTrainType}`)}
Icon={linkedTrainType === 'anterior' ? <ArrowUp size="lg" /> : <ArrowDown size="lg" />}
className="add-linked-train"
/>
</div>
) : (
<StdcmCard
disabled={disabled}
name={cardName}
name={t(`trainPath.linkedTrain.${linkedTrainType}`)}
title={
<button type="button" onClick={() => setShowLinkedTrainSearch(false)}>
{t('translation:common.delete').toLowerCase()}
</button>
}
className="linked-path"
className="linked-train"
>
<div className="d-flex pr-1 pl-3">
<Input
id="linked-path-id"
id="linked-train-id"
type="text"
value={trainNameInput}
onChange={(e) => {
Expand All @@ -79,7 +73,7 @@ const StdcmLinkedTrainSearch = ({
/>
<DatePicker
inputProps={{
id: 'linked-path-date',
id: 'linked-train-date',
label: 'Date',
name: 'op-date',
}}
Expand All @@ -92,20 +86,26 @@ const StdcmLinkedTrainSearch = ({
</div>
{displaySearchButton && (
<button
className="stdcm-linked-path-button"
className="stdcm-linked-train-button"
type="button"
onClick={launchTrainScheduleSearch}
>
{t('find')}
</button>
)}
{!displaySearchButton && !linkedTrainResults.length && (
<div className="stdcm-linked-path-button white">
<Gear size="lg" className="stdcm-linked-path-loading" />
<div className="stdcm-linked-train-button white">
<Gear size="lg" className="stdcm-linked-train-loading" />
</div>
)}
{linkedTrainResults.length > 0 ? (
<StdcmLinkedTrainResults linkedTrainResults={linkedTrainResults} linkedOp={linkedOp} />
<StdcmLinkedTrainResults
linkedTrainResults={linkedTrainResults}
linkedOp={{
extremityType: linkedTrainType === 'anterior' ? 'destination' : 'origin',
id: linkedOpId,
}}
/>
) : (
hasSearchBeenLaunched && (
<p className="text-center mb-0">{t('noCorrespondingResults')}</p>
Expand Down
2 changes: 2 additions & 0 deletions front/src/applications/stdcm/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,5 @@ export type StdcmLinkedTrainResult = {
};

export type ExtremityPathStepType = 'origin' | 'destination';

export type LinkedTrainType = 'anterior' | 'posterior';
4 changes: 2 additions & 2 deletions front/src/styles/scss/applications/stdcm/_card.scss
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
.stdcm-card__body {
padding: 14px 24px 24px 8px;

&.add-linked-path,
&.linked-path {
&.add-linked-train,
&.linked-train {
width: 450px;
padding: 11px 8px 13px;
}
Expand Down
16 changes: 8 additions & 8 deletions front/src/styles/scss/applications/stdcm/_linkedTrain.scss
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
.stdcm-linked-path-search-container {
.stdcm-linked-train-search-container {
align-self: flex-end;

&.anterior-linked-path {
&.anterior-linked-train {
margin-bottom: 18px;
}

&.posterior-linked-path {
&.posterior-linked-train {
margin-top: 18px;
}

Expand All @@ -17,8 +17,8 @@
}
}

.linked-path {
.stdcm-linked-path-button {
.linked-train {
.stdcm-linked-train-button {
text-align: center;
width: 402px;
height: 40px;
Expand All @@ -29,18 +29,18 @@
&.white {
background-color: var(--white);
}
.stdcm-linked-path-loading {
.stdcm-linked-train-loading {
color: var(--primary90);
align-self: center;
}
}

.stdcm-linked-path-results {
.stdcm-linked-train-results {
padding: 10px 17px 0;
border-top: 1px solid var(--grey20);
margin-top: 21px;

.linked-path-result-infos {
.linked-train-result-infos {
width: 100%;
margin-bottom: 7px;

Expand Down

0 comments on commit 5b48a87

Please sign in to comment.