Library sidebar: folders, pinned-top, per-page menus, and an all-pages view

- Page.isFolder (migration 027): folders are content-less pages reusing
  parentId; folder delete reparents children one level up
- Sidebar: Pages group becomes Library; Pinned at top; folder tree; page
  menu (duplicate/pin/copy link/rename/move/trash); folder menu
- /pages index: filterable Library table (all/recent/pinned/untagged) with
  folder path + last edit (components/library-index.tsx)
- Docs: API.md isFolder + folder-delete semantics
This commit is contained in:
Andrew S Erwin
2026-12-01 06:07:12 -06:00
parent 50c89c1653
commit 9dbf9fa3ea
9 changed files with 541 additions and 231 deletions
+68
View File
@@ -0,0 +1,68 @@
package http
import "testing"
// Library folders (migration 027): a folder is a content-less Page (isFolder)
// reusing the parentId hierarchy. Deleting a folder reparents its children
// (pages AND subfolders) to the folder's own parent, keeping them one level up.
func TestPageFolders(t *testing.T) {
srv := testServer(t)
alice := newAPIUser(t, srv, "folders@superbrain.test")
top := alice.request("POST", "/api/pages", map[string]any{"title": "Personal", "isFolder": true}, 201)
topID := top["id"].(string)
if top["isFolder"] != true {
t.Fatalf("folder flag not stored: %v", top)
}
sub := alice.request("POST", "/api/pages", map[string]any{"title": "Travel", "isFolder": true, "parentId": topID}, 201)["id"].(string)
page := alice.request("POST", "/api/pages", map[string]any{"title": "Lisbon", "parentId": sub}, 201)["id"].(string)
loose := alice.request("POST", "/api/pages", map[string]any{"title": "Loose", "parentId": topID}, 201)["id"].(string)
// isFolder is exposed in the list projection.
found := false
for _, p := range alice.getJSON("/api/pages", 200) {
if p["id"] == topID {
found = p["isFolder"] == true
}
}
if !found {
t.Fatal("isFolder missing from list projection")
}
// Deleting the nested folder promotes its page and keeps it under the
// grandparent (top), not at the root.
alice.request("DELETE", "/api/pages/"+sub, nil, 200)
after := map[string]string{}
for _, p := range alice.getJSON("/api/pages", 200) {
parent, _ := p["parentId"].(string)
after[p["id"].(string)] = parent
}
if after[page] != topID {
t.Fatalf("page not reparented to grandparent: %v", after)
}
if _, ok := after[sub]; ok {
t.Fatal("deleted folder still listed")
}
// Deleting the top folder promotes remaining children to the root.
alice.request("DELETE", "/api/pages/"+topID, nil, 200)
after = map[string]string{}
for _, p := range alice.getJSON("/api/pages", 200) {
parent, _ := p["parentId"].(string)
after[p["id"].(string)] = parent
}
if after[page] != "" || after[loose] != "" {
t.Fatalf("children not promoted to root: %v", after)
}
// A plain page delete still promotes children to the root (SET NULL).
p1 := alice.request("POST", "/api/pages", map[string]any{"title": "P1"}, 201)["id"].(string)
p2 := alice.request("POST", "/api/pages", map[string]any{"title": "P2", "parentId": p1}, 201)["id"].(string)
alice.request("DELETE", "/api/pages/"+p1, nil, 200)
for _, p := range alice.getJSON("/api/pages", 200) {
if p["id"] == p2 && p["parentId"] != nil {
t.Fatalf("plain page delete did not promote child: %v", p)
}
}
}