@sincpro/web-framework 3.1.0 → 3.2.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/core/copy.d.ts +2 -0
- package/dist/core/copy.js +2 -0
- package/dist/core/list.d.ts +3 -0
- package/dist/react/context.d.ts +3 -0
- package/dist/react/context.js +5 -0
- package/dist/web/index.d.ts +1 -0
- package/dist/web/index.js +1 -0
- package/dist/web/list/EntityList.d.ts +4 -1
- package/dist/web/list/EntityList.js +21 -12
- package/dist/web/list/EntitySearchBar.d.ts +6 -2
- package/dist/web/list/EntitySearchBar.js +11 -3
- package/dist/web/list/columns.js +29 -2
- package/dist/web/list/search.d.ts +14 -5
- package/dist/web/list/search.js +29 -14
- package/dist/web/record/ActionButton.d.ts +14 -4
- package/dist/web/record/ActionButton.js +45 -2
- package/dist/web/record/CommandButton.d.ts +10 -1
- package/dist/web/record/CommandButton.js +23 -4
- package/dist/web/record/ServiceButton.d.ts +20 -4
- package/dist/web/record/ServiceButton.js +30 -5
- package/dist/web/record/ask.d.ts +59 -0
- package/dist/web/record/ask.js +59 -0
- package/dist/web/record/control.d.ts +2 -2
- package/dist/web/record/control.js +7 -3
- package/dist/web/record/edit.d.ts +1 -1
- package/dist/web/record/edit.js +9 -1
- package/dist/web/workspace/composer.d.ts +7 -2
- package/dist/web/workspace/composer.js +24 -4
- package/package.json +3 -3
package/dist/core/copy.d.ts
CHANGED
|
@@ -94,6 +94,8 @@ export type FrameworkCopy = {
|
|
|
94
94
|
cancel: string;
|
|
95
95
|
/** While the dry run is asked. */
|
|
96
96
|
rehearsing: string;
|
|
97
|
+
/** Sends what an action asked for (`ask`). */
|
|
98
|
+
send: string;
|
|
97
99
|
};
|
|
98
100
|
failure: {
|
|
99
101
|
/** The server could not be reached at all — nothing it said is known. */
|
package/dist/core/copy.js
CHANGED
|
@@ -53,6 +53,7 @@ export const ENGLISH_FRAMEWORK_COPY = {
|
|
|
53
53
|
confirm: "Do it",
|
|
54
54
|
cancel: "Cancel",
|
|
55
55
|
rehearsing: "Checking what it would do…",
|
|
56
|
+
send: "Confirm",
|
|
56
57
|
},
|
|
57
58
|
failure: {
|
|
58
59
|
unreachable: "The server could not be reached",
|
|
@@ -141,6 +142,7 @@ export const SPANISH_FRAMEWORK_COPY = {
|
|
|
141
142
|
confirm: "Hacerlo",
|
|
142
143
|
cancel: "Cancelar",
|
|
143
144
|
rehearsing: "Revisando qué haría…",
|
|
145
|
+
send: "Confirmar",
|
|
144
146
|
},
|
|
145
147
|
failure: {
|
|
146
148
|
unreachable: "No se pudo hablar con el servidor",
|
package/dist/core/list.d.ts
CHANGED
|
@@ -40,6 +40,9 @@ export type ListDefinition<T extends AnyRecord = AnyRecord> = {
|
|
|
40
40
|
columns?: readonly string[];
|
|
41
41
|
/** The cuts it offers by name in the search bar. */
|
|
42
42
|
filters?: readonly NamedFilter<T>[];
|
|
43
|
+
/** The fields the search bar offers to look a typed text up in, in order — «Buscar Nombres:
|
|
44
|
+
* Excel». Without it, the ones the entity's search template names, else its display. */
|
|
45
|
+
facets?: readonly string[];
|
|
43
46
|
/** The faces it offers, the first one shown. */
|
|
44
47
|
views?: readonly ("table" | "rows" | "board" | "sheet" | "pivot")[];
|
|
45
48
|
/** Grouped from the start — the server counts the groups. */
|
package/dist/react/context.d.ts
CHANGED
|
@@ -81,6 +81,9 @@ export declare function FrameworkProvider({ transport, locale, metas: seed, enti
|
|
|
81
81
|
children: ReactNode;
|
|
82
82
|
}): import("react").JSX.Element;
|
|
83
83
|
export declare function useFramework(): FrameworkContextValue;
|
|
84
|
+
/** The provider's values, or `null` outside one: for a piece that works without it
|
|
85
|
+
* (`ServiceButton` runs a use case, which needs no provider). */
|
|
86
|
+
export declare function useFrameworkIfAny(): FrameworkContextValue | null;
|
|
84
87
|
/** The declared entity a relation points at (`"Cliente"`), or `undefined`. */
|
|
85
88
|
export declare function useEntityFor(target: string | undefined): Entity | undefined;
|
|
86
89
|
export {};
|
package/dist/react/context.js
CHANGED
|
@@ -91,6 +91,11 @@ export function useFramework() {
|
|
|
91
91
|
throw new Error("useFramework outside a FrameworkProvider");
|
|
92
92
|
return value;
|
|
93
93
|
}
|
|
94
|
+
/** The provider's values, or `null` outside one: for a piece that works without it
|
|
95
|
+
* (`ServiceButton` runs a use case, which needs no provider). */
|
|
96
|
+
export function useFrameworkIfAny() {
|
|
97
|
+
return useContext(FrameworkContext);
|
|
98
|
+
}
|
|
94
99
|
/** The declared entity a relation points at (`"Cliente"`), or `undefined`. */
|
|
95
100
|
export function useEntityFor(target) {
|
|
96
101
|
const { entities, metas } = useFramework();
|
package/dist/web/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export { pivotOf } from "./list/pivot.js";
|
|
|
10
10
|
export { type CardLook, type ChoiceTones, type OptionLook, type Presentation, presentationOf, type Presented, presented, type RowLook, } from "./list/presentation.js";
|
|
11
11
|
export { type RowCommand, type RowCommands, useRowCommands, } from "./list/rowCommands.js";
|
|
12
12
|
export { facetsOf, modelOf } from "./list/search.js";
|
|
13
|
+
export { type AskedField, type AskField, type AskForm, askFormOf, } from "./record/ask.js";
|
|
13
14
|
export { CommandButton } from "./record/CommandButton.js";
|
|
14
15
|
export { RelationPicker } from "./record/control.js";
|
|
15
16
|
export { dirtyOf, type FieldControl, RecordField, } from "./record/edit.js";
|
package/dist/web/index.js
CHANGED
|
@@ -10,6 +10,7 @@ export { pivotOf } from "./list/pivot.js";
|
|
|
10
10
|
export { presentationOf, presented, } from "./list/presentation.js";
|
|
11
11
|
export { useRowCommands, } from "./list/rowCommands.js";
|
|
12
12
|
export { facetsOf, modelOf } from "./list/search.js";
|
|
13
|
+
export { askFormOf, } from "./record/ask.js";
|
|
13
14
|
export { CommandButton } from "./record/CommandButton.js";
|
|
14
15
|
export { RelationPicker } from "./record/control.js";
|
|
15
16
|
export { dirtyOf, RecordField, } from "./record/edit.js";
|
|
@@ -89,6 +89,9 @@ export type EntityListProps<T extends AnyRecord, C extends CommandBodies = Comma
|
|
|
89
89
|
sums?: readonly string[] | false;
|
|
90
90
|
/** The cuts this list offers by name: «sólo pagadas», «vencidas». */
|
|
91
91
|
filters?: readonly NamedFilter<T>[];
|
|
92
|
+
/** The fields the search bar offers to look a typed text up in. Without it, the list
|
|
93
|
+
* definition's, else the entity's search template's, else its display (`facetsOf`). */
|
|
94
|
+
facets?: readonly string[];
|
|
92
95
|
/** The fields «Group by» offers, in this order — among those the model lets split the set.
|
|
93
96
|
* Without it, the list definition's, else every one the model does. */
|
|
94
97
|
groupable?: readonly string[];
|
|
@@ -132,4 +135,4 @@ export type EntityFace<T> = {
|
|
|
132
135
|
render: (set: ListSet<T>) => ReactNode;
|
|
133
136
|
};
|
|
134
137
|
export type View = "table" | "rows" | "board" | "sheet" | "pivot";
|
|
135
|
-
export declare function EntityList<T extends AnyRecord, C extends CommandBodies = CommandBodies>({ listing, api, columns: askedColumns, cells, views: askedViews, title: askedTitle, description: askedDescription, crumbs, actions, onOpen, onPeek, openTargets, onOpenIn, pivot: pivotAsked, empty, search, sums, filters: askedFilters, groupable: askedGroupable, selectable, selectionActions, embedded, create, commands, rowActions: askedRowActions, faces, }: EntityListProps<T, C>): import("react").JSX.Element;
|
|
138
|
+
export declare function EntityList<T extends AnyRecord, C extends CommandBodies = CommandBodies>({ listing, api, columns: askedColumns, cells, views: askedViews, title: askedTitle, description: askedDescription, crumbs, actions, onOpen, onPeek, openTargets, onOpenIn, pivot: pivotAsked, empty, search, sums, filters: askedFilters, facets: askedFacets, groupable: askedGroupable, selectable, selectionActions, embedded, create, commands, rowActions: askedRowActions, faces, }: EntityListProps<T, C>): import("react").JSX.Element;
|
|
@@ -33,7 +33,7 @@ const TRAILS = 50;
|
|
|
33
33
|
const NO_COMMANDS = [];
|
|
34
34
|
/** What a list offers when nobody said: every face that needs no configuration. */
|
|
35
35
|
const EVERY_VIEW = ["table", "rows", "board", "sheet"];
|
|
36
|
-
export function EntityList({ listing, api, columns: askedColumns, cells, views: askedViews, title: askedTitle, description: askedDescription, crumbs, actions, onOpen, onPeek, openTargets, onOpenIn, pivot: pivotAsked, empty, search = "bar", sums, filters: askedFilters, groupable: askedGroupable, selectable = false, selectionActions, embedded = false, create = true, commands = NO_COMMANDS, rowActions: askedRowActions, faces, }) {
|
|
36
|
+
export function EntityList({ listing, api, columns: askedColumns, cells, views: askedViews, title: askedTitle, description: askedDescription, crumbs, actions, onOpen, onPeek, openTargets, onOpenIn, pivot: pivotAsked, empty, search = "bar", sums, filters: askedFilters, facets: askedFacets, groupable: askedGroupable, selectable = false, selectionActions, embedded = false, create = true, commands = NO_COMMANDS, rowActions: askedRowActions, faces, }) {
|
|
37
37
|
// A named list (`defineList`) brings its own columns, filters, faces and words; what the
|
|
38
38
|
// screen passes wins.
|
|
39
39
|
const definition = listing.definition;
|
|
@@ -45,6 +45,7 @@ export function EntityList({ listing, api, columns: askedColumns, cells, views:
|
|
|
45
45
|
(embedded ? ["table"] : pivotAsked === undefined ? EVERY_VIEW : [...EVERY_VIEW, "pivot"]);
|
|
46
46
|
const filters = askedFilters ?? definition?.filters ?? [];
|
|
47
47
|
const groupable = askedGroupable ?? definition?.groupable;
|
|
48
|
+
const facets = askedFacets ?? definition?.facets;
|
|
48
49
|
const title = askedTitle ?? definition?.title;
|
|
49
50
|
const description = askedDescription ?? definition?.description;
|
|
50
51
|
const copy = frameworkCopy().list;
|
|
@@ -323,12 +324,15 @@ export function EntityList({ listing, api, columns: askedColumns, cells, views:
|
|
|
323
324
|
// grouped set (each group says its own, counted by the server). While the rows are not the
|
|
324
325
|
// whole set the list says the figures are this page's (`pageTotals`): the server's total over
|
|
325
326
|
// everything filtered waits on a reading of measures (sincpro_framework, PRD_09).
|
|
326
|
-
const totalled = !grouped &&
|
|
327
|
-
listing.rows.length > 0 &&
|
|
328
|
-
shown.some((column) => column.aggregate !== undefined && !column.defaultHidden);
|
|
329
327
|
const partial = listing.paging === "pages"
|
|
330
328
|
? page.hasPrev || page.hasNext
|
|
331
329
|
: listing.hasMore || listing.capped;
|
|
330
|
+
// Inside a record or a panel a list is its rows: a page's sum there reads as THE total, so an
|
|
331
|
+
// embedded list adds up only when every row is in hand.
|
|
332
|
+
const totalled = !grouped &&
|
|
333
|
+
!(embedded && partial) &&
|
|
334
|
+
listing.rows.length > 0 &&
|
|
335
|
+
shown.some((column) => column.aggregate !== undefined && !column.defaultHidden);
|
|
332
336
|
// A row's actions: the entity's Commands, then whatever else the screen offers.
|
|
333
337
|
// The trash (`trashOf`): each row is brought back from where it is, with the entity's own
|
|
334
338
|
// `restore` — it can be undone, so it runs on the click; the list reads again after.
|
|
@@ -348,13 +352,20 @@ export function EntityList({ listing, api, columns: askedColumns, cells, views:
|
|
|
348
352
|
? undefined
|
|
349
353
|
: (row) => [...rowCommands.rowActions(row), ...(askedRowActions?.(row) ?? [])];
|
|
350
354
|
const refused = rowCommands.error === null ? null : explain(rowCommands.error);
|
|
355
|
+
// The way through the set. Inside a record or a panel, only while there is more than what is
|
|
356
|
+
// on screen: «1–5 / 5» repeats the rows.
|
|
357
|
+
const fits = embedded && !partial;
|
|
358
|
+
const through = grouped ? (groups.status !== "ready" ? null : (_jsx("span", { className: "text-meta text-muted", children: groups.capped
|
|
359
|
+
? copy.groupsCapped(groups.buckets.length)
|
|
360
|
+
: copy.groups(groups.buckets.length, records) }))) : fits ? null : listing.paging === "pages" ? (page.from === 0 ? null : (_jsx(Pagination, { from: page.from, to: page.to, total: count?.value ?? page.to, ...(page.hasPrev ? { onPrev: listing.prev } : {}), ...(page.hasNext ? { onNext: listing.next } : {}) }))) : (_jsxs(_Fragment, { children: [count === null ? null : (_jsx("span", { className: "text-meta text-muted", children: copy.shown(listing.rows.length, count.value, count.exact) })), listing.capped ? (_jsx("span", { className: "text-meta text-muted", children: copy.capped(listing.rows.length) })) : listing.hasMore ? (_jsx(Button, { size: "sm", role: "secondary", disabled: listing.status === "loadingMore", onClick: listing.more, children: listing.status === "loadingMore" ? copy.loading : copy.loadMore })) : null] }));
|
|
361
|
+
const pageTotals = totalled && partial && present === "table";
|
|
362
|
+
// Written only when it says something: web-ui draws an embedded list's bar for any slot
|
|
363
|
+
// written, an empty one too.
|
|
364
|
+
const paging = !pageTotals && dropped.length === 0 && through === null ? null : (_jsxs(_Fragment, { children: [pageTotals ? _jsx("span", { className: "text-meta text-muted", children: copy.pageTotals }) : null, dropped.length === 0 ? null : (_jsx(Tag, { tone: "warn", title: copy.dropped(dropped), children: copy.dropped(dropped) })), through] }));
|
|
351
365
|
return (_jsxs(List, { items: listing.rows, keyOf: idOf, embedded: embedded, present: present, onPresentChange: setPresent, ...grouping,
|
|
352
366
|
// The whole order, as web-ui 1.7 shows and sets it: ⇧-click on a header adds a field,
|
|
353
367
|
// the sort menu reorders them — the same list the criteria builder writes.
|
|
354
|
-
sort: sortStates,
|
|
355
|
-
// The faces with no headers (rows, board) sort too, by the fields the model marks
|
|
356
|
-
// sortable — on the server, so no `value` is given.
|
|
357
|
-
sortable: sortable, onSortChange: (next) => listing.orderBy(next.map((one) => ({ field: one.key, descending: one.direction === "desc" }))), state: {
|
|
368
|
+
sort: sortStates, ...(embedded ? {} : { sortable }), onSortChange: (next) => listing.orderBy(next.map((one) => ({ field: one.key, descending: one.direction === "desc" }))), state: {
|
|
358
369
|
// Only the FIRST reading shows the skeleton. Refining (typing, a filter, the next
|
|
359
370
|
// page) keeps the rows on screen until the server answers: web-ui swaps the body for
|
|
360
371
|
// a skeleton while `loading`, and a row that vanished under the pointer lost a click.
|
|
@@ -371,14 +382,12 @@ export function EntityList({ listing, api, columns: askedColumns, cells, views:
|
|
|
371
382
|
}, filtered: listing.selection !== undefined || listing.text !== "", empty: {
|
|
372
383
|
sentence: empty ?? copy.empty,
|
|
373
384
|
whenFiltered: { sentence: copy.emptyFiltered },
|
|
374
|
-
}, ...(selection === undefined ? {} : { selection }), ...(opening === undefined ? {} : { onOpen: opening }), ...(peeking === undefined ? {} : { onPeek: peeking, rowClick: "open" }), children: [_jsxs(List.Bar, { children: [trail === undefined || trail.length === 0 ? null : _jsx(List.Crumbs, { crumbs: trail }), embedded ? null : (_jsx(List.Identity, { title: title ?? nameOf(meta, locale), ...(description === undefined ? {} : { description }) })), search === "bar" ? (_jsx(List.Search, { children: _jsx(EntitySearchBar, { listing: listing, filters: filters, groups: groups, ...(groupable === undefined ? {} : { groupable }), ...(asked === "" ? {} : { seed: asked }) }) })) : null, search === "box" && meta?.search != null ? (_jsx(List.Search, { children: _jsx(SearchField, { value: draft, onChange: (next) => {
|
|
385
|
+
}, ...(selection === undefined ? {} : { selection }), ...(opening === undefined ? {} : { onOpen: opening }), ...(peeking === undefined ? {} : { onPeek: peeking, rowClick: "open" }), children: [_jsxs(List.Bar, { children: [trail === undefined || trail.length === 0 ? null : _jsx(List.Crumbs, { crumbs: trail }), embedded ? null : (_jsx(List.Identity, { title: title ?? nameOf(meta, locale), ...(description === undefined ? {} : { description }) })), search === "bar" ? (_jsx(List.Search, { children: _jsx(EntitySearchBar, { listing: listing, filters: filters, groups: groups, ...(groupable === undefined ? {} : { groupable }), ...(facets === undefined ? {} : { facets }), ...(asked === "" ? {} : { seed: asked }) }) })) : null, search === "box" && meta?.search != null ? (_jsx(List.Search, { children: _jsx(SearchField, { value: draft, onChange: (next) => {
|
|
375
386
|
setDraft(next);
|
|
376
387
|
// Emptied (or cleared with ×): the whole set again, at once.
|
|
377
388
|
if (next === "" && listing.text !== "")
|
|
378
389
|
listing.search("", { now: true });
|
|
379
|
-
}, onSubmit: (text) => listing.search(text, { now: true }), placeholder: copy.search, "aria-label": copy.search }) })) : null, actions === undefined && creating === undefined ? null : (_jsxs(List.Actions, { children: [actions, creating === undefined ? null : (_jsx(Button, { role: "primary", size: "sm", onClick: creating, children: frameworkCopy().record.create }))] })),
|
|
380
|
-
? copy.groupsCapped(groups.buckets.length)
|
|
381
|
-
: copy.groups(groups.buckets.length, records) }))) : listing.paging === "pages" ? (page.from === 0 ? null : (_jsx(Pagination, { from: page.from, to: page.to, total: count?.value ?? page.to, ...(page.hasPrev ? { onPrev: listing.prev } : {}), ...(page.hasNext ? { onNext: listing.next } : {}) }))) : (_jsxs(_Fragment, { children: [count === null ? null : (_jsx("span", { className: "text-meta text-muted", children: copy.shown(listing.rows.length, count.value, count.exact) })), listing.capped ? (_jsx("span", { className: "text-meta text-muted", children: copy.capped(listing.rows.length) })) : listing.hasMore ? (_jsx(Button, { size: "sm", role: "secondary", disabled: listing.status === "loadingMore", onClick: listing.more, children: listing.status === "loadingMore" ? copy.loading : copy.loadMore })) : null] }))] })] }), views.includes("table") ? (_jsx(List.Table, { columns: shown, ...(totalled ? { totals: true } : {}), ...(rowActions === undefined ? {} : { rowActions }) })) : null, _jsx(List.Rows, { row: rowOf }), views.includes("sheet") ? (_jsx(List.Sheet, { columns: sheetColumns, cell: (row, column) => {
|
|
390
|
+
}, onSubmit: (text) => listing.search(text, { now: true }), placeholder: copy.search, "aria-label": copy.search }) })) : null, actions === undefined && creating === undefined ? null : (_jsxs(List.Actions, { children: [actions, creating === undefined ? null : (_jsx(Button, { role: "primary", size: "sm", onClick: creating, children: frameworkCopy().record.create }))] })), paging === null ? null : _jsx(List.Pagination, { children: paging })] }), views.includes("table") ? (_jsx(List.Table, { columns: shown, ...(totalled ? { totals: true } : {}), ...(rowActions === undefined ? {} : { rowActions }) })) : null, _jsx(List.Rows, { row: rowOf }), views.includes("sheet") ? (_jsx(List.Sheet, { columns: sheetColumns, cell: (row, column) => {
|
|
382
391
|
const value = row[column.id];
|
|
383
392
|
return value === null || value === undefined
|
|
384
393
|
? null
|
|
@@ -12,7 +12,8 @@ import type { Listing } from "../../react/useListing.js";
|
|
|
12
12
|
* - a free text is the entity's LITERAL search — its whole template, every field at once
|
|
13
13
|
* (sincpro_framework's `LiteralSearch`, the same question a many2one and ⌘K ask): it is
|
|
14
14
|
* what Enter puts, unless the model reads the text as a question of its own;
|
|
15
|
-
* - «search by name»: facets are the fields the
|
|
15
|
+
* - «search by name»: facets are the fields the screen names (`facets`), else the ones the
|
|
16
|
+
* entity's search template names — never every text field;
|
|
16
17
|
* - a typed question («total > 5000») is checked against each field's operators;
|
|
17
18
|
* - a named filter is one click; the builder writes what nobody foresaw (all/any/not);
|
|
18
19
|
* - everything put becomes ONE `selection` the SERVER answers (`listing.filter`) — web-ui
|
|
@@ -23,7 +24,7 @@ import type { Listing } from "../../react/useListing.js";
|
|
|
23
24
|
* <List.Search><EntitySearchBar listing={listing} filters={…} /></List.Search>
|
|
24
25
|
*/
|
|
25
26
|
export type { NamedFilter };
|
|
26
|
-
export declare function EntitySearchBar<T extends AnyRecord>({ listing, filters, groups, groupable: only, seed, }: {
|
|
27
|
+
export declare function EntitySearchBar<T extends AnyRecord>({ listing, filters, groups, groupable: only, facets: named, seed, }: {
|
|
27
28
|
listing: Listing<T>;
|
|
28
29
|
/** The cuts this set offers by name: «sólo pagadas», «vencidas». */
|
|
29
30
|
filters?: readonly NamedFilter<T>[];
|
|
@@ -32,6 +33,9 @@ export declare function EntitySearchBar<T extends AnyRecord>({ listing, filters,
|
|
|
32
33
|
/** The fields «Group by» offers, in this order — among those the model lets split the set.
|
|
33
34
|
* Without it, every one it does. */
|
|
34
35
|
groupable?: readonly string[];
|
|
36
|
+
/** The fields a typed text is offered to be looked up in, in order. Without it, the ones the
|
|
37
|
+
* entity's search template names, else its display (`facetsOf`). */
|
|
38
|
+
facets?: readonly string[];
|
|
35
39
|
/** A text to start on, put as the literal search chip — what was typed in a picker whose
|
|
36
40
|
* «Buscar más…» opened this list. */
|
|
37
41
|
seed?: string;
|
|
@@ -8,13 +8,21 @@ import { CriteriaBuilder, describeFilter, Dialog, fillCopy, filterCriteria, Grou
|
|
|
8
8
|
import { useEffect, useMemo, useRef, useState } from "react";
|
|
9
9
|
/** No grouping: one constant, so the control is not handed a new array on every render. */
|
|
10
10
|
const NO_LEVELS = [];
|
|
11
|
-
export function EntitySearchBar({ listing, filters = [], groups, groupable: only, seed, }) {
|
|
11
|
+
export function EntitySearchBar({ listing, filters = [], groups, groupable: only, facets: named, seed, }) {
|
|
12
12
|
const copy = frameworkCopy().list;
|
|
13
13
|
const { meta, locale } = listing;
|
|
14
14
|
const [put, setPut] = useState([]);
|
|
15
15
|
const [building, setBuilding] = useState(false);
|
|
16
16
|
const model = useMemo(() => (meta ? modelOf(meta, locale) : undefined), [meta, locale]);
|
|
17
|
-
|
|
17
|
+
// Compared by content: a screen usually writes the list inline.
|
|
18
|
+
const naming = named?.join("\u0000");
|
|
19
|
+
const facets = useMemo(() => (meta ? facetsOf(meta, locale, named) : []),
|
|
20
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
21
|
+
[meta, locale, naming]);
|
|
22
|
+
// The bar's model: its text fields are only the facets — every other one is the builder's.
|
|
23
|
+
const asked = useMemo(() => meta
|
|
24
|
+
? modelOf(meta, locale, facets.map((one) => one.id))
|
|
25
|
+
: undefined, [meta, locale, facets]);
|
|
18
26
|
const groupable = useMemo(() => groupableOf(meta, locale, only), [meta, locale, only]);
|
|
19
27
|
const ui = useUiCopy();
|
|
20
28
|
const seeded = useRef(false);
|
|
@@ -43,7 +51,7 @@ export function EntitySearchBar({ listing, filters = [], groups, groupable: only
|
|
|
43
51
|
};
|
|
44
52
|
// What the bar holds, as one selection: what the builder opens on.
|
|
45
53
|
const current = selectionOf(put);
|
|
46
|
-
return (_jsxs(_Fragment, { children: [_jsx(SearchBar, { facets: facets, model: model, criteria: put, onCriteriaChange: place, placeholder: copy.searchBar, ...(filters.length === 0
|
|
54
|
+
return (_jsxs(_Fragment, { children: [_jsx(SearchBar, { facets: facets, model: asked ?? model, criteria: put, onCriteriaChange: place, placeholder: copy.searchBar, ...(filters.length === 0
|
|
47
55
|
? {}
|
|
48
56
|
: {
|
|
49
57
|
filters: [
|
package/dist/web/list/columns.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
3
|
import { frameworkCopy } from "../../core/copy.js";
|
|
3
4
|
import { totalOf } from "../../core/measure.js";
|
|
4
5
|
import { BOOKKEEPING, defaultFields, fieldMetaOf, sortKeyOf, textOf, valueAt, viewOf, } from "../../core/present.js";
|
|
6
|
+
import { relationFieldOf } from "../../core/relation.js";
|
|
7
|
+
import { useEntityFor } from "../../react/context.js";
|
|
8
|
+
import { useNameOf } from "../../react/useNameOf.js";
|
|
5
9
|
import { Tag } from "@sincpro/web-ui";
|
|
6
10
|
import { Check } from "lucide-react";
|
|
7
11
|
/**
|
|
@@ -14,7 +18,9 @@ import { Check } from "lucide-react";
|
|
|
14
18
|
* can be ordered is what the server said (`sortable`). A cell is drawn by its TYPE: a choice is a
|
|
15
19
|
* tag in the tone the application declared for its value (`presented(entity, { tones })`), a
|
|
16
20
|
* yes/no a check, an amount the model draws as money is money. A cell that needs more — a link,
|
|
17
|
-
* a figure of its own — is the one thing a screen writes (`cells`).
|
|
21
|
+
* a figure of its own — is the one thing a screen writes (`cells`). A column that holds a key of
|
|
22
|
+
* another record (`organo_id`, an `EntityID`) reads the record's name, as its picker does: every
|
|
23
|
+
* key of the page asked in ONE request per entity (`useNameOf`), the key until it answers.
|
|
18
24
|
*
|
|
19
25
|
* A column the model adds up at a list's foot (`total`: `sum`, `avg`, `min`, `max`) declares it
|
|
20
26
|
* (`aggregate`), with its own format: the foot reads «Bs 1.204,50» like the cells above it.
|
|
@@ -36,6 +42,11 @@ export function aggregateOf(meta, name) {
|
|
|
36
42
|
const total = totalOf(meta, name);
|
|
37
43
|
return total === undefined ? undefined : AGGREGATES[total];
|
|
38
44
|
}
|
|
45
|
+
/** A key's cell: the name of the record it points at, the key until it answers or when the
|
|
46
|
+
* application declared no entity for it. */
|
|
47
|
+
function KeyName({ target, id }) {
|
|
48
|
+
return _jsx(_Fragment, { children: useNameOf(useEntityFor(target), id) ?? id });
|
|
49
|
+
}
|
|
39
50
|
function columnOf(meta, name, options, hidden) {
|
|
40
51
|
const view = viewOf(meta, name, options.locale);
|
|
41
52
|
const field = fieldMetaOf(meta, name);
|
|
@@ -48,12 +59,28 @@ function columnOf(meta, name, options, hidden) {
|
|
|
48
59
|
const tones = options.tones?.[name];
|
|
49
60
|
const choice = (field?.choices?.length ?? 0) > 0;
|
|
50
61
|
const aggregate = aggregateOf(meta, name);
|
|
62
|
+
// The column IS a key of another record: `customer_id` beside its relation, or a key alone.
|
|
63
|
+
const relation = relationFieldOf(meta, name);
|
|
64
|
+
const pointing = relation !== undefined && !relation.many && relation.key === name ? relation : undefined;
|
|
65
|
+
const named = pointing === undefined
|
|
66
|
+
? undefined
|
|
67
|
+
: (row) => {
|
|
68
|
+
const key = raw(row);
|
|
69
|
+
if (key === null || key === undefined || key === "")
|
|
70
|
+
return null;
|
|
71
|
+
// Held beside its key, the record names itself; a key alone asks its name.
|
|
72
|
+
const held = pointing.relation === name
|
|
73
|
+
? null
|
|
74
|
+
: textOf(meta, pointing.relation, row[pointing.relation], options.locale);
|
|
75
|
+
return held ?? _jsx(KeyName, { target: pointing.target, id: String(key) });
|
|
76
|
+
};
|
|
51
77
|
return {
|
|
52
78
|
id: name,
|
|
53
79
|
header: view.label,
|
|
54
80
|
field: name,
|
|
55
81
|
value: (row) => sortKeyOf(meta, name, raw(row)),
|
|
56
82
|
cell: own ??
|
|
83
|
+
named ??
|
|
57
84
|
(choice
|
|
58
85
|
? // A state reads at a glance: its word in a tag, in the tone the application gave it.
|
|
59
86
|
(row) => {
|
|
@@ -11,11 +11,20 @@ import type { ModelDefinition, SearchFacet } from "@sincpro/web-ui";
|
|
|
11
11
|
*
|
|
12
12
|
* Known gap: web-ui's field has `choices` but no word for each choice, so the bar offers an
|
|
13
13
|
* enum's raw values («paid») where a cell says «Pagada». Fixing it is web-ui's.
|
|
14
|
+
*
|
|
15
|
+
* `texts` keeps only those plain text fields: web-ui's bar offers a typed word in EVERY text
|
|
16
|
+
* field of the model it is handed (its `facets` are read only without one), so the bar is handed
|
|
17
|
+
* the model with the text fields a person types into (`facetsOf`) — and the criteria builder the
|
|
18
|
+
* whole one.
|
|
14
19
|
*/
|
|
15
|
-
export declare function modelOf(meta: Meta, locale?: string): ModelDefinition;
|
|
20
|
+
export declare function modelOf(meta: Meta, locale?: string, texts?: readonly string[]): ModelDefinition;
|
|
16
21
|
/**
|
|
17
|
-
* Where a typed text can be looked for: the fields the
|
|
18
|
-
*
|
|
19
|
-
*
|
|
22
|
+
* Where a typed text can be looked for: the fields the screen names (`defineList facets`), else
|
|
23
|
+
* the ones the entity's search template names — what a typed text already means for it —, else
|
|
24
|
+
* its display field.
|
|
25
|
+
*
|
|
26
|
+
* Context: it used to append every text field that takes `like`, and «Excel» in a list of
|
|
27
|
+
* enrollments offered sixteen places to look, «ID» and a storage key among them. Which fields a
|
|
28
|
+
* person types into is the screen's decision; every other field is still in the criteria builder.
|
|
20
29
|
*/
|
|
21
|
-
export declare function facetsOf(meta: Meta, locale?: string): SearchFacet[];
|
|
30
|
+
export declare function facetsOf(meta: Meta, locale?: string, named?: readonly string[]): SearchFacet[];
|
package/dist/web/list/search.js
CHANGED
|
@@ -10,13 +10,25 @@ import { labelOf } from "@sincpro/criteria";
|
|
|
10
10
|
*
|
|
11
11
|
* Known gap: web-ui's field has `choices` but no word for each choice, so the bar offers an
|
|
12
12
|
* enum's raw values («paid») where a cell says «Pagada». Fixing it is web-ui's.
|
|
13
|
+
*
|
|
14
|
+
* `texts` keeps only those plain text fields: web-ui's bar offers a typed word in EVERY text
|
|
15
|
+
* field of the model it is handed (its `facets` are read only without one), so the bar is handed
|
|
16
|
+
* the model with the text fields a person types into (`facetsOf`) — and the criteria builder the
|
|
17
|
+
* whole one.
|
|
13
18
|
*/
|
|
14
|
-
export function modelOf(meta, locale) {
|
|
15
|
-
const
|
|
19
|
+
export function modelOf(meta, locale, texts) {
|
|
20
|
+
const kept = (name) => {
|
|
21
|
+
const field = meta.fields[name];
|
|
22
|
+
const text = field?.type === "text" && !field.choices?.length;
|
|
23
|
+
return texts === undefined || !text || texts.includes(name);
|
|
24
|
+
};
|
|
25
|
+
const names = Object.keys(meta.fields).filter(kept);
|
|
16
26
|
return {
|
|
17
27
|
aggregate: meta.aggregate,
|
|
18
28
|
identity: meta.identity,
|
|
19
|
-
fields: Object.fromEntries(Object.entries(meta.fields)
|
|
29
|
+
fields: Object.fromEntries(Object.entries(meta.fields)
|
|
30
|
+
.filter(([name]) => kept(name))
|
|
31
|
+
.map(([name, field]) => [
|
|
20
32
|
name,
|
|
21
33
|
{
|
|
22
34
|
type: field.type,
|
|
@@ -26,7 +38,9 @@ export function modelOf(meta, locale) {
|
|
|
26
38
|
kind: field.kind,
|
|
27
39
|
...(field.many === undefined ? {} : { many: field.many }),
|
|
28
40
|
...(field.relation === undefined ? {} : { relation: field.relation }),
|
|
29
|
-
...(field.identified_by === undefined
|
|
41
|
+
...(field.identified_by === undefined
|
|
42
|
+
? {}
|
|
43
|
+
: { identifiedBy: field.identified_by }),
|
|
30
44
|
...(field.choices && field.choices.length > 0 ? { choices: field.choices } : {}),
|
|
31
45
|
},
|
|
32
46
|
])),
|
|
@@ -58,15 +72,16 @@ function searchedFields(meta) {
|
|
|
58
72
|
return found;
|
|
59
73
|
}
|
|
60
74
|
/**
|
|
61
|
-
* Where a typed text can be looked for: the fields the
|
|
62
|
-
*
|
|
63
|
-
*
|
|
75
|
+
* Where a typed text can be looked for: the fields the screen names (`defineList facets`), else
|
|
76
|
+
* the ones the entity's search template names — what a typed text already means for it —, else
|
|
77
|
+
* its display field.
|
|
78
|
+
*
|
|
79
|
+
* Context: it used to append every text field that takes `like`, and «Excel» in a list of
|
|
80
|
+
* enrollments offered sixteen places to look, «ID» and a storage key among them. Which fields a
|
|
81
|
+
* person types into is the screen's decision; every other field is still in the criteria builder.
|
|
64
82
|
*/
|
|
65
|
-
export function facetsOf(meta, locale) {
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
.map(([name]) => name);
|
|
70
|
-
const order = [...new Set([...first, ...texts])];
|
|
71
|
-
return order.map((name) => ({ id: name, label: labelOf(meta, name, locale) }));
|
|
83
|
+
export function facetsOf(meta, locale, named) {
|
|
84
|
+
const searched = [...new Set(searchedFields(meta))];
|
|
85
|
+
const fields = named ?? (searched.length > 0 ? searched : meta.display ? [meta.display] : []);
|
|
86
|
+
return fields.map((name) => ({ id: name, label: labelOf(meta, name, locale) }));
|
|
72
87
|
}
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import type { Rehearsal } from "../../react/useCommand.js";
|
|
2
|
+
import type { AskForm } from "./ask.js";
|
|
3
|
+
/** What a person filled in before the action runs, by field name. */
|
|
4
|
+
export type Asked = Readonly<Record<string, unknown>>;
|
|
2
5
|
/**
|
|
3
6
|
* What a button needs of an action to draw it — whatever runs behind: an entity's Command
|
|
4
7
|
* (`useCommand`) or one of the application's use cases (`useService`).
|
|
5
8
|
*/
|
|
6
9
|
export type ButtonAction<R> = {
|
|
7
|
-
/** Does it
|
|
8
|
-
|
|
10
|
+
/** Does it — with what was asked, when it asks —; `undefined` when it failed: the failure is
|
|
11
|
+
* in `error`. */
|
|
12
|
+
run: (asked?: Asked) => Promise<R | undefined>;
|
|
9
13
|
/** Asks first what it would do — a dry run: the action destroys something. */
|
|
10
|
-
rehearse?: () => Promise<Rehearsal | undefined>;
|
|
14
|
+
rehearse?: (asked?: Asked) => Promise<Rehearsal | undefined>;
|
|
11
15
|
busy: boolean;
|
|
12
16
|
error: unknown;
|
|
13
17
|
/** What the last dry run said it would do. */
|
|
@@ -23,12 +27,18 @@ export type ButtonAction<R> = {
|
|
|
23
27
|
* confirmation is the consequence, in the server's words, not a question. A refusal is shown
|
|
24
28
|
* where it happened, with what to do. Off while it runs: a click twice is one action.
|
|
25
29
|
*
|
|
30
|
+
* One that needs input (`ask`) opens its fields first, filled from the record, and sends them on
|
|
31
|
+
* «Confirmar»; when it can rehearse, the first «Confirmar» asks what it would do with them and
|
|
32
|
+
* the second does it. A refusal stays in the dialog over the fields, so they can be put right.
|
|
33
|
+
*
|
|
26
34
|
* Internal: the gesture is drawn here once; what runs behind is each button's own.
|
|
27
35
|
*/
|
|
28
|
-
export declare function ActionButton<R>({ action, label, role, disabled, onDone, }: {
|
|
36
|
+
export declare function ActionButton<R>({ action, label, role, disabled, ask: form, onDone, }: {
|
|
29
37
|
action: ButtonAction<R>;
|
|
30
38
|
label: string;
|
|
31
39
|
role?: "primary" | "secondary" | "ghost";
|
|
32
40
|
disabled?: boolean;
|
|
41
|
+
/** What it asks for before it runs — `askFormOf`. */
|
|
42
|
+
ask?: AskForm;
|
|
33
43
|
onDone?: (answer: R) => void;
|
|
34
44
|
}): import("react").JSX.Element;
|
|
@@ -2,8 +2,38 @@
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
import { frameworkCopy } from "../../core/copy.js";
|
|
4
4
|
import { Refused } from "../Refused.js";
|
|
5
|
-
import { Button, Dialog } from "@sincpro/web-ui";
|
|
5
|
+
import { Button, Dialog, Field, FormSection } from "@sincpro/web-ui";
|
|
6
6
|
import { useState } from "react";
|
|
7
|
+
/** The fields of an action that asks, its refusal over them and what its dry run said. */
|
|
8
|
+
function AskDialog({ action, form, label, onClose, onDone, }) {
|
|
9
|
+
const copy = frameworkCopy().command;
|
|
10
|
+
const [values, setValues] = useState(() => ({ ...form.initial }));
|
|
11
|
+
const rehearsing = action.rehearse !== undefined;
|
|
12
|
+
const confirm = async () => {
|
|
13
|
+
if (rehearsing && action.rehearsal === null) {
|
|
14
|
+
await action.rehearse?.(values);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const answer = await action.run(values);
|
|
18
|
+
if (answer !== undefined)
|
|
19
|
+
onDone(answer);
|
|
20
|
+
};
|
|
21
|
+
return (_jsxs(Dialog, { open: true, title: label, onClose: onClose, footer: _jsxs("div", { className: "flex justify-end gap-2", children: [_jsx(Button, { size: "sm", role: "secondary", onClick: onClose, children: copy.cancel }), _jsx(Button, { size: "sm", role: "primary", disabled: action.busy, onClick: () => void confirm(), children: rehearsing && action.rehearsal !== null ? copy.confirm : copy.send })] }), children: [action.error === null ? null : _jsx(Refused, { error: action.error }), _jsx(FormSection, { children: form.fields.map((field) => {
|
|
22
|
+
const control = {
|
|
23
|
+
value: values[field.name],
|
|
24
|
+
set: (next) => {
|
|
25
|
+
setValues((now) => ({ ...now, [field.name]: next }));
|
|
26
|
+
// What the dry run said was about the values before this one.
|
|
27
|
+
if (action.rehearsal !== null || action.error !== null)
|
|
28
|
+
action.reset();
|
|
29
|
+
},
|
|
30
|
+
readonly: false,
|
|
31
|
+
invalid: false,
|
|
32
|
+
label: field.label,
|
|
33
|
+
};
|
|
34
|
+
return field.labelled ? (_jsx("div", { children: field.draw(control) }, field.name)) : (_jsx(Field, { label: field.label, children: field.draw(control) }, field.name));
|
|
35
|
+
}) }), action.rehearsal === null ? null : _jsx("p", { className: "text-ink", children: action.rehearsal.text })] }));
|
|
36
|
+
}
|
|
7
37
|
/**
|
|
8
38
|
* An action as a button — the gesture `CommandButton` and `ServiceButton` share.
|
|
9
39
|
*
|
|
@@ -13,11 +43,24 @@ import { useState } from "react";
|
|
|
13
43
|
* confirmation is the consequence, in the server's words, not a question. A refusal is shown
|
|
14
44
|
* where it happened, with what to do. Off while it runs: a click twice is one action.
|
|
15
45
|
*
|
|
46
|
+
* One that needs input (`ask`) opens its fields first, filled from the record, and sends them on
|
|
47
|
+
* «Confirmar»; when it can rehearse, the first «Confirmar» asks what it would do with them and
|
|
48
|
+
* the second does it. A refusal stays in the dialog over the fields, so they can be put right.
|
|
49
|
+
*
|
|
16
50
|
* Internal: the gesture is drawn here once; what runs behind is each button's own.
|
|
17
51
|
*/
|
|
18
|
-
export function ActionButton({ action, label, role = "secondary", disabled = false, onDone, }) {
|
|
52
|
+
export function ActionButton({ action, label, role = "secondary", disabled = false, ask: form, onDone, }) {
|
|
19
53
|
const copy = frameworkCopy().command;
|
|
20
54
|
const [open, setOpen] = useState(false);
|
|
55
|
+
if (form !== undefined)
|
|
56
|
+
return (_jsxs(_Fragment, { children: [_jsx(Button, { size: "sm", role: role, disabled: disabled || action.busy, onClick: () => setOpen(true), children: label }), open ? (_jsx(AskDialog, { action: action, form: form, label: label, onClose: () => {
|
|
57
|
+
setOpen(false);
|
|
58
|
+
action.reset();
|
|
59
|
+
}, onDone: (answer) => {
|
|
60
|
+
setOpen(false);
|
|
61
|
+
action.reset();
|
|
62
|
+
onDone?.(answer);
|
|
63
|
+
} })) : null] }));
|
|
21
64
|
const destructive = action.rehearse !== undefined;
|
|
22
65
|
const run = async () => {
|
|
23
66
|
const answer = await action.run();
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type CommandAnswers, type CommandBodies, type Entity } from "@sincpro/client-framework";
|
|
2
2
|
import type { AnyRecord } from "@sincpro/criteria";
|
|
3
3
|
import { type AnswerOf } from "../../react/useCommand.js";
|
|
4
|
+
import { type AskField } from "./ask.js";
|
|
4
5
|
/**
|
|
5
6
|
* An entity's Command as a button: sent as it is, over the screens' transport.
|
|
6
7
|
*
|
|
@@ -8,8 +9,12 @@ import { type AnswerOf } from "../../react/useCommand.js";
|
|
|
8
9
|
* server's dry run first and show what it would do; a refusal where it happened. An action that is
|
|
9
10
|
* one of the application's own use cases — logic of its own, composed, traced as
|
|
10
11
|
* `<context>/<Service>` — is a `ServiceButton`.
|
|
12
|
+
*
|
|
13
|
+
* One that needs input names the fields it asks for (`ask`): a dialog draws them as the
|
|
14
|
+
* record's fields of the same name, filled from `record`, and what is filled goes in the body
|
|
15
|
+
* beside `body`.
|
|
11
16
|
*/
|
|
12
|
-
export declare function CommandButton<T extends AnyRecord, R = unknown, C extends CommandBodies = CommandBodies, N extends keyof C & string = keyof C & string, A extends CommandAnswers = CommandAnswers>({ entity, command, id, body, label, destructive, role, disabled, onDone, }: {
|
|
17
|
+
export declare function CommandButton<T extends AnyRecord, R = unknown, C extends CommandBodies = CommandBodies, N extends keyof C & string = keyof C & string, A extends CommandAnswers = CommandAnswers>({ entity, command, id, body, label, destructive, role, disabled, ask, record, onDone, }: {
|
|
13
18
|
entity: Entity<T, C, A>;
|
|
14
19
|
/** One the entity declares; a typed entity takes only its own names. */
|
|
15
20
|
command: N;
|
|
@@ -22,5 +27,9 @@ export declare function CommandButton<T extends AnyRecord, R = unknown, C extend
|
|
|
22
27
|
role?: "primary" | "secondary" | "ghost";
|
|
23
28
|
/** Not offered right now — «Mover» with no other tenant chosen. The server still decides. */
|
|
24
29
|
disabled?: boolean;
|
|
30
|
+
/** The fields it asks for before it runs, sent in its body: `["areas"]`. */
|
|
31
|
+
ask?: readonly AskField[];
|
|
32
|
+
/** The record it acts on: what the asked fields start with. */
|
|
33
|
+
record?: AnyRecord;
|
|
25
34
|
onDone?: (answer: AnswerOf<R, A, N>) => void;
|
|
26
35
|
}): import("react").JSX.Element;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import {} from "@sincpro/client-framework";
|
|
4
|
+
import { entityFor } from "../../core/relation.js";
|
|
5
|
+
import { useFramework } from "../../react/context.js";
|
|
4
6
|
import { useCommand } from "../../react/useCommand.js";
|
|
5
7
|
import { ActionButton } from "./ActionButton.js";
|
|
8
|
+
import { askFormOf } from "./ask.js";
|
|
6
9
|
/**
|
|
7
10
|
* An entity's Command as a button: sent as it is, over the screens' transport.
|
|
8
11
|
*
|
|
@@ -10,12 +13,28 @@ import { ActionButton } from "./ActionButton.js";
|
|
|
10
13
|
* server's dry run first and show what it would do; a refusal where it happened. An action that is
|
|
11
14
|
* one of the application's own use cases — logic of its own, composed, traced as
|
|
12
15
|
* `<context>/<Service>` — is a `ServiceButton`.
|
|
16
|
+
*
|
|
17
|
+
* One that needs input names the fields it asks for (`ask`): a dialog draws them as the
|
|
18
|
+
* record's fields of the same name, filled from `record`, and what is filled goes in the body
|
|
19
|
+
* beside `body`.
|
|
13
20
|
*/
|
|
14
|
-
export function CommandButton({ entity, command, id, body, label, destructive = false, role = "secondary", disabled = false, onDone, }) {
|
|
21
|
+
export function CommandButton({ entity, command, id, body, label, destructive = false, role = "secondary", disabled = false, ask, record, onDone, }) {
|
|
15
22
|
const sending = useCommand(entity, command);
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
23
|
+
const { metas, entities, locale } = useFramework();
|
|
24
|
+
const form = ask === undefined
|
|
25
|
+
? undefined
|
|
26
|
+
: askFormOf(ask, {
|
|
27
|
+
meta: metas.get(entity.key),
|
|
28
|
+
locale,
|
|
29
|
+
record,
|
|
30
|
+
entityFor: (target) => entityFor(entities, target, metas.get),
|
|
31
|
+
});
|
|
32
|
+
const bodyWith = (asked) => (asked === undefined ? body : { ...body, ...asked });
|
|
33
|
+
return (_jsx(ActionButton, { ...(form === undefined ? {} : { ask: form }), action: {
|
|
34
|
+
run: (asked) => sending.run(id, bodyWith(asked)),
|
|
35
|
+
...(destructive
|
|
36
|
+
? { rehearse: (asked) => sending.rehearse(id, bodyWith(asked)) }
|
|
37
|
+
: {}),
|
|
19
38
|
busy: sending.busy,
|
|
20
39
|
error: sending.error,
|
|
21
40
|
rehearsal: sending.rehearsal,
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
import type { Entity } from "@sincpro/client-framework";
|
|
2
|
+
import type { AnyRecord } from "@sincpro/criteria";
|
|
1
3
|
import type { Rehearsal } from "../../react/useCommand.js";
|
|
4
|
+
import { type Asked } from "./ActionButton.js";
|
|
5
|
+
import { type AskField } from "./ask.js";
|
|
2
6
|
/**
|
|
3
7
|
* One of the application's use cases as a button — its Feature or ApplicationService, run on its
|
|
4
8
|
* bounded context.
|
|
@@ -17,15 +21,27 @@ import type { Rehearsal } from "../../react/useCommand.js";
|
|
|
17
21
|
* and shows what it would do. What it changed, every screen hears by itself: the use case's
|
|
18
22
|
* client announces its write (`processChanges`), so `onDone` is for what only this screen does
|
|
19
23
|
* next — a toast, closing a window —, never to read again.
|
|
24
|
+
*
|
|
25
|
+
* A use case that needs input names the fields it asks for (`ask`), read as `entity`'s fields of
|
|
26
|
+
* the same name and filled from `record`; `run` and `rehearse` receive what was filled.
|
|
27
|
+
*
|
|
28
|
+
* <ServiceButton label="Delegar áreas" entity={cuentas} record={cuenta} ask={["areas"]}
|
|
29
|
+
* run={(asked) => cuentaBoundedContext.execute(new CommandDelegarAreas(cuenta.id, asked.areas))} />
|
|
20
30
|
*/
|
|
21
|
-
export declare function ServiceButton<R>({ label, run, rehearse, role, disabled, onDone, }: {
|
|
31
|
+
export declare function ServiceButton<R>({ label, run, rehearse, role, disabled, ask, entity, record, onDone, }: {
|
|
22
32
|
label: string;
|
|
23
|
-
/** The use case, executed on its bounded context. */
|
|
24
|
-
run: () => Promise<R>;
|
|
33
|
+
/** The use case, executed on its bounded context — with what was asked, when it asks. */
|
|
34
|
+
run: (asked: Asked) => Promise<R>;
|
|
25
35
|
/** The same use case run dry — what it would do, nothing touched —, asked before `run`. */
|
|
26
|
-
rehearse?: () => Promise<Rehearsal>;
|
|
36
|
+
rehearse?: (asked: Asked) => Promise<Rehearsal>;
|
|
27
37
|
role?: "primary" | "secondary" | "ghost";
|
|
28
38
|
/** Not offered right now. The use case still decides. */
|
|
29
39
|
disabled?: boolean;
|
|
40
|
+
/** The fields it asks for before it runs: `["areas"]`. */
|
|
41
|
+
ask?: readonly AskField[];
|
|
42
|
+
/** Whose fields `ask` names: their labels, choices and controls. */
|
|
43
|
+
entity?: Entity;
|
|
44
|
+
/** The record it acts on: what the asked fields start with. */
|
|
45
|
+
record?: AnyRecord;
|
|
30
46
|
onDone?: (answer: R) => void;
|
|
31
47
|
}): import("react").JSX.Element;
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { entityFor } from "../../core/relation.js";
|
|
4
|
+
import { useFrameworkIfAny } from "../../react/context.js";
|
|
3
5
|
import { useService } from "../../react/useService.js";
|
|
4
6
|
import { ActionButton } from "./ActionButton.js";
|
|
7
|
+
import { askFormOf } from "./ask.js";
|
|
5
8
|
/** What the button runs when there is no dry run: nothing. */
|
|
6
|
-
const NO_REHEARSAL = async () => undefined;
|
|
9
|
+
const NO_REHEARSAL = async (_asked) => undefined;
|
|
10
|
+
/** What a use case that asks nothing receives. */
|
|
11
|
+
const NOTHING_ASKED = {};
|
|
7
12
|
/**
|
|
8
13
|
* One of the application's use cases as a button — its Feature or ApplicationService, run on its
|
|
9
14
|
* bounded context.
|
|
@@ -22,11 +27,31 @@ const NO_REHEARSAL = async () => undefined;
|
|
|
22
27
|
* and shows what it would do. What it changed, every screen hears by itself: the use case's
|
|
23
28
|
* client announces its write (`processChanges`), so `onDone` is for what only this screen does
|
|
24
29
|
* next — a toast, closing a window —, never to read again.
|
|
30
|
+
*
|
|
31
|
+
* A use case that needs input names the fields it asks for (`ask`), read as `entity`'s fields of
|
|
32
|
+
* the same name and filled from `record`; `run` and `rehearse` receive what was filled.
|
|
33
|
+
*
|
|
34
|
+
* <ServiceButton label="Delegar áreas" entity={cuentas} record={cuenta} ask={["areas"]}
|
|
35
|
+
* run={(asked) => cuentaBoundedContext.execute(new CommandDelegarAreas(cuenta.id, asked.areas))} />
|
|
25
36
|
*/
|
|
26
|
-
export function ServiceButton({ label, run, rehearse, role = "secondary", disabled = false, onDone, }) {
|
|
27
|
-
const running = useService(run);
|
|
28
|
-
const rehearsing = useService(rehearse ?? NO_REHEARSAL);
|
|
29
|
-
|
|
37
|
+
export function ServiceButton({ label, run, rehearse, role = "secondary", disabled = false, ask, entity, record, onDone, }) {
|
|
38
|
+
const running = useService((asked) => run(asked ?? NOTHING_ASKED));
|
|
39
|
+
const rehearsing = useService((asked) => (rehearse ?? NO_REHEARSAL)(asked ?? NOTHING_ASKED));
|
|
40
|
+
// Outside a provider it still runs: the asked fields are then drawn by what `ask` says.
|
|
41
|
+
const framework = useFrameworkIfAny();
|
|
42
|
+
const form = ask === undefined
|
|
43
|
+
? undefined
|
|
44
|
+
: askFormOf(ask, {
|
|
45
|
+
meta: entity === undefined ? undefined : framework?.metas.get(entity.key),
|
|
46
|
+
locale: framework?.locale,
|
|
47
|
+
record,
|
|
48
|
+
...(framework === null
|
|
49
|
+
? {}
|
|
50
|
+
: {
|
|
51
|
+
entityFor: (target) => entityFor(framework.entities, target, framework.metas.get),
|
|
52
|
+
}),
|
|
53
|
+
});
|
|
54
|
+
return (_jsx(ActionButton, { ...(form === undefined ? {} : { ask: form }), action: {
|
|
30
55
|
run: running.run,
|
|
31
56
|
...(rehearse === undefined ? {} : { rehearse: rehearsing.run }),
|
|
32
57
|
busy: running.busy || rehearsing.busy,
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { Entity } from "@sincpro/client-framework";
|
|
2
|
+
import { type AnyRecord, type Meta } from "@sincpro/criteria";
|
|
3
|
+
import { type FieldControl } from "./control.js";
|
|
4
|
+
import type { ReactNode } from "react";
|
|
5
|
+
/**
|
|
6
|
+
* A field an action asks for before it runs: a field of the entity by its name — `"areas"` —, or
|
|
7
|
+
* one the entity does not have, described by the action.
|
|
8
|
+
*
|
|
9
|
+
* <CommandButton entity={cuentas} command="delegar_areas" id={cuenta.id} record={cuenta}
|
|
10
|
+
* label="Delegar áreas" ask={["areas"]} />
|
|
11
|
+
* ask={[{ name: "motivo", label: "Motivo", widget: "textarea" }]}
|
|
12
|
+
*
|
|
13
|
+
* Context: a Command that needs input could not live among a record's actions, so a screen drew
|
|
14
|
+
* its fields in the record's body with a button of their own. What the dialog shows is the
|
|
15
|
+
* screen's: the backend adds nothing for it. A field named by the entity reads as the record's
|
|
16
|
+
* field of that name — its label, its choices in their words, its control —; a control of the
|
|
17
|
+
* application's goes in with `as`, never a widget named in a string (`widget` takes only the
|
|
18
|
+
* framework's own).
|
|
19
|
+
*/
|
|
20
|
+
export type AskField = string | {
|
|
21
|
+
name: string;
|
|
22
|
+
label: string;
|
|
23
|
+
/** The type of its value as the model writes it — `text` (the default), `number`, `date`,
|
|
24
|
+
* `boolean`, `text[]`. */
|
|
25
|
+
type?: string;
|
|
26
|
+
/** The values it takes, each with its word: a select, or checks for a `text[]`. */
|
|
27
|
+
choices?: readonly {
|
|
28
|
+
value: unknown;
|
|
29
|
+
label: string;
|
|
30
|
+
}[];
|
|
31
|
+
/** One of the framework's own widgets: `textarea`, several lines of prose. */
|
|
32
|
+
widget?: "textarea";
|
|
33
|
+
/** The application's own control. */
|
|
34
|
+
as?: (control: FieldControl) => ReactNode;
|
|
35
|
+
};
|
|
36
|
+
/** A field ready to draw: its name, its label, its control. */
|
|
37
|
+
export type AskedField = {
|
|
38
|
+
name: string;
|
|
39
|
+
label: string;
|
|
40
|
+
/** It draws its own label — a yes/no, a list of checks —: not wrapped in a `Field`. */
|
|
41
|
+
labelled: boolean;
|
|
42
|
+
draw: (control: FieldControl) => ReactNode;
|
|
43
|
+
};
|
|
44
|
+
/** What a form of asked fields needs to be drawn and filled. */
|
|
45
|
+
export type AskForm = {
|
|
46
|
+
fields: readonly AskedField[];
|
|
47
|
+
initial: Readonly<Record<string, unknown>>;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* The asked fields, drawn from the entity's model, and what they start with: the record's own
|
|
51
|
+
* values. Its key is never asked — the action already knows whose record it is.
|
|
52
|
+
*/
|
|
53
|
+
export declare function askFormOf(fields: readonly AskField[], options: {
|
|
54
|
+
meta: Meta | null | undefined;
|
|
55
|
+
locale?: string | undefined;
|
|
56
|
+
record?: AnyRecord | undefined;
|
|
57
|
+
/** The declared entity a relation points at, to choose it with its picker. */
|
|
58
|
+
entityFor?: (target: string) => Entity | undefined;
|
|
59
|
+
}): AskForm;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { choicesOf } from "@sincpro/criteria";
|
|
4
|
+
import { fieldMetaOf, viewOf } from "../../core/present.js";
|
|
5
|
+
import { relationFieldOf } from "../../core/relation.js";
|
|
6
|
+
import { controlFor, RelationPicker, } from "./control.js";
|
|
7
|
+
/** Whether a field's control names itself: a checkbox and a list of checks carry their label. */
|
|
8
|
+
function labels(type, choices) {
|
|
9
|
+
return type === "boolean" || (type.endsWith("[]") && choices.length > 0);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The asked fields, drawn from the entity's model, and what they start with: the record's own
|
|
13
|
+
* values. Its key is never asked — the action already knows whose record it is.
|
|
14
|
+
*/
|
|
15
|
+
export function askFormOf(fields, options) {
|
|
16
|
+
const { meta, locale, record } = options;
|
|
17
|
+
const key = meta?.get_id || meta?.identity || "id";
|
|
18
|
+
const asked = [];
|
|
19
|
+
const initial = {};
|
|
20
|
+
for (const one of fields) {
|
|
21
|
+
if (typeof one !== "string") {
|
|
22
|
+
const choices = [...(one.choices ?? [])];
|
|
23
|
+
const type = one.type ?? "text";
|
|
24
|
+
asked.push({
|
|
25
|
+
name: one.name,
|
|
26
|
+
label: one.label,
|
|
27
|
+
labelled: one.as === undefined && labels(type, choices),
|
|
28
|
+
draw: (control) => one.as?.(control) ?? controlFor(control, type, false, choices, one.widget),
|
|
29
|
+
});
|
|
30
|
+
if (record !== undefined && record[one.name] !== undefined)
|
|
31
|
+
initial[one.name] = record[one.name];
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (one === key || one === "id")
|
|
35
|
+
continue;
|
|
36
|
+
const view = viewOf(meta, one, locale);
|
|
37
|
+
const field = fieldMetaOf(meta, one);
|
|
38
|
+
const relation = relationFieldOf(meta, one);
|
|
39
|
+
const target = relation === undefined || relation.many
|
|
40
|
+
? undefined
|
|
41
|
+
: options.entityFor?.(relation.target);
|
|
42
|
+
// A many2one is chosen by its key, with the picker of the entity it points at.
|
|
43
|
+
const name = target === undefined || relation === undefined ? one : relation.key;
|
|
44
|
+
const choices = choicesOf(meta, one, locale);
|
|
45
|
+
asked.push({
|
|
46
|
+
name,
|
|
47
|
+
label: view.label,
|
|
48
|
+
labelled: target === undefined && labels(view.type, choices),
|
|
49
|
+
draw: target === undefined
|
|
50
|
+
? (control) => controlFor(control, view.type, field?.exact === true, choices, field?.widget)
|
|
51
|
+
: (control) => (_jsx(RelationPicker, { target: target, value: control.value === null || control.value === undefined
|
|
52
|
+
? ""
|
|
53
|
+
: String(control.value), onChange: (id) => control.set(id), label: control.label, onClear: () => control.set(null) })),
|
|
54
|
+
});
|
|
55
|
+
if (record !== undefined && record[name] !== undefined)
|
|
56
|
+
initial[name] = record[name];
|
|
57
|
+
}
|
|
58
|
+
return { fields: asked, initial };
|
|
59
|
+
}
|
|
@@ -13,8 +13,8 @@ export type FieldControl = {
|
|
|
13
13
|
standalone?: boolean;
|
|
14
14
|
};
|
|
15
15
|
/**
|
|
16
|
-
* The control a field's TYPE asks for — a choice,
|
|
17
|
-
* list of words, a text — or the one its `widget` names when the model names one of the
|
|
16
|
+
* The control a field's TYPE asks for — a choice, several of a choice (checks), a number, a
|
|
17
|
+
* date, a date and time, a yes/no, a list of words, a text — or the one its `widget` names when the model names one of the
|
|
18
18
|
* framework's own: `textarea`, several lines of prose.
|
|
19
19
|
* Shared by a record's field (`RecordField`) and a line's cell and dialog (`RecordLinesEditor`):
|
|
20
20
|
* one rule for what a value is edited with.
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { dayOf, instantOf, timeZoneNow, wallTimeOf, } from "@sincpro/client-framework";
|
|
4
4
|
import { EntityPicker } from "./EntityPicker.js";
|
|
5
|
-
import { Checkbox, DatePicker, DateTimePicker, NumberInput, Select, TagsField, TextArea, TextInput, } from "@sincpro/web-ui";
|
|
5
|
+
import { Checkbox, CheckList, DatePicker, DateTimePicker, NumberInput, Select, TagsField, TextArea, TextInput, } from "@sincpro/web-ui";
|
|
6
6
|
/**
|
|
7
|
-
* The control a field's TYPE asks for — a choice,
|
|
8
|
-
* list of words, a text — or the one its `widget` names when the model names one of the
|
|
7
|
+
* The control a field's TYPE asks for — a choice, several of a choice (checks), a number, a
|
|
8
|
+
* date, a date and time, a yes/no, a list of words, a text — or the one its `widget` names when the model names one of the
|
|
9
9
|
* framework's own: `textarea`, several lines of prose.
|
|
10
10
|
* Shared by a record's field (`RecordField`) and a line's cell and dialog (`RecordLinesEditor`):
|
|
11
11
|
* one rule for what a value is edited with.
|
|
@@ -19,6 +19,10 @@ import { Checkbox, DatePicker, DateTimePicker, NumberInput, Select, TagsField, T
|
|
|
19
19
|
export function controlFor(control, type, exact, choices, widget) {
|
|
20
20
|
const { value, set } = control;
|
|
21
21
|
const named = control.standalone === true ? { "aria-label": control.label } : {};
|
|
22
|
+
// Several of the values at once — a list whose values are a choice: each one a check, the
|
|
23
|
+
// list's label above them.
|
|
24
|
+
if (choices.length > 0 && type.endsWith("[]"))
|
|
25
|
+
return (_jsx(CheckList, { label: control.label, items: choices.map((one) => ({ value: String(one.value), label: one.label })), value: Array.isArray(value) ? value.map(String) : [], onChange: set }));
|
|
22
26
|
if (choices.length > 0)
|
|
23
27
|
return (_jsx(Select, { value: value === null || value === undefined ? "" : String(value), options: choices.map((one) => ({ value: String(one.value), label: one.label })), onChange: set, ...named }));
|
|
24
28
|
switch (type) {
|
|
@@ -47,7 +47,7 @@ export declare function RecordField<T extends Record<string, unknown>>({ record,
|
|
|
47
47
|
/** A one2many of a declared entity, the screen's way: anything `EntityList` takes — its
|
|
48
48
|
* cells, row actions, commands, faces of its own. What it passes wins over the defaults. */
|
|
49
49
|
list?: Omit<EntityListProps<AnyRecord>, "listing" | "embedded">;
|
|
50
|
-
}): import("react").JSX.Element | null;
|
|
50
|
+
}): string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | import("react").JSX.Element | null | undefined;
|
|
51
51
|
/**
|
|
52
52
|
* The record's «save / discard», for `<Record dirty={…}>`: present only while something changed,
|
|
53
53
|
* off while saving, and off with the reason while a required field is empty.
|
package/dist/web/record/edit.js
CHANGED
|
@@ -181,9 +181,17 @@ export function RecordField({ record, name, as, bare = false, lines: look, list:
|
|
|
181
181
|
},
|
|
182
182
|
}) }));
|
|
183
183
|
}
|
|
184
|
+
// A list of checks names itself, as a checkbox does: inside a `Field` it would read twice.
|
|
185
|
+
const choices = choicesOf(place.meta, place.name, locale);
|
|
186
|
+
if (as === undefined &&
|
|
187
|
+
!state.readonly &&
|
|
188
|
+
view.type.endsWith("[]") &&
|
|
189
|
+
choices.length > 0 &&
|
|
190
|
+
relation === undefined)
|
|
191
|
+
return controlFor(control, view.type, false, choices, field?.widget);
|
|
184
192
|
if (view.type === "boolean" && as === undefined)
|
|
185
193
|
return (_jsx(Checkbox, { checked: value === true, onChange: control.set, label: view.label, disabled: state.readonly }));
|
|
186
|
-
return (_jsx(Field, { label: view.label, required: state.required && !state.readonly, ...(view.help === undefined ? {} : { hint: view.help }), ...(error === undefined ? {} : { error }), children: as !== undefined ? (as(control)) : relation !== undefined && !relation.many && target !== undefined ? (manyToOne()) : state.readonly ? (_jsx(ReadValue, { value: textOf(meta, name, value, locale) ?? "—" })) : (controlFor(control, view.type, field?.exact === true,
|
|
194
|
+
return (_jsx(Field, { label: view.label, required: state.required && !state.readonly, ...(view.help === undefined ? {} : { hint: view.help }), ...(error === undefined ? {} : { error }), children: as !== undefined ? (as(control)) : relation !== undefined && !relation.many && target !== undefined ? (manyToOne()) : state.readonly ? (_jsx(ReadValue, { value: textOf(meta, name, value, locale) ?? "—" })) : (controlFor(control, view.type, field?.exact === true, choices, field?.widget)) }));
|
|
187
195
|
}
|
|
188
196
|
/**
|
|
189
197
|
* The record's «save / discard», for `<Record dirty={…}>`: present only while something changed,
|
|
@@ -18,8 +18,10 @@ import { type ComponentType } from "react";
|
|
|
18
18
|
* (`entity.newRef(values)`), which `useRecord(entity, resource)` fills with the model's defaults
|
|
19
19
|
* and what the reference carries.
|
|
20
20
|
*
|
|
21
|
-
* ⌘K asks the server with `matching` — 8 records
|
|
22
|
-
*
|
|
21
|
+
* ⌘K asks the server with `matching` — 8 records — the same question a many2one asks. Each hit
|
|
22
|
+
* says what it is (`noun`, composer's) and, beside it, what tells it apart: the entity's own
|
|
23
|
+
* `option` look, else its summary's description or type — never its key, which tells a person
|
|
24
|
+
* nothing a UUID long («María Fernanda Apaza Quispe 01a1ebd4…»). The model definition is asked for once, on the first search, unless `meta`
|
|
23
25
|
* is handed over. A list whose route answers a SCOPE by its params (forge's `/projects`
|
|
24
26
|
* without `tenant_id` is the projects with NO tenant) is searched in the one ⌘K should see:
|
|
25
27
|
* `search: { params }`.
|
|
@@ -35,6 +37,9 @@ export type EntityViewOptions = {
|
|
|
35
37
|
transport: Transport;
|
|
36
38
|
/** How it reads in the palette, a panel's frame and the breadcrumb. */
|
|
37
39
|
name: string;
|
|
40
|
+
/** What ONE of its records is called — «Colegiado» —, beside each record ⌘K finds, so two
|
|
41
|
+
* «María» of different kinds say which is which. Without it, the model's own name. */
|
|
42
|
+
noun?: string;
|
|
38
43
|
/** Its list. Without it, `EntityList` over the entity: search bar, pages, «Nuevo». */
|
|
39
44
|
list?: ComponentType<ViewProps>;
|
|
40
45
|
/** Its record. Without it, `EntityRecord`: the form the model describes. */
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { isEntityId, listRoute, NEW_PARAM, scopeNameOf, scopeOfRef, } from "@sincpro/client-framework";
|
|
4
|
-
import { matching } from "@sincpro/criteria";
|
|
3
|
+
import { isEntityId, listRoute, NEW_PARAM, processContext, scopeNameOf, scopeOfRef, } from "@sincpro/client-framework";
|
|
4
|
+
import { matching, nameOf } from "@sincpro/criteria";
|
|
5
5
|
import { usePhone, } from "@sincpro/web-composer";
|
|
6
6
|
import { lookupOf } from "../../core/lookup.js";
|
|
7
|
+
import { summaryOf } from "../../core/summary.js";
|
|
7
8
|
import { ListScopeProvider } from "../../react/scope.js";
|
|
8
9
|
import { useListing } from "../../react/useListing.js";
|
|
9
10
|
import { EntityList } from "../list/EntityList.js";
|
|
@@ -49,6 +50,11 @@ function recordOf(entity, title) {
|
|
|
49
50
|
return (_jsx(EntityRecord, { ...props, entity: entity, ...(title === undefined ? {} : { title }) }));
|
|
50
51
|
};
|
|
51
52
|
}
|
|
53
|
+
/** The language the screens speak now — the provider puts it in the process's context. */
|
|
54
|
+
function localeNow() {
|
|
55
|
+
const lang = processContext.get("lang");
|
|
56
|
+
return typeof lang === "string" && lang !== "" ? lang : undefined;
|
|
57
|
+
}
|
|
52
58
|
/**
|
|
53
59
|
* What a reference reads as before its view names it — a crumb whose view is not mounted, a
|
|
54
60
|
* record still loading: the list is the view's name (with its cut's, `entity.listRef`); a record
|
|
@@ -85,6 +91,12 @@ export function entityView(entity, options) {
|
|
|
85
91
|
return {
|
|
86
92
|
domain: entity.domain,
|
|
87
93
|
kind: entity.kind,
|
|
94
|
+
// Read when ⌘K draws a hit, so the model's own name is there once a search brought it.
|
|
95
|
+
get noun() {
|
|
96
|
+
if (options.noun !== undefined)
|
|
97
|
+
return options.noun;
|
|
98
|
+
return meta?.name === undefined ? undefined : nameOf(meta, localeNow());
|
|
99
|
+
},
|
|
88
100
|
title: (ref) => titleOf(ref, options.name),
|
|
89
101
|
goto: options.goto ?? true,
|
|
90
102
|
...(options.icon === undefined ? {} : { icon: options.icon }),
|
|
@@ -97,11 +109,19 @@ export function entityView(entity, options) {
|
|
|
97
109
|
if (meta?.search == null)
|
|
98
110
|
return [];
|
|
99
111
|
const page = await options.transport.list(route, matching(meta, query));
|
|
112
|
+
const known = meta;
|
|
113
|
+
const locale = localeNow();
|
|
100
114
|
// ⌘K writes text: of the entity's look of a choice, its name and its meta.
|
|
101
115
|
const look = presentationOf(entity).option;
|
|
102
|
-
return lookupOf(
|
|
116
|
+
return lookupOf(known, page.rows, entity.summary).map((one) => {
|
|
103
117
|
const own = look === undefined || one.record === undefined ? {} : look(one.record);
|
|
104
|
-
const
|
|
118
|
+
const summary = one.record === undefined
|
|
119
|
+
? undefined
|
|
120
|
+
: summaryOf(known, one.record, {
|
|
121
|
+
fields: entity.summary ?? {},
|
|
122
|
+
...(locale === undefined ? {} : { locale }),
|
|
123
|
+
});
|
|
124
|
+
const detail = own.meta ?? summary?.description ?? summary?.type ?? undefined;
|
|
105
125
|
return {
|
|
106
126
|
ref: entity.ref(one.id),
|
|
107
127
|
label: own.name ?? one.label,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sincpro/web-framework",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "The web client of sincpro_framework: entities, lists and records bound to the metadata the server publishes, drawn with @sincpro/web-ui and arranged with @sincpro/web-composer.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -75,8 +75,8 @@
|
|
|
75
75
|
"@sincpro/client-framework": "^2.2.0",
|
|
76
76
|
"@sincpro/criteria": "^2.2.2",
|
|
77
77
|
"@sincpro/criteria-react": "^2.1.0",
|
|
78
|
-
"@sincpro/web-composer": "^1.
|
|
79
|
-
"@sincpro/web-ui": "^2.
|
|
78
|
+
"@sincpro/web-composer": "^1.8.0",
|
|
79
|
+
"@sincpro/web-ui": "^2.4.0",
|
|
80
80
|
"@storybook/addon-a11y": "10.6.5",
|
|
81
81
|
"@storybook/addon-docs": "10.6.5",
|
|
82
82
|
"@storybook/addon-mcp": "10.6.5",
|