Skip to content

[UI][Admin Portal] Improve validation feedback in Governance Action Dialog#1314

Open
Perera1325 wants to merge 1 commit into
wso2:mainfrom
Perera1325:fix/governance-ui-validation
Open

[UI][Admin Portal] Improve validation feedback in Governance Action Dialog#1314
Perera1325 wants to merge 1 commit into
wso2:mainfrom
Perera1325:fix/governance-ui-validation

Conversation

@Perera1325
Copy link
Copy Markdown

@Perera1325 Perera1325 commented Apr 11, 2026

Problem

In the Admin Portal governance policy configuration, the "Action Configuration" dialog disables the "Save" button when mandatory fields (like "Governed State") are missing, but it fails to provide visual feedback or error messages to the user. This creates a confusing user experience where the user has to guess why they cannot proceed.

Solution

Implemented inline validation feedback for the "Governed State" field:

  • Added isSubmitted state to track when the user first attempts to save.
  • Updated FormControl to display an error state and a FormHelperText when validation fails.
  • Used FormattedMessage for localized error messages, adhering to WSO2 standards.

Impact

Improves the usability and self-service capability of the Governance features in the Admin Portal by providing immediate, clear feedback during configuration.

Summary by CodeRabbit

  • Bug Fixes
    • Form validation now properly prevents saving when required fields are empty.
    • Visual error indicators are displayed for unfilled required fields during submission attempts.
    • Added helpful messages to guide users when completing the form.

Copilot AI review requested due to automatic review settings April 11, 2026 07:12
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 11, 2026

Walkthrough

A single-file change to ActionConfigDialog.jsx that adds form validation to the save workflow. Introduces an isSubmitted state flag and modifies the save handler to prevent form submission when validation fails, while displaying error states and helper text on invalid fields.

Changes

Cohort / File(s) Summary
Form Validation Enhancement
portals/admin/src/main/webapp/source/src/app/components/Governance/Policies/ActionConfigDialog.jsx
Added FormHelperText import and isSubmitted state. Modified handleSave to validate form before saving; prevents save/close operations if validation fails. Enhanced governedState FormControl to display error styling and required-field helper message when submitted but empty.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A dialog now validates with care,
No saving when the fields are bare,
With error states so clearly shown,
The form's new strictness has been grown,
Submit with confidence, declare! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: improving validation feedback in the Governance Action Dialog. It directly relates to the implementation of inline validation with FormHelperText and error states.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds inline validation feedback to the Admin Portal Governance “Action Configuration” dialog so users understand why “Save” can’t proceed when required fields are missing.

Changes:

  • Introduces an isSubmitted state flag to drive validation UI after a save attempt.
  • Marks the “Governed State” FormControl as error and shows a localized FormHelperText when missing.
Comments suppressed due to low confidence (1)

portals/admin/src/main/webapp/source/src/app/components/Governance/Policies/ActionConfigDialog.jsx:60

  • isSubmitted is set to true on a failed save attempt, but it’s never reset when the dialog is closed or reopened (or when switching between create/edit via editAction). This can cause the field to render in an error state immediately on the next open. Reset isSubmitted in handleClose and/or in an effect keyed on open/editAction.
    const [isSubmitted, setIsSubmitted] = useState(false);

    useEffect(() => {
        setFormState(editAction || {
            governedState: '',
            actions: {

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 80 to 86
const handleSave = () => {
onSave(formState);
handleClose(); // Reset the form after saving
setIsSubmitted(true);
if (isValid()) {
onSave(formState);
handleClose(); // Reset the form after saving
}
};
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handleSave sets isSubmitted to true to trigger validation UI, but the Save button is still disabled={!isValid()} (later in this component). When the form is invalid, the button can’t be clicked, so handleSave never runs and the inline error will never appear. Consider keeping Save enabled and gating the actual save inside handleSave, or change the disabled logic so the first click is allowed to set isSubmitted and show errors.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@portals/admin/src/main/webapp/source/src/app/components/Governance/Policies/ActionConfigDialog.jsx`:
- Line 55: The isSubmitted state in ActionConfigDialog.jsx can stay true across
dialog sessions; reset it whenever the dialog closes or is reset by calling
setIsSubmitted(false) in the dialog close/reset flow (e.g., in the onClose
handler and/or the form reset logic) and/or add a useEffect that watches the
dialog open prop to clear isSubmitted when open becomes false or when reopening;
update the functions that reset the form or handle dialog close (the component's
onClose, resetForm, or similar handlers referenced in ActionConfigDialog) to
call setIsSubmitted(false).
- Around line 81-85: The Save button is currently disabled when the form is
invalid so users can never trigger handleSave and setIsSubmitted(true), blocking
inline validation; fix by making the primary Save button enabled (remove or
change the disabled prop that uses isValid()) and ensure handleSave starts with
setIsSubmitted(true) and then returns early if !isValid(), keeping
onSave(formState) and handleClose() only when valid; update references in the
component to handleSave, isValid, isSubmitted and the Save button render so
validation state is exposed on first save attempt.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ff6b7b6a-072c-4fe1-a053-5b75e9a336b2

📥 Commits

Reviewing files that changed from the base of the PR and between 9ec2ed2 and 6986ca2.

📒 Files selected for processing (1)
  • portals/admin/src/main/webapp/source/src/app/components/Governance/Policies/ActionConfigDialog.jsx

info: CONSTS.GOVERNANCE_ACTIONS.NOTIFY,
},
});
const [isSubmitted, setIsSubmitted] = useState(false);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Reset isSubmitted when the dialog is closed/reset.

isSubmitted can remain true across 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
Verify each finding against the current code and only fix it if needed.

In
`@portals/admin/src/main/webapp/source/src/app/components/Governance/Policies/ActionConfigDialog.jsx`
at line 55, The isSubmitted state in ActionConfigDialog.jsx can stay true across
dialog sessions; reset it whenever the dialog closes or is reset by calling
setIsSubmitted(false) in the dialog close/reset flow (e.g., in the onClose
handler and/or the form reset logic) and/or add a useEffect that watches the
dialog open prop to clear isSubmitted when open becomes false or when reopening;
update the functions that reset the form or handle dialog close (the component's
onClose, resetForm, or similar handlers referenced in ActionConfigDialog) to
call setIsSubmitted(false).

Comment on lines +81 to +85
setIsSubmitted(true);
if (isValid()) {
onSave(formState);
handleClose(); // Reset the form after saving
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Validation feedback path is blocked by the disabled Save button.

isSubmitted is set only in handleSave, but invalid forms cannot call handleSave because Save is disabled (Line 280). This prevents the new inline error state from appearing in the primary invalid path.

💡 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
Verify each finding against the current code and only fix it if needed.

In
`@portals/admin/src/main/webapp/source/src/app/components/Governance/Policies/ActionConfigDialog.jsx`
around lines 81 - 85, The Save button is currently disabled when the form is
invalid so users can never trigger handleSave and setIsSubmitted(true), blocking
inline validation; fix by making the primary Save button enabled (remove or
change the disabled prop that uses isValid()) and ensure handleSave starts with
setIsSubmitted(true) and then returns early if !isValid(), keeping
onSave(formState) and handleClose() only when valid; update references in the
component to handleSave, isValid, isSubmitted and the Save button render so
validation state is exposed on first save attempt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants