@olenbetong/appframe-ds 0.7.0 → 0.9.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/CHANGELOG.md +175 -0
- package/package.json +52 -8
- package/scripts/copyAssets.mjs +13 -0
- package/src/AfLookup/LookupCombobox.css +1 -1
- package/src/AfLookup/LookupCombobox.tsx +3 -1
- package/src/autocomplete/Autocomplete.css +63 -42
- package/src/autocomplete/Autocomplete.tsx +2 -0
- package/src/autocomplete/AutocompleteFrame.tsx +21 -2
- package/src/autocomplete/Combobox.tsx +15 -2
- package/src/autocomplete/types.ts +4 -0
- package/src/container/Container.tsx +49 -0
- package/src/container/index.ts +1 -0
- package/src/filter/ChipListInput.tsx +79 -0
- package/src/filter/FieldFilterPanel.css +127 -0
- package/src/filter/FieldFilterPanel.tsx +309 -0
- package/src/filter/FilterBuilder.css +152 -0
- package/src/filter/FilterBuilder.test.tsx +153 -0
- package/src/filter/FilterBuilder.tsx +435 -0
- package/src/filter/FilterEditor.css +231 -0
- package/src/filter/FilterEditor.test.tsx +259 -0
- package/src/filter/FilterEditor.tsx +74 -0
- package/src/filter/FilterGroupEditor.tsx +160 -0
- package/src/filter/FilterNameDialog.css +22 -0
- package/src/filter/FilterNameDialog.tsx +81 -0
- package/src/filter/FilterRow.tsx +117 -0
- package/src/filter/FilterShareDialog.css +28 -0
- package/src/filter/FilterShareDialog.tsx +201 -0
- package/src/filter/FilterStringField.tsx +77 -0
- package/src/filter/FilterValueEditor.tsx +220 -0
- package/src/filter/SavedFilterTree.css +107 -0
- package/src/filter/SavedFilterTree.test.tsx +94 -0
- package/src/filter/SavedFilterTree.tsx +222 -0
- package/src/filter/fieldFilter.test.ts +158 -0
- package/src/filter/fieldFilter.ts +139 -0
- package/src/filter/index.ts +27 -0
- package/src/filter/types.ts +38 -0
- package/src/filter/useDistinctValues.test.ts +102 -0
- package/src/filter/useDistinctValues.ts +230 -0
- package/src/global.d.ts +11 -0
- package/src/grid/AfGridColumnsPanel.tsx +118 -0
- package/src/grid/AfGridContext.tsx +51 -0
- package/src/grid/AfGridError.tsx +46 -0
- package/src/grid/AfHeaderFilterCell.tsx +151 -0
- package/src/grid/AfHeaderFilterPanel.tsx +111 -0
- package/src/grid/Toolbar.tsx +233 -0
- package/src/grid/editing.ts +90 -0
- package/src/grid/filter.ts +78 -0
- package/src/grid/formatters.ts +48 -0
- package/src/grid/index.css +187 -0
- package/src/grid/index.tsx +376 -0
- package/src/grid/license.ts +48 -0
- package/src/grid/localization.ts +369 -0
- package/src/grid/slots/index.tsx +275 -0
- package/src/grid/slots/slots.css +53 -0
- package/src/grid/theme.tsx +185 -0
- package/src/grid/useAfColumns.tsx +313 -0
- package/src/grid/useAfCurrentIndex.ts +55 -0
- package/src/grid/useAfData.ts +20 -0
- package/src/grid/useAfFilter.ts +160 -0
- package/src/grid/useAfFilterFields.ts +55 -0
- package/src/grid/useAfGridApi.ts +66 -0
- package/src/grid/useAfKeyBindings.ts +36 -0
- package/src/grid/useAfPagination.ts +53 -0
- package/src/grid/useAfPersistedState.ts +222 -0
- package/src/grid/useAfRowEditModel.ts +137 -0
- package/src/grid/useAfSortModel.ts +72 -0
- package/src/index.ts +2 -0
- package/src/input/InputAdornments.tsx +6 -1
- package/src/paper/Paper.tsx +2 -0
- package/src/report-downloader/ReportDownloader.css +67 -0
- package/src/report-downloader/components/StatusItem.tsx +86 -0
- package/src/report-downloader/components/StatusList.tsx +28 -0
- package/src/report-downloader/index.ts +41 -0
- package/src/report-downloader/status.tsx +92 -0
- package/src/test/setup.ts +8 -0
- package/vitest.config.ts +10 -0
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
import "./FilterBuilder.css";
|
|
2
|
+
|
|
3
|
+
import { Button, Checkbox, Dialog, Heading } from "@digdir/designsystemet-react";
|
|
4
|
+
import { XMarkIcon } from "@navikt/aksel-icons";
|
|
5
|
+
import {
|
|
6
|
+
canEditSavedFilter,
|
|
7
|
+
canSetCrossDomain,
|
|
8
|
+
canShareSavedFilter,
|
|
9
|
+
createEmptyFilter,
|
|
10
|
+
findSavedFilter,
|
|
11
|
+
type FilterTree,
|
|
12
|
+
getLocalizedString,
|
|
13
|
+
isEmptyFilter,
|
|
14
|
+
pruneFilter,
|
|
15
|
+
type SavedFilter,
|
|
16
|
+
} from "@olenbetong/appframe-core";
|
|
17
|
+
import { type NamedFilterType, setNamedFilter, useFilterConversion, useSavedFilters } from "@olenbetong/appframe-react";
|
|
18
|
+
import type { SaveFilterInput } from "@olenbetong/appframe-react";
|
|
19
|
+
import type { DataObject } from "@olenbetong/appframe-data";
|
|
20
|
+
import clsx from "clsx";
|
|
21
|
+
import { type ReactNode, useCallback, useEffect, useState } from "react";
|
|
22
|
+
|
|
23
|
+
import { FilterEditor } from "./FilterEditor.js";
|
|
24
|
+
import { FilterNameDialog } from "./FilterNameDialog.js";
|
|
25
|
+
import { FilterShareDialog } from "./FilterShareDialog.js";
|
|
26
|
+
import { SavedFilterTree } from "./SavedFilterTree.js";
|
|
27
|
+
import type { FilterEditorSize, GetFieldOptions } from "./types.js";
|
|
28
|
+
import type { FieldMetadata } from "@olenbetong/appframe-core";
|
|
29
|
+
|
|
30
|
+
export type FilterBuilderProps = {
|
|
31
|
+
/** The fields the user can filter on. Fields with `excludeFromFilter` are hidden. */
|
|
32
|
+
fields: FieldMetadata[];
|
|
33
|
+
/**
|
|
34
|
+
* The view the filter applies to. Used both for conversion and, unless
|
|
35
|
+
* `dbObjectId` is set, as the key saved filters are stored under.
|
|
36
|
+
*/
|
|
37
|
+
viewName?: string;
|
|
38
|
+
/** Overrides `viewName` as the key saved filters are stored under. */
|
|
39
|
+
dbObjectId?: string;
|
|
40
|
+
/** Loads the filters saved for a report instead of for a view. */
|
|
41
|
+
reportId?: string;
|
|
42
|
+
getFieldOptions?: GetFieldOptions;
|
|
43
|
+
/**
|
|
44
|
+
* `"dialog"` wraps the builder in a modal, `"inline"` renders it in place.
|
|
45
|
+
* @default "dialog"
|
|
46
|
+
*/
|
|
47
|
+
variant?: "dialog" | "inline";
|
|
48
|
+
/** Whether the dialog is open. Ignored when `variant` is `"inline"`. */
|
|
49
|
+
open?: boolean;
|
|
50
|
+
/** Called when the dialog is dismissed, and after the filter is applied. */
|
|
51
|
+
onClose?: () => void;
|
|
52
|
+
/** The filter tree. Use together with `onChange` for a controlled component. */
|
|
53
|
+
value?: FilterTree | null;
|
|
54
|
+
/** The initial filter tree when uncontrolled. */
|
|
55
|
+
defaultValue?: FilterTree | null;
|
|
56
|
+
/** Called on every edit. */
|
|
57
|
+
onChange?: (filter: FilterTree) => void;
|
|
58
|
+
/**
|
|
59
|
+
* Called when the user applies the filter. The tree is pruned, so incomplete
|
|
60
|
+
* conditions are dropped and an empty filter is reported as `null`.
|
|
61
|
+
*/
|
|
62
|
+
onApply?: (filter: FilterTree | null, filterString: string) => void;
|
|
63
|
+
/**
|
|
64
|
+
* Applies the filter to a data object when the user confirms. The filter is
|
|
65
|
+
* written to a named slot, so it composes with other filter providers on the
|
|
66
|
+
* same data object instead of overwriting them.
|
|
67
|
+
*/
|
|
68
|
+
dataObject?: DataObject<any>;
|
|
69
|
+
/**
|
|
70
|
+
* Parameter the filter is applied to.
|
|
71
|
+
* @default "filterObject"
|
|
72
|
+
*/
|
|
73
|
+
filterType?: NamedFilterType;
|
|
74
|
+
/**
|
|
75
|
+
* Name of the slot the filter is applied to.
|
|
76
|
+
* @default "filterBuilder"
|
|
77
|
+
*/
|
|
78
|
+
slotName?: string;
|
|
79
|
+
/**
|
|
80
|
+
* Shows the filter string below the tree.
|
|
81
|
+
* @default true
|
|
82
|
+
*/
|
|
83
|
+
showFilterString?: boolean;
|
|
84
|
+
/** Called whenever the filter string is reconverted. */
|
|
85
|
+
onFilterStringChange?: (filterString: string) => void;
|
|
86
|
+
/** Called when a saved filter is selected, and with `null` for "New Filter". */
|
|
87
|
+
onSelect?: (filter: SavedFilter | null) => void;
|
|
88
|
+
/**
|
|
89
|
+
* Extra columns written along with the filter when it is saved. The report
|
|
90
|
+
* launcher stores its header text, its hide-criteria flag and its parameter
|
|
91
|
+
* values here.
|
|
92
|
+
*/
|
|
93
|
+
saveValues?: SavedFilterValues;
|
|
94
|
+
/**
|
|
95
|
+
* Hides the OK/Cancel row, for callers that supply their own actions. The
|
|
96
|
+
* saved-filter toolbar stays.
|
|
97
|
+
*/
|
|
98
|
+
hideActions?: boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Replaces the OK/Cancel buttons, so a caller's own actions share the row
|
|
101
|
+
* with the buttons acting on the selected saved filter.
|
|
102
|
+
*/
|
|
103
|
+
actions?: ReactNode;
|
|
104
|
+
/**
|
|
105
|
+
* Wraps the criteria editor, for callers that put it beside content of their
|
|
106
|
+
* own — the report launcher puts it in a tab next to the report parameters.
|
|
107
|
+
* Whatever is returned fills the column next to the saved-filter list.
|
|
108
|
+
*/
|
|
109
|
+
renderMain?: (editor: ReactNode) => ReactNode;
|
|
110
|
+
/** Hides the saved-filter list, leaving just the criteria editor. */
|
|
111
|
+
hideSavedFilters?: boolean;
|
|
112
|
+
className?: string;
|
|
113
|
+
"data-size"?: FilterEditorSize;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/** The parts of a saved filter the builder writes on behalf of a caller. */
|
|
117
|
+
export type SavedFilterValues = Pick<SaveFilterInput, "headerText" | "hideCriteria" | "parameters">;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* The web port of the Windows filter builder: the saved-filter list, the
|
|
121
|
+
* criteria editor and the save/share toolbar.
|
|
122
|
+
*
|
|
123
|
+
* Saved filters are stored as criteria strings, so selecting one round-trips
|
|
124
|
+
* through the conversion endpoint to rebuild the tree, and saving converts the
|
|
125
|
+
* tree back.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```jsx
|
|
129
|
+
* <FilterBuilder
|
|
130
|
+
* open={open}
|
|
131
|
+
* fields={dsPersons.getFields()}
|
|
132
|
+
* viewName="aviw_Personnel_Persons"
|
|
133
|
+
* dataObject={dsPersons}
|
|
134
|
+
* onClose={() => setOpen(false)}
|
|
135
|
+
* />
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
export function FilterBuilder({
|
|
139
|
+
fields,
|
|
140
|
+
viewName,
|
|
141
|
+
dbObjectId,
|
|
142
|
+
reportId,
|
|
143
|
+
getFieldOptions,
|
|
144
|
+
variant = "dialog",
|
|
145
|
+
open = true,
|
|
146
|
+
onClose,
|
|
147
|
+
value,
|
|
148
|
+
defaultValue,
|
|
149
|
+
onChange,
|
|
150
|
+
onApply,
|
|
151
|
+
dataObject,
|
|
152
|
+
filterType = "filterObject",
|
|
153
|
+
slotName = "filterBuilder",
|
|
154
|
+
showFilterString = true,
|
|
155
|
+
onFilterStringChange,
|
|
156
|
+
onSelect,
|
|
157
|
+
saveValues,
|
|
158
|
+
hideActions,
|
|
159
|
+
actions,
|
|
160
|
+
renderMain,
|
|
161
|
+
hideSavedFilters,
|
|
162
|
+
className,
|
|
163
|
+
"data-size": size = "sm",
|
|
164
|
+
}: FilterBuilderProps) {
|
|
165
|
+
let resolvedId = dbObjectId ?? viewName;
|
|
166
|
+
let { mine, shared, filters, loading, save, rename, remove, setCrossDomain } = useSavedFilters({
|
|
167
|
+
dbObjectId: reportId ? undefined : resolvedId,
|
|
168
|
+
reportId,
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
let [uncontrolled, setUncontrolled] = useState<FilterTree>(() => defaultValue ?? createEmptyFilter());
|
|
172
|
+
let isControlled = value !== undefined;
|
|
173
|
+
let filter = isControlled ? (value ?? createEmptyFilter()) : uncontrolled;
|
|
174
|
+
|
|
175
|
+
let [selectedId, setSelectedId] = useState<number | null>(null);
|
|
176
|
+
let [dirty, setDirty] = useState(false);
|
|
177
|
+
let [saving, setSaving] = useState(false);
|
|
178
|
+
let [sharing, setSharing] = useState(false);
|
|
179
|
+
let [error, setError] = useState<string | null>(null);
|
|
180
|
+
|
|
181
|
+
let { filterString, isConverting, parseFilterString } = useFilterConversion(filter, { viewName });
|
|
182
|
+
let selected = findSavedFilter(filters, selectedId);
|
|
183
|
+
|
|
184
|
+
useEffect(() => {
|
|
185
|
+
onFilterStringChange?.(filterString);
|
|
186
|
+
}, [filterString, onFilterStringChange]);
|
|
187
|
+
|
|
188
|
+
let update = useCallback(
|
|
189
|
+
(next: FilterTree) => {
|
|
190
|
+
if (!isControlled) setUncontrolled(next);
|
|
191
|
+
onChange?.(next);
|
|
192
|
+
setDirty(true);
|
|
193
|
+
},
|
|
194
|
+
[isControlled, onChange],
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
function applyFilter(next: FilterTree, markClean: boolean) {
|
|
198
|
+
if (!isControlled) setUncontrolled(next);
|
|
199
|
+
onChange?.(next);
|
|
200
|
+
if (markClean) setDirty(false);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
async function handleSelect(filterId: number | null) {
|
|
204
|
+
setSelectedId(filterId);
|
|
205
|
+
setError(null);
|
|
206
|
+
|
|
207
|
+
if (filterId === null) {
|
|
208
|
+
applyFilter(createEmptyFilter(), true);
|
|
209
|
+
onSelect?.(null);
|
|
210
|
+
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
let savedFilter = findSavedFilter(filters, filterId);
|
|
215
|
+
if (!savedFilter) return;
|
|
216
|
+
|
|
217
|
+
onSelect?.(savedFilter);
|
|
218
|
+
|
|
219
|
+
// Filters are stored as criteria strings, so the tree has to be rebuilt.
|
|
220
|
+
let parsed = await parseFilterString(savedFilter.criteria);
|
|
221
|
+
applyFilter(parsed ?? createEmptyFilter(), true);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
async function handleSave(name: string) {
|
|
225
|
+
setSaving(false);
|
|
226
|
+
setError(null);
|
|
227
|
+
|
|
228
|
+
try {
|
|
229
|
+
// Saving under an existing name of the user's own replaces that
|
|
230
|
+
// filter rather than creating a duplicate.
|
|
231
|
+
let existing = mine.find((candidate) => candidate.name === name);
|
|
232
|
+
let saved = await save({
|
|
233
|
+
...saveValues,
|
|
234
|
+
filterId: existing?.filterId ?? null,
|
|
235
|
+
name,
|
|
236
|
+
criteria: filterString,
|
|
237
|
+
crossDomain: existing?.crossDomain ?? undefined,
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
if (saved) setSelectedId(saved.filterId);
|
|
241
|
+
setDirty(false);
|
|
242
|
+
} catch (cause) {
|
|
243
|
+
setError(String((cause as Error)?.message ?? cause));
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
async function handleOverwrite() {
|
|
248
|
+
if (!selected) return;
|
|
249
|
+
|
|
250
|
+
setError(null);
|
|
251
|
+
|
|
252
|
+
try {
|
|
253
|
+
await save({ ...saveValues, filterId: selected.filterId, name: selected.name, criteria: filterString });
|
|
254
|
+
setDirty(false);
|
|
255
|
+
} catch (cause) {
|
|
256
|
+
setError(String((cause as Error)?.message ?? cause));
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function handleRename(savedFilter: SavedFilter) {
|
|
261
|
+
let name = globalThis.prompt?.(getLocalizedString("Filter name"), savedFilter.name);
|
|
262
|
+
if (name?.trim()) void rename(savedFilter.filterId, name.trim());
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function handleDelete(savedFilter: SavedFilter) {
|
|
266
|
+
let message = getLocalizedString("Delete the filter {0}?").replace("{0}", savedFilter.name);
|
|
267
|
+
if (!globalThis.confirm?.(message)) return;
|
|
268
|
+
|
|
269
|
+
void remove(savedFilter.filterId).then(() => {
|
|
270
|
+
if (savedFilter.filterId === selectedId) void handleSelect(null);
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function handleApply() {
|
|
275
|
+
let pruned = pruneFilter(filter);
|
|
276
|
+
|
|
277
|
+
if (dataObject) {
|
|
278
|
+
setNamedFilter(dataObject, slotName, pruned, { type: filterType });
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
onApply?.(pruned, filterString);
|
|
282
|
+
onClose?.();
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
let isEmpty = isEmptyFilter(filter);
|
|
286
|
+
let canOverwrite = Boolean(selected) && canEditSavedFilter(selected as SavedFilter) && dirty && !isEmpty;
|
|
287
|
+
|
|
288
|
+
let editor = (
|
|
289
|
+
<FilterEditor
|
|
290
|
+
fields={fields}
|
|
291
|
+
value={filter}
|
|
292
|
+
viewName={viewName}
|
|
293
|
+
getFieldOptions={getFieldOptions}
|
|
294
|
+
showFilterString={showFilterString}
|
|
295
|
+
data-size={size}
|
|
296
|
+
onChange={update}
|
|
297
|
+
/>
|
|
298
|
+
);
|
|
299
|
+
|
|
300
|
+
let content = (
|
|
301
|
+
<div
|
|
302
|
+
className={clsx("ObFilterBuilder-root", hideSavedFilters && "ObFilterBuilder-root--noSavedFilters", className)}
|
|
303
|
+
data-size={size}
|
|
304
|
+
>
|
|
305
|
+
{!hideSavedFilters && (
|
|
306
|
+
<div className="ObFilterBuilder-sidebar">
|
|
307
|
+
<SavedFilterTree
|
|
308
|
+
mine={mine}
|
|
309
|
+
shared={shared}
|
|
310
|
+
value={selectedId}
|
|
311
|
+
dirty={dirty}
|
|
312
|
+
loading={loading}
|
|
313
|
+
data-size={size}
|
|
314
|
+
onChange={(filterId) => void handleSelect(filterId)}
|
|
315
|
+
onRename={handleRename}
|
|
316
|
+
onDelete={handleDelete}
|
|
317
|
+
/>
|
|
318
|
+
</div>
|
|
319
|
+
)}
|
|
320
|
+
<div className="ObFilterBuilder-main">{renderMain ? renderMain(editor) : editor}</div>
|
|
321
|
+
{error && (
|
|
322
|
+
<p className="ObFilterBuilder-error" role="alert">
|
|
323
|
+
{error}
|
|
324
|
+
</p>
|
|
325
|
+
)}
|
|
326
|
+
<div className="ObFilterBuilder-footer">
|
|
327
|
+
{!hideSavedFilters && (
|
|
328
|
+
<div className="ObFilterBuilder-toolbar">
|
|
329
|
+
<Button
|
|
330
|
+
type="button"
|
|
331
|
+
variant="secondary"
|
|
332
|
+
data-size={size}
|
|
333
|
+
disabled={!selected || !canShareSavedFilter(selected)}
|
|
334
|
+
onClick={() => setSharing(true)}
|
|
335
|
+
>
|
|
336
|
+
{getLocalizedString("Sharing...")}
|
|
337
|
+
</Button>
|
|
338
|
+
<Button
|
|
339
|
+
type="button"
|
|
340
|
+
variant="secondary"
|
|
341
|
+
data-size={size}
|
|
342
|
+
disabled={isEmpty || isConverting}
|
|
343
|
+
onClick={() => setSaving(true)}
|
|
344
|
+
>
|
|
345
|
+
{getLocalizedString("Save as")}
|
|
346
|
+
</Button>
|
|
347
|
+
<Button
|
|
348
|
+
type="button"
|
|
349
|
+
variant="secondary"
|
|
350
|
+
data-size={size}
|
|
351
|
+
disabled={!canOverwrite || isConverting}
|
|
352
|
+
onClick={() => void handleOverwrite()}
|
|
353
|
+
>
|
|
354
|
+
{getLocalizedString("Save")}
|
|
355
|
+
</Button>
|
|
356
|
+
<Checkbox
|
|
357
|
+
data-size={size}
|
|
358
|
+
label={getLocalizedString("All Domains")}
|
|
359
|
+
checked={selected?.crossDomain ?? false}
|
|
360
|
+
disabled={!selected || !canSetCrossDomain(selected)}
|
|
361
|
+
onChange={(event) => {
|
|
362
|
+
if (selected) void setCrossDomain(selected.filterId, event.currentTarget.checked);
|
|
363
|
+
}}
|
|
364
|
+
/>
|
|
365
|
+
</div>
|
|
366
|
+
)}
|
|
367
|
+
{!hideActions && (
|
|
368
|
+
<div className="ObFilterBuilder-actions">
|
|
369
|
+
{actions ?? (
|
|
370
|
+
<>
|
|
371
|
+
<Button type="button" data-size={size} onClick={handleApply}>
|
|
372
|
+
{getLocalizedString("OK")}
|
|
373
|
+
</Button>
|
|
374
|
+
<Button type="button" variant="secondary" data-size={size} onClick={onClose}>
|
|
375
|
+
{getLocalizedString("Cancel")}
|
|
376
|
+
</Button>
|
|
377
|
+
</>
|
|
378
|
+
)}
|
|
379
|
+
</div>
|
|
380
|
+
)}
|
|
381
|
+
</div>
|
|
382
|
+
<FilterNameDialog
|
|
383
|
+
open={saving}
|
|
384
|
+
defaultName={selected?.name ?? ""}
|
|
385
|
+
existingNames={mine.map((candidate) => candidate.name)}
|
|
386
|
+
data-size={size}
|
|
387
|
+
onCancel={() => setSaving(false)}
|
|
388
|
+
onSubmit={(name) => void handleSave(name)}
|
|
389
|
+
/>
|
|
390
|
+
<FilterShareDialog
|
|
391
|
+
open={sharing}
|
|
392
|
+
filterId={selectedId}
|
|
393
|
+
filterName={selected?.name}
|
|
394
|
+
data-size={size}
|
|
395
|
+
onClose={() => setSharing(false)}
|
|
396
|
+
/>
|
|
397
|
+
</div>
|
|
398
|
+
);
|
|
399
|
+
|
|
400
|
+
if (variant === "inline") return content;
|
|
401
|
+
|
|
402
|
+
return (
|
|
403
|
+
<Dialog
|
|
404
|
+
open={open}
|
|
405
|
+
closedby="closerequest"
|
|
406
|
+
closeButton={false}
|
|
407
|
+
data-size={size}
|
|
408
|
+
className="ObFilterBuilder-dialog"
|
|
409
|
+
onClose={onClose}
|
|
410
|
+
>
|
|
411
|
+
{/*
|
|
412
|
+
* `Dialog`'s own close button is a floated first child of the dialog,
|
|
413
|
+
* which a flex layout takes out of its float and stacks above the
|
|
414
|
+
* heading. Rendering it in the header instead keeps it aligned.
|
|
415
|
+
*/}
|
|
416
|
+
<Dialog.Block className="ObFilterBuilder-dialogHeader">
|
|
417
|
+
<Heading level={2} data-size="xs">
|
|
418
|
+
{getLocalizedString("Edit filter")}
|
|
419
|
+
</Heading>
|
|
420
|
+
<Button
|
|
421
|
+
type="button"
|
|
422
|
+
variant="tertiary"
|
|
423
|
+
data-color="neutral"
|
|
424
|
+
data-size={size}
|
|
425
|
+
icon
|
|
426
|
+
aria-label={getLocalizedString("Close")}
|
|
427
|
+
onClick={onClose}
|
|
428
|
+
>
|
|
429
|
+
<XMarkIcon aria-hidden />
|
|
430
|
+
</Button>
|
|
431
|
+
</Dialog.Block>
|
|
432
|
+
<Dialog.Block className="ObFilterBuilder-dialogBody">{content}</Dialog.Block>
|
|
433
|
+
</Dialog>
|
|
434
|
+
);
|
|
435
|
+
}
|
|
@@ -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
|
+
}
|