@sincpro/web-ui 1.11.1 → 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 +35 -22
- package/dist/components/search/CriteriaBuilder.js +95 -85
- package/dist/components/search/CriteriaChips.d.ts +9 -9
- package/dist/components/search/CriteriaChips.js +13 -13
- package/dist/components/search/FilterBuilder.d.ts +72 -71
- package/dist/components/search/FilterBuilder.js +190 -145
- 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 +21 -18
- package/dist/components/search/SearchBar.d.ts +34 -34
- package/dist/components/search/SearchBar.js +113 -113
- package/dist/components/search/criteria.d.ts +86 -74
- package/dist/components/search/criteria.js +44 -43
- 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.d.ts +2 -2
- package/dist/components/search/index.js +14 -14
- 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 +104 -94
- package/dist/foundations/copy.es.js +6 -1
- package/dist/foundations/copy.js +6 -1
- 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,53 +4,66 @@ export interface BuiltSort {
|
|
|
4
4
|
field: string;
|
|
5
5
|
descending?: boolean;
|
|
6
6
|
}
|
|
7
|
+
/** A grouping level, like criteria's `Level`: the field and, if it is a date, the grain. */
|
|
7
8
|
export interface BuiltLevel {
|
|
8
9
|
field: string;
|
|
9
10
|
grain?: string | null;
|
|
10
11
|
}
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
/**
|
|
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
|
+
*/
|
|
17
|
+
export interface BuiltMeasure {
|
|
18
|
+
function: string;
|
|
19
|
+
field: string;
|
|
20
|
+
/** What the function needs besides the field. Only `percentile`: the cut's fraction. */
|
|
21
|
+
argument?: number;
|
|
22
|
+
}
|
|
23
|
+
/** From where a page of heaps starts — the same shape as the rows' pagination. */
|
|
14
24
|
export type BuiltPageStrategy = {
|
|
15
|
-
token
|
|
25
|
+
token: string | null;
|
|
16
26
|
} | {
|
|
17
|
-
rows
|
|
27
|
+
rows: number;
|
|
18
28
|
};
|
|
19
29
|
export interface BuiltGroupPagination {
|
|
20
30
|
limit?: number;
|
|
21
31
|
strategy?: BuiltPageStrategy;
|
|
22
32
|
}
|
|
33
|
+
/** The grouping as `@sincpro/criteria` 2.0 declares it, key by key. */
|
|
23
34
|
export interface BuiltGrouping {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
35
|
+
/** The levels, in order: they are not added, they nest. */
|
|
36
|
+
group_by?: BuiltLevel[];
|
|
37
|
+
/** The numbers each heap answers, each under a chosen name. */
|
|
38
|
+
measures?: Record<string, BuiltMeasure>;
|
|
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
|
+
where_measures?: BuiltFilter;
|
|
42
|
+
/** In what order the heaps come back: by the level's own field, by a name from
|
|
43
|
+
* `measures`, or by `count`. */
|
|
31
44
|
order?: BuiltSort[];
|
|
32
|
-
/**
|
|
45
|
+
/** How many heaps of the first level come back, and from where. Absent is all of them. */
|
|
33
46
|
pagination?: BuiltGroupPagination;
|
|
34
47
|
}
|
|
35
|
-
/**
|
|
36
|
-
*
|
|
48
|
+
/** The criteria as the engine declares it. It is what this component builds and returns, and what
|
|
49
|
+
* the code editor shows. */
|
|
37
50
|
export interface BuiltCriteria {
|
|
38
|
-
|
|
51
|
+
selection?: BuiltFilter;
|
|
39
52
|
order?: BuiltSort[];
|
|
40
53
|
grouping?: BuiltGrouping;
|
|
41
54
|
specification?: Record<string, Record<string, never>>;
|
|
42
55
|
}
|
|
43
56
|
export declare function CriteriaBuilder({ model, initial, focus, onApply, onCancel, }: {
|
|
44
57
|
model: ModelDefinition;
|
|
45
|
-
/**
|
|
58
|
+
/** The criteria that was already set. Reopening has to continue where it was left. */
|
|
46
59
|
initial?: BuiltCriteria;
|
|
47
60
|
/**
|
|
48
|
-
*
|
|
49
|
-
*
|
|
61
|
+
* The condition's field to show first: the chip somebody
|
|
62
|
+
* touched in the bar.
|
|
50
63
|
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
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.
|
|
54
67
|
*/
|
|
55
68
|
focus?: string;
|
|
56
69
|
onApply: (criteria: BuiltCriteria | undefined) => void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
-
import { blankGroup, ExpressionView, treeFromFilter, treeToFilter,
|
|
3
|
+
import { blankGroup, ExpressionView, SelectionTree, treeFromFilter, treeToFilter, } from "./FilterBuilder.js";
|
|
4
4
|
import { LazyJsonEditor } from "./LazyJsonEditor.js";
|
|
5
5
|
import { filterableNames, } from "./model.js";
|
|
6
6
|
import { fillCopy, useUiCopy } from "../../foundations/copy.js";
|
|
@@ -12,37 +12,45 @@ 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
|
-
*
|
|
27
|
-
*
|
|
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
|
-
*
|
|
31
|
-
const
|
|
29
|
+
/** The functions a measure can ask for here, closed on the server side because the
|
|
30
|
+
* name reaches SQL. */
|
|
31
|
+
const MEASURE_FUNCTIONS = ["sum", "avg", "min", "max", "count"];
|
|
32
32
|
function isEmpty(criteria) {
|
|
33
|
-
return (criteria.
|
|
33
|
+
return (criteria.selection === undefined &&
|
|
34
34
|
(criteria.order ?? []).length === 0 &&
|
|
35
|
-
(criteria.grouping?.
|
|
36
|
-
Object.keys(criteria.grouping?.
|
|
35
|
+
(criteria.grouping?.group_by ?? []).length === 0 &&
|
|
36
|
+
Object.keys(criteria.grouping?.measures ?? {}).length === 0 &&
|
|
37
37
|
Object.keys(criteria.specification ?? {}).length === 0);
|
|
38
38
|
}
|
|
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
|
+
function measuresTreeOf(filter, model) {
|
|
42
|
+
const node = filter === undefined ? null : treeFromFilter(filter);
|
|
43
|
+
if (node === null)
|
|
44
|
+
return blankGroup(model, "count");
|
|
45
|
+
return node.kind === "group" ? node : { kind: "group", join: "all", children: [node] };
|
|
46
|
+
}
|
|
39
47
|
/**
|
|
40
|
-
*
|
|
48
|
+
* THE CHIP THAT ADDS: a «+» that opens the list of what can be chosen.
|
|
41
49
|
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
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.
|
|
46
54
|
*/
|
|
47
55
|
function AddTag({ label, options, onPick, }) {
|
|
48
56
|
const [open, setOpen] = useState(false);
|
|
@@ -57,7 +65,7 @@ function AddTag({ label, options, onPick, }) {
|
|
|
57
65
|
},
|
|
58
66
|
})) }) })) : null] }));
|
|
59
67
|
}
|
|
60
|
-
/**
|
|
68
|
+
/** The next cut, and back to the start. */
|
|
61
69
|
function nextGrain(grain) {
|
|
62
70
|
const at = GRAINS.indexOf(grain ?? null);
|
|
63
71
|
return GRAINS[(at + 1) % GRAINS.length] ?? null;
|
|
@@ -65,70 +73,66 @@ function nextGrain(grain) {
|
|
|
65
73
|
export function CriteriaBuilder({ model, initial, focus, onApply, onCancel, }) {
|
|
66
74
|
const surface = useSurface();
|
|
67
75
|
const names = Object.keys(model.fields).sort();
|
|
68
|
-
/*
|
|
69
|
-
(`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. */
|
|
70
78
|
const scalarNames = filterableNames(model);
|
|
71
79
|
const sortable = names.filter((name) => model.fields[name]?.sortable === true);
|
|
72
|
-
const decomposed = initial?.
|
|
80
|
+
const decomposed = initial?.selection === undefined ? null : treeFromFilter(initial.selection);
|
|
73
81
|
const [tree, setTree] = useState(() => decomposed !== null && decomposed.kind === "group"
|
|
74
82
|
? decomposed
|
|
75
83
|
: decomposed !== null
|
|
76
84
|
? { kind: "group", join: "all", children: [decomposed] }
|
|
77
85
|
: blankGroup(model, scalarNames[0]));
|
|
78
86
|
const copy = useUiCopy();
|
|
79
|
-
const [
|
|
87
|
+
const [lockedSelection, setLockedSelection] = useState(initial?.selection !== undefined && decomposed === null ? initial.selection : null);
|
|
80
88
|
const [order, setOrder] = useState(initial?.order ?? []);
|
|
81
|
-
const [levels, setLevels] = useState(initial?.grouping?.
|
|
82
|
-
const [
|
|
89
|
+
const [levels, setLevels] = useState(initial?.grouping?.group_by ?? []);
|
|
90
|
+
const [measures, setMeasures] = useState(initial?.grouping?.measures ?? {});
|
|
83
91
|
const [groupOrder, setGroupOrder] = useState(initial?.grouping?.order ?? []);
|
|
84
92
|
const [groupLimit, setGroupLimit] = useState(initial?.grouping?.pagination?.limit);
|
|
85
|
-
/* `
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
+
const measuresModel = useMemo(() => ({
|
|
98
|
+
aggregate: "where_measures",
|
|
90
99
|
identity: "count",
|
|
91
100
|
fields: Object.fromEntries([
|
|
92
101
|
["count", { type: "integer", nullable: false, sortable: false, ops: COMPARABLE }],
|
|
93
|
-
...Object.keys(
|
|
102
|
+
...Object.keys(measures).map((name) => [
|
|
94
103
|
name,
|
|
95
104
|
{ type: "number", nullable: false, sortable: false, ops: COMPARABLE },
|
|
96
105
|
]),
|
|
97
106
|
]),
|
|
98
|
-
}), [
|
|
99
|
-
const
|
|
100
|
-
const [havingTree, setHavingTree] = useState(() => havingDecomposed !== null && havingDecomposed.kind === "group"
|
|
101
|
-
? havingDecomposed
|
|
102
|
-
: havingDecomposed !== null
|
|
103
|
-
? { kind: "group", join: "all", children: [havingDecomposed] }
|
|
104
|
-
: blankGroup(havingModel, "count"));
|
|
107
|
+
}), [measures]);
|
|
108
|
+
const [measuresTree, setMeasuresTree] = useState(() => measuresTreeOf(initial?.grouping?.where_measures, measuresModel));
|
|
105
109
|
const [fields, setFields] = useState(Object.keys(initial?.specification ?? {}));
|
|
106
110
|
const [rawText, setRawText] = useState(() => initial === undefined ? "" : JSON.stringify(initial, null, 2));
|
|
107
111
|
const [rawError, setRawError] = useState(null);
|
|
108
|
-
/**
|
|
112
|
+
/** What the controls say, together: it is what is applied and what the JSON shows. */
|
|
109
113
|
function assemble(next) {
|
|
110
|
-
const
|
|
114
|
+
const selection = next.locked ?? lockedSelection ?? treeToFilter(next.tree ?? tree);
|
|
111
115
|
const sorts = next.order ?? order;
|
|
112
|
-
const
|
|
113
|
-
const
|
|
114
|
-
const
|
|
116
|
+
const groupBy = next.levels ?? levels;
|
|
117
|
+
const measured = next.measures ?? measures;
|
|
118
|
+
const whereMeasures = treeToFilter(next.measuresTree ?? measuresTree);
|
|
115
119
|
const groupSorts = next.groupOrder ?? groupOrder;
|
|
116
120
|
const limit = "groupLimit" in next ? next.groupLimit : groupLimit;
|
|
117
121
|
const chosen = next.fields ?? fields;
|
|
118
|
-
/*
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
const grouping =
|
|
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
|
+
const grouping = groupBy.length === 0
|
|
122
126
|
? {}
|
|
123
127
|
: {
|
|
124
|
-
|
|
125
|
-
...(Object.keys(
|
|
126
|
-
...(
|
|
128
|
+
group_by: groupBy,
|
|
129
|
+
...(Object.keys(measured).length === 0 ? {} : { measures: measured }),
|
|
130
|
+
...(whereMeasures === undefined ? {} : { where_measures: whereMeasures }),
|
|
127
131
|
...(groupSorts.length === 0 ? {} : { order: groupSorts }),
|
|
128
132
|
...(limit === undefined ? {} : { pagination: { limit } }),
|
|
129
133
|
};
|
|
130
134
|
return {
|
|
131
|
-
...(
|
|
135
|
+
...(selection === undefined ? {} : { selection }),
|
|
132
136
|
...(sorts.length === 0 ? {} : { order: sorts }),
|
|
133
137
|
...(Object.keys(grouping).length === 0 ? {} : { grouping }),
|
|
134
138
|
...(chosen.length === 0
|
|
@@ -138,20 +142,20 @@ export function CriteriaBuilder({ model, initial, focus, onApply, onCancel, }) {
|
|
|
138
142
|
}),
|
|
139
143
|
};
|
|
140
144
|
}
|
|
141
|
-
/*
|
|
145
|
+
/* Touching any control rewrites the whole JSON: the two views are the same criteria. */
|
|
142
146
|
function push(next) {
|
|
143
147
|
if (next.tree !== undefined)
|
|
144
148
|
setTree(next.tree);
|
|
145
149
|
if (next.locked !== undefined)
|
|
146
|
-
|
|
150
|
+
setLockedSelection(next.locked);
|
|
147
151
|
if (next.order !== undefined)
|
|
148
152
|
setOrder(next.order);
|
|
149
153
|
if (next.levels !== undefined)
|
|
150
154
|
setLevels(next.levels);
|
|
151
|
-
if (next.
|
|
152
|
-
|
|
153
|
-
if (next.
|
|
154
|
-
|
|
155
|
+
if (next.measures !== undefined)
|
|
156
|
+
setMeasures(next.measures);
|
|
157
|
+
if (next.measuresTree !== undefined)
|
|
158
|
+
setMeasuresTree(next.measuresTree);
|
|
155
159
|
if (next.groupOrder !== undefined)
|
|
156
160
|
setGroupOrder(next.groupOrder);
|
|
157
161
|
if ("groupLimit" in next)
|
|
@@ -162,7 +166,7 @@ export function CriteriaBuilder({ model, initial, focus, onApply, onCancel, }) {
|
|
|
162
166
|
setRawText(isEmpty(built) ? "" : JSON.stringify(built, null, 2));
|
|
163
167
|
setRawError(null);
|
|
164
168
|
}
|
|
165
|
-
/*
|
|
169
|
+
/* Writing the JSON rebuilds the controls, as long as what was written is a criteria. */
|
|
166
170
|
function updateRaw(text) {
|
|
167
171
|
setRawText(text);
|
|
168
172
|
if (text.trim() === "") {
|
|
@@ -182,36 +186,31 @@ export function CriteriaBuilder({ model, initial, focus, onApply, onCancel, }) {
|
|
|
182
186
|
return;
|
|
183
187
|
}
|
|
184
188
|
setRawError(null);
|
|
185
|
-
const node = parsed.
|
|
189
|
+
const node = parsed.selection === undefined ? null : treeFromFilter(parsed.selection);
|
|
186
190
|
if (node !== null) {
|
|
187
191
|
setTree(node.kind === "group" ? node : { kind: "group", join: "all", children: [node] });
|
|
188
|
-
|
|
192
|
+
setLockedSelection(null);
|
|
189
193
|
}
|
|
190
|
-
else if (parsed.
|
|
191
|
-
|
|
194
|
+
else if (parsed.selection !== undefined) {
|
|
195
|
+
setLockedSelection(parsed.selection);
|
|
192
196
|
}
|
|
193
197
|
else {
|
|
194
198
|
setTree(blankGroup(model, scalarNames[0]));
|
|
195
|
-
|
|
199
|
+
setLockedSelection(null);
|
|
196
200
|
}
|
|
197
201
|
setOrder(parsed.order ?? []);
|
|
198
|
-
setLevels(parsed.grouping?.
|
|
199
|
-
|
|
202
|
+
setLevels(parsed.grouping?.group_by ?? []);
|
|
203
|
+
setMeasures(parsed.grouping?.measures ?? {});
|
|
200
204
|
setGroupOrder(parsed.grouping?.order ?? []);
|
|
201
205
|
setGroupLimit(parsed.grouping?.pagination?.limit);
|
|
202
|
-
|
|
203
|
-
setHavingTree(havingNode !== null && havingNode.kind === "group"
|
|
204
|
-
? havingNode
|
|
205
|
-
: havingNode !== null
|
|
206
|
-
? { kind: "group", join: "all", children: [havingNode] }
|
|
207
|
-
: blankGroup(havingModel, "count"));
|
|
206
|
+
setMeasuresTree(measuresTreeOf(parsed.grouping?.where_measures, measuresModel));
|
|
208
207
|
setFields(Object.keys(parsed.specification ?? {}));
|
|
209
208
|
}
|
|
210
209
|
const box = surface === "chrome"
|
|
211
210
|
? "border-chrome-ink/20 bg-chrome text-chrome-ink"
|
|
212
211
|
: "border-ink/15 bg-surface text-ink";
|
|
213
212
|
const select = `min-w-0 flex-1 basis-40 rounded-control border px-2 py-1 text-meta ${box}`;
|
|
214
|
-
return (_jsxs("div", { className: "flex min-w-0 flex-col gap-3 p-3", children: [_jsxs("section", { className: "flex min-w-0 flex-col gap-2", children: [_jsx(Rule, { label: copy.builder.filter }), _jsx("div", { className: "max-h-72 min-w-0 overflow-auto", children:
|
|
213
|
+
return (_jsxs("div", { className: "flex min-w-0 flex-col gap-3 p-3", children: [_jsxs("section", { className: "flex min-w-0 flex-col gap-2", children: [_jsx(Rule, { label: copy.builder.filter }), _jsx("div", { className: "max-h-72 min-w-0 overflow-auto", children: lockedSelection !== null ? (_jsxs(_Fragment, { children: [_jsx("p", { className: "mb-2 text-meta text-muted", children: copy.search.unreadable }), _jsx(ExpressionView, { node: lockedSelection, model: model })] })) : (_jsx(SelectionTree, { model: model, group: tree, onChange: (next) => push({ tree: next }), ...(focus === undefined ? {} : { focus }) })) })] }), _jsxs("section", { className: "flex min-w-0 flex-col gap-2", children: [_jsx(Rule, { label: copy.builder.order }), _jsxs("div", { className: "flex min-w-0 flex-wrap items-center gap-1", children: [_jsx(Tags, { items: order.map((sort, index) => ({
|
|
215
214
|
id: `${sort.field}-${index}`,
|
|
216
215
|
label: sort.field,
|
|
217
216
|
note: sort.descending === true ? "↓" : "↑",
|
|
@@ -239,26 +238,37 @@ export function CriteriaBuilder({ model, initial, focus, onApply, onCancel, }) {
|
|
|
239
238
|
onRemove: () => push({ levels: levels.filter((_, at) => at !== index) }),
|
|
240
239
|
removeLabel: fillCopy(copy.builder.dropLevel, { field: level.field }),
|
|
241
240
|
},
|
|
242
|
-
] })] }, `${level.field}-${index}`))), _jsx(AddTag, { label: copy.builder.addGroup, options: scalarNames.filter((name) => !levels.some((one) => one.field === name)), onPick: (name) => push({ levels: [...levels, { field: name }] }) })] }), levels.length === 0 ? (_jsx("p", { className: "text-meta text-muted", children: copy.builder.noGrouping })) : null] }), levels.length > 0 ? (_jsxs(_Fragment, { children: [_jsxs("section", { className: "flex min-w-0 flex-col gap-2", children: [_jsx(Rule, { label: copy.builder.totals }), Object.keys(
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
241
|
+
] })] }, `${level.field}-${index}`))), _jsx(AddTag, { label: copy.builder.addGroup, options: scalarNames.filter((name) => !levels.some((one) => one.field === name)), onPick: (name) => push({ levels: [...levels, { field: name }] }) })] }), levels.length === 0 ? (_jsx("p", { className: "text-meta text-muted", children: copy.builder.noGrouping })) : null] }), levels.length > 0 ? (_jsxs(_Fragment, { children: [_jsxs("section", { className: "flex min-w-0 flex-col gap-2", children: [_jsx(Rule, { label: copy.builder.totals }), Object.keys(measures).length === 0 ? (_jsx("p", { className: "text-meta text-muted", children: copy.builder.noTotals })) : null, Object.entries(measures).map(([name, measure]) => (_jsxs("div", { className: "flex min-w-0 flex-wrap items-center gap-2", children: [_jsx("select", { "aria-label": fillCopy(copy.builder.totalFunction, { name }), value: measure.function, onChange: (event) => push({
|
|
242
|
+
measures: {
|
|
243
|
+
...measures,
|
|
244
|
+
[name]: { function: event.target.value, field: measure.field },
|
|
245
|
+
},
|
|
246
|
+
}), className: `min-w-0 flex-1 basis-28 rounded-control border px-2 py-1 text-meta ${box}`, children: MEASURE_FUNCTIONS.map((one) => (_jsx("option", { value: one, children: one }, one))) }), _jsx("select", { "aria-label": fillCopy(copy.builder.totalField, { name }), value: measure.field, onChange: (event) => push({
|
|
247
|
+
measures: {
|
|
248
|
+
...measures,
|
|
249
|
+
[name]: { ...measure, field: event.target.value },
|
|
250
|
+
},
|
|
251
|
+
}), className: select, children: scalarNames.map((one) => (_jsx("option", { value: one, children: one }, one))) }), _jsx("span", { className: "shrink-0 text-micro text-muted", children: fillCopy(copy.builder.totalAs, { name }) }), _jsx("button", { type: "button", "aria-label": copy.builder.dropTotal, onClick: () => {
|
|
252
|
+
const { [name]: _dropped, ...rest } = measures;
|
|
253
|
+
push({ measures: rest });
|
|
247
254
|
}, className: "ml-auto shrink-0 text-muted", children: _jsx(Trash2, { className: "size-4" }) })] }, name))), _jsx("div", { children: _jsxs(Button, { role: "ghost", disabled: scalarNames.length === 0, onClick: () => {
|
|
248
255
|
let name = "total";
|
|
249
256
|
let index = 2;
|
|
250
|
-
while (name in
|
|
257
|
+
while (name in measures)
|
|
251
258
|
name = `total_${index++}`;
|
|
252
259
|
push({
|
|
253
|
-
|
|
260
|
+
measures: {
|
|
261
|
+
...measures,
|
|
262
|
+
[name]: { function: "sum", field: scalarNames[0] ?? "" },
|
|
263
|
+
},
|
|
254
264
|
});
|
|
255
|
-
}, children: [_jsx(Plus, { className: "size-4" }), " ", copy.builder.addTotal] }) })] }), _jsxs("section", { className: "flex min-w-0 flex-col gap-2", children: [_jsx(Rule, { label: copy.builder.filterPiles }), _jsx("p", { className: "text-meta text-muted", children: copy.builder.pilesNote }), _jsx(
|
|
265
|
+
}, children: [_jsx(Plus, { className: "size-4" }), " ", copy.builder.addTotal] }) })] }), _jsxs("section", { className: "flex min-w-0 flex-col gap-2", children: [_jsx(Rule, { label: copy.builder.filterPiles }), _jsx("p", { className: "text-meta text-muted", children: copy.builder.pilesNote }), _jsx(SelectionTree, { model: measuresModel, group: measuresTree, onChange: (next) => push({ measuresTree: next }) })] }), _jsxs("section", { className: "flex min-w-0 flex-col gap-2", children: [_jsx(Rule, { label: copy.builder.pileOrder }), groupOrder.length === 0 ? (_jsx("p", { className: "text-meta text-muted", children: copy.builder.noPileOrder })) : null, groupOrder.map((sort, index) => (_jsxs("div", { className: "flex min-w-0 flex-wrap items-center gap-2", children: [_jsx("select", { "aria-label": copy.builder.pileOrderField, value: sort.field, onChange: (event) => push({
|
|
256
266
|
groupOrder: groupOrder.map((one, at) => at === index ? { ...one, field: event.target.value } : one),
|
|
257
267
|
}), className: select, children: [
|
|
258
268
|
...levels.map((level) => level.field),
|
|
259
|
-
...Object.keys(
|
|
269
|
+
...Object.keys(measures),
|
|
260
270
|
"count",
|
|
261
|
-
].map((name) => (_jsx("option", { value: name, children: name }, name))) }), _jsxs("select", { value: sort.descending === true ? "desc" : "asc", onChange: (event) => push({
|
|
271
|
+
].map((name) => (_jsx("option", { value: name, children: name }, name))) }), _jsxs("select", { "aria-label": copy.builder.pileOrderDirection, value: sort.descending === true ? "desc" : "asc", onChange: (event) => push({
|
|
262
272
|
groupOrder: groupOrder.map((one, at) => at === index
|
|
263
273
|
? { ...one, descending: event.target.value === "desc" }
|
|
264
274
|
: one),
|
|
@@ -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
|
-
|
|
87
|
-
const editable = node.kind === "group" || node.
|
|
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
|
+
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 }) }));
|