-
Notifications
You must be signed in to change notification settings - Fork 45
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: rename and refacto StdcmInputVia #10218
Open
clarani
wants to merge
3
commits into
dev
Choose a base branch
from
cni/refacto-stdcm-input-via
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+79
−76
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
60 changes: 0 additions & 60 deletions
60
front/src/applications/stdcm/components/StdcmForm/StdcmInputVia.tsx
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
75 changes: 75 additions & 0 deletions
75
front/src/applications/stdcm/components/StdcmForm/StopDurationInput.tsx
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,75 @@ | ||
import { useMemo, useEffect, useState } from 'react'; | ||
|
||
import { Input } from '@osrd-project/ui-core'; | ||
import type { Status } from '@osrd-project/ui-core/dist/components/inputs/StatusMessage'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import { useOsrdConfActions } from 'common/osrdContext'; | ||
import type { StdcmConfSliceActions } from 'reducers/osrdconf/stdcmConf'; | ||
import type { StdcmPathStep } from 'reducers/osrdconf/types'; | ||
import { useAppDispatch } from 'store'; | ||
import { useDebounce } from 'utils/helpers'; | ||
|
||
import { StdcmStopTypes } from '../../types'; | ||
|
||
type StopDurationInputProps = { | ||
pathStep: Extract<StdcmPathStep, { isVia: true }>; | ||
}; | ||
|
||
const StopDurationInput = ({ pathStep }: StopDurationInputProps) => { | ||
const dispatch = useAppDispatch(); | ||
const { t } = useTranslation('stdcm'); | ||
|
||
const { updateStdcmPathStep } = useOsrdConfActions() as StdcmConfSliceActions; | ||
|
||
const [stopDuration, setStopDuration] = useState(''); | ||
const debouncedStopDuration = useDebounce(stopDuration, 300); | ||
|
||
const stopWarning = useMemo( | ||
() => | ||
pathStep.stopType === StdcmStopTypes.DRIVER_SWITCH && | ||
pathStep.stopFor !== undefined && | ||
pathStep.stopFor < 3 | ||
? { | ||
status: 'warning' as Status, | ||
message: t('trainPath.warningMinStopTime'), | ||
} | ||
: undefined, | ||
[pathStep.stopType, pathStep.stopFor] | ||
); | ||
useEffect(() => { | ||
setStopDuration(pathStep.stopFor !== undefined ? `${pathStep.stopFor}` : ''); | ||
}, [pathStep.stopFor]); | ||
|
||
useEffect(() => { | ||
const newStopDuration = debouncedStopDuration ? Number(debouncedStopDuration) : undefined; | ||
if (newStopDuration !== pathStep.stopFor) { | ||
dispatch( | ||
updateStdcmPathStep({ | ||
id: pathStep.id, | ||
updates: { stopFor: newStopDuration }, | ||
}) | ||
); | ||
} | ||
}, [debouncedStopDuration]); | ||
|
||
return ( | ||
<div className="stop-time"> | ||
<Input | ||
id="stdcm-via-stop-time" | ||
type="text" | ||
label={t('trainPath.stopFor')} | ||
onChange={(e) => { | ||
// TODO: Find a better way to prevent user from entering decimal values | ||
const value = e.target.value.replace(/[\D.,]/g, ''); | ||
setStopDuration(value); | ||
}} | ||
value={stopDuration} | ||
trailingContent="minutes" | ||
statusWithMessage={stopWarning} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default StopDurationInput; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it would be better to don't automatically replace value with a regex and warn the user that the value can't be used.
Because if I put
3.5
, it compute35
and if i don't pay attention, i will launch the simulation using a35
minutes stopThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So you can make a handleChange function, that will turn a flag and display a warning if the value don't respect the expexted value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another solution would be to round up or down the value to keep minutes only, but this need to be discuss
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This portion of code is not related to my PR, can we discuss this later ? :/
We won't forget it since there is already a TODO comment above the problematic lines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following Mathieu's invitation, here is my user experience comment. This behaviour is problematic as the change is difficult to spot (a little larger letter spacing and a dot) and could affect results.
That said, we haven't witnessed users entering decimal values during our tests.
As there would be no way for us to know if users get this problem or not, I'm inviting POs to prioritize the issue as high, especially since we currently don't have the possibility to cancel computations.