@dudousxd/nestjs-catalog-react 0.10.0 → 0.12.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/dist/PipelineConsole.js +52 -2
- package/dist/context.d.ts +26 -1
- package/dist/context.js +21 -0
- package/dist/index.d.ts +6 -5
- package/dist/index.js +24 -1
- package/dist/search-console.d.ts +23 -0
- package/dist/search-console.js +146 -0
- package/package.json +2 -2
package/dist/PipelineConsole.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
3
3
|
import { Cable, CircleCheck, CircleX, Code2, KeyRound, Loader2, Play, Plug, Plus, RefreshCw, ScanSearch, Trash2, TriangleAlert, } from 'lucide-react';
|
|
4
|
-
import { useState } from 'react';
|
|
4
|
+
import { useMemo, useState } from 'react';
|
|
5
5
|
import { ConnectionPanel, connectionOptionsFor } from './ConnectionPanel';
|
|
6
6
|
import { TransformEditor } from './TransformEditor';
|
|
7
7
|
import { cn } from './cn';
|
|
@@ -18,6 +18,28 @@ import { Tooltip, TooltipProvider } from './ui/tooltip';
|
|
|
18
18
|
const MUTED = 'text-zinc-400 dark:text-zinc-500';
|
|
19
19
|
const RULE = 'border-zinc-200 dark:border-zinc-800';
|
|
20
20
|
const PANEL = 'bg-white dark:bg-zinc-900';
|
|
21
|
+
/**
|
|
22
|
+
* The discovery response, checked rather than assumed.
|
|
23
|
+
*
|
|
24
|
+
* The client returns `unknown` because this package must not import
|
|
25
|
+
* `@dudousxd/nestjs-catalog-pipeline` — it would drag database drivers behind
|
|
26
|
+
* optional imports into a browser bundle — so the shape above is a mirror of a
|
|
27
|
+
* contract held somewhere else. A mirror can fall behind: a console talking to
|
|
28
|
+
* an older server gets a body with no `columns`, and rendering it would throw
|
|
29
|
+
* somewhere deep in the table with a message about `undefined.map`.
|
|
30
|
+
*
|
|
31
|
+
* Checked at the seam, once, so the failure names itself. Only the fields this
|
|
32
|
+
* screen would crash without — validating every column here would be
|
|
33
|
+
* re-implementing the server's own shape in a place that cannot be kept honest.
|
|
34
|
+
*/
|
|
35
|
+
function narrowDiscovery(answer) {
|
|
36
|
+
if (!answer || typeof answer !== 'object' || !Array.isArray(Reflect.get(answer, 'columns'))) {
|
|
37
|
+
throw new Error('The server answered the discovery request with something this console does not recognise. ' +
|
|
38
|
+
'It is most likely running a version of @dudousxd/nestjs-catalog-pipeline older than this ' +
|
|
39
|
+
'console expects.');
|
|
40
|
+
}
|
|
41
|
+
return Object.assign(Object.create(null), answer);
|
|
42
|
+
}
|
|
21
43
|
/**
|
|
22
44
|
* Where data comes from, and the code that shapes it.
|
|
23
45
|
*
|
|
@@ -29,6 +51,34 @@ const PANEL = 'bg-white dark:bg-zinc-900';
|
|
|
29
51
|
export function PipelineConsole({ title = 'Connectors', eyebrow = 'Ingestion', intro = 'A source, code that reshapes it, and a snapshot at the end. Running one goes through exactly the same append-and-commit a publisher uses, so there is one way rows arrive rather than two.', canEdit = true, schemaDiscovery, }) {
|
|
30
52
|
const client = useCatalogClient();
|
|
31
53
|
const [tab, setTab] = useState('connectors');
|
|
54
|
+
/**
|
|
55
|
+
* The bridge, from the client, unless the host supplied its own.
|
|
56
|
+
*
|
|
57
|
+
* Until this existed the panel took `schemaDiscovery` as a prop and nothing
|
|
58
|
+
* supplied one, so the feature was reachable only by a host that had read the
|
|
59
|
+
* source and written the two calls itself. The prop stays — a host embedding
|
|
60
|
+
* this screen may route discovery through its own gateway — but it is an
|
|
61
|
+
* override now rather than the only way in.
|
|
62
|
+
*/
|
|
63
|
+
const bridge = useMemo(() => ({
|
|
64
|
+
discover: async (connectorId) => narrowDiscovery(await client.discoverConnectorSchema(connectorId)),
|
|
65
|
+
// `async` on purpose: `publishType` THROWS rather than rejecting when the
|
|
66
|
+
// transport cannot PUT, and a bridge whose method throws synchronously
|
|
67
|
+
// would escape the panel's error handling and take the screen with it.
|
|
68
|
+
createType: async (draft) => client.publishType(draft.name, {
|
|
69
|
+
// Only what a person confirmed on screen. Everything else about a type
|
|
70
|
+
// — its label, its description, its units — is curation, and inventing
|
|
71
|
+
// any of it here would put words nobody chose into a catalog whose
|
|
72
|
+
// whole claim is that its names were chosen.
|
|
73
|
+
properties: draft.properties.map((property) => ({
|
|
74
|
+
name: property.name,
|
|
75
|
+
columnName: property.columnName,
|
|
76
|
+
type: property.type,
|
|
77
|
+
nullable: property.nullable,
|
|
78
|
+
})),
|
|
79
|
+
}),
|
|
80
|
+
}), [client]);
|
|
81
|
+
const discovery = schemaDiscovery ?? bridge;
|
|
32
82
|
const { data: capabilities } = useQuery({
|
|
33
83
|
queryKey: catalogQueryKeys.capabilities,
|
|
34
84
|
queryFn: () => client.pipelineCapabilities(),
|
|
@@ -39,7 +89,7 @@ export function PipelineConsole({ title = 'Connectors', eyebrow = 'Ingestion', i
|
|
|
39
89
|
});
|
|
40
90
|
return (_jsx(TooltipProvider, { children: _jsx("div", { className: "h-full overflow-y-auto", children: _jsxs("div", { className: "mx-auto max-w-5xl px-8 py-8", children: [_jsx("p", { className: cn('font-mono text-[11px] uppercase tracking-[0.18em]', MUTED), children: eyebrow }), _jsx("h1", { className: "mt-1 text-2xl font-semibold tracking-tight", children: title }), _jsx("p", { className: "mt-1 max-w-2xl text-sm text-zinc-500 dark:text-zinc-400", children: intro }), _jsxs(Tabs, { value: tab, onValueChange: setTab, className: "mt-6", children: [_jsxs(TabsList, { children: [_jsxs(TabsTab, { value: "connections", children: [_jsx(Plug, { size: 13 }), "Connections"] }), _jsxs(TabsTab, { value: "connectors", children: [_jsx(Cable, { size: 13 }), "Connectors"] }), _jsxs(TabsTab, { value: "transforms", children: [_jsx(Code2, { size: 13 }), "Transforms"] }), _jsx(Tooltip, { content: capabilities?.pythonPackages?.length
|
|
41
91
|
? `Python transforms may import ${capabilities.pythonPackages.join(', ')} — provisioned by the image, not by this service.`
|
|
42
|
-
: 'Which languages this deployment can actually execute.', children: _jsx("span", { className: cn('ml-auto cursor-help self-center font-mono text-[10px]', MUTED), children: capabilities ? `runs ${capabilities.languages.join(' · ')}` : 'checking…' }) })] }), _jsx(TabsPanel, { value: "connections", children: _jsx(ConnectionPanel, { canEdit: canEdit }) }), _jsx(TabsPanel, { value: "connectors", children: _jsx(ConnectorList, { canEdit: canEdit, schemaDiscovery:
|
|
92
|
+
: 'Which languages this deployment can actually execute.', children: _jsx("span", { className: cn('ml-auto cursor-help self-center font-mono text-[10px]', MUTED), children: capabilities ? `runs ${capabilities.languages.join(' · ')}` : 'checking…' }) })] }), _jsx(TabsPanel, { value: "connections", children: _jsx(ConnectionPanel, { canEdit: canEdit }) }), _jsx(TabsPanel, { value: "connectors", children: _jsx(ConnectorList, { canEdit: canEdit, schemaDiscovery: discovery }) }), _jsx(TabsPanel, { value: "transforms", children: _jsx(TransformList, { canEdit: canEdit, languages: capabilities?.languages ?? ['javascript'], pythonPackages: capabilities?.pythonPackages ?? [] }) })] })] }) }) }));
|
|
43
93
|
}
|
|
44
94
|
function ConnectorList({ canEdit, schemaDiscovery, }) {
|
|
45
95
|
const client = useCatalogClient();
|
package/dist/context.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CatalogAuditEvent, CatalogConnection, CatalogConnector, CatalogObjectPage, CatalogQueryRelation, CatalogQueryResult, CatalogSnapshot, CatalogTraceList, CatalogTransform, ConnectionCheck, ConnectorRun, Dashboard, DashboardCard, ObjectQueryParams, PropertyPatch, SaveQueryInput, SavedQuery, TraceQuery, TransformLanguage, TransformResult, TypePatch } from '@dudousxd/nestjs-catalog/client';
|
|
1
|
+
import type { CatalogAuditEvent, CatalogConnection, CatalogConnector, CatalogObjectPage, CatalogQueryRelation, CatalogQueryResult, CatalogSearchResult, CatalogSnapshot, CatalogTraceList, CatalogTransform, ConnectionCheck, ConnectorRun, Dashboard, DashboardCard, ObjectQueryParams, PropertyPatch, SaveQueryInput, SavedQuery, TraceQuery, TransformLanguage, TransformResult, TypePatch } from '@dudousxd/nestjs-catalog/client';
|
|
2
2
|
import { type ReactNode } from 'react';
|
|
3
3
|
import type { EmbeddedChartPayload, EmbeddedDashboardPayload } from './embed/payload';
|
|
4
4
|
import { type PeopleQuery } from './routes';
|
|
@@ -224,6 +224,19 @@ export interface CatalogClient {
|
|
|
224
224
|
sql: string;
|
|
225
225
|
maxRows?: number;
|
|
226
226
|
}): Promise<CatalogQueryResult>;
|
|
227
|
+
/**
|
|
228
|
+
* One term across object types, properties, saved queries and dashboards.
|
|
229
|
+
*
|
|
230
|
+
* One call rather than four, and the ranking is the server's. A client that
|
|
231
|
+
* merged four lists would own the order across kinds, which means the order
|
|
232
|
+
* would live in whichever screen was written last — see the block above
|
|
233
|
+
* `CatalogService.search`, which makes the argument where the code is.
|
|
234
|
+
*
|
|
235
|
+
* `limit` is the caller's request and the server's decision: it caps whatever
|
|
236
|
+
* is asked for, and the answer carries `total` and `truncated` so a screen can
|
|
237
|
+
* say "50 of 312" rather than implying the list it drew is the list.
|
|
238
|
+
*/
|
|
239
|
+
search(term: string, limit?: number): Promise<CatalogSearchResult>;
|
|
227
240
|
workspaceCapabilities(): Promise<{
|
|
228
241
|
workspace: boolean;
|
|
229
242
|
query: boolean;
|
|
@@ -440,6 +453,18 @@ export declare const catalogQueryKeys: {
|
|
|
440
453
|
all: readonly ["nestjs-catalog"];
|
|
441
454
|
snapshot: readonly ["nestjs-catalog", "snapshot"];
|
|
442
455
|
objects: (type: string, params: ObjectQueryParams) => readonly ["nestjs-catalog", "objects", string, ObjectQueryParams];
|
|
456
|
+
/**
|
|
457
|
+
* Keyed on the term, so react-query caches per term and a backspace shows the
|
|
458
|
+
* previous answer instantly instead of re-asking.
|
|
459
|
+
*
|
|
460
|
+
* Deliberately NOT keyed on anything about the caller. The answer already
|
|
461
|
+
* depends on who is asking — the route filters by principal — and a cache key
|
|
462
|
+
* that did not say so would be a bug; it is safe here only because a browser
|
|
463
|
+
* session is one principal, and a host that swaps identity in place without a
|
|
464
|
+
* reload should invalidate `catalogQueryKeys.all`, which is what that prefix
|
|
465
|
+
* is for.
|
|
466
|
+
*/
|
|
467
|
+
search: (term: string, limit?: number) => readonly ["nestjs-catalog", "search", string, number | null];
|
|
443
468
|
/**
|
|
444
469
|
* The pipeline keys are nested under one prefix so a host — or a screen that
|
|
445
470
|
* just ran a connector — can invalidate the whole of it at once. Running a
|
package/dist/context.js
CHANGED
|
@@ -17,6 +17,15 @@ export function CatalogProvider({ transport, pipelineBasePath = DEFAULT_PIPELINE
|
|
|
17
17
|
reset: () => transport.post(catalogRoutes.reset()),
|
|
18
18
|
queryRelations: () => transport.get(catalogRoutes.queryRelations()),
|
|
19
19
|
runQuery: (input) => transport.post(catalogRoutes.query(), input),
|
|
20
|
+
// `limit` is omitted rather than sent undefined when nobody asked for
|
|
21
|
+
// one, for the reason `listRuns` states below: a transport that
|
|
22
|
+
// serialises `limit=` hands the server an empty string, and `Number('')`
|
|
23
|
+
// is 0 — which the route would floor back to 1 and answer with a single
|
|
24
|
+
// row that reads as "there is only one match".
|
|
25
|
+
search: (term, limit) => transport.get(catalogRoutes.search(), {
|
|
26
|
+
q: term,
|
|
27
|
+
...(limit === undefined ? {} : { limit }),
|
|
28
|
+
}),
|
|
20
29
|
workspaceCapabilities: () => transport.get(catalogRoutes.workspaceCapabilities()),
|
|
21
30
|
listSavedQueries: () => transport.get(catalogRoutes.savedQueries()),
|
|
22
31
|
saveQuery: (input) => transport.post(catalogRoutes.savedQueries(), input),
|
|
@@ -91,6 +100,18 @@ export const catalogQueryKeys = {
|
|
|
91
100
|
all: ['nestjs-catalog'],
|
|
92
101
|
snapshot: ['nestjs-catalog', 'snapshot'],
|
|
93
102
|
objects: (type, params) => ['nestjs-catalog', 'objects', type, params],
|
|
103
|
+
/**
|
|
104
|
+
* Keyed on the term, so react-query caches per term and a backspace shows the
|
|
105
|
+
* previous answer instantly instead of re-asking.
|
|
106
|
+
*
|
|
107
|
+
* Deliberately NOT keyed on anything about the caller. The answer already
|
|
108
|
+
* depends on who is asking — the route filters by principal — and a cache key
|
|
109
|
+
* that did not say so would be a bug; it is safe here only because a browser
|
|
110
|
+
* session is one principal, and a host that swaps identity in place without a
|
|
111
|
+
* reload should invalidate `catalogQueryKeys.all`, which is what that prefix
|
|
112
|
+
* is for.
|
|
113
|
+
*/
|
|
114
|
+
search: (term, limit) => ['nestjs-catalog', 'search', term, limit ?? null],
|
|
94
115
|
/**
|
|
95
116
|
* The pipeline keys are nested under one prefix so a host — or a screen that
|
|
96
117
|
* just ran a connector — can invalidate the whole of it at once. Running a
|
package/dist/index.d.ts
CHANGED
|
@@ -11,17 +11,18 @@ export { EMBED_ACTIONS, type EmbedAction, type EmbedActions, EmbeddedChart, type
|
|
|
11
11
|
export { FlowView } from './FlowView';
|
|
12
12
|
export { GovernanceTimeline } from './GovernanceTimeline';
|
|
13
13
|
export { QueryConsole, type QueryConsoleProps } from './QueryConsole';
|
|
14
|
+
export { CatalogSearch, type CatalogSearchProps } from './search-console';
|
|
14
15
|
export { SavedQueryPanel } from './SavedQueryPanel';
|
|
15
16
|
export { CATALOG_EVENT_META, type CatalogTraceSource, eventMeta, TraceExplorer, useTraceSource, } from './TraceExplorer';
|
|
16
17
|
export { ConnectionPanel, type ConnectionPanelProps, connectionOptionsFor, describeConnection, } from './ConnectionPanel';
|
|
17
|
-
export { PipelineConsole, type PipelineConsoleProps } from './PipelineConsole';
|
|
18
|
+
export { type ColumnChoice, type ConnectorSchemaDiscovery, type DiscoveredColumn, type DiscoveredTypeDraft, initialChoices, PipelineConsole, type PipelineConsoleProps, proposalFrom, type SchemaDiscoveryBridge, type SchemaDrift, } from './PipelineConsole';
|
|
18
19
|
export { TransformEditor, type TransformEditorProps } from './TransformEditor';
|
|
19
20
|
export { AccessConsole, type AccessConsoleProps } from './AccessConsole';
|
|
20
|
-
export { type CatalogWorkflow, describeDurability, isWorkflowNodeKind, newLocalId, nodeName, producedTypes, WORKFLOW_NODE_ID_PATTERN, WORKFLOW_NODE_KINDS, type WorkflowDurability, type WorkflowEdge, type WorkflowGraph, type WorkflowInput, type WorkflowNode, type WorkflowNodeKind, type WorkflowRun, type WorkflowRunNode, type WorkflowSinkNode, type WorkflowSourceNode, type WorkflowTransformNode, } from './workflow/model';
|
|
21
|
+
export { type CatalogWorkflow, describeDurability, type DurabilityCopy, isWorkflowNodeKind, newLocalId, nodeName, producedTypes, WORKFLOW_NODE_ID_PATTERN, WORKFLOW_NODE_KINDS, type WorkflowDurability, type WorkflowEdge, type WorkflowGraph, type WorkflowInput, type WorkflowNode, type WorkflowNodeKind, type WorkflowRun, type WorkflowRunNode, type WorkflowSinkNode, type WorkflowSourceNode, type WorkflowTransformNode, } from './workflow/model';
|
|
21
22
|
export { WORKFLOW_NAME } from './workflow/name';
|
|
22
|
-
export { canConnect, type ConnectionVerdict, edgeId, hasBlockingProblem, problemsByNode, validateWorkflow, type WorkflowProblem, type WorkflowProblemCode, wouldCycle, } from './workflow/validate';
|
|
23
|
-
export { type CatalogClient, type CatalogIdentity, type CatalogPersonRole, type CatalogPersonSummary, type CatalogPrincipalSummary, CatalogProvider, type CatalogProviderProps, type CatalogTransport, type ConnectionInput, type ConnectorInput, catalogQueryKeys, type PersonInput, type PersonUpsertResult, type PipelineCapabilities, type TransformInput, useCatalogClient, } from './context';
|
|
24
|
-
export { type AccessRoutes, accessRoutes, DEFAULT_ACCESS_BASE_PATH, DEFAULT_PIPELINE_BASE_PATH, embedRoutes, type PipelineRoutes, pipelineRoutes, } from './routes';
|
|
23
|
+
export { canConnect, type ConnectionVerdict, edgeId, hasBlockingProblem, problemsByNode, type ValidateOptions, validateWorkflow, type WorkflowDraft, type WorkflowProblem, type WorkflowProblemCode, type WorkflowProblemLevel, wouldCycle, } from './workflow/validate';
|
|
24
|
+
export { type CatalogClient, type CatalogIdentity, type CatalogPeoplePage, type CatalogPersonRole, type CatalogPersonSummary, type CatalogPrincipalSummary, CatalogProvider, type CatalogProviderProps, type CatalogTransport, type ConnectionInput, type ConnectorInput, catalogQueryKeys, type PersonInput, type PersonUpsertResult, type PipelineCapabilities, type TransformInput, useCatalogClient, } from './context';
|
|
25
|
+
export { type AccessRoutes, accessRoutes, DEFAULT_ACCESS_BASE_PATH, DEFAULT_PIPELINE_BASE_PATH, DEFAULT_PUBLISH_BASE_PATH, embedRoutes, type PeopleQuery, type PipelineRoutes, pipelineRoutes, } from './routes';
|
|
25
26
|
export { ConfirmDialog } from './ui/dialog';
|
|
26
27
|
export { FieldGroup, TextAreaField, TextField } from './ui/field';
|
|
27
28
|
export { Select, SelectField, type SelectOption } from './ui/select';
|
package/dist/index.js
CHANGED
|
@@ -15,13 +15,31 @@ export { EMBED_ACTIONS, EmbeddedChart, EmbeddedDashboard, chartsInLayoutOrder, r
|
|
|
15
15
|
export { FlowView } from './FlowView';
|
|
16
16
|
export { GovernanceTimeline } from './GovernanceTimeline';
|
|
17
17
|
export { QueryConsole } from './QueryConsole';
|
|
18
|
+
// One box across the whole catalog: types, properties, saved queries, boards.
|
|
19
|
+
// Not mounted anywhere by this package — a host places it wherever its shell
|
|
20
|
+
// wants a search, and tells it where each kind of thing lives with the same
|
|
21
|
+
// `explorerHref` shape `CatalogManager` takes.
|
|
22
|
+
export { CatalogSearch } from './search-console';
|
|
18
23
|
export { SavedQueryPanel } from './SavedQueryPanel';
|
|
19
24
|
export { CATALOG_EVENT_META, eventMeta, TraceExplorer, useTraceSource, } from './TraceExplorer';
|
|
20
25
|
// Getting data in: connections, connectors and the code that reshapes what they
|
|
21
26
|
// fetch. These used to live in the consuming app, which meant any other host
|
|
22
27
|
// installing this package got a console with no way to manage a load.
|
|
23
28
|
export { ConnectionPanel, connectionOptionsFor, describeConnection, } from './ConnectionPanel';
|
|
24
|
-
|
|
29
|
+
// The schema-discovery seam, whole.
|
|
30
|
+
//
|
|
31
|
+
// `PipelineConsoleProps['schemaDiscovery']` is a bridge the HOST implements —
|
|
32
|
+
// this package cannot ask a connector for its columns, only render the answer —
|
|
33
|
+
// and every one of these was reachable from that prop's type and from nowhere
|
|
34
|
+
// else. So the only way to write the bridge with its signature spelled out was
|
|
35
|
+
// to name it through an indexed access on a component's props, or to deep-import
|
|
36
|
+
// a file inside `dist/`. Both are the caller paying for a list that fell behind.
|
|
37
|
+
//
|
|
38
|
+
// `initialChoices` and `proposalFrom` come with them because they are the rules
|
|
39
|
+
// that decide whether a schema somebody ticked is one the publish route will
|
|
40
|
+
// accept — pure and deliberately outside the panel, per their own docblocks, and
|
|
41
|
+
// worth nothing there if the only way to run them is to render it.
|
|
42
|
+
export { initialChoices, PipelineConsole, proposalFrom, } from './PipelineConsole';
|
|
25
43
|
export { TransformEditor } from './TransformEditor';
|
|
26
44
|
export { AccessConsole } from './AccessConsole';
|
|
27
45
|
// The authored graph: sources wired through transforms into sinks.
|
|
@@ -57,6 +75,11 @@ export { CatalogProvider, catalogQueryKeys, useCatalogClient, } from './context'
|
|
|
57
75
|
// mount those endpoints wherever it likes and tell the provider where they are.
|
|
58
76
|
// See routes.ts for why they are here rather than in the server package.
|
|
59
77
|
export { accessRoutes, DEFAULT_ACCESS_BASE_PATH, DEFAULT_PIPELINE_BASE_PATH,
|
|
78
|
+
// The third default, which had been left out while its two siblings were
|
|
79
|
+
// exported — so `CatalogProviderProps.publishBasePath` was documented as
|
|
80
|
+
// defaulting to a constant a host could not name, and the way to override it
|
|
81
|
+
// relative to the default was to retype the string and hope.
|
|
82
|
+
DEFAULT_PUBLISH_BASE_PATH,
|
|
60
83
|
// The embed paths, which the catalog controller does serve — exported so a
|
|
61
84
|
// host writing its own embed consumer need not restate them. See routes.ts.
|
|
62
85
|
embedRoutes, pipelineRoutes, } from './routes';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface CatalogSearchProps {
|
|
2
|
+
/**
|
|
3
|
+
* Where the model screen lives, given a type name. Omit and type and property
|
|
4
|
+
* rows render as plain rows rather than as links.
|
|
5
|
+
*
|
|
6
|
+
* The same prop, the same shape and the same name as `CatalogManager`'s,
|
|
7
|
+
* because it is the same navigation: the host owns its routing, and the
|
|
8
|
+
* shipped console answers `#objects?type=X`. A second spelling here would
|
|
9
|
+
* mean a host wiring the two screens differently for one destination.
|
|
10
|
+
*/
|
|
11
|
+
explorerHref?: (typeName: string) => string;
|
|
12
|
+
/** Where a saved query opens. Omit to render saved-query rows as plain rows. */
|
|
13
|
+
savedQueryHref?: (id: string) => string;
|
|
14
|
+
/** Where a dashboard opens. Omit to render dashboard rows as plain rows. */
|
|
15
|
+
dashboardHref?: (id: string) => string;
|
|
16
|
+
/** How many rows to ask for. The server caps whatever this says. */
|
|
17
|
+
limit?: number;
|
|
18
|
+
placeholder?: string;
|
|
19
|
+
/** Heading copy, so the host can call this whatever its users call it. */
|
|
20
|
+
title?: string;
|
|
21
|
+
eyebrow?: string;
|
|
22
|
+
}
|
|
23
|
+
export declare function CatalogSearch({ explorerHref, savedQueryHref, dashboardHref, limit, placeholder, title, eyebrow, }: CatalogSearchProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useQuery } from '@tanstack/react-query';
|
|
3
|
+
import { ArrowUpRight, Search } from 'lucide-react';
|
|
4
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
5
|
+
import { cn } from './cn';
|
|
6
|
+
import { catalogQueryKeys, useCatalogClient } from './context';
|
|
7
|
+
import { TextField } from './ui/field';
|
|
8
|
+
/**
|
|
9
|
+
* One box that crosses the catalog.
|
|
10
|
+
*
|
|
11
|
+
* Today, finding anything means knowing which screen it lives on: object types
|
|
12
|
+
* and their properties on the model screen, saved queries on the query screen,
|
|
13
|
+
* boards on the dashboards screen. At two hundred types that IS the experience,
|
|
14
|
+
* and the thing a person actually types is a word they half-remember.
|
|
15
|
+
*
|
|
16
|
+
* Everything about which rows come back, and in what order, is the server's —
|
|
17
|
+
* see `search.ts` in `@dudousxd/nestjs-catalog`. This screen deliberately does
|
|
18
|
+
* no ranking, no client-side filtering and no merging of its own. That is not
|
|
19
|
+
* deference for its own sake: the same ranking has to hold for a host that
|
|
20
|
+
* writes its own box against the same route, and a second copy of it here would
|
|
21
|
+
* be a second answer to the same question the day one of them is touched.
|
|
22
|
+
*/
|
|
23
|
+
const MUTED = 'text-zinc-400 dark:text-zinc-500';
|
|
24
|
+
const SECONDARY = 'text-zinc-500 dark:text-zinc-400';
|
|
25
|
+
const RULE = 'border-zinc-200 dark:border-zinc-800';
|
|
26
|
+
/**
|
|
27
|
+
* The order the groups are drawn in, matching the server's own tie-break.
|
|
28
|
+
*
|
|
29
|
+
* Grouping is a trade and it is worth naming: it buys scannability — four short
|
|
30
|
+
* lists a reader recognises the shape of — and it costs the global ranking, so
|
|
31
|
+
* an exact property match no longer sits visually above a type that merely
|
|
32
|
+
* mentions the word. The `rank` chip on each row is what carries that back;
|
|
33
|
+
* without it the grouping would be lying by omission.
|
|
34
|
+
*/
|
|
35
|
+
const KIND_ORDER = ['objectType', 'property', 'savedQuery', 'dashboard'];
|
|
36
|
+
const KIND_LABEL = {
|
|
37
|
+
objectType: 'Object types',
|
|
38
|
+
property: 'Properties',
|
|
39
|
+
savedQuery: 'Saved queries',
|
|
40
|
+
dashboard: 'Dashboards',
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* What the rank means, in words, because "prefix" is jargon for the reader and
|
|
44
|
+
* the whole argument for four named ranks over a number is that a person can
|
|
45
|
+
* predict them. A tooltip would hide it behind a hover; this is four words.
|
|
46
|
+
*/
|
|
47
|
+
const RANK_LABEL = {
|
|
48
|
+
exact: 'exact name',
|
|
49
|
+
prefix: 'name starts with',
|
|
50
|
+
name: 'in the name',
|
|
51
|
+
text: 'in the text',
|
|
52
|
+
};
|
|
53
|
+
const RANK_TONE = {
|
|
54
|
+
exact: 'text-emerald-700 dark:text-emerald-300',
|
|
55
|
+
prefix: 'text-sky-700 dark:text-sky-300',
|
|
56
|
+
name: 'text-sky-700 dark:text-sky-300',
|
|
57
|
+
text: 'text-zinc-500 dark:text-zinc-400',
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* How long to wait after a keystroke before asking.
|
|
61
|
+
*
|
|
62
|
+
* Half the answer is free — the registry snapshot is already in memory — and
|
|
63
|
+
* half is two reads against the workspace store, so a request per keystroke
|
|
64
|
+
* would put a database under a typing load for rows that were going to be
|
|
65
|
+
* thrown away. 200ms is below the threshold at which a person notices the box
|
|
66
|
+
* is not instant, and above the interval at which anybody types.
|
|
67
|
+
*/
|
|
68
|
+
const DEBOUNCE_MS = 200;
|
|
69
|
+
export function CatalogSearch({ explorerHref, savedQueryHref, dashboardHref, limit, placeholder = 'A type, a column, a report — whatever you remember', title = 'Search', eyebrow = 'Across the catalog', }) {
|
|
70
|
+
const client = useCatalogClient();
|
|
71
|
+
const [term, setTerm] = useState('');
|
|
72
|
+
const [debounced, setDebounced] = useState('');
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
const handle = setTimeout(() => setDebounced(term), DEBOUNCE_MS);
|
|
75
|
+
return () => clearTimeout(handle);
|
|
76
|
+
}, [term]);
|
|
77
|
+
const trimmed = debounced.trim();
|
|
78
|
+
const { data, isFetching, isError } = useQuery({
|
|
79
|
+
queryKey: catalogQueryKeys.search(trimmed, limit),
|
|
80
|
+
queryFn: () => client.search(trimmed, limit),
|
|
81
|
+
// An empty box asks nothing. The route answers an empty term with an empty
|
|
82
|
+
// result rather than a 400, so this is politeness rather than protection —
|
|
83
|
+
// but a request fired on mount, before anybody has typed, is a request the
|
|
84
|
+
// server logs and nobody wanted.
|
|
85
|
+
enabled: trimmed.length > 0,
|
|
86
|
+
// The previous answer stays on screen while the next one is in flight, so
|
|
87
|
+
// the list does not blank between keystrokes. `isFetching` is what says so.
|
|
88
|
+
placeholderData: (previous) => previous,
|
|
89
|
+
staleTime: 15_000,
|
|
90
|
+
});
|
|
91
|
+
const grouped = useMemo(() => {
|
|
92
|
+
const hits = data?.hits ?? [];
|
|
93
|
+
return KIND_ORDER.map((kind) => [kind, hits.filter((hit) => hit.kind === kind)]).filter(([, rows]) => rows.length > 0);
|
|
94
|
+
}, [data]);
|
|
95
|
+
function hrefFor(hit) {
|
|
96
|
+
// A property navigates to the type it belongs to, not to a route of its
|
|
97
|
+
// own: there is no per-property screen, and inventing an anchor the host
|
|
98
|
+
// does not serve would be a link that goes nowhere.
|
|
99
|
+
if (hit.kind === 'objectType' || hit.kind === 'property') {
|
|
100
|
+
return hit.typeName && explorerHref ? explorerHref(hit.typeName) : undefined;
|
|
101
|
+
}
|
|
102
|
+
if (hit.kind === 'savedQuery')
|
|
103
|
+
return savedQueryHref?.(hit.id);
|
|
104
|
+
return dashboardHref?.(hit.id);
|
|
105
|
+
}
|
|
106
|
+
return (_jsxs("div", { className: "mx-auto flex h-full max-w-3xl flex-col px-6 py-8", children: [_jsxs("header", { className: "shrink-0", children: [_jsx("p", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: eyebrow }), _jsx("h2", { className: "mt-1 text-2xl font-semibold tracking-tight", children: title })] }), _jsxs("div", { className: "relative mt-5 shrink-0", children: [_jsx(Search, { size: 14, className: cn('pointer-events-none absolute right-2.5 top-[1.9rem] z-10', MUTED) }), _jsx(TextField, { label: "Search the catalog", value: term, onChange: setTerm, placeholder: placeholder })] }), _jsxs("div", { className: "mt-4 min-h-0 flex-1 overflow-y-auto", children: [_jsx(Status, { term: trimmed, isError: isError, isFetching: isFetching, total: data?.total, shown: data?.hits.length, truncated: data?.truncated }), grouped.map(([kind, rows]) => (_jsxs("section", { className: "mb-5", children: [_jsxs("div", { className: cn('flex items-baseline justify-between border-b px-1 pb-1', RULE), children: [_jsx("span", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: KIND_LABEL[kind] }), _jsx("span", { className: cn('font-mono text-[10px]', MUTED), children: rows.length })] }), rows.map((hit) => (_jsx(Row, { hit: hit, href: hrefFor(hit) }, `${hit.kind}:${hit.typeName ?? ''}:${hit.id}`)))] }, kind)))] })] }));
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The line above the results, which has four things to say and must not confuse
|
|
110
|
+
* two of them.
|
|
111
|
+
*
|
|
112
|
+
* "Nothing matched" and "we could not ask" lead a reader to opposite
|
|
113
|
+
* conclusions, and a refusal rendered as an empty list is the worse one — the
|
|
114
|
+
* same distinction `CatalogManager` makes, made again here because this screen
|
|
115
|
+
* has its own request.
|
|
116
|
+
*/
|
|
117
|
+
function Status({ term, isError, isFetching, total, shown, truncated, }) {
|
|
118
|
+
if (!term) {
|
|
119
|
+
return (_jsx("p", { className: cn('px-1 py-8 text-center text-xs', MUTED), children: "Types, properties, saved queries and dashboards, all at once." }));
|
|
120
|
+
}
|
|
121
|
+
if (isError) {
|
|
122
|
+
return _jsx("p", { className: "px-1 py-8 text-center text-xs text-rose-600", children: "The search did not run" });
|
|
123
|
+
}
|
|
124
|
+
if (total === undefined) {
|
|
125
|
+
return _jsx("p", { className: cn('px-1 py-8 text-center text-xs', MUTED), children: "Searching\u2026" });
|
|
126
|
+
}
|
|
127
|
+
if (total === 0) {
|
|
128
|
+
return _jsxs("p", { className: cn('px-1 py-8 text-center text-xs', MUTED), children: ["Nothing matches \u201C", term, "\u201D."] });
|
|
129
|
+
}
|
|
130
|
+
return (_jsxs("p", { className: cn('mb-3 px-1 font-mono text-[10px]', MUTED), children: [truncated ? `${shown} of ${total} matches` : `${total} ${total === 1 ? 'match' : 'matches'}`, isFetching ? ' · updating' : ''] }));
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* One result.
|
|
134
|
+
*
|
|
135
|
+
* An `<a>` when the host said where the kind lives and a `<div>` when it did
|
|
136
|
+
* not — rather than a dead link or a link to `#`. A row that looks clickable and
|
|
137
|
+
* is not is worse than a row that does not, and a host that mounts no dashboard
|
|
138
|
+
* screen should not have this one inventing an anchor for it.
|
|
139
|
+
*/
|
|
140
|
+
function Row({ hit, href }) {
|
|
141
|
+
const body = (_jsxs(_Fragment, { children: [_jsxs("span", { className: "min-w-0 flex-1", children: [_jsx("span", { className: "block truncate text-sm", children: hit.label }), _jsxs("span", { className: cn('block truncate font-mono text-[10px]', MUTED), children: [hit.typeName && hit.typeName !== hit.label ? `${hit.typeName} · ` : '', hit.id, hit.detail ? ` · ${hit.detail}` : ''] })] }), _jsxs("span", { className: cn('shrink-0 font-mono text-[10px]', RANK_TONE[hit.rank]), children: [RANK_LABEL[hit.rank], _jsx("span", { className: cn('ml-1.5', SECONDARY), children: hit.field })] }), href && _jsx(ArrowUpRight, { size: 13, className: cn('shrink-0', MUTED), "aria-hidden": true })] }));
|
|
142
|
+
const className = cn('flex items-center gap-3 rounded-md px-2 py-2 text-left', href && 'transition-colors hover:bg-zinc-50 dark:hover:bg-zinc-800');
|
|
143
|
+
if (!href)
|
|
144
|
+
return _jsx("div", { className: className, children: body });
|
|
145
|
+
return (_jsx("a", { href: href, className: className, children: body }));
|
|
146
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dudousxd/nestjs-catalog-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "Ready-made React screens for @dudousxd/nestjs-catalog — a model manager and a generic object explorer you can drop into your own app shell.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Davide Carvalho",
|
|
@@ -106,7 +106,7 @@
|
|
|
106
106
|
"@tiptap/pm": "3.29.2",
|
|
107
107
|
"tiptap-markdown": "0.9.0",
|
|
108
108
|
"@tiptap/core": "3.29.2",
|
|
109
|
-
"@dudousxd/nestjs-catalog": "0.
|
|
109
|
+
"@dudousxd/nestjs-catalog": "0.9.0"
|
|
110
110
|
},
|
|
111
111
|
"dependencies": {
|
|
112
112
|
"clsx": "2.1.1",
|