@sincpro/web-framework 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +298 -40
- package/dist/core/cache.js +2 -2
- package/dist/core/copy.d.ts +26 -0
- package/dist/core/copy.js +32 -0
- package/dist/core/edit.d.ts +48 -3
- package/dist/core/edit.js +79 -5
- package/dist/core/entity.d.ts +46 -0
- package/dist/core/entity.js +57 -0
- package/dist/core/form.d.ts +21 -0
- package/dist/core/form.js +30 -0
- package/dist/core/index.d.ts +11 -3
- package/dist/core/index.js +10 -2
- package/dist/core/lines.d.ts +53 -0
- package/dist/core/lines.js +120 -0
- package/dist/core/list.d.ts +64 -0
- package/dist/core/list.js +22 -0
- package/dist/core/lookup.d.ts +7 -2
- package/dist/core/lookup.js +8 -2
- package/dist/core/measure.d.ts +16 -0
- package/dist/core/measure.js +38 -0
- package/dist/core/memory.js +18 -4
- package/dist/core/relation.d.ts +28 -0
- package/dist/core/relation.js +30 -0
- package/dist/core/rest.d.ts +5 -9
- package/dist/core/rest.js +25 -7
- package/dist/core/retry.d.ts +24 -0
- package/dist/core/retry.js +25 -0
- package/dist/core/summary.d.ts +50 -0
- package/dist/core/summary.js +54 -0
- package/dist/core/trail.d.ts +44 -0
- package/dist/core/trail.js +70 -0
- package/dist/core/transport.d.ts +22 -2
- package/dist/react/context.d.ts +20 -1
- package/dist/react/context.js +10 -2
- package/dist/react/index.d.ts +5 -2
- package/dist/react/index.js +4 -1
- package/dist/react/useCommand.d.ts +3 -1
- package/dist/react/useCommand.js +12 -4
- package/dist/react/useGroups.d.ts +52 -0
- package/dist/react/useGroups.js +110 -0
- package/dist/react/useListing.d.ts +29 -7
- package/dist/react/useListing.js +49 -8
- package/dist/react/useLookup.d.ts +30 -5
- package/dist/react/useLookup.js +56 -3
- package/dist/react/usePivot.d.ts +33 -0
- package/dist/react/usePivot.js +59 -0
- package/dist/react/useRecord.d.ts +28 -9
- package/dist/react/useRecord.js +156 -18
- package/dist/react/useSummary.d.ts +15 -0
- package/dist/react/useSummary.js +22 -0
- package/dist/web/index.d.ts +15 -3
- package/dist/web/index.js +14 -2
- package/dist/web/list/EntityList.d.ts +69 -7
- package/dist/web/list/EntityList.js +281 -23
- package/dist/web/list/EntitySearchBar.d.ts +16 -8
- package/dist/web/list/EntitySearchBar.js +52 -4
- package/dist/web/list/columns.d.ts +0 -13
- package/dist/web/list/columns.js +20 -1
- package/dist/web/list/groups.d.ts +17 -0
- package/dist/web/list/groups.js +80 -0
- package/dist/web/list/openIn.d.ts +41 -0
- package/dist/web/list/openIn.js +55 -0
- package/dist/web/list/pivot.d.ts +23 -0
- package/dist/web/list/pivot.js +64 -0
- package/dist/web/list/presentation.d.ts +51 -0
- package/dist/web/list/presentation.js +20 -0
- package/dist/web/list/rowCommands.d.ts +41 -0
- package/dist/web/list/rowCommands.js +56 -0
- package/dist/web/record/EntityPicker.d.ts +45 -14
- package/dist/web/record/EntityPicker.js +64 -20
- package/dist/web/record/EntityTags.d.ts +38 -0
- package/dist/web/record/EntityTags.js +52 -0
- package/dist/web/record/RelatedList.d.ts +8 -1
- package/dist/web/record/RelatedList.js +37 -3
- package/dist/web/record/control.d.ts +42 -0
- package/dist/web/record/control.js +60 -0
- package/dist/web/record/edit.d.ts +27 -12
- package/dist/web/record/edit.js +92 -25
- package/dist/web/record/lines.d.ts +84 -0
- package/dist/web/record/lines.js +190 -0
- package/dist/web/record/opening.d.ts +34 -0
- package/dist/web/record/opening.js +10 -0
- package/dist/web/record/summary.d.ts +22 -0
- package/dist/web/record/summary.js +63 -0
- package/dist/web/workspace/SincproApp.d.ts +4 -1
- package/dist/web/workspace/SincproApp.js +2 -2
- package/dist/web/workspace/composer.d.ts +27 -4
- package/dist/web/workspace/composer.js +75 -7
- package/dist/web/workspace/open.d.ts +49 -0
- package/dist/web/workspace/open.js +51 -0
- package/dist/web/workspace/record.d.ts +30 -0
- package/dist/web/workspace/record.js +83 -0
- package/dist/web/workspace/skin.d.ts +0 -9
- package/dist/web/workspace/skin.js +25 -13
- package/dist/web/workspace/workspace.d.ts +33 -3
- package/dist/web/workspace/workspace.js +63 -4
- package/package.json +9 -9
|
@@ -1,15 +1,46 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx,
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
import { nameOf } from "@sincpro/criteria";
|
|
4
|
-
import { RecordLink } from "@sincpro/web-composer";
|
|
4
|
+
import { RecordLink, useCrumbs } from "@sincpro/web-composer";
|
|
5
5
|
import { frameworkCopy } from "../../core/copy.js";
|
|
6
|
+
import { PICK_PARAM, QUERY_PARAM, TRAIL_PARAM } from "../../core/entity.js";
|
|
6
7
|
import { textOf, viewOf } from "../../core/present.js";
|
|
7
8
|
import { explain } from "../../core/transport.js";
|
|
9
|
+
import { useFramework } from "../../react/context.js";
|
|
10
|
+
import { useGroups } from "../../react/useGroups.js";
|
|
11
|
+
import { usePivot } from "../../react/usePivot.js";
|
|
8
12
|
import { columnsOf } from "./columns.js";
|
|
9
|
-
import { EntitySearchBar
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
+
import { EntitySearchBar } from "./EntitySearchBar.js";
|
|
14
|
+
import { pilesOf } from "./groups.js";
|
|
15
|
+
import { OpenInMenu, openOptions, targetsFor } from "./openIn.js";
|
|
16
|
+
import { pivotOf } from "./pivot.js";
|
|
17
|
+
import { over, presentationOf } from "./presentation.js";
|
|
18
|
+
import { useRowCommands } from "./rowCommands.js";
|
|
19
|
+
import { Button, Callout, List, Pagination, pathKey, RecordCard, SearchField, Tag, } from "@sincpro/web-ui";
|
|
20
|
+
import { useEffect, useId, useMemo, useRef, useState } from "react";
|
|
21
|
+
/** What `useCrumbs` reads when the list is not in a workspace: no trail, and nothing to follow. */
|
|
22
|
+
const NO_TRAIL = [];
|
|
23
|
+
const NO_WORKSPACE = {
|
|
24
|
+
crumbs: () => NO_TRAIL,
|
|
25
|
+
context: { subscribe: () => () => undefined },
|
|
26
|
+
};
|
|
27
|
+
/** How many lists' trails are kept: the records opened from the last fifty lists page on. */
|
|
28
|
+
const TRAILS = 50;
|
|
29
|
+
/** No commands: one constant, so the hook is not handed a new array on every render. */
|
|
30
|
+
const NO_COMMANDS = [];
|
|
31
|
+
/** What a list offers when nobody said: every face that needs no configuration. */
|
|
32
|
+
const EVERY_VIEW = ["table", "rows", "board", "sheet"];
|
|
33
|
+
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, selectable = false, selectionActions, embedded = false, create = true, commands = NO_COMMANDS, rowActions: askedRowActions, faces, }) {
|
|
34
|
+
// A named list (`defineList`) brings its own columns, filters, faces and words; what the
|
|
35
|
+
// screen passes wins.
|
|
36
|
+
const definition = listing.definition;
|
|
37
|
+
const columns = askedColumns ?? definition?.columns;
|
|
38
|
+
const views = askedViews ??
|
|
39
|
+
definition?.views ??
|
|
40
|
+
(embedded ? ["table"] : pivotAsked === undefined ? EVERY_VIEW : [...EVERY_VIEW, "pivot"]);
|
|
41
|
+
const filters = askedFilters ?? definition?.filters ?? [];
|
|
42
|
+
const title = askedTitle ?? definition?.title;
|
|
43
|
+
const description = askedDescription ?? definition?.description;
|
|
13
44
|
const copy = frameworkCopy().list;
|
|
14
45
|
const { meta, locale, count, page } = listing;
|
|
15
46
|
const identity = meta?.identity ?? "id";
|
|
@@ -17,17 +48,107 @@ export function EntityList({ listing, api, columns, cells, views = ["table"], ti
|
|
|
17
48
|
const failed = listing.status === "failed" ? explain(listing.error) : null;
|
|
18
49
|
const dropped = listing.dropped.map((d) => viewOf(meta, d.field, locale).label);
|
|
19
50
|
const [present, setPresent] = useState(views[0] ?? "table");
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
//
|
|
23
|
-
|
|
24
|
-
|
|
51
|
+
// Opened to choose on what was typed in a picker (`chooserRef(query)`): it starts searched.
|
|
52
|
+
const asked = api?.self.params?.[QUERY_PARAM] ?? "";
|
|
53
|
+
// The box's text is a draft until Enter: typing asks the server nothing.
|
|
54
|
+
const [draft, setDraft] = useState(asked === "" ? listing.text : asked);
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
if (asked !== "" && search === "box")
|
|
57
|
+
listing.search(asked, { now: true });
|
|
58
|
+
// Once, as it opens: what the person types next is theirs.
|
|
59
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
60
|
+
}, []);
|
|
61
|
+
// Opened by `api.pick` (`entity.chooserRef()`): a row ANSWERS whoever asked, it does not open.
|
|
62
|
+
const choosing = api?.self.params?.[PICK_PARAM] !== undefined;
|
|
63
|
+
// The record opened from a row knows the page it came from: «3 / 64» and its neighbours.
|
|
64
|
+
const { trails } = useFramework();
|
|
65
|
+
const trailKey = `trail:${useId()}`;
|
|
66
|
+
// Kept current with the page on screen: the row and its name (`RecordLink`) open the same
|
|
67
|
+
// reference, and whichever opens it, the record finds where it came from.
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
if (api === undefined)
|
|
70
|
+
return;
|
|
71
|
+
const pages = listing.paging === "pages";
|
|
72
|
+
trails.set(trailKey, {
|
|
73
|
+
route: listing.route,
|
|
74
|
+
question: listing.question,
|
|
75
|
+
key: identity,
|
|
76
|
+
ids: listing.rows.map(idOf),
|
|
77
|
+
offset: pages ? Math.max(0, listing.page.from - 1) : 0,
|
|
78
|
+
size: listing.page.size,
|
|
79
|
+
cursors: pages ? listing.page.cursors : [null],
|
|
80
|
+
after: pages ? listing.page.after : null,
|
|
81
|
+
total: pages ? (listing.count?.value ?? null) : listing.rows.length,
|
|
82
|
+
});
|
|
83
|
+
// Never forgotten when the list unmounts — the record it opened replaced it and still walks
|
|
84
|
+
// on it — so the oldest go past a ceiling instead: one per list ever shown, fifty at most.
|
|
85
|
+
for (const old of trails.keys()) {
|
|
86
|
+
if (trails.size <= TRAILS)
|
|
87
|
+
break;
|
|
88
|
+
if (old !== trailKey)
|
|
89
|
+
trails.delete(old);
|
|
90
|
+
}
|
|
91
|
+
// The page on screen is what the trail is: its rows, its cursors, its count.
|
|
92
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
93
|
+
}, [
|
|
94
|
+
api,
|
|
95
|
+
trails,
|
|
96
|
+
trailKey,
|
|
97
|
+
listing.rows,
|
|
98
|
+
listing.count,
|
|
99
|
+
listing.page.from,
|
|
100
|
+
listing.page.after,
|
|
101
|
+
]);
|
|
102
|
+
const refOf = (row) => {
|
|
103
|
+
const ref = listing.entity.ref(idOf(row));
|
|
104
|
+
return { ...ref, params: { ...ref.params, [TRAIL_PARAM]: trailKey } };
|
|
105
|
+
};
|
|
106
|
+
const openWithTrail = (row) => api?.open(refOf(row));
|
|
107
|
+
const opening = onOpen ??
|
|
108
|
+
(api === undefined
|
|
109
|
+
? undefined
|
|
110
|
+
: choosing
|
|
111
|
+
? (row) => api.answer(listing.entity.ref(idOf(row)))
|
|
112
|
+
: openWithTrail);
|
|
113
|
+
const creating = create &&
|
|
114
|
+
api !== undefined &&
|
|
115
|
+
!choosing &&
|
|
116
|
+
!embedded &&
|
|
117
|
+
listing.entity.create !== undefined
|
|
118
|
+
? () => api.open(listing.entity.newRef())
|
|
119
|
+
: undefined;
|
|
120
|
+
// A press opens the page — the composer's one predictable gesture. Every other place the
|
|
121
|
+
// record may open is offered beside its name («Abrir en…») and, for a look, as web-ui's 👁
|
|
122
|
+
// (`onPeek` with `rowClick="open"`: the press stays «open»). A chooser only chooses.
|
|
123
|
+
const openingIn = onOpenIn ??
|
|
124
|
+
(api === undefined
|
|
125
|
+
? undefined
|
|
126
|
+
: (row, to) => to === "page" ? openWithTrail(row) : api.open(refOf(row), openOptions(to)));
|
|
127
|
+
const targets = choosing || openingIn === undefined
|
|
128
|
+
? []
|
|
129
|
+
: (openTargets ?? (api === undefined ? [] : targetsFor(api)));
|
|
130
|
+
const elsewhere = targets.filter((to) => to !== "page");
|
|
131
|
+
const peeking = onPeek ??
|
|
132
|
+
(targets.includes("peek") && openingIn !== undefined
|
|
133
|
+
? (row) => openingIn(row, "peek")
|
|
134
|
+
: undefined);
|
|
135
|
+
// The cells are memoised (below): they reach the opener through a ref, so a screen's inline
|
|
136
|
+
// `onOpenIn` is always the current one without redrawing every cell.
|
|
137
|
+
const openingNow = useRef(openingIn);
|
|
138
|
+
openingNow.current = openingIn;
|
|
139
|
+
const openInOf = (row) => elsewhere.length === 0 || openingIn === undefined ? null : (_jsx(OpenInMenu, { targets: elsewhere, name: idOf(row), onOpen: (to) => openingNow.current?.(row, to) }));
|
|
140
|
+
const linked = choosing ||
|
|
141
|
+
cells?.[identity] !== undefined ||
|
|
142
|
+
(api === undefined && elsewhere.length === 0)
|
|
25
143
|
? cells
|
|
26
144
|
: {
|
|
27
145
|
...cells,
|
|
28
|
-
[identity]: (row) => (_jsx(RecordLink, { api: api, resource:
|
|
146
|
+
[identity]: (row) => (_jsxs("span", { className: "inline-flex items-center gap-1", children: [api === undefined ? (idOf(row)) : (_jsx(RecordLink, { api: api, resource: refOf(row), children: idOf(row) })), openInOf(row)] })),
|
|
29
147
|
};
|
|
30
|
-
|
|
148
|
+
// `useCrumbs`, not `api.crumbs()`: the crumb must follow a name given later (`setTitle`).
|
|
149
|
+
// Without a workspace it reads a trail that never changes — a hook cannot be skipped.
|
|
150
|
+
const following = useCrumbs(api ?? NO_WORKSPACE);
|
|
151
|
+
const trail = crumbs ?? (embedded || api === undefined ? undefined : following);
|
|
31
152
|
const [ticked, setTicked] = useState(() => new Set());
|
|
32
153
|
const tick = (next) => {
|
|
33
154
|
setTicked(next);
|
|
@@ -55,28 +176,165 @@ export function EntityList({ listing, api, columns, cells, views = ["table"], ti
|
|
|
55
176
|
const names = columns?.join("\u0000");
|
|
56
177
|
const shown = useMemo(() => columnsOf(meta, columns, { locale, ...(linked ? { cells: linked } : {}) }),
|
|
57
178
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
58
|
-
[meta, locale, names, cells, api]);
|
|
179
|
+
[meta, locale, names, cells, api, elsewhere.join(), openingIn === undefined]);
|
|
59
180
|
// A row and a card read the record by its display and the first fields shown beside it.
|
|
60
181
|
const display = meta?.display || identity;
|
|
61
182
|
const facts = shown
|
|
62
183
|
.filter((c) => c.id !== display && c.id !== identity && !c.defaultHidden)
|
|
63
184
|
.slice(0, 3);
|
|
64
|
-
|
|
185
|
+
// The entity's own look of a row and a card (`presented`) goes over these defaults.
|
|
186
|
+
const look = presentationOf(listing.entity);
|
|
187
|
+
// The pivot asks the server only while it is the face on screen.
|
|
188
|
+
const axes = pivotAsked === undefined || present !== "pivot" || !views.includes("pivot")
|
|
189
|
+
? null
|
|
190
|
+
: {
|
|
191
|
+
rows: typeof pivotAsked.rows === "string"
|
|
192
|
+
? { field: pivotAsked.rows }
|
|
193
|
+
: pivotAsked.rows,
|
|
194
|
+
columns: typeof pivotAsked.columns === "string"
|
|
195
|
+
? { field: pivotAsked.columns }
|
|
196
|
+
: pivotAsked.columns,
|
|
197
|
+
...(pivotAsked.measures === undefined ? {} : { measures: pivotAsked.measures }),
|
|
198
|
+
};
|
|
199
|
+
const crossing = usePivot(listing, axes);
|
|
200
|
+
const folded = axes === null
|
|
201
|
+
? null
|
|
202
|
+
: pivotOf({
|
|
203
|
+
crossed: crossing.crossed,
|
|
204
|
+
byColumn: crossing.columns,
|
|
205
|
+
rows: axes.rows,
|
|
206
|
+
columns: axes.columns,
|
|
207
|
+
measures: crossing.measures,
|
|
208
|
+
meta,
|
|
209
|
+
locale,
|
|
210
|
+
});
|
|
211
|
+
// The sheet's columns are the table's on screen: one set of fields, two ways to read them.
|
|
212
|
+
const sheetColumns = useMemo(() => shown
|
|
213
|
+
.filter((column) => !column.defaultHidden)
|
|
214
|
+
.map((column) => ({
|
|
215
|
+
id: column.id,
|
|
216
|
+
header: String(column.header),
|
|
217
|
+
...(column.numeric === true ? { numeric: true } : {}),
|
|
218
|
+
})), [shown]);
|
|
219
|
+
const sortStates = useMemo(() => listing.order.map((one) => ({
|
|
220
|
+
key: one.field,
|
|
221
|
+
direction: one.descending ? "desc" : "asc",
|
|
222
|
+
})), [listing.order]);
|
|
223
|
+
const sortable = useMemo(() => shown
|
|
224
|
+
.filter((column) => column.sortable === true && column.field !== undefined)
|
|
225
|
+
.map((column) => ({ field: column.field, label: String(column.header) })), [shown]);
|
|
226
|
+
const rowOf = (row) => over({
|
|
65
227
|
name: textOf(meta, display, row[display], locale) ?? idOf(row),
|
|
66
228
|
meta: [
|
|
67
229
|
...(display === identity ? [] : [idOf(row)]),
|
|
68
230
|
...facts.map((c) => textOf(meta, c.id, row[c.id], locale)).filter(Boolean),
|
|
69
231
|
].join(" · "),
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
232
|
+
...(elsewhere.length === 0 ? {} : { actions: openInOf(row) }),
|
|
233
|
+
}, look.row?.(row));
|
|
234
|
+
// Without a look of its own, the board's card is web-ui's, made of the row. With one, the
|
|
235
|
+
// same card — the row's name, meta and tags — under it, and pressing it is still the list's:
|
|
236
|
+
// web-ui (1.5) hands an own card the list's press rule (`ways.press`: open, or choose).
|
|
237
|
+
const ownCard = look.card;
|
|
238
|
+
const cardOfRow = ownCard === undefined
|
|
239
|
+
? undefined
|
|
240
|
+
: (row, ways) => {
|
|
241
|
+
const d = rowOf(row);
|
|
242
|
+
return (_jsx(RecordCard, { ...over({
|
|
243
|
+
title: d.name,
|
|
244
|
+
...(d.tags === undefined ? {} : { tags: d.tags }),
|
|
245
|
+
...(d.meta === undefined ? {} : { meta: d.meta }),
|
|
246
|
+
}, ownCard(row)), ...(ways.press === undefined ? {} : { onOpen: ways.press }) }));
|
|
247
|
+
};
|
|
248
|
+
// Grouped: the SERVER counts the groups; a group's rows are read when it is opened, so every
|
|
249
|
+
// group starts closed. Every face of web-ui (1.4) draws these piles, the table included, and
|
|
250
|
+
// each says what its next «more» brings (1.5).
|
|
251
|
+
const groups = useGroups(listing, sums === undefined ? {} : { sums: sums || [] });
|
|
252
|
+
const grouped = groups.levels.length > 0;
|
|
253
|
+
const { piles, bucketAt } = pilesOf(groups.buckets, groups.levels, meta, locale, groups.rowsOf, groups.brings);
|
|
254
|
+
const [opened, setOpened] = useState(() => new Set());
|
|
255
|
+
useEffect(() => setOpened(new Set()), [groups.buckets]);
|
|
256
|
+
const collapsed = [...bucketAt.keys()].filter((key) => !opened.has(key));
|
|
257
|
+
const toggle = (key) => {
|
|
258
|
+
const next = new Set(opened);
|
|
259
|
+
if (next.has(key))
|
|
260
|
+
next.delete(key);
|
|
261
|
+
else {
|
|
262
|
+
next.add(key);
|
|
263
|
+
const bucket = bucketAt.get(key);
|
|
264
|
+
const deepest = bucket !== undefined && (bucket.groups ?? []).length === 0;
|
|
265
|
+
if (deepest && groups.rowsOf(bucket) === undefined)
|
|
266
|
+
groups.open(bucket);
|
|
267
|
+
}
|
|
268
|
+
setOpened(next);
|
|
269
|
+
};
|
|
270
|
+
const failure = grouped && groups.status === "failed" ? explain(groups.error) : grouped ? null : failed;
|
|
271
|
+
const grouping = grouped
|
|
272
|
+
? {
|
|
273
|
+
group: {
|
|
274
|
+
levels: groups.levels,
|
|
275
|
+
of: (row, level) => String(row[level.field] ?? ""),
|
|
276
|
+
piles,
|
|
277
|
+
collapsed,
|
|
278
|
+
onToggle: toggle,
|
|
279
|
+
// «See N more» inside an open group: its next page, on the server's cursor (web-ui 1.4).
|
|
280
|
+
onMore: (pile) => {
|
|
281
|
+
const bucket = bucketAt.get(pathKey(pile.path));
|
|
282
|
+
if (bucket !== undefined)
|
|
283
|
+
groups.more(bucket);
|
|
284
|
+
},
|
|
285
|
+
},
|
|
286
|
+
}
|
|
287
|
+
: {};
|
|
288
|
+
const records = groups.buckets.reduce((sum, bucket) => sum + bucket.count, 0);
|
|
289
|
+
// A row's actions: the entity's Commands, then whatever else the screen offers.
|
|
290
|
+
const rowCommands = useRowCommands(listing, commands);
|
|
291
|
+
const rowActions = commands.length === 0 && askedRowActions === undefined
|
|
292
|
+
? undefined
|
|
293
|
+
: (row) => [...rowCommands.rowActions(row), ...(askedRowActions?.(row) ?? [])];
|
|
294
|
+
const refused = rowCommands.error === null ? null : explain(rowCommands.error);
|
|
295
|
+
return (_jsxs(List, { items: listing.rows, keyOf: idOf, embedded: embedded, present: present, onPresentChange: setPresent, ...grouping,
|
|
296
|
+
// The whole order, as web-ui 1.7 shows and sets it: ⇧-click on a header adds a field,
|
|
297
|
+
// the sort menu reorders them — the same list the criteria builder writes.
|
|
298
|
+
sort: sortStates,
|
|
299
|
+
// The faces with no headers (rows, board) sort too, by the fields the model marks
|
|
300
|
+
// sortable — on the server, so no `value` is given.
|
|
301
|
+
sortable: sortable, onSortChange: (next) => listing.orderBy(next.map((one) => ({ field: one.key, descending: one.direction === "desc" }))), state: {
|
|
302
|
+
// Only the FIRST reading shows the skeleton. Refining (typing, a filter, the next
|
|
303
|
+
// page) keeps the rows on screen until the server answers: web-ui swaps the body for
|
|
304
|
+
// a skeleton while `loading`, and a row that vanished under the pointer lost a click.
|
|
305
|
+
// Meanwhile `refreshing` (web-ui 1.4) draws a quiet bar over the rows: asking, not gone.
|
|
306
|
+
loading: grouped
|
|
307
|
+
? groups.status === "loading" && groups.buckets.length === 0
|
|
308
|
+
: listing.status === "loading" && listing.rows.length === 0,
|
|
309
|
+
refreshing: grouped
|
|
310
|
+
? groups.status === "loading" && groups.buckets.length > 0
|
|
311
|
+
: listing.status === "loading" && listing.rows.length > 0,
|
|
312
|
+
error: failure === null
|
|
76
313
|
? null
|
|
77
|
-
: [
|
|
314
|
+
: [failure.heading, failure.sentence].filter(Boolean).join(". "),
|
|
78
315
|
}, filtered: listing.where !== undefined || listing.text !== "", empty: {
|
|
79
316
|
sentence: empty ?? copy.empty,
|
|
80
317
|
whenFiltered: { sentence: copy.emptyFiltered },
|
|
81
|
-
}, ...(selection === undefined ? {} : { selection }), ...(opening === undefined ? {} : { onOpen: opening }), ...(
|
|
318
|
+
}, ...(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, ...(asked === "" ? {} : { seed: asked }) }) })) : null, search === "box" && meta?.search != null ? (_jsx(List.Search, { children: _jsx(SearchField, { value: draft, onChange: (next) => {
|
|
319
|
+
setDraft(next);
|
|
320
|
+
// Emptied (or cleared with ×): the whole set again, at once.
|
|
321
|
+
if (next === "" && listing.text !== "")
|
|
322
|
+
listing.search("", { now: true });
|
|
323
|
+
}, 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 }))] })), _jsxs(List.Pagination, { children: [dropped.length === 0 ? null : (_jsx(Tag, { tone: "warn", title: copy.dropped(dropped), children: copy.dropped(dropped) })), grouped ? (groups.status !== "ready" ? null : (_jsx("span", { className: "text-meta text-muted", children: groups.capped
|
|
324
|
+
? copy.groupsCapped(groups.buckets.length)
|
|
325
|
+
: 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, ...(rowActions === undefined ? {} : { rowActions }) })) : null, _jsx(List.Rows, { row: rowOf }), views.includes("sheet") ? (_jsx(List.Sheet, { columns: sheetColumns, cell: (row, column) => {
|
|
326
|
+
const value = row[column.id];
|
|
327
|
+
return value === null || value === undefined
|
|
328
|
+
? null
|
|
329
|
+
: (textOf(meta, column.id, value, locale) ?? String(value));
|
|
330
|
+
} })) : null, views.includes("pivot") ? (_jsx(List.Pivot, { folded: folded ??
|
|
331
|
+
pivotOf({
|
|
332
|
+
crossed: [],
|
|
333
|
+
byColumn: [],
|
|
334
|
+
rows: { field: "" },
|
|
335
|
+
columns: { field: "" },
|
|
336
|
+
measures: [],
|
|
337
|
+
meta,
|
|
338
|
+
locale,
|
|
339
|
+
}) })) : null, views.includes("board") ? (_jsx(List.Board, { ...(cardOfRow === undefined ? {} : { card: cardOfRow }) })) : null, (faces ?? []).map((face) => (_jsx(List.Present, { id: face.id, label: face.label, icon: face.icon, ...(face.wide === undefined ? {} : { wide: face.wide }), children: face.render }, face.id))), refused === null ? null : (_jsx(Callout, { tone: "bad", title: refused.heading, children: refused.sentence }))] }));
|
|
82
340
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type AnyRecord } from "@sincpro/criteria";
|
|
2
|
+
import type { NamedFilter } from "../../core/list.js";
|
|
3
|
+
import type { Groups } from "../../react/useGroups.js";
|
|
2
4
|
import type { Listing } from "../../react/useListing.js";
|
|
3
5
|
/**
|
|
4
6
|
* web-ui's search bar and criteria builder, bound to a `Listing`.
|
|
@@ -7,20 +9,26 @@ import type { Listing } from "../../react/useListing.js";
|
|
|
7
9
|
* of a record, a chooser — so it is a piece of its own, not something only `EntityList` can do.
|
|
8
10
|
* A screen that writes its own `List` drops it in `List.Search` and gets the same behaviour:
|
|
9
11
|
*
|
|
12
|
+
* - a free text is the entity's LITERAL search — its whole template, every field at once
|
|
13
|
+
* (sincpro_framework's `LiteralSearch`, the same question a many2one and ⌘K ask): it is
|
|
14
|
+
* what Enter puts, unless the model reads the text as a question of its own;
|
|
10
15
|
* - «search by name»: facets are the fields the entity's search template names first;
|
|
11
16
|
* - a typed question («total > 5000») is checked against each field's operators;
|
|
12
17
|
* - a named filter is one click; the builder writes what nobody foresaw (all/any/not);
|
|
13
|
-
* - everything put becomes ONE `where` the SERVER answers (`listing.filter`)
|
|
18
|
+
* - everything put becomes ONE `where` the SERVER answers (`listing.filter`);
|
|
19
|
+
* - with `groups`, «Group by» offers the fields the model says may split the set, and the
|
|
20
|
+
* SERVER counts the groups (`useGroups`).
|
|
14
21
|
*
|
|
15
22
|
* <List.Search><EntitySearchBar listing={listing} filters={…} /></List.Search>
|
|
16
23
|
*/
|
|
17
|
-
export type NamedFilter
|
|
18
|
-
|
|
19
|
-
label: string;
|
|
20
|
-
where: Expression<T>;
|
|
21
|
-
};
|
|
22
|
-
export declare function EntitySearchBar<T extends AnyRecord>({ listing, filters, }: {
|
|
24
|
+
export type { NamedFilter };
|
|
25
|
+
export declare function EntitySearchBar<T extends AnyRecord>({ listing, filters, groups, seed, }: {
|
|
23
26
|
listing: Listing<T>;
|
|
24
27
|
/** The cuts this set offers by name: «sólo pagadas», «vencidas». */
|
|
25
28
|
filters?: readonly NamedFilter<T>[];
|
|
29
|
+
/** The grouping of the same set (`useGroups(listing)`): offers «Group by». */
|
|
30
|
+
groups?: Groups<T>;
|
|
31
|
+
/** A text to start on, put as the literal search chip — what was typed in a picker whose
|
|
32
|
+
* «Buscar más…» opened this list. */
|
|
33
|
+
seed?: string;
|
|
26
34
|
}): import("react").JSX.Element | null;
|
|
@@ -1,16 +1,40 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { matching } from "@sincpro/criteria";
|
|
3
4
|
import { frameworkCopy } from "../../core/copy.js";
|
|
5
|
+
import { groupableOf } from "./groups.js";
|
|
4
6
|
import { facetsOf, modelOf } from "./search.js";
|
|
5
|
-
import { CriteriaBuilder, describeFilter, Dialog, filterCriteria, hasNamed, SearchBar, toggleNamed, whereOf, } from "@sincpro/web-ui";
|
|
6
|
-
import { useMemo, useState } from "react";
|
|
7
|
-
|
|
7
|
+
import { CriteriaBuilder, describeFilter, Dialog, fillCopy, filterCriteria, GroupingLevels, hasNamed, SearchBar, toggleNamed, useGroupingControl, useUiCopy, whereOf, } from "@sincpro/web-ui";
|
|
8
|
+
import { useEffect, useMemo, useRef, useState } from "react";
|
|
9
|
+
/** No grouping: one constant, so the control is not handed a new array on every render. */
|
|
10
|
+
const NO_LEVELS = [];
|
|
11
|
+
export function EntitySearchBar({ listing, filters = [], groups, seed, }) {
|
|
8
12
|
const copy = frameworkCopy().list;
|
|
9
13
|
const { meta, locale } = listing;
|
|
10
14
|
const [put, setPut] = useState([]);
|
|
11
15
|
const [building, setBuilding] = useState(false);
|
|
12
16
|
const model = useMemo(() => (meta ? modelOf(meta, locale) : undefined), [meta, locale]);
|
|
13
17
|
const facets = useMemo(() => (meta ? facetsOf(meta, locale) : []), [meta, locale]);
|
|
18
|
+
const groupable = useMemo(() => groupableOf(meta, locale), [meta, locale]);
|
|
19
|
+
const ui = useUiCopy();
|
|
20
|
+
const seeded = useRef(false);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (seeded.current || seed === undefined || seed === "" || meta?.search == null)
|
|
23
|
+
return;
|
|
24
|
+
seeded.current = true;
|
|
25
|
+
const where = matching(meta, seed).where;
|
|
26
|
+
if (where === undefined)
|
|
27
|
+
return;
|
|
28
|
+
const chip = filterCriteria(where, fillCopy(ui.search.literalChip, { text: seed }));
|
|
29
|
+
setPut([chip]);
|
|
30
|
+
listing.filter(whereOf([chip]));
|
|
31
|
+
// Once the definition is known; what the person changes afterwards is theirs.
|
|
32
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
33
|
+
}, [meta, seed]);
|
|
34
|
+
const control = useGroupingControl({
|
|
35
|
+
levels: groups?.levels ?? NO_LEVELS,
|
|
36
|
+
onLevelsChange: (next) => groups?.group(next),
|
|
37
|
+
});
|
|
14
38
|
if (model === undefined)
|
|
15
39
|
return null;
|
|
16
40
|
const place = (next) => {
|
|
@@ -34,10 +58,34 @@ export function EntitySearchBar({ listing, filters = [], }) {
|
|
|
34
58
|
if (named !== undefined)
|
|
35
59
|
place(toggleNamed(put, { ...named, where: named.where }));
|
|
36
60
|
},
|
|
37
|
-
}),
|
|
61
|
+
}), ...(groups === undefined || groupable.length === 0
|
|
62
|
+
? {}
|
|
63
|
+
: { grouping: _jsx(GroupingLevels, { fields: groupable, control: control }) }), onOpenBuilder: () => setBuilding(true), ...(meta?.search == null
|
|
64
|
+
? {}
|
|
65
|
+
: {
|
|
66
|
+
literal: (text) => matching(meta, text).where ?? null,
|
|
67
|
+
}) }), building ? (_jsx(Dialog, { open: true, width: "lg", title: copy.builder, onClose: () => setBuilding(false), children: _jsx(CriteriaBuilder, { model: model, ...(whereOf(put) === undefined && listing.order.length === 0
|
|
68
|
+
? {}
|
|
69
|
+
: {
|
|
70
|
+
initial: {
|
|
71
|
+
...(whereOf(put) === undefined ? {} : { where: whereOf(put) }),
|
|
72
|
+
...(listing.order.length === 0
|
|
73
|
+
? {}
|
|
74
|
+
: {
|
|
75
|
+
order: listing.order.map((one) => ({
|
|
76
|
+
field: String(one.field),
|
|
77
|
+
...(one.descending === true ? { descending: true } : {}),
|
|
78
|
+
})),
|
|
79
|
+
}),
|
|
80
|
+
},
|
|
81
|
+
}), onApply: (built) => {
|
|
38
82
|
place(built?.where === undefined
|
|
39
83
|
? []
|
|
40
84
|
: [filterCriteria(built.where, describeFilter(built.where, model))]);
|
|
85
|
+
listing.orderBy((built?.order ?? []).map((one) => ({
|
|
86
|
+
field: one.field,
|
|
87
|
+
...(one.descending === true ? { descending: true } : {}),
|
|
88
|
+
})));
|
|
41
89
|
setBuilding(false);
|
|
42
90
|
}, onCancel: () => setBuilding(false) }) })) : null] }));
|
|
43
91
|
}
|
|
@@ -1,19 +1,6 @@
|
|
|
1
1
|
import type { AnyRecord, Meta } from "@sincpro/criteria";
|
|
2
2
|
import type { DataColumn } from "@sincpro/web-ui";
|
|
3
3
|
import type { ReactNode } from "react";
|
|
4
|
-
/**
|
|
5
|
-
* The columns of a table, from the model: name the fields, the rest follows.
|
|
6
|
-
*
|
|
7
|
-
* Context: forge's lists wrote every column by hand — `header: "nombre"`, `value: (p) =>
|
|
8
|
-
* p.display_name`, a date formatter per screen — while the server already said what each field
|
|
9
|
-
* is called and what type it holds. Here a column is a NAME: its header is the model's label,
|
|
10
|
-
* its cell the text the value reads as (`textOf`), its sort key the raw value, and whether it
|
|
11
|
-
* can be ordered is what the server said (`sortable`). A cell that needs more than text — a
|
|
12
|
-
* link, a tag — is the one thing a screen writes (`cells`).
|
|
13
|
-
*
|
|
14
|
-
* The fields NOT named still exist: they come after, `optional` and hidden, so the columns
|
|
15
|
-
* menu offers them and nobody edits the screen to see a field the server already sends.
|
|
16
|
-
*/
|
|
17
4
|
export type ColumnOptions<T> = {
|
|
18
5
|
locale?: string | undefined;
|
|
19
6
|
/** The cells that are not plain text, by field name. */
|
package/dist/web/list/columns.js
CHANGED
|
@@ -1,14 +1,33 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
2
|
import { BOOKKEEPING, defaultFields, sortKeyOf, textOf, viewOf, } from "../../core/present.js";
|
|
3
|
+
/**
|
|
4
|
+
* The columns of a table, from the model: name the fields, the rest follows.
|
|
5
|
+
*
|
|
6
|
+
* Context: forge's lists wrote every column by hand — `header: "nombre"`, `value: (p) =>
|
|
7
|
+
* p.display_name`, a date formatter per screen — while the server already said what each field
|
|
8
|
+
* is called and what type it holds. Here a column is a NAME: its header is the model's label,
|
|
9
|
+
* its cell the text the value reads as (`textOf`), its sort key the raw value, and whether it
|
|
10
|
+
* can be ordered is what the server said (`sortable`). A cell that needs more than text — a
|
|
11
|
+
* link, a tag — is the one thing a screen writes (`cells`).
|
|
12
|
+
*
|
|
13
|
+
* The fields NOT named still exist: they come after, `optional` and hidden, so the columns
|
|
14
|
+
* menu offers them and nobody edits the screen to see a field the server already sends.
|
|
15
|
+
*/
|
|
16
|
+
/** The types whose value is one short thing, read whole. */
|
|
17
|
+
const DATES = new Set(["date", "datetime", "time"]);
|
|
2
18
|
function columnOf(meta, name, options, hidden) {
|
|
3
19
|
const view = viewOf(meta, name, options.locale);
|
|
4
20
|
const text = (row) => textOf(meta, name, row[name], options.locale) ?? "";
|
|
5
21
|
const own = options.cells?.[name];
|
|
22
|
+
// A code, a date, an amount is read whole: «F-2026-0060» in three lines is three values.
|
|
23
|
+
const whole = view.name === meta?.identity || view.numeric || DATES.has(view.type);
|
|
6
24
|
return {
|
|
7
25
|
id: name,
|
|
8
26
|
header: view.label,
|
|
9
27
|
field: name,
|
|
10
28
|
value: (row) => sortKeyOf(meta, name, row[name]),
|
|
11
|
-
cell: own ??
|
|
29
|
+
cell: own ??
|
|
30
|
+
(whole ? (row) => _jsx("span", { className: "whitespace-nowrap", children: text(row) }) : text),
|
|
12
31
|
text,
|
|
13
32
|
numeric: view.numeric,
|
|
14
33
|
sortable: view.sortable,
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type AnyRecord, type Bucket, type Meta } from "@sincpro/criteria";
|
|
2
|
+
import type { GroupLevel } from "../../react/useGroups.js";
|
|
3
|
+
import { type GroupableField, type Pile } from "@sincpro/web-ui";
|
|
4
|
+
/** The fields the model says may split a set (`groupable`), in its words. The identity splits
|
|
5
|
+
* into groups of one, and the version means nothing to a person: neither is offered. */
|
|
6
|
+
export declare function groupableOf(meta: Meta | null, locale?: string): GroupableField[];
|
|
7
|
+
/**
|
|
8
|
+
* The server's groups as piles, with the words a person reads, and each pile's group so that
|
|
9
|
+
* opening one reads its rows. Rows sit only on the deepest level, once read.
|
|
10
|
+
*/
|
|
11
|
+
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,
|
|
12
|
+
/** What a group's next «more» brings (`Pile.more`); omitted, web-ui says nothing about it. */
|
|
13
|
+
brings?: (bucket: Bucket<T>) => number | false | undefined): {
|
|
14
|
+
piles: Pile<T>[];
|
|
15
|
+
bucketAt: ReadonlyMap<string, Bucket<T>>;
|
|
16
|
+
deepest: number;
|
|
17
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { labelOf } from "@sincpro/criteria";
|
|
2
|
+
import { frameworkCopy } from "../../core/copy.js";
|
|
3
|
+
import { detailOf } from "../../core/measure.js";
|
|
4
|
+
import { textOf } from "../../core/present.js";
|
|
5
|
+
import { dateLabel, pathKey, } from "@sincpro/web-ui";
|
|
6
|
+
/**
|
|
7
|
+
* Grouping, as web-ui draws it: which fields may split a set, and the server's groups as the
|
|
8
|
+
* piles a `List` shows.
|
|
9
|
+
*
|
|
10
|
+
* Context: web-ui keeps «what was asked» (`GroupLevel`) apart from «what is drawn» (`Pile`)
|
|
11
|
+
* precisely so that piles can come counted from whoever keeps the data. These are the two
|
|
12
|
+
* translations from the model and from criteria's `Bucket`.
|
|
13
|
+
*/
|
|
14
|
+
/** The cuts a date offers, coarse to fine — web-ui orders the levels by them. */
|
|
15
|
+
const DATE_GRAINS = ["year", "quarter", "month", "week", "day"];
|
|
16
|
+
/** The fields the model says may split a set (`groupable`), in its words. The identity splits
|
|
17
|
+
* into groups of one, and the version means nothing to a person: neither is offered. */
|
|
18
|
+
export function groupableOf(meta, locale) {
|
|
19
|
+
if (meta === null)
|
|
20
|
+
return [];
|
|
21
|
+
return Object.entries(meta.fields)
|
|
22
|
+
.filter(([name, field]) => field.groupable === true &&
|
|
23
|
+
field.kind === "scalar" &&
|
|
24
|
+
name !== meta.identity &&
|
|
25
|
+
name !== "version")
|
|
26
|
+
.map(([name, field]) => ({
|
|
27
|
+
field: name,
|
|
28
|
+
label: labelOf(meta, name, locale),
|
|
29
|
+
...(field.type === "date" || field.type === "datetime" ? { grains: DATE_GRAINS } : {}),
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The server's groups as piles, with the words a person reads, and each pile's group so that
|
|
34
|
+
* opening one reads its rows. Rows sit only on the deepest level, once read.
|
|
35
|
+
*/
|
|
36
|
+
export function pilesOf(buckets, levels, meta, locale, rowsOf,
|
|
37
|
+
/** What a group's next «more» brings (`Pile.more`); omitted, web-ui says nothing about it. */
|
|
38
|
+
brings) {
|
|
39
|
+
const bucketAt = new Map();
|
|
40
|
+
const none = frameworkCopy().list.noValue;
|
|
41
|
+
const labelFor = (bucket, depth, key) => {
|
|
42
|
+
const level = levels[depth];
|
|
43
|
+
if (bucket.value === null || bucket.value === undefined || bucket.value === "")
|
|
44
|
+
return none;
|
|
45
|
+
if (level?.grain) {
|
|
46
|
+
const within = levels
|
|
47
|
+
.slice(0, depth)
|
|
48
|
+
.flatMap((one) => (one.field === level.field && one.grain ? [one.grain] : []));
|
|
49
|
+
return dateLabel(key, level.grain, within);
|
|
50
|
+
}
|
|
51
|
+
return textOf(meta, bucket.field, bucket.value, locale) || key;
|
|
52
|
+
};
|
|
53
|
+
const detailed = (bucket) => {
|
|
54
|
+
const detail = detailOf(meta, bucket.measures, locale);
|
|
55
|
+
return detail === undefined ? {} : { detail };
|
|
56
|
+
};
|
|
57
|
+
const more = (bucket, deepest) => {
|
|
58
|
+
const next = deepest ? brings?.(bucket) : undefined;
|
|
59
|
+
return next === undefined ? {} : { more: next };
|
|
60
|
+
};
|
|
61
|
+
const walk = (level, above, depth) => level.map((bucket) => {
|
|
62
|
+
const key = bucket.value === null || bucket.value === undefined ? "" : String(bucket.value);
|
|
63
|
+
const path = [...above, key];
|
|
64
|
+
bucketAt.set(pathKey(path), bucket);
|
|
65
|
+
const below = bucket.groups ?? [];
|
|
66
|
+
return {
|
|
67
|
+
path,
|
|
68
|
+
depth,
|
|
69
|
+
field: bucket.field,
|
|
70
|
+
key,
|
|
71
|
+
label: labelFor(bucket, depth, key),
|
|
72
|
+
count: bucket.count,
|
|
73
|
+
...detailed(bucket),
|
|
74
|
+
items: below.length === 0 ? [...(rowsOf(bucket) ?? [])] : [],
|
|
75
|
+
piles: walk(below, path, depth + 1),
|
|
76
|
+
...more(bucket, below.length === 0),
|
|
77
|
+
};
|
|
78
|
+
});
|
|
79
|
+
return { piles: walk(buckets, [], 0), bucketAt, deepest: levels.length - 1 };
|
|
80
|
+
}
|