@sincpro/web-framework 3.15.0 → 3.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/copy.d.ts +2 -1
- package/dist/core/groups.d.ts +55 -1
- package/dist/core/groups.js +72 -0
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +1 -1
- package/dist/react/useGroups.d.ts +51 -9
- package/dist/react/useGroups.js +323 -66
- package/dist/react/useListing.d.ts +10 -0
- package/dist/react/useListing.js +23 -2
- package/dist/web/list/EntityList.js +50 -24
- package/dist/web/list/groups.d.ts +10 -2
- package/dist/web/list/groups.js +21 -6
- package/dist/web/list/presentation.d.ts +12 -1
- package/dist/web/record/control.d.ts +7 -0
- package/dist/web/record/control.js +10 -1
- package/dist/web/record/edit.d.ts +1 -1
- package/dist/web/record/edit.js +21 -4
- package/dist/web/record/richText.js +3 -1
- package/dist/web/workspace/record.d.ts +2 -0
- package/dist/web/workspace/record.js +8 -2
- package/package.json +7 -7
package/dist/core/copy.d.ts
CHANGED
|
@@ -36,7 +36,8 @@ export type FrameworkCopy = {
|
|
|
36
36
|
reorderElsewhere: string;
|
|
37
37
|
/** The group of the records that hold no value in the field grouped by. */
|
|
38
38
|
noValue: string;
|
|
39
|
-
/** More groups than shown: narrow the set instead of scrolling them.
|
|
39
|
+
/** More groups than shown: narrow the set instead of scrolling them.
|
|
40
|
+
* @deprecated The groups are paged («Ver N grupos más», web-ui's); nothing says this now. */
|
|
40
41
|
groupsCapped: (shown: number) => string;
|
|
41
42
|
/** «12 groups · 187 records»: what the grouping split. */
|
|
42
43
|
groups: (groups: number, records: number) => string;
|
package/dist/core/groups.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { Bucket } from "@sincpro/criteria";
|
|
1
|
+
import type { AnyRecord, Bucket, Criteria, Measure } from "@sincpro/criteria";
|
|
2
|
+
import type { GroupLevel } from "./list.js";
|
|
2
3
|
/**
|
|
3
4
|
* Whether an answer to a grouped question holds groups — each with how many records it holds
|
|
4
5
|
* (`count`) and the criteria that opens it, its levels below too.
|
|
@@ -10,8 +11,61 @@ import type { Bucket } from "@sincpro/criteria";
|
|
|
10
11
|
* a list that got no groups says so in its failed state.
|
|
11
12
|
*/
|
|
12
13
|
export declare function areGroups(rows: readonly unknown[]): rows is readonly Bucket[];
|
|
14
|
+
/**
|
|
15
|
+
* Whether the answer to a grouped question of the first level is groups: buckets, and never
|
|
16
|
+
* none over a set that holds records.
|
|
17
|
+
*
|
|
18
|
+
* Context: the groups come with no record beside them (`pagination: { limit: 0 }`), so a backend
|
|
19
|
+
* that does not group answers an empty page — which `areGroups` reads as «no groups». It counts
|
|
20
|
+
* the records it was asked to count, though, and records always make at least one group.
|
|
21
|
+
*/
|
|
22
|
+
export declare function isGroupedAnswer(page: {
|
|
23
|
+
rows: readonly unknown[];
|
|
24
|
+
count?: {
|
|
25
|
+
value: number;
|
|
26
|
+
} | null;
|
|
27
|
+
}): boolean;
|
|
13
28
|
/** What a grouped question was answered with when it was not groups: the list's failure. */
|
|
14
29
|
export declare class NotGrouped extends Error {
|
|
15
30
|
readonly route: string;
|
|
16
31
|
constructor(route: string);
|
|
17
32
|
}
|
|
33
|
+
/** Where a page of groups starts: the first, or past the groups already in hand. */
|
|
34
|
+
export type GroupPage = {
|
|
35
|
+
limit: number;
|
|
36
|
+
offset?: number;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* The question for ONE level of groups — the first page of it, or the next.
|
|
40
|
+
*
|
|
41
|
+
* `base` is what the groups split: the list's question at the first level, the opened group's
|
|
42
|
+
* own criteria (`bucket.criteria`) below it. Each level is the first level of its own question,
|
|
43
|
+
* so every level pages and counts the same way (sincpro_framework#391): the backend pages only
|
|
44
|
+
* the first level of a grouping and answers `groups_count` for it — asking all the levels at
|
|
45
|
+
* once brought every sub-group of every group, unpaged.
|
|
46
|
+
*
|
|
47
|
+
* No record comes with the groups (`pagination: { limit: 0 }`): a group's rows are read when it
|
|
48
|
+
* is opened. A page of one record, as before, made the backend read one record per group, all
|
|
49
|
+
* of them. `counted` asks the total of records beside the groups — the first level's summary
|
|
50
|
+
* («800 grupos · 2 329 registros»); below it every bucket already says its own `count`.
|
|
51
|
+
*
|
|
52
|
+
* levelQuestion(listing.question, { field: "state" }, { limit: 80 }, { counted: true })
|
|
53
|
+
* levelQuestion(bucket.criteria, { field: "month" }, { limit: 80, offset: 80 })
|
|
54
|
+
*/
|
|
55
|
+
export declare function levelQuestion<T extends AnyRecord>(base: Criteria<T>, level: GroupLevel, page: GroupPage, options?: {
|
|
56
|
+
measures?: Readonly<Record<string, Measure>>;
|
|
57
|
+
counted?: boolean;
|
|
58
|
+
}): Criteria<T>;
|
|
59
|
+
/**
|
|
60
|
+
* The question for the rows of a group of the deepest level: its own criteria, a page of rows.
|
|
61
|
+
* Whatever grouped or counted it is left out — the rows of a group are a plain list.
|
|
62
|
+
*/
|
|
63
|
+
export declare function rowsQuestion<T extends AnyRecord>(bucket: Bucket<T>, limit: number): Criteria<T>;
|
|
64
|
+
/**
|
|
65
|
+
* What the next «more» of a level brings: how many groups, or `false` when none are left —
|
|
66
|
+
* web-ui's `morePiles`. `undefined` when nobody counted the level (an older backend): then
|
|
67
|
+
* web-ui offers no foot, as before.
|
|
68
|
+
*/
|
|
69
|
+
export declare function nextGroups(shown: number, count: number | null | undefined, pageSize: number): number | false | undefined;
|
|
70
|
+
/** A group's value as the text that keys it — the same `pilesOf` writes in a pile's path. */
|
|
71
|
+
export declare function groupKeyOf(bucket: Pick<Bucket, "value">): string;
|
package/dist/core/groups.js
CHANGED
|
@@ -20,6 +20,17 @@ export function areGroups(rows) {
|
|
|
20
20
|
(bucket.groups === undefined || areGroups(bucket.groups)));
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Whether the answer to a grouped question of the first level is groups: buckets, and never
|
|
25
|
+
* none over a set that holds records.
|
|
26
|
+
*
|
|
27
|
+
* Context: the groups come with no record beside them (`pagination: { limit: 0 }`), so a backend
|
|
28
|
+
* that does not group answers an empty page — which `areGroups` reads as «no groups». It counts
|
|
29
|
+
* the records it was asked to count, though, and records always make at least one group.
|
|
30
|
+
*/
|
|
31
|
+
export function isGroupedAnswer(page) {
|
|
32
|
+
return areGroups(page.rows) && !(page.rows.length === 0 && (page.count?.value ?? 0) > 0);
|
|
33
|
+
}
|
|
23
34
|
/** What a grouped question was answered with when it was not groups: the list's failure. */
|
|
24
35
|
export class NotGrouped extends Error {
|
|
25
36
|
route;
|
|
@@ -29,3 +40,64 @@ export class NotGrouped extends Error {
|
|
|
29
40
|
this.name = "NotGrouped";
|
|
30
41
|
}
|
|
31
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* The question for ONE level of groups — the first page of it, or the next.
|
|
45
|
+
*
|
|
46
|
+
* `base` is what the groups split: the list's question at the first level, the opened group's
|
|
47
|
+
* own criteria (`bucket.criteria`) below it. Each level is the first level of its own question,
|
|
48
|
+
* so every level pages and counts the same way (sincpro_framework#391): the backend pages only
|
|
49
|
+
* the first level of a grouping and answers `groups_count` for it — asking all the levels at
|
|
50
|
+
* once brought every sub-group of every group, unpaged.
|
|
51
|
+
*
|
|
52
|
+
* No record comes with the groups (`pagination: { limit: 0 }`): a group's rows are read when it
|
|
53
|
+
* is opened. A page of one record, as before, made the backend read one record per group, all
|
|
54
|
+
* of them. `counted` asks the total of records beside the groups — the first level's summary
|
|
55
|
+
* («800 grupos · 2 329 registros»); below it every bucket already says its own `count`.
|
|
56
|
+
*
|
|
57
|
+
* levelQuestion(listing.question, { field: "state" }, { limit: 80 }, { counted: true })
|
|
58
|
+
* levelQuestion(bucket.criteria, { field: "month" }, { limit: 80, offset: 80 })
|
|
59
|
+
*/
|
|
60
|
+
export function levelQuestion(base, level, page, options = {}) {
|
|
61
|
+
// What paged, grouped or counted the base means nothing here: a bucket's criteria carries the
|
|
62
|
+
// question that made it (its empty grouping, its page of no rows).
|
|
63
|
+
const { pagination: _page, grouping: _grouping, count: _count, ...own } = base;
|
|
64
|
+
const offset = page.offset ?? 0;
|
|
65
|
+
return {
|
|
66
|
+
...own,
|
|
67
|
+
count: options.counted === true ? "exact" : "none",
|
|
68
|
+
grouping: {
|
|
69
|
+
group_by: [{ ...level }],
|
|
70
|
+
...(options.measures === undefined || Object.keys(options.measures).length === 0
|
|
71
|
+
? {}
|
|
72
|
+
: { measures: { ...options.measures } }),
|
|
73
|
+
pagination: {
|
|
74
|
+
limit: page.limit,
|
|
75
|
+
...(offset > 0 ? { strategy: { rows: offset } } : {}),
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
pagination: { limit: 0 },
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The question for the rows of a group of the deepest level: its own criteria, a page of rows.
|
|
83
|
+
* Whatever grouped or counted it is left out — the rows of a group are a plain list.
|
|
84
|
+
*/
|
|
85
|
+
export function rowsQuestion(bucket, limit) {
|
|
86
|
+
const { grouping: _grouping, pagination: _page, count: _count, ...own } = bucket.criteria;
|
|
87
|
+
return { ...own, count: "none", pagination: { limit } };
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* What the next «more» of a level brings: how many groups, or `false` when none are left —
|
|
91
|
+
* web-ui's `morePiles`. `undefined` when nobody counted the level (an older backend): then
|
|
92
|
+
* web-ui offers no foot, as before.
|
|
93
|
+
*/
|
|
94
|
+
export function nextGroups(shown, count, pageSize) {
|
|
95
|
+
if (count === null || count === undefined)
|
|
96
|
+
return undefined;
|
|
97
|
+
const left = count - shown;
|
|
98
|
+
return left <= 0 ? false : Math.min(pageSize, left);
|
|
99
|
+
}
|
|
100
|
+
/** A group's value as the text that keys it — the same `pilesOf` writes in a pile's path. */
|
|
101
|
+
export function groupKeyOf(bucket) {
|
|
102
|
+
return bucket.value === null || bucket.value === undefined ? "" : String(bucket.value);
|
|
103
|
+
}
|
package/dist/core/index.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export { type Advice, adviceAt, changesOf, computedLocally, creationOf, defaults
|
|
|
14
14
|
export { explain } from "./explain.js";
|
|
15
15
|
export { FILE_WIDGETS, holdsFile, type Published, renditionUrl, type RenditionValue, sendFile, storedFileOf, type StoredFileValue, type UploadAbout, uploadRefusalOf, type Uploads, } from "./files.js";
|
|
16
16
|
export { type FormLayout, formOf } from "./form.js";
|
|
17
|
-
export { areGroups, NotGrouped } from "./groups.js";
|
|
17
|
+
export { areGroups, groupKeyOf, type GroupPage, isGroupedAnswer, levelQuestion, nextGroups, NotGrouped, rowsQuestion, } from "./groups.js";
|
|
18
18
|
export { FACT_TONES, type FactTone, type HistoryChange, type HistoryEntry, historyOf, toneOfFact, } from "./history.js";
|
|
19
19
|
export { addingOf, type AddingRule, blankLine, type Declared, editableLines, isReference, type LineAdding, lineFields, lineKey, linesAnswered, moved, sameLine, writtenInCell, } from "./lines.js";
|
|
20
20
|
export { CHOOSE_MANY, choosesMany, defineList, type GroupLevel, isList, type ListDefinition, listingAsk, type ListingQuestion, type ListSpec, type NamedFilter, readListing, scopeOf, trashOf, } from "./list.js";
|
package/dist/core/index.js
CHANGED
|
@@ -14,7 +14,7 @@ export { adviceAt, changesOf, computedLocally, creationOf, defaultsOf, editedOf,
|
|
|
14
14
|
export { explain } from "./explain.js";
|
|
15
15
|
export { FILE_WIDGETS, holdsFile, renditionUrl, sendFile, storedFileOf, uploadRefusalOf, } from "./files.js";
|
|
16
16
|
export { formOf } from "./form.js";
|
|
17
|
-
export { areGroups, NotGrouped } from "./groups.js";
|
|
17
|
+
export { areGroups, groupKeyOf, isGroupedAnswer, levelQuestion, nextGroups, NotGrouped, rowsQuestion, } from "./groups.js";
|
|
18
18
|
export { FACT_TONES, historyOf, toneOfFact, } from "./history.js";
|
|
19
19
|
export { addingOf, blankLine, editableLines, isReference, lineFields, lineKey, linesAnswered, moved, sameLine, writtenInCell, } from "./lines.js";
|
|
20
20
|
export { CHOOSE_MANY, choosesMany, defineList, isList, listingAsk, readListing, scopeOf, trashOf, } from "./list.js";
|
|
@@ -2,33 +2,70 @@ import { type AnyRecord, type Bucket } from "@sincpro/criteria";
|
|
|
2
2
|
import type { GroupLevel } from "../core/list.js";
|
|
3
3
|
import type { Listing } from "./useListing.js";
|
|
4
4
|
/**
|
|
5
|
-
* The set of a list, split into groups — counted by the SERVER over every row that matches
|
|
5
|
+
* The set of a list, split into groups — counted by the SERVER over every row that matches, a
|
|
6
|
+
* page of groups at a time, each level read when its group is opened.
|
|
6
7
|
*
|
|
7
8
|
* Context: grouping is the same question as filtering («which part of this am I looking at»),
|
|
8
9
|
* and it obeys the same rule: never on the page. Twelve rows on screen cannot say «187 paid»;
|
|
9
10
|
* whoever keeps the set can. So the listing's own question (scope, search, filter) goes to the
|
|
10
|
-
* server with `group_by`, and what comes back is the groups: their value, their real count,
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* server with `group_by`, and what comes back is the groups: their value, their real count, and
|
|
12
|
+
* the criteria that opens each one (sincpro_framework's aggregation; the in-memory server
|
|
13
|
+
* answers the same with criteria's engine). Nobody rebuilds a filter here.
|
|
14
|
+
*
|
|
15
|
+
* A register of 2 329 people grouped by surname makes ~800 groups: the first level comes a page
|
|
16
|
+
* at a time, with how many there are in all (`groups_count`), and «more groups» asks the next.
|
|
17
|
+
* A level below is asked when its group opens — the opened group's criteria, split by the next
|
|
18
|
+
* level, paged the same way (sincpro_framework#391). The rows of a group of the deepest level
|
|
19
|
+
* are read when it opens, a page at a time on the server's cursor.
|
|
20
|
+
*
|
|
21
|
+
* What is open stays open while the question changes — a search, a filter, a save —: each open
|
|
22
|
+
* group whose value is still there is read again, its pages kept, and what was on screen stays
|
|
23
|
+
* until the answer replaces it.
|
|
14
24
|
*
|
|
15
25
|
* const groups = useGroups(listing);
|
|
16
26
|
* groups.group([{ field: "state" }, { field: "invoice_date", grain: "month" }]);
|
|
17
|
-
* groups.buckets
|
|
18
|
-
* groups.
|
|
27
|
+
* groups.buckets // the first page of the first level
|
|
28
|
+
* groups.groupsCount // how many groups it makes in all
|
|
29
|
+
* groups.toggle(bucket) // opens it: the level below, or its first page of rows
|
|
30
|
+
* groups.groupsOf(bucket) // the level below, once read
|
|
31
|
+
* groups.rowsOf(bucket) // its rows, once read (the deepest level)
|
|
19
32
|
*/
|
|
20
33
|
export type { GroupLevel };
|
|
21
34
|
export type Groups<T> = {
|
|
22
35
|
levels: readonly GroupLevel[];
|
|
23
36
|
/** Split by these levels, outermost first; none is no grouping. */
|
|
24
37
|
group: (levels: readonly GroupLevel[]) => void;
|
|
38
|
+
/** The first level's reading. */
|
|
25
39
|
status: "idle" | "loading" | "ready" | "failed";
|
|
40
|
+
/** The groups of the first level read so far — its pages, in order. */
|
|
26
41
|
buckets: readonly Bucket<T>[];
|
|
27
42
|
error: unknown;
|
|
28
|
-
/**
|
|
43
|
+
/** How many groups the first level makes in all; `null` when the server did not say. */
|
|
44
|
+
groupsCount: number | null;
|
|
45
|
+
/** How many records the groups hold in all; `null` when the server did not say. */
|
|
46
|
+
records: number | null;
|
|
47
|
+
/**
|
|
48
|
+
* More groups exist than are read.
|
|
49
|
+
* @deprecated The groups are paged: ask `bringsGroups(null)` and `moreGroups(null)`.
|
|
50
|
+
*/
|
|
29
51
|
capped: boolean;
|
|
30
|
-
/** Read the
|
|
52
|
+
/** Read the next page of groups: of the first level (`null`), or below an open group. */
|
|
53
|
+
moreGroups: (parent: Bucket<T> | null) => void;
|
|
54
|
+
/** What the next `moreGroups` brings: a number of groups, `false` when none are left,
|
|
55
|
+
* `undefined` while the level is unread or nobody counted it — web-ui's `morePiles`. */
|
|
56
|
+
bringsGroups: (parent: Bucket<T> | null) => number | false | undefined;
|
|
57
|
+
/** Whether the group is on the deepest level: it holds rows, not groups. */
|
|
58
|
+
isDeepest: (bucket: Bucket<T>) => boolean;
|
|
59
|
+
/** Whether the person opened it. */
|
|
60
|
+
isOpen: (bucket: Bucket<T>) => boolean;
|
|
61
|
+
/** Opens it and reads what it holds, if not read yet: the level below, or its rows. */
|
|
31
62
|
open: (bucket: Bucket<T>) => void;
|
|
63
|
+
close: (bucket: Bucket<T>) => void;
|
|
64
|
+
toggle: (bucket: Bucket<T>) => void;
|
|
65
|
+
/** The level below a group, once read: its groups so far. `undefined` while unread. */
|
|
66
|
+
groupsOf: (bucket: Bucket<T>) => readonly Bucket<T>[] | undefined;
|
|
67
|
+
/** How many groups the level below makes in all, once read; `null` when nobody counted. */
|
|
68
|
+
groupsCountOf: (bucket: Bucket<T>) => number | null | undefined;
|
|
32
69
|
/** The rows of a group once read; `undefined` while it was never opened or is loading. */
|
|
33
70
|
rowsOf: (bucket: Bucket<T>) => readonly T[] | undefined;
|
|
34
71
|
/** Read the group's next page and append it — on the server's cursor, like the list's «load
|
|
@@ -40,9 +77,14 @@ export type Groups<T> = {
|
|
|
40
77
|
* has no next page, or the ceiling was reached), `undefined` while the group is unread.
|
|
41
78
|
* web-ui's `Pile.more`: «Show 50 more of 49,950», or «Showing 500 of 49,950». */
|
|
42
79
|
brings: (bucket: Bucket<T>) => number | false | undefined;
|
|
80
|
+
/** Why reading what a group holds failed — its level below or its rows —, or `null`. */
|
|
81
|
+
errorOf: (bucket: Bucket<T>) => unknown;
|
|
43
82
|
};
|
|
44
83
|
export declare function useGroups<T extends AnyRecord>(listing: Listing<T>, options?: {
|
|
84
|
+
/** Rows a group reads at a time. 50 by default. */
|
|
45
85
|
pageSize?: number;
|
|
86
|
+
/** Groups a level reads at a time — 80 by default, as Odoo's grouped list. */
|
|
87
|
+
groupPageSize?: number;
|
|
46
88
|
/** The fields each group adds up, over every row of it (`detailOf` reads them). Without
|
|
47
89
|
* it, the figures the model computes (`sumsOf`); `[]` adds nothing up. */
|
|
48
90
|
sums?: readonly string[];
|