@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
|
@@ -12,43 +12,43 @@ import { Button } from "../../primitives/button/index.js";
|
|
|
12
12
|
import { FolderTree, Plus, Trash2 } from "lucide-react";
|
|
13
13
|
import { useState } from "react";
|
|
14
14
|
/* ====================================================================== *
|
|
15
|
-
*
|
|
15
|
+
* A FILTER SOMEBODY BUILDS, FROM WHAT THE MODEL SAYS IT ACCEPTS.
|
|
16
16
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* JSON
|
|
17
|
+
* The named cuts alongside —«vencidas», «con entregas pendientes»— are the
|
|
18
|
+
* questions somebody already thought of. This is for the rest: choose a field, an
|
|
19
|
+
* operator, write a value — group them with AND or with OR, nest a group
|
|
20
|
+
* inside another as many times as needed, or write the
|
|
21
|
+
* JSON directly to copy or paste a whole criteria.
|
|
22
22
|
*
|
|
23
|
-
* **
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
23
|
+
* **Nothing here is written by hand.** The fields come from the model
|
|
24
|
+
* definition the server sends, and so do each one's operators: a
|
|
25
|
+
* text field offers «contiene», a numeric one offers «>», one that admits
|
|
26
|
+
* empty offers «está vacío». Adding a column makes it appear here, with
|
|
27
|
+
* its correct operators, without touching this file.
|
|
28
28
|
*
|
|
29
|
-
* **
|
|
30
|
-
* «todas / cualquiera»
|
|
31
|
-
*
|
|
32
|
-
*
|
|
29
|
+
* **A tree, not a list.** Each group —the root included— has its own
|
|
30
|
+
* «todas / cualquiera» and its own children: a condition, or another group
|
|
31
|
+
* nested inside. The tree icon adds a new group beside the
|
|
32
|
+
* row that was touched; the `+` adds another condition.
|
|
33
33
|
*
|
|
34
|
-
* **
|
|
35
|
-
*
|
|
36
|
-
* criteria,
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
34
|
+
* **One component renders and builds — and there is always a JSON
|
|
35
|
+
* beside it.** The tree and the code editor are two views of the SAME
|
|
36
|
+
* criteria, synchronised in both directions: touching the tree rewrites
|
|
37
|
+
* the JSON, and writing a recognisable JSON rebuilds the tree. The only thing the
|
|
38
|
+
* tree does not know how to build or show is a NOT: if the filter brings one at
|
|
39
|
+
* any level, it is drawn read-only with `ExpressionView` in its
|
|
40
|
+
* place, and the JSON remains the way to touch it.
|
|
41
41
|
* ====================================================================== */
|
|
42
|
-
/*
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
/**
|
|
42
|
+
/* What an operator is called for whoever reads it: `copy.ops`, which is the SAME table the
|
|
43
|
+
bar uses when building the question. Two tables means the same comparison is called two ways
|
|
44
|
+
on the same screen. */
|
|
45
|
+
/** Which operators take no value: asking whether something is empty needs nothing written. */
|
|
46
46
|
const WITHOUT_VALUE = new Set(["is null"]);
|
|
47
|
-
/**
|
|
48
|
-
*
|
|
49
|
-
*
|
|
47
|
+
/** Which operators compare against TWO values. «Entre el 1 y el 31» is the question everybody
|
|
48
|
+
* asks about dates, and writing it as two loose rules is the way to
|
|
49
|
+
* get one of the two ends wrong. */
|
|
50
50
|
const WITH_RANGE = new Set(["between"]);
|
|
51
|
-
/**
|
|
51
|
+
/** What kind of input asks for a value, read from the field's type. */
|
|
52
52
|
function inputType(type) {
|
|
53
53
|
if (type === "integer" || type === "number")
|
|
54
54
|
return "number";
|
|
@@ -66,10 +66,10 @@ function isCondition(value) {
|
|
|
66
66
|
typeof value.operator === "string" &&
|
|
67
67
|
"value" in value);
|
|
68
68
|
}
|
|
69
|
-
/**
|
|
70
|
-
* `negate
|
|
71
|
-
*
|
|
72
|
-
*
|
|
69
|
+
/** Whether this is one of the shapes the filter recognises — condition, or `all`/`any`/
|
|
70
|
+
* `negate` group. A valid JSON that is none of these —`{}`, `{"foo": 1}`, a loose array—
|
|
71
|
+
* is not a filter this component knows how to draw, and is treated as a shape error instead of
|
|
72
|
+
* trying to show anything at all. */
|
|
73
73
|
export function isRecognizedFilter(value) {
|
|
74
74
|
if (isCondition(value))
|
|
75
75
|
return true;
|
|
@@ -82,7 +82,7 @@ export function isRecognizedFilter(value) {
|
|
|
82
82
|
return true;
|
|
83
83
|
if ("negate" in record)
|
|
84
84
|
return true;
|
|
85
|
-
if (
|
|
85
|
+
if (isThrough(record))
|
|
86
86
|
return true;
|
|
87
87
|
return false;
|
|
88
88
|
}
|
|
@@ -91,9 +91,49 @@ function isThrough(value) {
|
|
|
91
91
|
if (typeof value !== "object" || value === null)
|
|
92
92
|
return false;
|
|
93
93
|
const record = value;
|
|
94
|
-
return
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
return typeof record.through === "string" && "selection" in record;
|
|
95
|
+
}
|
|
96
|
+
function isNegate(value) {
|
|
97
|
+
return typeof value === "object" && value !== null && "negate" in value;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* A relation crossed, read off criteria's shape: the quantifier is not a key, it is the
|
|
101
|
+
* sentence the `negate`s around the `through` make.
|
|
102
|
+
*
|
|
103
|
+
* {through, selection: s} «alguno» s
|
|
104
|
+
* {negate: {through, selection: s}} «ninguno» s
|
|
105
|
+
* {negate: {through, selection: {negate: s}}} «todos» s (none that does not)
|
|
106
|
+
*
|
|
107
|
+
* «Ninguno con no-s» and «todos con s» are the same filter; it reads as the second, the
|
|
108
|
+
* shorter sentence, and that is also how a path of two hops comes back: «ninguna línea con
|
|
109
|
+
* ningún impuesto» returns as «todas las líneas con algún impuesto», which filters the same.
|
|
110
|
+
* Anything else is not a relation crossed: `null`.
|
|
111
|
+
*/
|
|
112
|
+
function crossedOf(value) {
|
|
113
|
+
if (isThrough(value)) {
|
|
114
|
+
return { through: value.through, match: "any", selection: value.selection };
|
|
115
|
+
}
|
|
116
|
+
if (!isNegate(value) || !isThrough(value.negate))
|
|
117
|
+
return null;
|
|
118
|
+
const { through, selection } = value.negate;
|
|
119
|
+
return isNegate(selection)
|
|
120
|
+
? { through, match: "all", selection: selection.negate }
|
|
121
|
+
: { through, match: "none", selection };
|
|
122
|
+
}
|
|
123
|
+
/** The other way: a relation and its quantifier, written the way criteria reads them. */
|
|
124
|
+
function crossing(through, match, inner) {
|
|
125
|
+
if (match === "none")
|
|
126
|
+
return { negate: { through, selection: inner } };
|
|
127
|
+
if (match === "all")
|
|
128
|
+
return { negate: { through, selection: { negate: inner } } };
|
|
129
|
+
return { through, selection: inner };
|
|
130
|
+
}
|
|
131
|
+
/** Whether a «some» crossing reaches ONE record: a to-one relation, as the model says. Then
|
|
132
|
+
* it is said as a path («Cliente > País»), since «alguno de» would be noise. Without the
|
|
133
|
+
* model it is said as what `{through, selection}` means — «alguno de» —, never wrong. */
|
|
134
|
+
function reachesOne(model, crossed) {
|
|
135
|
+
const field = model?.fields[crossed.through];
|
|
136
|
+
return crossed.match === "any" && field !== undefined && !isToMany(field);
|
|
97
137
|
}
|
|
98
138
|
export function blankCondition(model, first) {
|
|
99
139
|
const field = first ?? "";
|
|
@@ -107,18 +147,18 @@ export function blankCondition(model, first) {
|
|
|
107
147
|
export function blankGroup(model, first) {
|
|
108
148
|
return { kind: "group", join: "all", children: [blankCondition(model, first)] };
|
|
109
149
|
}
|
|
110
|
-
/**
|
|
150
|
+
/** The tree as the filter that travels.
|
|
111
151
|
*
|
|
112
|
-
* in
|
|
113
|
-
* out
|
|
152
|
+
* in a lone condition
|
|
153
|
+
* out that condition, unwrapped
|
|
114
154
|
*
|
|
115
|
-
* in
|
|
155
|
+
* in group with two children, join «any»
|
|
116
156
|
* out {any: [ … , … ]}
|
|
117
157
|
*
|
|
118
|
-
*
|
|
119
|
-
* «todas»
|
|
120
|
-
*
|
|
121
|
-
*
|
|
158
|
+
* A group with a single child is not wrapped —it is that child—, and a group with no children disappears: neither
|
|
159
|
+
* an empty «todas» nor «cualquiera» is a filter anybody asked for. The rule holds at any
|
|
160
|
+
* level, not only at the root, so nesting a single-condition group is the same as not
|
|
161
|
+
* having nested it. */
|
|
122
162
|
export function treeToFilter(node) {
|
|
123
163
|
if (node.kind === "condition") {
|
|
124
164
|
const leaf = conditionToFilter(node);
|
|
@@ -129,9 +169,7 @@ export function treeToFilter(node) {
|
|
|
129
169
|
/** The relations of a path, as nested `through` nodes around the condition: the first hop
|
|
130
170
|
* outside, the last one next to the condition — the order the path reads in. */
|
|
131
171
|
function wrapThrough(hops, leaf) {
|
|
132
|
-
return hops.reduceRight((inner, hop) => hop.
|
|
133
|
-
? { through: hop.field, match: hop.match, where: inner }
|
|
134
|
-
: { through: hop.field, where: inner }, leaf);
|
|
172
|
+
return hops.reduceRight((inner, hop) => crossing(hop.field, hop.match, inner), leaf);
|
|
135
173
|
}
|
|
136
174
|
function conditionToFilter(node) {
|
|
137
175
|
{
|
|
@@ -141,17 +179,17 @@ function conditionToFilter(node) {
|
|
|
141
179
|
return { field: node.field, operator: node.operator, value: true };
|
|
142
180
|
}
|
|
143
181
|
if (WITH_RANGE.has(node.operator)) {
|
|
144
|
-
/*
|
|
145
|
-
|
|
182
|
+
/* A half-written range is not half a range: while one end is missing, the rule does not
|
|
183
|
+
travel. */
|
|
146
184
|
if (node.value === "" || (node.upper ?? "") === "")
|
|
147
185
|
return undefined;
|
|
148
186
|
return { field: node.field, operator: node.operator, value: [node.value, node.upper] };
|
|
149
187
|
}
|
|
150
|
-
/* **
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
188
|
+
/* **A rule with no value does not filter.** It used to travel with `value: ""`, and that is not «not
|
|
189
|
+
written anything yet»: against an `=` it is «the field is the empty string», which empties the list
|
|
190
|
+
while somebody is still typing, and against a `like` it is «contains nothing», which leaves it
|
|
191
|
+
the same. To ask for what is empty there is the «está vacío» operator, which the
|
|
192
|
+
model publishes on the fields that admit it — explicit, and not by omission. */
|
|
155
193
|
if (node.value === "")
|
|
156
194
|
return undefined;
|
|
157
195
|
return { field: node.field, operator: node.operator, value: node.value };
|
|
@@ -163,9 +201,9 @@ function groupToFilter(node) {
|
|
|
163
201
|
.filter((one) => one !== undefined);
|
|
164
202
|
if (kept.length === 0)
|
|
165
203
|
return undefined;
|
|
166
|
-
/* «Ninguna»
|
|
167
|
-
grande»
|
|
168
|
-
|
|
204
|
+
/* «Ninguna» negates the WHOLE group and not each child on its own: «ni vencida ni
|
|
205
|
+
grande» is `not (vencida or grande)`. And a group of one is not dismantled
|
|
206
|
+
here either —dismantling it would lose the negation—, which is what the bar does. */
|
|
169
207
|
if (node.join === "not") {
|
|
170
208
|
return { negate: kept.length === 1 ? kept[0] : { any: kept } };
|
|
171
209
|
}
|
|
@@ -173,8 +211,8 @@ function groupToFilter(node) {
|
|
|
173
211
|
return kept[0];
|
|
174
212
|
return node.join === "any" ? { any: kept } : { all: kept };
|
|
175
213
|
}
|
|
176
|
-
/**
|
|
177
|
-
*
|
|
214
|
+
/** A condition back to an editable row: the value goes back to text, which is the only thing
|
|
215
|
+
* an `<input>` knows how to show. A list —an `in`'s value— is written separated by commas. */
|
|
178
216
|
function conditionToTree(condition) {
|
|
179
217
|
if (WITH_RANGE.has(condition.operator) && Array.isArray(condition.value)) {
|
|
180
218
|
const [from, to] = condition.value;
|
|
@@ -197,51 +235,47 @@ function conditionToTree(condition) {
|
|
|
197
235
|
: String(condition.value ?? ""),
|
|
198
236
|
};
|
|
199
237
|
}
|
|
200
|
-
/**
|
|
238
|
+
/** The filter read back into a tree.
|
|
201
239
|
*
|
|
202
240
|
* in {field: "name", operator: "=", value: "labs"}
|
|
203
241
|
* out TreeCondition
|
|
204
242
|
*
|
|
205
|
-
* in {any: [{all: [cond1, cond2]}, cond3]}
|
|
206
|
-
* out TreeGroup(any)
|
|
243
|
+
* in {any: [{all: [cond1, cond2]}, cond3]} group inside a group
|
|
244
|
+
* out TreeGroup(any) with a TreeGroup(all) and a condition as children
|
|
207
245
|
*
|
|
208
246
|
* in {negate: {any: [cond1, cond2]}}
|
|
209
|
-
* out TreeGroup(not)
|
|
247
|
+
* out TreeGroup(not) with the two conditions as children
|
|
210
248
|
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
*
|
|
249
|
+
* An `any`'s `negate` opens into the «ninguna» group and does not stay as a group
|
|
250
|
+
* inside another: it is what `treeToFilter` writes back, so there and
|
|
251
|
+
* back give the same. What can NOT be read —an object that is neither a
|
|
252
|
+
* condition nor any of the three shapes— returns `null`, and there the component
|
|
253
|
+
* shows it read-only while still letting you touch it as JSON.
|
|
216
254
|
*/
|
|
217
255
|
export function treeFromFilter(filter) {
|
|
218
256
|
if (isCondition(filter))
|
|
219
257
|
return conditionToTree(filter);
|
|
220
258
|
/* A chain of relations ending in ONE condition is one row with its path. A chain that ends
|
|
221
259
|
in a group («alguna línea con impuesto > 10 Y cantidad > 2», both about the SAME line)
|
|
222
|
-
cannot be a row: the tree shows it read-only and the JSON stays the way to edit it.
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
}
|
|
234
|
-
if (!isCondition(node))
|
|
235
|
-
return null;
|
|
236
|
-
return { ...conditionToTree(node), through: hops };
|
|
260
|
+
cannot be a row: the tree shows it read-only and the JSON stays the way to edit it.
|
|
261
|
+
Read before `negate`: «ninguna línea con…» is a `negate` around a `through`, and it is
|
|
262
|
+
one row with its quantifier, not a group. */
|
|
263
|
+
const hops = [];
|
|
264
|
+
let node = filter;
|
|
265
|
+
for (let crossed = crossedOf(node); crossed !== null; crossed = crossedOf(node)) {
|
|
266
|
+
hops.push({ field: crossed.through, match: crossed.match });
|
|
267
|
+
node = crossed.selection;
|
|
268
|
+
}
|
|
269
|
+
if (hops.length > 0) {
|
|
270
|
+
return isCondition(node) ? { ...conditionToTree(node), through: hops } : null;
|
|
237
271
|
}
|
|
238
272
|
if (typeof filter !== "object" || filter === null)
|
|
239
273
|
return null;
|
|
240
274
|
const record = filter;
|
|
241
275
|
if ("negate" in record) {
|
|
242
276
|
const inside = record.negate;
|
|
243
|
-
/*
|
|
244
|
-
|
|
277
|
+
/* An `any`'s `negate` is the negated group's children; anything else
|
|
278
|
+
is a single child. */
|
|
245
279
|
const raws = typeof inside === "object" &&
|
|
246
280
|
inside !== null &&
|
|
247
281
|
Array.isArray(inside.any)
|
|
@@ -260,8 +294,8 @@ export function treeFromFilter(filter) {
|
|
|
260
294
|
const children = readChildren(record[join]);
|
|
261
295
|
return children === null ? null : { kind: "group", join, children };
|
|
262
296
|
}
|
|
263
|
-
/**
|
|
264
|
-
*
|
|
297
|
+
/** A group's children, or `null` if any cannot be read: half a tree is
|
|
298
|
+
* worse than none, because it draws something that is not what filters. */
|
|
265
299
|
function readChildren(raws) {
|
|
266
300
|
const children = [];
|
|
267
301
|
for (const raw of raws) {
|
|
@@ -275,8 +309,8 @@ function readChildren(raws) {
|
|
|
275
309
|
function stringifyFilter(filter) {
|
|
276
310
|
return filter === undefined ? "" : JSON.stringify(filter, null, 2);
|
|
277
311
|
}
|
|
278
|
-
/**
|
|
279
|
-
*
|
|
312
|
+
/** A condition value, legible: a list is joined with commas, and what has nothing is
|
|
313
|
+
* said in words instead of showing a bare `true`/`undefined`. */
|
|
280
314
|
function describeValue(value, operator) {
|
|
281
315
|
const copy = currentCopy();
|
|
282
316
|
if (Array.isArray(value)) {
|
|
@@ -284,15 +318,15 @@ function describeValue(value, operator) {
|
|
|
284
318
|
? value.join(` ${copy.search.and} `)
|
|
285
319
|
: value.join(", ");
|
|
286
320
|
}
|
|
287
|
-
/*
|
|
288
|
-
|
|
321
|
+
/* The same two words the table puts in a boolean cell: a `sí` that
|
|
322
|
+
is not the `sí` next door is a second way of saying the same thing. */
|
|
289
323
|
if (typeof value === "boolean")
|
|
290
324
|
return value ? copy.table.yes : copy.table.no;
|
|
291
325
|
return String(value ?? "");
|
|
292
326
|
}
|
|
293
|
-
/**
|
|
327
|
+
/** The filter said in one line, for a chip or a label.
|
|
294
328
|
*
|
|
295
|
-
* in {field: "row_count", operator: ">", value: 1000},
|
|
329
|
+
* in {field: "row_count", operator: ">", value: 1000}, with the model
|
|
296
330
|
* out 'filas mayor que 1000'
|
|
297
331
|
*
|
|
298
332
|
* in {all: [cond1, cond2]}
|
|
@@ -301,17 +335,17 @@ function describeValue(value, operator) {
|
|
|
301
335
|
* in {any: [cond1, cond2]}
|
|
302
336
|
* out 'el nombre es a o el nombre es b'
|
|
303
337
|
*
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
*
|
|
338
|
+
* Each condition is said by `sayCondition`, which is the same one the bar uses: without
|
|
339
|
+
* that, what is written in the bar and what is built in the dialog read differently even though
|
|
340
|
+
* they filter the same, and nobody knows which of the two phrases is the one in charge.
|
|
307
341
|
*
|
|
308
|
-
* **
|
|
309
|
-
*
|
|
310
|
-
*
|
|
342
|
+
* **The model is the one that knows what a field is called.** Without it the raw
|
|
343
|
+
* name remains —`row_count`—, which is the best that can be said without asking
|
|
344
|
+
* anybody.
|
|
311
345
|
*
|
|
312
|
-
*
|
|
313
|
-
*
|
|
314
|
-
*
|
|
346
|
+
* A nested group is enclosed in parentheses, which is what keeps «a y (b o c)» from being
|
|
347
|
+
* read as «(a y b) o c». Past three conditions it is cut: a chip that does not fit in
|
|
348
|
+
* the bar says nothing — that is what opening the builder and seeing it whole is for. */
|
|
315
349
|
export function describeFilter(node, model,
|
|
316
350
|
/** The model at the end of a path of relations, when it already arrived: it names the
|
|
317
351
|
* fields of a `through`. Without it they keep their raw names. */
|
|
@@ -320,14 +354,17 @@ modelAt) {
|
|
|
320
354
|
}
|
|
321
355
|
function say(node, model, depth, at, modelAt) {
|
|
322
356
|
const copy = currentCopy();
|
|
323
|
-
|
|
357
|
+
const crossed = crossedOf(node);
|
|
358
|
+
if (crossed !== null) {
|
|
324
359
|
/* «alguno de Líneas con alguno de Impuestos con Monto mayor que 10». The quantifier
|
|
325
360
|
is a separate word and not «algún impuesto» because the model publishes the label,
|
|
326
361
|
not its gender or its singular: «algún Impuestos» would be worse than neutral. */
|
|
327
|
-
const relation = model === undefined ?
|
|
328
|
-
const next = [...at,
|
|
329
|
-
const inner = say(
|
|
330
|
-
const template =
|
|
362
|
+
const relation = model === undefined ? crossed.through : fieldLabel(model, crossed.through, copy.locale);
|
|
363
|
+
const next = [...at, crossed.through];
|
|
364
|
+
const inner = say(crossed.selection, modelAt?.(next), depth + 1, next, modelAt);
|
|
365
|
+
const template = reachesOne(model, crossed)
|
|
366
|
+
? copy.fieldPath.say.one
|
|
367
|
+
: copy.fieldPath.say[crossed.match];
|
|
331
368
|
return fillCopy(template, { relation, inner });
|
|
332
369
|
}
|
|
333
370
|
if ("all" in node || "any" in node) {
|
|
@@ -343,45 +380,50 @@ function say(node, model, depth, at, modelAt) {
|
|
|
343
380
|
if ("negate" in node) {
|
|
344
381
|
return `${copy.search.notWord} ${say(node.negate, model, depth + 1, at, modelAt)}`;
|
|
345
382
|
}
|
|
383
|
+
/* Every `through` was said above; anything still not a condition is not a shape of the
|
|
384
|
+
grammar, and it is shown as it came rather than as a sentence it is not. */
|
|
385
|
+
if (!isCondition(node))
|
|
386
|
+
return JSON.stringify(node);
|
|
346
387
|
const label = model === undefined ? node.field : fieldLabel(model, node.field, copy.locale);
|
|
347
388
|
return sayCondition(label, node.operator, describeValue(node.value, node.operator));
|
|
348
389
|
}
|
|
349
|
-
/**
|
|
350
|
-
*
|
|
390
|
+
/** The filter drawn as it is, recursive: a condition is a line, `all`/`any` are a
|
|
391
|
+
* group with its label and its children inside, `negate` is «no» wrapping the one it negates.
|
|
351
392
|
*
|
|
352
|
-
*
|
|
353
|
-
*
|
|
393
|
+
* It is the read-only half of this file, and it also works alone: showing what a
|
|
394
|
+
* filter that is already set says does not need opening the builder. */
|
|
354
395
|
export function ExpressionView({ node, model, depth = 0, modelAt, at = [], }) {
|
|
355
396
|
const surface = useSurface();
|
|
356
397
|
const copy = useUiCopy();
|
|
357
398
|
const box = surface === "chrome" ? "border-chrome-ink/20" : "border-ink/15";
|
|
358
399
|
const indent = depth === 0 ? "" : "ml-4";
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
const
|
|
400
|
+
const crossed = crossedOf(node);
|
|
401
|
+
if (crossed !== null) {
|
|
402
|
+
const relation = model === undefined ? crossed.through : fieldLabel(model, crossed.through, copy.locale);
|
|
403
|
+
const next = [...at, crossed.through];
|
|
362
404
|
const inner = modelAt?.(next);
|
|
363
|
-
return (_jsxs("div", { className: `flex flex-col gap-1 border-l-2 pl-2 ${box} ${indent}`, children: [_jsx("p", { className: "text-micro text-muted", children:
|
|
405
|
+
return (_jsxs("div", { className: `flex flex-col gap-1 border-l-2 pl-2 ${box} ${indent}`, children: [_jsx("p", { className: "text-micro text-muted", children: reachesOne(model, crossed)
|
|
364
406
|
? relation
|
|
365
|
-
: `${copy.fieldPath.match[
|
|
407
|
+
: `${copy.fieldPath.match[crossed.match]} · ${relation}` }), _jsx(ExpressionView, { node: crossed.selection, ...(inner === undefined ? {} : { model: inner }), ...(modelAt === undefined ? {} : { modelAt }), at: next, depth: depth + 1 })] }));
|
|
366
408
|
}
|
|
367
409
|
if ("all" in node || "any" in node) {
|
|
368
|
-
/*
|
|
369
|
-
con alguna»
|
|
370
|
-
|
|
410
|
+
/* THE SAME THREE WORDS AS THE BAR. A group that is called «coincide
|
|
411
|
+
con alguna» here and «cualquiera» on the chip is two vocabularies for one
|
|
412
|
+
thing, and whoever reads them has to learn both. */
|
|
371
413
|
const label = "all" in node ? copy.search.joins.all : copy.search.joins.any;
|
|
372
414
|
const items = "all" in node ? node.all : node.any;
|
|
373
|
-
return (_jsxs("div", { className: `flex flex-col gap-1 border-l-2 pl-2 ${box} ${indent}`, children: [_jsx("p", { className: "text-micro text-muted", children: label }), items.map((child, index) => (_jsx(ExpressionView, { node: child, ...(model === undefined ? {} : { model }), depth: depth + 1 }, index)))] }));
|
|
415
|
+
return (_jsxs("div", { className: `flex flex-col gap-1 border-l-2 pl-2 ${box} ${indent}`, children: [_jsx("p", { className: "text-micro text-muted", children: label }), items.map((child, index) => (_jsx(ExpressionView, { node: child, ...(model === undefined ? {} : { model }), ...(modelAt === undefined ? {} : { modelAt }), at: at, depth: depth + 1 }, index)))] }));
|
|
374
416
|
}
|
|
375
417
|
if ("negate" in node) {
|
|
376
|
-
return (_jsxs("div", { className: `flex flex-col gap-1 border-l-2 pl-2 ${box} ${indent}`, children: [_jsx("p", { className: "text-micro text-muted", children: copy.search.joins.none }), _jsx(ExpressionView, { node: node.negate, ...(model === undefined ? {} : { model }), depth: depth + 1 })] }));
|
|
418
|
+
return (_jsxs("div", { className: `flex flex-col gap-1 border-l-2 pl-2 ${box} ${indent}`, children: [_jsx("p", { className: "text-micro text-muted", children: copy.search.joins.none }), _jsx(ExpressionView, { node: node.negate, ...(model === undefined ? {} : { model }), ...(modelAt === undefined ? {} : { modelAt }), at: at, depth: depth + 1 })] }));
|
|
377
419
|
}
|
|
378
|
-
/*
|
|
420
|
+
/* And the same phrase as the chip: a condition reads the same wherever it is. */
|
|
379
421
|
return _jsx("p", { className: `text-meta ${indent}`, children: describeFilter(node, model) });
|
|
380
422
|
}
|
|
381
423
|
/* ---------------------------------------------------------------------- *
|
|
382
|
-
*
|
|
424
|
+
* A GROUP, DRAWN — the piece that calls itself to nest.
|
|
383
425
|
* ---------------------------------------------------------------------- */
|
|
384
|
-
export function
|
|
426
|
+
export function SelectionTree({ model, group, onChange, depth = 0, focus, loadModel, models: shared, }) {
|
|
385
427
|
const names = filterableNames(model);
|
|
386
428
|
const copy = useUiCopy();
|
|
387
429
|
const surface = useSurface();
|
|
@@ -418,19 +460,19 @@ export function WhereTree({ model, group, onChange, depth = 0, focus, loadModel,
|
|
|
418
460
|
function removeAt(index) {
|
|
419
461
|
onChange({ ...group, children: group.children.filter((_, at) => at !== index) });
|
|
420
462
|
}
|
|
421
|
-
return (_jsxs("div", { className: `flex min-w-0 flex-col gap-2 rounded-control border p-2 ${box}`, children: [_jsxs("p", { className: "flex flex-wrap items-baseline gap-1 text-meta", children: [copy.search.askJoin, _jsx(JoinWord, { join: group.join, onChange: (join) => onChange({ ...group, join }) })] }), group.children.map((child, index) => child.kind === "group" ? (_jsxs("div", { className: "flex min-w-0 items-start gap-2", children: [_jsx("div", { className: "min-w-0 flex-1", children: _jsx(
|
|
463
|
+
return (_jsxs("div", { className: `flex min-w-0 flex-col gap-2 rounded-control border p-2 ${box}`, children: [_jsxs("p", { className: "flex flex-wrap items-baseline gap-1 text-meta", children: [copy.search.askJoin, _jsx(JoinWord, { join: group.join, onChange: (join) => onChange({ ...group, join }) })] }), group.children.map((child, index) => child.kind === "group" ? (_jsxs("div", { className: "flex min-w-0 items-start gap-2", children: [_jsx("div", { className: "min-w-0 flex-1", children: _jsx(SelectionTree, { model: model, group: child, onChange: (next) => setChild(index, next), depth: depth + 1, models: models, ...(focus === undefined ? {} : { focus }) }) }), _jsx("button", { type: "button", "aria-label": copy.builder.dropGroup, disabled: group.children.length === 1, onClick: () => removeAt(index), className: "mt-2 text-muted disabled:opacity-30", children: _jsx(Trash2, { className: "size-4" }) })] }, index)) : (_jsx(ConditionRow, { model: model, models: models, child: child, box: box, focused: focus !== undefined && child.field === focus, onChange: (next) => setChild(index, next), actions: _jsxs("span", { className: "ml-auto flex shrink-0 items-center gap-2", children: [_jsx("button", { type: "button", "aria-label": copy.builder.addRule, onClick: () => addConditionAfter(index), className: "text-muted hover:text-ink", children: _jsx(Plus, { className: "size-4" }) }), _jsx("button", { type: "button", "aria-label": copy.builder.addNested, onClick: () => addGroupAfter(index), className: "text-muted hover:text-ink", children: _jsx(FolderTree, { className: "size-4" }) }), _jsx("button", { type: "button", "aria-label": copy.builder.dropRule, disabled: group.children.length === 1, onClick: () => removeAt(index), className: "text-muted disabled:opacity-30", children: _jsx(Trash2, { className: "size-4" }) })] }) }, index)))] }));
|
|
422
464
|
}
|
|
423
465
|
/* ---------------------------------------------------------------------- *
|
|
424
|
-
*
|
|
466
|
+
* A RULE — the path to the field, how many of each relation, the operator and the value.
|
|
425
467
|
* ---------------------------------------------------------------------- */
|
|
426
468
|
function ConditionRow({ model, models, child, box, focused, onChange, actions, }) {
|
|
427
469
|
const copy = useUiCopy();
|
|
428
470
|
const hops = child.through ?? [];
|
|
429
471
|
const path = child.field === "" ? [] : [...hops.map((hop) => hop.field), child.field];
|
|
430
472
|
const steps = useFieldPathSteps(models, path);
|
|
431
|
-
/*
|
|
432
|
-
|
|
433
|
-
|
|
473
|
+
/* The operator and the value come from the path's LAST field: «Monto», reached through two
|
|
474
|
+
relations, is compared as a number and not as the relation it was reached through. A
|
|
475
|
+
root rule knows it without waiting for anybody. */
|
|
434
476
|
const leaf = steps?.at(-1)?.field ?? (hops.length === 0 ? model.fields[child.field] : undefined);
|
|
435
477
|
const ops = leaf?.ops ?? [];
|
|
436
478
|
const type = leaf?.type ?? "text";
|
|
@@ -440,8 +482,7 @@ function ConditionRow({ model, models, child, box, focused, onChange, actions, }
|
|
|
440
482
|
return;
|
|
441
483
|
const nextHops = found.slice(0, -1).map((step, at) => ({
|
|
442
484
|
field: step.name,
|
|
443
|
-
|
|
444
|
-
/* Cambiar el campo final no reinicia la ficha de una relación que sigue en el camino. */
|
|
485
|
+
/* Changing the final field does not reset the chip of a relation that remains in the path. */
|
|
445
486
|
match: hops[at]?.field === step.name ? hops[at].match : "any",
|
|
446
487
|
}));
|
|
447
488
|
onChange({
|
|
@@ -460,11 +501,15 @@ function ConditionRow({ model, models, child, box, focused, onChange, actions, }
|
|
|
460
501
|
});
|
|
461
502
|
}
|
|
462
503
|
return (_jsxs("div", {
|
|
463
|
-
/*
|
|
464
|
-
|
|
465
|
-
ref: focused ? (node) => node?.scrollIntoView({ block: "nearest" }) : undefined, className: `flex min-w-0 flex-wrap items-center gap-2 rounded-control ${focused ? "-m-1 p-1 ring-1 ring-primary/60" : ""}`, children: [_jsx(FieldPath, { model: model, models: models, value: path, label: copy.builder.ruleField, filter: (field) => isFilterable(field), onChange: choosePath }), hops.map((hop, at) =>
|
|
466
|
-
|
|
467
|
-
|
|
504
|
+
/* The one that was come to see is marked and brought into view. A ring and not
|
|
505
|
+
a background: the background competes with the `select` that has to be touched. */
|
|
506
|
+
ref: focused ? (node) => node?.scrollIntoView({ block: "nearest" }) : undefined, className: `flex min-w-0 flex-wrap items-center gap-2 rounded-control ${focused ? "-m-1 p-1 ring-1 ring-primary/60" : ""}`, children: [_jsx(FieldPath, { model: model, models: models, value: path, label: copy.builder.ruleField, filter: (field) => isFilterable(field), onChange: choosePath }), hops.map((hop, at) => {
|
|
507
|
+
const step = steps?.[at];
|
|
508
|
+
const many = step !== undefined && isToMany(step.field);
|
|
509
|
+
return hop.match !== "any" || many ? (_jsxs("label", { className: `flex min-w-0 shrink-0 items-center gap-1 rounded-control border px-2 py-0.5 text-micro ${box}`, children: [_jsx("span", { className: "max-w-32 truncate text-muted", children: step?.label ?? hop.field }), _jsx("select", { "aria-label": fillCopy(copy.fieldPath.match.label, {
|
|
510
|
+
relation: step?.label ?? hop.field,
|
|
511
|
+
}), value: hop.match, onChange: (event) => setMatch(at, event.target.value), className: "bg-transparent text-micro font-medium", children: MATCHES.map((match) => (_jsx("option", { value: match, children: copy.fieldPath.match[match] }, match))) })] }, `${hop.field}-${at}`)) : null;
|
|
512
|
+
}), _jsx("select", { "aria-label": copy.builder.ruleOperator, value: child.operator, onChange: (event) => onChange({ ...child, operator: event.target.value }), className: `min-w-0 flex-1 basis-36 rounded-control border px-2 py-1 text-meta ${box}`, children: ops.map((operator) => (_jsx("option", { value: operator, children: opLabel(operator) }, operator))) }), WITHOUT_VALUE.has(child.operator) ? (_jsx("span", { className: "flex-1 text-meta text-muted", children: copy.builder.noValue })) : WITH_RANGE.has(child.operator) ? (_jsxs("span", { className: "flex min-w-0 flex-1 basis-40 items-center gap-1", children: [_jsx("input", { type: inputType(type), value: child.value, onChange: (event) => onChange({ ...child, value: event.target.value }), placeholder: copy.builder.from, className: `min-w-0 flex-1 rounded-control border px-2 py-1 text-meta ${box}` }), _jsx("span", { className: "shrink-0 text-micro text-muted", children: copy.search.and }), _jsx("input", { type: inputType(type), value: child.upper ?? "", onChange: (event) => onChange({ ...child, upper: event.target.value }), placeholder: copy.builder.to, className: `min-w-0 flex-1 rounded-control border px-2 py-1 text-meta ${box}` })] })) : (_jsx("input", { type: inputType(type), value: child.value, onChange: (event) => onChange({ ...child, value: event.target.value }), placeholder: copy.builder.value, className: `min-w-0 flex-1 basis-40 rounded-control border px-2 py-1 text-meta ${box}` })), actions] }));
|
|
468
513
|
}
|
|
469
514
|
export function FilterBuilder({ model, initial, onApply, onCancel, loadModel, models: shared, }) {
|
|
470
515
|
const names = filterableNames(model);
|
|
@@ -479,18 +524,18 @@ export function FilterBuilder({ model, initial, onApply, onCancel, loadModel, mo
|
|
|
479
524
|
const [lockedView, setLockedView] = useState(initial !== undefined && decomposed === null ? initial : null);
|
|
480
525
|
const [rawText, setRawText] = useState(() => stringifyFilter(initial ?? treeToFilter(tree)));
|
|
481
526
|
const [rawError, setRawError] = useState(null);
|
|
482
|
-
/*
|
|
483
|
-
|
|
527
|
+
/* Touching the tree rewrites the JSON so it shows exactly what the tree now says,
|
|
528
|
+
and drops any read-only view that may have been left. */
|
|
484
529
|
function updateTree(next) {
|
|
485
530
|
setTree(next);
|
|
486
531
|
setLockedView(null);
|
|
487
532
|
setRawText(stringifyFilter(treeToFilter(next)));
|
|
488
533
|
setRawError(null);
|
|
489
534
|
}
|
|
490
|
-
/*
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
535
|
+
/* Writing in the JSON tries the same the other way round: if what was typed brings no `negate` at
|
|
536
|
+
any level, the tree is rebuilt to show it — AND and OR, at any depth. If it brings
|
|
537
|
+
one, it is drawn read-only, but the JSON remains what will be applied. If it is
|
|
538
|
+
neither —half-written, or not a filter— what was there is not touched. */
|
|
494
539
|
function updateRaw(text) {
|
|
495
540
|
setRawText(text);
|
|
496
541
|
if (text.trim() === "") {
|
|
@@ -521,5 +566,5 @@ export function FilterBuilder({ model, initial, onApply, onCancel, loadModel, mo
|
|
|
521
566
|
setLockedView(parsed);
|
|
522
567
|
}
|
|
523
568
|
}
|
|
524
|
-
return (_jsxs("div", { className: "flex min-w-0 flex-col gap-3 p-3", children: [_jsx("div", { className: "max-h-80 min-w-0 overflow-auto", children: lockedView !== null ? (_jsxs(_Fragment, { children: [_jsx("p", { className: "text-meta text-muted", children: copy.search.unreadable }), _jsx(ExpressionView, { node: lockedView, model: model, modelAt: models.peek })] })) : (_jsx(
|
|
569
|
+
return (_jsxs("div", { className: "flex min-w-0 flex-col gap-3 p-3", children: [_jsx("div", { className: "max-h-80 min-w-0 overflow-auto", children: lockedView !== null ? (_jsxs(_Fragment, { children: [_jsx("p", { className: "text-meta text-muted", children: copy.search.unreadable }), _jsx(ExpressionView, { node: lockedView, model: model, modelAt: models.peek })] })) : (_jsx(SelectionTree, { model: model, group: tree, onChange: updateTree, models: models })) }), _jsx(LazyJsonEditor, { value: rawText, onChange: updateRaw, error: rawError, label: copy.builder.jsonFilter }), _jsxs("div", { className: "flex gap-2", children: [_jsx(Button, { role: "primary", disabled: rawError !== null, onClick: () => onApply(rawText.trim() === "" ? undefined : JSON.parse(rawText)), children: copy.builder.add }), onCancel === undefined ? null : (_jsx(Button, { role: "ghost", onClick: onCancel, children: copy.builder.cancel }))] })] }));
|
|
525
570
|
}
|