Skip to content

Add inline file creation to the config tab#27

Merged
mlund01 merged 4 commits into
mainfrom
claude/charming-yalow-b51cff
Apr 23, 2026
Merged

Add inline file creation to the config tab#27
mlund01 merged 4 commits into
mainfrom
claude/charming-yalow-b51cff

Conversation

@mlund01
Copy link
Copy Markdown
Owner

@mlund01 mlund01 commented Apr 22, 2026

Summary

  • Right-click the config file tree to create new files inline:
    • Right-click empty space → Add file (creates at root)
    • Right-click a folder → Add file to folder (folder auto-expands, input appears inside it)
  • Inline input replaces a modal — auto-focused, Enter to create, Escape or blur to cancel, red border on validation errors (invalid path / collision).
  • Uses the existing PUT /api/instances/{id}/config/files/{name} endpoint with empty content, so no backend changes.
  • Path-building and validation logic extracted to web/src/lib/config-files.ts with 14 vitest unit tests covering root vs. nested placement, whitespace, absolute paths, .. traversal, and collisions.
  • Adds vitest as a dev dep; npm test / npm run test:watch.

Not included

Delete (file/folder) was discussed but skipped — squadron-wire doesn't currently expose a delete-config-file message type. Worth a follow-up that extends the protocol and the instance-side handler.

Test plan

  • npm test in web/ passes
  • npm run build in web/ succeeds
  • With a connected Squadron instance and config editing enabled:
    • Right-click empty file-tree space → "Add file" → type a name → Enter creates and selects the file
    • Right-click a folder → "Add file to folder" → folder expands and input appears indented; create works
    • Escape cancels; clicking outside cancels
    • Typing an existing filename shows red border; submit is suppressed
    • Typing ../foo or /foo shows red border

mlund01 added 4 commits April 21, 2026 21:29
Right-click on empty file-tree space opens an "Add file" menu; right-click
on a folder opens "Add file to folder". Selecting either reveals an inline
input in the tree (auto-focused, Enter to create, Escape/blur to cancel)
rather than a modal dialog. Uses the existing PUT config-file endpoint
with empty content, so no backend changes are needed.

Path/collision validation is extracted to a pure helper module
(web/src/lib/config-files.ts) and covered by vitest unit tests. Adds
vitest as a dev dep and wires up `npm test` / `npm run test:watch`.

Delete is intentionally left out — squadron-wire doesn't expose a
delete-config-file message yet.
…-b51cff

# Conflicts:
#	web/src/pages/ConfigPage.tsx
Replaces the hand-rolled popover with radix-backed ContextMenu components
so we get proper keyboard nav, focus management, and portalled
positioning. Root (empty space) and per-folder triggers are nested so
each gets its own appropriate items.

The project's --radius token is 1.15rem, which makes stock shadcn menus
render with ~16px-radius items that look pill-ish. Overridden to
6px/4px on the menu content and items so the menu looks like a menu.
- Accept a leading './' on new filenames (normalized away before path
  concat and collision checks) so './foo.md' behaves identically to
  'foo.md'.
- Extract splitDirAndBase helper and use it at the four inline
  substring/lastIndexOf sites in ConfigPage.
- Replace the nested-ternary error-code-to-message mapping with a
  lookup object.
- Extract the shared ContextMenuContent className and onCloseAutoFocus
  handler into module-level constants.
- Drop the redundant setTimeout around the inline input's focus call —
  onCloseAutoFocus already prevents Radix's focus restore.
- Reuse cancelAddingFile in handleCreateFile's success path.
- Tests: 5 new cases for './' handling and splitDirAndBase (19 total).
@mlund01 mlund01 merged commit 7eb4bf9 into main Apr 23, 2026
1 check passed
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.

1 participant