-
Notifications
You must be signed in to change notification settings - Fork 46
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
lmr: add mandatory fields and error messages to the form #10271
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ const ConsistCardTitle = ({ | |
); | ||
}; | ||
|
||
const StdcmConsist = ({ disabled = false }: StdcmConfigCardProps) => { | ||
const StdcmConsist = ({ disabled = false, showErrors }: StdcmConfigCardProps) => { | ||
const { t } = useTranslation('stdcm'); | ||
const { speedLimitByTag, speedLimitsByTags, dispatchUpdateSpeedLimitByTag } = | ||
useStoreDataForSpeedLimitByTagSelector({ isStdcm: true }); | ||
|
@@ -65,6 +65,12 @@ const StdcmConsist = ({ disabled = false }: StdcmConfigCardProps) => { | |
filters: towedRsFilters, | ||
} = useFilterTowedRollingStock(); | ||
|
||
const isTractionEngineEmpty = !filters.text.trim(); | ||
const isTowedRollingStockEmpty = !towedRsFilters.text.trim(); | ||
const isTotalMassEmpty = totalMass === undefined || totalMass === null; | ||
const isTotalLengthEmpty = totalLength === undefined || totalLength === null; | ||
const isMaxSpeedEmpty = maxSpeed === undefined || maxSpeed === null; | ||
Comment on lines
+70
to
+72
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can’t we use the same function for all number fields? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, you're right, it would be clearer. I will change this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could use |
||
|
||
useEffect(() => { | ||
if (towedRollingStock) { | ||
searchTowedRollingStock(towedRollingStock.name); | ||
|
@@ -128,6 +134,11 @@ const StdcmConsist = ({ disabled = false }: StdcmConfigCardProps) => { | |
suggestions={filteredRollingStockList} | ||
getSuggestionLabel={(suggestion: LightRollingStockWithLiveries) => getLabel(suggestion)} | ||
onSelectSuggestion={onSelectSuggestion} | ||
statusWithMessage={ | ||
showErrors && isTractionEngineEmpty | ||
? { tooltip: 'left', status: 'error', message: t('form.missingValue') } | ||
: undefined | ||
} | ||
/> | ||
</div> | ||
<div className="towed-rolling-stock"> | ||
|
@@ -154,6 +165,11 @@ const StdcmConsist = ({ disabled = false }: StdcmConfigCardProps) => { | |
prefillConsist(rollingStock, towed, speedLimitByTag); | ||
dispatch(updateTowedRollingStockID(towed?.id)); | ||
}} | ||
statusWithMessage={ | ||
showErrors && isTowedRollingStockEmpty | ||
? { tooltip: 'left', status: 'error', message: t('form.missingValue') } | ||
: undefined | ||
} | ||
/> | ||
</div> | ||
<div className="stdcm-consist__properties"> | ||
|
@@ -166,6 +182,11 @@ const StdcmConsist = ({ disabled = false }: StdcmConfigCardProps) => { | |
value={totalMass ?? ''} | ||
onChange={onTotalMassChange} | ||
disabled={disabled} | ||
statusWithMessage={ | ||
showErrors && isTotalMassEmpty | ||
? { tooltip: 'left', status: 'error', message: t('form.missingValue') } | ||
: undefined | ||
} | ||
/> | ||
<Input | ||
id="length" | ||
|
@@ -176,6 +197,11 @@ const StdcmConsist = ({ disabled = false }: StdcmConfigCardProps) => { | |
value={totalLength ?? ''} | ||
onChange={onTotalLengthChange} | ||
disabled={disabled} | ||
statusWithMessage={ | ||
showErrors && isTotalLengthEmpty | ||
? { tooltip: 'left', status: 'error', message: t('form.missingValue') } | ||
: undefined | ||
} | ||
/> | ||
</div> | ||
<div className="stdcm-consist__properties"> | ||
|
@@ -194,6 +220,11 @@ const StdcmConsist = ({ disabled = false }: StdcmConfigCardProps) => { | |
value={maxSpeed ?? ''} | ||
onChange={onMaxSpeedChange} | ||
disabled={disabled} | ||
statusWithMessage={ | ||
showErrors && isMaxSpeedEmpty | ||
? { tooltip: 'left', status: 'error', message: t('form.missingValue') } | ||
: undefined | ||
} | ||
/> | ||
</div> | ||
</StdcmCard> | ||
|
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.
Instead of that, I think you could use the same logic than @Wadjetz in his consist PR (in StdcmConfig). We could have one object having boolean properties for each required fields changing when these fields changes.
We should also
setShowError(false)
as soon as the field changes.