@sincpro/web-framework 3.5.0 → 3.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/dist/core/command.d.ts +16 -0
- package/dist/core/command.js +17 -0
- package/dist/core/copy.d.ts +16 -0
- package/dist/core/copy.js +26 -0
- package/dist/core/crumbs.d.ts +4 -0
- package/dist/core/crumbs.js +24 -0
- package/dist/core/history.d.ts +16 -4
- package/dist/core/history.js +20 -17
- package/dist/core/index.d.ts +4 -3
- package/dist/core/index.js +3 -2
- package/dist/core/list.d.ts +12 -0
- package/dist/core/list.js +14 -0
- package/dist/core/present.d.ts +12 -0
- package/dist/core/present.js +39 -0
- package/dist/react/index.d.ts +2 -0
- package/dist/react/index.js +2 -0
- package/dist/react/useBatchCommand.d.ts +50 -0
- package/dist/react/useBatchCommand.js +124 -0
- package/dist/react/useCommand.js +3 -4
- package/dist/react/useSelection.d.ts +37 -0
- package/dist/react/useSelection.js +40 -0
- package/dist/web/index.d.ts +7 -3
- package/dist/web/index.js +7 -3
- package/dist/web/list/BatchProgress.d.ts +16 -0
- package/dist/web/list/BatchProgress.js +40 -0
- package/dist/web/list/EntityList.d.ts +31 -8
- package/dist/web/list/EntityList.js +122 -39
- package/dist/web/list/EntitySearchBar.d.ts +9 -0
- package/dist/web/list/EntitySearchBar.js +15 -5
- package/dist/web/list/columns.d.ts +4 -1
- package/dist/web/list/columns.js +14 -6
- package/dist/web/list/dock.d.ts +19 -0
- package/dist/web/list/dock.js +20 -0
- package/dist/web/list/groups.d.ts +7 -1
- package/dist/web/list/groups.js +25 -5
- package/dist/web/list/pivot.d.ts +5 -1
- package/dist/web/list/pivot.js +28 -11
- package/dist/web/list/records.d.ts +100 -0
- package/dist/web/list/records.js +219 -0
- package/dist/web/list/search.d.ts +0 -17
- package/dist/web/list/search.js +33 -5
- package/dist/web/record/ActionButton.d.ts +25 -0
- package/dist/web/record/ActionButton.js +39 -18
- package/dist/web/record/CommandButton.d.ts +22 -2
- package/dist/web/record/CommandButton.js +43 -17
- package/dist/web/record/EntityTags.d.ts +5 -2
- package/dist/web/record/EntityTags.js +34 -12
- package/dist/web/record/RecordLifecycle.d.ts +28 -7
- package/dist/web/record/RecordLifecycle.js +63 -10
- package/dist/web/record/ServiceButton.d.ts +20 -2
- package/dist/web/record/ServiceButton.js +35 -27
- package/dist/web/record/dock.d.ts +31 -0
- package/dist/web/record/dock.js +14 -0
- package/dist/web/record/opening.d.ts +6 -2
- package/dist/web/record/record.d.ts +14 -3
- package/dist/web/record/record.js +39 -6
- package/dist/web/workspace/SincproApp.js +13 -2
- package/dist/web/workspace/composer.d.ts +1 -1
- package/dist/web/workspace/composer.js +23 -25
- package/dist/web/workspace/record.d.ts +8 -3
- package/dist/web/workspace/record.js +20 -16
- package/package.json +9 -9
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx,
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { PICK_PARAM, QUERY_PARAM, TRAIL_PARAM, } from "@sincpro/client-framework";
|
|
4
4
|
import { nameOf } from "@sincpro/criteria";
|
|
5
5
|
import { RecordLink, useCrumbs, usePhone } from "@sincpro/web-composer";
|
|
6
6
|
import { frameworkCopy } from "../../core/copy.js";
|
|
7
|
+
import { ownCrumbs } from "../../core/crumbs.js";
|
|
7
8
|
import { explain } from "../../core/explain.js";
|
|
9
|
+
import { choosesMany, } from "../../core/list.js";
|
|
8
10
|
import { textOf, viewOf } from "../../core/present.js";
|
|
9
11
|
import { summaryFieldsOf } from "../../core/summary.js";
|
|
10
12
|
import { useFramework } from "../../react/context.js";
|
|
11
13
|
import { useGroups } from "../../react/useGroups.js";
|
|
12
14
|
import { usePivot } from "../../react/usePivot.js";
|
|
15
|
+
import { useSelection } from "../../react/useSelection.js";
|
|
13
16
|
import { columnsOf } from "./columns.js";
|
|
17
|
+
import { actionsOf } from "./dock.js";
|
|
14
18
|
import { EntitySearchBar } from "./EntitySearchBar.js";
|
|
15
19
|
import { pilesOf } from "./groups.js";
|
|
16
20
|
import { OpenInMenu, openOptions, targetsFor } from "./openIn.js";
|
|
@@ -18,7 +22,7 @@ import { pivotOf } from "./pivot.js";
|
|
|
18
22
|
import { over, presentationOf } from "./presentation.js";
|
|
19
23
|
import { RESTORE, useRowCommands, } from "./rowCommands.js";
|
|
20
24
|
import { Button, Callout, List, Pagination, pathKey, RecordCard, SearchField, Tag, } from "@sincpro/web-ui";
|
|
21
|
-
import { RotateCcw } from "lucide-react";
|
|
25
|
+
import { Plus, RotateCcw } from "lucide-react";
|
|
22
26
|
import { useEffect, useId, useMemo, useRef, useState } from "react";
|
|
23
27
|
/** What `useCrumbs` reads when the list is not in a workspace: no trail, and nothing to follow. */
|
|
24
28
|
const NO_TRAIL = [];
|
|
@@ -33,7 +37,7 @@ const TRAILS = 50;
|
|
|
33
37
|
const NO_COMMANDS = [];
|
|
34
38
|
/** What a list offers when nobody said: every face that needs no configuration. */
|
|
35
39
|
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, facets: askedFacets, groupable: askedGroupable, selectable = false, selectionActions, embedded = false, create = true, commands = NO_COMMANDS, rowActions: askedRowActions, faces, }) {
|
|
40
|
+
export function EntityList({ listing, api, columns: askedColumns, cells, yesNo, 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, selection: held, selectionActions, embedded = false, create = true, commands = NO_COMMANDS, rowActions: askedRowActions, faces, }) {
|
|
37
41
|
// A named list (`defineList`) brings its own columns, filters, faces and words; what the
|
|
38
42
|
// screen passes wins.
|
|
39
43
|
const definition = listing.definition;
|
|
@@ -67,6 +71,14 @@ export function EntityList({ listing, api, columns: askedColumns, cells, views:
|
|
|
67
71
|
}, []);
|
|
68
72
|
// Opened by `api.pick` (`entity.chooserRef()`): a row ANSWERS whoever asked, it does not open.
|
|
69
73
|
const choosing = api?.self.params?.[PICK_PARAM] !== undefined;
|
|
74
|
+
// Asked for SEVERAL (`CHOOSE_MANY`, a many2many's «Buscar más…»): a row press ticks it, and
|
|
75
|
+
// «Agregar (N)» answers what was chosen — the keys, or every record the list matches.
|
|
76
|
+
const choosingMany = choosing && choosesMany(api?.choosing?.question);
|
|
77
|
+
const own = useSelection(listing);
|
|
78
|
+
const chosen = held ?? own;
|
|
79
|
+
// Actions for the chosen rows make the rows choosable: given without `selectable` they were
|
|
80
|
+
// silently never shown — no ticks, nothing to act on.
|
|
81
|
+
const ticking = selectable || choosingMany || selectionActions !== undefined;
|
|
70
82
|
// The record opened from a row knows the page it came from: «3 / 64» and its neighbours.
|
|
71
83
|
const { trails, dateStyle } = useFramework();
|
|
72
84
|
const trailKey = `trail:${useId()}`;
|
|
@@ -114,9 +126,11 @@ export function EntityList({ listing, api, columns: askedColumns, cells, views:
|
|
|
114
126
|
const opening = onOpen ??
|
|
115
127
|
(api === undefined
|
|
116
128
|
? undefined
|
|
117
|
-
:
|
|
118
|
-
? (row) =>
|
|
119
|
-
:
|
|
129
|
+
: choosingMany
|
|
130
|
+
? (row) => chosen.toggle(idOf(row))
|
|
131
|
+
: choosing
|
|
132
|
+
? (row) => api.answer(listing.entity.ref(idOf(row)))
|
|
133
|
+
: openWithTrail);
|
|
120
134
|
const creating = create &&
|
|
121
135
|
api !== undefined &&
|
|
122
136
|
!choosing &&
|
|
@@ -124,9 +138,30 @@ export function EntityList({ listing, api, columns: askedColumns, cells, views:
|
|
|
124
138
|
listing.entity.create !== undefined
|
|
125
139
|
? () => api.open(listing.entity.newRef())
|
|
126
140
|
: undefined;
|
|
141
|
+
// What the list starts, as data: «Nuevo» — the primary — and the screen's, drawn by the view
|
|
142
|
+
// style (`List.Dock`). Actions drawn by hand stay in the bar, with «Nuevo» beside them.
|
|
143
|
+
const started = actionsOf(actions);
|
|
144
|
+
const startDock = started.drawn !== null
|
|
145
|
+
? []
|
|
146
|
+
: [
|
|
147
|
+
...(creating === undefined
|
|
148
|
+
? []
|
|
149
|
+
: [
|
|
150
|
+
{
|
|
151
|
+
id: "create",
|
|
152
|
+
label: frameworkCopy().record.create,
|
|
153
|
+
icon: Plus,
|
|
154
|
+
primary: true,
|
|
155
|
+
onSelect: creating,
|
|
156
|
+
},
|
|
157
|
+
]),
|
|
158
|
+
...started.dock,
|
|
159
|
+
];
|
|
127
160
|
// A press opens the page — the composer's one predictable gesture. Every other place the
|
|
128
|
-
// record may open is
|
|
129
|
-
// (`onPeek` with `rowClick="open"`: the press stays «open»)
|
|
161
|
+
// record may open is among the row's ways in, web-ui's (`openTargets` + `onOpenIn`, web-ui
|
|
162
|
+
// 2.10): 👁 for a look (`onPeek` with `rowClick="open"`: the press stays «open»), and «Abrir
|
|
163
|
+
// en…» with the rest — in ONE place at the row's end, a pill in the modern style. Drawn beside
|
|
164
|
+
// the name as well, a row offered three unaligned sets. A chooser only chooses.
|
|
130
165
|
const openingIn = onOpenIn ??
|
|
131
166
|
(api === undefined
|
|
132
167
|
? undefined
|
|
@@ -139,49 +174,72 @@ export function EntityList({ listing, api, columns: askedColumns, cells, views:
|
|
|
139
174
|
(targets.includes("peek") && openingIn !== undefined
|
|
140
175
|
? (row) => openingIn(row, "peek")
|
|
141
176
|
: undefined);
|
|
142
|
-
// The cells are memoised (below)
|
|
143
|
-
// `onOpenIn` is always the current one without redrawing
|
|
177
|
+
// The cells are memoised (below) and web-ui holds the row ways: both reach the opener through
|
|
178
|
+
// a ref, so a screen's inline `onOpenIn` is always the current one without redrawing.
|
|
144
179
|
const openingNow = useRef(openingIn);
|
|
145
180
|
openingNow.current = openingIn;
|
|
181
|
+
// The rows face (not the table) takes «Abrir en…» as its row's actions.
|
|
146
182
|
const openInOf = (row) => elsewhere.length === 0 || openingIn === undefined ? null : (_jsx(OpenInMenu, { targets: elsewhere, name: idOf(row), onOpen: (to) => openingNow.current?.(row, to) }));
|
|
147
|
-
// The column that names a row carries its link
|
|
148
|
-
//
|
|
183
|
+
// The column that names a row carries its link: the identity, or — in a list that does not
|
|
184
|
+
// show it (a relation inside a record) — the record's name, else the first. The link is only
|
|
185
|
+
// the name (`compact`): the places it opens in are the row's ways.
|
|
149
186
|
const named = columns === undefined || columns.includes(identity)
|
|
150
187
|
? identity
|
|
151
188
|
: meta?.display && columns.includes(meta.display)
|
|
152
189
|
? meta.display
|
|
153
190
|
: (columns[0] ?? identity);
|
|
154
191
|
const rowName = (row) => named === identity ? idOf(row) : (textOf(meta, named, row[named], locale) ?? idOf(row));
|
|
155
|
-
const linked = choosing || cells?.[named] !== undefined ||
|
|
192
|
+
const linked = choosing || cells?.[named] !== undefined || api === undefined
|
|
156
193
|
? cells
|
|
157
194
|
: {
|
|
158
195
|
...cells,
|
|
159
|
-
[named]: (row) => (
|
|
196
|
+
[named]: (row) => (_jsx(RecordLink, { api: api, resource: refOf(row), compact: true, children: rowName(row) })),
|
|
160
197
|
};
|
|
161
198
|
// `useCrumbs`, not `api.crumbs()`: the crumb must follow a name given later (`setTitle`).
|
|
162
199
|
// Without a workspace it reads a trail that never changes — a hook cannot be skipped.
|
|
163
200
|
const following = useCrumbs(api ?? NO_WORKSPACE);
|
|
164
201
|
usePhone(api ?? NO_WORKSPACE); // where a row opens follows the mode (`targetsFor`)
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
202
|
+
// The workspace's crumbs say each view's whole name (its tab's); in the trail a crumb says only
|
|
203
|
+
// what is its own — «Pagos», not «Pagos · María Fernanda» under «María Fernanda».
|
|
204
|
+
const trail = crumbs ?? (embedded || api === undefined ? undefined : ownCrumbs(following));
|
|
205
|
+
// The workspace hears what is chosen: the keys, or — «all that match» — the ones on screen.
|
|
206
|
+
const published = (chosen.selection.by === "keys"
|
|
207
|
+
? chosen.selection.keys
|
|
208
|
+
: listing.rows.map((row) => idOf(row)).filter((id) => chosen.isChosen(id))).join("\u0000");
|
|
209
|
+
const heard = useRef(published);
|
|
210
|
+
useEffect(() => {
|
|
211
|
+
if (!ticking || heard.current === published)
|
|
212
|
+
return;
|
|
213
|
+
heard.current = published;
|
|
214
|
+
api?.select(published === "" ? [] : published.split("\u0000").map((id) => listing.entity.ref(id)));
|
|
215
|
+
}, [api, ticking, published, listing.entity]);
|
|
216
|
+
// «Elegir los 187 que coinciden» only past the page, and only with the server's exact count.
|
|
217
|
+
const total = listing.count?.exact === true ? listing.count.value : null;
|
|
218
|
+
// What is done to the chosen rows: answering whoever asked for several, else the screen's.
|
|
219
|
+
const onChosen = choosingMany
|
|
220
|
+
? [
|
|
221
|
+
{
|
|
222
|
+
id: "add-chosen",
|
|
223
|
+
label: frameworkCopy().picker.addChosen(chosen.size),
|
|
224
|
+
primary: true,
|
|
225
|
+
onSelect: () => api?.answer(chosen.selection),
|
|
181
226
|
},
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
227
|
+
]
|
|
228
|
+
: typeof selectionActions === "function"
|
|
229
|
+
? selectionActions(chosen)
|
|
230
|
+
: selectionActions;
|
|
231
|
+
// As data they go to the dock, where the view style draws them; by hand, in the bar.
|
|
232
|
+
const forChosen = actionsOf(onChosen);
|
|
233
|
+
const selection = ticking
|
|
234
|
+
? {
|
|
235
|
+
has: chosen.isChosen,
|
|
236
|
+
toggle: chosen.toggle,
|
|
237
|
+
count: chosen.size ?? 0,
|
|
238
|
+
clear: chosen.clear,
|
|
239
|
+
...(total !== null && total > listing.rows.length
|
|
240
|
+
? { matching: { total, onSelect: chosen.chooseAllMatching } }
|
|
241
|
+
: {}),
|
|
242
|
+
...(forChosen.drawn === null ? {} : { actions: forChosen.drawn }),
|
|
185
243
|
}
|
|
186
244
|
: undefined;
|
|
187
245
|
// Rebuilt only when what it reads changes: a new set of columns on every render redraws
|
|
@@ -192,9 +250,20 @@ export function EntityList({ listing, api, columns: askedColumns, cells, views:
|
|
|
192
250
|
locale,
|
|
193
251
|
...(linked ? { cells: linked } : {}),
|
|
194
252
|
...(look.tones === undefined ? {} : { tones: look.tones }),
|
|
253
|
+
...(yesNo === undefined ? {} : { yesNo }),
|
|
195
254
|
}),
|
|
196
255
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
197
|
-
[
|
|
256
|
+
[
|
|
257
|
+
meta,
|
|
258
|
+
locale,
|
|
259
|
+
names,
|
|
260
|
+
cells,
|
|
261
|
+
yesNo,
|
|
262
|
+
api,
|
|
263
|
+
elsewhere.join(),
|
|
264
|
+
openingIn === undefined,
|
|
265
|
+
dateStyle,
|
|
266
|
+
]);
|
|
198
267
|
// A state the application gave colours to is the row's tag — and not again among its facts.
|
|
199
268
|
const stateField = summaryFieldsOf(meta, {}, listing.entity.summary).state;
|
|
200
269
|
const stateTones = stateField === undefined ? undefined : look.tones?.[stateField];
|
|
@@ -284,7 +353,15 @@ export function EntityList({ listing, api, columns: askedColumns, cells, views:
|
|
|
284
353
|
// each says what its next «more» brings (1.5).
|
|
285
354
|
const groups = useGroups(listing, sums === undefined ? {} : { sums: sums || [] });
|
|
286
355
|
const grouped = groups.levels.length > 0;
|
|
287
|
-
|
|
356
|
+
// A table and a sheet say a group's sums under their columns (web-ui 2.9): beside the group's
|
|
357
|
+
// name, only what no column shown adds up.
|
|
358
|
+
const columnar = present === "table" || present === "sheet";
|
|
359
|
+
const underColumns = new Set(columnar
|
|
360
|
+
? shown.flatMap((column) => column.aggregate === undefined || column.defaultHidden || column.field === undefined
|
|
361
|
+
? []
|
|
362
|
+
: [column.field])
|
|
363
|
+
: []);
|
|
364
|
+
const { piles, bucketAt } = pilesOf(groups.buckets, groups.levels, meta, locale, groups.rowsOf, groups.brings, underColumns);
|
|
288
365
|
const [opened, setOpened] = useState(() => new Set());
|
|
289
366
|
useEffect(() => setOpened(new Set()), [groups.buckets]);
|
|
290
367
|
const collapsed = [...bucketAt.keys()].filter((key) => !opened.has(key));
|
|
@@ -360,8 +437,9 @@ export function EntityList({ listing, api, columns: askedColumns, cells, views:
|
|
|
360
437
|
: 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
438
|
const pageTotals = totalled && partial && present === "table";
|
|
362
439
|
// Written only when it says something: web-ui draws an embedded list's bar for any slot
|
|
363
|
-
// written, an empty one too.
|
|
364
|
-
|
|
440
|
+
// written, an empty one too. Its parts side by side and apart: the slot does not space them,
|
|
441
|
+
// and «Totales de esta página» read glued to «1–50 / 112».
|
|
442
|
+
const paging = !pageTotals && dropped.length === 0 && through === null ? null : (_jsxs("span", { className: "flex items-center gap-3", 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] }));
|
|
365
443
|
return (_jsxs(List, { items: listing.rows, keyOf: idOf, embedded: embedded, present: present, onPresentChange: setPresent, ...grouping,
|
|
366
444
|
// The whole order, as web-ui 1.7 shows and sets it: ⇧-click on a header adds a field,
|
|
367
445
|
// the sort menu reorders them — the same list the criteria builder writes.
|
|
@@ -382,12 +460,17 @@ export function EntityList({ listing, api, columns: askedColumns, cells, views:
|
|
|
382
460
|
}, filtered: listing.selection !== undefined || listing.text !== "", empty: {
|
|
383
461
|
sentence: empty ?? copy.empty,
|
|
384
462
|
whenFiltered: { sentence: copy.emptyFiltered },
|
|
385
|
-
}, ...(selection === undefined ? {} : { selection }), ...(opening === undefined ? {} : { onOpen: opening }), ...(peeking === undefined ? {} : { onPeek: peeking, rowClick: "open" }),
|
|
463
|
+
}, ...(selection === undefined ? {} : { selection }), ...(opening === undefined ? {} : { onOpen: opening }), ...(peeking === undefined ? {} : { onPeek: peeking, rowClick: "open" }), ...(elsewhere.length === 0 || openingIn === undefined
|
|
464
|
+
? {}
|
|
465
|
+
: {
|
|
466
|
+
openTargets: elsewhere,
|
|
467
|
+
onOpenIn: (row, to) => openingNow.current?.(row, to),
|
|
468
|
+
}), 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) => {
|
|
386
469
|
setDraft(next);
|
|
387
470
|
// Emptied (or cleared with ×): the whole set again, at once.
|
|
388
471
|
if (next === "" && listing.text !== "")
|
|
389
472
|
listing.search("", { now: true });
|
|
390
|
-
}, onSubmit: (text) => listing.search(text, { now: true }), placeholder: copy.search, "aria-label": copy.search }) })) : null,
|
|
473
|
+
}, onSubmit: (text) => listing.search(text, { now: true }), placeholder: copy.search, "aria-label": copy.search }) })) : null, started.drawn === null ? null : (_jsxs(List.Actions, { children: [started.drawn, creating === undefined ? null : (_jsx(Button, { role: "primary", size: "sm", onClick: creating, children: frameworkCopy().record.create }))] })), startDock.length === 0 && forChosen.dock.length === 0 ? null : (_jsx(List.Dock, { ...(startDock.length === 0 ? {} : { actions: startDock }), ...(forChosen.dock.length === 0 ? {} : { selection: forChosen.dock }) })), 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) => {
|
|
391
474
|
const value = row[column.id];
|
|
392
475
|
return value === null || value === undefined
|
|
393
476
|
? null
|
|
@@ -15,6 +15,15 @@ import type { Listing } from "../../react/useListing.js";
|
|
|
15
15
|
* - «search by name»: facets are the fields the screen names (`facets`), else the ones the
|
|
16
16
|
* entity's search template names — never every text field;
|
|
17
17
|
* - a typed question («total > 5000») is checked against each field's operators;
|
|
18
|
+
* - a relation unfolds into its RECORDS that match what was typed — «andres» → the customers
|
|
19
|
+
* —, chosen by key and read by name («Cliente: Andrés Pérez»), and an enum into its words
|
|
20
|
+
* («Estado: Pagada», sent as `paid`): the related entity's literal search
|
|
21
|
+
* (`useSearchRecords`), unless the application put its own in a web-ui `SearchProvider`;
|
|
22
|
+
* inside a workspace, «Buscar más…» under them opens the entity's list to choose
|
|
23
|
+
* (`useRecordsBrowser`) — the bar's, never the builder's: the builder is a modal dialog, and
|
|
24
|
+
* what opens outside one cannot be used;
|
|
25
|
+
* - the builder walks relations — «Cliente › País» — through the models along the path
|
|
26
|
+
* (`useLoadModel`), and picks the related records themselves;
|
|
18
27
|
* - a named filter is one click; the builder writes what nobody foresaw (all/any/not);
|
|
19
28
|
* - everything put becomes ONE `selection` the SERVER answers (`listing.filter`) — web-ui
|
|
20
29
|
* writes it in criteria's own shape, a filter through a relation included;
|
|
@@ -3,8 +3,9 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
3
3
|
import { matching } from "@sincpro/criteria";
|
|
4
4
|
import { frameworkCopy } from "../../core/copy.js";
|
|
5
5
|
import { groupableOf } from "./groups.js";
|
|
6
|
+
import { useLoadModel, useRecordsBrowser, useSearchRecords, } from "./records.js";
|
|
6
7
|
import { facetsOf, modelOf } from "./search.js";
|
|
7
|
-
import { CriteriaBuilder, describeFilter, Dialog, fillCopy, filterCriteria, GroupingLevels, hasNamed, SearchBar, selectionOf, toggleNamed, useGroupingControl, useUiCopy, } from "@sincpro/web-ui";
|
|
8
|
+
import { CriteriaBuilder, describeFilter, Dialog, fillCopy, filterCriteria, GroupingLevels, hasNamed, SearchBar, selectionOf, toggleNamed, useGroupingControl, useSearchSettings, useUiCopy, } from "@sincpro/web-ui";
|
|
8
9
|
import { useEffect, useMemo, useRef, useState } from "react";
|
|
9
10
|
/** No grouping: one constant, so the control is not handed a new array on every render. */
|
|
10
11
|
const NO_LEVELS = [];
|
|
@@ -25,6 +26,11 @@ export function EntitySearchBar({ listing, filters = [], groups, groupable: only
|
|
|
25
26
|
: undefined, [meta, locale, facets]);
|
|
26
27
|
const groupable = useMemo(() => groupableOf(meta, locale, only), [meta, locale, only]);
|
|
27
28
|
const ui = useUiCopy();
|
|
29
|
+
// The application's own search of records wins; the framework's is the default.
|
|
30
|
+
const framework = useSearchRecords();
|
|
31
|
+
const searchRecords = useSearchSettings().searchRecords ?? framework;
|
|
32
|
+
const browseRecords = useRecordsBrowser();
|
|
33
|
+
const loadModel = useLoadModel(meta);
|
|
28
34
|
const seeded = useRef(false);
|
|
29
35
|
useEffect(() => {
|
|
30
36
|
if (seeded.current || seed === undefined || seed === "" || meta?.search == null)
|
|
@@ -51,7 +57,7 @@ export function EntitySearchBar({ listing, filters = [], groups, groupable: only
|
|
|
51
57
|
};
|
|
52
58
|
// What the bar holds, as one selection: what the builder opens on.
|
|
53
59
|
const current = selectionOf(put);
|
|
54
|
-
return (_jsxs(_Fragment, { children: [_jsx(SearchBar, { facets: facets, model: asked ?? model, criteria: put, onCriteriaChange: place, placeholder: copy.searchBar, ...(filters.length === 0
|
|
60
|
+
return (_jsxs(_Fragment, { children: [_jsx(SearchBar, { facets: facets, model: asked ?? model, criteria: put, onCriteriaChange: place, placeholder: copy.searchBar, searchRecords: searchRecords, ...(browseRecords === null ? {} : { browseRecords }), ...(filters.length === 0
|
|
55
61
|
? {}
|
|
56
62
|
: {
|
|
57
63
|
filters: [
|
|
@@ -78,7 +84,7 @@ export function EntitySearchBar({ listing, filters = [], groups, groupable: only
|
|
|
78
84
|
? {}
|
|
79
85
|
: {
|
|
80
86
|
literal: (text) => matching(meta, text).selection ?? null,
|
|
81
|
-
}) }), building ? (_jsx(Dialog, { open: true, width: "lg", title: copy.builder, onClose: () => setBuilding(false), children: _jsx(CriteriaBuilder, { model: model, ...(current === undefined && listing.order.length === 0
|
|
87
|
+
}) }), building ? (_jsx(Dialog, { open: true, width: "lg", title: copy.builder, onClose: () => setBuilding(false), children: _jsx(CriteriaBuilder, { model: model, searchRecords: searchRecords, ...(loadModel === undefined ? {} : { loadModel }), ...(current === undefined && listing.order.length === 0
|
|
82
88
|
? {}
|
|
83
89
|
: {
|
|
84
90
|
initial: {
|
|
@@ -92,10 +98,14 @@ export function EntitySearchBar({ listing, filters = [], groups, groupable: only
|
|
|
92
98
|
})),
|
|
93
99
|
}),
|
|
94
100
|
},
|
|
95
|
-
}),
|
|
101
|
+
}),
|
|
102
|
+
// The chip reads as the builder says it — a chosen record by its name, never its key.
|
|
103
|
+
onApply: (built, said) => {
|
|
96
104
|
place(built?.selection === undefined
|
|
97
105
|
? []
|
|
98
|
-
: [
|
|
106
|
+
: [
|
|
107
|
+
filterCriteria(built.selection, said ?? describeFilter(built.selection, model)),
|
|
108
|
+
]);
|
|
99
109
|
listing.orderBy((built?.order ?? []).map((one) => ({
|
|
100
110
|
field: one.field,
|
|
101
111
|
...(one.descending === true ? { descending: true } : {}),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AnyRecord, Meta } from "@sincpro/criteria";
|
|
2
2
|
import type { ChoiceTones } from "./presentation.js";
|
|
3
|
-
import { type Aggregate, type DataColumn } from "@sincpro/web-ui";
|
|
3
|
+
import { type Aggregate, type DataColumn, type YesNoColumn } from "@sincpro/web-ui";
|
|
4
4
|
import type { ReactNode } from "react";
|
|
5
5
|
export type ColumnOptions<T> = {
|
|
6
6
|
locale?: string | undefined;
|
|
@@ -8,6 +8,9 @@ export type ColumnOptions<T> = {
|
|
|
8
8
|
cells?: Readonly<Partial<Record<string, (row: T) => ReactNode>>>;
|
|
9
9
|
/** The colour of each value of a choice (`presented(entity, { tones })`). */
|
|
10
10
|
tones?: ChoiceTones<T> | undefined;
|
|
11
|
+
/** How a yes/no column reads — web-ui's `yesNo`: `check` (the default here: ✓ and nothing),
|
|
12
|
+
* `icon`, `word` — or, with `onToggle`, a `checkbox` / `switch` that writes it from the list. */
|
|
13
|
+
yesNo?: Readonly<Partial<Record<string, YesNoColumn<T>>>> | undefined;
|
|
11
14
|
};
|
|
12
15
|
/** How the model adds a field up at a list's foot, as web-ui's `aggregate`. */
|
|
13
16
|
export declare function aggregateOf(meta: Meta | null | undefined, name: string): Aggregate | undefined;
|
package/dist/web/list/columns.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { frameworkCopy } from "../../core/copy.js";
|
|
4
3
|
import { totalOf } from "../../core/measure.js";
|
|
5
4
|
import { BOOKKEEPING, defaultFields, fieldMetaOf, sortKeyOf, textOf, valueAt, viewOf, } from "../../core/present.js";
|
|
6
5
|
import { relationFieldOf } from "../../core/relation.js";
|
|
7
6
|
import { useEntityFor } from "../../react/context.js";
|
|
8
7
|
import { useNameOf } from "../../react/useNameOf.js";
|
|
9
8
|
import { Tag } from "@sincpro/web-ui";
|
|
10
|
-
import { Check } from "lucide-react";
|
|
11
9
|
/**
|
|
12
10
|
* The columns of a table, from the model: name the fields, the rest follows.
|
|
13
11
|
*
|
|
@@ -58,6 +56,7 @@ function columnOf(meta, name, options, hidden) {
|
|
|
58
56
|
const whole = view.name === meta?.identity || view.numeric || money || DATES.has(view.type);
|
|
59
57
|
const tones = options.tones?.[name];
|
|
60
58
|
const choice = (field?.choices?.length ?? 0) > 0;
|
|
59
|
+
const boolean = view.type === "boolean";
|
|
61
60
|
const aggregate = aggregateOf(meta, name);
|
|
62
61
|
// The column IS a key of another record: `customer_id` beside its relation, or a key alone.
|
|
63
62
|
const relation = relationFieldOf(meta, name);
|
|
@@ -87,14 +86,23 @@ function columnOf(meta, name, options, hidden) {
|
|
|
87
86
|
const word = text(row);
|
|
88
87
|
return word === "" ? null : (_jsx(Tag, { tone: tones?.[String(raw(row))] ?? "neutral", children: word }));
|
|
89
88
|
}
|
|
90
|
-
:
|
|
91
|
-
? //
|
|
92
|
-
|
|
89
|
+
: boolean
|
|
90
|
+
? // Drawn by web-ui from the value (`yesNo`, below): no cell of its own.
|
|
91
|
+
undefined
|
|
93
92
|
: whole
|
|
94
93
|
? (row) => _jsx("span", { className: "whitespace-nowrap", children: text(row) })
|
|
95
94
|
: text),
|
|
96
|
-
text
|
|
95
|
+
// A yes/no reads by its look (web-ui's `YesNo`): with a `text` of its own the table would
|
|
96
|
+
// draw the words instead.
|
|
97
|
+
...(boolean ? {} : { text }),
|
|
97
98
|
numeric: view.numeric || money,
|
|
99
|
+
...(boolean
|
|
100
|
+
? {
|
|
101
|
+
// A yes is a check and a no is nothing by default: a column of «sí/no» is noise to
|
|
102
|
+
// scan. Every look still says «sí» / «no» to a screen reader.
|
|
103
|
+
yesNo: { look: "check", ...options.yesNo?.[name] },
|
|
104
|
+
}
|
|
105
|
+
: {}),
|
|
98
106
|
sortable: view.sortable,
|
|
99
107
|
...(view.name === meta?.identity ? { mono: true } : {}),
|
|
100
108
|
...(hidden ? { optional: true, defaultHidden: true } : {}),
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { DockAction } from "@sincpro/web-ui";
|
|
2
|
+
import { type ReactNode } from "react";
|
|
3
|
+
/**
|
|
4
|
+
* A screen's actions: as DATA — web-ui's `DockAction`s, which the application's view style
|
|
5
|
+
* draws (the bar's buttons in `traditional`, one pill floating at the bottom in `modern`) — or
|
|
6
|
+
* drawn by hand, a node that stays where it is put.
|
|
7
|
+
*
|
|
8
|
+
* actions={[{ id: "import", label: "Importar", icon: Upload, onSelect: importar }]}
|
|
9
|
+
* actions={<ImportarColegiados />} // its own dialog: drawn by hand, in the bar
|
|
10
|
+
*/
|
|
11
|
+
export type ScreenActions = readonly DockAction[] | ReactNode;
|
|
12
|
+
/**
|
|
13
|
+
* The actions split by who draws them: `dock`, the ones given as data, for the view style;
|
|
14
|
+
* `drawn`, a node drawn by hand, to put where it goes — `null` when there is none.
|
|
15
|
+
*/
|
|
16
|
+
export declare function actionsOf(actions: ScreenActions): {
|
|
17
|
+
dock: readonly DockAction[];
|
|
18
|
+
drawn: ReactNode;
|
|
19
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { isValidElement } from "react";
|
|
2
|
+
/** One action as data: an object with its id and its words, not an element. */
|
|
3
|
+
function isDockAction(one) {
|
|
4
|
+
return (typeof one === "object" &&
|
|
5
|
+
one !== null &&
|
|
6
|
+
!isValidElement(one) &&
|
|
7
|
+
"id" in one &&
|
|
8
|
+
"label" in one);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The actions split by who draws them: `dock`, the ones given as data, for the view style;
|
|
12
|
+
* `drawn`, a node drawn by hand, to put where it goes — `null` when there is none.
|
|
13
|
+
*/
|
|
14
|
+
export function actionsOf(actions) {
|
|
15
|
+
if (actions === undefined || actions === null || actions === false)
|
|
16
|
+
return { dock: [], drawn: null };
|
|
17
|
+
if (Array.isArray(actions) && actions.every(isDockAction))
|
|
18
|
+
return { dock: actions, drawn: null };
|
|
19
|
+
return { dock: [], drawn: actions };
|
|
20
|
+
}
|
|
@@ -17,10 +17,16 @@ export declare function groupableOf(meta: Meta | null, locale?: string, only?: r
|
|
|
17
17
|
/**
|
|
18
18
|
* The server's groups as piles, with the words a person reads, and each pile's group so that
|
|
19
19
|
* opening one reads its rows. Rows sit only on the deepest level, once read.
|
|
20
|
+
*
|
|
21
|
+
* What the server summed for a group is its `totals` — web-ui (2.9) says each figure under its
|
|
22
|
+
* column in a grouped table and a sheet, as Odoo's grouped list — and, in words beside the
|
|
23
|
+
* group's name (`detail`), what no column on screen says: a board's card has no columns.
|
|
20
24
|
*/
|
|
21
25
|
export declare function pilesOf<T extends AnyRecord>(buckets: readonly Bucket<T>[], levels: readonly GroupLevel[], meta: Meta | null, locale: string | undefined, rowsOf: (bucket: Bucket<T>) => readonly T[] | undefined,
|
|
22
26
|
/** What a group's next «more» brings (`Pile.more`); omitted, web-ui says nothing about it. */
|
|
23
|
-
brings?: (bucket: Bucket<T>) => number | false | undefined
|
|
27
|
+
brings?: (bucket: Bucket<T>) => number | false | undefined,
|
|
28
|
+
/** The figures a column on screen already says under itself: not said again in words. */
|
|
29
|
+
underColumns?: ReadonlySet<string>): {
|
|
24
30
|
piles: Pile<T>[];
|
|
25
31
|
bucketAt: ReadonlyMap<string, Bucket<T>>;
|
|
26
32
|
deepest: number;
|
package/dist/web/list/groups.js
CHANGED
|
@@ -42,13 +42,24 @@ export function groupableOf(meta, locale, only) {
|
|
|
42
42
|
...(field.type === "date" || field.type === "datetime" ? { grains: DATE_GRAINS } : {}),
|
|
43
43
|
}));
|
|
44
44
|
}
|
|
45
|
+
/** A summed figure as a number — the wire may carry an exact decimal as text («1204.50»). */
|
|
46
|
+
function figureOf(value) {
|
|
47
|
+
const figure = typeof value === "number" ? value : typeof value === "string" ? Number(value) : NaN;
|
|
48
|
+
return value === "" || !Number.isFinite(figure) ? undefined : figure;
|
|
49
|
+
}
|
|
45
50
|
/**
|
|
46
51
|
* The server's groups as piles, with the words a person reads, and each pile's group so that
|
|
47
52
|
* opening one reads its rows. Rows sit only on the deepest level, once read.
|
|
53
|
+
*
|
|
54
|
+
* What the server summed for a group is its `totals` — web-ui (2.9) says each figure under its
|
|
55
|
+
* column in a grouped table and a sheet, as Odoo's grouped list — and, in words beside the
|
|
56
|
+
* group's name (`detail`), what no column on screen says: a board's card has no columns.
|
|
48
57
|
*/
|
|
49
58
|
export function pilesOf(buckets, levels, meta, locale, rowsOf,
|
|
50
59
|
/** What a group's next «more» brings (`Pile.more`); omitted, web-ui says nothing about it. */
|
|
51
|
-
brings
|
|
60
|
+
brings,
|
|
61
|
+
/** The figures a column on screen already says under itself: not said again in words. */
|
|
62
|
+
underColumns = new Set()) {
|
|
52
63
|
const bucketAt = new Map();
|
|
53
64
|
const none = frameworkCopy().list.noValue;
|
|
54
65
|
const labelFor = (bucket, depth, key) => {
|
|
@@ -63,9 +74,18 @@ brings) {
|
|
|
63
74
|
}
|
|
64
75
|
return textOf(meta, bucket.field, bucket.value, locale) || key;
|
|
65
76
|
};
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
|
|
77
|
+
const summed = (bucket) => {
|
|
78
|
+
const measures = Object.entries(bucket.measures ?? {});
|
|
79
|
+
const totals = Object.fromEntries(measures.flatMap(([field, value]) => {
|
|
80
|
+
const figure = figureOf(value);
|
|
81
|
+
return figure === undefined ? [] : [[field, figure]];
|
|
82
|
+
}));
|
|
83
|
+
const inWords = measures.filter(([field]) => !underColumns.has(field));
|
|
84
|
+
const detail = detailOf(meta, Object.fromEntries(inWords), locale);
|
|
85
|
+
return {
|
|
86
|
+
...(Object.keys(totals).length === 0 ? {} : { totals }),
|
|
87
|
+
...(detail === undefined ? {} : { detail }),
|
|
88
|
+
};
|
|
69
89
|
};
|
|
70
90
|
const more = (bucket, deepest) => {
|
|
71
91
|
const next = deepest ? brings?.(bucket) : undefined;
|
|
@@ -83,7 +103,7 @@ brings) {
|
|
|
83
103
|
key,
|
|
84
104
|
label: labelFor(bucket, depth, key),
|
|
85
105
|
count: bucket.count,
|
|
86
|
-
...
|
|
106
|
+
...summed(bucket),
|
|
87
107
|
items: below.length === 0 ? [...(rowsOf(bucket) ?? [])] : [],
|
|
88
108
|
piles: walk(below, path, depth + 1),
|
|
89
109
|
...more(bucket, below.length === 0),
|
package/dist/web/list/pivot.d.ts
CHANGED
|
@@ -8,7 +8,11 @@ import type { Pivot } from "@sincpro/web-ui";
|
|
|
8
8
|
* Nothing is added up here — a margin is read from the base, never summed from cells.
|
|
9
9
|
*
|
|
10
10
|
* A key is how its value READS («Pagada», «Efectivo»): the grid draws keys, and the server's
|
|
11
|
-
* value («paid») is not a word for a person.
|
|
11
|
+
* value («paid») is not a word for a person. A level cut by a grain is the exception: its key
|
|
12
|
+
* is the period the server counted («2026-11»), which web-ui reads by the level's grain —
|
|
13
|
+
* «Noviembre de 2026» in the grid, «nov» under a chart's tick — and which lets a chart fill the
|
|
14
|
+
* months nothing fell in. Read as the field's value, a month was an instant: «31/10/2026 20:00»
|
|
15
|
+
* in La Paz.
|
|
12
16
|
*/
|
|
13
17
|
export declare function pivotOf<T extends AnyRecord>({ crossed, byColumn, rows, columns, measures, meta, locale, }: {
|
|
14
18
|
/** Grouped by rows, then columns (`usePivot().crossed`). */
|