@olenbetong/synergi-react 3.0.0 → 3.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/es/filter/index.d.ts +8 -11
- package/es/filter/index.js +8 -10
- package/es/report/ReportLauncher.d.ts +1 -1
- package/es/report/ReportLauncher.js +1 -1
- package/es/report/ReportParameters.d.ts +1 -1
- package/package.json +6 -6
- package/src/components/ImageEditor/ImageEditor.css +5 -5
- package/src/components/ImageEditor/ImageEditor.tsx +1 -1
- package/src/filter/index.ts +34 -11
- package/src/report/ReportLauncher.tsx +1 -2
- package/src/report/ReportParameters.tsx +1 -1
- package/es/filter/ChipListInput.d.ts +0 -13
- package/es/filter/ChipListInput.js +0 -34
- package/es/filter/FilterBuilder.css +0 -152
- package/es/filter/FilterBuilder.d.ts +0 -115
- package/es/filter/FilterBuilder.js +0 -146
- package/es/filter/FilterBuilder.test.d.ts +0 -1
- package/es/filter/FilterBuilder.test.js +0 -120
- package/es/filter/FilterEditor.css +0 -231
- package/es/filter/FilterEditor.d.ts +0 -17
- package/es/filter/FilterEditor.js +0 -38
- package/es/filter/FilterEditor.test.d.ts +0 -1
- package/es/filter/FilterEditor.test.js +0 -183
- package/es/filter/FilterGroupEditor.d.ts +0 -22
- package/es/filter/FilterGroupEditor.js +0 -34
- package/es/filter/FilterNameDialog.css +0 -22
- package/es/filter/FilterNameDialog.d.ts +0 -18
- package/es/filter/FilterNameDialog.js +0 -32
- package/es/filter/FilterRow.d.ts +0 -14
- package/es/filter/FilterRow.js +0 -32
- package/es/filter/FilterShareDialog.css +0 -28
- package/es/filter/FilterShareDialog.d.ts +0 -23
- package/es/filter/FilterShareDialog.js +0 -63
- package/es/filter/FilterStringField.d.ts +0 -15
- package/es/filter/FilterStringField.js +0 -37
- package/es/filter/FilterValueEditor.d.ts +0 -16
- package/es/filter/FilterValueEditor.js +0 -85
- package/es/filter/SavedFilterTree.css +0 -107
- package/es/filter/SavedFilterTree.d.ts +0 -45
- package/es/filter/SavedFilterTree.js +0 -44
- package/es/filter/SavedFilterTree.test.d.ts +0 -1
- package/es/filter/SavedFilterTree.test.js +0 -75
- package/es/filter/types.d.ts +0 -34
- package/es/filter/types.js +0 -1
- package/src/filter/ChipListInput.tsx +0 -79
- package/src/filter/FilterBuilder.css +0 -152
- package/src/filter/FilterBuilder.test.tsx +0 -153
- package/src/filter/FilterBuilder.tsx +0 -435
- package/src/filter/FilterEditor.css +0 -231
- package/src/filter/FilterEditor.test.tsx +0 -259
- package/src/filter/FilterEditor.tsx +0 -74
- package/src/filter/FilterGroupEditor.tsx +0 -160
- package/src/filter/FilterNameDialog.css +0 -22
- package/src/filter/FilterNameDialog.tsx +0 -81
- package/src/filter/FilterRow.tsx +0 -117
- package/src/filter/FilterShareDialog.css +0 -28
- package/src/filter/FilterShareDialog.tsx +0 -201
- package/src/filter/FilterStringField.tsx +0 -77
- package/src/filter/FilterValueEditor.tsx +0 -220
- package/src/filter/SavedFilterTree.css +0 -107
- package/src/filter/SavedFilterTree.test.tsx +0 -94
- package/src/filter/SavedFilterTree.tsx +0 -222
- package/src/filter/types.ts +0 -38
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
.ObFilterEditor-root {
|
|
2
|
-
display: flex;
|
|
3
|
-
flex-direction: column;
|
|
4
|
-
gap: var(--ds-size-2);
|
|
5
|
-
min-block-size: 0;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
/*
|
|
9
|
-
* The conditions scroll, the generated filter string does not, so it stays in
|
|
10
|
-
* view at the foot of the editor. The flex basis keeps the scroll area usable
|
|
11
|
-
* when the editor is short, as on a phone, but — unlike a minimum height — it
|
|
12
|
-
* still lets the editor shrink when it shares a fixed height with content below
|
|
13
|
-
* it, which would otherwise overflow and overlap that content.
|
|
14
|
-
*/
|
|
15
|
-
.ObFilterEditor-body {
|
|
16
|
-
display: flex;
|
|
17
|
-
flex-direction: column;
|
|
18
|
-
gap: var(--ds-size-2);
|
|
19
|
-
flex: 1 1 min(16rem, 50dvh);
|
|
20
|
-
min-block-size: 0;
|
|
21
|
-
overflow: auto;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
.ObFilterEditor-filterString {
|
|
25
|
-
flex: 0 0 auto;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
.ObFilterEditor-intro {
|
|
29
|
-
margin: 0;
|
|
30
|
-
color: var(--ds-color-neutral-text-subtle);
|
|
31
|
-
font-size: var(--ds-font-size-2);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
.ObFilterEditor-groups {
|
|
35
|
-
display: flex;
|
|
36
|
-
flex-direction: column;
|
|
37
|
-
gap: var(--ds-size-3);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
.ObFilterEditor-group {
|
|
41
|
-
display: flex;
|
|
42
|
-
flex-direction: column;
|
|
43
|
-
gap: var(--ds-size-2);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/*
|
|
47
|
-
* The border is drawn around the conditions only, not the group header, and the
|
|
48
|
-
* whole box is indented so the header reads as owning the conditions below it
|
|
49
|
-
* rather than as a sibling of the first one.
|
|
50
|
-
*/
|
|
51
|
-
.ObFilterEditor-groupItems {
|
|
52
|
-
display: flex;
|
|
53
|
-
flex-direction: column;
|
|
54
|
-
gap: var(--ds-size-2);
|
|
55
|
-
|
|
56
|
-
margin-inline-start: var(--ds-size-4);
|
|
57
|
-
padding: var(--ds-size-2);
|
|
58
|
-
border: 1px solid var(--ds-color-neutral-border-subtle);
|
|
59
|
-
border-radius: var(--ds-border-radius-md);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/* Nested groups are tinted so the tree structure is readable. */
|
|
63
|
-
.ObFilterEditor-groupItems .ObFilterEditor-groupItems {
|
|
64
|
-
background-color: var(--ds-color-neutral-surface-tinted);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
.ObFilterEditor-groupHeader {
|
|
68
|
-
display: flex;
|
|
69
|
-
align-items: center;
|
|
70
|
-
gap: var(--ds-size-2);
|
|
71
|
-
flex-wrap: wrap;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
.ObFilterEditor-groupButton svg {
|
|
75
|
-
flex: 0 0 auto;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/*
|
|
79
|
-
* The group buttons do not fit next to the operator select on a phone, so only
|
|
80
|
-
* their icon is shown. `aria-label` carries the name either way.
|
|
81
|
-
*/
|
|
82
|
-
@media (width < 40rem) {
|
|
83
|
-
.ObFilterEditor-groupButtonLabel {
|
|
84
|
-
display: none;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
.ObFilterEditor-groupItems {
|
|
88
|
-
margin-inline-start: var(--ds-size-2);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
.ObFilterEditor-groupMode {
|
|
93
|
-
flex: 0 0 auto;
|
|
94
|
-
width: auto;
|
|
95
|
-
min-width: 6rem;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
.ObFilterEditor-groupLabel {
|
|
99
|
-
font-weight: 600;
|
|
100
|
-
font-size: var(--ds-font-size-2);
|
|
101
|
-
text-transform: uppercase;
|
|
102
|
-
letter-spacing: 0.04em;
|
|
103
|
-
color: var(--ds-color-neutral-text-subtle);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
.ObFilterEditor-row {
|
|
107
|
-
display: flex;
|
|
108
|
-
align-items: center;
|
|
109
|
-
gap: var(--ds-size-2);
|
|
110
|
-
flex-wrap: wrap;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/*
|
|
114
|
-
* On narrow viewports the parts of a condition wrap onto several lines, which
|
|
115
|
-
* makes neighbouring conditions run together. Separate them with extra spacing
|
|
116
|
-
* and a rule so it stays obvious where one condition ends and the next begins.
|
|
117
|
-
*/
|
|
118
|
-
@media (width < 40rem) {
|
|
119
|
-
.ObFilterEditor-row {
|
|
120
|
-
gap: var(--ds-size-3);
|
|
121
|
-
padding-block-end: var(--ds-size-3);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
.ObFilterEditor-row:not(:last-child) {
|
|
125
|
-
border-block-end: 1px solid var(--ds-color-neutral-border-subtle);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
.ObFilterEditor-field {
|
|
130
|
-
flex: 1 1 12rem;
|
|
131
|
-
min-width: 10rem;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
.ObFilterEditor-operator {
|
|
135
|
-
flex: 0 1 12rem;
|
|
136
|
-
min-width: 8rem;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
.ObFilterEditor-valueCell {
|
|
140
|
-
display: flex;
|
|
141
|
-
align-items: center;
|
|
142
|
-
gap: var(--ds-size-1);
|
|
143
|
-
flex: 2 1 14rem;
|
|
144
|
-
min-width: 10rem;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
.ObFilterEditor-value {
|
|
148
|
-
flex: 1 1 auto;
|
|
149
|
-
min-width: 0;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
.ObFilterEditor-pair {
|
|
153
|
-
display: flex;
|
|
154
|
-
align-items: center;
|
|
155
|
-
gap: var(--ds-size-2);
|
|
156
|
-
flex: 1 1 auto;
|
|
157
|
-
min-width: 0;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
.ObFilterEditor-pairSeparator {
|
|
161
|
-
flex: 0 0 auto;
|
|
162
|
-
color: var(--ds-color-neutral-text-subtle);
|
|
163
|
-
font-size: var(--ds-font-size-2);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
.ObFilterEditor-chipList {
|
|
167
|
-
display: flex;
|
|
168
|
-
align-items: center;
|
|
169
|
-
flex-wrap: wrap;
|
|
170
|
-
gap: var(--ds-size-1);
|
|
171
|
-
flex: 1 1 auto;
|
|
172
|
-
min-width: 0;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
.ObFilterEditor-chipListInput {
|
|
176
|
-
flex: 1 1 6rem;
|
|
177
|
-
min-width: 6rem;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
.ObFilterEditor-iconButton {
|
|
181
|
-
display: inline-flex;
|
|
182
|
-
align-items: center;
|
|
183
|
-
justify-content: center;
|
|
184
|
-
flex: 0 0 auto;
|
|
185
|
-
|
|
186
|
-
width: 2rem;
|
|
187
|
-
height: 2rem;
|
|
188
|
-
padding: 0;
|
|
189
|
-
|
|
190
|
-
background: none;
|
|
191
|
-
border: none;
|
|
192
|
-
border-radius: var(--ds-border-radius-md);
|
|
193
|
-
color: var(--ds-color-neutral-text-subtle);
|
|
194
|
-
cursor: pointer;
|
|
195
|
-
|
|
196
|
-
&:hover {
|
|
197
|
-
background-color: var(--ds-color-neutral-surface-hover);
|
|
198
|
-
color: var(--ds-color-neutral-text-default);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
&[aria-pressed="true"] {
|
|
202
|
-
background-color: var(--ds-color-surface-active);
|
|
203
|
-
color: var(--ds-color-text-default);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
svg {
|
|
207
|
-
width: 1.25rem;
|
|
208
|
-
height: 1.25rem;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
.ObFilterEditor-filterString {
|
|
213
|
-
display: flex;
|
|
214
|
-
flex-direction: column;
|
|
215
|
-
gap: var(--ds-size-1);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
.ObFilterEditor-hint {
|
|
219
|
-
color: var(--ds-color-neutral-text-subtle);
|
|
220
|
-
font-size: var(--ds-font-size-1);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/*
|
|
224
|
-
* The converting hint sits on the label row rather than under the input, so that
|
|
225
|
-
* it appearing and disappearing does not shift the layout.
|
|
226
|
-
*/
|
|
227
|
-
.ObFilterEditor-filterStringLabel {
|
|
228
|
-
display: flex;
|
|
229
|
-
align-items: baseline;
|
|
230
|
-
gap: var(--ds-size-2);
|
|
231
|
-
}
|
|
@@ -1,259 +0,0 @@
|
|
|
1
|
-
import type { FieldMetadata, FilterExpression, FilterTree } from "@olenbetong/appframe-core";
|
|
2
|
-
import { render, screen } from "@testing-library/react";
|
|
3
|
-
import userEvent from "@testing-library/user-event";
|
|
4
|
-
import { describe, expect, it, vi } from "vitest";
|
|
5
|
-
|
|
6
|
-
import { FilterEditor } from "./FilterEditor.js";
|
|
7
|
-
|
|
8
|
-
const FIELDS: FieldMetadata[] = [
|
|
9
|
-
{ name: "PersonID", caption: "Person ID", type: "string", nullable: true },
|
|
10
|
-
{ name: "Age", caption: "Age", type: "number" },
|
|
11
|
-
{ name: "Created", caption: "Created", type: "datetime" },
|
|
12
|
-
{ name: "IsActive", caption: "Is active", type: "boolean" },
|
|
13
|
-
{ name: "Secret", caption: "Secret", type: "string", excludeFromFilter: true },
|
|
14
|
-
];
|
|
15
|
-
|
|
16
|
-
/** A tree with a single root `and` group holding one expression. */
|
|
17
|
-
function filterWith(column: string, operator: string, value: unknown, valueType = "string"): FilterTree {
|
|
18
|
-
return {
|
|
19
|
-
type: "group",
|
|
20
|
-
mode: "and",
|
|
21
|
-
items: [{ type: "expression", column, operator, value, valueType } as never],
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function firstExpression(onChange: ReturnType<typeof vi.fn>, call = 0) {
|
|
26
|
-
let [filter] = onChange.mock.calls[call] as [FilterTree];
|
|
27
|
-
|
|
28
|
-
return filter.items[0] as FilterExpression;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
describe("FilterEditor", () => {
|
|
32
|
-
it("renders one row per expression", () => {
|
|
33
|
-
render(<FilterEditor fields={FIELDS} value={filterWith("PersonID", "beginswith", "silv")} />);
|
|
34
|
-
|
|
35
|
-
expect(screen.getAllByLabelText("Field")).toHaveLength(1);
|
|
36
|
-
expect(screen.getByLabelText("Operator")).toHaveValue("beginswith");
|
|
37
|
-
expect(screen.getByLabelText("Value")).toHaveValue("silv");
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it("wraps a bare expression in a group", () => {
|
|
41
|
-
let filter = {
|
|
42
|
-
type: "expression",
|
|
43
|
-
column: "Age",
|
|
44
|
-
operator: "equals",
|
|
45
|
-
value: "42",
|
|
46
|
-
valueType: "number",
|
|
47
|
-
} as never as FilterTree;
|
|
48
|
-
|
|
49
|
-
render(<FilterEditor fields={FIELDS} value={filter} />);
|
|
50
|
-
|
|
51
|
-
expect(screen.getByLabelText("Value")).toHaveValue(42);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it("hides fields marked as excluded from the field picker", async () => {
|
|
55
|
-
let user = userEvent.setup();
|
|
56
|
-
render(<FilterEditor fields={FIELDS} value={{ type: "group", mode: "and", items: [] }} />);
|
|
57
|
-
|
|
58
|
-
await user.click(screen.getByLabelText("Add condition"));
|
|
59
|
-
|
|
60
|
-
expect(screen.queryByRole("option", { name: "Secret" })).not.toBeInTheDocument();
|
|
61
|
-
expect(screen.getByRole("option", { name: "Person ID" })).toBeInTheDocument();
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it("adds an expression when a field is picked in the blank row", async () => {
|
|
65
|
-
let user = userEvent.setup();
|
|
66
|
-
let onChange = vi.fn();
|
|
67
|
-
render(<FilterEditor fields={FIELDS} value={filterWith("PersonID", "beginswith", "silv")} onChange={onChange} />);
|
|
68
|
-
|
|
69
|
-
await user.click(screen.getByLabelText("Add condition"));
|
|
70
|
-
await user.click(screen.getByRole("option", { name: "Age" }));
|
|
71
|
-
|
|
72
|
-
expect(onChange).toHaveBeenCalledTimes(1);
|
|
73
|
-
let [filter] = onChange.mock.calls[0] as [FilterTree];
|
|
74
|
-
|
|
75
|
-
expect(filter.items).toHaveLength(2);
|
|
76
|
-
// Numbers default to "equals", strings to "begins with".
|
|
77
|
-
expect(filter.items[1]).toMatchObject({ column: "Age", operator: "equals", valueType: "number" });
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it("changes the operator and resets the value when the arity changes", async () => {
|
|
81
|
-
let user = userEvent.setup();
|
|
82
|
-
let onChange = vi.fn();
|
|
83
|
-
render(<FilterEditor fields={FIELDS} value={filterWith("Age", "equals", "42", "number")} onChange={onChange} />);
|
|
84
|
-
|
|
85
|
-
await user.selectOptions(screen.getByLabelText("Operator"), "between");
|
|
86
|
-
|
|
87
|
-
expect(firstExpression(onChange)).toMatchObject({ operator: "between", value: ["", ""] });
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it("renders no value editor for parameterless operators", () => {
|
|
91
|
-
render(<FilterEditor fields={FIELDS} value={filterWith("IsActive", "istrue", null, "null")} />);
|
|
92
|
-
|
|
93
|
-
expect(screen.queryByLabelText("Value")).not.toBeInTheDocument();
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it("renders two inputs for range operators", () => {
|
|
97
|
-
render(<FilterEditor fields={FIELDS} value={filterWith("Age", "between", ["1", "10"], "number")} />);
|
|
98
|
-
|
|
99
|
-
expect(screen.getByLabelText("From")).toHaveValue(1);
|
|
100
|
-
expect(screen.getByLabelText("To")).toHaveValue(10);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it("renders one chip per value for list operators", () => {
|
|
104
|
-
render(<FilterEditor fields={FIELDS} value={filterWith("PersonID", "inlist", ["a", "b"])} />);
|
|
105
|
-
|
|
106
|
-
expect(screen.getByRole("button", { name: "Remove a" })).toBeInTheDocument();
|
|
107
|
-
expect(screen.getByRole("button", { name: "Remove b" })).toBeInTheDocument();
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it("adds a list value on Enter", async () => {
|
|
111
|
-
let user = userEvent.setup();
|
|
112
|
-
let onChange = vi.fn();
|
|
113
|
-
render(<FilterEditor fields={FIELDS} value={filterWith("PersonID", "inlist", ["a"])} onChange={onChange} />);
|
|
114
|
-
|
|
115
|
-
await user.type(screen.getByLabelText("Value"), "b{Enter}");
|
|
116
|
-
|
|
117
|
-
let [filter] = onChange.mock.calls.at(-1) as [FilterTree];
|
|
118
|
-
|
|
119
|
-
expect((filter.items[0] as FilterExpression).value).toEqual(["a", "b"]);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it("switches a date value to a relative value", async () => {
|
|
123
|
-
let user = userEvent.setup();
|
|
124
|
-
let onChange = vi.fn();
|
|
125
|
-
render(
|
|
126
|
-
<FilterEditor fields={FIELDS} value={filterWith("Created", "equals", "", "datetime")} onChange={onChange} />,
|
|
127
|
-
);
|
|
128
|
-
|
|
129
|
-
await user.click(screen.getByRole("button", { name: "Use a relative value" }));
|
|
130
|
-
|
|
131
|
-
expect(firstExpression(onChange)).toMatchObject({ value: "Yesterday", valueType: "special" });
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it("does not offer relative values for numbers", () => {
|
|
135
|
-
render(<FilterEditor fields={FIELDS} value={filterWith("Age", "equals", "1", "number")} />);
|
|
136
|
-
|
|
137
|
-
expect(screen.queryByRole("button", { name: "Use a relative value" })).not.toBeInTheDocument();
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it("removes a condition", async () => {
|
|
141
|
-
let user = userEvent.setup();
|
|
142
|
-
let onChange = vi.fn();
|
|
143
|
-
render(<FilterEditor fields={FIELDS} value={filterWith("PersonID", "beginswith", "silv")} onChange={onChange} />);
|
|
144
|
-
|
|
145
|
-
await user.click(screen.getByRole("button", { name: "Remove condition" }));
|
|
146
|
-
|
|
147
|
-
let [filter] = onChange.mock.calls[0] as [FilterTree];
|
|
148
|
-
|
|
149
|
-
expect(filter.items).toHaveLength(0);
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
it("hides every editing affordance when read only", () => {
|
|
153
|
-
render(<FilterEditor fields={FIELDS} value={filterWith("PersonID", "beginswith", "silv")} readOnly />);
|
|
154
|
-
|
|
155
|
-
expect(screen.queryByLabelText("Add condition")).not.toBeInTheDocument();
|
|
156
|
-
expect(screen.queryByRole("button", { name: "Remove condition" })).not.toBeInTheDocument();
|
|
157
|
-
expect(screen.queryByRole("button", { name: "Add group" })).not.toBeInTheDocument();
|
|
158
|
-
expect(screen.getByLabelText("Group operator")).toBeDisabled();
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it("keeps a row editable when the field is not in the view", () => {
|
|
162
|
-
render(<FilterEditor fields={FIELDS} value={filterWith("Removed", "equals", "x")} />);
|
|
163
|
-
|
|
164
|
-
expect(screen.getByLabelText("Field")).toHaveValue("Removed");
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
it("uses supplied options as a value list", () => {
|
|
168
|
-
render(
|
|
169
|
-
<FilterEditor
|
|
170
|
-
fields={FIELDS}
|
|
171
|
-
value={filterWith("PersonID", "equals", "a")}
|
|
172
|
-
getFieldOptions={(field) =>
|
|
173
|
-
field.name === "PersonID"
|
|
174
|
-
? [
|
|
175
|
-
{ value: "a", label: "Alpha" },
|
|
176
|
-
{ value: "b", label: "Bravo" },
|
|
177
|
-
]
|
|
178
|
-
: undefined
|
|
179
|
-
}
|
|
180
|
-
/>,
|
|
181
|
-
);
|
|
182
|
-
|
|
183
|
-
expect(screen.getByLabelText("Value")).toHaveValue("Alpha");
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
it("changes the mode of the root group", async () => {
|
|
187
|
-
let user = userEvent.setup();
|
|
188
|
-
let onChange = vi.fn();
|
|
189
|
-
render(<FilterEditor fields={FIELDS} value={filterWith("PersonID", "beginswith", "silv")} onChange={onChange} />);
|
|
190
|
-
|
|
191
|
-
expect(screen.getByLabelText("Group operator")).toHaveValue("and");
|
|
192
|
-
|
|
193
|
-
await user.selectOptions(screen.getByLabelText("Group operator"), "or");
|
|
194
|
-
|
|
195
|
-
let [filter] = onChange.mock.calls[0] as [FilterTree];
|
|
196
|
-
|
|
197
|
-
expect(filter.mode).toBe("or");
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
it("adds and removes nested groups", async () => {
|
|
201
|
-
let user = userEvent.setup();
|
|
202
|
-
let onChange = vi.fn();
|
|
203
|
-
let { rerender } = render(
|
|
204
|
-
<FilterEditor fields={FIELDS} value={filterWith("PersonID", "beginswith", "silv")} onChange={onChange} />,
|
|
205
|
-
);
|
|
206
|
-
|
|
207
|
-
expect(screen.queryByRole("button", { name: "Remove group" })).not.toBeInTheDocument();
|
|
208
|
-
|
|
209
|
-
await user.click(screen.getByRole("button", { name: "Add group" }));
|
|
210
|
-
|
|
211
|
-
let [withGroup] = onChange.mock.calls[0] as [FilterTree];
|
|
212
|
-
expect(withGroup.items).toHaveLength(2);
|
|
213
|
-
// A nested group defaults to the opposite mode of its parent.
|
|
214
|
-
expect(withGroup.items[1]).toMatchObject({ type: "group", mode: "or", items: [] });
|
|
215
|
-
|
|
216
|
-
rerender(<FilterEditor fields={FIELDS} value={withGroup} onChange={onChange} />);
|
|
217
|
-
expect(screen.getAllByLabelText("Group operator")).toHaveLength(2);
|
|
218
|
-
|
|
219
|
-
await user.click(screen.getByRole("button", { name: "Remove group" }));
|
|
220
|
-
|
|
221
|
-
let [removed] = onChange.mock.calls[1] as [FilterTree];
|
|
222
|
-
expect(removed.items).toHaveLength(1);
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
it("edits a condition inside a nested group", async () => {
|
|
226
|
-
let user = userEvent.setup();
|
|
227
|
-
let onChange = vi.fn();
|
|
228
|
-
let filter: FilterTree = {
|
|
229
|
-
type: "group",
|
|
230
|
-
mode: "and",
|
|
231
|
-
items: [
|
|
232
|
-
{ type: "expression", column: "Age", operator: "equals", value: "1", valueType: "number" },
|
|
233
|
-
{
|
|
234
|
-
type: "group",
|
|
235
|
-
mode: "or",
|
|
236
|
-
items: [{ type: "expression", column: "PersonID", operator: "beginswith", value: "a", valueType: "string" }],
|
|
237
|
-
},
|
|
238
|
-
],
|
|
239
|
-
};
|
|
240
|
-
render(<FilterEditor fields={FIELDS} value={filter} onChange={onChange} />);
|
|
241
|
-
|
|
242
|
-
await user.click(screen.getAllByRole("button", { name: "Remove condition" })[1]);
|
|
243
|
-
|
|
244
|
-
let [next] = onChange.mock.calls[0] as [FilterTree];
|
|
245
|
-
|
|
246
|
-
expect(next.items[0]).toMatchObject({ column: "Age" });
|
|
247
|
-
expect(next.items[1]).toMatchObject({ type: "group", items: [] });
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
it("keeps its own state when uncontrolled", async () => {
|
|
251
|
-
let user = userEvent.setup();
|
|
252
|
-
render(<FilterEditor fields={FIELDS} defaultValue={filterWith("PersonID", "beginswith", "silv")} />);
|
|
253
|
-
|
|
254
|
-
await user.clear(screen.getByLabelText("Value"));
|
|
255
|
-
await user.type(screen.getByLabelText("Value"), "gold");
|
|
256
|
-
|
|
257
|
-
expect(screen.getByLabelText("Value")).toHaveValue("gold");
|
|
258
|
-
});
|
|
259
|
-
});
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import "./FilterEditor.css";
|
|
2
|
-
|
|
3
|
-
import { type FilterTree, getLocalizedString, toFilterTree } from "@olenbetong/appframe-core";
|
|
4
|
-
import clsx from "clsx";
|
|
5
|
-
import { useMemo, useState } from "react";
|
|
6
|
-
|
|
7
|
-
import { FilterGroupEditor } from "./FilterGroupEditor.js";
|
|
8
|
-
import { FilterStringField } from "./FilterStringField.js";
|
|
9
|
-
import type { FilterEditorProps } from "./types.js";
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* The criteria tree of the filter builder. Groups can be nested and each group
|
|
13
|
-
* combines its items with either `and` or `or`, matching the advanced filter
|
|
14
|
-
* editor in the Windows client.
|
|
15
|
-
*
|
|
16
|
-
* Works both controlled (`value` + `onChange`) and uncontrolled
|
|
17
|
-
* (`defaultValue`). Saving and sharing filters is handled by `FilterBuilder`,
|
|
18
|
-
* which composes this component.
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* ```jsx
|
|
22
|
-
* <FilterEditor fields={fields} value={filter} onChange={setFilter} showFilterString />
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
export function FilterEditor({
|
|
26
|
-
fields,
|
|
27
|
-
value,
|
|
28
|
-
defaultValue,
|
|
29
|
-
onChange,
|
|
30
|
-
readOnly,
|
|
31
|
-
showFilterString,
|
|
32
|
-
viewName,
|
|
33
|
-
getFieldOptions,
|
|
34
|
-
className,
|
|
35
|
-
"data-size": size = "sm",
|
|
36
|
-
}: FilterEditorProps) {
|
|
37
|
-
let [uncontrolled, setUncontrolled] = useState<FilterTree>(() => toFilterTree(defaultValue));
|
|
38
|
-
let isControlled = value !== undefined;
|
|
39
|
-
// Normalizing on every render would create a new tree each time, which
|
|
40
|
-
// retriggers the filter string conversion.
|
|
41
|
-
let controlled = useMemo(() => toFilterTree(value), [value]);
|
|
42
|
-
let filter = isControlled ? controlled : uncontrolled;
|
|
43
|
-
|
|
44
|
-
let visibleFields = useMemo(() => fields.filter((field) => !field.excludeFromFilter), [fields]);
|
|
45
|
-
|
|
46
|
-
function update(next: FilterTree) {
|
|
47
|
-
if (!isControlled) setUncontrolled(next);
|
|
48
|
-
onChange?.(next);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return (
|
|
52
|
-
<div className={clsx("ObFilterEditor-root", className)} data-size={size}>
|
|
53
|
-
<div className="ObFilterEditor-body">
|
|
54
|
-
<p className="ObFilterEditor-intro">
|
|
55
|
-
{filter.mode === "and"
|
|
56
|
-
? getLocalizedString("Find rows that match all of these criteria:")
|
|
57
|
-
: getLocalizedString("Find rows that match one or more of these criteria:")}
|
|
58
|
-
</p>
|
|
59
|
-
<FilterGroupEditor
|
|
60
|
-
filter={filter}
|
|
61
|
-
path={[]}
|
|
62
|
-
fields={visibleFields}
|
|
63
|
-
getFieldOptions={getFieldOptions}
|
|
64
|
-
readOnly={readOnly}
|
|
65
|
-
data-size={size}
|
|
66
|
-
onChange={update}
|
|
67
|
-
/>
|
|
68
|
-
</div>
|
|
69
|
-
{showFilterString && (
|
|
70
|
-
<FilterStringField filter={filter} viewName={viewName} readOnly={readOnly} data-size={size} onChange={update} />
|
|
71
|
-
)}
|
|
72
|
-
</div>
|
|
73
|
-
);
|
|
74
|
-
}
|