Skip to content

Add onURLBlur handler for InputField - #48854

Merged
cdcme merged 3 commits into
mainfrom
fix-40410-inconsistent-error-validation
Jul 7, 2026
Merged

Add onURLBlur handler for InputField#48854
cdcme merged 3 commits into
mainfrom
fix-40410-inconsistent-error-validation

Conversation

@cdcme

@cdcme cdcme commented Jul 7, 2026

Copy link
Copy Markdown
Member

Related issue: Resolves #40410

Checklist for submitter

  • Changes file added for user-visible changes in changes/. See Changes files for more information.
  • Input data is properly validated (webhook Destination URL is now validated on blur, matching the other URL fields in the app).

Testing

  • QA'd all new/changed functionality manually
qa-40410.webm

Summary by CodeRabbit

  • Bug Fixes
    • Improved “Destination URL” validation by checking the URL when the field loses focus and surfacing invalid webhook URLs immediately.
    • Validation and error display are now suppressed when vulnerability automations are disabled or when GitOps mode is enabled, preventing confusing blur-time errors.
  • Tests
    • Added automated coverage for blur-time URL validation, including typing/clearing behavior, valid vs empty states, and GitOps mode scenarios.

@cdcme
cdcme marked this pull request as ready for review July 7, 2026 13:40
@cdcme
cdcme requested a review from a team as a code owner July 7, 2026 13:40
Copilot AI review requested due to automatic review settings July 7, 2026 13:40

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.07%. Comparing base (7dfcb76) to head (a6b52b3).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #48854      +/-   ##
==========================================
+ Coverage   68.03%   68.07%   +0.04%     
==========================================
  Files        3689     3689              
  Lines      234205   234210       +5     
  Branches    12489    12341     -148     
==========================================
+ Hits       159347   159446      +99     
+ Misses      60543    60449      -94     
  Partials    14315    14315              
Flag Coverage Δ
frontend 59.22% <100.00%> (+0.27%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Warning

  • Copilot's review of this pull request may be incomplete because some of the changed files are excluded by your Copilot content exclusion settings. See Excluding content from Copilot for details.

Pull request overview

This PR updates the software automations “Manage automations” modal so the Webhook “Destination URL” field validates when the user leaves the field (on blur), matching the behavior of other URL inputs across the Fleet UI.

Changes:

  • Add an onURLBlur handler that runs validateWebhookURL(destinationUrl) and updates errors.url.
  • Wire the new handler into the Webhook “Destination URL” <InputField onBlur={...} />.

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated 1 comment.

File Description
frontend/pages/SoftwarePage/components/modals/ManageSoftwareAutomationsModal/ManageSoftwareAutomationsModal.tsx Adds on-blur URL validation for the webhook destination URL input.
changes/40410-webhook-url-validation-onblur.md User-visible change note (excluded from diff by policy; not reviewed).
Files excluded by content exclusion policy (1)
  • changes/40410-webhook-url-validation-onblur.md

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

@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8f233e49-1377-45b0-a06d-0a5eccf8e814

📥 Commits

Reviewing files that changed from the base of the PR and between 696029f and a6b52b3.

📒 Files selected for processing (2)
  • frontend/pages/SoftwarePage/components/modals/ManageSoftwareAutomationsModal/ManageSoftwareAutomationsModal.tests.tsx
  • frontend/pages/SoftwarePage/components/modals/ManageSoftwareAutomationsModal/ManageSoftwareAutomationsModal.tsx
🚧 Files skipped from review as they are similar to previous changes (2)
  • frontend/pages/SoftwarePage/components/modals/ManageSoftwareAutomationsModal/ManageSoftwareAutomationsModal.tests.tsx
  • frontend/pages/SoftwarePage/components/modals/ManageSoftwareAutomationsModal/ManageSoftwareAutomationsModal.tsx

Walkthrough

This change adds blur-based validation for the Destination URL field in ManageSoftwareAutomationsModal. The modal now runs validateWebhookURL(destinationUrl) in an onURLBlur handler when vulnerability automations are enabled, updates the url error state, and wires that handler to the input’s onBlur. Tests cover invalid, empty, and valid blur behavior plus error clearing after editing and GitOps mode handling.

Changes

Area Change
ManageSoftwareAutomationsModal.tsx Added onURLBlur and connected it to the Destination URL field
ManageSoftwareAutomationsModal.tests.tsx Added interaction tests for blur-time URL validation and GitOps mode

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant DestinationURLField
  participant onURLBlur
  participant errorsState

  User->>DestinationURLField: blur event
  DestinationURLField->>onURLBlur: onBlur
  onURLBlur->>onURLBlur: check softwareAutomationsEnabled
  onURLBlur->>onURLBlur: validateWebhookURL(destinationUrl)
  onURLBlur->>errorsState: replace url error
  errorsState-->>DestinationURLField: render validation state
Loading

Estimated code review effort: Medium

Related issues: #40410 — Inconsistent "invalid URL" error handling.

Suggested labels: frontend, bug

Suggested reviewers: none identified

Poem

  • The URL waits at the gate,
  • Blur arrives to validate,
  • No need to save to learn its fate,
  • Errors speak when focus breaks.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding an onURLBlur handler for the input field.
Description check ✅ Passed The description covers the related issue, the validation change, testing, and a changes-file note.
Linked Issues check ✅ Passed The change implements the requested onBlur URL validation and adds tests for the reported invalid-URL behavior.
Out of Scope Changes check ✅ Passed The added blur validation, GitOps guard, and tests all align with the linked issue and expected fix.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-40410-inconsistent-error-validation

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
frontend/pages/SoftwarePage/components/modals/ManageSoftwareAutomationsModal/ManageSoftwareAutomationsModal.tsx (1)

230-238: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider consolidating duplicated validation/merge logic.

onURLBlur and handleSaveAutomation both call validateWebhookURL(destinationUrl) and merge the result into errors with slightly different merge patterns (omit + spread vs. conditional omit). Extracting a shared applyWebhookUrlErrors helper would reduce duplication and keep the two call sites in sync if validation logic changes.

♻️ Example consolidation
+  const applyWebhookUrlErrors = (webhookErrors: { [key: string]: string }) => {
+    setErrors((prevErrs) => ({ ...omit(prevErrs, "url"), ...webhookErrors }));
+  };
+
   const onURLBlur = () => {
     if (!softwareAutomationsEnabled) {
       return;
     }
     const { errors: webhookErrors } = validateWebhookURL(destinationUrl);
-    setErrors((prevErrs) => ({ ...omit(prevErrs, "url"), ...webhookErrors }));
+    applyWebhookUrlErrors(webhookErrors);
   };

Also applies to: 240-251

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@frontend/pages/SoftwarePage/components/modals/ManageSoftwareAutomationsModal/ManageSoftwareAutomationsModal.tsx`
around lines 230 - 238, The webhook URL validation and error-merging logic is
duplicated between onURLBlur and handleSaveAutomation in
ManageSoftwareAutomationsModal, so extract a shared helper such as
applyWebhookUrlErrors around validateWebhookURL(destinationUrl). Update both
call sites to use the helper consistently instead of each doing its own
omit/spread merge, keeping the error shape and behavior in sync if validation
changes.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@frontend/pages/SoftwarePage/components/modals/ManageSoftwareAutomationsModal/ManageSoftwareAutomationsModal.tsx`:
- Around line 230-238: The webhook URL validation and error-merging logic is
duplicated between onURLBlur and handleSaveAutomation in
ManageSoftwareAutomationsModal, so extract a shared helper such as
applyWebhookUrlErrors around validateWebhookURL(destinationUrl). Update both
call sites to use the helper consistently instead of each doing its own
omit/spread merge, keeping the error shape and behavior in sync if validation
changes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e0c99fed-0159-4204-bcdc-2583a24b99fe

📥 Commits

Reviewing files that changed from the base of the PR and between 88ee1fe and 2136a4e.

⛔ Files ignored due to path filters (1)
  • changes/40410-webhook-url-validation-onblur.md is excluded by !**/*.md
📒 Files selected for processing (1)
  • frontend/pages/SoftwarePage/components/modals/ManageSoftwareAutomationsModal/ManageSoftwareAutomationsModal.tsx

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
frontend/pages/SoftwarePage/components/modals/ManageSoftwareAutomationsModal/ManageSoftwareAutomationsModal.tests.tsx (2)

47-106: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

No coverage for the disabled-field early return in onURLBlur.

Per the upstream handler (ManageSoftwareAutomationsModal.tsx:230-238), blur validation is skipped when softwareAutomationsEnabled is false. Consider adding a test with the webhook disabled to lock in that no error surfaces on blur in that state.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@frontend/pages/SoftwarePage/components/modals/ManageSoftwareAutomationsModal/ManageSoftwareAutomationsModal.tests.tsx`
around lines 47 - 106, Add test coverage for the disabled-state early return in
onURLBlur: when softwareAutomationsEnabled is false, blurring the destination
URL field should skip validation and not surface either INVALID_URL_ERROR or
REQUIRED_URL_ERROR. Extend the ManageSoftwareAutomationsModal tests by rendering
the modal in the disabled webhook state and asserting no error appears after
blur, using the existing renderModal helper and URL placeholder assertions for
location.

55-104: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Prefer accessible queries over getByPlaceholderText.

Placeholder text is presentational and can change independently of the field's semantics; querying by label/role (e.g. getByLabelText(/destination url/i)) is more resilient and better reflects how users/assistive tech identify the field.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@frontend/pages/SoftwarePage/components/modals/ManageSoftwareAutomationsModal/ManageSoftwareAutomationsModal.tests.tsx`
around lines 55 - 104, Update the ManageSoftwareAutomationsModal tests to query
the URL field via an accessible selector instead of getByPlaceholderText;
replace uses of URL_PLACEHOLDER in these cases with a label- or role-based query
that matches the field’s accessible name (for example, the destination URL
label). Keep the existing validation assertions unchanged and update any related
test helpers in ManageSoftwareAutomationsModal.tests.tsx to use the same
accessible lookup consistently.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@frontend/pages/SoftwarePage/components/modals/ManageSoftwareAutomationsModal/ManageSoftwareAutomationsModal.tests.tsx`:
- Around line 47-106: Add test coverage for the disabled-state early return in
onURLBlur: when softwareAutomationsEnabled is false, blurring the destination
URL field should skip validation and not surface either INVALID_URL_ERROR or
REQUIRED_URL_ERROR. Extend the ManageSoftwareAutomationsModal tests by rendering
the modal in the disabled webhook state and asserting no error appears after
blur, using the existing renderModal helper and URL placeholder assertions for
location.
- Around line 55-104: Update the ManageSoftwareAutomationsModal tests to query
the URL field via an accessible selector instead of getByPlaceholderText;
replace uses of URL_PLACEHOLDER in these cases with a label- or role-based query
that matches the field’s accessible name (for example, the destination URL
label). Keep the existing validation assertions unchanged and update any related
test helpers in ManageSoftwareAutomationsModal.tests.tsx to use the same
accessible lookup consistently.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7ae4f086-aefd-412c-8938-6c5888c66c1f

📥 Commits

Reviewing files that changed from the base of the PR and between 2136a4e and 696029f.

📒 Files selected for processing (1)
  • frontend/pages/SoftwarePage/components/modals/ManageSoftwareAutomationsModal/ManageSoftwareAutomationsModal.tests.tsx

};

const onURLBlur = () => {
// Skip validation whenever the field is disabled (automations off or GitOps

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Going to note that this should be a documented pattern

expect(urlInput).toBeDisabled();

// The field is read-only in GitOps mode, so a blur must not surface an error.
fireEvent.blur(urlInput);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

TODO @RachelElysia: update docs/Contributing/guides/ui/fleet-ui-testing.md to explicitly state the userEvent-over-fireEvent convention examples already demonstrate const { user } = renderWithSetup(...), but there's no prose rule. Add a short note covering when fireEvent is still warranted (events with no user-gesture equivalent like scroll/resize/visibilitychange, and defense-in-depth guard tests like blurring a disabled input).

@cdcme
cdcme merged commit d85dd50 into main Jul 7, 2026
25 of 27 checks passed
@cdcme
cdcme deleted the fix-40410-inconsistent-error-validation branch July 7, 2026 15:52

@RachelElysia RachelElysia left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks like it's not building because of test type errors

cdcme added a commit that referenced this pull request Jul 28, 2026
…p) (#49932)

<!-- Add the related story/sub-task/bug number, like Resolves #123, or
remove if NA -->
**Related issue:** Resolves #40410

Follow-up to #48854, which added on-blur validation to the software
vulnerability automations webhook. QA found three more forms with
inconsistent validation, in two flavors:

- **Validated only on save** (no on-blur feedback): Policies > Manage
automations > Other workflows > Destination URL.
- **Errored before any input** (validation fired on mount/enable):
Settings > Users > Add/edit user > Email, and the host status webhook
Destination URL (both global and fleet settings).

This makes them consistent with the rest of the app: no error on
open/enable → validate on blur → clear the field's error as the user
edits → validate on submit.

- `OtherWorkflowsModal` — added an on-blur handler for the Destination
URL (guarded by the field's disabled condition).
- `UserForm` — on-blur now validates only the blurred field (so blurring
the autofocused Name no longer flags the empty Email/Password); submit
validates all fields.
- `GlobalHostStatusWebhook` — removed the `useEffect` that validated the
moment the webhook was enabled; validation now runs on blur and submit.
- `TeamSettings` (fleet host status webhook) — the Destination URL error
is no longer surfaced on change/enable; it validates on blur and submit.

# Checklist for submitter

- [x] Changes file added for user-visible changes in `changes/`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files)
for more information.
- [x] Input data is properly validated (URL and email fields validate on
blur and on submit; no errors are shown before the user interacts).

## Testing

- [x] Added/updated automated tests
- [x] QA'd all new/changed functionality manually


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Bug Fixes**
* Improved webhook destination URL validation across integrations, team
settings, and workflow automation forms.
* Validation messages now appear after leaving the URL field, rather
than prematurely while enabling or editing.
* Prevented saving or submitting forms with missing or invalid
destination URLs.
  * Correctly clears validation errors once a valid URL is entered.
* Improved user form validation so field-specific errors appear only for
the field being reviewed, while submit continues to validate the full
form.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
cdcme added a commit that referenced this pull request Jul 29, 2026
…rms (#40410 follow-up) (#50129)

Cherry-pick of #49932 into the 4.90 RC branch.

Second of two PRs for #40410. The first (#48854) is already present in
`rc-minor-fleet-v4.90.0` (merged before the branch was cut); this brings
in the follow-up so the fix ships complete in 4.90.

Applied cleanly with no conflicts.
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.

Inconsistent "invalid URL" error handling in forms/modals

3 participants