-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f34c60f
commit 5827d95
Showing
6 changed files
with
110 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import cx from 'classnames'; | ||
import type { TFunction } from 'i18next'; | ||
import { keyColumn, type Column, checkboxColumn, createTextColumn } from 'react-datasheet-grid'; | ||
import type { CellComponent } from 'react-datasheet-grid/dist/types'; | ||
|
||
import type { ManageTrainSchedulePathProperties } from 'applications/operationalStudies/types'; | ||
import { marginRegExValidation } from 'utils/physics'; | ||
|
||
import TimeInput from './TimeInput'; | ||
import type { PathWaypointColumn } from './types'; | ||
|
||
const timeColumn: Partial<Column<string | null | undefined, string, string>> = { | ||
component: TimeInput as CellComponent<string | null | undefined, string>, | ||
deleteValue: () => null, | ||
copyValue: ({ rowData }) => rowData ?? null, | ||
pasteValue: ({ value }) => value, | ||
minWidth: 170, | ||
isCellEmpty: ({ rowData }) => !rowData, | ||
}; | ||
|
||
export const inputColumns = ( | ||
t: TFunction<'timesStops', undefined>, | ||
pathProperties: ManageTrainSchedulePathProperties | ||
) => | ||
[ | ||
{ | ||
...keyColumn('name', createTextColumn()), | ||
title: t('name'), | ||
disabled: true, | ||
}, | ||
{ | ||
...keyColumn('ch', createTextColumn()), | ||
title: 'Ch', | ||
disabled: true, | ||
grow: 0.1, | ||
}, | ||
{ | ||
...keyColumn('arrival', timeColumn), | ||
title: t('arrivalTime'), | ||
|
||
// We should not be able to edit the arrival time of the origin | ||
disabled: ({ rowIndex }) => rowIndex === 0, | ||
grow: 0.6, | ||
}, | ||
{ | ||
...keyColumn( | ||
'stopFor', | ||
createTextColumn({ | ||
continuousUpdates: false, | ||
alignRight: true, | ||
}) | ||
), | ||
title: `${t('stopTime')}`, | ||
grow: 0.6, | ||
}, | ||
{ | ||
...keyColumn('onStopSignal', checkboxColumn as Partial<Column<boolean | undefined>>), | ||
title: t('receptionOnClosedSignal'), | ||
|
||
// We should not be able to edit the reception on close signal if stopFor is not filled | ||
// except for the destination | ||
grow: 0.6, | ||
disabled: ({ rowData, rowIndex }) => | ||
rowIndex !== pathProperties.allWaypoints?.length - 1 && !rowData.stopFor, | ||
}, | ||
{ | ||
...keyColumn( | ||
'theoreticalMargin', | ||
createTextColumn({ | ||
continuousUpdates: false, | ||
alignRight: true, | ||
placeholder: t('theoreticalMarginPlaceholder'), | ||
formatBlurredInput: (value) => { | ||
if (!value || value === 'none') return ''; | ||
if (!marginRegExValidation.test(value)) { | ||
return `${value}${t('theoreticalMarginPlaceholder')}`; | ||
} | ||
return value; | ||
}, | ||
}) | ||
), | ||
cellClassName: ({ rowData }) => cx({ invalidCell: !rowData.isMarginValid }), | ||
title: t('theoreticalMargin'), | ||
disabled: ({ rowIndex }) => rowIndex === pathProperties.allWaypoints.length - 1, | ||
}, | ||
] as Column<PathWaypointColumn>[]; | ||
|
||
export default timeColumn; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters