Skip to content

feat(ssh): open the host add/edit form in a modal dialog (STA-3067) - #12172

Merged
AmethystLiang merged 5 commits into
mainfrom
jinjing/sta-3067-feature-open-the-ssh-host-addedit-form-in-a-modal-dialog-so
Aug 3, 2026
Merged

AmethystLiang merged 5 commits into
mainfrom
jinjing/sta-3067-feature-open-the-ssh-host-addedit-form-in-a-modal-dialog-so

Conversation

@AmethystLiang

@AmethystLiang AmethystLiang commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #11709

Summary

The SSH host add/edit form used to mount inline underneath the host list in Settings → SSH Hosts. Once you had more than a handful of hosts, opening it pushed the fields below the fold — you had to scroll past the whole list to reach Host, Advanced, and Save. It now opens in a modal dialog instead.

  • Viewport-stable. Sticky header and footer; only the field region scrolls, so the title and the Save/Cancel actions stay on screen even with Advanced expanded.
  • Editing context chip. The edit dialog shows the target's label and user@host:port so it's clear which host you're changing.
  • Accidental-dismiss protection. An outside click on a dirty form is ignored; Escape, Cancel, and × stay explicit discard paths. An untouched form dismisses normally.
  • Advanced resets per session. Advanced auto-expands only when the target actually has proxy/jump/reuse values set, and no longer leaks its open state across cancel → reopen.
  • Duplicate-save guard. The submit button is disabled and the Enter path is gated while a save is in flight, so a double click can't write two targets.
  • The Add Target button now stays visible while the dialog is open (the inline form used to hide it).

The add-ssh-host settings deep link opens the same dialog. New strings are in the catalog for en/es/ja/ko/zh.

Screenshots

Pending. Needs a capture of the add and edit dialogs — including Advanced expanded over a long host list — before merge.

Testing

  • pnpm lint — not run in full. Ran oxlint (default config and config/oxlint-react-doctor.json) over the changed files, oxfmt --check, check:max-lines-ratchet, verify:localization-catalog, and verify:localization-extraction. All clean.
  • pnpm typecheck — ran typecheck:web (clean). The node/cli projects don't include these files; not run.
  • pnpm test — not run in full. Ran the settings scope: 138 files / 924 tests passed.
  • pnpm build — not run.
  • Added or updated high-quality tests that would catch regressions:
    • SshTargetForm.test.tsx — dialog chrome and sticky header/footer regions, edit-mode chip, Advanced reset across cancel → reopen, submit gating while saving, and clean-session outside dismissal.
    • ssh-target-draft.test.ts — table-driven dirty check across all 11 editable fields, so dropping a comparison (which would silently discard unsaved edits on outside click) fails the suite.
    • tests/e2e/ssh-host-form-modal.spec.ts — end-to-end add + edit over a seeded 10-host list: viewport assertions on header/footer with Advanced expanded, dirty outside-click preserving the draft, Advanced reset on reopen, and the deep-link intent path.

The e2e spec has not been executed — it compiles and lists under --project=electron-headless, but a full Electron e2e run wasn't possible in this environment. It needs a green CI run.

AI Review Report

Reviewed by CodeRabbit and Greptile on the branch; the 7 threads were triaged and fixed with Claude Code in 4135bfd.

Fixed:

  1. (Major) Double-clicking submit fired two addTarget/updateTarget IPC calls, creating duplicate hosts. Added a saving flag that both disables the button and gates the form's onSubmit (a disabled button doesn't block Enter).
  2. (P1) preventOutsideDismiss captured isDirty from the render closure. When an edit session starts, the effect rewrites baselineRef.current, but for the typical non-advanced target setAdvancedOpen is called with the value it already holds, React bails out, and no re-render happens — so the handler kept a stale isDirty === true and refused to dismiss a freshly opened, untouched edit dialog. Now both refs are read at call time. Verified the new regression test fails against the old code and passes against the fix.
  3. (P2) form in the effect dep array re-ran the effect on every keystroke. Deps narrowed to [open, editingId], with the draft read through a ref.
  4. (Minor) The e2e HOST_PREFIX derived from Date.now() alone could collide between Playwright workers, whose afterEach deletes every target matching the prefix — one worker could delete another's fixtures. Added a random suffix.
  5. (Minor) locator.isVisible({ timeout }) is one-shot and ignores its timeout, so the announcement dismissal could miss a late-rendering button. Switched to a retrying expect(...).toBeVisible().
  6. (Minor) Spanish grammar: multiplexación is feminine (Desactívalo → Desactiva esta opción) and a la que puedas iniciar sesión → en la que.
  7. (Trivial) The e2e located host cards by Tailwind classes (div.rounded-lg.border). Added data-ssh-target-card / data-ssh-target-label to SshTargetCard and locate by those.

Not actionable: one Major claimed the zh (and other) locales were missing the new SshTargetForm keys. Those keys had already landed in e5016e0b/6b6bb35b, and the auto.actions.updateTarget.description key it cited is referenced nowhere in the repo.

Knock-on change: adding the saving state pushed SshPane.tsx past the 400-line oxlint max-lines budget. AGENTS.md forbids disabling or baselining that rule, so terminateSessionsWithReconnect moved verbatim into ssh-session-termination.ts. No behaviour change.

Cross-platform (macOS / Linux / Windows): explicitly checked. The diff is renderer-only and introduces no metaKey/ctrlKey handling, no shortcut labels, no filesystem path construction, no shell invocation, and no Electron main-process code or platform branches. Dialog behaviour comes from the existing shadcn/Radix Dialog primitive already shipping on all three platforms. The single keyboard path touched — Enter submitting the form — is platform-neutral.

Security Audit

  • No IPC surface change. Nothing under src/main, src/preload, or src/shared is touched; no new channels, handlers, or permissions. Saves still go through the existing window.api.ssh.addTarget / updateTarget with the pre-existing buildSshTargetSavePayload validation.
  • Input handling: host, proxyCommand, jumpHost, and identityFile remain the same user-supplied fields parsed by the same ssh-target-draft helpers. The modal only changes where they're rendered.
  • No command execution or path construction is added anywhere in the diff.
  • No secrets exposure. Nothing is logged. The editing chip renders user@host:port, which the host card already displays; no key material, passphrase, or credential is read or rendered.
  • Write amplification reduced, not increased: the duplicate-submit guard strictly lowers the number of writes a single draft can produce.
  • Test hygiene: the e2e spec seeds hosts under a randomized e2e-ssh-modal-* label prefix and its cleanup deletes only labels carrying that prefix.
  • No follow-up needed.

Notes

  • Renderer-only; no platform-specific behaviour and no main-process changes.
  • This is the SSH host management surface itself. Folder workspaces and git worktrees are unaffected — no workspace, Git, or execution-host code paths are touched.
  • Before merge: attach screenshots, and get a green CI run of tests/e2e/ssh-host-form-modal.spec.ts.

Form moves from inline to a viewport-stable modal (STA-3067) so fields stay
accessible with long host lists. Includes sticky header/footer, dirty-state
protection against outside click, and session-aware Advanced state reset on
cancel/reopen.
@coderabbitai

coderabbitai Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 67bdac4d-fa04-4e65-b1ff-205394e1761c

📥 Commits

Reviewing files that changed from the base of the PR and between 4135bfd and 0731e38.

📒 Files selected for processing (1)
  • src/renderer/src/components/settings/SshTargetForm.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/renderer/src/components/settings/SshTargetForm.tsx

📝 Walkthrough

Walkthrough

The SSH target form now uses a controlled modal for add and edit operations. The modal tracks unsaved changes, blocks accidental outside dismissal, resets session state on close, and manages advanced-field visibility. The SSH pane prevents concurrent saves, uses shared session termination logic, and keeps the Add Target button visible. New localization, component tests, and end-to-end tests cover the modal workflow and settings intent.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the primary user-visible change: moving the SSH host add/edit form into a modal dialog.
Description check ✅ Passed The description covers the required sections, user-visible behavior, testing, review, security, and platform checks, while clearly noting pending screenshots and e2e execution.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

Sync en.json catalog for modal title/description strings so
verify:localization-catalog passes in static analysis.

@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.

Actionable comments posted: 4

🧹 Nitpick comments (2)
src/renderer/src/components/settings/ssh-target-draft.test.ts (1)

254-259: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Cover every field in the dirty comparison.

The test exercises host and systemSshConnectionReuse only. isSshTargetFormDirty compares 11 fields. If a comparison is dropped for one of the other fields, an outside click discards unsaved edits and no test fails. A table-driven case keeps coverage aligned with EditingTarget.

♻️ Table-driven coverage for all editable fields
   it('detects field changes against the open-session baseline', () => {
-    expect(isSshTargetFormDirty({ ...EMPTY_FORM, host: 'box' }, EMPTY_FORM)).toBe(true)
-    expect(
-      isSshTargetFormDirty({ ...EMPTY_FORM, systemSshConnectionReuse: false }, EMPTY_FORM)
-    ).toBe(true)
+    const changes: Partial<Record<keyof typeof EMPTY_FORM, unknown>>[] = [
+      { label: 'box' },
+      { configHost: 'alias' },
+      { host: 'box' },
+      { port: '2222' },
+      { username: 'deploy' },
+      { identityFile: '~/.ssh/id_ed25519' },
+      { proxyCommand: 'nc %h %p' },
+      { jumpHost: 'bastion' },
+      { systemSshConnectionReuse: false },
+      { relayGracePeriodSeconds: '600' },
+      { relayKeepAliveUntilReset: false }
+    ]
+    for (const change of changes) {
+      expect(isSshTargetFormDirty({ ...EMPTY_FORM, ...change }, EMPTY_FORM)).toBe(true)
+    }
   })
tests/e2e/ssh-host-form-modal.spec.ts (1)

152-154: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Replace the Tailwind class locator with a stable selector.

div.rounded-lg.border targets presentation classes on SshTargetCard. A styling change breaks this test with a confusing failure. Add a data-testid or a data-ssh-target-id attribute to the card and locate by that attribute.

♻️ Proposed change

Add the attribute on the card root in src/renderer/src/components/settings/SshTargetCard.tsx:

<div data-ssh-target-card="" data-ssh-target-label={target.label} className="rounded-lg border ...">

Then locate by it:

-    const createdCard = sshSection.locator('div.rounded-lg.border').filter({
-      has: orcaPage.getByText(createdLabel, { exact: true })
-    })
+    const createdCard = sshSection.locator(
+      `[data-ssh-target-card][data-ssh-target-label="${createdLabel}"]`
+    )

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 09329e30-dd49-44f4-bbe6-35842f89cb22

📥 Commits

Reviewing files that changed from the base of the PR and between 45a78e1 and 875db78.

📒 Files selected for processing (6)
  • src/renderer/src/components/settings/SshPane.tsx
  • src/renderer/src/components/settings/SshTargetForm.test.tsx
  • src/renderer/src/components/settings/SshTargetForm.tsx
  • src/renderer/src/components/settings/ssh-target-draft.test.ts
  • src/renderer/src/components/settings/ssh-target-draft.ts
  • tests/e2e/ssh-host-form-modal.spec.ts

Comment thread tests/e2e/ssh-host-form-modal.spec.ts Resolved
Comment thread tests/e2e/ssh-host-form-modal.spec.ts Resolved
@greptile-apps

greptile-apps Bot commented Aug 3, 2026 •

Copy link
Copy Markdown

Greptile Summary

This PR converts the SSH host add/edit form from an inline element beneath the host list into a viewport-stable modal dialog, so fields remain accessible regardless of how long the list is. Alongside the layout change it adds accidental-dismiss protection (dirty-check via isSshTargetFormDirty), a duplicate-submit guard (saving flag gating both the button and the Enter path), an editing-context chip in the header, and per-session Advanced-section state reset.

  • Modal dialog with sticky chrome (SshTargetForm.tsx): wraps the existing fields in a Radix Dialog with overflow-hidden content, a shrink-0 header/footer, and a scrollable body; onPointerDownOutside/onInteractOutside call preventOutsideDismiss, which reads the current and baseline form via refs so the handler is never stale.
  • Saving guard (SshPane.tsx): saving state disables the submit button and also gates onSubmit so a keyboard Enter cannot bypass the disabled state; reset is done in finally with a mountedRef check.
  • Extraction and tests: terminateSshSessionsWithReconnect moves verbatim to ssh-session-termination.ts to stay under the oxlint line budget; SshTargetForm.test.tsx and ssh-target-draft.test.ts add unit coverage for the new dialog chrome, dirty-check completeness, Advanced reset, and save gating; an unexecuted E2E spec covers the end-to-end add/edit flow.

Confidence Score: 5/5

Renderer-only change with no IPC surface changes; the existing save/validate path is unchanged and the new modal wrapping is well-tested.

The core logic — dirty-check baseline via refs, saving guard in both onSubmit and the button, session-scoped Advanced reset — is correctly implemented and each path is covered by a unit test. The one edge case worth noting is that Escape is not blocked while a save is in-flight, so a very fast Escape-then-reopen sequence could let the success path's setShowForm(false) close a newly-opened form session; however, the IPC window is typically sub-10 ms for a local disk write and the sequence requires deliberate unusual user action, making it a low-urgency hardening opportunity rather than a blocking issue.

Files Needing Attention: The stale-success-path concern is in SshPane.tsx around handleSave; the other files are clean.

Important Files Changed

Filename Overview
src/renderer/src/components/settings/SshPane.tsx Adds saving state to gate the submit button and Enter path; extracts terminateSessionsWithReconnect to a shared module; moves SshTargetForm outside conditional rendering as a controlled modal. The success path's state-reset calls are not session-scoped, creating a narrow race when Escape is pressed mid-save.
src/renderer/src/components/settings/SshTargetForm.tsx Converts the inline form to a Dialog; adds per-session baseline tracking via refs so preventOutsideDismiss reads current state rather than stale closure values; adds context chip, sticky header/footer layout, and Advanced reset on reopen. Implementation is correct and well-commented.
src/renderer/src/components/settings/ssh-target-draft.ts Adds isSshTargetFormDirty covering all 11 editable fields for the outside-dismiss guard. Clean and table-driven, with a corresponding table-driven test ensuring no field is silently dropped.
src/renderer/src/components/settings/ssh-session-termination.ts Verbatim extraction of terminateSessionsWithReconnect from SshPane to keep the file under the oxlint max-lines budget. No behaviour change.
src/renderer/src/components/settings/SshTargetForm.test.tsx New unit tests covering dialog chrome structure, edit-mode chip, Advanced reset across cancel → reopen, save gating, clean-session outside dismissal, and Advanced auto-expand for targets with advanced values. Good coverage of the critical paths.
tests/e2e/ssh-host-form-modal.spec.ts New E2E spec seeding 10 hosts to validate viewport-stable dialog, dirty outside-click preservation, Advanced reset on reopen, and the deep-link intent path. Randomised prefix guards against worker collisions.
src/renderer/src/components/settings/SshTargetCard.tsx Adds data-ssh-target-card and data-ssh-target-label attributes so E2E tests can locate cards by stable selectors rather than Tailwind class names.
src/renderer/src/i18n/locales/en.json Adds five new SshTargetForm strings using human-readable keys (editTitle, addTitle, etc.) rather than the hash-code format used for every existing key in the file.

Sequence Diagram

sequenceDiagram
    participant User
    participant SshPane
    participant SshTargetForm
    participant IPC as window.api.ssh

    User->>SshPane: click Add Target / Edit
    SshPane->>SshPane: setShowForm(true), setEditingId, setForm
    SshPane->>SshTargetForm: "open=true, form, editingId, saving=false"

    Note over SshTargetForm: session effect fires<br/>baselineRef ← formRef.current<br/>advancedOpen reset

    User->>SshTargetForm: types / edits fields
    SshTargetForm->>SshPane: onFormChange(updater)

    User->>SshTargetForm: click Save / press Enter
    SshTargetForm->>SshPane: onSave()
    SshPane->>SshPane: setSaving(true)
    SshPane->>IPC: addTarget / updateTarget
    SshTargetForm-->>User: button disabled, Enter blocked

    alt Save succeeds
        IPC-->>SshPane: result
        SshPane->>SshPane: setShowForm(false), setForm(EMPTY_FORM)
        SshPane->>SshPane: setSaving(false) [finally]
        SshTargetForm-->>User: dialog closes
    else Save fails
        IPC-->>SshPane: error
        SshPane-->>User: toast.error
        SshPane->>SshPane: setSaving(false) [finally]
    end

    User->>SshTargetForm: click outside (dirty form)
    SshTargetForm->>SshTargetForm: preventOutsideDismiss reads formRef + baselineRef
    SshTargetForm-->>User: dismiss blocked (form is dirty)

    User->>SshTargetForm: click Cancel or press Escape
    SshTargetForm->>SshPane: onOpenChange(false)
    SshPane->>SshPane: cancelForm() → setShowForm(false), setForm(EMPTY_FORM)
Loading

Reviews (3): Last reviewed commit: "fix: stop mutating formRef during render..." | Re-trigger Greptile

Add non-English catalog entries for the new modal title and
description keys so localized UIs match English.

@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.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 197dd18d-5b42-4d76-82b8-64617de61310

📥 Commits

Reviewing files that changed from the base of the PR and between e5016e0 and 6b6bb35.

📒 Files selected for processing (4)
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/zh.json

Comment thread src/renderer/src/i18n/locales/es.json Resolved
Comment thread src/renderer/src/i18n/locales/zh.json Resolved
Adds a saving state to prevent concurrent saves when a user double-clicks
the submit button. Fixes outside-click dismissal by correctly tracking form
state across re-renders using refs. Extracts session termination logic to
a reusable module.
@AmethystLiang AmethystLiang changed the title Sta 3067 feature open the ssh host addedit form in a modal dialog so feat(ssh): open the host add/edit form in a modal dialog (STA-3067) Aug 3, 2026
React Doctor fails the static-analysis gate when refs are written during
render. Sync form into formRef in an effect so render stays pure.
@AmethystLiang
AmethystLiang merged commit 565ef63 into main Aug 3, 2026
46 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…tablyai#12172)

* Open SSH host add/edit form in modal dialog

Form moves from inline to a viewport-stable modal (STA-3067) so fields stay
accessible with long host lists. Includes sticky header/footer, dirty-state
protection against outside click, and session-aware Advanced state reset on
cancel/reopen.

* fix: add missing SshTargetForm localization keys

Sync en.json catalog for modal title/description strings so
verify:localization-catalog passes in static analysis.

* fix: translate SshTargetForm modal strings in es/ja/ko/zh

Add non-English catalog entries for the new modal title and
description keys so localized UIs match English.

* Prevent SSH form double-submit and fix dismissal detection

Adds a saving state to prevent concurrent saves when a user double-clicks
the submit button. Fixes outside-click dismissal by correctly tracking form
state across re-renders using refs. Extracts session termination logic to
a reusable module.

* fix: stop mutating formRef during render in SshTargetForm

React Doctor fails the static-analysis gate when refs are written during
render. Sync form into formRef in an effect so render stays pure.
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.

[Feature]: Open the SSH host add/edit form in a modal dialog so it stays visible with long host lists

1 participant