@sincpro/web-framework 3.18.0 → 3.20.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 +83 -54
- package/dist/core/copy.d.ts +14 -0
- package/dist/core/copy.js +57 -2
- package/dist/core/edit.d.ts +13 -0
- package/dist/core/edit.js +14 -0
- package/dist/core/explain.d.ts +4 -0
- package/dist/core/explain.js +4 -0
- package/dist/core/export.d.ts +29 -0
- package/dist/core/export.js +47 -0
- package/dist/core/groups.d.ts +3 -1
- package/dist/core/groups.js +7 -0
- package/dist/core/index.d.ts +4 -3
- package/dist/core/index.js +4 -3
- package/dist/core/lines.d.ts +10 -0
- package/dist/core/lines.js +24 -0
- package/dist/core/list.d.ts +12 -0
- package/dist/react/context.d.ts +44 -1
- package/dist/react/context.js +50 -1
- package/dist/react/index.d.ts +4 -2
- package/dist/react/index.js +4 -2
- package/dist/react/useCounts.d.ts +23 -0
- package/dist/react/useCounts.js +43 -0
- package/dist/react/useGroups.js +38 -5
- package/dist/react/useNameOf.d.ts +13 -0
- package/dist/react/useNameOf.js +32 -0
- package/dist/react/usePeopleOf.d.ts +14 -0
- package/dist/react/usePeopleOf.js +35 -0
- package/dist/react/useRecord.js +2 -2
- package/dist/react/useServiceReading.d.ts +8 -0
- package/dist/react/useServiceReading.js +12 -2
- package/dist/web/index.d.ts +4 -2
- package/dist/web/index.js +4 -2
- package/dist/web/list/EntityList.d.ts +36 -177
- package/dist/web/list/EntityList.js +175 -536
- package/dist/web/list/entityList/choosing.d.ts +50 -0
- package/dist/web/list/entityList/choosing.js +77 -0
- package/dist/web/list/entityList/faces.d.ts +53 -0
- package/dist/web/list/entityList/faces.js +155 -0
- package/dist/web/list/entityList/grouping.d.ts +50 -0
- package/dist/web/list/entityList/grouping.js +97 -0
- package/dist/web/list/entityList/opening.d.ts +68 -0
- package/dist/web/list/entityList/opening.js +149 -0
- package/dist/web/list/entityList/paging.d.ts +30 -0
- package/dist/web/list/entityList/paging.js +39 -0
- package/dist/web/list/entityList/props.d.ts +174 -0
- package/dist/web/list/entityList/props.js +16 -0
- package/dist/web/list/entityList/rowActions.d.ts +31 -0
- package/dist/web/list/entityList/rowActions.js +40 -0
- package/dist/web/list/export.d.ts +13 -0
- package/dist/web/list/export.js +61 -0
- package/dist/web/list/groups.d.ts +16 -0
- package/dist/web/list/groups.js +39 -0
- package/dist/web/list/useEntityList.d.ts +183 -0
- package/dist/web/list/useEntityList.js +225 -0
- package/dist/web/parts.d.ts +42 -0
- package/dist/web/parts.js +88 -0
- package/dist/web/record/lines.d.ts +3 -0
- package/dist/web/record/lines.js +75 -9
- package/dist/web/workspace/RecordScreen.d.ts +206 -0
- package/dist/web/workspace/RecordScreen.js +251 -0
- package/dist/web/workspace/SincproApp.d.ts +14 -2
- package/dist/web/workspace/SincproApp.js +27 -9
- package/dist/web/workspace/composer.js +1 -1
- package/dist/web/workspace/record.d.ts +21 -27
- package/dist/web/workspace/record.js +29 -77
- package/dist/web/workspace/workspace.d.ts +2 -0
- package/dist/web/workspace/workspace.js +1 -1
- package/package.json +7 -7
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { TRAIL_PARAM } from "@sincpro/client-framework";
|
|
4
|
+
import { frameworkCopy } from "../../../core/copy.js";
|
|
5
|
+
import { canCreate } from "../../../core/edit.js";
|
|
6
|
+
import { trailKeyOf } from "../../../core/trail.js";
|
|
7
|
+
import { useFramework } from "../../../react/context.js";
|
|
8
|
+
import { actionsOf } from "../dock.js";
|
|
9
|
+
import { useListExport } from "../export.js";
|
|
10
|
+
import { OpenInMenu, openOptions, targetsFor } from "../openIn.js";
|
|
11
|
+
import { Plus } from "lucide-react";
|
|
12
|
+
import { useEffect, useId, useRef } from "react";
|
|
13
|
+
/** How many lists' trails are kept: the records opened from the last fifty lists page on. */
|
|
14
|
+
const TRAILS = 50;
|
|
15
|
+
/**
|
|
16
|
+
* The trail a record opened from this list walks on: «3 / 64» and its neighbours.
|
|
17
|
+
*
|
|
18
|
+
* Kept current with the page on screen, so the row and its name (`RecordLink`) open the same
|
|
19
|
+
* reference and the record finds where it came from. Never forgotten when the list unmounts —
|
|
20
|
+
* the record it opened replaced it and still walks on it — so the oldest go past a ceiling
|
|
21
|
+
* instead: one per list ever shown, fifty at most.
|
|
22
|
+
*/
|
|
23
|
+
export function useListTrail(listing, api, identity, idOf) {
|
|
24
|
+
const { trails } = useFramework();
|
|
25
|
+
const trailKey = trailKeyOf(useId());
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (api === undefined)
|
|
28
|
+
return;
|
|
29
|
+
const pages = listing.paging === "pages";
|
|
30
|
+
trails.set(trailKey, {
|
|
31
|
+
route: listing.route,
|
|
32
|
+
question: listing.question,
|
|
33
|
+
key: identity,
|
|
34
|
+
ids: listing.rows.map(idOf),
|
|
35
|
+
offset: pages ? Math.max(0, listing.page.from - 1) : 0,
|
|
36
|
+
size: listing.page.size,
|
|
37
|
+
cursors: pages ? listing.page.cursors : [null],
|
|
38
|
+
after: pages ? listing.page.after : null,
|
|
39
|
+
total: pages ? (listing.count?.value ?? null) : listing.rows.length,
|
|
40
|
+
});
|
|
41
|
+
for (const old of trails.keys()) {
|
|
42
|
+
if (trails.size <= TRAILS)
|
|
43
|
+
break;
|
|
44
|
+
if (old !== trailKey)
|
|
45
|
+
trails.delete(old);
|
|
46
|
+
}
|
|
47
|
+
// The page on screen is what the trail is: its rows, its cursors, its count.
|
|
48
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
49
|
+
}, [
|
|
50
|
+
api,
|
|
51
|
+
trails,
|
|
52
|
+
trailKey,
|
|
53
|
+
listing.rows,
|
|
54
|
+
listing.count,
|
|
55
|
+
listing.page.from,
|
|
56
|
+
listing.page.after,
|
|
57
|
+
]);
|
|
58
|
+
return trailKey;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* What a row does, and where its record may open.
|
|
62
|
+
*
|
|
63
|
+
* A press opens the page — the composer's one predictable gesture —, answers whoever asked
|
|
64
|
+
* (a chooser), or ticks the row (a chooser of several). Every other place the record may open is
|
|
65
|
+
* among the row's ways in, web-ui's (`openTargets` + `onOpenIn`): 👁 for a look, and «Abrir en…»
|
|
66
|
+
* with the rest, in ONE place at the row's end. A chooser only chooses.
|
|
67
|
+
*/
|
|
68
|
+
export function useListOpening({ listing, api, idOf, chosen, choosing, choosingMany, embedded, create, actions, onOpen, onPeek, openTargets, onOpenIn, }) {
|
|
69
|
+
const trailKey = useListTrail(listing, api, listing.meta?.identity ?? "id", idOf);
|
|
70
|
+
const refOf = (row) => {
|
|
71
|
+
const ref = listing.entity.ref(idOf(row));
|
|
72
|
+
return { ...ref, params: { ...ref.params, [TRAIL_PARAM]: trailKey } };
|
|
73
|
+
};
|
|
74
|
+
const openWithTrail = (row) => api?.open(refOf(row));
|
|
75
|
+
const opening = onOpen ??
|
|
76
|
+
(api === undefined
|
|
77
|
+
? undefined
|
|
78
|
+
: choosingMany
|
|
79
|
+
? (row) => chosen.toggle(idOf(row))
|
|
80
|
+
: choosing
|
|
81
|
+
? (row) => api.answer(listing.entity.ref(idOf(row)))
|
|
82
|
+
: openWithTrail);
|
|
83
|
+
// «Nuevo» opens the record's form with no id, where the entity can be created.
|
|
84
|
+
const creating = create &&
|
|
85
|
+
api !== undefined &&
|
|
86
|
+
!choosing &&
|
|
87
|
+
!embedded &&
|
|
88
|
+
canCreate(listing.entity, listing.meta)
|
|
89
|
+
? () => api.open(listing.entity.newRef())
|
|
90
|
+
: undefined;
|
|
91
|
+
// What the list starts, as data: «Nuevo» — the primary — and the screen's, drawn by the view
|
|
92
|
+
// style (`List.Dock`). Actions drawn by hand stay in the bar, with «Nuevo» beside them.
|
|
93
|
+
const started = actionsOf(actions);
|
|
94
|
+
// «Exportar», tucked: the list's question as a spreadsheet, when the entity declares its export.
|
|
95
|
+
const exporting = useListExport(listing, !embedded && !choosing);
|
|
96
|
+
const startDock = started.drawn !== null
|
|
97
|
+
? []
|
|
98
|
+
: [
|
|
99
|
+
...(creating === undefined
|
|
100
|
+
? []
|
|
101
|
+
: [
|
|
102
|
+
{
|
|
103
|
+
id: "create",
|
|
104
|
+
label: typeof create === "string" ? create : frameworkCopy().record.create,
|
|
105
|
+
icon: Plus,
|
|
106
|
+
primary: true,
|
|
107
|
+
onSelect: creating,
|
|
108
|
+
},
|
|
109
|
+
]),
|
|
110
|
+
...started.dock,
|
|
111
|
+
...(exporting === null ? [] : [exporting]),
|
|
112
|
+
];
|
|
113
|
+
const openingIn = onOpenIn ??
|
|
114
|
+
(api === undefined
|
|
115
|
+
? undefined
|
|
116
|
+
: (row, to) => to === "page" ? openWithTrail(row) : api.open(refOf(row), openOptions(to)));
|
|
117
|
+
const targets = choosing || openingIn === undefined
|
|
118
|
+
? []
|
|
119
|
+
: (openTargets ?? (api === undefined ? [] : targetsFor(api)));
|
|
120
|
+
const elsewhere = targets.filter((to) => to !== "page");
|
|
121
|
+
const peeking = onPeek ??
|
|
122
|
+
(targets.includes("peek") && openingIn !== undefined
|
|
123
|
+
? (row) => openingIn(row, "peek")
|
|
124
|
+
: undefined);
|
|
125
|
+
// The cells are memoised and web-ui holds the row ways: both reach the opener through a ref,
|
|
126
|
+
// so a screen's inline `onOpenIn` is always the current one without redrawing.
|
|
127
|
+
const openingNow = useRef(openingIn);
|
|
128
|
+
openingNow.current = openingIn;
|
|
129
|
+
const openIn = (row, to) => openingNow.current?.(row, to);
|
|
130
|
+
return {
|
|
131
|
+
refOf,
|
|
132
|
+
/** Whether a row may open elsewhere at all (the cells' link depends on it). */
|
|
133
|
+
opens: openingIn !== undefined,
|
|
134
|
+
/** The places other than the page a row's record may open in. */
|
|
135
|
+
elsewhere,
|
|
136
|
+
/** The rows face takes «Abrir en…» as its row's actions. */
|
|
137
|
+
openInOf: (row) => elsewhere.length === 0 || openingIn === undefined ? null : (_jsx(OpenInMenu, { targets: elsewhere, name: idOf(row), onOpen: (to) => openIn(row, to) })),
|
|
138
|
+
/** What the bar starts: drawn by hand, «Nuevo» beside it; as data, in the dock. */
|
|
139
|
+
started: { drawn: started.drawn, creating, dock: startDock },
|
|
140
|
+
/** web-ui `List`'s props for what a row does. */
|
|
141
|
+
ways: {
|
|
142
|
+
...(opening === undefined ? {} : { onOpen: opening }),
|
|
143
|
+
...(peeking === undefined ? {} : { onPeek: peeking, rowClick: "open" }),
|
|
144
|
+
...(elsewhere.length === 0 || openingIn === undefined
|
|
145
|
+
? {}
|
|
146
|
+
: { openTargets: elsewhere, onOpenIn: openIn }),
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { CommandBodies } from "@sincpro/client-framework";
|
|
2
|
+
import type { AnyRecord } from "@sincpro/criteria";
|
|
3
|
+
import type { Groups } from "../../../react/useGroups.js";
|
|
4
|
+
import type { Listing } from "../../../react/useListing.js";
|
|
5
|
+
import { type DataColumn } from "@sincpro/web-ui";
|
|
6
|
+
import type { ReactNode } from "react";
|
|
7
|
+
/**
|
|
8
|
+
* The way through the set, and whether its figures add up.
|
|
9
|
+
*
|
|
10
|
+
* In `pages` mode the pager walks the server's cursor; in `more` mode «Cargar más» grows the page
|
|
11
|
+
* up to its ceiling; grouped, the server's count of groups and records. Inside a record or a
|
|
12
|
+
* panel only while there is more than what is on screen: «1–5 / 5» repeats the rows.
|
|
13
|
+
*
|
|
14
|
+
* The foot adds up what the model says adds up — over the rows in hand, never a grouped set
|
|
15
|
+
* (each group says its own). While the rows are not the whole set the list says the figures are
|
|
16
|
+
* this page's; inside a record or a panel a page's sum reads as THE total, so an embedded list
|
|
17
|
+
* adds up only when every row is in hand.
|
|
18
|
+
*/
|
|
19
|
+
export declare function useListPaging<T extends AnyRecord, C extends CommandBodies>({ listing, groups, grouped, records, columns, embedded, present, }: {
|
|
20
|
+
listing: Listing<T, C>;
|
|
21
|
+
groups: Groups<T>;
|
|
22
|
+
grouped: boolean;
|
|
23
|
+
records: number;
|
|
24
|
+
columns: readonly DataColumn<T>[];
|
|
25
|
+
embedded: boolean;
|
|
26
|
+
present: string;
|
|
27
|
+
}): {
|
|
28
|
+
totalled: boolean;
|
|
29
|
+
paging: ReactNode;
|
|
30
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { frameworkCopy } from "../../../core/copy.js";
|
|
4
|
+
import { viewOf } from "../../../core/present.js";
|
|
5
|
+
import { Button, Pagination, Tag } from "@sincpro/web-ui";
|
|
6
|
+
/**
|
|
7
|
+
* The way through the set, and whether its figures add up.
|
|
8
|
+
*
|
|
9
|
+
* In `pages` mode the pager walks the server's cursor; in `more` mode «Cargar más» grows the page
|
|
10
|
+
* up to its ceiling; grouped, the server's count of groups and records. Inside a record or a
|
|
11
|
+
* panel only while there is more than what is on screen: «1–5 / 5» repeats the rows.
|
|
12
|
+
*
|
|
13
|
+
* The foot adds up what the model says adds up — over the rows in hand, never a grouped set
|
|
14
|
+
* (each group says its own). While the rows are not the whole set the list says the figures are
|
|
15
|
+
* this page's; inside a record or a panel a page's sum reads as THE total, so an embedded list
|
|
16
|
+
* adds up only when every row is in hand.
|
|
17
|
+
*/
|
|
18
|
+
export function useListPaging({ listing, groups, grouped, records, columns, embedded, present, }) {
|
|
19
|
+
const copy = frameworkCopy().list;
|
|
20
|
+
const { page, count, meta, locale } = listing;
|
|
21
|
+
const partial = listing.paging === "pages"
|
|
22
|
+
? page.hasPrev || page.hasNext
|
|
23
|
+
: listing.hasMore || listing.capped;
|
|
24
|
+
const totalled = !grouped &&
|
|
25
|
+
!(embedded && partial) &&
|
|
26
|
+
listing.rows.length > 0 &&
|
|
27
|
+
columns.some((column) => column.aggregate !== undefined && !column.defaultHidden);
|
|
28
|
+
const fits = embedded && !partial;
|
|
29
|
+
const through = grouped ? (groups.status !== "ready" ? null : (_jsx("span", { className: "text-meta text-muted", children: copy.groups(groups.groupsCount ?? 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,
|
|
30
|
+
/* The range is touched to choose how many rows fit — in both styles. */
|
|
31
|
+
pageSize: page.size, onPageSizeChange: listing.resize, ...(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] }));
|
|
32
|
+
// The conditions the server could not apply, said where the set is counted.
|
|
33
|
+
const dropped = listing.dropped.map((d) => viewOf(meta, d.field, locale).label);
|
|
34
|
+
const pageTotals = totalled && partial && present === "table";
|
|
35
|
+
// Its parts side by side and apart: the slot does not space them, and «Totales de esta
|
|
36
|
+
// página» read glued to «1–50 / 112».
|
|
37
|
+
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] }));
|
|
38
|
+
return { totalled, paging };
|
|
39
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import type { CommandBodies } from "@sincpro/client-framework";
|
|
2
|
+
import type { AnyRecord } from "@sincpro/criteria";
|
|
3
|
+
import type { WorkspaceApi } from "@sincpro/web-composer";
|
|
4
|
+
import type { GroupLevel, NamedFilter } from "../../../core/list.js";
|
|
5
|
+
import type { Listing } from "../../../react/useListing.js";
|
|
6
|
+
import type { ListSelection } from "../../../react/useSelection.js";
|
|
7
|
+
import type { ScreenActions } from "../dock.js";
|
|
8
|
+
import type { RowCommand } from "../rowCommands.js";
|
|
9
|
+
import type { ListCrumb, ListEmpty, ListPresentProps, ListSet, OpenTarget, RowAction, YesNoColumn } from "@sincpro/web-ui";
|
|
10
|
+
import type { ReactNode } from "react";
|
|
11
|
+
export type { NamedFilter };
|
|
12
|
+
/**
|
|
13
|
+
* What a screen says to an `EntityList`: values, never regions — a region is a part
|
|
14
|
+
* (`EntityList.Bar`, `EntityList.Table`…).
|
|
15
|
+
*/
|
|
16
|
+
export type EntityListProps<T extends AnyRecord, C extends CommandBodies = CommandBodies> = {
|
|
17
|
+
listing: Listing<T, C>;
|
|
18
|
+
/**
|
|
19
|
+
* The workspace this list is a view of. With it, a row opens its record as a page, the
|
|
20
|
+
* identity column is the composer's `RecordLink` (peek, side panel, window on hover) and the
|
|
21
|
+
* breadcrumb is the composer's — nothing for the screen to write.
|
|
22
|
+
*/
|
|
23
|
+
api?: WorkspaceApi;
|
|
24
|
+
/** The fields shown, in order. Without it, the named list's, or every scalar field. */
|
|
25
|
+
columns?: readonly string[];
|
|
26
|
+
/** The cells that are not plain text: a link, a tag. Memoise it: compared by identity. */
|
|
27
|
+
cells?: Readonly<Partial<Record<string, (row: T) => ReactNode>>>;
|
|
28
|
+
/**
|
|
29
|
+
* How a yes/no column reads, by field — web-ui's `yesNo`: `check` (the default: ✓ and
|
|
30
|
+
* nothing), `icon` (a green ✓ and a quiet ✕), `word` — or a `checkbox` / `switch` that
|
|
31
|
+
* changes it from the list with `onToggle` (an update, a Command). Memoise it.
|
|
32
|
+
*
|
|
33
|
+
* yesNo={{ published: { look: "switch", onToggle: (course, on) => publish.run(course.id, on) } }}
|
|
34
|
+
*/
|
|
35
|
+
yesNo?: Readonly<Partial<Record<string, YesNoColumn<T>>>>;
|
|
36
|
+
/**
|
|
37
|
+
* The ways to look at the set, the first one shown: `table` (columns), `rows` (a name and
|
|
38
|
+
* its facts, what a narrow panel wants), `board` (cards), `sheet` (a spreadsheet, every
|
|
39
|
+
* cell a value — web-ui's, windowed) and `tiles` (a grid of pictures — a till's products, a
|
|
40
|
+
* shop's items; asked for, never offered by itself: a set of invoices has no picture). The
|
|
41
|
+
* same set, the same search, the same page in each. Without it, a named list's; else the
|
|
42
|
+
* first four on a screen, and the table (rows when narrow) inside a record. The id of one
|
|
43
|
+
* of `faces` opens on that face.
|
|
44
|
+
*/
|
|
45
|
+
views?: readonly (View | (string & {}))[];
|
|
46
|
+
/**
|
|
47
|
+
* The set crossed by two fields — `{ rows: "state", columns: "payment" }` — counted and added
|
|
48
|
+
* up by the server (`usePivot`), offered as the `pivot` face. Only while it is on screen does
|
|
49
|
+
* it ask; never folded from the page.
|
|
50
|
+
*/
|
|
51
|
+
pivot?: {
|
|
52
|
+
rows: string | GroupLevel;
|
|
53
|
+
columns: string | GroupLevel;
|
|
54
|
+
/** What each crossing adds up. Without it, the figures the model computes. */
|
|
55
|
+
measures?: readonly string[];
|
|
56
|
+
};
|
|
57
|
+
/** Without it, the model's own name. */
|
|
58
|
+
title?: string;
|
|
59
|
+
description?: string;
|
|
60
|
+
crumbs?: readonly ListCrumb[];
|
|
61
|
+
/**
|
|
62
|
+
* What the list starts — «Importar», «Exportar ▸» —, beside «Nuevo». As data (`DockAction`s)
|
|
63
|
+
* the application's view style draws them with «Nuevo»: the bar's buttons in `traditional`,
|
|
64
|
+
* one pill floating at the bottom in `modern` (web-ui's `ViewStyleProvider`). A node drawn
|
|
65
|
+
* by hand stays in the bar.
|
|
66
|
+
*/
|
|
67
|
+
actions?: ScreenActions;
|
|
68
|
+
onOpen?: (row: T) => void;
|
|
69
|
+
onPeek?: (row: T) => void;
|
|
70
|
+
/**
|
|
71
|
+
* Where a row's record may open besides a press (the page): a look (👁), a modal, beside, a
|
|
72
|
+
* window — offered in «Abrir en…» by the row's name. With `api`, everywhere the workspace
|
|
73
|
+
* allows from here (`targetsFor`: no modal from inside a modal); `[]` or a few restrict it.
|
|
74
|
+
*/
|
|
75
|
+
openTargets?: readonly OpenTarget[];
|
|
76
|
+
/** Open a row's record there — without `api`, how a screen (a one2many) places it. */
|
|
77
|
+
onOpenIn?: (row: T, to: OpenTarget) => void;
|
|
78
|
+
/**
|
|
79
|
+
* What an empty list says. A text is its sentence; an object is web-ui's empty (2.14) — a
|
|
80
|
+
* `title`, an `icon` or the application's `illustration`, an `action` — for a list that IS the
|
|
81
|
+
* screen («Todavía no hay facturas» with a button to create one). What it leaves out is the
|
|
82
|
+
* framework's words, and `whenFiltered` is what it says when a search emptied it.
|
|
83
|
+
*/
|
|
84
|
+
empty?: string | EntityEmpty;
|
|
85
|
+
/**
|
|
86
|
+
* `"bar"` (the default) is the full search bar with the criteria builder; `"box"` is one
|
|
87
|
+
* text box over the entity's search template — a chooser, a narrow panel; `false` is none.
|
|
88
|
+
* Both ask the server on Enter, never per keystroke: a table is searched on purpose.
|
|
89
|
+
*/
|
|
90
|
+
search?: "bar" | "box" | false;
|
|
91
|
+
/**
|
|
92
|
+
* The bar remembers, in this browser, the last searches put on this list, and offers them
|
|
93
|
+
* when it takes the focus empty («Recientes»). `true` keeps them under the list's key (a
|
|
94
|
+
* named list's, else its entity's); a text, under that name — one per tenant, say. Off by
|
|
95
|
+
* default: what was searched may name a customer, and whether a browser may keep it is the
|
|
96
|
+
* application's call.
|
|
97
|
+
*/
|
|
98
|
+
recent?: boolean | string;
|
|
99
|
+
/** What each group adds up when the list is grouped — «Total 1.204.933,00» in its header,
|
|
100
|
+
* summed by the server over every row of it. Without it, the figures the model computes
|
|
101
|
+
* (read-only exact numbers, `sumsOf`); `false` adds nothing up. */
|
|
102
|
+
sums?: readonly string[] | false;
|
|
103
|
+
/** The cuts this list offers by name: «sólo pagadas», «vencidas». */
|
|
104
|
+
filters?: readonly NamedFilter<T>[];
|
|
105
|
+
/** The fields the search bar offers to look a typed text up in. Without it, the list
|
|
106
|
+
* definition's, else the entity's search template's, else its display (`facetsOf`). */
|
|
107
|
+
facets?: readonly string[];
|
|
108
|
+
/** The fields «Group by» offers, in this order — among those the model lets split the set.
|
|
109
|
+
* Without it, the list definition's, else every one the model does. */
|
|
110
|
+
groupable?: readonly string[];
|
|
111
|
+
/**
|
|
112
|
+
* Rows can be ticked — and, past the page, «Elegir los 187 que coinciden». With `api`, what is
|
|
113
|
+
* chosen is PUBLISHED to the workspace (`api.select`): a panel beside it follows the selection
|
|
114
|
+
* without knowing this list.
|
|
115
|
+
*/
|
|
116
|
+
selectable?: boolean;
|
|
117
|
+
/** The selection, held by the screen (`useSelection(listing)`): read and set from outside the
|
|
118
|
+
* list. Without it the list holds its own. */
|
|
119
|
+
selection?: ListSelection<T>;
|
|
120
|
+
/** What to do with what is chosen, while something is — handed the selection to act on it
|
|
121
|
+
* (`useBatchCommand`). As data, the view style draws it: in the bar in place of the search
|
|
122
|
+
* in `traditional`, a pill floating at the bottom in `modern` («3 elegidas ✕ · Confirmar»).
|
|
123
|
+
* Giving it makes the rows choosable: `selectable` is not needed with it. */
|
|
124
|
+
selectionActions?: ScreenActions | ((selection: ListSelection<T>) => ScreenActions);
|
|
125
|
+
/** The list is a FIELD of a record — its lines, its members — and not a screen. */
|
|
126
|
+
embedded?: boolean;
|
|
127
|
+
/**
|
|
128
|
+
* With `api` and an entity that declares `create`, the bar offers «New», which opens the
|
|
129
|
+
* record's form with no id (`entity.newRef()`). `false` hides it — a list of what only a
|
|
130
|
+
* Command produces, or a caller who may not create. A text is its words, the business's way:
|
|
131
|
+
* `create="Nueva noticia"`.
|
|
132
|
+
*/
|
|
133
|
+
create?: boolean | string;
|
|
134
|
+
/**
|
|
135
|
+
* The entity's Commands offered on each row («Confirmar»), sent with their idempotency key;
|
|
136
|
+
* the list is read again when one is done (`useRowCommands`).
|
|
137
|
+
*/
|
|
138
|
+
commands?: readonly RowCommand<T, C>[];
|
|
139
|
+
/** Any other action of a row — or the commands built by hand with `useRowCommands`. */
|
|
140
|
+
rowActions?: (row: T) => readonly RowAction[];
|
|
141
|
+
/**
|
|
142
|
+
* Ways of looking at the set the SCREEN writes — a gallery, a map, a record with its lines and
|
|
143
|
+
* its buttons — offered beside the built-in ones (web-ui's `List.Present`). Each is handed the
|
|
144
|
+
* same set the others draw: the page, the search's grouping, the selection and what a press
|
|
145
|
+
* does (`ListSet`). Offered after `views`; name one in `views` to open on it.
|
|
146
|
+
*/
|
|
147
|
+
faces?: readonly EntityFace<T>[];
|
|
148
|
+
};
|
|
149
|
+
/** A face of a list written by the screen: its name and icon in the switcher, and how it draws
|
|
150
|
+
* the set. `wide` when it needs width (a narrow list does not offer it). */
|
|
151
|
+
export type EntityFace<T> = {
|
|
152
|
+
id: string;
|
|
153
|
+
label: string;
|
|
154
|
+
icon: ListPresentProps<T>["icon"];
|
|
155
|
+
wide?: boolean;
|
|
156
|
+
render: (set: ListSet<T>) => ReactNode;
|
|
157
|
+
};
|
|
158
|
+
/** An empty list as web-ui draws it (`ListEmpty`), every sentence optional: the copy's words. */
|
|
159
|
+
export type EntityEmpty = Omit<ListEmpty, "sentence" | "whenFiltered"> & {
|
|
160
|
+
sentence?: string;
|
|
161
|
+
whenFiltered?: Omit<NonNullable<ListEmpty["whenFiltered"]>, "sentence"> & {
|
|
162
|
+
sentence?: string;
|
|
163
|
+
};
|
|
164
|
+
};
|
|
165
|
+
/** web-ui's empty for this list: what the screen said, over the framework's words. */
|
|
166
|
+
export declare function emptyOf(asked: string | EntityEmpty | undefined, words: {
|
|
167
|
+
empty: string;
|
|
168
|
+
emptyFiltered: string;
|
|
169
|
+
}): ListEmpty;
|
|
170
|
+
/** No commands: one constant, so the hook is not handed a new array on every render. */
|
|
171
|
+
export declare const NO_COMMANDS: readonly never[];
|
|
172
|
+
export type View = "table" | "rows" | "board" | "tiles" | "sheet" | "pivot";
|
|
173
|
+
/** What a list offers when nobody said: every face that needs no configuration. */
|
|
174
|
+
export declare const EVERY_VIEW: readonly View[];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** web-ui's empty for this list: what the screen said, over the framework's words. */
|
|
2
|
+
export function emptyOf(asked, words) {
|
|
3
|
+
const own = typeof asked === "string" ? { sentence: asked } : (asked ?? {});
|
|
4
|
+
return {
|
|
5
|
+
...own,
|
|
6
|
+
sentence: own.sentence ?? words.empty,
|
|
7
|
+
whenFiltered: {
|
|
8
|
+
...own.whenFiltered,
|
|
9
|
+
sentence: own.whenFiltered?.sentence ?? words.emptyFiltered,
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/** No commands: one constant, so the hook is not handed a new array on every render. */
|
|
14
|
+
export const NO_COMMANDS = [];
|
|
15
|
+
/** What a list offers when nobody said: every face that needs no configuration. */
|
|
16
|
+
export const EVERY_VIEW = ["table", "rows", "board", "sheet"];
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { CommandBodies } from "@sincpro/client-framework";
|
|
2
|
+
import type { AnyRecord } from "@sincpro/criteria";
|
|
3
|
+
import type { Listing } from "../../../react/useListing.js";
|
|
4
|
+
import { type RowCommand } from "../rowCommands.js";
|
|
5
|
+
import type { RowAction } from "@sincpro/web-ui";
|
|
6
|
+
/**
|
|
7
|
+
* What can be done to one row: the entity's Commands, then whatever else the screen offers —
|
|
8
|
+
* and moving it, when the rows are put in their order by hand.
|
|
9
|
+
*
|
|
10
|
+
* In the trash (`trashOf`) each row is brought back with the entity's own `restore`: it can be
|
|
11
|
+
* undone, so it runs on the click, and the list reads again after. Rows are reordered only on the
|
|
12
|
+
* whole order, never grouped or while choosing.
|
|
13
|
+
*/
|
|
14
|
+
export declare function useListRowActions<T extends AnyRecord, C extends CommandBodies>({ listing, idOf, commands, rowActions: asked, grouped, choosing, }: {
|
|
15
|
+
listing: Listing<T, C>;
|
|
16
|
+
idOf: (row: T) => string;
|
|
17
|
+
commands: readonly RowCommand<T, C>[];
|
|
18
|
+
rowActions: ((row: T) => readonly RowAction[]) | undefined;
|
|
19
|
+
grouped: boolean;
|
|
20
|
+
choosing: boolean;
|
|
21
|
+
}): {
|
|
22
|
+
/** The row's actions, for the table; none at all when nothing is offered. */
|
|
23
|
+
rowActions: ((row: T) => RowAction[]) | undefined;
|
|
24
|
+
reorder: import("../reorder.js").Reorder<T>;
|
|
25
|
+
/** A Command or a move the server refused, in words. */
|
|
26
|
+
refused: {
|
|
27
|
+
heading: string;
|
|
28
|
+
sentence: string;
|
|
29
|
+
retryable: boolean;
|
|
30
|
+
} | null;
|
|
31
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { frameworkCopy } from "../../../core/copy.js";
|
|
3
|
+
import { explain } from "../../../core/explain.js";
|
|
4
|
+
import { useReorder } from "../reorder.js";
|
|
5
|
+
import { RESTORE, useRowCommands, } from "../rowCommands.js";
|
|
6
|
+
import { RotateCcw } from "lucide-react";
|
|
7
|
+
import { useMemo } from "react";
|
|
8
|
+
/**
|
|
9
|
+
* What can be done to one row: the entity's Commands, then whatever else the screen offers —
|
|
10
|
+
* and moving it, when the rows are put in their order by hand.
|
|
11
|
+
*
|
|
12
|
+
* In the trash (`trashOf`) each row is brought back with the entity's own `restore`: it can be
|
|
13
|
+
* undone, so it runs on the click, and the list reads again after. Rows are reordered only on the
|
|
14
|
+
* whole order, never grouped or while choosing.
|
|
15
|
+
*/
|
|
16
|
+
export function useListRowActions({ listing, idOf, commands, rowActions: asked, grouped, choosing, }) {
|
|
17
|
+
const restoring = listing.definition?.trash === true && listing.entity.restore !== undefined;
|
|
18
|
+
const offered = useMemo(() => restoring
|
|
19
|
+
? [
|
|
20
|
+
...commands,
|
|
21
|
+
{
|
|
22
|
+
command: RESTORE,
|
|
23
|
+
label: frameworkCopy().record.restore,
|
|
24
|
+
icon: RotateCcw,
|
|
25
|
+
},
|
|
26
|
+
]
|
|
27
|
+
: commands, [restoring, commands]);
|
|
28
|
+
const rowCommands = useRowCommands(listing, offered);
|
|
29
|
+
const reorder = useReorder(listing, idOf, !grouped && !choosing);
|
|
30
|
+
const refusal = rowCommands.error ?? reorder.error;
|
|
31
|
+
return {
|
|
32
|
+
/** The row's actions, for the table; none at all when nothing is offered. */
|
|
33
|
+
rowActions: offered.length === 0 && asked === undefined
|
|
34
|
+
? undefined
|
|
35
|
+
: (row) => [...rowCommands.rowActions(row), ...(asked?.(row) ?? [])],
|
|
36
|
+
reorder,
|
|
37
|
+
/** A Command or a move the server refused, in words. */
|
|
38
|
+
refused: refusal === null ? null : explain(refusal),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type AnyRecord } from "@sincpro/criteria";
|
|
2
|
+
import type { Listing } from "../../react/useListing.js";
|
|
3
|
+
import { type DockAction } from "@sincpro/web-ui";
|
|
4
|
+
/**
|
|
5
|
+
* «Exportar»: the list's records — its question on screen, filter and order, every page — as a
|
|
6
|
+
* spreadsheet (`core/export`), saved by the browser. Offered when the entity declares its export
|
|
7
|
+
* (`entity(…, { export: "/invoices/export" })`); `null` otherwise.
|
|
8
|
+
*
|
|
9
|
+
* Context: the server writes the export (JSON Lines, read as it streams: no page of the list is
|
|
10
|
+
* fetched to build it, so a million rows is the server's work, not the page's), and this writes
|
|
11
|
+
* what a person opens: the model's words as headers, the region's separator and decimal.
|
|
12
|
+
*/
|
|
13
|
+
export declare function useListExport<T extends AnyRecord>(listing: Listing<T>, enabled: boolean): DockAction | null;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { downloadRoute, exportRoute } from "@sincpro/client-framework";
|
|
3
|
+
import { nameOf } from "@sincpro/criteria";
|
|
4
|
+
import { frameworkCopy } from "../../core/copy.js";
|
|
5
|
+
import { csvOf, exportColumnsOf } from "../../core/export.js";
|
|
6
|
+
import { useFramework } from "../../react/context.js";
|
|
7
|
+
import { refusalNotice } from "./records.js";
|
|
8
|
+
import { useToastIfAny } from "@sincpro/web-ui";
|
|
9
|
+
import { Download } from "lucide-react";
|
|
10
|
+
/**
|
|
11
|
+
* «Exportar»: the list's records — its question on screen, filter and order, every page — as a
|
|
12
|
+
* spreadsheet (`core/export`), saved by the browser. Offered when the entity declares its export
|
|
13
|
+
* (`entity(…, { export: "/invoices/export" })`); `null` otherwise.
|
|
14
|
+
*
|
|
15
|
+
* Context: the server writes the export (JSON Lines, read as it streams: no page of the list is
|
|
16
|
+
* fetched to build it, so a million rows is the server's work, not the page's), and this writes
|
|
17
|
+
* what a person opens: the model's words as headers, the region's separator and decimal.
|
|
18
|
+
*/
|
|
19
|
+
export function useListExport(listing, enabled) {
|
|
20
|
+
const { transport, locale } = useFramework();
|
|
21
|
+
const toast = useToastIfAny();
|
|
22
|
+
const entity = listing.entity;
|
|
23
|
+
if (!enabled || entity.export === undefined)
|
|
24
|
+
return null;
|
|
25
|
+
const path = entity.export;
|
|
26
|
+
return {
|
|
27
|
+
id: "export",
|
|
28
|
+
label: frameworkCopy().list.export,
|
|
29
|
+
icon: Download,
|
|
30
|
+
tucked: true,
|
|
31
|
+
onSelect: () => {
|
|
32
|
+
// The question on screen without its page: every record it keeps, in its order.
|
|
33
|
+
const { pagination: _page, ...asked } = listing.question;
|
|
34
|
+
void downloadRoute(transport, exportRoute(path, asked, "jsonl"))
|
|
35
|
+
.then((download) => download.blob())
|
|
36
|
+
.then((blob) => blob.text())
|
|
37
|
+
.then((text) => {
|
|
38
|
+
const csv = csvOf(text.split("\n"), exportColumnsOf(listing.meta, locale), regionOf());
|
|
39
|
+
save(new Blob([csv], { type: "text/csv;charset=utf-8" }), fileNameOf(listing.meta, locale));
|
|
40
|
+
})
|
|
41
|
+
.catch((failure) => toast?.show(refusalNotice(failure)));
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/** The region numbers are written in: the browser's, as a spreadsheet on this machine reads. */
|
|
46
|
+
function regionOf() {
|
|
47
|
+
return typeof navigator === "undefined" ? undefined : navigator.language;
|
|
48
|
+
}
|
|
49
|
+
function fileNameOf(meta, locale) {
|
|
50
|
+
const name = nameOf(meta, locale) || "export";
|
|
51
|
+
return `${name.toLowerCase().replace(/\s+/g, "-")}.csv`;
|
|
52
|
+
}
|
|
53
|
+
/** Saved by the browser, as a link the person followed. */
|
|
54
|
+
function save(blob, name) {
|
|
55
|
+
const url = URL.createObjectURL(blob);
|
|
56
|
+
const link = document.createElement("a");
|
|
57
|
+
link.href = url;
|
|
58
|
+
link.download = name;
|
|
59
|
+
link.click();
|
|
60
|
+
setTimeout(() => URL.revokeObjectURL(url), 0);
|
|
61
|
+
}
|
|
@@ -39,3 +39,19 @@ underColumns?: ReadonlySet<string>, tree?: GroupTree<T>): {
|
|
|
39
39
|
bucketAt: ReadonlyMap<string, Bucket<T>>;
|
|
40
40
|
deepest: number;
|
|
41
41
|
};
|
|
42
|
+
/**
|
|
43
|
+
* The levels that split by a key of another record (`organo`: an `EntityID[Organo]`, or
|
|
44
|
+
* `customer_id` beside its relation), by the aggregate each key names. Their groups are the
|
|
45
|
+
* keys; a person reads the records' names (`namedPiles`).
|
|
46
|
+
*/
|
|
47
|
+
export declare function keyedLevels(meta: Meta | null | undefined, levels: readonly GroupLevel[]): ReadonlyMap<string, string>;
|
|
48
|
+
/** The keys a person reads as names in these piles, each with the aggregate it names. */
|
|
49
|
+
export declare function keysOfPiles<T>(piles: readonly Pile<T>[], keyed: ReadonlyMap<string, string>): {
|
|
50
|
+
target: string;
|
|
51
|
+
id: string;
|
|
52
|
+
}[];
|
|
53
|
+
/**
|
|
54
|
+
* The piles with each key named by its record — «Consejo Técnico», not «CONSEJO_TECNICO» —, as a
|
|
55
|
+
* column of the same key reads. The key until the name arrives, or when nobody names it.
|
|
56
|
+
*/
|
|
57
|
+
export declare function namedPiles<T>(piles: readonly Pile<T>[], keyed: ReadonlyMap<string, string>, nameOf: (target: string, id: string) => string | undefined): Pile<T>[];
|
package/dist/web/list/groups.js
CHANGED
|
@@ -3,6 +3,7 @@ import { frameworkCopy } from "../../core/copy.js";
|
|
|
3
3
|
import { explain } from "../../core/explain.js";
|
|
4
4
|
import { detailOf } from "../../core/measure.js";
|
|
5
5
|
import { textOf } from "../../core/present.js";
|
|
6
|
+
import { relationFieldOf } from "../../core/relation.js";
|
|
6
7
|
import { dateLabel, pathKey, } from "@sincpro/web-ui";
|
|
7
8
|
/**
|
|
8
9
|
* Grouping, as web-ui draws it: which fields may split a set, and the server's groups as the
|
|
@@ -130,3 +131,41 @@ underColumns = new Set(), tree) {
|
|
|
130
131
|
});
|
|
131
132
|
return { piles: walk(buckets, [], 0), bucketAt, deepest: levels.length - 1 };
|
|
132
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* The levels that split by a key of another record (`organo`: an `EntityID[Organo]`, or
|
|
136
|
+
* `customer_id` beside its relation), by the aggregate each key names. Their groups are the
|
|
137
|
+
* keys; a person reads the records' names (`namedPiles`).
|
|
138
|
+
*/
|
|
139
|
+
export function keyedLevels(meta, levels) {
|
|
140
|
+
return new Map(levels.flatMap((level) => {
|
|
141
|
+
const relation = relationFieldOf(meta, level.field);
|
|
142
|
+
return relation !== undefined && !relation.many && relation.key === level.field
|
|
143
|
+
? [[level.field, relation.target]]
|
|
144
|
+
: [];
|
|
145
|
+
}));
|
|
146
|
+
}
|
|
147
|
+
/** The keys a person reads as names in these piles, each with the aggregate it names. */
|
|
148
|
+
export function keysOfPiles(piles, keyed) {
|
|
149
|
+
return piles.flatMap((pile) => {
|
|
150
|
+
const target = pile.field === undefined ? undefined : keyed.get(pile.field);
|
|
151
|
+
const own = target === undefined || pile.key === "" ? [] : [{ target, id: pile.key }];
|
|
152
|
+
return [...own, ...keysOfPiles(pile.piles ?? [], keyed)];
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* The piles with each key named by its record — «Consejo Técnico», not «CONSEJO_TECNICO» —, as a
|
|
157
|
+
* column of the same key reads. The key until the name arrives, or when nobody names it.
|
|
158
|
+
*/
|
|
159
|
+
export function namedPiles(piles, keyed, nameOf) {
|
|
160
|
+
if (keyed.size === 0)
|
|
161
|
+
return [...piles];
|
|
162
|
+
return piles.map((pile) => {
|
|
163
|
+
const target = pile.field === undefined ? undefined : keyed.get(pile.field);
|
|
164
|
+
const name = target === undefined ? undefined : nameOf(target, pile.key);
|
|
165
|
+
return {
|
|
166
|
+
...pile,
|
|
167
|
+
...(name === undefined ? {} : { label: name }),
|
|
168
|
+
...(pile.piles === undefined ? {} : { piles: namedPiles(pile.piles, keyed, nameOf) }),
|
|
169
|
+
};
|
|
170
|
+
});
|
|
171
|
+
}
|