Repository navigation
feat(ssh): open the host add/edit form in a modal dialog (STA-3067) - #12172
Conversation
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.
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe 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)
✨ Finishing Touches📝 Generate docstrings
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. Comment |
Sync en.json catalog for modal title/description strings so verify:localization-catalog passes in static analysis.
There was a problem hiding this comment.
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 winCover every field in the dirty comparison.
The test exercises
hostandsystemSshConnectionReuseonly.isSshTargetFormDirtycompares 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 withEditingTarget.♻️ 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 winReplace the Tailwind class locator with a stable selector.
div.rounded-lg.bordertargets presentation classes onSshTargetCard. A styling change breaks this test with a confusing failure. Add adata-testidor adata-ssh-target-idattribute 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
📒 Files selected for processing (6)
src/renderer/src/components/settings/SshPane.tsxsrc/renderer/src/components/settings/SshTargetForm.test.tsxsrc/renderer/src/components/settings/SshTargetForm.tsxsrc/renderer/src/components/settings/ssh-target-draft.test.tssrc/renderer/src/components/settings/ssh-target-draft.tstests/e2e/ssh-host-form-modal.spec.ts
Greptile SummaryThis 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
Confidence Score: 5/5Renderer-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.
|
| 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)
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.
There was a problem hiding this comment.
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
📒 Files selected for processing (4)
src/renderer/src/i18n/locales/es.jsonsrc/renderer/src/i18n/locales/ja.jsonsrc/renderer/src/i18n/locales/ko.jsonsrc/renderer/src/i18n/locales/zh.json
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.
React Doctor fails the static-analysis gate when refs are written during render. Sync form into formRef in an effect so render stays pure.
…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.
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.
user@host:portso it's clear which host you're changing.The
add-ssh-hostsettings 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. Ranoxlint(default config andconfig/oxlint-react-doctor.json) over the changed files,oxfmt --check,check:max-lines-ratchet,verify:localization-catalog, andverify:localization-extraction. All clean.pnpm typecheck— rantypecheck: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.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:
addTarget/updateTargetIPC calls, creating duplicate hosts. Added asavingflag that both disables the button and gates the form'sonSubmit(a disabled button doesn't block Enter).preventOutsideDismisscapturedisDirtyfrom the render closure. When an edit session starts, the effect rewritesbaselineRef.current, but for the typical non-advanced targetsetAdvancedOpenis called with the value it already holds, React bails out, and no re-render happens — so the handler kept a staleisDirty === trueand 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.formin the effect dep array re-ran the effect on every keystroke. Deps narrowed to[open, editingId], with the draft read through a ref.HOST_PREFIXderived fromDate.now()alone could collide between Playwright workers, whoseafterEachdeletes every target matching the prefix — one worker could delete another's fixtures. Added a random suffix.locator.isVisible({ timeout })is one-shot and ignores its timeout, so the announcement dismissal could miss a late-rendering button. Switched to a retryingexpect(...).toBeVisible().multiplexaciónis feminine (Desactívalo→Desactiva esta opción) anda la que puedas iniciar sesión→en la que.div.rounded-lg.border). Addeddata-ssh-target-card/data-ssh-target-labeltoSshTargetCardand locate by those.Not actionable: one Major claimed the zh (and other) locales were missing the new
SshTargetFormkeys. Those keys had already landed ine5016e0b/6b6bb35b, and theauto.actions.updateTarget.descriptionkey it cited is referenced nowhere in the repo.Knock-on change: adding the saving state pushed
SshPane.tsxpast the 400-line oxlintmax-linesbudget. AGENTS.md forbids disabling or baselining that rule, soterminateSessionsWithReconnectmoved verbatim intossh-session-termination.ts. No behaviour change.Cross-platform (macOS / Linux / Windows): explicitly checked. The diff is renderer-only and introduces no
metaKey/ctrlKeyhandling, 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/RadixDialogprimitive already shipping on all three platforms. The single keyboard path touched — Enter submitting the form — is platform-neutral.Security Audit
src/main,src/preload, orsrc/sharedis touched; no new channels, handlers, or permissions. Saves still go through the existingwindow.api.ssh.addTarget/updateTargetwith the pre-existingbuildSshTargetSavePayloadvalidation.host,proxyCommand,jumpHost, andidentityFileremain the same user-supplied fields parsed by the samessh-target-drafthelpers. The modal only changes where they're rendered.user@host:port, which the host card already displays; no key material, passphrase, or credential is read or rendered.e2e-ssh-modal-*label prefix and its cleanup deletes only labels carrying that prefix.Notes
tests/e2e/ssh-host-form-modal.spec.ts.