-
Notifications
You must be signed in to change notification settings - Fork 196
[UI][Admin Portal] Improve validation feedback in Governance Action Dialog #1314
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
base: main
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 |
|---|---|---|
|
|
@@ -34,6 +34,7 @@ import { | |
| Radio, | ||
| Grid, | ||
| Alert, | ||
| FormHelperText, | ||
| } from '@mui/material'; | ||
| import InfoOutlinedIcon from '@mui/icons-material/InfoOutlined'; | ||
| import { FormattedMessage, useIntl } from 'react-intl'; | ||
|
|
@@ -51,6 +52,7 @@ export default function ActionConfigDialog({ | |
| info: CONSTS.GOVERNANCE_ACTIONS.NOTIFY, | ||
| }, | ||
| }); | ||
| const [isSubmitted, setIsSubmitted] = useState(false); | ||
|
|
||
| useEffect(() => { | ||
| setFormState(editAction || { | ||
|
|
@@ -76,8 +78,11 @@ export default function ActionConfigDialog({ | |
| }; | ||
|
|
||
| const handleSave = () => { | ||
| onSave(formState); | ||
| handleClose(); // Reset the form after saving | ||
| setIsSubmitted(true); | ||
| if (isValid()) { | ||
| onSave(formState); | ||
| handleClose(); // Reset the form after saving | ||
| } | ||
|
Comment on lines
+81
to
+85
Contributor
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. Validation feedback path is blocked by the disabled Save button.
💡 Proposed fix const handleSave = () => {
setIsSubmitted(true);
- if (isValid()) {
- onSave(formState);
- handleClose(); // Reset the form after saving
- }
+ if (!isValid()) {
+ return;
+ }
+ onSave(formState);
+ handleClose(); // Reset the form after saving
};
...
<Button
onClick={handleSave}
variant='contained'
color='primary'
- disabled={!isValid()}
+ disabled={isSubmitted && !isValid()}
size='small'
>🤖 Prompt for AI Agents |
||
| }; | ||
|
Comment on lines
80
to
86
|
||
|
|
||
| const isValid = () => { | ||
|
|
@@ -101,7 +106,11 @@ export default function ActionConfigDialog({ | |
| </DialogTitle> | ||
| <DialogContent sx={{ p: 3 }}> | ||
| <Box mb={3} mt={1}> | ||
| <FormControl fullWidth size='small'> | ||
| <FormControl | ||
| fullWidth | ||
| size='small' | ||
| error={isSubmitted && !formState.governedState} | ||
| > | ||
| <InputLabel> | ||
| <FormattedMessage | ||
| id='Governance.Policies.AddEdit.enforcement.state.label' | ||
|
|
@@ -148,6 +157,14 @@ export default function ActionConfigDialog({ | |
| </MenuItem> | ||
| ))} | ||
| </Select> | ||
| {isSubmitted && !formState.governedState && ( | ||
| <FormHelperText> | ||
| <FormattedMessage | ||
| id='Governance.Policies.AddEdit.enforcement.state.required' | ||
| defaultMessage='This field is required' | ||
| /> | ||
| </FormHelperText> | ||
| )} | ||
| </FormControl> | ||
| </Box> | ||
|
|
||
|
|
||
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.
Reset
isSubmittedwhen the dialog is closed/reset.isSubmittedcan remaintrueacross opens, causing stale validation UI on subsequent dialog sessions.💡 Proposed fix
const handleClose = () => { + setIsSubmitted(false); setFormState({ governedState: '', actions: { error: CONSTS.GOVERNANCE_ACTIONS.NOTIFY, warn: CONSTS.GOVERNANCE_ACTIONS.NOTIFY, info: CONSTS.GOVERNANCE_ACTIONS.NOTIFY, }, }); onClose(); }; useEffect(() => { + setIsSubmitted(false); setFormState(editAction || { governedState: '', actions: { error: CONSTS.GOVERNANCE_ACTIONS.NOTIFY, warn: CONSTS.GOVERNANCE_ACTIONS.NOTIFY, info: CONSTS.GOVERNANCE_ACTIONS.NOTIFY, }, }); }, [editAction]);🤖 Prompt for AI Agents