Skip to content

Commit e9c1294

Browse files
committed
transitRouting: use the useHistoryTracking for routing form
Let the form use the `useHistoryTracking` hook to allow to track object changes history. As the `TransitRouting` object is a simple one, without ID, or DB representation, it is a good candidate to be the first to migrate to the new form structure, using hooks instead of inheritance for history tracking. Also add an UndoRedoButtons widget to allow to undo/redo changes in the form.
1 parent 8e15362 commit e9c1294

File tree

2 files changed

+171
-84
lines changed

2 files changed

+171
-84
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright 2025, Polytechnique Montreal and contributors
3+
*
4+
* This file is licensed under the MIT License.
5+
* License text available at https://opensource.org/licenses/MIT
6+
*/
7+
import React from 'react';
8+
import { useTranslation } from 'react-i18next';
9+
import { faUndoAlt } from '@fortawesome/free-solid-svg-icons/faUndoAlt';
10+
import { faRedoAlt } from '@fortawesome/free-solid-svg-icons/faRedoAlt';
11+
12+
import Button from '../input/Button';
13+
14+
export type UndoRedoButtonsProps = {
15+
/**
16+
* Function called after the undo button was clicked and the last action was
17+
* undone
18+
*/
19+
onUndo: () => void;
20+
/**
21+
* Function called after the redo button was clicked and the last action was
22+
* redone
23+
*/
24+
onRedo: () => void;
25+
canRedo: () => boolean;
26+
canUndo: () => boolean;
27+
};
28+
29+
const UndoRedoButtons: React.FunctionComponent<UndoRedoButtonsProps> = (props: UndoRedoButtonsProps) => {
30+
const { t } = useTranslation(['main', 'notifications']);
31+
32+
return (
33+
<div className="tr__form-buttons-container tr__form-selected-object-buttons-container">
34+
<Button
35+
title={t('main:Undo')}
36+
name="undo"
37+
key="undo"
38+
color="grey"
39+
disabled={!props.canUndo()}
40+
icon={faUndoAlt}
41+
iconClass="_icon-alone"
42+
label=""
43+
onClick={props.onUndo}
44+
/>
45+
<Button
46+
title={t('main:Redo')}
47+
name="redo"
48+
key="redo"
49+
color="grey"
50+
disabled={!props.canRedo()}
51+
icon={faRedoAlt}
52+
iconClass="_icon-alone"
53+
label=""
54+
onClick={props.onRedo}
55+
/>
56+
</div>
57+
);
58+
};
59+
60+
export default UndoRedoButtons;

0 commit comments

Comments
 (0)