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: fix format time on arrival time column #7623

Merged
merged 1 commit into from
Jun 13, 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
3 changes: 2 additions & 1 deletion front/public/locales/en/timesStops.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"receptionOnClosedSignal": "Reception on Closed Signal",
"theoreticalMargin": "Theoretical Margin",
"theoreticalMarginPlaceholder": "% or min/100km",
"waypoint": "Waypoint {{id}}"
"waypoint": "Waypoint {{id}}",
"noPathLoaded": "No path loaded"
}
3 changes: 2 additions & 1 deletion front/public/locales/fr/timesStops.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"receptionOnClosedSignal": "Réception sur signal fermé",
"theoreticalMargin": "Marge théorique",
"theoreticalMarginPlaceholder": "% ou min/100km",
"waypoint": "Via {{id}}"
"waypoint": "Via {{id}}",
"noPathLoaded": "Aucun chemin chargé"
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const ManageTrainScheduleV2 = () => {
</div>
),
label: t('tabs.timesStops'),
content: pathProperties && <TimesStops pathProperties={pathProperties} pathSteps={pathSteps} />,
content: <TimesStops pathProperties={pathProperties} pathSteps={pathSteps} />,
};

const tabSimulationSettings = {
Expand Down
27 changes: 17 additions & 10 deletions front/src/modules/timesStops/TimeColumnComponent.tsx
SharglutDev marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,37 +1,44 @@
import React, { useLayoutEffect, useRef } from 'react';
import React, { useEffect, useRef, useState } from 'react';

import cx from 'classnames';
import type { CellComponent, CellProps, Column } from 'react-datasheet-grid/dist/types';

const TimeComponent = ({
focus,
rowData,
active,
setRowData,
}: CellProps<string | null | undefined, string>) => {
const ref = useRef<HTMLInputElement>(null);
const [tempTimeValue, setTempTimeValue] = useState<string | null | undefined>(rowData);

useLayoutEffect(() => {
if (focus) {
useEffect(() => {
if (active) {
ref.current?.select();
} else {
ref.current?.blur();
}
}, [focus]);
}, [active]);

return (
<input
className={cx('dsg-input', !focus && 'dsg-hide-time-picker')}
className="dsg-input"
type="time"
tabIndex={-1}
ref={ref}
step={2}
style={{
pointerEvents: focus ? 'auto' : 'none',
opacity: rowData || focus ? undefined : 0,
opacity: rowData || active ? undefined : 0,
}}
value={rowData ?? ''}
value={tempTimeValue ?? ''}
onChange={(e) => {
const time = e.target.value;
setRowData(time);
setTempTimeValue(e.target.value);
}}
onBlur={() => {
// To prevent the operational point to be transformed into a via if we leave the cell empty after focusing it
if (rowData !== tempTimeValue) {
setRowData(tempTimeValue);
}
}}
/>
);
Expand Down
17 changes: 16 additions & 1 deletion front/src/modules/timesStops/TimesStops.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { removeElementAtIndex } from 'utils/array';
import timeColumn from './TimeColumnComponent';

type TimesStopsProps = {
pathProperties: ManageTrainSchedulePathProperties;
pathProperties: ManageTrainSchedulePathProperties | undefined;
pathSteps?: (PathStep | null)[];
};

Expand Down Expand Up @@ -63,6 +63,15 @@ const createDeleteViaButton = ({

const TimesStops = ({ pathProperties, pathSteps = [] }: TimesStopsProps) => {
const { t } = useTranslation('timesStops');

if (!pathProperties) {
return (
<div className="d-flex justify-content-center align-items-center h-100">
<p className="pt-1 px-5">{t('noPathLoaded')}</p>
</div>
);
}

const dispatch = useAppDispatch();
const { upsertViaFromSuggestedOP, updatePathSteps } = useOsrdConfActions();

Expand Down Expand Up @@ -103,6 +112,10 @@ const TimesStops = ({ pathProperties, pathSteps = [] }: TimesStopsProps) => {
})
),
title: `${t('stopTime')}`,

// We should not be able to edit the stopping time of the origin and destination
disabled: ({ rowIndex }) =>
rowIndex === 0 || rowIndex === pathProperties.allVias?.length - 1,
grow: 0.6,
},
{
Expand All @@ -111,6 +124,8 @@ const TimesStops = ({ pathProperties, pathSteps = [] }: TimesStopsProps) => {
checkboxColumn as Partial<Column<boolean | undefined>>
),
title: t('receptionOnClosedSignal'),

// We should not be able to edit the reception on close signal of the origin
grow: 0.6,
disabled: ({ rowData }) => !rowData.stopFor,
},
Expand Down
Loading