@smartmemory/wiki-components 0.4.0 → 0.5.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: seven calls (`identity`, `featureHub`, `decisions`, `decisionsPage`, `sourcesPage`, `docsByArea`, `search`), the endpoint and
29
+ `src/data-client.d.ts` is the contract: nine calls (`identity`, `featureHub`, `decisions`, `decisionsPage`, `sourcesPage`, `docsByArea`, `ledger`, `upcomingCalls`, `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,7 +34,7 @@ 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, AreaDocs, wikiPath } from "@smartmemory/wiki-components";
37
+ import { WikiDataProvider, FeatureHub, Search, Decisions, Sources, AreaDocs, Ledger, wikiPath } from "@smartmemory/wiki-components";
38
38
 
39
39
  <WikiDataProvider client={myClient}>
40
40
  <FeatureHub featureId="CORE-1" workspace="wiki-eng" />
@@ -44,6 +44,7 @@ import { WikiDataProvider, FeatureHub, Search, Decisions, Sources, AreaDocs, wik
44
44
  <Decisions workspace="wiki-eng" />
45
45
  <Sources workspace="wiki-eng" />
46
46
  <AreaDocs area="search" workspace="wiki-eng" onNavigate={go} hrefFor={href} />
47
+ <Ledger workspace="wiki-eng" />
47
48
  </WikiDataProvider>
48
49
  ```
49
50
 
@@ -61,6 +62,13 @@ import { WikiDataProvider, FeatureHub, Search, Decisions, Sources, AreaDocs, wik
61
62
  `client.docsByArea({workspace, area, cursor?, size?})` (`POST /query/docs_by_area`, `filters: {area}`, `page: {size, cursor?}`),
62
63
  which resolves `{items, total, next_cursor, generated_at}` with `DocItem` rows. With `onNavigate` or `hrefFor`, each doc
63
64
  lists its areas as links, the new NavTarget `{kind: "area", area}` (`wikiPath` gives `/area/<area>`; `areaUrl` is exported).
65
+ - `Ledger` is the last 30 days of the workspace's ledger, newest first, 50 a page, plus an "Upcoming calls" section when
66
+ the host serves that feed. Its data is `client.ledger({workspace, from, to, cursor?, size?})` (`POST /query/ledger`,
67
+ `filters: {from, to}`, ISO instants with an offset; the sort is the host's, `ts` newest first, a screen never sends it),
68
+ which resolves `{items, total, next_cursor, generated_at}` with `EntryItem` rows, and `client.upcomingCalls({workspace})`
69
+ (`GET /feeds/upcoming_calls`), which resolves `{items, errors}`, or `null` when the host does not serve the feed (the
70
+ section is then left out; an empty feed still shows "No upcoming calls."). The window is 30 days back to one day ahead of
71
+ `now`, an optional prop (ms since the epoch) for tests, else the first render's time. Also exported: `LedgerTimeline`.
64
72
  - `workspace` / `workspaces` are optional: without them a screen calls `client.identity()` and uses the caller's grants
65
73
  (FeatureHub the first one).
66
74
  - `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.4.0",
3
+ "version": "0.5.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",
package/src/Ledger.jsx ADDED
@@ -0,0 +1,47 @@
1
+ import React, { useMemo } from "react";
2
+ import { useClientCall, useDataClient, useWorkspaces } from "./data-client";
3
+ import { usePagedCall } from "./paged";
4
+ import ListPage from "./parts/ListPage";
5
+ import PageHeader from "./parts/PageHeader";
6
+ import LedgerTimeline from "./parts/LedgerTimeline";
7
+ import EntryRows from "./parts/EntryRows";
8
+ import Section from "./parts/Section";
9
+ import Loading from "./parts/Loading";
10
+ import Pager from "./parts/Pager";
11
+ import ErrorBox from "./parts/ErrorBox";
12
+
13
+ const DAY_MS = 86_400_000;
14
+ const iso = (ms) => new Date(ms).toISOString().replace(/\.\d+Z$/, "Z");
15
+
16
+ /** The ledger timeline: the last 30 days of `workspace` (default: the first of identity().workspaces), newest first, 50 a
17
+ * page with a pager, and an "Upcoming calls" section when the host serves that feed. The window runs from 30 days before
18
+ * `now` to one day after it (ms since the epoch; default: the time of the first render, kept for the life of the screen so
19
+ * the query key stays stable). `onNavigate` / `hrefFor` are accepted for the host contract shared by the screens; the
20
+ * timeline has no links yet. Data: DataClient ledger (one call per page) and upcomingCalls (one call). */
21
+ export default function Ledger({ workspace: given, now }) {
22
+ const client = useDataClient();
23
+ const ws = useWorkspaces(given ? [given] : undefined);
24
+ const workspace = given || ws.workspaces?.[0];
25
+ const fixedNow = useMemo(() => Date.now(), []);
26
+ const at = now ?? fixedNow;
27
+ const range = useMemo(() => ({ from: iso(at - 30 * DAY_MS), to: iso(at + DAY_MS) }), [at]);
28
+ const p = usePagedCall(["ledger", workspace, range], (page) => client.ledger({ workspace, ...range, ...page }), { enabled: !!workspace });
29
+ const calls = useClientCall(["upcoming_calls", workspace], () => client.upcomingCalls({ workspace }), { enabled: !!workspace });
30
+ const error = p.error || ws.error;
31
+ return (
32
+ <ListPage header={<PageHeader title="Ledger">{p.total != null && `${p.total.toLocaleString()} entries in the last 30 days, newest first`}</PageHeader>} foot={<Pager p={p} />}>
33
+ <ErrorBox error={error} />
34
+ {p.isLoading || ws.isLoading ? <Loading /> : <LedgerTimeline entries={p.items} />}
35
+ {/* the calendar feed is served only on a host that wires it: elsewhere (null) there is no calls section */}
36
+ {!calls.isLoading && calls.data !== null && (calls.data || calls.error) && (
37
+ <Section title="Upcoming calls" className="mt-12">
38
+ {(calls.data?.errors || []).map((e) => (
39
+ <p key={e.code} role="status" className="mb-2 rounded-md border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-800">Calls are incomplete: {e.message} ({e.code})</p>
40
+ ))}
41
+ <ErrorBox error={calls.error} />
42
+ {calls.data && <EntryRows entries={calls.data.items} empty="No upcoming calls." />}
43
+ </Section>
44
+ )}
45
+ </ListPage>
46
+ );
47
+ }
@@ -1,4 +1,4 @@
1
- // WIKI-UI-COMPONENTS-1: the DataClient contract. Every call the FeatureHub, Search, Decisions, Sources and AreaDocs screens make, and nothing else.
1
+ // WIKI-UI-COMPONENTS-1: the DataClient contract. Every call the FeatureHub, Search, Decisions, Sources, AreaDocs and Ledger 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
  //
@@ -12,6 +12,8 @@
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
14
  // docsByArea POST /query/docs_by_area {query: "docs_by_area", workspace, filters: {area}, page: {size: 50, cursor?}}
15
+ // ledger POST /query/ledger {query: "ledger", workspace, filters: {from, to}, page: {size: 50, cursor?}} (sort is the host's: ts, newest first)
16
+ // upcomingCalls GET /feeds/upcoming_calls?workspace= (none) -> data_envelope; an absent feed (the wiki answers 404 not_found) resolves to null
15
17
  // search POST /query/search {query: "search", workspace, filters: {q}, page: {}}
16
18
  //
17
19
  // The same table is runtime data in data-client.jsx (DATA_CLIENT_CALLS); a test pins the two to each other.
@@ -105,6 +107,12 @@ export interface SourceItem {
105
107
  overdue: boolean | null;
106
108
  }
107
109
 
110
+ /** The upcoming_calls feed (component.schema.json data_envelope): `items` are entries; `errors` say what a partial answer is missing. */
111
+ export interface UpcomingCalls {
112
+ items: EntryItem[];
113
+ errors: { code: string; message?: string }[];
114
+ }
115
+
108
116
  /** x-named-queries.feature_hub.result: the feature's docs plus the feature itself (null when it is not on the roadmap). */
109
117
  export interface FeatureHubResult extends QueryResult<DocItem> {
110
118
  feature: FeatureItem | null;
@@ -132,6 +140,11 @@ export interface DataClient {
132
140
  /** POST /query/docs_by_area, filters {area} (required, 1 to 200 characters), page {size (default 50), cursor?}: one page of the live docs
133
141
  * filed under `area`. `cursor` is the previous page's `next_cursor`, opaque. */
134
142
  docsByArea(args: { workspace: Workspace; area: string; cursor?: string; size?: number }): Promise<QueryResult<DocItem>>;
143
+ /** POST /query/ledger, filters {from, to} (both required: ISO instants with an offset, `from` <= `to`, at most 366 days apart), page {size (default 50), cursor?}:
144
+ * one page of the ledger entries in the window, newest first (the sort is fixed by the host, never sent by a screen). `cursor` is the previous page's `next_cursor`, opaque. */
145
+ ledger(args: { workspace: Workspace; from: string; to: string; cursor?: string; size?: number }): Promise<QueryResult<EntryItem>>;
146
+ /** GET /feeds/upcoming_calls: the calendar feed's items, or null when this host does not serve the feed (not an error, not an empty list). */
147
+ upcomingCalls(args: { workspace: Workspace }): Promise<UpcomingCalls | null>;
135
148
  /** POST /query/search, filters {q} (1 to 256 characters), page {}. One call per workspace searched. */
136
149
  search(args: { workspace: Workspace; q: string }): Promise<SearchResult>;
137
150
  }
@@ -9,6 +9,8 @@ export const DATA_CLIENT_CALLS = [
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
11
  { method: "docsByArea", endpoint: "POST /query/docs_by_area", query: "docs_by_area", page: { size: 50 } },
12
+ { method: "ledger", endpoint: "POST /query/ledger", query: "ledger", page: { size: 50 } },
13
+ { method: "upcomingCalls", endpoint: "GET /feeds/upcoming_calls" },
12
14
  { method: "search", endpoint: "POST /query/search", query: "search", page: {} },
13
15
  ];
14
16
 
package/src/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  // Types for @smartmemory/wiki-components. The DataClient contract and NavTarget: data-client.d.ts.
2
2
  import type { ReactElement, ReactNode } from "react";
3
- import type { DataClient, NavTarget, QueryResult, Workspace } from "./data-client";
3
+ import type { DataClient, EntryItem, NavTarget, QueryResult, Workspace } from "./data-client";
4
4
 
5
5
  export * from "./data-client";
6
6
 
@@ -31,6 +31,10 @@ export function Sources(props: { workspace?: Workspace | null } & NavProps): Rea
31
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
32
  export function AreaDocs(props: { area: string; workspace?: Workspace | null } & NavProps): ReactElement;
33
33
 
34
+ /** The last 30 days of `workspace` (default: the first of identity().workspaces), newest first, 50 a page with a pager, plus an "Upcoming calls" section when the host serves that feed. `now` (ms since the epoch) fixes the window's end for tests; default: the first render's time. */
35
+ export function Ledger(props: { workspace?: Workspace | null; now?: number } & NavProps): ReactElement;
36
+ export function LedgerTimeline(props: { entries: EntryItem[] }): ReactElement;
37
+
34
38
  /** One DataClient call paged by cursor. `run({cursor?, size})` fetches a page; a new `key` restarts at page one. */
35
39
  export function usePagedCall<T>(
36
40
  key: unknown,
package/src/index.js CHANGED
@@ -5,6 +5,7 @@ export { default as Search } from "./Search";
5
5
  export { default as Decisions } from "./Decisions";
6
6
  export { default as Sources } from "./Sources";
7
7
  export { default as AreaDocs } from "./AreaDocs";
8
+ export { default as Ledger } from "./Ledger";
8
9
  export { usePagedCall } from "./paged";
9
10
  export { WikiDataProvider, useDataClient, useClientCall, DATA_CLIENT_CALLS } from "./data-client";
10
11
  export { wikiPath, wsName, wsUrl, noteUrl, areaUrl, toDate, fmtDate, ago, fmtDuration, summaryOf } from "./lib";
@@ -25,5 +26,6 @@ export { default as SearchBox } from "./parts/SearchBox";
25
26
  export { default as NavLink } from "./parts/NavLink";
26
27
  export { default as Table } from "./parts/Table";
27
28
  export { default as Pager } from "./parts/Pager";
29
+ export { default as LedgerTimeline } from "./parts/LedgerTimeline";
28
30
  export { default as FreshnessBadge } from "./parts/FreshnessBadge";
29
31
  export { default as OverdueBadge } from "./parts/OverdueBadge";
@@ -0,0 +1,20 @@
1
+ import React from "react";
2
+ import { fmtDate } from "../lib";
3
+
4
+ export default function LedgerTimeline({ entries }) {
5
+ if (!entries.length) return <p className="px-3 text-sm text-neutral-400">No ledger entries.</p>;
6
+ return (
7
+ <ol className="relative ml-2 border-l border-neutral-200">
8
+ {entries.map((e, i) => (
9
+ <li key={e.entry_id} className="relative pb-4 pl-5">
10
+ <span className="absolute -left-[4.5px] top-1.5 h-2 w-2 rounded-full bg-neutral-300" />
11
+ {(i === 0 || entries[i - 1].ts.slice(0, 10) !== e.ts.slice(0, 10)) && <div className="mb-1 text-xs font-semibold text-neutral-500">{fmtDate(e.ts)}</div>}
12
+ <div className="flex flex-wrap items-baseline gap-x-2 gap-y-1">
13
+ <span className="font-mono text-[11px] text-neutral-400">{e.ts.slice(11, 16)}</span>
14
+ <span className="text-[13px] text-neutral-800">{e.text}</span>
15
+ </div>
16
+ </li>
17
+ ))}
18
+ </ol>
19
+ );
20
+ }