@smartmemory/wiki-components 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -26,7 +26,7 @@ npm install @smartmemory/wiki-components react react-dom date-fns lucide-react
26
26
 
27
27
  ## Contract
28
28
 
29
- `src/data-client.d.ts` is the contract: six calls (`identity`, `featureHub`, `decisions`, `decisionsPage`, `sourcesPage`, `search`), the endpoint and
29
+ `src/data-client.d.ts` is the contract: seven calls (`identity`, `featureHub`, `decisions`, `decisionsPage`, `sourcesPage`, `docsByArea`, `search`), the endpoint and
30
30
  request body each maps to on the wiki API, and the result types (from `wiki/contracts/query.schema.json`). The same list is
31
31
  runtime data in `DATA_CLIENT_CALLS`; `ui/test/wiki-components.test.jsx` pins the typed file, the table and the app's client
32
32
  to each other. `<WikiDataProvider>` refuses a client missing a method.
@@ -34,15 +34,16 @@ to each other. `<WikiDataProvider>` refuses a client missing a method.
34
34
  ## Use
35
35
 
36
36
  ```jsx
37
- import { WikiDataProvider, FeatureHub, Search, Decisions, Sources, wikiPath } from "@smartmemory/wiki-components";
37
+ import { WikiDataProvider, FeatureHub, Search, Decisions, Sources, AreaDocs, wikiPath } from "@smartmemory/wiki-components";
38
38
 
39
39
  <WikiDataProvider client={myClient}>
40
40
  <FeatureHub featureId="CORE-1" workspace="wiki-eng" />
41
41
  <Search query="recall" workspaces={["wiki-eng", "wiki-gtm"]}
42
- onNavigate={(target) => /* {kind: "search", query?, workspace?} | {kind: "note", workspace, docId} */ go(target)}
42
+ onNavigate={(target) => /* {kind: "search", query?, workspace?} | {kind: "note", workspace, docId} | {kind: "area", area} */ go(target)}
43
43
  hrefFor={(target) => `http://127.0.0.1:8791/ui${wikiPath(target)}`} />
44
44
  <Decisions workspace="wiki-eng" />
45
45
  <Sources workspace="wiki-eng" />
46
+ <AreaDocs area="search" workspace="wiki-eng" onNavigate={go} hrefFor={href} />
46
47
  </WikiDataProvider>
47
48
  ```
48
49
 
@@ -56,6 +57,10 @@ import { WikiDataProvider, FeatureHub, Search, Decisions, Sources, wikiPath } fr
56
57
  `client.sourcesPage({workspace, cursor?, size?})` (`POST /query/sources`, `filters: {}`, `page: {size, cursor?}`), which
57
58
  resolves `{items, total, next_cursor, generated_at}` with `SourceItem` rows. Also exported: `FreshnessBadge`,
58
59
  `OverdueBadge`, `useNow`, `ago`, `fmtDuration`.
60
+ - `AreaDocs` is the paged list of the docs filed under one area (`area` prop, required), 50 a page. Its data is
61
+ `client.docsByArea({workspace, area, cursor?, size?})` (`POST /query/docs_by_area`, `filters: {area}`, `page: {size, cursor?}`),
62
+ which resolves `{items, total, next_cursor, generated_at}` with `DocItem` rows. With `onNavigate` or `hrefFor`, each doc
63
+ lists its areas as links, the new NavTarget `{kind: "area", area}` (`wikiPath` gives `/area/<area>`; `areaUrl` is exported).
59
64
  - `workspace` / `workspaces` are optional: without them a screen calls `client.identity()` and uses the caller's grants
60
65
  (FeatureHub the first one).
61
66
  - `onNavigate(target)` receives a plain left click on a link and the search box's submit. `hrefFor(target)` is each link's
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smartmemory/wiki-components",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "The wiki's feature hub and search screens as router-free React components fed by an injected DataClient (WIKI-UI-COMPONENTS-1). Ships JSX source for a bundler host (Vite).",
5
5
  "license": "BUSL-1.1",
6
6
  "author": "Regression Analytics LLC",
@@ -0,0 +1,26 @@
1
+ import React from "react";
2
+ import { useDataClient, useWorkspaces } from "./data-client";
3
+ import { usePagedCall } from "./paged";
4
+ import ListPage from "./parts/ListPage";
5
+ import PageHeader from "./parts/PageHeader";
6
+ import DocRow from "./parts/DocRow";
7
+ import Loading from "./parts/Loading";
8
+ import Pager from "./parts/Pager";
9
+ import ErrorBox from "./parts/ErrorBox";
10
+
11
+ /** The docs filed under one area: `area` of `workspace` (default: the first of identity().workspaces), 50 a page with a
12
+ * pager. Each doc lists its areas as links: `onNavigate({kind: "area", area})` follows one, `hrefFor(target)` is its href.
13
+ * Data: DataClient docsByArea. */
14
+ export default function AreaDocs({ area, workspace: given, onNavigate, hrefFor }) {
15
+ const client = useDataClient();
16
+ const ws = useWorkspaces(given ? [given] : undefined);
17
+ const workspace = given || ws.workspaces?.[0];
18
+ const p = usePagedCall(["docs_by_area", workspace, area], (page) => client.docsByArea({ workspace, area, ...page }), { enabled: !!workspace && !!area });
19
+ const error = p.error || ws.error;
20
+ return (
21
+ <ListPage header={<PageHeader eyebrow="Area" title={area}>{p.total != null && `${p.total} docs`}</PageHeader>} foot={<Pager p={p} />}>
22
+ <ErrorBox error={error} />
23
+ {p.isLoading || ws.isLoading ? <Loading /> : !error && p.items.length === 0 ? <p className="text-sm text-neutral-400">No docs in this area yet.</p> : p.items.map((d) => <DocRow key={d.doc_id} doc={d} onNavigate={onNavigate} hrefFor={hrefFor} />)}
24
+ </ListPage>
25
+ );
26
+ }
@@ -1,4 +1,4 @@
1
- // WIKI-UI-COMPONENTS-1: the DataClient contract. Every call the FeatureHub, Search, Decisions and Sources screens make, and nothing else.
1
+ // WIKI-UI-COMPONENTS-1: the DataClient contract. Every call the FeatureHub, Search, Decisions, Sources and AreaDocs screens make, and nothing else.
2
2
  // A host (the wiki's /ui/ app, Compose's wiki tab) passes one object with these async methods to <WikiDataProvider>.
3
3
  // The components never fetch: each call below is the whole of their I/O.
4
4
  //
@@ -11,6 +11,7 @@
11
11
  // decisions POST /query/decisions {query: "decisions", workspace, filters: {feature_id}, page: {size: 50}}
12
12
  // decisionsPage POST /query/decisions {query: "decisions", workspace, filters: {}, page: {size: 50, cursor?}}
13
13
  // sourcesPage POST /query/sources {query: "sources", workspace, filters: {}, page: {size: 50, cursor?}}
14
+ // docsByArea POST /query/docs_by_area {query: "docs_by_area", workspace, filters: {area}, page: {size: 50, cursor?}}
14
15
  // search POST /query/search {query: "search", workspace, filters: {q}, page: {}}
15
16
  //
16
17
  // The same table is runtime data in data-client.jsx (DATA_CLIENT_CALLS); a test pins the two to each other.
@@ -128,6 +129,9 @@ export interface DataClient {
128
129
  /** POST /query/sources, filters {}, page {size (default 50), cursor?}: one page of the workspace's ingestion sources.
129
130
  * `cursor` is the previous page's `next_cursor`, opaque. */
130
131
  sourcesPage(args: { workspace: Workspace; cursor?: string; size?: number }): Promise<QueryResult<SourceItem>>;
132
+ /** POST /query/docs_by_area, filters {area} (required, 1 to 200 characters), page {size (default 50), cursor?}: one page of the live docs
133
+ * filed under `area`. `cursor` is the previous page's `next_cursor`, opaque. */
134
+ docsByArea(args: { workspace: Workspace; area: string; cursor?: string; size?: number }): Promise<QueryResult<DocItem>>;
131
135
  /** POST /query/search, filters {q} (1 to 256 characters), page {}. One call per workspace searched. */
132
136
  search(args: { workspace: Workspace; q: string }): Promise<SearchResult>;
133
137
  }
@@ -136,4 +140,5 @@ export interface DataClient {
136
140
  * (the /ui/ app: wikiPath()). */
137
141
  export type NavTarget =
138
142
  | { kind: "search"; query?: string; workspace?: Workspace }
139
- | { kind: "note"; workspace: Workspace; docId: string };
143
+ | { kind: "note"; workspace: Workspace; docId: string }
144
+ | { kind: "area"; area: string };
@@ -8,6 +8,7 @@ export const DATA_CLIENT_CALLS = [
8
8
  { method: "decisions", endpoint: "POST /query/decisions", query: "decisions", page: { size: 50 } },
9
9
  { method: "decisionsPage", endpoint: "POST /query/decisions", query: "decisions", page: { size: 50 } },
10
10
  { method: "sourcesPage", endpoint: "POST /query/sources", query: "sources", page: { size: 50 } },
11
+ { method: "docsByArea", endpoint: "POST /query/docs_by_area", query: "docs_by_area", page: { size: 50 } },
11
12
  { method: "search", endpoint: "POST /query/search", query: "search", page: {} },
12
13
  ];
13
14
 
package/src/index.d.ts CHANGED
@@ -28,6 +28,9 @@ export function Decisions(props: { workspace?: Workspace | null } & NavProps): R
28
28
  /** Every ingestion source of `workspace` (default: the first of identity().workspaces), 50 a page with a pager. */
29
29
  export function Sources(props: { workspace?: Workspace | null } & NavProps): ReactElement;
30
30
 
31
+ /** The docs filed under `area` of `workspace` (default: the first of identity().workspaces), 50 a page with a pager. Each doc's other areas link to their own AreaDocs through `onNavigate({kind: "area", area})`. */
32
+ export function AreaDocs(props: { area: string; workspace?: Workspace | null } & NavProps): ReactElement;
33
+
31
34
  /** One DataClient call paged by cursor. `run({cursor?, size})` fetches a page; a new `key` restarts at page one. */
32
35
  export function usePagedCall<T>(
33
36
  key: unknown,
@@ -46,3 +49,5 @@ export function Pager(props: { p: { total?: number; index: number; size: number;
46
49
  /** A NavTarget as a path of the wiki's /ui/ app (relative to its basename, e.g. "/search?q=x"). */
47
50
  export function wikiPath(target: NavTarget): string;
48
51
  export function wsName(workspace: Workspace): string;
52
+ /** The path of an area's docs page in the wiki's /ui/ app. */
53
+ export function areaUrl(area: string): string;
package/src/index.js CHANGED
@@ -4,9 +4,10 @@ export { default as FeatureHub, prefixOnly } from "./FeatureHub";
4
4
  export { default as Search } from "./Search";
5
5
  export { default as Decisions } from "./Decisions";
6
6
  export { default as Sources } from "./Sources";
7
+ export { default as AreaDocs } from "./AreaDocs";
7
8
  export { usePagedCall } from "./paged";
8
9
  export { WikiDataProvider, useDataClient, useClientCall, DATA_CLIENT_CALLS } from "./data-client";
9
- export { wikiPath, wsName, wsUrl, noteUrl, toDate, fmtDate, ago, fmtDuration, summaryOf } from "./lib";
10
+ export { wikiPath, wsName, wsUrl, noteUrl, areaUrl, toDate, fmtDate, ago, fmtDuration, summaryOf } from "./lib";
10
11
  export { default as useNow } from "./useNow";
11
12
  // The parts the screens are built from; the /ui/ app's other pages use them too (ui/src/components/wiki/* re-export them).
12
13
  export { default as ErrorBox } from "./parts/ErrorBox";
package/src/lib.js CHANGED
@@ -10,6 +10,7 @@ export const wsName = (ws) => {
10
10
  return WS_NAMES[tail] || tail.split(/[-_]+/).filter(Boolean).map((w) => w[0].toUpperCase() + w.slice(1)).join(" ") || "Workspace";
11
11
  };
12
12
  export const wsUrl = (ws) => `/w/${encodeURIComponent(ws)}`;
13
+ export const areaUrl = (a) => `/area/${encodeURIComponent(a)}`;
13
14
  export const noteUrl = (ws, id) => `${wsUrl(ws)}/note?id=${encodeURIComponent(id)}`;
14
15
 
15
16
  export const toDate = (d) => (d ? new Date(d.length <= 10 || /([zZ]|[+-]\d\d:?\d\d)$/.test(d) ? d : d + "Z") : null);
@@ -33,6 +34,7 @@ export const summaryOf = (feature) => (typeof feature?.summary === "string" && f
33
34
  /** A NavTarget (data-client.d.ts) as a route of the wiki's own /ui/ app, relative to its basename. */
34
35
  export function wikiPath(target) {
35
36
  if (target.kind === "note") return noteUrl(target.workspace, target.docId);
37
+ if (target.kind === "area") return areaUrl(target.area);
36
38
  if (target.kind === "search") {
37
39
  const p = new URLSearchParams({ ...(target.query ? { q: target.query } : {}), ...(target.workspace ? { workspace: target.workspace } : {}) });
38
40
  return `/search?${p}`;
@@ -1,9 +1,13 @@
1
1
  import React from "react";
2
2
  import TypeBadge from "./TypeBadge";
3
+ import NavLink from "./NavLink";
3
4
  import { fmtDate } from "../lib";
4
5
 
5
- export default function DocRow({ doc, right }) {
6
- return (
6
+ /** One doc. With `onNavigate` or `hrefFor` (a screen that links, e.g. AreaDocs) the doc's areas are listed under the row,
7
+ * each a NavTarget {kind: "area"}; without them the row is exactly as before. */
8
+ export default function DocRow({ doc, right, onNavigate, hrefFor }) {
9
+ const links = (onNavigate || hrefFor) && doc.areas?.length > 0;
10
+ const row = (
7
11
  <div className="grid items-center gap-3 rounded-md px-3 py-2 hover:bg-neutral-50 grid-cols-[6.5rem_1fr_auto] sm:grid-cols-[6.5rem_1fr_16rem_6.5rem]">
8
12
  <TypeBadge type={doc.kind} />
9
13
  <span className="truncate font-medium text-neutral-900">{doc.title}</span>
@@ -12,4 +16,15 @@ export default function DocRow({ doc, right }) {
12
16
  {right}
13
17
  </div>
14
18
  );
19
+ if (!links) return row;
20
+ return (
21
+ <div>
22
+ {row}
23
+ <div className="flex flex-wrap gap-1.5 px-3 pb-2 pl-[7.75rem]" data-testid="area-links">
24
+ {doc.areas.map((a) => (
25
+ <NavLink key={a} target={{ kind: "area", area: a }} hrefFor={hrefFor} onNavigate={onNavigate} className="rounded-full border border-neutral-200 px-2 py-0.5 text-[11px] text-neutral-600 hover:border-blue-500 hover:text-neutral-900">{a}</NavLink>
26
+ ))}
27
+ </div>
28
+ </div>
29
+ );
15
30
  }