|
5 | 5 | SearchResultItemOperationalPoint,
|
6 | 6 | osrdEditoastApi,
|
7 | 7 | } from 'common/api/osrdEditoastApi';
|
8 |
| -import React, { useEffect, useState } from 'react'; |
| 8 | +import React, { useEffect, useMemo, useState } from 'react'; |
9 | 9 | import { useTranslation } from 'react-i18next';
|
10 | 10 | import { useDispatch, useSelector } from 'react-redux';
|
11 | 11 | import { getInfraID, getRollingStockID } from 'reducers/osrdconf/selectors';
|
@@ -52,24 +52,23 @@ function OpTooltips({ opList }: { opList: SearchResultItemOperationalPoint[] })
|
52 | 52 |
|
53 | 53 | export default function TypeAndPath({ zoomToFeature }: PathfindingProps) {
|
54 | 54 | const dispatch = useDispatch();
|
55 |
| - const [inputText, setInputText] = useState<string>(''); |
| 55 | + const [inputText, setInputText] = useState(''); |
56 | 56 | const [opList, setOpList] = useState<SearchResultItemOperationalPoint[]>([]);
|
57 | 57 | const infraId = useSelector(getInfraID);
|
58 | 58 | const rollingStockId = useSelector(getRollingStockID);
|
59 |
| - const [postSearch] = osrdEditoastApi.usePostSearchMutation(); |
| 59 | + const [postSearch] = osrdEditoastApi.endpoints.postSearch.useMutation(); |
60 | 60 | const [postPathfinding] = osrdEditoastApi.usePostPathfindingMutation();
|
61 | 61 | const { t } = useTranslation('operationalStudies/manageTrainSchedule');
|
62 | 62 |
|
63 | 63 | const debouncedInputText = useDebounce(inputText.trimEnd(), 500);
|
64 | 64 |
|
65 | 65 | const handleInput = (text: string) => {
|
66 |
| - // setInputText(text.trimStart().toUpperCase()); |
67 | 66 | setInputText(text.trimStart());
|
68 | 67 | };
|
69 | 68 |
|
70 | 69 | function getOpNames() {
|
71 | 70 | if (infraId !== undefined) {
|
72 |
| - const opTrigrams = inputText.toUpperCase().split(' '); |
| 71 | + const opTrigrams = inputText.toUpperCase().trimEnd().split(' '); |
73 | 72 | const constraint = opTrigrams.reduce(
|
74 | 73 | (res, trigram) => [...res, ['=', ['trigram'], trigram]],
|
75 | 74 | ['or'] as (string | SearchConstraintType)[]
|
@@ -100,7 +99,7 @@ export default function TypeAndPath({ zoomToFeature }: PathfindingProps) {
|
100 | 99 | }
|
101 | 100 | }
|
102 | 101 |
|
103 |
| - const isInvalid = !opList.every((op) => op.name || op.trigram === ''); |
| 102 | + const isInvalid = useMemo(() => opList.some((op) => !op.name && op.trigram !== ''), [opList]); |
104 | 103 |
|
105 | 104 | function launchPathFinding() {
|
106 | 105 | if (infraId && rollingStockId && opList.length > 0) {
|
@@ -169,7 +168,7 @@ export default function TypeAndPath({ zoomToFeature }: PathfindingProps) {
|
169 | 168 | className="btn btn-sm btn-success"
|
170 | 169 | type="button"
|
171 | 170 | onClick={launchPathFinding}
|
172 |
| - disabled={isInvalid} |
| 171 | + disabled={isInvalid || opList.length < 2} |
173 | 172 | >
|
174 | 173 | <GoTriangleRight />
|
175 | 174 | </button>
|
|
0 commit comments