-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
front: add logic to handle non-feasibility in stdcm simulations
Signed-off-by: Achraf Mohyeddine <[email protected]>
- Loading branch information
1 parent
aaae986
commit c3d0409
Showing
17 changed files
with
502 additions
and
105 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
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
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
101 changes: 101 additions & 0 deletions
101
front/src/applications/stdcm/hooks/useConflictsMessages.ts
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,101 @@ | ||
import { useEffect, useState } from 'react'; | ||
|
||
import type { TFunction } from 'i18next'; | ||
|
||
import { formatConflicts } from 'applications/stdcm/utils/formatConflicts'; | ||
import { hasConflicts } from 'applications/stdcm/utils/simulationOutputUtils'; | ||
|
||
import type { StdcmSimulationOutputs } from '../types'; | ||
|
||
const useConflictsMessages = (t: TFunction, selectedSimulationOutput?: StdcmSimulationOutputs) => { | ||
const [trackConflicts, setTrackConflicts] = useState<string[]>([]); | ||
const [workConflicts, setWorkConflicts] = useState<string[]>([]); | ||
|
||
useEffect(() => { | ||
if (!hasConflicts(selectedSimulationOutput)) return; | ||
|
||
const generateConflictMessages = () => { | ||
const { pathProperties } = selectedSimulationOutput; | ||
const { trackConflictsData, workConflictsData } = formatConflicts( | ||
selectedSimulationOutput?.conflicts, | ||
pathProperties | ||
); | ||
|
||
const trackMessages: string[] = []; | ||
trackConflictsData.slice(0, 2).forEach((conflict) => { | ||
const { waypointBefore, waypointAfter, startDate, endDate, startTime, endTime } = conflict; | ||
|
||
if (startDate === endDate) { | ||
trackMessages.push( | ||
t('trackConflictSameDay', { | ||
waypointBefore, | ||
waypointAfter, | ||
startTime, | ||
endTime, | ||
startDate, | ||
}) | ||
); | ||
} else { | ||
trackMessages.push( | ||
t('trackConflict', { | ||
waypointBefore, | ||
waypointAfter, | ||
startDate, | ||
endDate, | ||
startTime, | ||
endTime, | ||
}) | ||
); | ||
} | ||
}); | ||
|
||
const remainingTrackConflicts = trackConflictsData.length - 2; | ||
if (remainingTrackConflicts > 0) { | ||
trackMessages.push(t('remainingTrackConflicts', { count: remainingTrackConflicts })); | ||
} | ||
|
||
const workMessages: string[] = []; | ||
workConflictsData.slice(0, 2).forEach((conflict) => { | ||
const { waypointBefore, waypointAfter, startDate, endDate, startTime, endTime } = conflict; | ||
|
||
if (startDate === endDate) { | ||
workMessages.push( | ||
t('workConflictSameDay', { | ||
waypointBefore, | ||
waypointAfter, | ||
startDate, | ||
startTime, | ||
endTime, | ||
}) | ||
); | ||
} else { | ||
workMessages.push( | ||
t('workConflict', { | ||
waypointBefore, | ||
waypointAfter, | ||
startDate, | ||
startTime, | ||
endDate, | ||
endTime, | ||
}) | ||
); | ||
} | ||
}); | ||
|
||
const remainingWorkConflicts = workConflictsData.length - 2; | ||
if (remainingWorkConflicts > 0) { | ||
workMessages.push(t('remainingWorkConflicts', { count: remainingWorkConflicts })); | ||
} | ||
|
||
// Update the state with generated messages | ||
setTrackConflicts(trackMessages); | ||
setWorkConflicts(workMessages); | ||
}; | ||
|
||
generateConflictMessages(); | ||
}, [t, selectedSimulationOutput]); | ||
|
||
return { trackConflicts, workConflicts }; | ||
}; | ||
|
||
export default useConflictsMessages; |
Oops, something went wrong.