@sincpro/web-ui 2.0.0 → 2.1.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/components/activity/Activity.d.ts +13 -14
- package/dist/components/activity/Activity.js +1 -1
- package/dist/components/activity/Messages.d.ts +5 -5
- package/dist/components/activity/Messages.js +8 -8
- package/dist/components/form/Form.js +6 -6
- package/dist/components/form/index.js +2 -2
- package/dist/components/frame/FrameView.d.ts +5 -5
- package/dist/components/frame/FrameView.js +4 -4
- package/dist/components/listing/GroupingLevels.d.ts +22 -22
- package/dist/components/listing/GroupingLevels.js +9 -9
- package/dist/components/listing/Listing.d.ts +11 -11
- package/dist/components/listing/Listing.js +11 -11
- package/dist/components/listing/ListingBar.js +11 -11
- package/dist/components/listing/Row.d.ts +19 -19
- package/dist/components/listing/Row.js +25 -25
- package/dist/components/listing/SortMenu.d.ts +36 -36
- package/dist/components/listing/SortMenu.js +6 -6
- package/dist/components/listing/grouping.d.ts +16 -16
- package/dist/components/listing/grouping.js +6 -6
- package/dist/components/listing/index.js +1 -1
- package/dist/components/listing/modelColumns.d.ts +25 -25
- package/dist/components/listing/modelColumns.js +24 -24
- package/dist/components/listing/pages.js +4 -4
- package/dist/components/listing/set.d.ts +18 -18
- package/dist/components/navigation/index.js +2 -2
- package/dist/components/record/RecordSkeleton.js +7 -7
- package/dist/components/search/CriteriaBuilder.d.ts +22 -22
- package/dist/components/search/CriteriaBuilder.js +31 -31
- package/dist/components/search/CriteriaChips.d.ts +9 -9
- package/dist/components/search/CriteriaChips.js +12 -12
- package/dist/components/search/FilterBuilder.d.ts +67 -67
- package/dist/components/search/FilterBuilder.js +104 -104
- package/dist/components/search/JoinWord.d.ts +1 -1
- package/dist/components/search/JoinWord.js +14 -14
- package/dist/components/search/JsonEditor.d.ts +8 -8
- package/dist/components/search/JsonEditor.js +16 -16
- package/dist/components/search/SearchBar.d.ts +34 -34
- package/dist/components/search/SearchBar.js +110 -110
- package/dist/components/search/criteria.d.ts +61 -61
- package/dist/components/search/criteria.js +39 -39
- package/dist/components/search/datePeriods.d.ts +47 -48
- package/dist/components/search/datePeriods.js +29 -29
- package/dist/components/search/dateRanges.d.ts +27 -27
- package/dist/components/search/dateRanges.js +16 -16
- package/dist/components/search/index.js +13 -13
- package/dist/components/search/model.d.ts +28 -28
- package/dist/components/search/model.js +21 -21
- package/dist/components/search/query.d.ts +71 -71
- package/dist/components/search/query.js +119 -119
- package/dist/components/shell/AppFrame.js +3 -3
- package/dist/components/shell/index.js +1 -1
- package/dist/foundations/calendar.d.ts +27 -27
- package/dist/foundations/calendar.js +72 -72
- package/dist/foundations/chart.d.ts +57 -57
- package/dist/foundations/chart.js +27 -27
- package/dist/foundations/copy.d.ts +96 -94
- package/dist/foundations/copy.es.js +1 -0
- package/dist/foundations/copy.js +1 -0
- package/dist/foundations/grouping.d.ts +175 -175
- package/dist/foundations/grouping.js +0 -0
- package/dist/foundations/index.d.ts +1 -1
- package/dist/foundations/index.js +21 -21
- package/dist/foundations/pivot.d.ts +133 -131
- package/dist/foundations/pivot.js +54 -54
- package/dist/foundations/pivotSheet.d.ts +36 -36
- package/dist/foundations/pivotSheet.js +0 -0
- package/dist/foundations/slots.d.ts +38 -38
- package/dist/foundations/slots.js +18 -18
- package/dist/foundations/sticky.d.ts +28 -28
- package/dist/foundations/sticky.js +59 -59
- package/dist/foundations/xlsx.d.ts +47 -47
- package/dist/foundations/xlsx.js +0 -0
- package/dist/primitives/block/Line.d.ts +4 -4
- package/dist/primitives/block/Line.js +28 -28
- package/dist/primitives/block/index.js +2 -2
- package/dist/primitives/cell/index.js +2 -2
- package/dist/primitives/choice/index.js +3 -3
- package/dist/primitives/date/Calendar.d.ts +7 -1
- package/dist/primitives/date/Calendar.js +13 -3
- package/dist/primitives/date/DatePicker.d.ts +4 -1
- package/dist/primitives/date/DatePicker.js +2 -2
- package/dist/primitives/date/index.js +3 -3
- package/dist/primitives/disclosure/index.js +1 -1
- package/dist/primitives/menu/Menu.d.ts +3 -3
- package/dist/primitives/notice/Callout.d.ts +30 -30
- package/dist/primitives/notice/Callout.js +6 -6
- package/dist/primitives/overlay/index.js +3 -3
- package/dist/primitives/picker/Picker.d.ts +6 -0
- package/dist/primitives/picker/Picker.js +27 -4
- package/dist/primitives/picker/index.js +2 -2
- package/dist/primitives/table/DataTable.d.ts +32 -32
- package/dist/primitives/table/DataTable.js +24 -24
- package/dist/primitives/table/EditableTable.d.ts +10 -10
- package/dist/primitives/table/EditableTable.js +9 -9
- package/dist/primitives/table/ReportTable.js +7 -7
- package/dist/primitives/table/SheetTable.d.ts +13 -13
- package/dist/primitives/table/SheetTable.js +14 -14
- package/dist/primitives/table/Table.js +8 -8
- package/dist/primitives/tabs/Tabs.d.ts +46 -46
- package/dist/primitives/tabs/Tabs.js +7 -7
- package/dist/primitives/tag/index.js +2 -2
- package/dist/primitives/toolbar/index.js +1 -1
- package/dist/primitives/value/Copyable.d.ts +22 -22
- package/dist/primitives/value/Copyable.js +9 -9
- package/dist/tokens.css +17 -17
- package/dist/views/list/List.d.ts +36 -36
- package/dist/views/list/List.js +19 -19
- package/dist/views/list/ListView.js +74 -74
- package/dist/views/list/columns.d.ts +10 -10
- package/dist/views/list/columns.js +10 -10
- package/dist/views/list/derive.d.ts +30 -30
- package/dist/views/list/derive.js +49 -49
- package/dist/views/list/index.js +2 -2
- package/dist/views/list/presentations.js +3 -3
- package/dist/views/list/types.d.ts +109 -109
- package/dist/views/record/Record.d.ts +14 -14
- package/dist/views/record/Record.js +24 -24
- package/dist/views/record/index.js +1 -1
- package/package.json +1 -1
|
@@ -4,23 +4,23 @@ export interface BuiltSort {
|
|
|
4
4
|
field: string;
|
|
5
5
|
descending?: boolean;
|
|
6
6
|
}
|
|
7
|
-
/**
|
|
7
|
+
/** A grouping level, like criteria's `Level`: the field and, if it is a date, the grain. */
|
|
8
8
|
export interface BuiltLevel {
|
|
9
9
|
field: string;
|
|
10
10
|
grain?: string | null;
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
14
|
-
* `{ function: "sum", field: "row_count" }`.
|
|
15
|
-
*
|
|
13
|
+
* A number that each heap answers, like criteria's `Measure`:
|
|
14
|
+
* `{ function: "sum", field: "row_count" }`. Named parts and not a pair, just as a
|
|
15
|
+
* condition travels as `{field, operator, value}`.
|
|
16
16
|
*/
|
|
17
17
|
export interface BuiltMeasure {
|
|
18
18
|
function: string;
|
|
19
19
|
field: string;
|
|
20
|
-
/**
|
|
20
|
+
/** What the function needs besides the field. Only `percentile`: the cut's fraction. */
|
|
21
21
|
argument?: number;
|
|
22
22
|
}
|
|
23
|
-
/**
|
|
23
|
+
/** From where a page of heaps starts — the same shape as the rows' pagination. */
|
|
24
24
|
export type BuiltPageStrategy = {
|
|
25
25
|
token: string | null;
|
|
26
26
|
} | {
|
|
@@ -30,23 +30,23 @@ export interface BuiltGroupPagination {
|
|
|
30
30
|
limit?: number;
|
|
31
31
|
strategy?: BuiltPageStrategy;
|
|
32
32
|
}
|
|
33
|
-
/**
|
|
33
|
+
/** The grouping as `@sincpro/criteria` 2.0 declares it, key by key. */
|
|
34
34
|
export interface BuiltGrouping {
|
|
35
|
-
/**
|
|
35
|
+
/** The levels, in order: they are not added, they nest. */
|
|
36
36
|
group_by?: BuiltLevel[];
|
|
37
|
-
/**
|
|
37
|
+
/** The numbers each heap answers, each under a chosen name. */
|
|
38
38
|
measures?: Record<string, BuiltMeasure>;
|
|
39
|
-
/**
|
|
40
|
-
*
|
|
39
|
+
/** A filter on what the heaps measured, not on the rows: `count > 10`. The
|
|
40
|
+
* names it admits are those of `measures`, plus `"count"`. */
|
|
41
41
|
where_measures?: BuiltFilter;
|
|
42
|
-
/**
|
|
43
|
-
* `measures`,
|
|
42
|
+
/** In what order the heaps come back: by the level's own field, by a name from
|
|
43
|
+
* `measures`, or by `count`. */
|
|
44
44
|
order?: BuiltSort[];
|
|
45
|
-
/**
|
|
45
|
+
/** How many heaps of the first level come back, and from where. Absent is all of them. */
|
|
46
46
|
pagination?: BuiltGroupPagination;
|
|
47
47
|
}
|
|
48
|
-
/**
|
|
49
|
-
*
|
|
48
|
+
/** The criteria as the engine declares it. It is what this component builds and returns, and what
|
|
49
|
+
* the code editor shows. */
|
|
50
50
|
export interface BuiltCriteria {
|
|
51
51
|
selection?: BuiltFilter;
|
|
52
52
|
order?: BuiltSort[];
|
|
@@ -55,15 +55,15 @@ export interface BuiltCriteria {
|
|
|
55
55
|
}
|
|
56
56
|
export declare function CriteriaBuilder({ model, initial, focus, onApply, onCancel, }: {
|
|
57
57
|
model: ModelDefinition;
|
|
58
|
-
/**
|
|
58
|
+
/** The criteria that was already set. Reopening has to continue where it was left. */
|
|
59
59
|
initial?: BuiltCriteria;
|
|
60
60
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
61
|
+
* The condition's field to show first: the chip somebody
|
|
62
|
+
* touched in the bar.
|
|
63
63
|
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
64
|
+
* Without this, touching a cut opened the builder on rule one and you had to
|
|
65
|
+
* search among twelve for the one you were looking at — which is the quickest way to
|
|
66
|
+
* edit the wrong one.
|
|
67
67
|
*/
|
|
68
68
|
focus?: string;
|
|
69
69
|
onApply: (criteria: BuiltCriteria | undefined) => void;
|
|
@@ -12,22 +12,22 @@ import { Tags } from "../../primitives/tag/Tags.js";
|
|
|
12
12
|
import { Plus, Trash2 } from "lucide-react";
|
|
13
13
|
import { Fragment, useMemo, useState } from "react";
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
15
|
+
* A date's cuts, from COARSE to fine, with `null` first: with no cut, a
|
|
16
|
+
* date field splits by instant and every row ends up in its own heap.
|
|
17
17
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
18
|
+
* The order is not a preference — a whole day lives inside a single month— and
|
|
19
|
+
* it is the same one `GRAIN_ORDER` publishes for the bar: a single direction for
|
|
20
|
+
* both screens. A level's chip rotates through this list.
|
|
21
21
|
*/
|
|
22
22
|
const GRAINS = [null, ...GRAIN_ORDER];
|
|
23
|
-
/**
|
|
23
|
+
/** Which types admit a grain: cutting a text by month means nothing. */
|
|
24
24
|
const DATE_TYPES = new Set(["date", "datetime"]);
|
|
25
|
-
/**
|
|
26
|
-
* `where_measures`:
|
|
27
|
-
* `is null`
|
|
25
|
+
/** The operators that a measure —always a number— or `count` admit in a
|
|
26
|
+
* `where_measures`: the same ones the model definition publishes for a numeric field,
|
|
27
|
+
* `is null` aside, which means nothing on a number the engine itself computed. */
|
|
28
28
|
const COMPARABLE = ["=", "!=", ">", ">=", "<", "<=", "between"];
|
|
29
|
-
/**
|
|
30
|
-
*
|
|
29
|
+
/** The functions a measure can ask for here, closed on the server side because the
|
|
30
|
+
* name reaches SQL. */
|
|
31
31
|
const MEASURE_FUNCTIONS = ["sum", "avg", "min", "max", "count"];
|
|
32
32
|
function isEmpty(criteria) {
|
|
33
33
|
return (criteria.selection === undefined &&
|
|
@@ -36,8 +36,8 @@ function isEmpty(criteria) {
|
|
|
36
36
|
Object.keys(criteria.grouping?.measures ?? {}).length === 0 &&
|
|
37
37
|
Object.keys(criteria.specification ?? {}).length === 0);
|
|
38
38
|
}
|
|
39
|
-
/**
|
|
40
|
-
*
|
|
39
|
+
/** The `where_measures` editor's tree: what was read, wrapped in a group if it is a single
|
|
40
|
+
* condition, or a blank one over `count` if there is nothing to read. */
|
|
41
41
|
function measuresTreeOf(filter, model) {
|
|
42
42
|
const node = filter === undefined ? null : treeFromFilter(filter);
|
|
43
43
|
if (node === null)
|
|
@@ -45,12 +45,12 @@ function measuresTreeOf(filter, model) {
|
|
|
45
45
|
return node.kind === "group" ? node : { kind: "group", join: "all", children: [node] };
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
48
|
-
*
|
|
48
|
+
* THE CHIP THAT ADDS: a «+» that opens the list of what can be chosen.
|
|
49
49
|
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
50
|
+
* It is the same as what the hash sign does in the bar, and for the same reason: choosing
|
|
51
|
+
* among twenty fields is choosing from a LIST, not unfolding a `<select>` that already
|
|
52
|
+
* comes with one set and has to be changed. With the `<select>`, adding a
|
|
53
|
+
* level put the model's first field even though nobody had asked for it.
|
|
54
54
|
*/
|
|
55
55
|
function AddTag({ label, options, onPick, }) {
|
|
56
56
|
const [open, setOpen] = useState(false);
|
|
@@ -65,7 +65,7 @@ function AddTag({ label, options, onPick, }) {
|
|
|
65
65
|
},
|
|
66
66
|
})) }) })) : null] }));
|
|
67
67
|
}
|
|
68
|
-
/**
|
|
68
|
+
/** The next cut, and back to the start. */
|
|
69
69
|
function nextGrain(grain) {
|
|
70
70
|
const at = GRAINS.indexOf(grain ?? null);
|
|
71
71
|
return GRAINS[(at + 1) % GRAINS.length] ?? null;
|
|
@@ -73,8 +73,8 @@ function nextGrain(grain) {
|
|
|
73
73
|
export function CriteriaBuilder({ model, initial, focus, onApply, onCancel, }) {
|
|
74
74
|
const surface = useSurface();
|
|
75
75
|
const names = Object.keys(model.fields).sort();
|
|
76
|
-
/*
|
|
77
|
-
(`ops`
|
|
76
|
+
/* Never a relational nor a value-object: neither has a comparison of its own
|
|
77
|
+
(empty `ops`), so neither serves as a target for a filter, an order or a level. */
|
|
78
78
|
const scalarNames = filterableNames(model);
|
|
79
79
|
const sortable = names.filter((name) => model.fields[name]?.sortable === true);
|
|
80
80
|
const decomposed = initial?.selection === undefined ? null : treeFromFilter(initial.selection);
|
|
@@ -90,10 +90,10 @@ export function CriteriaBuilder({ model, initial, focus, onApply, onCancel, }) {
|
|
|
90
90
|
const [measures, setMeasures] = useState(initial?.grouping?.measures ?? {});
|
|
91
91
|
const [groupOrder, setGroupOrder] = useState(initial?.grouping?.order ?? []);
|
|
92
92
|
const [groupLimit, setGroupLimit] = useState(initial?.grouping?.pagination?.limit);
|
|
93
|
-
/* `where_measures`
|
|
94
|
-
|
|
95
|
-
`SelectionTree`
|
|
96
|
-
|
|
93
|
+
/* `where_measures` is a filter like any other, over a synthetic model whose only
|
|
94
|
+
fields are the names it admits: those of `measures`, plus `count`. Reusing
|
|
95
|
+
`SelectionTree` over that model is simpler and more correct than building a separate
|
|
96
|
+
conditions editor. */
|
|
97
97
|
const measuresModel = useMemo(() => ({
|
|
98
98
|
aggregate: "where_measures",
|
|
99
99
|
identity: "count",
|
|
@@ -109,7 +109,7 @@ export function CriteriaBuilder({ model, initial, focus, onApply, onCancel, }) {
|
|
|
109
109
|
const [fields, setFields] = useState(Object.keys(initial?.specification ?? {}));
|
|
110
110
|
const [rawText, setRawText] = useState(() => initial === undefined ? "" : JSON.stringify(initial, null, 2));
|
|
111
111
|
const [rawError, setRawError] = useState(null);
|
|
112
|
-
/**
|
|
112
|
+
/** What the controls say, together: it is what is applied and what the JSON shows. */
|
|
113
113
|
function assemble(next) {
|
|
114
114
|
const selection = next.locked ?? lockedSelection ?? treeToFilter(next.tree ?? tree);
|
|
115
115
|
const sorts = next.order ?? order;
|
|
@@ -119,9 +119,9 @@ export function CriteriaBuilder({ model, initial, focus, onApply, onCancel, }) {
|
|
|
119
119
|
const groupSorts = next.groupOrder ?? groupOrder;
|
|
120
120
|
const limit = "groupLimit" in next ? next.groupLimit : groupLimit;
|
|
121
121
|
const chosen = next.fields ?? fields;
|
|
122
|
-
/*
|
|
123
|
-
|
|
124
|
-
|
|
122
|
+
/* Without levels there is nothing to measure, nothing to filter between heaps, nor in what order or page
|
|
123
|
+
they would come back — a measure, a `where_measures` or a page set and then emptied of
|
|
124
|
+
levels must not survive loose in the criteria that is sent. */
|
|
125
125
|
const grouping = groupBy.length === 0
|
|
126
126
|
? {}
|
|
127
127
|
: {
|
|
@@ -142,7 +142,7 @@ export function CriteriaBuilder({ model, initial, focus, onApply, onCancel, }) {
|
|
|
142
142
|
}),
|
|
143
143
|
};
|
|
144
144
|
}
|
|
145
|
-
/*
|
|
145
|
+
/* Touching any control rewrites the whole JSON: the two views are the same criteria. */
|
|
146
146
|
function push(next) {
|
|
147
147
|
if (next.tree !== undefined)
|
|
148
148
|
setTree(next.tree);
|
|
@@ -166,7 +166,7 @@ export function CriteriaBuilder({ model, initial, focus, onApply, onCancel, }) {
|
|
|
166
166
|
setRawText(isEmpty(built) ? "" : JSON.stringify(built, null, 2));
|
|
167
167
|
setRawError(null);
|
|
168
168
|
}
|
|
169
|
-
/*
|
|
169
|
+
/* Writing the JSON rebuilds the controls, as long as what was written is a criteria. */
|
|
170
170
|
function updateRaw(text) {
|
|
171
171
|
setRawText(text);
|
|
172
172
|
if (text.trim() === "") {
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { type CriteriaJoin, type CriteriaPath, type SearchCriteria } from "./criteria.js";
|
|
2
2
|
import type { Surface } from "../../foundations/types.js";
|
|
3
3
|
export type CriteriaChipsProps = {
|
|
4
|
-
/**
|
|
4
|
+
/** What the bar has set. Groups and filters mixed: here they are separated. */
|
|
5
5
|
criteria: readonly SearchCriteria[];
|
|
6
|
-
/**
|
|
6
|
+
/** Open the builder on an instance. */
|
|
7
7
|
onOpen?: (path: CriteriaPath) => void;
|
|
8
|
-
/**
|
|
8
|
+
/** Change how a node's ones are joined. */
|
|
9
9
|
onJoin?: (path: CriteriaPath, join: CriteriaJoin) => void;
|
|
10
|
-
/**
|
|
10
|
+
/** Remove an instance, or a whole branch. */
|
|
11
11
|
onRemove?: (path: CriteriaPath) => void;
|
|
12
|
-
/**
|
|
12
|
+
/** Remove several at once: the × of the grouping chain drops every level. */
|
|
13
13
|
onRemoveMany?: (paths: readonly CriteriaPath[]) => void;
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* Which node is OPEN: where the next thing written will land.
|
|
16
16
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
17
|
+
* It is marked because otherwise, writing `#and` and then a condition puts it in a
|
|
18
|
+
* place nobody chose by looking: the group exists, the condition goes in, and the
|
|
19
|
+
* only one who knew where it was is the one who wrote it.
|
|
20
20
|
*/
|
|
21
21
|
open?: CriteriaPath;
|
|
22
22
|
/** How many facets show before the rest fold into «+N» (the grouping chain counts as one).
|
|
@@ -12,9 +12,9 @@ export function CriteriaChips({ criteria, onOpen, onJoin, onRemove, onRemoveMany
|
|
|
12
12
|
const [expanded, setExpanded] = useState(false);
|
|
13
13
|
const groups = groupsOf(criteria);
|
|
14
14
|
const filters = filtersOf(criteria);
|
|
15
|
-
/*
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
/* The path is counted over the WHOLE list and not over the drawn half: it is the
|
|
16
|
+
instance's identity, and an identity that changes depending on which side
|
|
17
|
+
you look at it from identifies nothing. */
|
|
18
18
|
const pathOf = (one) => [
|
|
19
19
|
criteria.findIndex((each) => each.id === one.id),
|
|
20
20
|
];
|
|
@@ -81,26 +81,26 @@ function GroupChain({ groups, onOpen, onRemoveMany, surface, }) {
|
|
|
81
81
|
function Node({ node, path, onOpen, onJoin, onRemove, open, surface, }) {
|
|
82
82
|
const copy = useUiCopy();
|
|
83
83
|
if (node.kind !== "join") {
|
|
84
|
-
/*
|
|
85
|
-
|
|
86
|
-
|
|
84
|
+
/* An instance that carries no expression has nothing to edit: the builder
|
|
85
|
+
edits what TRAVELS, and this one is answered by whoever declared it. It is seen and removed
|
|
86
|
+
like any other; what it does not do is promise a door that opens onto nothing. */
|
|
87
87
|
const editable = node.kind === "group" || node.selection !== undefined;
|
|
88
88
|
return (_jsx(Chip, { label: node.label, path: path, ...(onOpen === undefined || !editable ? {} : { onOpen }), ...(onRemove === undefined ? {} : { onRemove }), surface: surface }));
|
|
89
89
|
}
|
|
90
|
-
/*
|
|
91
|
-
|
|
90
|
+
/* The open node is marked: it is where the next thing will land. A ring and not a
|
|
91
|
+
background, because inside there are chips that already have their own. */
|
|
92
92
|
const isOpen = open !== undefined && open.join(".") === path.join(".");
|
|
93
93
|
return (_jsxs("span", { className: `inline-flex min-w-0 flex-wrap items-center gap-1 rounded-control border px-1.5 py-0.5 ${bySurface(surface, "border-line bg-ink/4", "border-chrome-ink/25 bg-chrome-ink/8")} ${isOpen ? "ring-1 ring-primary/60" : ""}`, children: [_jsx(JoinWord, { join: node.join, ...(onJoin === undefined ? {} : { onChange: (next) => onJoin(path, next) }), surface: surface }), node.of.length === 0 ? (
|
|
94
|
-
/*
|
|
95
|
-
|
|
94
|
+
/* A newly opened node has nothing inside, and an empty bracket reads
|
|
95
|
+
as an error. It says it is waiting. */
|
|
96
96
|
_jsx("span", { className: `shrink-0 text-micro italic ${bySurface(surface, "text-muted", "text-chrome-muted")}`, children: copy.search.landsHere })) : null, node.of.map((child, at) => (_jsx(Node, { node: child, path: [...path, at], ...(onOpen === undefined ? {} : { onOpen }), ...(onJoin === undefined ? {} : { onJoin }), ...(onRemove === undefined ? {} : { onRemove }), ...(open === undefined ? {} : { open }), surface: surface }, child.id)))] }));
|
|
97
97
|
}
|
|
98
98
|
function Chip({ label, path, onOpen, onRemove, surface, }) {
|
|
99
99
|
const copy = useUiCopy();
|
|
100
100
|
const shell = `inline-flex min-w-0 max-w-(--container-facet) items-center gap-1 rounded-pill border py-0.5 text-micro ${bySurface(surface, "border-accent/40 bg-accent/18 text-ink", "border-chrome-link/35 bg-chrome-link/18 text-chrome-link")} ${onRemove === undefined ? "px-2" : "pr-0.5 pl-2"}`;
|
|
101
101
|
const remove = onRemove === undefined ? null : (_jsx("button", { type: "button", onClick: (event) => {
|
|
102
|
-
/*
|
|
103
|
-
|
|
102
|
+
/* Without this, removing it also opens it: the click arrives here and then
|
|
103
|
+
bubbles up. */
|
|
104
104
|
event.stopPropagation();
|
|
105
105
|
onRemove(path);
|
|
106
106
|
}, "aria-label": copy.search.removeFilter.replace("{label}", label), className: `inline-flex size-4 shrink-0 items-center justify-center rounded-pill transition-colors duration-(--duration-instant) ${bySurface(surface, "hover:bg-primary/20", "hover:bg-chrome-link/25")}`, children: _jsx(X, { className: "size-3", strokeWidth: 2.5 }) }));
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { BuiltFilter, CriteriaJoin, ThroughMatch } from "./criteria.js";
|
|
2
2
|
import { type ModelDefinition } from "./model.js";
|
|
3
3
|
import { type LoadModel, type ModelCache } from "./paths.js";
|
|
4
|
-
/**
|
|
5
|
-
* `negate
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
/** Whether this is one of the shapes the filter recognises — condition, or `all`/`any`/
|
|
5
|
+
* `negate` group. A valid JSON that is none of these —`{}`, `{"foo": 1}`, a loose array—
|
|
6
|
+
* is not a filter this component knows how to draw, and is treated as a shape error instead of
|
|
7
|
+
* trying to show anything at all. */
|
|
8
8
|
export declare function isRecognizedFilter(value: unknown): value is BuiltFilter;
|
|
9
9
|
/** One relation crossed on the way to a condition's field: «Líneas», and how many of the
|
|
10
10
|
* lines have to match. Whether the relation reaches many is the MODEL's to say, not the
|
|
@@ -24,55 +24,55 @@ export interface TreeCondition {
|
|
|
24
24
|
field: string;
|
|
25
25
|
operator: string;
|
|
26
26
|
value: string;
|
|
27
|
-
/**
|
|
28
|
-
*
|
|
27
|
+
/** The other end, for the operators that compare against two —today `between`—. Empty in
|
|
28
|
+
* all the others, where it means nothing. */
|
|
29
29
|
upper?: string;
|
|
30
30
|
}
|
|
31
31
|
export interface TreeGroup {
|
|
32
32
|
kind: "group";
|
|
33
|
-
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
33
|
+
/** All, any, or NONE. All three, and the same as the bar's: negating
|
|
34
|
+
* something could only be written in the JSON, and a question the editor does not
|
|
35
|
+
* know how to build is a question most people will not ask. */
|
|
36
36
|
join: CriteriaJoin;
|
|
37
37
|
children: TreeNode[];
|
|
38
38
|
}
|
|
39
39
|
export type TreeNode = TreeCondition | TreeGroup;
|
|
40
40
|
export declare function blankCondition(model: ModelDefinition, first: string | undefined): TreeCondition;
|
|
41
41
|
export declare function blankGroup(model: ModelDefinition, first: string | undefined): TreeGroup;
|
|
42
|
-
/**
|
|
42
|
+
/** The tree as the filter that travels.
|
|
43
43
|
*
|
|
44
|
-
* in
|
|
45
|
-
* out
|
|
44
|
+
* in a lone condition
|
|
45
|
+
* out that condition, unwrapped
|
|
46
46
|
*
|
|
47
|
-
* in
|
|
47
|
+
* in group with two children, join «any»
|
|
48
48
|
* out {any: [ … , … ]}
|
|
49
49
|
*
|
|
50
|
-
*
|
|
51
|
-
* «todas»
|
|
52
|
-
*
|
|
53
|
-
*
|
|
50
|
+
* A group with a single child is not wrapped —it is that child—, and a group with no children disappears: neither
|
|
51
|
+
* an empty «todas» nor «cualquiera» is a filter anybody asked for. The rule holds at any
|
|
52
|
+
* level, not only at the root, so nesting a single-condition group is the same as not
|
|
53
|
+
* having nested it. */
|
|
54
54
|
export declare function treeToFilter(node: TreeNode): BuiltFilter | undefined;
|
|
55
|
-
/**
|
|
55
|
+
/** The filter read back into a tree.
|
|
56
56
|
*
|
|
57
57
|
* in {field: "name", operator: "=", value: "labs"}
|
|
58
58
|
* out TreeCondition
|
|
59
59
|
*
|
|
60
|
-
* in {any: [{all: [cond1, cond2]}, cond3]}
|
|
61
|
-
* out TreeGroup(any)
|
|
60
|
+
* in {any: [{all: [cond1, cond2]}, cond3]} group inside a group
|
|
61
|
+
* out TreeGroup(any) with a TreeGroup(all) and a condition as children
|
|
62
62
|
*
|
|
63
63
|
* in {negate: {any: [cond1, cond2]}}
|
|
64
|
-
* out TreeGroup(not)
|
|
64
|
+
* out TreeGroup(not) with the two conditions as children
|
|
65
65
|
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
66
|
+
* An `any`'s `negate` opens into the «ninguna» group and does not stay as a group
|
|
67
|
+
* inside another: it is what `treeToFilter` writes back, so there and
|
|
68
|
+
* back give the same. What can NOT be read —an object that is neither a
|
|
69
|
+
* condition nor any of the three shapes— returns `null`, and there the component
|
|
70
|
+
* shows it read-only while still letting you touch it as JSON.
|
|
71
71
|
*/
|
|
72
72
|
export declare function treeFromFilter(filter: unknown): TreeNode | null;
|
|
73
|
-
/**
|
|
73
|
+
/** The filter said in one line, for a chip or a label.
|
|
74
74
|
*
|
|
75
|
-
* in {field: "row_count", operator: ">", value: 1000},
|
|
75
|
+
* in {field: "row_count", operator: ">", value: 1000}, with the model
|
|
76
76
|
* out 'filas mayor que 1000'
|
|
77
77
|
*
|
|
78
78
|
* in {all: [cond1, cond2]}
|
|
@@ -81,35 +81,35 @@ export declare function treeFromFilter(filter: unknown): TreeNode | null;
|
|
|
81
81
|
* in {any: [cond1, cond2]}
|
|
82
82
|
* out 'el nombre es a o el nombre es b'
|
|
83
83
|
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
84
|
+
* Each condition is said by `sayCondition`, which is the same one the bar uses: without
|
|
85
|
+
* that, what is written in the bar and what is built in the dialog read differently even though
|
|
86
|
+
* they filter the same, and nobody knows which of the two phrases is the one in charge.
|
|
87
87
|
*
|
|
88
|
-
* **
|
|
89
|
-
*
|
|
90
|
-
*
|
|
88
|
+
* **The model is the one that knows what a field is called.** Without it the raw
|
|
89
|
+
* name remains —`row_count`—, which is the best that can be said without asking
|
|
90
|
+
* anybody.
|
|
91
91
|
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
92
|
+
* A nested group is enclosed in parentheses, which is what keeps «a y (b o c)» from being
|
|
93
|
+
* read as «(a y b) o c». Past three conditions it is cut: a chip that does not fit in
|
|
94
|
+
* the bar says nothing — that is what opening the builder and seeing it whole is for. */
|
|
95
95
|
export declare function describeFilter(node: BuiltFilter, model?: ModelDefinition,
|
|
96
96
|
/** The model at the end of a path of relations, when it already arrived: it names the
|
|
97
97
|
* fields of a `through`. Without it they keep their raw names. */
|
|
98
98
|
modelAt?: (path: readonly string[]) => ModelDefinition | undefined): string;
|
|
99
|
-
/**
|
|
100
|
-
*
|
|
99
|
+
/** The filter drawn as it is, recursive: a condition is a line, `all`/`any` are a
|
|
100
|
+
* group with its label and its children inside, `negate` is «no» wrapping the one it negates.
|
|
101
101
|
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
102
|
+
* It is the read-only half of this file, and it also works alone: showing what a
|
|
103
|
+
* filter that is already set says does not need opening the builder. */
|
|
104
104
|
export declare function ExpressionView({ node, model, depth, modelAt, at, }: {
|
|
105
105
|
node: BuiltFilter;
|
|
106
|
-
/**
|
|
106
|
+
/** Who knows what a field is called. Without it the raw name remains. */
|
|
107
107
|
model?: ModelDefinition;
|
|
108
108
|
depth?: number;
|
|
109
|
-
/**
|
|
109
|
+
/** The model at the end of a path of relations, if it has arrived: it names the fields of a
|
|
110
110
|
* `through`. */
|
|
111
111
|
modelAt?: (path: readonly string[]) => ModelDefinition | undefined;
|
|
112
|
-
/**
|
|
112
|
+
/** The path up to here (through the outer `through`s). */
|
|
113
113
|
at?: readonly string[];
|
|
114
114
|
}): import("react").JSX.Element;
|
|
115
115
|
export declare function SelectionTree({ model, group, onChange, depth, focus, loadModel, models: shared, }: {
|
|
@@ -118,41 +118,41 @@ export declare function SelectionTree({ model, group, onChange, depth, focus, lo
|
|
|
118
118
|
onChange: (next: TreeGroup) => void;
|
|
119
119
|
depth?: number;
|
|
120
120
|
/**
|
|
121
|
-
*
|
|
122
|
-
*
|
|
121
|
+
* The condition's field to show FIRST: the one somebody touched in
|
|
122
|
+
* the bar.
|
|
123
123
|
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
124
|
+
* Without this, touching a chip opened the builder on rule one and you had to
|
|
125
|
+
* search among twelve for the one you were looking at — which is the quickest way to
|
|
126
|
+
* edit the wrong one. It is marked and brought into view; it does not open in a different
|
|
127
|
+
* mode, because the builder is the same.
|
|
128
128
|
*
|
|
129
|
-
*
|
|
129
|
+
* It marks at ANY depth: the tree passes it to the groups it nests.
|
|
130
130
|
*
|
|
131
|
-
* **
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
131
|
+
* **It is a field name, not a path**, so two conditions on the
|
|
132
|
+
* same field in different branches are both marked and the view goes to the first.
|
|
133
|
+
* Telling them apart requires the tree and the bar's instances to share
|
|
134
|
+
* identity, and today they do not: `selectionOf` builds the filter skipping the
|
|
135
|
+
* levels and what does not travel, so the position in one is not the position in
|
|
136
|
+
* the other.
|
|
137
137
|
*/
|
|
138
138
|
focus?: string;
|
|
139
|
-
/**
|
|
140
|
-
*
|
|
139
|
+
/** The model at the end of a path of relations. With this, each rule's field can
|
|
140
|
+
* be one from a related record («Líneas > Impuestos > Monto»). */
|
|
141
141
|
loadModel?: LoadModel;
|
|
142
|
-
/**
|
|
142
|
+
/** The model cache the rules share. The outer tree builds it. */
|
|
143
143
|
models?: ModelCache;
|
|
144
144
|
}): import("react").JSX.Element;
|
|
145
145
|
export declare function FilterBuilder({ model, initial, onApply, onCancel, loadModel, models: shared, }: {
|
|
146
146
|
model: ModelDefinition;
|
|
147
|
-
/**
|
|
148
|
-
*
|
|
149
|
-
* web-ui
|
|
147
|
+
/** The model at the end of a path of relations. With this, a rule can ask about
|
|
148
|
+
* a field of a related record: «alguna línea con algún impuesto con monto > 10».
|
|
149
|
+
* web-ui asks for nothing: whoever draws the builder knows where the models come from. */
|
|
150
150
|
loadModel?: LoadModel;
|
|
151
|
-
/**
|
|
152
|
-
*
|
|
151
|
+
/** A model cache shared with whoever draws the builder —the same one it uses to
|
|
152
|
+
* describe the applied filter with `describeFilter(…, modelAt)`—. Without this, its own. */
|
|
153
153
|
models?: ModelCache;
|
|
154
|
-
/**
|
|
155
|
-
*
|
|
154
|
+
/** The filter that was already set, if there was one. Reopening the builder with this inside
|
|
155
|
+
* has to continue where it was left, not start blank. */
|
|
156
156
|
initial?: BuiltFilter;
|
|
157
157
|
onApply: (selection: BuiltFilter | undefined) => void;
|
|
158
158
|
onCancel?: () => void;
|