Skip to content

Commit

Permalink
front: harmonize comfort type
Browse files Browse the repository at this point in the history
  • Loading branch information
younesschrifi committed Aug 29, 2024
1 parent 6319aa8 commit 8f93c46
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { MdLocalGasStation } from 'react-icons/md';
import { LazyLoadComponent } from 'react-lazy-load-image-component';

import type {
RollingStockComfortType,
Comfort,
LightRollingStockWithLiveries,
} from 'common/api/osrdEditoastApi';
import RollingStock2Img from 'modules/rollingStock/components/RollingStock2Img';
Expand All @@ -35,7 +35,7 @@ const RollingStockCard = ({
ref2scroll = undefined,
setOpenedRollingStockCardId,
}: RollingStockCardProps) => {
const [curvesComfortList, setCurvesComfortList] = useState<RollingStockComfortType[]>([]);
const [curvesComfortList, setCurvesComfortList] = useState<Comfort[]>([]);

const ref2scrollWhenOpened: React.RefObject<HTMLInputElement> = useRef<HTMLInputElement>(null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { isEmpty, uniq } from 'lodash';
import { useTranslation } from 'react-i18next';

import { osrdEditoastApi } from 'common/api/osrdEditoastApi';
import type { RollingStockComfortType, RollingStockWithLiveries } from 'common/api/osrdEditoastApi';
import type { Comfort, RollingStockWithLiveries } from 'common/api/osrdEditoastApi';
import { Loader } from 'common/Loaders/Loader';
import RollingStock2Img from 'modules/rollingStock/components/RollingStock2Img';
import RollingStockCurves from 'modules/rollingStock/components/RollingStockCurve';
Expand All @@ -20,14 +20,14 @@ type RollingStockCardDetailProps = {
id: number;
hideCurves?: boolean;
form?: string;
curvesComfortList: RollingStockComfortType[];
setCurvesComfortList: (curvesComfortList: RollingStockComfortType[]) => void;
curvesComfortList: Comfort[];
setCurvesComfortList: (curvesComfortList: Comfort[]) => void;
};

export const getCurvesComforts = (curvesData: EffortCurveForms) => {
const modes = Object.keys(curvesData);
return modes.length
? modes.reduce<RollingStockComfortType[]>((list, mode) => {
? modes.reduce<Comfort[]>((list, mode) => {
const modeComfortList = curvesData[mode].curves.reduce(
(acc, curve) => {
const { comfort } = curve.cond;
Expand Down
12 changes: 6 additions & 6 deletions front/src/modules/rollingStock/components/RollingStockCurve.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { PointTooltipProps } from '@nivo/line';
import cx from 'classnames';
import { useTranslation } from 'react-i18next';

import type { RollingStock, RollingStockComfortType } from 'common/api/osrdEditoastApi';
import type { RollingStock, Comfort } from 'common/api/osrdEditoastApi';
import { COLORS } from 'modules/rollingStock/components/RollingStockSelector/consts/consts';
import { comfort2pictogram } from 'modules/rollingStock/components/RollingStockSelector/RollingStockHelpers';
import { STANDARD_COMFORT_LEVEL, THERMAL_TRACTION_IDENTIFIER } from 'modules/rollingStock/consts';
Expand Down Expand Up @@ -44,14 +44,14 @@ const parseData = (
};

function LegendComfortSwitches(props: {
curvesComfortList: RollingStockComfortType[];
curvesComfortList: Comfort[];
comfortsStates: { [key: string]: boolean };
onComfortsStatesChange: (comfort: string) => void;
}) {
const { curvesComfortList, comfortsStates, onComfortsStatesChange } = props;

// TODO: remove this condition when getRollingStock endpoint returns comfort
// with type Comfort instead of RollingStockComfortType */
// with type Comfort instead of Comfort */
const curvesComfortListV2 = curvesComfortList.map((comfort) =>
comfort === 'AC' ? 'AIR_CONDITIONING' : comfort
);
Expand Down Expand Up @@ -109,7 +109,7 @@ function Legend(props: {
{isOnEditionMode && !showPowerRestriction && curve.electrical_profile_level}
{!isOnEditionMode && !showPowerRestriction && curve.mode}
{/* TODO: remove this condition when getRollingStock endpoint returns comfort
with type Comfort instead of RollingStockComfortType */}
with type Comfort instead of Comfort */}
{curve.comfort !== STANDARD_COMFORT_LEVEL &&
!isOnEditionMode &&
comfort2pictogram(curve.comfort === 'AC' ? 'AIR_CONDITIONING' : curve.comfort)}
Expand Down Expand Up @@ -181,7 +181,7 @@ export default function RollingStockCurve({
selectedElectricalParam,
}: {
data: RollingStock['effort_curves']['modes'];
curvesComfortList: RollingStockComfortType[];
curvesComfortList: Comfort[];
isOnEditionMode?: boolean;
showPowerRestriction?: boolean;
hoveredElectricalParam?: string | null;
Expand Down Expand Up @@ -245,7 +245,7 @@ export default function RollingStockCurve({
{transformedCurve.comfort !== STANDARD_COMFORT_LEVEL && (
<span className="curves-chart-tooltip-comfort">
{/* TODO: remove this condition when getRollingStock endpoint returns comfort
with type Comfort instead of RollingStockComfortType */}
with type Comfort instead of Comfort */}
{comfort2pictogram(
transformedCurve.comfort === 'AC' ? 'AIR_CONDITIONING' : transformedCurve.comfort
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { osrdEditoastApi } from 'common/api/osrdEditoastApi';
import type {
ConditionalEffortCurve,
RollingStock,
RollingStockComfortType,
Comfort,
} from 'common/api/osrdEditoastApi';
import { useModal } from 'common/BootstrapSNCF/ModalSNCF';
import Selector from 'common/Selector/Selector';
Expand Down Expand Up @@ -51,14 +51,14 @@ const addNewCurveToMode = (

type RollingStockEditorCurvesProps = {
selectedParams: {
comfortLevel: RollingStockComfortType;
comfortLevel: Comfort;
electricalProfile: string | null;
powerRestriction: string | null;
tractionMode: string | null;
};
selectedParamsSetter: (
key: 'comfortLevel' | 'tractionMode' | 'electricalProfile' | 'powerRestriction',
value: RollingStockComfortType | string | null
value: Comfort | string | null
) => void;

effortCurves: EffortCurveForms | null;
Expand Down Expand Up @@ -126,7 +126,7 @@ const CurveParamSelectors = ({
}));
}, [availableModes, rollingstockParams.tractionModes]);

const updateComfortLevelsList = (value: RollingStockComfortType) => {
const updateComfortLevelsList = (value: Comfort) => {
if (!effortCurves) return;
// add the new comfort to all the modes
const updatedCurves = Object.keys(effortCurves).reduce((acc, mode) => {
Expand Down Expand Up @@ -200,7 +200,7 @@ const CurveParamSelectors = ({

const removeAnotherRsParam = (
title: 'comfort' | 'electrical_profile_level' | 'power_restriction_code',
value: string | RollingStockComfortType
value: string | Comfort
) => {
if (!effortCurves) return;
const condKey = title as keyof ConditionalEffortCurve['cond'];
Expand Down Expand Up @@ -229,7 +229,7 @@ const CurveParamSelectors = ({

const confirmRsParamRemoval = (
title: 'comfort' | 'tractionMode' | 'electrical_profile_level' | 'power_restriction_code',
value: string | null | RollingStockComfortType
value: string | null | Comfort
) => {
if (value === null) return;
openModal(
Expand Down Expand Up @@ -260,10 +260,10 @@ const CurveParamSelectors = ({
displayedItems={translateItemsList(t, rollingstockParams.comfortLevels, 'comfortTypes')}
selectedItem={selectedComfortLvl}
permanentItems={[STANDARD_COMFORT_LEVEL]}
onItemSelected={(item: RollingStockComfortType) => {
onItemSelected={(item: Comfort) => {
selectedParamsSetter('comfortLevel', item);
}}
onItemRemoved={(item: RollingStockComfortType) => {
onItemRemoved={(item: Comfort) => {
confirmRsParamRemoval('comfort', item);
}}
selectNewItemButtonProps={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { isEmpty } from 'lodash';
import type {
EffortCurves,
RollingStock,
RollingStockComfortType,
Comfort,
} from 'common/api/osrdEditoastApi';
import { getCurvesComforts } from 'modules/rollingStock/components/RollingStockCard/RollingStockCardDetail';
import RollingStockCurve from 'modules/rollingStock/components/RollingStockCurve';
Expand Down Expand Up @@ -60,14 +60,14 @@ const RollingStockEditorCurves = ({
children,
}: PropsWithChildren<RollingStockEditorCurvesProps>) => {
const [selectedParams, setSelectedParams] = useState<{
comfortLevel: RollingStockComfortType;
comfortLevel: Comfort;
electricalProfile: string | null;
powerRestriction: string | null;
}>(EMPTY_SELECTED_PARAMS);

const updateSelectedParams = (
key: 'comfortLevel' | 'tractionMode' | 'electricalProfile' | 'powerRestriction',
value: RollingStockComfortType | string | null
value: Comfort | string | null
) => {
if (key === 'tractionMode') {
setSelectedTractionMode(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useState } from 'react';

import cx from 'classnames';

import type { RollingStockComfortType, RollingStockWithLiveries } from 'common/api/osrdEditoastApi';
import type { Comfort, RollingStockWithLiveries } from 'common/api/osrdEditoastApi';
import RollingStock2Img from 'modules/rollingStock/components/RollingStock2Img';
import RollingStockCardDetail, {
getCurvesComforts,
Expand All @@ -21,7 +21,7 @@ export default function RollingStockInformationPanel({
isEditing,
rollingStock,
}: RollingStockInformationPanelProps) {
const [curvesComfortList, setCurvesComfortList] = useState<RollingStockComfortType[]>([]);
const [curvesComfortList, setCurvesComfortList] = useState<Comfort[]>([]);

return (
<div className={cx('rollingstock-editor-form', { borders: !isEditing })}>
Expand Down
6 changes: 3 additions & 3 deletions front/src/modules/rollingStock/consts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Comfort, RollingStockComfortType } from 'common/api/osrdEditoastApi';
import type { Comfort, Comfort } from 'common/api/osrdEditoastApi';
import { isElectric } from 'modules/rollingStock/helpers/electric';
import type {
ElectricalProfileByMode,
Expand All @@ -8,7 +8,7 @@ import type {
} from 'modules/rollingStock/types';

export const THERMAL_TRACTION_IDENTIFIER = 'thermal';
export const STANDARD_COMFORT_LEVEL: RollingStockComfortType = 'STANDARD';
export const STANDARD_COMFORT_LEVEL: Comfort = 'STANDARD';

export const DEFAULT_SIGNALING_SYSTEMS = ['BAL', 'BAPR'];

Expand Down Expand Up @@ -310,7 +310,7 @@ export const ComfortLevels: Record<Comfort, Comfort> = {
HEATING: 'HEATING',
};

export const COMFORTS = Object.keys(ComfortLevels) as RollingStockComfortType[];
export const COMFORTS = Object.keys(ComfortLevels) as Comfort[];

export const EP_BY_MODE: ElectricalProfileByMode = {
'1500V': [
Expand Down
4 changes: 2 additions & 2 deletions front/src/modules/rollingStock/helpers/curves.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { RollingStockComfortType } from 'common/api/osrdEditoastApi';
import type { Comfort } from 'common/api/osrdEditoastApi';
import { geti18nKeyForNull } from 'utils/strings';

// eslint-disable-next-line import/prefer-default-export
export const getCurveName = (
name: string,
comfort: RollingStockComfortType,
comfort: Comfort,
electricalProfileLevel: string | null,
powerRestrictionCode: string | null,
isOnEditionMode?: boolean
Expand Down
4 changes: 2 additions & 2 deletions front/src/modules/rollingStock/helpers/rollingStockEditor.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* eslint-disable import/prefer-default-export */
import type { RollingStockComfortType } from 'common/api/osrdEditoastApi';
import type { Comfort } from 'common/api/osrdEditoastApi';
import type { EffortCurveForms, ElectricalParamsLists } from 'modules/rollingStock/types';
import type { ValueOf } from 'utils/types';

/** Get the list of electrical profiles and power restrictions for an ModeEffortCurves */
export const getElectricalProfilesAndPowerRestrictions = (
effortCurvesByMode: ValueOf<EffortCurveForms>,
selectedComfortLvl: RollingStockComfortType,
selectedComfortLvl: Comfort,
selectedElectricalProfile: string | null
) =>
effortCurvesByMode.curves.reduce<ElectricalParamsLists>(
Expand Down
6 changes: 3 additions & 3 deletions front/src/modules/rollingStock/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { floor, groupBy, has, isNil, isNull, omit, pick } from 'lodash';

import type {
EffortCurve,
RollingStockComfortType,
Comfort,
RollingStock,
RollingStockForm,
} from 'common/api/osrdEditoastApi';
Expand Down Expand Up @@ -296,7 +296,7 @@ const formatCurveCondition = (
};

export const createEmptyCurve = (
comfort: RollingStockComfortType,
comfort: Comfort,
electricalProfile: string | null = null,
powerRestriction: string | null = null
) => ({
Expand All @@ -309,7 +309,7 @@ export const createEmptyCurve = (
});

/** given a tractionMode and a list of comfort, return empty EffortCurves */
export const createEmptyCurves = (tractionMode: string, comforts: RollingStockComfortType[]) => ({
export const createEmptyCurves = (tractionMode: string, comforts: Comfort[]) => ({
curves: comforts.map((comfort) => createEmptyCurve(comfort)),
default_curve: { speeds: [0], max_efforts: [0] },
is_electric: tractionMode !== THERMAL_TRACTION_IDENTIFIER,
Expand Down
8 changes: 4 additions & 4 deletions front/src/modules/rollingStock/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {
EffortCurveConditions,
LoadingGaugeType,
RollingStockComfortType,
Comfort,
RollingStock,
} from 'common/api/osrdEditoastApi';

Expand Down Expand Up @@ -148,7 +148,7 @@ export type EffortCurveForms = Record<
>;

export type RollingStockSelectorParams = {
comfortLevels: RollingStockComfortType[];
comfortLevels: Comfort[];
electricalProfiles: (string | null)[];
powerRestrictions: (string | null)[];
tractionModes: string[];
Expand All @@ -162,7 +162,7 @@ export type ElectricalParamsLists = Omit<
export type TransformedCurves = {
[index: string]: {
mode: string;
comfort: RollingStockComfortType;
comfort: Comfort;
speeds: number[];
max_efforts: number[];
electricalProfile: string | null;
Expand All @@ -172,7 +172,7 @@ export type TransformedCurves = {

export type ParsedCurve = {
color: string;
comfort: RollingStockComfortType;
comfort: Comfort;
data: {
x: number;
y: number;
Expand Down
4 changes: 2 additions & 2 deletions front/src/stories/RollingStockSelector.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Meta } from '@storybook/react';

import exampleRollingStockImage1 from 'assets/defaultRSImages/example_rolling_stock_image_1.gif';
import exampleRollingStockImage2 from 'assets/defaultRSImages/example_rolling_stock_image_2.gif';
import type { RollingStockComfortType } from 'common/api/osrdEditoastApi';
import type { Comfort } from 'common/api/osrdEditoastApi';
import { RollingStockSelector } from 'modules/rollingStock/components/RollingStockSelector';
import ROLLING_STOCK_SAMPLE_DATA from 'modules/rollingStock/components/RollingStockSelector/sampleData';

Expand All @@ -22,7 +22,7 @@ const image = (

const defaultArgs = {
rollingStockSelected: ROLLING_STOCK_SAMPLE_DATA,
rollingStockComfort: 'STANDARD' as RollingStockComfortType,
rollingStockComfort: 'STANDARD' as Comfort,
image,
};

Expand Down

0 comments on commit 8f93c46

Please sign in to comment.