Skip to content

Commit

Permalink
- create file for micro macro switch
Browse files Browse the repository at this point in the history
  • Loading branch information
Uriel-Sautron committed Jul 22, 2024
1 parent c79555b commit 9d79c6a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react';

import cx from 'classnames';

type MicroMacroSwitchProps = {
isMacro: boolean;
onClickButton: (isMacro: boolean) => void;
t: (key: string) => string;
};

const MicroMacroSwitch = ({ isMacro, onClickButton, t }: MicroMacroSwitchProps) => (
<div className="tabs-container">
<div className="tabs">
<div
className={cx('tab', { active: !isMacro })}
role="button"
tabIndex={0}
onClick={() => onClickButton(false)}
>
{t('microscopic')}
</div>
<div
className={cx('tab', { active: isMacro })}
role="button"
tabIndex={0}
onClick={() => onClickButton(true)}
>
{t('macroscopic')}
</div>
</div>
</div>
);

export default MicroMacroSwitch;
49 changes: 10 additions & 39 deletions front/src/applications/operationalStudies/views/v2/ScenarioV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useParams } from 'react-router-dom';

import BreadCrumbs from 'applications/operationalStudies/components/BreadCrumbs';
import NGE from 'applications/operationalStudies/components/MacroEditor/NGE';
import MicroMacroSwitch from 'applications/operationalStudies/components/MicroMacroSwitch';
import InfraLoadingState from 'applications/operationalStudies/components/Scenario/InfraLoadingState';
import { MANAGE_TRAIN_SCHEDULE_TYPES } from 'applications/operationalStudies/consts';
import type { TrainSpaceTimeData } from 'applications/operationalStudies/types';
Expand All @@ -32,35 +33,6 @@ import ImportTrainScheduleV2 from './ImportTrainScheduleV2';
import ManageTrainScheduleV2 from './ManageTrainScheduleV2';
import SimulationResultsV2 from './SimulationResultsV2';

type MicroMacroSwitchProps = {
isMacro: boolean;
onClickButton: (isMacro: boolean) => void;
t: (key: string) => string;
};

const MicroMacroSwitch = ({ isMacro, onClickButton, t }: MicroMacroSwitchProps) => (
<div className="tabs-container">
<div className="tabs">
<div
className={cx('tab', { active: !isMacro })}
role="button"
tabIndex={0}
onClick={() => onClickButton(false)}
>
{t('microscopic')}
</div>
<div
className={cx('tab', { active: isMacro })}
role="button"
tabIndex={0}
onClick={() => onClickButton(true)}
>
{t('macroscopic')}
</div>
</div>
</div>
);

type SimulationParams = {
projectId: string;
studyId: string;
Expand Down Expand Up @@ -179,15 +151,11 @@ const ScenarioV2 = () => {
[]
);

const onClickMicroMacroButton = (isMacroButton: boolean) => {
setIsMacro(isMacroButton);
setCollapsedTimetable(isMacroButton);
const toggleMicroMacroButton = (isMacroMode: boolean) => {
setIsMacro(isMacroMode);
setCollapsedTimetable(isMacroMode);
};

const microMacroSwitch = (
<MicroMacroSwitch isMacro={isMacro} onClickButton={onClickMicroMacroButton} t={t} />
);

if (!scenario || !infraId || !timetableId || !timetable) return null;

return (
Expand Down Expand Up @@ -285,7 +253,7 @@ const ScenarioV2 = () => {
<div className="scenario-details-description">{scenario.description}</div>
</div>
)}
{microMacroSwitch}
<MicroMacroSwitch isMacro={isMacro} onClickButton={toggleMicroMacroButton} t={t} />
{!isMacro && (
<>
{displayTrainScheduleManagement !== MANAGE_TRAIN_SCHEDULE_TYPES.none &&
Expand All @@ -296,7 +264,6 @@ const ScenarioV2 = () => {
setTrainResultsToFetch={setTrainResultsToFetch}
trainIdToEdit={trainIdToEdit}
setTrainIdToEdit={setTrainIdToEdit}
infraState={infra.state}
/>
)}
{infra && (
Expand Down Expand Up @@ -361,7 +328,11 @@ const ScenarioV2 = () => {
: t('noElectricalProfileSet')}
</div>
</div>
{microMacroSwitch}
<MicroMacroSwitch
isMacro={isMacro}
onClickButton={toggleMicroMacroButton}
t={t}
/>
</>
)}
{isMacro ? (
Expand Down

0 comments on commit 9d79c6a

Please sign in to comment.