I'd love to add tags to forum posts so they can be sorted by type

merged…
osebo28d ago

I'd love to add tags to forum posts so they can be sorted by type

12 repliesoldestnewest
Osebotfable-5-128d ago

Reading "forum posts" as threads (the things listed on a workspace home), so: tags on threads, filterable by tag.

Plan:

  1. Schema: threads.tags text[] not null default '{}' + GIN index (drizzle/0016). Tags are normalised labels (lowercase, a-z0-9-, ≤24 chars, ≤5 per thread) in a dependency-free lib/tags.ts so client and server agree.
  2. Write paths: POST /api/threads takes optional tags (the start-a-thread composer gets a small "tags" field in its tool bar, comma/space separated, with a datalist of the workspace's existing tags). PATCH /api/threads/[id] { tags } for the creator / workspace owner (same gate as Manage), edited inline on the thread page.
  3. Read/filter: GET /api/threads?tag=x → listThreads({ tag }) (tags @> array[x]); ?tag= on /<slug> next to ?status=. The filter bar gets an "All tags" dropdown next to the status one (same bare mono label + chevron drawing, listing the tags used in that workspace with counts). Tags show on list rows (meta line) and in the thread status row as chips that link to the filtered list.
  4. Osebot sees them: <thread … tags="…"> in lib/context.ts.

Not doing: a tag taxonomy per workspace (free-form, emerges from use), tags on individual replies.

Osebotfable-5-128d agothreadide@6e8a85b

Code is written and type-checks (commit 6e8a85b, local for now). Shape of it:

  • drizzle/0016_thread_tags.sql: threads.tags text[] not null default '{}' + GIN index. lib/tags.ts normalises (normalizeTag, parseTagInput, isTag; TAG_MAX 24, TAGS_MAX 5).
  • lib/data.ts: listThreads({ tag }) (tags @> array[tag]), createThread({ tags }), setThreadTags, listWorkspaceTags(wsId) (tag + count, most used first).
  • API: GET /api/threads?tag=, POST /api/threads { tags } (guests too), PATCH /api/threads/[id] { tags } (creator / owner, same gate as public).
  • UI: composer gets a # tags field in its tool row (datalist of the workspace's tags, completing the tag being typed after a comma); workspace home gets an "All tags" dropdown next to the status one, only once a tag exists; list rows show tag chips; thread page status row shows chips linking to /<slug>?tag=x plus an inline "Add tags / Edit tags" editor for creator/owner.
  • lib/context.ts: <thread … tags="bug, design">.

Now standing up a local Postgres + the app in the sandbox to run the migration and the SQL for real, and to take screenshots before pushing.

Osebotfable-5-128d agothreadide@322446c

Done and pushed to thread/0e08faf9 (6e8a85b feature, 322446c polish).

What you get

  • Starting a thread: a # tags field in the composer's tool row (comma separated, suggests the workspace's existing tags as you type, also for guests).
  • On a thread: tag chips in the status row linking to the filtered list, plus Add tags / Edit tags inline for the creator or a workspace owner.
  • On the workspace home: an All tags dropdown next to All statuses (only appears once a tag exists), ?tag=bug in the URL so filtered views are shareable, chips on every row. Combines with status and search.
  • Osebot sees tags="bug, api" on the thread line of its prompt.

home
thread
phone

Decisions worth knowing

  • Tags are free-form, normalised to lowercase-a-z0-9- (≤24 chars, ≤5 per thread) in lib/tags.ts; no taxonomy to maintain, the dropdown lists what's in use with counts.
  • Stored as threads.tags text[] with a GIN index (drizzle/0016), not a join table.
  • Editing tags uses the same gate as "Make public" / delete (creator or owner). Easy to widen to members if you'd rather anyone could tag.
  • Read "forum posts" as threads. Tags on individual replies are not in this; say if you want that too.

Verified against a local Postgres in the sandbox: migration, create/edit normalisation, the @> filter, 401 for anonymous PATCH; tsc clean. Details in the PR description.

oseboasked Osebot28d ago

The tag list should be defined by the workspace creators

Osebotfable-5-128d ago

Switching tags from free-form to a workspace-defined list:

  1. Schema: workspaces.tags text[] not null default '{}' (drizzle/0017). The owner edits the list on the manage page (/workspaces/[id], a new "Tags" card: add / remove chips) via PATCH /api/workspaces/[id] { tags }.
  2. Threads only carry tags from that list: POST /api/threads and PATCH /api/threads/[id] drop anything not in the workspace list (400 if nothing valid is left? no, just filter). Removing a tag from the workspace list also strips it from that workspace's threads so the filter never shows ghosts.
  3. UI: the composer's # text field becomes a picker of the workspace's tags (toggle chips, nothing shown when the list is empty); the thread page editor is the same chip toggle; the "All tags" filter lists the workspace list (with counts) instead of "what's in use".
  4. Osebot's prompt mentions the workspace's tag list so it can suggest one.

Keeping lib/tags.ts normalisation (lowercase a-z0-9-, ≤24 chars) for the owner's input; the per-thread cap stays 5.

Osebotfable-5-128d agothreadide@ff05f40

Code is written, type-checks, committed locally as ff05f40 (not pushed yet). Shape:

  • workspaces.tags text[] (drizzle/0017). The migration backfills each workspace's list from the tags its threads already carry, so nothing already tagged loses its label.
  • lib/tags.ts allowedTags(input, workspaceList): a thread's tags = the subset of the owner's list, in the list's order, ≤5. createThread and setThreadTags both go through it; setWorkspaceTags rewrites the list and strips a removed tag from every thread in one transaction.
  • Manage page (/workspaces/[id], owner block) gets a Tags card: chips with a two-tap × (removal also untags threads), plus a # field to add one or several (shows "Will be added as #feature-request" while typing).
  • The composer and the thread page drop the free-text field for a TagPicker (toggle chips over the list, shared component). An owner on a thread in a workspace without a list sees "Define tags" linking to the manage card; everyone else sees nothing until tags exist.
  • Filter dropdown lists the owner's tags with counts (0 for unused ones). Osebot's system prompt names the list.

Now standing up Postgres in the sandbox to run the migration + the strip-on-remove SQL for real, and Playwright for screenshots of the manage card and the picker.

Osebotfable-5-128d agothreadide@5652a95

Done and pushed to thread/0e08faf9 (ff05f40 + 5652a95 on top of the earlier free-form version). The tag list is now the workspace owner's.

How it works now

  • Manage page → Tags card (owners): the list as chips, each with a × that arms to "remove?" (removing a tag also takes it off every thread that has it, so it's two-tap), and a # field to add one or several (comma separated; "feature request" becomes #feature-request, shown before you add).
  • Threads only carry tags from the list. The composer and the thread page's Edit tags swap the free-text field for toggle chips over the owner's list; the server also cuts anything else out, so the API can't sneak a rogue tag in. Nothing shows until the owner has defined tags; an owner opening a thread in a list-less workspace gets a "Define tags" link to the card.
  • Filter: All tags lists the owner's tags with counts (unused ones show 0), ?tag= stays shareable.
  • Osebot's prompt names the workspace's tags.

manage
home
thread

Migration note: drizzle/0017 seeds each workspace's list from the tags its threads already carry, so anything tagged before this merges keeps its label. Caps: 30 tags per workspace, 5 per thread, 24 chars each.

Verified in the sandbox against a real Postgres: migrations + backfill, normalisation, rogue tags dropped on create/edit, strip-on-remove, empty list → no tags/options; via the dev server: 401 anonymous / 403 member-not-owner on the list PATCH, guest posts keep only listed tags. tsc clean. Two dev-console warnings I saw predate this branch (invite-box hydration mismatch on the manage page, a key warning on the page's composer fragment); say if you want those fixed too.

390px: the picker row wraps under the text; tagged rows keep their chips on their own line
390px: the picker row wraps under the text; tagged rows keep their chips on their own line
oseboasked Osebot28d ago

The tag list can just be a dropdown, also show me how they’re created in a workspace, the admin should have to opt in to creating tags

Osebotfable-5-128d ago

Three things from this post, taking them as:

  1. Opt-in: a workspace gets tags only after the owner switches them on. New workspaces.tags_enabled boolean (drizzle/0018, default false; backfilled true where a list already exists). Toggle lives on the manage page next to "Open workspace"; the Tags card (define the list) only appears once it's on. With it off, nothing tag-related renders anywhere (composer, thread page, filter, prompt) and the API drops tags.
  2. Dropdown instead of chips: the composer's and thread page's toggle-chip picker becomes a native <select> (same bare mono label + chevron drawing as the status filter). A thread picks one tag from the dropdown; the Edit tags row on the thread page is the same select.
  3. Show how they're created: screenshots of the manage page flow (switch on → Tags card → add a tag) in the done post.

Keeping: owner-only list, strip-on-remove, ?tag= filter.

Osebotfable-5-128d agothreadide@4d01861

Code is written, type-checks, committed locally as 4d01861 (not pushed yet). Shape:

  • Opt-in: workspaces.tags_enabled (drizzle/0018, default false; the backfill switches on workspaces that already have a list). The manage page's Tags card opens with a note and a Turn on tags button; only then does the list editor appear. Turn off tags under the editor is two-tap, because switching off also empties the list and untags every thread, so "off" always means "no tags anywhere" and the composer, thread page, filter and Osebot prompt all hide on the empty list without a second flag check. PATCH /api/workspaces/[id] { tagsEnabled }; sending a tags list while off answers 409.
  • Dropdown: TAGS_MAX is 1, a thread has one tag (its type). TagSelect (components/thread-tags.tsx) is a native select sized by its current label ("No tag" / "#bug", same trick as the model picker). It sits in the composer's tools row beside the image chip, and on the thread page the creator / owner's status-row control IS the dropdown: picking saves at once, no Edit / Save / Cancel. Readers still get the chip link to ?tag=.
  • threads.tags stays text[] so the GIN @> filter and API shape are unchanged.

Now: Postgres + Playwright are installing in the sandbox; next I run the migration and the strip-on-off SQL for real and take the "how tags are created" screenshots of the manage card.

Osebotfable-5-128d agothreadide@d49db16

Done and pushed to thread/0e08faf9 (4d01861 + d49db16 on top of the earlier passes).

How tags are created in a workspace (manage page /workspaces/<id>, owners only):

1. Tags card before opting in

  1. The Tags card starts off. Nothing tag-related exists anywhere in the workspace until the owner taps Turn on tags.

2. The list after adding three tags
2. Once on, the card shows the list editor: type bug, design, feature request and Add; each becomes a chip (#feature-request, normalised) with a two-tap × to remove it (removal also takes it off every thread).

3. Turn off tags, armed
3. Turn off tags under the list is two-tap: it removes the list and untags every thread, so "off" always means no tags anywhere.

The dropdown

home

  • Starting a thread: a No tag / #bug / #design… dropdown beside Post & run (a thread has one tag, its type). The All tags filter and the row chips are unchanged.

thread

  • On a thread: for the creator or an owner the status row's control is the dropdown and saves as soon as you pick; everyone else sees the tag as a chip linking to the filtered list. No more Edit / Save / Cancel.

phone

  • 390px: the dropdown shares the actions row with Post & run, so the Ask Osebot / model / image chips keep their room.

Decisions worth knowing

  • workspaces.tags_enabled (drizzle/0018, default off; the backfill turns it on for a workspace that already has a list). Turning off clears the list and the threads' tags in one transaction, so every control hides on the empty list and nothing else needs to check the flag. PATCH /api/workspaces/[id] { tagsEnabled }; a tags list while off is a 409.
  • One tag per thread (TAGS_MAX 1). Storage stays text[] with the GIN index, so the ?tag= filter and API are unchanged and widening to several tags later is a UI-only change.
  • Osebot's prompt still names the workspace's tags once they exist.

Verified in the sandbox against a real Postgres (migrations, refusal while off, cap to one tag in list order, rogue tags dropped, counts/filter, strip-on-remove, backfill, turn-off untagging everything) and through the dev server with Playwright for the flow above. tsc and lint clean. PR description written.

Osebot28d ago

Merged threadide #170 by @osebo (merge, d632020).