@sincpro/web-framework 3.12.0 → 3.12.1
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/list.d.ts
CHANGED
|
@@ -70,6 +70,15 @@ export type NamedFilter<T> = {
|
|
|
70
70
|
label: string;
|
|
71
71
|
/** What it keeps, as criteria's `selection`. */
|
|
72
72
|
selection: Expression<T>;
|
|
73
|
+
/**
|
|
74
|
+
* The cuts of one question share a group — «Pedidos», «Trabajando», «Terminados» are values of
|
|
75
|
+
* the same status. Odoo's rule: set together, the filters of a group ADD UP (one chip, «Pedidos
|
|
76
|
+
* o Trabajando»); a group and anything else narrow each other. The panel lists each group
|
|
77
|
+
* apart, in the order declared. Without it, a filter narrows everything else.
|
|
78
|
+
*
|
|
79
|
+
* { id: "running", label: "Trabajando", group: "status", selection: … }
|
|
80
|
+
*/
|
|
81
|
+
group?: string;
|
|
73
82
|
};
|
|
74
83
|
/** One level of a grouping: by which field, and by which cut of time when it is a date. */
|
|
75
84
|
export type GroupLevel = {
|
|
@@ -24,11 +24,14 @@ import type { Listing } from "../../react/useListing.js";
|
|
|
24
24
|
* what opens outside one cannot be used;
|
|
25
25
|
* - the builder walks relations — «Cliente › País» — through the models along the path
|
|
26
26
|
* (`useLoadModel`), and picks the related records themselves;
|
|
27
|
-
* - a named filter is one click; the
|
|
27
|
+
* - a named filter is one click; the ones of one `group` add up in one chip («Pedidos o
|
|
28
|
+
* Trabajando»), as Odoo's; the builder writes what nobody foresaw (all/any/not);
|
|
28
29
|
* - everything put becomes ONE `selection` the SERVER answers (`listing.filter`) — web-ui
|
|
29
30
|
* writes it in criteria's own shape, a filter through a relation included;
|
|
30
31
|
* - with `groups`, «Group by» offers the fields the model says may split the set, and the
|
|
31
|
-
* SERVER counts the groups (`useGroups`)
|
|
32
|
+
* SERVER counts the groups (`useGroups`); how the set is grouped is a facet of the bar too
|
|
33
|
+
* («⧉ Estado › Creado el · mes ×»), so a grouped list never looks ungrouped, and removing
|
|
34
|
+
* the chip ungroups it.
|
|
32
35
|
*
|
|
33
36
|
* <List.Search><EntitySearchBar listing={listing} filters={…} /></List.Search>
|
|
34
37
|
*/
|
|
@@ -5,10 +5,34 @@ import { frameworkCopy } from "../../core/copy.js";
|
|
|
5
5
|
import { groupableOf } from "./groups.js";
|
|
6
6
|
import { useLoadModel, useRecordsBrowser, useSearchRecords, } from "./records.js";
|
|
7
7
|
import { facetsOf, modelOf } from "./search.js";
|
|
8
|
-
import { CriteriaBuilder, describeFilter, Dialog, fillCopy, filterCriteria, GroupingLevels, hasNamed, SearchBar, selectionOf, toggleNamed, useGroupingControl, useSearchSettings, useUiCopy, } from "@sincpro/web-ui";
|
|
8
|
+
import { CriteriaBuilder, describeFilter, Dialog, fillCopy, filterCriteria, filtersOf, GroupingLevels, hasNamed, levelLabeler, levelsOf, SearchBar, selectionOf, toggleNamed, useGroupingControl, useSearchSettings, useUiCopy, withLevels, } from "@sincpro/web-ui";
|
|
9
9
|
import { useEffect, useMemo, useRef, useState } from "react";
|
|
10
10
|
/** No grouping: one constant, so the control is not handed a new array on every render. */
|
|
11
11
|
const NO_LEVELS = [];
|
|
12
|
+
/** The same levels, in the same order: the bar asks to group only when they changed. */
|
|
13
|
+
const sameLevels = (one, other) => one.length === other.length &&
|
|
14
|
+
one.every((level, at) => level.field === other[at]?.field && level.grain === other[at]?.grain);
|
|
15
|
+
/** The named filters as the panel lists them: each `group` apart, in the order declared; the
|
|
16
|
+
* ones without a group together, where the first of them was. */
|
|
17
|
+
function panelOf(filters, isSet) {
|
|
18
|
+
const order = [];
|
|
19
|
+
const by = new Map();
|
|
20
|
+
for (const one of filters) {
|
|
21
|
+
const key = one.group ?? "";
|
|
22
|
+
if (!by.has(key)) {
|
|
23
|
+
by.set(key, []);
|
|
24
|
+
order.push(key);
|
|
25
|
+
}
|
|
26
|
+
by.get(key).push(one);
|
|
27
|
+
}
|
|
28
|
+
return order.map((key) => ({
|
|
29
|
+
options: (by.get(key) ?? []).map((one) => ({
|
|
30
|
+
id: one.id,
|
|
31
|
+
label: one.label,
|
|
32
|
+
checked: isSet(one.id),
|
|
33
|
+
})),
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
12
36
|
export function EntitySearchBar({ listing, filters = [], groups, groupable: only, facets: named, seed, recentKey, }) {
|
|
13
37
|
const copy = frameworkCopy().list;
|
|
14
38
|
const { meta, locale } = listing;
|
|
@@ -45,6 +69,13 @@ export function EntitySearchBar({ listing, filters = [], groups, groupable: only
|
|
|
45
69
|
// Once the definition is known; what the person changes afterwards is theirs.
|
|
46
70
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
47
71
|
}, [meta, seed]);
|
|
72
|
+
// How a level reads in the bar's chain: the field's label, and its grain for a date.
|
|
73
|
+
const levelName = useMemo(() => levelLabeler(groupableOf(meta, locale)), [meta, locale]);
|
|
74
|
+
const levels = groups?.levels ?? NO_LEVELS;
|
|
75
|
+
// What the bar draws: how the set is grouped (always first), then what narrows it.
|
|
76
|
+
const shown = useMemo(() => (groups === undefined ? put : withLevels(put, levels, levelName)),
|
|
77
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
78
|
+
[put, levels, levelName, groups === undefined]);
|
|
48
79
|
const control = useGroupingControl({
|
|
49
80
|
levels: groups?.levels ?? NO_LEVELS,
|
|
50
81
|
onLevelsChange: (next) => groups?.group(next),
|
|
@@ -55,20 +86,19 @@ export function EntitySearchBar({ listing, filters = [], groups, groupable: only
|
|
|
55
86
|
setPut(next);
|
|
56
87
|
listing.filter(selectionOf(next));
|
|
57
88
|
};
|
|
89
|
+
// A change made in the bar: the grouping chain to the grouping, the rest to the filter.
|
|
90
|
+
const changed = (next) => {
|
|
91
|
+
const asked = levelsOf(next);
|
|
92
|
+
if (groups !== undefined && !sameLevels(asked, levels))
|
|
93
|
+
groups.group(asked);
|
|
94
|
+
place(filtersOf(next));
|
|
95
|
+
};
|
|
58
96
|
// What the bar holds, as one selection: what the builder opens on.
|
|
59
97
|
const current = selectionOf(put);
|
|
60
|
-
return (_jsxs(_Fragment, { children: [_jsx(SearchBar, { facets: facets, model: asked ?? model, criteria:
|
|
98
|
+
return (_jsxs(_Fragment, { children: [_jsx(SearchBar, { facets: facets, model: asked ?? model, criteria: shown, onCriteriaChange: changed, placeholder: copy.searchBar, searchRecords: searchRecords, ...(browseRecords === null ? {} : { browseRecords }), ...(filters.length === 0
|
|
61
99
|
? {}
|
|
62
100
|
: {
|
|
63
|
-
filters:
|
|
64
|
-
{
|
|
65
|
-
options: filters.map((one) => ({
|
|
66
|
-
id: one.id,
|
|
67
|
-
label: one.label,
|
|
68
|
-
checked: hasNamed(put, one.id),
|
|
69
|
-
})),
|
|
70
|
-
},
|
|
71
|
-
],
|
|
101
|
+
filters: panelOf(filters, (id) => hasNamed(put, id)),
|
|
72
102
|
onFilterSelect: (id) => {
|
|
73
103
|
const named = filters.find((one) => one.id === id);
|
|
74
104
|
if (named !== undefined)
|
|
@@ -76,7 +106,8 @@ export function EntitySearchBar({ listing, filters = [], groups, groupable: only
|
|
|
76
106
|
id: named.id,
|
|
77
107
|
label: named.label,
|
|
78
108
|
selection: named.selection,
|
|
79
|
-
|
|
109
|
+
...(named.group === undefined ? {} : { group: named.group }),
|
|
110
|
+
}, { or: ui.search.or }));
|
|
80
111
|
},
|
|
81
112
|
}), ...(groups === undefined || groupable.length === 0
|
|
82
113
|
? {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sincpro/web-framework",
|
|
3
|
-
"version": "3.12.
|
|
3
|
+
"version": "3.12.1",
|
|
4
4
|
"description": "The web client of sincpro_framework: entities, lists and records bound to the metadata the server publishes, drawn with @sincpro/web-ui and arranged with @sincpro/web-composer.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"@sincpro/criteria": "^2.4.0",
|
|
56
56
|
"@sincpro/criteria-react": "^2.4.0",
|
|
57
57
|
"@sincpro/web-composer": "^1.7.0",
|
|
58
|
-
"@sincpro/web-ui": "^2.14.
|
|
58
|
+
"@sincpro/web-ui": "^2.14.1",
|
|
59
59
|
"react": ">=19",
|
|
60
60
|
"react-dom": ">=19"
|
|
61
61
|
},
|
|
@@ -99,7 +99,7 @@
|
|
|
99
99
|
"@sincpro/criteria": "^2.5.0",
|
|
100
100
|
"@sincpro/criteria-react": "^2.5.0",
|
|
101
101
|
"@sincpro/web-composer": "^1.9.0",
|
|
102
|
-
"@sincpro/web-ui": "^2.14.
|
|
102
|
+
"@sincpro/web-ui": "^2.14.1",
|
|
103
103
|
"@storybook/addon-a11y": "10.6.5",
|
|
104
104
|
"@storybook/addon-docs": "10.6.5",
|
|
105
105
|
"@storybook/addon-mcp": "10.6.5",
|