@olenbetong/synergi-react 2.9.0 → 3.0.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.
Files changed (113) hide show
  1. package/es/chrome/AppShell/index.d.ts +8 -0
  2. package/es/chrome/AppShell/index.js +10 -130
  3. package/es/components/ImageEditor/ImageEditor.css +10 -0
  4. package/es/components/ImageEditor/index.d.ts +1 -0
  5. package/es/components/ImageEditor/index.js +1 -0
  6. package/es/components/ImageEditor/plugins/cropPlugin/CropOverlay.js +27 -5
  7. package/es/components/ImageEditor/plugins/cropPlugin/CropToolbar.js +4 -3
  8. package/es/components/ImageEditor/plugins/cropPlugin/useCropTool.d.ts +20 -3
  9. package/es/components/ImageEditor/plugins/cropPlugin/useCropTool.js +216 -33
  10. package/es/components/ImageEditor/plugins/zoomPlugin/ZoomContext.d.ts +5 -0
  11. package/es/components/ImageEditor/plugins/zoomPlugin/ZoomContext.js +7 -0
  12. package/es/components/ImageEditor/useEdgeDetection.d.ts +0 -2
  13. package/es/components/ImageEditor/useEdgeDetection.js +11 -30
  14. package/es/components/ImageEditor/useOpenCV.d.ts +26 -1
  15. package/es/components/ImageEditor/useOpenCV.js +108 -42
  16. package/es/components/SplitContainer/index.js +2 -4
  17. package/es/filter/ChipListInput.d.ts +13 -0
  18. package/es/filter/ChipListInput.js +34 -0
  19. package/es/filter/FilterBuilder.css +152 -0
  20. package/es/filter/FilterBuilder.d.ts +115 -0
  21. package/es/filter/FilterBuilder.js +146 -0
  22. package/es/filter/FilterBuilder.test.d.ts +1 -0
  23. package/es/filter/FilterBuilder.test.js +120 -0
  24. package/es/filter/FilterEditor.css +231 -0
  25. package/es/filter/FilterEditor.d.ts +17 -0
  26. package/es/filter/FilterEditor.js +38 -0
  27. package/es/filter/FilterEditor.test.d.ts +1 -0
  28. package/es/filter/FilterEditor.test.js +183 -0
  29. package/es/filter/FilterGroupEditor.d.ts +22 -0
  30. package/es/filter/FilterGroupEditor.js +34 -0
  31. package/es/filter/FilterNameDialog.css +22 -0
  32. package/es/filter/FilterNameDialog.d.ts +18 -0
  33. package/es/filter/FilterNameDialog.js +32 -0
  34. package/es/filter/FilterRow.d.ts +14 -0
  35. package/es/filter/FilterRow.js +32 -0
  36. package/es/filter/FilterShareDialog.css +28 -0
  37. package/es/filter/FilterShareDialog.d.ts +23 -0
  38. package/es/filter/FilterShareDialog.js +63 -0
  39. package/es/filter/FilterStringField.d.ts +15 -0
  40. package/es/filter/FilterStringField.js +37 -0
  41. package/es/filter/FilterValueEditor.d.ts +16 -0
  42. package/es/filter/FilterValueEditor.js +85 -0
  43. package/es/filter/SavedFilterTree.css +107 -0
  44. package/es/filter/SavedFilterTree.d.ts +45 -0
  45. package/es/filter/SavedFilterTree.js +44 -0
  46. package/es/filter/SavedFilterTree.test.d.ts +1 -0
  47. package/es/filter/SavedFilterTree.test.js +75 -0
  48. package/es/filter/index.d.ts +11 -0
  49. package/es/filter/index.js +10 -0
  50. package/es/filter/types.d.ts +34 -0
  51. package/es/filter/types.js +1 -0
  52. package/es/index.d.ts +2 -1
  53. package/es/index.js +6 -1
  54. package/es/mui/MuiThemeProvider.d.ts +24 -0
  55. package/es/mui/MuiThemeProvider.js +152 -0
  56. package/es/mui/index.d.ts +1 -0
  57. package/es/mui/index.js +1 -0
  58. package/es/report/ReportLauncher.css +147 -0
  59. package/es/report/ReportLauncher.d.ts +55 -0
  60. package/es/report/ReportLauncher.js +142 -0
  61. package/es/report/ReportLauncher.test.d.ts +1 -0
  62. package/es/report/ReportLauncher.test.js +231 -0
  63. package/es/report/ReportParameters.css +29 -0
  64. package/es/report/ReportParameters.d.ts +46 -0
  65. package/es/report/ReportParameters.js +65 -0
  66. package/es/report/ReportParameters.test.d.ts +1 -0
  67. package/es/report/ReportParameters.test.js +84 -0
  68. package/es/report/index.d.ts +2 -0
  69. package/es/report/index.js +2 -0
  70. package/es/test/setup.d.ts +1 -0
  71. package/es/test/setup.js +6 -0
  72. package/package.json +22 -7
  73. package/src/chrome/AppShell/index.tsx +34 -171
  74. package/src/components/ImageEditor/ImageEditor.css +10 -0
  75. package/src/components/ImageEditor/index.ts +1 -0
  76. package/src/components/ImageEditor/plugins/cropPlugin/CropOverlay.tsx +66 -20
  77. package/src/components/ImageEditor/plugins/cropPlugin/CropToolbar.tsx +19 -3
  78. package/src/components/ImageEditor/plugins/cropPlugin/useCropTool.ts +266 -39
  79. package/src/components/ImageEditor/plugins/zoomPlugin/ZoomContext.tsx +8 -0
  80. package/src/components/ImageEditor/useEdgeDetection.ts +11 -51
  81. package/src/components/ImageEditor/useOpenCV.ts +112 -62
  82. package/src/components/SplitContainer/index.tsx +3 -4
  83. package/src/filter/ChipListInput.tsx +79 -0
  84. package/src/filter/FilterBuilder.css +152 -0
  85. package/src/filter/FilterBuilder.test.tsx +153 -0
  86. package/src/filter/FilterBuilder.tsx +435 -0
  87. package/src/filter/FilterEditor.css +231 -0
  88. package/src/filter/FilterEditor.test.tsx +259 -0
  89. package/src/filter/FilterEditor.tsx +74 -0
  90. package/src/filter/FilterGroupEditor.tsx +160 -0
  91. package/src/filter/FilterNameDialog.css +22 -0
  92. package/src/filter/FilterNameDialog.tsx +81 -0
  93. package/src/filter/FilterRow.tsx +117 -0
  94. package/src/filter/FilterShareDialog.css +28 -0
  95. package/src/filter/FilterShareDialog.tsx +201 -0
  96. package/src/filter/FilterStringField.tsx +77 -0
  97. package/src/filter/FilterValueEditor.tsx +220 -0
  98. package/src/filter/SavedFilterTree.css +107 -0
  99. package/src/filter/SavedFilterTree.test.tsx +94 -0
  100. package/src/filter/SavedFilterTree.tsx +222 -0
  101. package/src/filter/index.ts +11 -0
  102. package/src/filter/types.ts +38 -0
  103. package/src/index.ts +39 -1
  104. package/src/mui/MuiThemeProvider.tsx +174 -0
  105. package/src/mui/index.ts +1 -0
  106. package/src/report/ReportLauncher.css +147 -0
  107. package/src/report/ReportLauncher.test.tsx +281 -0
  108. package/src/report/ReportLauncher.tsx +421 -0
  109. package/src/report/ReportParameters.css +29 -0
  110. package/src/report/ReportParameters.test.tsx +133 -0
  111. package/src/report/ReportParameters.tsx +198 -0
  112. package/src/report/index.ts +2 -0
  113. package/src/test/setup.ts +8 -0
@@ -0,0 +1,231 @@
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
+ }
@@ -0,0 +1,17 @@
1
+ import "./FilterEditor.css";
2
+ import type { FilterEditorProps } from "./types.js";
3
+ /**
4
+ * The criteria tree of the filter builder. Groups can be nested and each group
5
+ * combines its items with either `and` or `or`, matching the advanced filter
6
+ * editor in the Windows client.
7
+ *
8
+ * Works both controlled (`value` + `onChange`) and uncontrolled
9
+ * (`defaultValue`). Saving and sharing filters is handled by `FilterBuilder`,
10
+ * which composes this component.
11
+ *
12
+ * @example
13
+ * ```jsx
14
+ * <FilterEditor fields={fields} value={filter} onChange={setFilter} showFilterString />
15
+ * ```
16
+ */
17
+ export declare function FilterEditor({ fields, value, defaultValue, onChange, readOnly, showFilterString, viewName, getFieldOptions, className, "data-size": size, }: FilterEditorProps): import("react").JSX.Element;
@@ -0,0 +1,38 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import "./FilterEditor.css";
3
+ import { getLocalizedString, toFilterTree } from "@olenbetong/appframe-core";
4
+ import clsx from "clsx";
5
+ import { useMemo, useState } from "react";
6
+ import { FilterGroupEditor } from "./FilterGroupEditor.js";
7
+ import { FilterStringField } from "./FilterStringField.js";
8
+ /**
9
+ * The criteria tree of the filter builder. Groups can be nested and each group
10
+ * combines its items with either `and` or `or`, matching the advanced filter
11
+ * editor in the Windows client.
12
+ *
13
+ * Works both controlled (`value` + `onChange`) and uncontrolled
14
+ * (`defaultValue`). Saving and sharing filters is handled by `FilterBuilder`,
15
+ * which composes this component.
16
+ *
17
+ * @example
18
+ * ```jsx
19
+ * <FilterEditor fields={fields} value={filter} onChange={setFilter} showFilterString />
20
+ * ```
21
+ */
22
+ export function FilterEditor({ fields, value, defaultValue, onChange, readOnly, showFilterString, viewName, getFieldOptions, className, "data-size": size = "sm", }) {
23
+ let [uncontrolled, setUncontrolled] = useState(() => toFilterTree(defaultValue));
24
+ let isControlled = value !== undefined;
25
+ // Normalizing on every render would create a new tree each time, which
26
+ // retriggers the filter string conversion.
27
+ let controlled = useMemo(() => toFilterTree(value), [value]);
28
+ let filter = isControlled ? controlled : uncontrolled;
29
+ let visibleFields = useMemo(() => fields.filter((field) => !field.excludeFromFilter), [fields]);
30
+ function update(next) {
31
+ if (!isControlled)
32
+ setUncontrolled(next);
33
+ onChange?.(next);
34
+ }
35
+ return (_jsxs("div", { className: clsx("ObFilterEditor-root", className), "data-size": size, children: [_jsxs("div", { className: "ObFilterEditor-body", children: [_jsx("p", { className: "ObFilterEditor-intro", children: filter.mode === "and"
36
+ ? getLocalizedString("Find rows that match all of these criteria:")
37
+ : getLocalizedString("Find rows that match one or more of these criteria:") }), _jsx(FilterGroupEditor, { filter: filter, path: [], fields: visibleFields, getFieldOptions: getFieldOptions, readOnly: readOnly, "data-size": size, onChange: update })] }), showFilterString && (_jsx(FilterStringField, { filter: filter, viewName: viewName, readOnly: readOnly, "data-size": size, onChange: update }))] }));
38
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,183 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
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
+ import { FilterEditor } from "./FilterEditor.js";
6
+ const FIELDS = [
7
+ { name: "PersonID", caption: "Person ID", type: "string", nullable: true },
8
+ { name: "Age", caption: "Age", type: "number" },
9
+ { name: "Created", caption: "Created", type: "datetime" },
10
+ { name: "IsActive", caption: "Is active", type: "boolean" },
11
+ { name: "Secret", caption: "Secret", type: "string", excludeFromFilter: true },
12
+ ];
13
+ /** A tree with a single root `and` group holding one expression. */
14
+ function filterWith(column, operator, value, valueType = "string") {
15
+ return {
16
+ type: "group",
17
+ mode: "and",
18
+ items: [{ type: "expression", column, operator, value, valueType }],
19
+ };
20
+ }
21
+ function firstExpression(onChange, call = 0) {
22
+ let [filter] = onChange.mock.calls[call];
23
+ return filter.items[0];
24
+ }
25
+ describe("FilterEditor", () => {
26
+ it("renders one row per expression", () => {
27
+ render(_jsx(FilterEditor, { fields: FIELDS, value: filterWith("PersonID", "beginswith", "silv") }));
28
+ expect(screen.getAllByLabelText("Field")).toHaveLength(1);
29
+ expect(screen.getByLabelText("Operator")).toHaveValue("beginswith");
30
+ expect(screen.getByLabelText("Value")).toHaveValue("silv");
31
+ });
32
+ it("wraps a bare expression in a group", () => {
33
+ let filter = {
34
+ type: "expression",
35
+ column: "Age",
36
+ operator: "equals",
37
+ value: "42",
38
+ valueType: "number",
39
+ };
40
+ render(_jsx(FilterEditor, { fields: FIELDS, value: filter }));
41
+ expect(screen.getByLabelText("Value")).toHaveValue(42);
42
+ });
43
+ it("hides fields marked as excluded from the field picker", async () => {
44
+ let user = userEvent.setup();
45
+ render(_jsx(FilterEditor, { fields: FIELDS, value: { type: "group", mode: "and", items: [] } }));
46
+ await user.click(screen.getByLabelText("Add condition"));
47
+ expect(screen.queryByRole("option", { name: "Secret" })).not.toBeInTheDocument();
48
+ expect(screen.getByRole("option", { name: "Person ID" })).toBeInTheDocument();
49
+ });
50
+ it("adds an expression when a field is picked in the blank row", async () => {
51
+ let user = userEvent.setup();
52
+ let onChange = vi.fn();
53
+ render(_jsx(FilterEditor, { fields: FIELDS, value: filterWith("PersonID", "beginswith", "silv"), onChange: onChange }));
54
+ await user.click(screen.getByLabelText("Add condition"));
55
+ await user.click(screen.getByRole("option", { name: "Age" }));
56
+ expect(onChange).toHaveBeenCalledTimes(1);
57
+ let [filter] = onChange.mock.calls[0];
58
+ expect(filter.items).toHaveLength(2);
59
+ // Numbers default to "equals", strings to "begins with".
60
+ expect(filter.items[1]).toMatchObject({ column: "Age", operator: "equals", valueType: "number" });
61
+ });
62
+ it("changes the operator and resets the value when the arity changes", async () => {
63
+ let user = userEvent.setup();
64
+ let onChange = vi.fn();
65
+ render(_jsx(FilterEditor, { fields: FIELDS, value: filterWith("Age", "equals", "42", "number"), onChange: onChange }));
66
+ await user.selectOptions(screen.getByLabelText("Operator"), "between");
67
+ expect(firstExpression(onChange)).toMatchObject({ operator: "between", value: ["", ""] });
68
+ });
69
+ it("renders no value editor for parameterless operators", () => {
70
+ render(_jsx(FilterEditor, { fields: FIELDS, value: filterWith("IsActive", "istrue", null, "null") }));
71
+ expect(screen.queryByLabelText("Value")).not.toBeInTheDocument();
72
+ });
73
+ it("renders two inputs for range operators", () => {
74
+ render(_jsx(FilterEditor, { fields: FIELDS, value: filterWith("Age", "between", ["1", "10"], "number") }));
75
+ expect(screen.getByLabelText("From")).toHaveValue(1);
76
+ expect(screen.getByLabelText("To")).toHaveValue(10);
77
+ });
78
+ it("renders one chip per value for list operators", () => {
79
+ render(_jsx(FilterEditor, { fields: FIELDS, value: filterWith("PersonID", "inlist", ["a", "b"]) }));
80
+ expect(screen.getByRole("button", { name: "Remove a" })).toBeInTheDocument();
81
+ expect(screen.getByRole("button", { name: "Remove b" })).toBeInTheDocument();
82
+ });
83
+ it("adds a list value on Enter", async () => {
84
+ let user = userEvent.setup();
85
+ let onChange = vi.fn();
86
+ render(_jsx(FilterEditor, { fields: FIELDS, value: filterWith("PersonID", "inlist", ["a"]), onChange: onChange }));
87
+ await user.type(screen.getByLabelText("Value"), "b{Enter}");
88
+ let [filter] = onChange.mock.calls.at(-1);
89
+ expect(filter.items[0].value).toEqual(["a", "b"]);
90
+ });
91
+ it("switches a date value to a relative value", async () => {
92
+ let user = userEvent.setup();
93
+ let onChange = vi.fn();
94
+ render(_jsx(FilterEditor, { fields: FIELDS, value: filterWith("Created", "equals", "", "datetime"), onChange: onChange }));
95
+ await user.click(screen.getByRole("button", { name: "Use a relative value" }));
96
+ expect(firstExpression(onChange)).toMatchObject({ value: "Yesterday", valueType: "special" });
97
+ });
98
+ it("does not offer relative values for numbers", () => {
99
+ render(_jsx(FilterEditor, { fields: FIELDS, value: filterWith("Age", "equals", "1", "number") }));
100
+ expect(screen.queryByRole("button", { name: "Use a relative value" })).not.toBeInTheDocument();
101
+ });
102
+ it("removes a condition", async () => {
103
+ let user = userEvent.setup();
104
+ let onChange = vi.fn();
105
+ render(_jsx(FilterEditor, { fields: FIELDS, value: filterWith("PersonID", "beginswith", "silv"), onChange: onChange }));
106
+ await user.click(screen.getByRole("button", { name: "Remove condition" }));
107
+ let [filter] = onChange.mock.calls[0];
108
+ expect(filter.items).toHaveLength(0);
109
+ });
110
+ it("hides every editing affordance when read only", () => {
111
+ render(_jsx(FilterEditor, { fields: FIELDS, value: filterWith("PersonID", "beginswith", "silv"), readOnly: true }));
112
+ expect(screen.queryByLabelText("Add condition")).not.toBeInTheDocument();
113
+ expect(screen.queryByRole("button", { name: "Remove condition" })).not.toBeInTheDocument();
114
+ expect(screen.queryByRole("button", { name: "Add group" })).not.toBeInTheDocument();
115
+ expect(screen.getByLabelText("Group operator")).toBeDisabled();
116
+ });
117
+ it("keeps a row editable when the field is not in the view", () => {
118
+ render(_jsx(FilterEditor, { fields: FIELDS, value: filterWith("Removed", "equals", "x") }));
119
+ expect(screen.getByLabelText("Field")).toHaveValue("Removed");
120
+ });
121
+ it("uses supplied options as a value list", () => {
122
+ render(_jsx(FilterEditor, { fields: FIELDS, value: filterWith("PersonID", "equals", "a"), getFieldOptions: (field) => field.name === "PersonID"
123
+ ? [
124
+ { value: "a", label: "Alpha" },
125
+ { value: "b", label: "Bravo" },
126
+ ]
127
+ : undefined }));
128
+ expect(screen.getByLabelText("Value")).toHaveValue("Alpha");
129
+ });
130
+ it("changes the mode of the root group", async () => {
131
+ let user = userEvent.setup();
132
+ let onChange = vi.fn();
133
+ render(_jsx(FilterEditor, { fields: FIELDS, value: filterWith("PersonID", "beginswith", "silv"), onChange: onChange }));
134
+ expect(screen.getByLabelText("Group operator")).toHaveValue("and");
135
+ await user.selectOptions(screen.getByLabelText("Group operator"), "or");
136
+ let [filter] = onChange.mock.calls[0];
137
+ expect(filter.mode).toBe("or");
138
+ });
139
+ it("adds and removes nested groups", async () => {
140
+ let user = userEvent.setup();
141
+ let onChange = vi.fn();
142
+ let { rerender } = render(_jsx(FilterEditor, { fields: FIELDS, value: filterWith("PersonID", "beginswith", "silv"), onChange: onChange }));
143
+ expect(screen.queryByRole("button", { name: "Remove group" })).not.toBeInTheDocument();
144
+ await user.click(screen.getByRole("button", { name: "Add group" }));
145
+ let [withGroup] = onChange.mock.calls[0];
146
+ expect(withGroup.items).toHaveLength(2);
147
+ // A nested group defaults to the opposite mode of its parent.
148
+ expect(withGroup.items[1]).toMatchObject({ type: "group", mode: "or", items: [] });
149
+ rerender(_jsx(FilterEditor, { fields: FIELDS, value: withGroup, onChange: onChange }));
150
+ expect(screen.getAllByLabelText("Group operator")).toHaveLength(2);
151
+ await user.click(screen.getByRole("button", { name: "Remove group" }));
152
+ let [removed] = onChange.mock.calls[1];
153
+ expect(removed.items).toHaveLength(1);
154
+ });
155
+ it("edits a condition inside a nested group", async () => {
156
+ let user = userEvent.setup();
157
+ let onChange = vi.fn();
158
+ let filter = {
159
+ type: "group",
160
+ mode: "and",
161
+ items: [
162
+ { type: "expression", column: "Age", operator: "equals", value: "1", valueType: "number" },
163
+ {
164
+ type: "group",
165
+ mode: "or",
166
+ items: [{ type: "expression", column: "PersonID", operator: "beginswith", value: "a", valueType: "string" }],
167
+ },
168
+ ],
169
+ };
170
+ render(_jsx(FilterEditor, { fields: FIELDS, value: filter, onChange: onChange }));
171
+ await user.click(screen.getAllByRole("button", { name: "Remove condition" })[1]);
172
+ let [next] = onChange.mock.calls[0];
173
+ expect(next.items[0]).toMatchObject({ column: "Age" });
174
+ expect(next.items[1]).toMatchObject({ type: "group", items: [] });
175
+ });
176
+ it("keeps its own state when uncontrolled", async () => {
177
+ let user = userEvent.setup();
178
+ render(_jsx(FilterEditor, { fields: FIELDS, defaultValue: filterWith("PersonID", "beginswith", "silv") }));
179
+ await user.clear(screen.getByLabelText("Value"));
180
+ await user.type(screen.getByLabelText("Value"), "gold");
181
+ expect(screen.getByLabelText("Value")).toHaveValue("gold");
182
+ });
183
+ });
@@ -0,0 +1,22 @@
1
+ import { type FieldMetadata, type FilterPath, type FilterTree } from "@olenbetong/appframe-core";
2
+ import type { FilterEditorSize, GetFieldOptions } from "./types.js";
3
+ export type FilterGroupEditorProps = {
4
+ /** The whole tree. Groups edit it through their own `path`. */
5
+ filter: FilterTree;
6
+ /** Path to the group this editor renders. The root group is the empty path. */
7
+ path: FilterPath;
8
+ fields: FieldMetadata[];
9
+ onChange: (filter: FilterTree) => void;
10
+ getFieldOptions?: GetFieldOptions;
11
+ readOnly?: boolean;
12
+ "data-size"?: FilterEditorSize;
13
+ };
14
+ /**
15
+ * One group of the filter tree. Groups can be nested and each one combines its
16
+ * items with either `and` or `or`, matching the advanced (DevExpress) filter
17
+ * editor in the Windows client.
18
+ *
19
+ * A blank row is always rendered at the end; picking a field in it appends a
20
+ * real condition to the group.
21
+ */
22
+ export declare function FilterGroupEditor({ filter, path, fields, onChange, getFieldOptions, readOnly, "data-size": size, }: FilterGroupEditorProps): import("react").JSX.Element | null;
@@ -0,0 +1,34 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Button, Select } from "@digdir/designsystemet-react";
3
+ import { FolderPlusIcon, TrashIcon } from "@navikt/aksel-icons";
4
+ import { addGroupAtPath, createExpression, getLocalizedString, getNodeAtPath, insertNodeAtPath, isExpression, isGroup, removeNodeAtPath, setGroupMode, updateNodeAtPath, } from "@olenbetong/appframe-core";
5
+ import { Combobox } from "@olenbetong/appframe-ds";
6
+ import { FilterRow, getFieldLabel } from "./FilterRow.js";
7
+ /**
8
+ * One group of the filter tree. Groups can be nested and each one combines its
9
+ * items with either `and` or `or`, matching the advanced (DevExpress) filter
10
+ * editor in the Windows client.
11
+ *
12
+ * A blank row is always rendered at the end; picking a field in it appends a
13
+ * real condition to the group.
14
+ */
15
+ export function FilterGroupEditor({ filter, path, fields, onChange, getFieldOptions, readOnly, "data-size": size = "sm", }) {
16
+ let node = getNodeAtPath(filter, path);
17
+ if (!node || !isGroup(node))
18
+ return null;
19
+ let group = node;
20
+ let isRoot = path.length === 0;
21
+ return (_jsxs("div", { className: "ObFilterEditor-group", "data-root": isRoot ? "" : undefined, children: [_jsxs("div", { className: "ObFilterEditor-groupHeader", children: [_jsxs(Select, { className: "ObFilterEditor-groupMode", "data-size": size, disabled: readOnly, "aria-label": getLocalizedString("Group operator"), value: group.mode, onChange: (event) => onChange(setGroupMode(filter, path, event.target.value)), children: [_jsx(Select.Option, { value: "and", children: getLocalizedString("And") }), _jsx(Select.Option, { value: "or", children: getLocalizedString("Or") })] }), !readOnly && (_jsxs(_Fragment, { children: [_jsxs(Button, { type: "button", variant: "tertiary", "data-size": size, className: "ObFilterEditor-groupButton", "aria-label": getLocalizedString("Add group"), onClick: () => onChange(addGroupAtPath(filter, path)), children: [_jsx(FolderPlusIcon, { "aria-hidden": true }), _jsx("span", { className: "ObFilterEditor-groupButtonLabel", children: getLocalizedString("Add group") })] }), !isRoot && (_jsxs(Button, { type: "button", variant: "tertiary", "data-color": "danger", "data-size": size, className: "ObFilterEditor-groupButton", "aria-label": getLocalizedString("Remove group"), onClick: () => onChange(removeNodeAtPath(filter, path)), children: [_jsx(TrashIcon, { "aria-hidden": true }), _jsx("span", { className: "ObFilterEditor-groupButtonLabel", children: getLocalizedString("Remove group") })] }))] }))] }), _jsxs("div", { className: "ObFilterEditor-groupItems", children: [group.items.map((item, index) => isExpression(item) ? (_jsx(FilterRow
22
+ // Rows have no stable identity, and reordering is not supported,
23
+ // so the index is the only key available.
24
+ // oxlint-disable-next-line no-array-index-key -- see above
25
+ , { expression: item, fields: fields, getFieldOptions: getFieldOptions, readOnly: readOnly, "data-size": size, onChange: (next) => onChange(replaceNode(filter, [...path, index], next)), onRemove: () => onChange(removeNodeAtPath(filter, [...path, index])) }, index)) : (_jsx(FilterGroupEditor
26
+ // oxlint-disable-next-line no-array-index-key -- see above
27
+ , { filter: filter, path: [...path, index], fields: fields, getFieldOptions: getFieldOptions, readOnly: readOnly, "data-size": size, onChange: onChange }, index))), !readOnly && (_jsx("div", { className: "ObFilterEditor-row ObFilterEditor-draftRow", children: _jsx(Combobox, { className: "ObFilterEditor-field", "data-size": size, "aria-label": getLocalizedString("Add condition"), placeholder: getLocalizedString("Add condition"), options: fields, getOptionLabel: getFieldLabel, getOptionKey: (option) => option.name, isOptionEqualToValue: (a, b) => a.name === b.name, value: null, onChange: (_event, field) => {
28
+ if (field)
29
+ onChange(insertNodeAtPath(filter, path, createExpression(field)));
30
+ } }) }))] })] }));
31
+ }
32
+ function replaceNode(filter, path, node) {
33
+ return updateNodeAtPath(filter, path, () => node);
34
+ }
@@ -0,0 +1,22 @@
1
+ /*
2
+ * Colours use the contextual `--ds-color-*` aliases so the dialog follows the
3
+ * active colour scheme. Never add hex fallbacks.
4
+ */
5
+
6
+ /*
7
+ * Designsystemet drops the dialog's own padding when its children are blocks,
8
+ * but the rule only looks at direct children, and the blocks here are wrapped
9
+ * in the form. Without this the blocks are inset and their dividers stop short
10
+ * of the dialog's edges.
11
+ */
12
+ .ObFilterNameDialog-root {
13
+ inline-size: min(28rem, 100%);
14
+ padding: 0;
15
+ }
16
+
17
+ .ObFilterNameDialog-actions {
18
+ display: flex;
19
+ flex-direction: row;
20
+ justify-content: flex-end;
21
+ gap: var(--ds-size-2);
22
+ }
@@ -0,0 +1,18 @@
1
+ import "./FilterNameDialog.css";
2
+ export type FilterNameDialogProps = {
3
+ open: boolean;
4
+ /** Pre-fills the field, e.g. with the current filter's name. */
5
+ defaultName?: string;
6
+ /** Names already in use; entering one asks the user to confirm the overwrite. */
7
+ existingNames?: string[];
8
+ onCancel: () => void;
9
+ onSubmit: (name: string) => void;
10
+ "data-size"?: "sm" | "md" | "lg";
11
+ };
12
+ /**
13
+ * Asks for the name to save a filter under.
14
+ *
15
+ * Reusing an existing name overwrites that filter, so the dialog warns before
16
+ * submitting rather than silently creating a second filter with the same name.
17
+ */
18
+ export declare function FilterNameDialog({ open, defaultName, existingNames, onCancel, onSubmit, "data-size": size, }: FilterNameDialogProps): import("react").JSX.Element;
@@ -0,0 +1,32 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import "./FilterNameDialog.css";
3
+ import { Button, Dialog, Heading, Textfield } from "@digdir/designsystemet-react";
4
+ import { getLocalizedString } from "@olenbetong/appframe-core";
5
+ import { useEffect, useState } from "react";
6
+ /**
7
+ * Asks for the name to save a filter under.
8
+ *
9
+ * Reusing an existing name overwrites that filter, so the dialog warns before
10
+ * submitting rather than silently creating a second filter with the same name.
11
+ */
12
+ export function FilterNameDialog({ open, defaultName = "", existingNames = [], onCancel, onSubmit, "data-size": size = "sm", }) {
13
+ let [name, setName] = useState(defaultName);
14
+ useEffect(() => {
15
+ if (open)
16
+ setName(defaultName);
17
+ }, [open, defaultName]);
18
+ let trimmed = name.trim();
19
+ // A filter keeping its own name is an update, not a collision.
20
+ let collides = trimmed !== defaultName && existingNames.some((existing) => existing === trimmed);
21
+ function handleSubmit(event) {
22
+ event.preventDefault();
23
+ if (!trimmed)
24
+ return;
25
+ onSubmit(trimmed);
26
+ }
27
+ return (_jsx(Dialog, { open: open, closedby: "any", "data-size": size, className: "ObFilterNameDialog-root", onClose: onCancel, children: _jsxs("form", { onSubmit: handleSubmit, children: [_jsx(Dialog.Block, { children: _jsx(Heading, { level: 2, "data-size": "xs", children: getLocalizedString("Save filter") }) }), _jsx(Dialog.Block, { children: _jsx(Textfield
28
+ // oxlint-disable-next-line jsx-a11y/no-autofocus -- the field is the only control in the dialog
29
+ , {
30
+ // oxlint-disable-next-line jsx-a11y/no-autofocus -- the field is the only control in the dialog
31
+ autoFocus: true, "data-size": size, label: getLocalizedString("Filter name"), value: name, error: collides ? getLocalizedString("A filter with this name already exists and will be replaced.") : undefined, onChange: (event) => setName(event.currentTarget.value) }) }), _jsxs(Dialog.Block, { className: "ObFilterNameDialog-actions", children: [_jsx(Button, { type: "submit", "data-size": size, disabled: !trimmed, children: collides ? getLocalizedString("Replace") : getLocalizedString("Save") }), _jsx(Button, { type: "button", variant: "secondary", "data-size": size, onClick: onCancel, children: getLocalizedString("Cancel") })] })] }) }));
32
+ }
@@ -0,0 +1,14 @@
1
+ import { type FieldMetadata, type FilterExpression } from "@olenbetong/appframe-core";
2
+ import type { FilterEditorSize, GetFieldOptions } from "./types.js";
3
+ export declare function getFieldLabel(field: FieldMetadata): string;
4
+ export type FilterRowProps = {
5
+ expression: FilterExpression;
6
+ fields: FieldMetadata[];
7
+ onChange: (expression: FilterExpression) => void;
8
+ onRemove: () => void;
9
+ getFieldOptions?: GetFieldOptions;
10
+ readOnly?: boolean;
11
+ "data-size"?: FilterEditorSize;
12
+ };
13
+ /** A single `field operator value` row. */
14
+ export declare function FilterRow({ expression, fields, onChange, onRemove, getFieldOptions, readOnly, "data-size": size, }: FilterRowProps): import("react").JSX.Element;
@@ -0,0 +1,32 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Select } from "@digdir/designsystemet-react";
3
+ import { XMarkIcon } from "@navikt/aksel-icons";
4
+ import { changeOperator, createExpression, getLocalizedString, getOperatorLabel, getOperatorsForField, normalizeOperator, } from "@olenbetong/appframe-core";
5
+ import { Combobox } from "@olenbetong/appframe-ds";
6
+ import { FilterValueEditor } from "./FilterValueEditor.js";
7
+ export function getFieldLabel(field) {
8
+ return field.caption || field.name;
9
+ }
10
+ /** A single `field operator value` row. */
11
+ export function FilterRow({ expression, fields, onChange, onRemove, getFieldOptions, readOnly, "data-size": size = "sm", }) {
12
+ let field = fields.find((item) => item.name === expression.column);
13
+ let operator = normalizeOperator(expression.operator);
14
+ // A filter can reference a field that is no longer in the view. Keep the row
15
+ // editable by falling back to a string field rather than dropping it.
16
+ let effectiveField = field ?? { name: expression.column, type: "string" };
17
+ let operators = getOperatorsForField(effectiveField);
18
+ if (!operators.includes(operator)) {
19
+ operators = [...operators, operator];
20
+ }
21
+ function handleFieldChange(next) {
22
+ if (!next)
23
+ return;
24
+ // Keep the operator when the new field supports it, so switching between
25
+ // two fields of the same type does not reset the row.
26
+ let operators = getOperatorsForField(next);
27
+ let keep = operators.includes(operator) ? operator : undefined;
28
+ let created = createExpression(next, keep);
29
+ onChange(keep ? { ...created, value: expression.value, valueType: expression.valueType } : created);
30
+ }
31
+ return (_jsxs("div", { className: "ObFilterEditor-row", children: [_jsx(Combobox, { className: "ObFilterEditor-field", "data-size": size, readOnly: readOnly, disableClearable: true, "aria-label": getLocalizedString("Field"), placeholder: getLocalizedString("Select field"), options: fields, getOptionLabel: getFieldLabel, getOptionKey: (option) => option.name, isOptionEqualToValue: (a, b) => a.name === b.name, value: effectiveField, onChange: (_event, next) => handleFieldChange(next) }), _jsx(Select, { className: "ObFilterEditor-operator", "data-size": size, disabled: readOnly, "aria-label": getLocalizedString("Operator"), value: operator, onChange: (event) => onChange(changeOperator(expression, event.target.value, effectiveField)), children: operators.map((item) => (_jsx(Select.Option, { value: item, children: getOperatorLabel(item, effectiveField.type) }, item))) }), _jsx(FilterValueEditor, { expression: expression, field: effectiveField, options: field ? getFieldOptions?.(field) : undefined, onChange: onChange, readOnly: readOnly, "data-size": size }), !readOnly && (_jsx("button", { type: "button", className: "ObFilterEditor-iconButton", title: getLocalizedString("Remove condition"), "aria-label": getLocalizedString("Remove condition"), onClick: onRemove, children: _jsx(XMarkIcon, { "aria-hidden": true }) }))] }));
32
+ }