feat(sidebar): manage folders that live under several model roots

The sidebar's folder tree merges every model root into one relative-path
namespace, but folder operations turned a node into a path by prefixing
default_*_root. A folder living under another root failed to delete with
"Folder no longer exists" (recipes under the primary lora root while
default_lora_root is the extra one), and where the same relative folder
exists in both roots the operation silently hit the other copy — 14 of the
16 top-level folders in the reporting library are shared, so guessing a root
was never safe.

Backend:
* ModelMoveService.resolve_folder() and GET /api/lm/{prefix}/resolve-folder
  answer which directories a library-relative folder maps to
  (folder_path/root/is_symlink), in scanner root order, skipping directories
  no root holds and refusing absolute or climbing paths.
* delete_folder/rename_folder tag a vanished directory with code "missing"
  so the sidebar can tell "this node is stale, refresh" from a failed
  operation.

Frontend:
* _resolveFolderCandidates() is the single place that turns a node into
  absolute paths: default root first, the old root-prefix fallback only
  while a single root is configured, and an explicit unresolved error for a
  multi-root library — nothing is guessed silently any more.
* One copy keeps the single-target modal, which now names the resolved
  absolute path. Several copies render one checkbox row per copy, each
  dry-run against the delete guard ("no models" / "contains N model
  file(s)..." / a deletion is still pending / no longer exists / symbolic
  link): a blocked copy is unticked, disabled and explained, the button
  reads "Delete N folders", every ticked copy is deleted and guarded on its
  own, and a partial failure is reported without discarding the successes.
* Rows are built once per open and only their status text is updated, so
  ticking a box no longer rebuilds the list, steals focus or resizes the
  modal mid-click; the action row keeps a fixed button width.
* Rename offers a root picker in its inline row, create inherits the
  parent's root when the parent resolves to exactly one directory, and the
  undo restores every copy a delete removed.

i18n: 26 new keys (sidebar.deleteFolderModal.*, .deleteFolderResult.*,
.renameFolderResult.*, .folderRoot.*, .folderResult.*) translated in all 9
locales, with the en wording normalized to the established "model root" noun
(it had said "library root") and the new terminology recorded in
docs/i18n-translation-guidelines.md.

Verified: pytest 3686 passed, vitest 1473 passed (86 in the folder-management
suite), pytest tests/i18n 20 passed, sync_translation_keys.py --dry-run
clean. A sandboxed standalone instance with two roots confirmed that deleting
one copy leaves the node in place, that the twin's model card survives the
purge, and that deleting both copies and undoing restores both directories.
This commit is contained in:
Will Miao
2026-10-06 17:14:07 +08:00
parent 5ebf5aeccc
commit 2dcaf6a30e
23 changed files with 2220 additions and 180 deletions
+101 -1
View File
@@ -42,6 +42,12 @@
animation: modalFadeIn 0.2s ease-out;
}
/* The label grows to "Delete N folders" when several roots are ticked; a fixed
floor keeps the centred action row from sliding sideways on every toggle. */
#deleteFolderModal .delete-btn {
min-width: 150px;
}
/* The folder delete confirm button is held disabled while the folder contents
are checked against the backend, so it must not look clickable. */
#deleteFolderModal .delete-btn:disabled {
@@ -99,4 +105,98 @@
word-break: break-all;
text-align: left;
line-height: 1.5;
}
}
/* Root list for a folder that exists under several library roots: one checkbox
per copy, since "the folder" in a merged tree is all of them. Each row carries
its own guard verdict, so a copy that cannot be removed says why instead of
silently dropping out of the list. */
.delete-folder-roots:empty {
display: none;
}
.folder-root-picker {
background: var(--lora-surface);
border: 1px solid var(--lora-border);
border-radius: var(--border-radius-sm);
padding: var(--space-2);
margin: var(--space-2) 0;
text-align: left;
max-height: 200px;
overflow-y: auto;
}
.folder-root-picker-title {
color: var(--text-color);
font-size: 0.9em;
margin-bottom: var(--space-1, 4px);
}
.folder-root-option {
display: flex;
align-items: flex-start;
gap: 6px;
padding: 4px 0;
cursor: pointer;
line-height: 1.4;
}
.folder-root-option.disabled {
opacity: 0.6;
cursor: not-allowed;
}
.folder-root-option input[type="checkbox"] {
margin-top: 2px;
flex: 0 0 auto;
}
/* Path over status, so a row keeps its height when the verdict replaces
"checking..." — the modal must not move while it is being read. */
.folder-root-body {
display: flex;
flex-direction: column;
min-width: 0;
flex: 1 1 auto;
}
.folder-root-path {
font-family: var(--font-mono);
font-size: 0.85em;
word-break: break-all;
}
.folder-root-status {
font-size: 0.78em;
opacity: 0.75;
min-height: 1.2em;
line-height: 1.2;
}
.folder-root-status.blocked {
color: var(--lora-error);
opacity: 0.95;
}
/* Says what the unchecked copies mean. The line is always in the DOM with its
height reserved, so warning about them cannot resize the modal mid-click. */
.folder-root-kept-note {
min-height: 1.2em;
margin-top: 4px;
font-size: 0.78em;
line-height: 1.2;
opacity: 0.85;
color: var(--lora-warning, var(--lora-error));
}
/* Rename row: same choice, inline. Kept narrow so the row still reads as one
editable line in the sidebar tree. */
.sidebar-folder-root-select {
flex: 0 0 auto;
max-width: 45%;
font-size: 0.8em;
background: var(--lora-surface);
color: var(--text-color);
border: 1px solid var(--lora-border);
border-radius: var(--border-radius-sm);
}