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: display electrical profile set name in scenario #9870

Merged
merged 1 commit into from
Nov 28, 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
4 changes: 4 additions & 0 deletions front/public/locales/en/operationalStudies/scenario.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"editScenario": "Edit scenario",
"description": {
"electricalProfileWithName": "Electrical profiles : {{name}} | ID{{id}}",
"electricalProfileWithId": "Electrical profiles : ID{{id}}"
},
"displayTrainsWithDetails": "Mask/unmask trains detail",
"electricalProfileSet": "Electrical profiles set",
"errorMessages": {
Expand Down
4 changes: 4 additions & 0 deletions front/public/locales/fr/operationalStudies/scenario.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"editScenario": "Modifier le scénario",
"description": {
"electricalProfileWithName": "Profils électriques : {{name}} | ID{{id}}",
"electricalProfileWithId": "Profils électriques : ID{{id}}"
},
"displayTrainsWithDetails": "Afficher/masquer le détail des trains",
"electricalProfileSet": "Set de profils électriques",
"errorMessages": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { useEffect, useRef, useState } from 'react';
import { useEffect, useMemo, useRef, useState } from 'react';

import { Blocked, ChevronLeft, Pencil, X } from '@osrd-project/ui-icons';
import { useTranslation } from 'react-i18next';

import type { InfraWithState, ScenarioResponse } from 'common/api/osrdEditoastApi';
import {
osrdEditoastApi,
type InfraWithState,
type ScenarioResponse,
} from 'common/api/osrdEditoastApi';
import { useModal } from 'common/BootstrapSNCF/ModalSNCF';
import AddAndEditScenarioModal from 'modules/scenario/components/AddOrEditScenarioModal';
import useOutsideClick from 'utils/hooks/useOutsideClick';
Expand All @@ -30,6 +34,15 @@ const ScenarioDescription = ({
const collapsedDescriptionRef = useRef<HTMLDivElement | null>(null);
const [isTooLongDescription, setIsTooLongDescription] = useState<boolean>(false);

const { data: electricalProfileSets } =
osrdEditoastApi.endpoints.getElectricalProfileSet.useQuery();

const electricalProfileSet = useMemo(
() =>
electricalProfileSets?.find((profile) => profile.id === scenario.electrical_profile_set_id),
[electricalProfileSets]
);

const toggleDescription = () => {
setIsOpenedDescription(!isOpenedDescription);
};
Expand Down Expand Up @@ -114,9 +127,20 @@ const ScenarioDescription = ({
</button>
</div>
<div className="scenario-details-electrical-profile-set">
{scenario.electrical_profile_set_id
? scenario.electrical_profile_set_id
: t('noElectricalProfileSet')}
{scenario.electrical_profile_set_id ? (
<span>
{electricalProfileSet?.name
? t('description.electricalProfileWithName', {
name: electricalProfileSet.name,
id: scenario.electrical_profile_set_id,
})
: t('description.electricalProfileWithId', {
id: scenario.electrical_profile_set_id,
})}
</span>
) : (
t('noElectricalProfileSet')
)}
</div>

<div className="scenario-details-infra-name">
Expand Down
Loading