@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,50 @@
|
|
|
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 { Listing } from "../../../react/useListing.js";
|
|
5
|
+
import { type ListSelection } from "../../../react/useSelection.js";
|
|
6
|
+
import { type ScreenActions } from "../dock.js";
|
|
7
|
+
/**
|
|
8
|
+
* Why the list is open: to browse, or to answer whoever asked for one record or several.
|
|
9
|
+
*
|
|
10
|
+
* Opened by `api.pick` (`entity.chooserRef()`), a row ANSWERS whoever asked, it does not open.
|
|
11
|
+
* Asked for SEVERAL (`CHOOSE_MANY`, a many2many's «Buscar más…»), a row press ticks it, and
|
|
12
|
+
* «Agregar (N)» answers what was chosen — the keys, or every record the list matches.
|
|
13
|
+
*/
|
|
14
|
+
export declare function purposeOf(api: WorkspaceApi | undefined): {
|
|
15
|
+
choosing: boolean;
|
|
16
|
+
choosingMany: boolean;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* The rows that are chosen, and what is done with them.
|
|
20
|
+
*
|
|
21
|
+
* The list holds its own selection unless the screen holds it (`held`). With `api`, what is
|
|
22
|
+
* chosen is PUBLISHED to the workspace (`api.select`), so a panel beside it follows the selection
|
|
23
|
+
* without knowing this list. Its actions — answering whoever asked for several, else the
|
|
24
|
+
* screen's — go to the dock as data, or into the bar when drawn by hand.
|
|
25
|
+
*/
|
|
26
|
+
export declare function useListChoosing<T extends AnyRecord, C extends CommandBodies>({ listing, api, idOf, held, selectable, selectionActions, choosingMany, }: {
|
|
27
|
+
listing: Listing<T, C>;
|
|
28
|
+
api: WorkspaceApi | undefined;
|
|
29
|
+
idOf: (row: T) => string;
|
|
30
|
+
held: ListSelection<T> | undefined;
|
|
31
|
+
selectable: boolean;
|
|
32
|
+
selectionActions: ScreenActions | ((selection: ListSelection<T>) => ScreenActions) | undefined;
|
|
33
|
+
choosingMany: boolean;
|
|
34
|
+
}): {
|
|
35
|
+
chosen: ListSelection<T>;
|
|
36
|
+
/** What the chosen rows start, floating in the dock. */
|
|
37
|
+
dock: readonly import("@sincpro/web-ui").DockAction[];
|
|
38
|
+
/** web-ui `List`'s `selection`, when the rows can be ticked. */
|
|
39
|
+
selection: {
|
|
40
|
+
actions?: string | number | bigint | boolean | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | import("react").ReactPortal | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | null | undefined> | undefined;
|
|
41
|
+
matching?: {
|
|
42
|
+
total: number;
|
|
43
|
+
onSelect: () => void;
|
|
44
|
+
} | undefined;
|
|
45
|
+
has: (key: string) => boolean;
|
|
46
|
+
toggle: (key: string) => void;
|
|
47
|
+
count: number;
|
|
48
|
+
clear: () => void;
|
|
49
|
+
} | undefined;
|
|
50
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { PICK_PARAM } from "@sincpro/client-framework";
|
|
3
|
+
import { frameworkCopy } from "../../../core/copy.js";
|
|
4
|
+
import { choosesMany } from "../../../core/list.js";
|
|
5
|
+
import { useSelection } from "../../../react/useSelection.js";
|
|
6
|
+
import { actionsOf } from "../dock.js";
|
|
7
|
+
import { useEffect, useRef } from "react";
|
|
8
|
+
/**
|
|
9
|
+
* Why the list is open: to browse, or to answer whoever asked for one record or several.
|
|
10
|
+
*
|
|
11
|
+
* Opened by `api.pick` (`entity.chooserRef()`), a row ANSWERS whoever asked, it does not open.
|
|
12
|
+
* Asked for SEVERAL (`CHOOSE_MANY`, a many2many's «Buscar más…»), a row press ticks it, and
|
|
13
|
+
* «Agregar (N)» answers what was chosen — the keys, or every record the list matches.
|
|
14
|
+
*/
|
|
15
|
+
export function purposeOf(api) {
|
|
16
|
+
const choosing = api?.self.params?.[PICK_PARAM] !== undefined;
|
|
17
|
+
return { choosing, choosingMany: choosing && choosesMany(api?.choosing?.question) };
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The rows that are chosen, and what is done with them.
|
|
21
|
+
*
|
|
22
|
+
* The list holds its own selection unless the screen holds it (`held`). With `api`, what is
|
|
23
|
+
* chosen is PUBLISHED to the workspace (`api.select`), so a panel beside it follows the selection
|
|
24
|
+
* without knowing this list. Its actions — answering whoever asked for several, else the
|
|
25
|
+
* screen's — go to the dock as data, or into the bar when drawn by hand.
|
|
26
|
+
*/
|
|
27
|
+
export function useListChoosing({ listing, api, idOf, held, selectable, selectionActions, choosingMany, }) {
|
|
28
|
+
const own = useSelection(listing);
|
|
29
|
+
const chosen = held ?? own;
|
|
30
|
+
// Actions for the chosen rows make the rows choosable: given without `selectable` they were
|
|
31
|
+
// silently never shown — no ticks, nothing to act on.
|
|
32
|
+
const ticking = selectable || choosingMany || selectionActions !== undefined;
|
|
33
|
+
// The workspace hears what is chosen: the keys, or — «all that match» — the ones on screen.
|
|
34
|
+
const published = (chosen.selection.by === "keys"
|
|
35
|
+
? chosen.selection.keys
|
|
36
|
+
: listing.rows.map((row) => idOf(row)).filter((id) => chosen.isChosen(id))).join("\u0000");
|
|
37
|
+
const heard = useRef(published);
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (!ticking || heard.current === published)
|
|
40
|
+
return;
|
|
41
|
+
heard.current = published;
|
|
42
|
+
api?.select(published === "" ? [] : published.split("\u0000").map((id) => listing.entity.ref(id)));
|
|
43
|
+
}, [api, ticking, published, listing.entity]);
|
|
44
|
+
// «Elegir los 187 que coinciden» only past the page, and only with the server's exact count.
|
|
45
|
+
const total = listing.count?.exact === true ? listing.count.value : null;
|
|
46
|
+
const onChosen = choosingMany
|
|
47
|
+
? [
|
|
48
|
+
{
|
|
49
|
+
id: "add-chosen",
|
|
50
|
+
label: frameworkCopy().picker.addChosen(chosen.size),
|
|
51
|
+
primary: true,
|
|
52
|
+
onSelect: () => api?.answer(chosen.selection),
|
|
53
|
+
},
|
|
54
|
+
]
|
|
55
|
+
: typeof selectionActions === "function"
|
|
56
|
+
? selectionActions(chosen)
|
|
57
|
+
: selectionActions;
|
|
58
|
+
const forChosen = actionsOf(onChosen);
|
|
59
|
+
return {
|
|
60
|
+
chosen,
|
|
61
|
+
/** What the chosen rows start, floating in the dock. */
|
|
62
|
+
dock: forChosen.dock,
|
|
63
|
+
/** web-ui `List`'s `selection`, when the rows can be ticked. */
|
|
64
|
+
selection: ticking
|
|
65
|
+
? {
|
|
66
|
+
has: chosen.isChosen,
|
|
67
|
+
toggle: chosen.toggle,
|
|
68
|
+
count: chosen.size ?? 0,
|
|
69
|
+
clear: chosen.clear,
|
|
70
|
+
...(total !== null && total > listing.rows.length
|
|
71
|
+
? { matching: { total, onSelect: chosen.chooseAllMatching } }
|
|
72
|
+
: {}),
|
|
73
|
+
...(forChosen.drawn === null ? {} : { actions: forChosen.drawn }),
|
|
74
|
+
}
|
|
75
|
+
: undefined,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { CommandBodies } from "@sincpro/client-framework";
|
|
2
|
+
import type { AnyRecord } from "@sincpro/criteria";
|
|
3
|
+
import { type ResourceRef, type WorkspaceApi } from "@sincpro/web-composer";
|
|
4
|
+
import type { Listing } from "../../../react/useListing.js";
|
|
5
|
+
import type { EntityListProps } from "./props.js";
|
|
6
|
+
import { type CardWays, type RowOf } from "@sincpro/web-ui";
|
|
7
|
+
import { type ReactNode } from "react";
|
|
8
|
+
/**
|
|
9
|
+
* The same set, read several ways: the table's columns, the sheet's, the order each face sorts
|
|
10
|
+
* by, a row's name and facts, the board's card and the till's tile, the pivot.
|
|
11
|
+
*
|
|
12
|
+
* Context: one set of fields, many faces. The columns are the model's (`columnsOf`), the cell
|
|
13
|
+
* that names a row is the link to its record, and every other face reads the record from those
|
|
14
|
+
* same columns — never a second list of fields. The pivot asks the server only while it is the
|
|
15
|
+
* face on screen.
|
|
16
|
+
*/
|
|
17
|
+
export declare function useListFaces<T extends AnyRecord, C extends CommandBodies>({ listing, api, idOf, columns, cells, yesNo, choosing, refOf, elsewhere, opens, openInOf, present, views, pivot: pivotAsked, }: {
|
|
18
|
+
listing: Listing<T, C>;
|
|
19
|
+
api: WorkspaceApi | undefined;
|
|
20
|
+
idOf: (row: T) => string;
|
|
21
|
+
columns: readonly string[] | undefined;
|
|
22
|
+
cells: EntityListProps<T, C>["cells"];
|
|
23
|
+
yesNo: EntityListProps<T, C>["yesNo"];
|
|
24
|
+
choosing: boolean;
|
|
25
|
+
refOf: (row: T) => ResourceRef;
|
|
26
|
+
elsewhere: readonly string[];
|
|
27
|
+
opens: boolean;
|
|
28
|
+
openInOf: (row: T) => ReactNode;
|
|
29
|
+
present: string;
|
|
30
|
+
views: readonly string[];
|
|
31
|
+
pivot: EntityListProps<T, C>["pivot"];
|
|
32
|
+
}): {
|
|
33
|
+
columns: import("@sincpro/web-ui").DataColumn<T>[];
|
|
34
|
+
sheetColumns: {
|
|
35
|
+
look?: "tag" | undefined;
|
|
36
|
+
numeric?: boolean | undefined;
|
|
37
|
+
id: string;
|
|
38
|
+
header: string;
|
|
39
|
+
}[];
|
|
40
|
+
sortStates: {
|
|
41
|
+
key: string;
|
|
42
|
+
direction: "desc" | "asc";
|
|
43
|
+
}[];
|
|
44
|
+
sortable: {
|
|
45
|
+
field: string;
|
|
46
|
+
label: string;
|
|
47
|
+
}[];
|
|
48
|
+
rowOf: (row: T) => RowOf;
|
|
49
|
+
cardOfRow: ((row: T, ways: CardWays) => import("react").JSX.Element) | undefined;
|
|
50
|
+
tileOfRow: ((row: T, ways: CardWays) => import("react").JSX.Element) | undefined;
|
|
51
|
+
tones: Readonly<Partial<Record<string | (keyof T & string), Readonly<Record<string, import("@sincpro/web-ui").Tone>>>>> | undefined;
|
|
52
|
+
folded: import("@sincpro/web-ui").Pivot | null;
|
|
53
|
+
};
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { RecordLink } from "@sincpro/web-composer";
|
|
4
|
+
import { textOf } from "../../../core/present.js";
|
|
5
|
+
import { summaryFieldsOf } from "../../../core/summary.js";
|
|
6
|
+
import { useFramework } from "../../../react/context.js";
|
|
7
|
+
import { usePivot } from "../../../react/usePivot.js";
|
|
8
|
+
import { columnsOf } from "../columns.js";
|
|
9
|
+
import { pivotOf } from "../pivot.js";
|
|
10
|
+
import { over, presentationOf, } from "../presentation.js";
|
|
11
|
+
import { RecordCard, Tag } from "@sincpro/web-ui";
|
|
12
|
+
import { useMemo } from "react";
|
|
13
|
+
/**
|
|
14
|
+
* The same set, read several ways: the table's columns, the sheet's, the order each face sorts
|
|
15
|
+
* by, a row's name and facts, the board's card and the till's tile, the pivot.
|
|
16
|
+
*
|
|
17
|
+
* Context: one set of fields, many faces. The columns are the model's (`columnsOf`), the cell
|
|
18
|
+
* that names a row is the link to its record, and every other face reads the record from those
|
|
19
|
+
* same columns — never a second list of fields. The pivot asks the server only while it is the
|
|
20
|
+
* face on screen.
|
|
21
|
+
*/
|
|
22
|
+
export function useListFaces({ listing, api, idOf, columns, cells, yesNo, choosing, refOf, elsewhere, opens, openInOf, present, views, pivot: pivotAsked, }) {
|
|
23
|
+
const { meta, locale } = listing;
|
|
24
|
+
const { dateStyle } = useFramework();
|
|
25
|
+
const look = presentationOf(listing.entity);
|
|
26
|
+
const identity = meta?.identity ?? "id";
|
|
27
|
+
// The column that names a row carries its link: the identity, or — in a list that does not
|
|
28
|
+
// show it (a relation inside a record) — the record's name, else the first. The link is only
|
|
29
|
+
// the name (`compact`): the places it opens in are the row's ways.
|
|
30
|
+
const named = columns === undefined || columns.includes(identity)
|
|
31
|
+
? identity
|
|
32
|
+
: meta?.display && columns.includes(meta.display)
|
|
33
|
+
? meta.display
|
|
34
|
+
: (columns[0] ?? identity);
|
|
35
|
+
const rowName = (row) => named === identity ? idOf(row) : (textOf(meta, named, row[named], locale) ?? idOf(row));
|
|
36
|
+
const linked = choosing || cells?.[named] !== undefined || api === undefined
|
|
37
|
+
? cells
|
|
38
|
+
: {
|
|
39
|
+
...cells,
|
|
40
|
+
[named]: (row) => (_jsx(RecordLink, { api: api, resource: refOf(row), compact: true, children: rowName(row) })),
|
|
41
|
+
};
|
|
42
|
+
// Rebuilt only when what it reads changes: a new set of columns on every render redraws
|
|
43
|
+
// every cell of the table. `columns` is compared by content (it is usually a literal);
|
|
44
|
+
// `cells` by identity, since its functions may close over state — memoise it to keep this.
|
|
45
|
+
const names = columns?.join("\u0000");
|
|
46
|
+
const where = elsewhere.join();
|
|
47
|
+
const shown = useMemo(() => columnsOf(meta, columns, {
|
|
48
|
+
locale,
|
|
49
|
+
...(linked ? { cells: linked } : {}),
|
|
50
|
+
...(look.tones === undefined ? {} : { tones: look.tones }),
|
|
51
|
+
...(yesNo === undefined ? {} : { yesNo }),
|
|
52
|
+
}),
|
|
53
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
54
|
+
[meta, locale, names, cells, yesNo, api, where, opens, dateStyle, look.tones]);
|
|
55
|
+
// The sheet's columns are the table's on screen: one set of fields, two ways to read them.
|
|
56
|
+
const sheetColumns = useMemo(() => shown
|
|
57
|
+
.filter((column) => !column.defaultHidden)
|
|
58
|
+
.map((column) => ({
|
|
59
|
+
id: column.id,
|
|
60
|
+
header: String(column.header),
|
|
61
|
+
...(column.numeric === true ? { numeric: true } : {}),
|
|
62
|
+
// A state in a toned tag, as the table draws it — not a painted cell, which is how
|
|
63
|
+
// a sheet marks a value out of range.
|
|
64
|
+
...(look.tones?.[column.id] === undefined
|
|
65
|
+
? {}
|
|
66
|
+
: { look: "tag" }),
|
|
67
|
+
})), [shown, look.tones]);
|
|
68
|
+
const sortStates = useMemo(() => listing.order.map((one) => ({
|
|
69
|
+
key: one.field,
|
|
70
|
+
direction: one.descending ? "desc" : "asc",
|
|
71
|
+
})), [listing.order]);
|
|
72
|
+
// The faces with no headers (rows, board) sort too, by the fields the model marks sortable.
|
|
73
|
+
const sortable = useMemo(() => shown
|
|
74
|
+
.filter((column) => column.sortable === true && column.field !== undefined)
|
|
75
|
+
.map((column) => ({ field: column.field, label: String(column.header) })), [shown]);
|
|
76
|
+
// A state the application gave colours to is the row's tag — and not again among its facts.
|
|
77
|
+
const stateField = summaryFieldsOf(meta, {}, listing.entity.summary).state;
|
|
78
|
+
const stateTones = stateField === undefined ? undefined : look.tones?.[stateField];
|
|
79
|
+
// A row and a card read the record by its display and the first fields shown beside it.
|
|
80
|
+
const display = meta?.display || identity;
|
|
81
|
+
const facts = shown
|
|
82
|
+
.filter((c) => c.id !== display &&
|
|
83
|
+
c.id !== identity &&
|
|
84
|
+
!c.defaultHidden &&
|
|
85
|
+
(stateTones === undefined || c.id !== stateField))
|
|
86
|
+
.slice(0, 3);
|
|
87
|
+
const tagOf = (row) => {
|
|
88
|
+
if (stateTones === undefined || stateField === undefined)
|
|
89
|
+
return {};
|
|
90
|
+
const word = textOf(meta, stateField, row[stateField], locale);
|
|
91
|
+
return word === null
|
|
92
|
+
? {}
|
|
93
|
+
: { tags: _jsx(Tag, { tone: stateTones[String(row[stateField])] ?? "neutral", children: word }) };
|
|
94
|
+
};
|
|
95
|
+
const rowOf = (row) => over({
|
|
96
|
+
name: textOf(meta, display, row[display], locale) ?? idOf(row),
|
|
97
|
+
meta: [
|
|
98
|
+
// The key only where the list reads it: one that leaves it out (a relation inside a
|
|
99
|
+
// record) does not print a UUID on every row.
|
|
100
|
+
...(display === identity || named !== identity ? [] : [idOf(row)]),
|
|
101
|
+
...facts.map((c) => textOf(meta, c.id, row[c.id], locale)).filter(Boolean),
|
|
102
|
+
].join(" · "),
|
|
103
|
+
...(elsewhere.length === 0 ? {} : { actions: openInOf(row) }),
|
|
104
|
+
...tagOf(row),
|
|
105
|
+
}, look.row?.(row));
|
|
106
|
+
// Without a look of its own, the board's card — and the tile — is web-ui's, made of the row.
|
|
107
|
+
// With one, the same card under it, and pressing it is still the list's: web-ui hands an own
|
|
108
|
+
// card the list's press rule (`ways.press`: open, or choose). A tile is the same card in its
|
|
109
|
+
// `tile` shape, under its own look.
|
|
110
|
+
const cardFrom = (own, layout) => own === undefined
|
|
111
|
+
? undefined
|
|
112
|
+
: (row, ways) => {
|
|
113
|
+
const d = rowOf(row);
|
|
114
|
+
return (_jsx(RecordCard, { ...over({
|
|
115
|
+
title: d.name,
|
|
116
|
+
...(d.tags === undefined ? {} : { tags: d.tags }),
|
|
117
|
+
...(d.meta === undefined ? {} : { meta: d.meta }),
|
|
118
|
+
}, own(row)), ...(layout === undefined ? {} : { layout }), ...(ways.press === undefined ? {} : { onOpen: ways.press }) }));
|
|
119
|
+
};
|
|
120
|
+
// The pivot asks the server only while it is the face on screen.
|
|
121
|
+
const axes = pivotAsked === undefined || present !== "pivot" || !views.includes("pivot")
|
|
122
|
+
? null
|
|
123
|
+
: {
|
|
124
|
+
rows: typeof pivotAsked.rows === "string"
|
|
125
|
+
? { field: pivotAsked.rows }
|
|
126
|
+
: pivotAsked.rows,
|
|
127
|
+
columns: typeof pivotAsked.columns === "string"
|
|
128
|
+
? { field: pivotAsked.columns }
|
|
129
|
+
: pivotAsked.columns,
|
|
130
|
+
...(pivotAsked.measures === undefined ? {} : { measures: pivotAsked.measures }),
|
|
131
|
+
};
|
|
132
|
+
const crossing = usePivot(listing, axes);
|
|
133
|
+
const folded = axes === null
|
|
134
|
+
? null
|
|
135
|
+
: pivotOf({
|
|
136
|
+
crossed: crossing.crossed,
|
|
137
|
+
byColumn: crossing.columns,
|
|
138
|
+
rows: axes.rows,
|
|
139
|
+
columns: axes.columns,
|
|
140
|
+
measures: crossing.measures,
|
|
141
|
+
meta,
|
|
142
|
+
locale,
|
|
143
|
+
});
|
|
144
|
+
return {
|
|
145
|
+
columns: shown,
|
|
146
|
+
sheetColumns,
|
|
147
|
+
sortStates,
|
|
148
|
+
sortable,
|
|
149
|
+
rowOf,
|
|
150
|
+
cardOfRow: cardFrom(look.card),
|
|
151
|
+
tileOfRow: cardFrom(look.tile, "tile"),
|
|
152
|
+
tones: look.tones,
|
|
153
|
+
folded,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
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 DataColumn, type Pile } from "@sincpro/web-ui";
|
|
5
|
+
/**
|
|
6
|
+
* The set grouped by the server, as web-ui's piles — and what failed to be read.
|
|
7
|
+
*
|
|
8
|
+
* The SERVER counts the groups, a page of them at a time; a level below and a group's rows are
|
|
9
|
+
* read when it is opened, so every group starts closed — but the first ones a named list opens
|
|
10
|
+
* (`defineList open`). A level split by a key of another record names each group by its record,
|
|
11
|
+
* as the key's column does. Every face of web-ui draws these piles,
|
|
12
|
+
* the table included; each says what its next «more» brings, and a level that holds fewer groups
|
|
13
|
+
* than it counts offers the next page of them. A table and a sheet say a group's sums under their
|
|
14
|
+
* columns: beside the group's name, only what no column shown adds up.
|
|
15
|
+
*/
|
|
16
|
+
export declare function useListGrouping<T extends AnyRecord, C extends CommandBodies>({ listing, sums, columns, present, }: {
|
|
17
|
+
listing: Listing<T, C>;
|
|
18
|
+
sums: readonly string[] | false | undefined;
|
|
19
|
+
columns: readonly DataColumn<T>[];
|
|
20
|
+
present: string;
|
|
21
|
+
}): {
|
|
22
|
+
groups: import("../../../react/useGroups.js").Groups<T>;
|
|
23
|
+
grouped: boolean;
|
|
24
|
+
failure: {
|
|
25
|
+
heading: string;
|
|
26
|
+
sentence: string;
|
|
27
|
+
retryable: boolean;
|
|
28
|
+
} | null;
|
|
29
|
+
/** How many records the SERVER counted — never the sum of the groups in hand. */
|
|
30
|
+
records: number;
|
|
31
|
+
/** web-ui `List`'s `group`, while the set is grouped. */
|
|
32
|
+
grouping: {
|
|
33
|
+
group: {
|
|
34
|
+
onMorePiles: (parent: Pile<T> | null) => void;
|
|
35
|
+
morePiles?: number | false | undefined;
|
|
36
|
+
pilesCount?: number | undefined;
|
|
37
|
+
levels: readonly import("../../../react/useGroups.js").GroupLevel[];
|
|
38
|
+
of: (row: T, level: {
|
|
39
|
+
field: string;
|
|
40
|
+
}) => string;
|
|
41
|
+
piles: Pile<T>[];
|
|
42
|
+
collapsed: string[];
|
|
43
|
+
onToggle: (key: string) => void;
|
|
44
|
+
onMore: (pile: Pile<T>) => void;
|
|
45
|
+
onPage: (pile: Pile<T>, step: 1 | -1) => void;
|
|
46
|
+
};
|
|
47
|
+
} | {
|
|
48
|
+
group?: undefined;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { explain } from "../../../core/explain.js";
|
|
3
|
+
import { useGroups } from "../../../react/useGroups.js";
|
|
4
|
+
import { useNamesOf } from "../../../react/useNameOf.js";
|
|
5
|
+
import { keyedLevels, keysOfPiles, namedPiles, pilesOf, } from "../groups.js";
|
|
6
|
+
import { pathKey } from "@sincpro/web-ui";
|
|
7
|
+
/**
|
|
8
|
+
* The set grouped by the server, as web-ui's piles — and what failed to be read.
|
|
9
|
+
*
|
|
10
|
+
* The SERVER counts the groups, a page of them at a time; a level below and a group's rows are
|
|
11
|
+
* read when it is opened, so every group starts closed — but the first ones a named list opens
|
|
12
|
+
* (`defineList open`). A level split by a key of another record names each group by its record,
|
|
13
|
+
* as the key's column does. Every face of web-ui draws these piles,
|
|
14
|
+
* the table included; each says what its next «more» brings, and a level that holds fewer groups
|
|
15
|
+
* than it counts offers the next page of them. A table and a sheet say a group's sums under their
|
|
16
|
+
* columns: beside the group's name, only what no column shown adds up.
|
|
17
|
+
*/
|
|
18
|
+
export function useListGrouping({ listing, sums, columns, present, }) {
|
|
19
|
+
const { meta, locale } = listing;
|
|
20
|
+
const groups = useGroups(listing, sums === undefined ? {} : { sums: sums || [] });
|
|
21
|
+
const grouped = groups.levels.length > 0;
|
|
22
|
+
const columnar = present === "table" || present === "sheet";
|
|
23
|
+
const underColumns = new Set(columnar
|
|
24
|
+
? columns.flatMap((column) => column.aggregate === undefined || column.defaultHidden || column.field === undefined
|
|
25
|
+
? []
|
|
26
|
+
: [column.field])
|
|
27
|
+
: []);
|
|
28
|
+
const { piles: keyedPiles, bucketAt } = pilesOf(groups.buckets, groups.levels, meta, locale, groups.rowsOf, groups.brings, underColumns, groups);
|
|
29
|
+
// A group by a key reads its record's name: the keys of the groups in hand, one request per
|
|
30
|
+
// entity.
|
|
31
|
+
const keyed = keyedLevels(meta, groups.levels);
|
|
32
|
+
const nameOf = useNamesOf(keysOfPiles(keyedPiles, keyed));
|
|
33
|
+
const piles = namedPiles(keyedPiles, keyed, nameOf);
|
|
34
|
+
// What is open is the groups' (it survives a search); a group above another is drawn open
|
|
35
|
+
// only once its level arrived — an empty open group would read as one with no rows.
|
|
36
|
+
const collapsed = [...bucketAt].flatMap(([key, bucket]) => groups.isOpen(bucket) &&
|
|
37
|
+
(groups.isDeepest(bucket) || groups.groupsOf(bucket) !== undefined)
|
|
38
|
+
? []
|
|
39
|
+
: [key]);
|
|
40
|
+
const at = (pile) => bucketAt.get(pathKey(pile.path));
|
|
41
|
+
const morePiles = groups.bringsGroups(null);
|
|
42
|
+
// What failed is what is on screen: the groups when grouped, else the listing.
|
|
43
|
+
const failed = grouped
|
|
44
|
+
? groups.status === "failed"
|
|
45
|
+
? explain(groups.error)
|
|
46
|
+
: null
|
|
47
|
+
: listing.status === "failed"
|
|
48
|
+
? explain(listing.error)
|
|
49
|
+
: null;
|
|
50
|
+
return {
|
|
51
|
+
groups,
|
|
52
|
+
grouped,
|
|
53
|
+
failure: failed,
|
|
54
|
+
/** How many records the SERVER counted — never the sum of the groups in hand. */
|
|
55
|
+
records: groups.records ?? groups.buckets.reduce((sum, bucket) => sum + bucket.count, 0),
|
|
56
|
+
/** web-ui `List`'s `group`, while the set is grouped. */
|
|
57
|
+
grouping: grouped
|
|
58
|
+
? {
|
|
59
|
+
group: {
|
|
60
|
+
levels: groups.levels,
|
|
61
|
+
of: (row, level) => String(row[level.field] ?? ""),
|
|
62
|
+
piles,
|
|
63
|
+
collapsed,
|
|
64
|
+
onToggle: (key) => {
|
|
65
|
+
const bucket = bucketAt.get(key);
|
|
66
|
+
if (bucket !== undefined)
|
|
67
|
+
groups.toggle(bucket);
|
|
68
|
+
},
|
|
69
|
+
// «See N more» inside an open group: its next page, on the server's cursor.
|
|
70
|
+
onMore: (pile) => {
|
|
71
|
+
const bucket = at(pile);
|
|
72
|
+
if (bucket !== undefined)
|
|
73
|
+
groups.more(bucket);
|
|
74
|
+
},
|
|
75
|
+
// Odoo's pager on an open group's line — «51–100 / 2.328 ‹ ›» — turns its page in
|
|
76
|
+
// place of its rows; «See N more» stays under it.
|
|
77
|
+
onPage: (pile, step) => {
|
|
78
|
+
const bucket = at(pile);
|
|
79
|
+
if (bucket !== undefined)
|
|
80
|
+
groups.page(bucket, step);
|
|
81
|
+
},
|
|
82
|
+
// «Ver N grupos más» after the last group of a level: the first level, or the one
|
|
83
|
+
// under an open group — counted by the server (`groups_count`).
|
|
84
|
+
...(groups.groupsCount === null ? {} : { pilesCount: groups.groupsCount }),
|
|
85
|
+
...(morePiles === undefined ? {} : { morePiles }),
|
|
86
|
+
onMorePiles: (parent) => {
|
|
87
|
+
if (parent === null)
|
|
88
|
+
return groups.moreGroups(null);
|
|
89
|
+
const bucket = at(parent);
|
|
90
|
+
if (bucket !== undefined)
|
|
91
|
+
groups.moreGroups(bucket);
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
}
|
|
95
|
+
: {},
|
|
96
|
+
};
|
|
97
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
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 { Listing } from "../../../react/useListing.js";
|
|
5
|
+
import type { ListSelection } from "../../../react/useSelection.js";
|
|
6
|
+
import { type ScreenActions } from "../dock.js";
|
|
7
|
+
import type { DockAction, OpenTarget } from "@sincpro/web-ui";
|
|
8
|
+
/**
|
|
9
|
+
* The trail a record opened from this list walks on: «3 / 64» and its neighbours.
|
|
10
|
+
*
|
|
11
|
+
* Kept current with the page on screen, so the row and its name (`RecordLink`) open the same
|
|
12
|
+
* reference and the record finds where it came from. Never forgotten when the list unmounts —
|
|
13
|
+
* the record it opened replaced it and still walks on it — so the oldest go past a ceiling
|
|
14
|
+
* instead: one per list ever shown, fifty at most.
|
|
15
|
+
*/
|
|
16
|
+
export declare function useListTrail<T extends AnyRecord, C extends CommandBodies>(listing: Listing<T, C>, api: WorkspaceApi | undefined, identity: string, idOf: (row: T) => string): string;
|
|
17
|
+
/**
|
|
18
|
+
* What a row does, and where its record may open.
|
|
19
|
+
*
|
|
20
|
+
* A press opens the page — the composer's one predictable gesture —, answers whoever asked
|
|
21
|
+
* (a chooser), or ticks the row (a chooser of several). Every other place the record may open is
|
|
22
|
+
* among the row's ways in, web-ui's (`openTargets` + `onOpenIn`): 👁 for a look, and «Abrir en…»
|
|
23
|
+
* with the rest, in ONE place at the row's end. A chooser only chooses.
|
|
24
|
+
*/
|
|
25
|
+
export declare function useListOpening<T extends AnyRecord, C extends CommandBodies>({ listing, api, idOf, chosen, choosing, choosingMany, embedded, create, actions, onOpen, onPeek, openTargets, onOpenIn, }: {
|
|
26
|
+
listing: Listing<T, C>;
|
|
27
|
+
api: WorkspaceApi | undefined;
|
|
28
|
+
idOf: (row: T) => string;
|
|
29
|
+
chosen: ListSelection<T>;
|
|
30
|
+
choosing: boolean;
|
|
31
|
+
choosingMany: boolean;
|
|
32
|
+
embedded: boolean;
|
|
33
|
+
create: boolean | string;
|
|
34
|
+
actions: ScreenActions | undefined;
|
|
35
|
+
onOpen: ((row: T) => void) | undefined;
|
|
36
|
+
onPeek: ((row: T) => void) | undefined;
|
|
37
|
+
openTargets: readonly OpenTarget[] | undefined;
|
|
38
|
+
onOpenIn: ((row: T, to: OpenTarget) => void) | undefined;
|
|
39
|
+
}): {
|
|
40
|
+
refOf: (row: T) => {
|
|
41
|
+
params: {
|
|
42
|
+
from: string;
|
|
43
|
+
};
|
|
44
|
+
domain: string;
|
|
45
|
+
kind: string;
|
|
46
|
+
id?: string;
|
|
47
|
+
};
|
|
48
|
+
/** Whether a row may open elsewhere at all (the cells' link depends on it). */
|
|
49
|
+
opens: boolean;
|
|
50
|
+
/** The places other than the page a row's record may open in. */
|
|
51
|
+
elsewhere: ("peek" | "modal" | "side" | "window")[];
|
|
52
|
+
/** The rows face takes «Abrir en…» as its row's actions. */
|
|
53
|
+
openInOf: (row: T) => import("react").JSX.Element | null;
|
|
54
|
+
/** What the bar starts: drawn by hand, «Nuevo» beside it; as data, in the dock. */
|
|
55
|
+
started: {
|
|
56
|
+
drawn: import("react").ReactNode;
|
|
57
|
+
creating: (() => void) | undefined;
|
|
58
|
+
dock: readonly DockAction[];
|
|
59
|
+
};
|
|
60
|
+
/** web-ui `List`'s props for what a row does. */
|
|
61
|
+
ways: {
|
|
62
|
+
openTargets?: ("peek" | "modal" | "side" | "window")[] | undefined;
|
|
63
|
+
onOpenIn?: ((row: T, to: OpenTarget) => void | undefined) | undefined;
|
|
64
|
+
onPeek?: ((row: T) => void) | undefined;
|
|
65
|
+
rowClick?: "open" | undefined;
|
|
66
|
+
onOpen?: ((row: T) => void) | undefined;
|
|
67
|
+
};
|
|
68
|
+
};
|