Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 52 additions & 21 deletions apps/web/src/dashboard/lib/collections.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { writableChangelogStatus } from "@feeblo/domain/changelog/machine";
import type { CommentReaction } from "@feeblo/domain/comment-reaction/schema";
import { HELP_CENTER_ARTICLE_LIST_MAX_LIMIT } from "@feeblo/domain/help-center-article/schema";
import type { TPostActivity } from "@feeblo/domain/post-activity/schema";
import type { PostReaction } from "@feeblo/domain/post-reaction/schema";
import type { PostSubscription } from "@feeblo/domain/post-subscription/schema";
Expand Down Expand Up @@ -33,6 +34,7 @@ import {
BasicIndex,
collectionOptions,
DbClient,
getLoadSubsetDemandKey,
parseLoadSubsetOptions,
} from "@tanstack/react-db";
import type {
Expand Down Expand Up @@ -733,10 +735,10 @@ export const HELP_CENTER_SECTION_ARTICLE_PAGE_SIZE = 25;
* drift between the two would leave the section page showing the article as it
* was before the save.
*
* It is the section's prefix, not a page: the on-demand collection appends the
* `LoadSubsetOptions` it is asked for (the window and the filters) to this key,
* which is what gives each page its own cache entry while the editor can still
* invalidate every page of a section by its prefix.
* It is the section's prefix, not a page: the collection's key function appends
* the demand's identity (the window and the filters) to this key, which is what
* gives each page its own cache entry while the editor can still invalidate
* every page of a section by its prefix.
*/
export function helpCenterArticleTopicQueryKey(
organizationId: string | undefined,
Expand Down Expand Up @@ -764,6 +766,15 @@ export function helpCenterArticleTopicQueryKey(
* order `sort: "updated"` names. The section page must order by the same two
* columns the repository sorts by, or a window would be cut from one order and
* rendered in another.
*
* The key is a function because a static on-demand key leaves the library a
* second, windowless "full source" query under the base key. That query asks
* for the whole section — the read pagination exists to remove — so the
* operation refuses it, and the editor's post-write invalidation, which
* refreshes this collection by its key, refetched the refused query and
* replaced the section page with its "Help center unavailable" state. A key
* function has no full-source query; the demand key it appends is the same
* identity the library appends to a static on-demand key itself.
*/
export function helpCenterTopicArticleCollection(
scope: DashboardCollectionScope,
Expand All @@ -778,7 +789,19 @@ export function helpCenterTopicArticleCollection(
queryCollectionOptions({
id,
queryClient: client.requireDependency<QueryClient>("queryClient"),
queryKey: helpCenterArticleTopicQueryKey(scope.organizationId, topicId),
// Each window is its own cache entry, so invalidating the section's
// prefix refreshes the pages that were asked for and cannot ask for the
// whole section to refresh them.
queryKey: (opts) => {
const base = helpCenterArticleTopicQueryKey(
scope.organizationId,
topicId
);

const demand = getLoadSubsetDemandKey(opts);

return demand === undefined ? base : [...base, demand];
},
queryFn: async (ctx) => {
const organizationId = scope.organizationId;

Expand All @@ -788,28 +811,36 @@ export function helpCenterTopicArticleCollection(

const window = ctx.meta?.loadSubsetOptions;

// The page windows every read, and the operation refuses a
// section-scoped list without one: a demand that named no window would
// ask the server for the whole section, which is the read this
// collection exists to avoid. It fails there rather than quietly
// returning a page a windowless demander would take as complete.
//
// The list operation filters by workspace and section on the server;
// the live query keeps its predicate as a second guard. The
// workspace-wide collection stays for the plan-usage meter, which is
// the one caller allowed to read without a window.
/**
* The window this demand asks for, or the whole browsable section.
*
* The page's demands name a window, but the collection's loader also
* asks for subsets that an offset/limit operation cannot express: an
* authoritative re-read after a write, and the boundary repair it runs
* when a refetched page moved a row (a publication sends the article to
* the top). Those demands name no limit, and the operation refuses a
* section-scoped read without one — so answering them with the list's
* own ceiling is what keeps the section page alive instead of failing
* its list. A single page would be worse than the cost: the loader
* would take it as the extent of the source and drop rows that sit
* past it.
*
* The list operation filters by workspace and section on the server;
* the live query keeps its predicate as a second guard. The
* workspace-wide collection stays for the plan-usage meter, which is
* the one caller allowed to read without a topic.
*/
const limit = window?.limit ?? HELP_CENTER_ARTICLE_LIST_MAX_LIMIT;
const offset = window?.offset ?? 0;

const data = await fetchRpc(
(rpc) =>
rpc.ListHelpCenterArticles({
organizationId,
limit,
offset,
sort: "updated",
topicId,
...(window?.limit === undefined
? undefined
: { limit: window.limit }),
...(window?.offset === undefined
? undefined
: { offset: window.offset }),
}),
{ signal: ctx.signal }
);
Expand Down
7 changes: 7 additions & 0 deletions apps/web/src/routes/s/help/articles/$articleSlug.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { PublicBoardPending } from "@feeblo/public-feature-board/components/pending";
import { createFileRoute } from "@tanstack/react-router";

import { HelpCenterArticlePage } from "@/portal/help-center/help-center-article-page";

export const Route = createFileRoute("/s/help/articles/$articleSlug")({
// Same shape as the help center index: the article arrives through the
// portal's Effect atoms, which the server cannot build a protocol for and
// does not dehydrate, so the body renders in the browser. The layout above
// still resolves the article's metadata and JSON-LD for crawlers.
pendingComponent: PublicBoardPending,
ssr: false,
component: RouteComponent,
});

Expand Down
14 changes: 14 additions & 0 deletions apps/web/src/routes/s/help/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
import { PublicBoardPending } from "@feeblo/public-feature-board/components/pending";
import { createFileRoute } from "@tanstack/react-router";

import { HelpCenterPage } from "@/portal/help-center/help-center-page";

export const Route = createFileRoute("/s/help/")({
// The body is client-rendered: it reads its documentation through Effect
// atoms, whose protocol is built from the browser's injected env and whose
// values are not dehydrated into the document. A server render would build
// the protocol from `undefined` and throw, and with that patched it would
// still produce markup the browser cannot reproduce on its first render —
// a hydration mismatch rather than a flash. The layout above still resolves
// the site and the page metadata for crawlers.
//
// The pending state must be the board's own: the router's default is the
// dashboard's skeleton, and for an `ssr: false` route that skeleton is what
// the server renders into the board shell.
pendingComponent: PublicBoardPending,
ssr: false,
component: HelpCenterPage,
});
4 changes: 3 additions & 1 deletion docs/help-center.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ A flip is an `UPDATE` of the same row. Flipping to helpful clears `reason`, beca

**Portal** (`ListHelpCenterTopicsPublic`, `ListHelpCenterArticlesPublic`, `GetHelpCenterArticlePublic`, `GetHelpCenterArticleFeedbackPublic`, `SetHelpCenterArticleFeedback`, `AddHelpCenterArticleView`, `GetHelpCenterAvailabilityPublic`) sees `published` and `archived` only, reads by slug, and gates on `SitePolicy.canViewHelpCenter`. A section that holds no published article is not listed, so publishing an empty section cannot disclose the draft pipeline. `GetHelpCenterAvailabilityPublic` is the same gate answered as a yes/no: the board's navbar draws its Help tab from it, so a public help center nobody has written into yet gets no tab that opens onto “No documentation yet” — the rule the widget already applies to its own tab.

**Dashboard routes.** `/$organizationId/help-center` lists the sections and their article counts, and is the only place a section is created; its row menu also moves a section up or down, sending the complete order to `ReorderHelpCenterTopics`. `/$organizationId/help-center/$topicId` is one section: its articles with the three counters, a page at a time — the list asks the collection for a window and `Load more` widens it — plus the section's edit and delete actions. `/$organizationId/help-center/$topicId/new` and `/$organizationId/help-center/article/$articleId` are the editor, opened on the create page with its section already chosen. It has the changelog editor's shape: a cover image, a title, the body, and a sidebar with the section. The slug is not a field — it is chosen in the publish dialog, so a save cannot move a live page's URL — and saving keeps the current status while publishing asks for the slug and date. A save carries the status **and** `updatedAt` the editor loaded, so a colleague's same-status save is a conflict rather than an overwrite; a refreshed row shows a reload banner and disables the write actions. The state changes the lifecycle does not derive from those (`archive`, `restore`) are offered beside the article's delete action, which asks for confirmation because a hard delete breaks the public URL. The body is edited in the same ProseKit editor the changelog uses and stored as Markdown — the editor serializes its document to Markdown and parses it back — so pasted images are written to `tmp/editor-media/` and the write's `assetIds` let the handler promote them to permanent objects before the row stores their URLs. The list collection holds summaries only — the editor reads one article by id and writes through the RPC operations, then invalidates the section's query key rather than waiting on a workspace-wide list. The editor's sidebar also shows the article's recent unhelpful votes with reasons, manager-only. The dashboard's search is a command dialog behind an icon in the index toolbar; it reads the dashboard `SearchHelpCenterArticles` operation, so drafts are findable.
**Dashboard routes.** `/$organizationId/help-center` lists the sections and their article counts, and is the only place a section is created; its row menu also moves a section up or down, sending the complete order to `ReorderHelpCenterTopics`. `/$organizationId/help-center/$topicId` is one section: its articles with the three counters, a page at a time — the list asks the collection for a window and `Load more` widens it — plus the section's edit and delete actions. `/$organizationId/help-center/$topicId/new` and `/$organizationId/help-center/article/$articleId` are the editor, opened on the create page with its section already chosen. It has the changelog editor's shape: a cover image, a title, the body, and a sidebar with the section. The slug is not a field — it is chosen in the publish dialog, so a save cannot move a live page's URL — and saving keeps the current status while publishing asks for the slug and date. A save carries the status **and** `updatedAt` the editor loaded, so a colleague's same-status save is a conflict rather than an overwrite; a refreshed row shows a reload banner and disables the write actions. The state changes the lifecycle does not derive from those (`archive`, `restore`) are offered beside the article's delete action, which asks for confirmation because a hard delete breaks the public URL. The body is edited in the same ProseKit editor the changelog uses and stored as Markdown — the editor serializes its document to Markdown and parses it back — so pasted images are written to `tmp/editor-media/` and the write's `assetIds` let the handler promote them to permanent objects before the row stores their URLs. The list collection holds summaries only — the editor reads one article by id and writes through the RPC operations, then invalidates the section's query key rather than waiting on a workspace-wide list. That key is a function of the demanded window rather than a static base key: a static on-demand key leaves the library a second, windowless query for the whole section, which the operation refuses. The collection also answers the loader's windowless authoritative reads — the re-read after a write and the boundary repair when a refetched page moved a row — with the list's 500-row ceiling, because an offset/limit operation cannot express the boundary and refusing the read replaced the section page with its unavailable state after a save. The editor's sidebar also shows the article's recent unhelpful votes with reasons, manager-only. The dashboard's search is a command dialog behind an icon in the index toolbar; it reads the dashboard `SearchHelpCenterArticles` operation, so drafts are findable.

**Portal routes.** `/s/help` and `/s/help/articles/$articleSlug`, in three columns: a rail of sections that opens in place, the article — cover image, title, section, reading time, the stored Markdown with heading anchors, the verdict — and a rail with "On this page", the article's actions, and a pointer to the board. The actions are Copy as Markdown, Export (download the Markdown mirror or print to PDF), Open in chat (a prefilled prompt pointed at the Markdown mirror), and Connect to MCP (the board's help-center MCP endpoint, with copy-ready client commands). Below `xl` they ride under the "On this page" disclosure, or in an "Article actions" disclosure when the article has no outline. Previous/next stay inside the section. The rails render from the public list, so navigating between articles never unmounts them: sections the reader opened stay open while the next body loads.

Both portal routes are `ssr: false`: their bodies read the public projections through Effect atoms, whose protocol is built from the browser's injected env and whose values are not dehydrated into the document, so a server render would produce markup the browser cannot reproduce on its first render. The layout above still server-renders the site, the page metadata and the article's JSON-LD for crawlers.

**Widget.** The same documentation is a widget module (`help`) beside `feedback` and `updates`, for a customer who would rather read than post. Two endpoints serve it: `POST /api/widget/v1/help-center` lists every published article with its section, ordered by section then article, so the iframe groups them without a topic read; `POST /api/widget/v1/help-center/article` answers one article by slug, rendered to HTML through the cached pipeline the updates module uses, or `article: null` for a slug that is not published — a reader cannot tell a draft from a typo. Both answer `enabled: false` under the same conditions as the deflection below — and the list also answers it when nothing is readable, because the widget's tab is decided by that one value and an empty documentation page is worse than no tab. Archived articles travel with `isArchived`, like the portal's carrier: a withdrawn page still resolves and says it is out of date. A hub whose only remaining surface is one tab renders no tab bar, so a reader who landed on `/help` is moved to the first module that exists rather than being left on a page that will never fill; a single-module `help` embed keeps its own empty state, since there is nowhere else to send them.

## Search
Expand Down
Loading
Loading