@smartmemory/wiki-components 0.2.0 → 0.3.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: five calls (`identity`, `featureHub`, `decisions`, `decisionsPage`, `search`), the endpoint and
29
+ `src/data-client.d.ts` is the contract: six calls (`identity`, `featureHub`, `decisions`, `decisionsPage`, `sourcesPage`, `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, wikiPath } from "@smartmemory/wiki-components";
37
+ import { WikiDataProvider, FeatureHub, Search, Decisions, Sources, wikiPath } from "@smartmemory/wiki-components";
38
38
 
39
39
  <WikiDataProvider client={myClient}>
40
40
  <FeatureHub featureId="CORE-1" workspace="wiki-eng" />
@@ -42,6 +42,7 @@ import { WikiDataProvider, FeatureHub, Search, Decisions, wikiPath } from "@smar
42
42
  onNavigate={(target) => /* {kind: "search", query?, workspace?} | {kind: "note", workspace, docId} */ go(target)}
43
43
  hrefFor={(target) => `http://127.0.0.1:8791/ui${wikiPath(target)}`} />
44
44
  <Decisions workspace="wiki-eng" />
45
+ <Sources workspace="wiki-eng" />
45
46
  </WikiDataProvider>
46
47
  ```
47
48
 
@@ -50,6 +51,11 @@ import { WikiDataProvider, FeatureHub, Search, Decisions, wikiPath } from "@smar
50
51
  which resolves `{items, total, next_cursor, generated_at}`. `cursor` is the previous page's `next_cursor`, opaque.
51
52
  The paging pieces are exported for the next screens: `usePagedCall(key, run, {size})` (the cursor stack in component
52
53
  state, no react-query), `Table`, `Pager`.
54
+ - `Sources` is the paged list of the workspace's ingestion sources, 50 a page, with status, last success, indexing age,
55
+ publication delay and an overdue badge (an unknown value reads "unknown", never 0 or "on time"). Its data is
56
+ `client.sourcesPage({workspace, cursor?, size?})` (`POST /query/sources`, `filters: {}`, `page: {size, cursor?}`), which
57
+ resolves `{items, total, next_cursor, generated_at}` with `SourceItem` rows. Also exported: `FreshnessBadge`,
58
+ `OverdueBadge`, `useNow`, `ago`, `fmtDuration`.
53
59
  - `workspace` / `workspaces` are optional: without them a screen calls `client.identity()` and uses the caller's grants
54
60
  (FeatureHub the first one).
55
61
  - `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.2.0",
3
+ "version": "0.3.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,41 @@
1
+ import React from "react";
2
+ import { useDataClient, useWorkspaces } from "./data-client";
3
+ import { usePagedCall } from "./paged";
4
+ import { fmtDuration } from "./lib";
5
+ import ListPage from "./parts/ListPage";
6
+ import PageHeader from "./parts/PageHeader";
7
+ import Table from "./parts/Table";
8
+ import Pager from "./parts/Pager";
9
+ import StatusChip from "./parts/StatusChip";
10
+ import FreshnessBadge from "./parts/FreshnessBadge";
11
+ import OverdueBadge from "./parts/OverdueBadge";
12
+
13
+ /** The sources list: every ingestion source of `workspace` (default: the first of identity().workspaces), 50 a page with a
14
+ * pager, each with its status, last success, indexing age, publication delay and overdue flag. `onNavigate` / `hrefFor`
15
+ * are accepted for the host contract shared by the screens; the list has no links. Data: DataClient sourcesPage. */
16
+ export default function Sources({ workspace: given }) {
17
+ const client = useDataClient();
18
+ const ws = useWorkspaces(given ? [given] : undefined);
19
+ const workspace = given || ws.workspaces?.[0];
20
+ const p = usePagedCall(["sources", workspace], (page) => client.sourcesPage({ workspace, ...page }), { enabled: !!workspace });
21
+ return (
22
+ <ListPage header={<PageHeader title="Sources">Where the indexer reads from, and how fresh each one is.</PageHeader>} foot={<Pager p={p} />}>
23
+ <Table head={["Source", "Plugin", "Host", "Docs", "Coverage", "Status", "Last success", "Indexing age", "Publication delay", "Overdue"]} loading={p.isLoading || ws.isLoading} error={p.error || ws.error} count={p.items.length}>
24
+ {p.items.map((s) => (
25
+ <tr key={s.source_id} className="align-top hover:bg-neutral-50/60">
26
+ <td className="px-3 py-2.5 font-medium">{s.source_id}</td>
27
+ <td className="px-3 py-2.5 font-mono text-xs text-neutral-600">{s.plugin}</td>
28
+ <td className="px-3 py-2.5 font-mono text-xs text-neutral-600">{s.host}</td>
29
+ <td className="px-3 py-2.5 tabular-nums">{s.discovered.toLocaleString()}</td>
30
+ <td className="px-3 py-2.5 text-xs text-neutral-600">{s.coverage}</td>
31
+ <td className="px-3 py-2.5"><StatusChip status={s.status} /></td>
32
+ <td className="px-3 py-2.5"><FreshnessBadge at={s.last_success} /></td>
33
+ <td className="px-3 py-2.5 tabular-nums text-xs text-neutral-600">{fmtDuration(s.indexing_age_s)}</td>
34
+ <td className="px-3 py-2.5 tabular-nums text-xs text-neutral-600">{fmtDuration(s.publication_delay_s)}</td>
35
+ <td className="px-3 py-2.5"><OverdueBadge overdue={s.overdue} /></td>
36
+ </tr>
37
+ ))}
38
+ </Table>
39
+ </ListPage>
40
+ );
41
+ }
@@ -1,4 +1,4 @@
1
- // WIKI-UI-COMPONENTS-1: the DataClient contract. Every call the FeatureHub, Search and Decisions screens make, and nothing else.
1
+ // WIKI-UI-COMPONENTS-1: the DataClient contract. Every call the FeatureHub, Search, Decisions and Sources 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
  //
@@ -10,6 +10,7 @@
10
10
  // featureHub POST /query/feature_hub {query: "feature_hub", workspace, filters: {feature_id}, page: {size: 200}}
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
+ // sourcesPage POST /query/sources {query: "sources", workspace, filters: {}, page: {size: 50, cursor?}}
13
14
  // search POST /query/search {query: "search", workspace, filters: {q}, page: {}}
14
15
  //
15
16
  // The same table is runtime data in data-client.jsx (DATA_CLIENT_CALLS); a test pins the two to each other.
@@ -89,6 +90,20 @@ export interface QueryResult<T> {
89
90
  generated_at: string;
90
91
  }
91
92
 
93
+ /** query.schema.json $defs/source_item. `overdue` and the two durations are null when unknown (never shown as 0 or "on time"). */
94
+ export interface SourceItem {
95
+ source_id: string;
96
+ plugin: string;
97
+ host: "us1" | "mac";
98
+ status: "ok" | "offline" | "failed" | "cursor_lost";
99
+ coverage: "full_text" | "excerpt" | "metadata";
100
+ last_success: string | null;
101
+ discovered: number;
102
+ indexing_age_s: number | null;
103
+ publication_delay_s: number | null;
104
+ overdue: boolean | null;
105
+ }
106
+
92
107
  /** x-named-queries.feature_hub.result: the feature's docs plus the feature itself (null when it is not on the roadmap). */
93
108
  export interface FeatureHubResult extends QueryResult<DocItem> {
94
109
  feature: FeatureItem | null;
@@ -110,6 +125,9 @@ export interface DataClient {
110
125
  /** POST /query/decisions, filters {}, page {size (default 50), cursor?}: one page of every decision of the workspace, newest first.
111
126
  * `cursor` is the previous page's `next_cursor`, opaque. */
112
127
  decisionsPage(args: { workspace: Workspace; cursor?: string; size?: number }): Promise<QueryResult<EntryItem>>;
128
+ /** POST /query/sources, filters {}, page {size (default 50), cursor?}: one page of the workspace's ingestion sources.
129
+ * `cursor` is the previous page's `next_cursor`, opaque. */
130
+ sourcesPage(args: { workspace: Workspace; cursor?: string; size?: number }): Promise<QueryResult<SourceItem>>;
113
131
  /** POST /query/search, filters {q} (1 to 256 characters), page {}. One call per workspace searched. */
114
132
  search(args: { workspace: Workspace; q: string }): Promise<SearchResult>;
115
133
  }
@@ -7,6 +7,7 @@ export const DATA_CLIENT_CALLS = [
7
7
  { method: "featureHub", endpoint: "POST /query/feature_hub", query: "feature_hub", page: { size: 200 } },
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
+ { method: "sourcesPage", endpoint: "POST /query/sources", query: "sources", page: { size: 50 } },
10
11
  { method: "search", endpoint: "POST /query/search", query: "search", page: {} },
11
12
  ];
12
13
 
package/src/index.d.ts CHANGED
@@ -25,6 +25,9 @@ export const DATA_CLIENT_CALLS: { method: keyof DataClient; endpoint: string; qu
25
25
  /** Every recorded decision of `workspace` (default: the first of identity().workspaces), 50 a page with a pager. */
26
26
  export function Decisions(props: { workspace?: Workspace | null } & NavProps): ReactElement;
27
27
 
28
+ /** Every ingestion source of `workspace` (default: the first of identity().workspaces), 50 a page with a pager. */
29
+ export function Sources(props: { workspace?: Workspace | null } & NavProps): ReactElement;
30
+
28
31
  /** One DataClient call paged by cursor. `run({cursor?, size})` fetches a page; a new `key` restarts at page one. */
29
32
  export function usePagedCall<T>(
30
33
  key: unknown,
@@ -32,6 +35,11 @@ export function usePagedCall<T>(
32
35
  opts?: { size?: number; enabled?: boolean },
33
36
  ): { items: T[]; result?: QueryResult<T>; total?: number; isLoading: boolean; error: Error | null; index: number; size: number; next: (() => void) | null; prev: (() => void) | null };
34
37
 
38
+ export function FreshnessBadge(props: { at?: string | null }): ReactElement;
39
+ export function OverdueBadge(props: { overdue?: boolean | null }): ReactElement;
40
+ export function ago(d?: string | null): string;
41
+ export function fmtDuration(s?: number | null): string;
42
+ export function useNow(ms?: number): number;
35
43
  export function Table(props: { head: ReactNode[]; children?: ReactNode; loading?: boolean; error?: Error | null; empty?: string; count?: number }): ReactElement;
36
44
  export function Pager(props: { p: { total?: number; index: number; size: number; items: unknown[]; next: (() => void) | null; prev: (() => void) | null } }): ReactElement | null;
37
45
 
package/src/index.js CHANGED
@@ -3,9 +3,11 @@
3
3
  export { default as FeatureHub, prefixOnly } from "./FeatureHub";
4
4
  export { default as Search } from "./Search";
5
5
  export { default as Decisions } from "./Decisions";
6
+ export { default as Sources } from "./Sources";
6
7
  export { usePagedCall } from "./paged";
7
8
  export { WikiDataProvider, useDataClient, useClientCall, DATA_CLIENT_CALLS } from "./data-client";
8
- export { wikiPath, wsName, wsUrl, noteUrl, toDate, fmtDate, summaryOf } from "./lib";
9
+ export { wikiPath, wsName, wsUrl, noteUrl, toDate, fmtDate, ago, fmtDuration, summaryOf } from "./lib";
10
+ export { default as useNow } from "./useNow";
9
11
  // The parts the screens are built from; the /ui/ app's other pages use them too (ui/src/components/wiki/* re-export them).
10
12
  export { default as ErrorBox } from "./parts/ErrorBox";
11
13
  export { default as Section } from "./parts/Section";
@@ -22,3 +24,5 @@ export { default as SearchBox } from "./parts/SearchBox";
22
24
  export { default as NavLink } from "./parts/NavLink";
23
25
  export { default as Table } from "./parts/Table";
24
26
  export { default as Pager } from "./parts/Pager";
27
+ export { default as FreshnessBadge } from "./parts/FreshnessBadge";
28
+ export { default as OverdueBadge } from "./parts/OverdueBadge";
package/src/lib.js CHANGED
@@ -1,4 +1,4 @@
1
- import { format } from "date-fns";
1
+ import { format, formatDistanceToNowStrict } from "date-fns";
2
2
 
3
3
  // Helpers the screens share with the rest of the /ui/ app (ui/src/lib/wiki.js re-exports them: one home).
4
4
 
@@ -14,6 +14,19 @@ export const noteUrl = (ws, id) => `${wsUrl(ws)}/note?id=${encodeURIComponent(id
14
14
 
15
15
  export const toDate = (d) => (d ? new Date(d.length <= 10 || /([zZ]|[+-]\d\d:?\d\d)$/.test(d) ? d : d + "Z") : null);
16
16
  export const fmtDate = (d) => (d ? format(toDate(d), "MMM d, yyyy") : "—");
17
+ export const ago = (d) => (d ? formatDistanceToNowStrict(toDate(d), { addSuffix: true }) : "never");
18
+
19
+ /** Whole seconds as "45s", "5m", "1h 30m", "2d 1h". A missing value is "unknown", never 0 or blank. */
20
+ export const fmtDuration = (s) => {
21
+ if (s === null || s === undefined || !Number.isFinite(s) || s < 0) return "unknown";
22
+ if (s < 60) return `${Math.floor(s)}s`;
23
+ const m = Math.floor(s / 60);
24
+ if (m < 60) return `${m}m`;
25
+ const h = Math.floor(m / 60);
26
+ if (h < 24) return m % 60 ? `${h}h ${m % 60}m` : `${h}h`;
27
+ const d = Math.floor(h / 24);
28
+ return h % 24 ? `${d}d ${h % 24}h` : `${d}d`;
29
+ };
17
30
  /** A feature's index summary: the trimmed string, or null when absent or blank (nothing is drawn for null). */
18
31
  export const summaryOf = (feature) => (typeof feature?.summary === "string" && feature.summary.trim() ? feature.summary.trim() : null);
19
32
 
@@ -0,0 +1,15 @@
1
+ import React from "react";
2
+ import useNow from "../useNow";
3
+ import { ago, toDate } from "../lib";
4
+
5
+ export default function FreshnessBadge({ at }) {
6
+ const now = useNow(30000);
7
+ const mins = at ? (now - toDate(at).getTime()) / 60000 : Infinity;
8
+ const tone = mins < 10 ? "bg-emerald-50 text-emerald-700 border-emerald-200" : mins < 60 ? "bg-amber-50 text-amber-700 border-amber-200" : "bg-red-50 text-red-700 border-red-200";
9
+ const dot = mins < 10 ? "bg-emerald-500" : mins < 60 ? "bg-amber-500" : "bg-red-500";
10
+ return (
11
+ <span className={`inline-flex items-center gap-1.5 whitespace-nowrap rounded-full border px-2 py-0.5 text-[11px] font-medium ${tone}`}>
12
+ <span className={`h-1.5 w-1.5 rounded-full ${dot}`} />{ago(at)}
13
+ </span>
14
+ );
15
+ }
@@ -0,0 +1,9 @@
1
+ import React from "react";
2
+
3
+ /** overdue: true = past its freshness line, false = within it, null/undefined = unknown (never shown as "on time"). */
4
+ export default function OverdueBadge({ overdue }) {
5
+ const [tone, label] = overdue === true ? ["bg-red-50 text-red-700 border-red-200", "overdue"]
6
+ : overdue === false ? ["bg-emerald-50 text-emerald-700 border-emerald-200", "on time"]
7
+ : ["bg-neutral-50 text-neutral-500 border-neutral-200", "unknown"];
8
+ return <span className={`inline-flex whitespace-nowrap rounded-full border px-2 py-0.5 text-[11px] font-medium ${tone}`}>{label}</span>;
9
+ }
package/src/useNow.js ADDED
@@ -0,0 +1,7 @@
1
+ import { useEffect, useState } from "react";
2
+
3
+ export default function useNow(ms = 30000) {
4
+ const [now, setNow] = useState(Date.now());
5
+ useEffect(() => { const t = setInterval(() => setNow(Date.now()), ms); return () => clearInterval(t); }, [ms]);
6
+ return now;
7
+ }