Sidebar reorganization + page tags, kanban explicit-only, bookmark group-by, calendar views
Sidebar (web/components/sidebar.tsx) reorganized to the requested structure:
Quick find at the top; a Pages group (All Pages tree with the existing
rename/reorder/pin/subpage/delete interactions, Pinned Pages, Untagged
Pages); a Bookmarks group (All Bookmarks, Calendar, and expandable carets
for Tags / Kanban / Collections / Contacts listing their entities with
deep-links /tags?tag=, /kanban?column=, /collections?id=, /contacts?open=);
Trash at the bottom. Collapsed desktop rail is a flat icon list; the mobile
drawer shows the full grouped nav.
Page tagging (new): PageTag join (migration 023 + schema.sql, db-converge
proven), POST/DELETE /api/pages/{id}/tags with owner-or-TagShare validation
(same rule as bookmark tags), tags exposed in the page list/detail
projections so the sidebar can compute the untagged subset. Tagging is
metadata (no content-version bump) and cascades on page/tag delete.
Dragging a page from Untagged Pages onto a tag assigns it (custom drag MIME
keeps it distinct from page reorder).
Kanban: only explicitly-placed cards render (no auto-populate of unassigned
bookmarks); the sidebar caret lists the existing columns and ?column=
scrolls/rings the target. e2e updated to assert no-auto-populate then place
the card explicitly.
All Bookmarks: a Group by selector (None/Calendar/Tags/Kanban/Collections/
Contacts) rendering grouped sections via shared row/card renderers; the
default None path is byte-identical to before (205-row table, same keys).
Collections grouping fetches membership once, sequence-guarded.
Calendar: Day/Week/Month/Year/List views (Month default), adaptive
prev/next + Today, date-sorted list; SSR-safe (date-fns only, post-mount
today), internal overflow containers so no page-level horizontal scroll.
Deep-link page wrappers for kanban/collections/contacts pass searchParams
into the clients' initial selection.
Test gate: the -race internal/http suite now exceeds the default 10m go
test timeout (~14m cold-cache), so the tests service and Makefile test
target use -timeout 30m; the suite passes in full.
Verified: regressions 20/20, real-stack e2e all pass, lint/SSR-lint/build
0 errors, db-converge green, full Go integration suite green; browser
checks of the grouped sidebar, drag-to-tag, bookmark group-by and every
calendar view show correct rendering with no horizontal overflow.
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
package http
|
||||
|
||||
import "testing"
|
||||
|
||||
// Page tags (sidebar "Untagged Pages" + drag-a-page-onto-a-tag): pages carry
|
||||
// tags like bookmarks, owner-scoped writes, metadata (no content-version
|
||||
// bump), cascade on tag/page delete, and the list/detail projections expose
|
||||
// tags so the sidebar can compute the untagged subset.
|
||||
func TestPageTags(t *testing.T) {
|
||||
srv := testServer(t)
|
||||
alice := newAPIUser(t, srv, "page-tags@superbrain.test")
|
||||
bob := newAPIUser(t, srv, "page-tags-other@superbrain.test")
|
||||
|
||||
page := alice.request("POST", "/api/pages", map[string]any{"title": "Taggable"}, 201)["id"].(string)
|
||||
other := alice.request("POST", "/api/pages", map[string]any{"title": "Untagged"}, 201)["id"].(string)
|
||||
tag := alice.request("POST", "/api/tags", map[string]any{"name": "research", "color": "#123456"}, 201)["id"].(string)
|
||||
|
||||
tagsOf := func(c apiClient, id string) []any {
|
||||
v := c.request("GET", "/api/pages/"+id, nil, 200)
|
||||
tags, _ := v["tags"].([]any)
|
||||
return tags
|
||||
}
|
||||
listTags := func(id string) []any {
|
||||
for _, p := range alice.getJSON("/api/pages", 200) {
|
||||
if p["id"] == id {
|
||||
tags, _ := p["tags"].([]any)
|
||||
return tags
|
||||
}
|
||||
}
|
||||
t.Fatalf("page %s not in list", id)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Both pages start untagged in detail AND list projections.
|
||||
if len(tagsOf(alice, page)) != 0 || len(tagsOf(alice, other)) != 0 {
|
||||
t.Fatal("pages should start untagged")
|
||||
}
|
||||
if len(listTags(page)) != 0 || len(listTags(other)) != 0 {
|
||||
t.Fatal("list projection should expose empty tags for untagged pages")
|
||||
}
|
||||
|
||||
// Attach: returns the refreshed projection carrying the tag.
|
||||
v0 := pageVersion(t, alice, page)
|
||||
res := alice.request("POST", "/api/pages/"+page+"/tags", map[string]any{"tagId": tag}, 200)
|
||||
if tags, _ := res["tags"].([]any); len(tags) != 1 {
|
||||
t.Fatalf("attach should return one tag: %v", res["tags"])
|
||||
}
|
||||
if len(tagsOf(alice, page)) != 1 || len(listTags(page)) != 1 {
|
||||
t.Fatal("tag not reflected in detail/list after attach")
|
||||
}
|
||||
// Tagging is metadata: it must not bump the content version.
|
||||
if pageVersion(t, alice, page) != v0 {
|
||||
t.Fatal("tag attach bumped the page content version")
|
||||
}
|
||||
// The other page stays untagged (the sidebar's untagged subset).
|
||||
if len(listTags(other)) != 0 {
|
||||
t.Fatal("unrelated page became tagged")
|
||||
}
|
||||
|
||||
// Idempotent re-attach.
|
||||
alice.request("POST", "/api/pages/"+page+"/tags", map[string]any{"tagId": tag}, 200)
|
||||
if len(tagsOf(alice, page)) != 1 {
|
||||
t.Fatal("re-attach duplicated the tag")
|
||||
}
|
||||
|
||||
// Invalid tag and missing tagId are rejected.
|
||||
alice.request("POST", "/api/pages/"+page+"/tags", map[string]any{"tagId": "nope"}, 400)
|
||||
alice.request("POST", "/api/pages/"+page+"/tags", map[string]any{}, 400)
|
||||
|
||||
// Cross-owner: bob cannot tag alice's page (404), even with his own tag.
|
||||
bobTag := bob.request("POST", "/api/tags", map[string]any{"name": "bobtag"}, 201)["id"].(string)
|
||||
bob.request("POST", "/api/pages/"+page+"/tags", map[string]any{"tagId": bobTag}, 404)
|
||||
bob.request("DELETE", "/api/pages/"+page+"/tags/"+tag, nil, 404)
|
||||
|
||||
// Detach.
|
||||
alice.request("DELETE", "/api/pages/"+page+"/tags/"+tag, nil, 200)
|
||||
if len(tagsOf(alice, page)) != 0 {
|
||||
t.Fatal("detach left the tag attached")
|
||||
}
|
||||
|
||||
// Deleting the tag cascades the join row.
|
||||
alice.request("POST", "/api/pages/"+page+"/tags", map[string]any{"tagId": tag}, 200)
|
||||
alice.request("DELETE", "/api/tags/"+tag, nil, 200)
|
||||
if len(tagsOf(alice, page)) != 0 {
|
||||
t.Fatal("tag delete did not cascade PageTag")
|
||||
}
|
||||
}
|
||||
@@ -102,6 +102,8 @@ func NewServer(cfg *config.Config, database *db.DB) *http.Server {
|
||||
mux.HandleFunc("GET /api/pages/{id}/revisions/{revisionId}", authed(handlers.HandlePageRevisionsGet))
|
||||
mux.HandleFunc("POST /api/pages/{id}/revisions/{revisionId}/restore", authed(handlers.HandlePageRevisionsRestore))
|
||||
mux.HandleFunc("GET /api/pages/{id}/markdown", authed(handlers.HandlePagesMarkdown))
|
||||
mux.HandleFunc("POST /api/pages/{id}/tags", authed(handlers.HandlePageTagsAdd))
|
||||
mux.HandleFunc("DELETE /api/pages/{id}/tags/{tagId}", authed(handlers.HandlePageTagsRemove))
|
||||
|
||||
// Trust phase: recoverable deletions and structured export.
|
||||
mux.HandleFunc("GET /api/trash", authed(handlers.HandleTrashList))
|
||||
|
||||
Reference in New Issue
Block a user