@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,85 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Select, Textfield } from "@digdir/designsystemet-react";
|
|
3
|
-
import { PencilIcon } from "@navikt/aksel-icons";
|
|
4
|
-
import { getDynamicValueLabel, getDynamicValuesForField, getLocalizedString, getOperatorArity, getValueType, normalizeOperator, } from "@olenbetong/appframe-core";
|
|
5
|
-
import { Combobox } from "@olenbetong/appframe-ds";
|
|
6
|
-
import { ChipListInput } from "./ChipListInput.js";
|
|
7
|
-
/** The `input` type used for a field's scalar editor. */
|
|
8
|
-
function getInputType(field) {
|
|
9
|
-
switch (field?.type) {
|
|
10
|
-
case "number":
|
|
11
|
-
return "number";
|
|
12
|
-
case "date":
|
|
13
|
-
return "date";
|
|
14
|
-
case "datetime":
|
|
15
|
-
return "datetime-local";
|
|
16
|
-
default:
|
|
17
|
-
return "text";
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
function toStringValue(value) {
|
|
21
|
-
if (value === null || value === undefined)
|
|
22
|
-
return "";
|
|
23
|
-
if (value instanceof Date)
|
|
24
|
-
return value.toISOString();
|
|
25
|
-
return String(value);
|
|
26
|
-
}
|
|
27
|
-
function toArrayValue(value, length) {
|
|
28
|
-
let array = Array.isArray(value) ? value.map(toStringValue) : [];
|
|
29
|
-
if (length === undefined)
|
|
30
|
-
return array;
|
|
31
|
-
// Pair editors always render two inputs, even before both are filled in.
|
|
32
|
-
return Array.from({ length }, (_, index) => array[index] ?? "");
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* The value part of a filter row. Which editor is rendered depends on the
|
|
36
|
-
* operator's arity, the field's type, and whether the value is a dynamic
|
|
37
|
-
* ("special") value such as `Today` or `CurrentUser`.
|
|
38
|
-
*/
|
|
39
|
-
export function FilterValueEditor({ expression, field, options, onChange, readOnly, "data-size": size = "sm", }) {
|
|
40
|
-
let operator = normalizeOperator(expression.operator);
|
|
41
|
-
let arity = getOperatorArity(operator);
|
|
42
|
-
let isDynamic = expression.valueType === "special";
|
|
43
|
-
let dynamicValues = field ? getDynamicValuesForField(field) : [];
|
|
44
|
-
let inputType = getInputType(field);
|
|
45
|
-
function setValue(value) {
|
|
46
|
-
onChange({ ...expression, value });
|
|
47
|
-
}
|
|
48
|
-
function setDynamic(enabled) {
|
|
49
|
-
if (enabled) {
|
|
50
|
-
onChange({ ...expression, value: dynamicValues[0] ?? null, valueType: "special" });
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
onChange({
|
|
54
|
-
...expression,
|
|
55
|
-
value: arity === "pair" ? ["", ""] : arity === "list" ? [] : "",
|
|
56
|
-
valueType: field ? getValueType(field, operator) : "string",
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
if (arity === "none")
|
|
61
|
-
return null;
|
|
62
|
-
let editor;
|
|
63
|
-
if (isDynamic) {
|
|
64
|
-
editor = (_jsx(Select, { className: "ObFilterEditor-value", "aria-label": getLocalizedString("Value"), "data-size": size, disabled: readOnly, value: toStringValue(expression.value), onChange: (event) => setValue(event.target.value), children: dynamicValues.map((dynamicValue) => (_jsx(Select.Option, { value: dynamicValue, children: getDynamicValueLabel(dynamicValue) }, dynamicValue))) }));
|
|
65
|
-
}
|
|
66
|
-
else if (arity === "list") {
|
|
67
|
-
editor = options ? (_jsx(Combobox, { className: "ObFilterEditor-value", multiple: true, "data-size": size, readOnly: readOnly, placeholder: getLocalizedString("Select values"), "aria-label": getLocalizedString("Value"), options: options, getOptionLabel: (option) => option.label ?? option.value, isOptionEqualToValue: (a, b) => a.value === b.value, value: toArrayValue(expression.value).map((item) => options.find((option) => option.value === item) ?? { value: item }), onChange: (_event, selected) => setValue(selected.map((option) => option.value)) })) : (_jsx(ChipListInput, { "aria-label": getLocalizedString("Value"), "data-size": size, readOnly: readOnly, type: inputType, value: toArrayValue(expression.value), onChange: setValue }));
|
|
68
|
-
}
|
|
69
|
-
else if (arity === "pair") {
|
|
70
|
-
let [from, to] = toArrayValue(expression.value, 2);
|
|
71
|
-
editor = (_jsxs("div", { className: "ObFilterEditor-pair", children: [_jsx(Textfield, { className: "ObFilterEditor-value", "aria-label": getLocalizedString("From"), "data-size": size, readOnly: readOnly, type: inputType, value: from, onChange: (event) => setValue([event.target.value, to]) }), _jsx("span", { className: "ObFilterEditor-pairSeparator", children: getLocalizedString("and") }), _jsx(Textfield, { className: "ObFilterEditor-value", "aria-label": getLocalizedString("To"), "data-size": size, readOnly: readOnly, type: inputType, value: to, onChange: (event) => setValue([from, event.target.value]) })] }));
|
|
72
|
-
}
|
|
73
|
-
else if (options) {
|
|
74
|
-
let current = toStringValue(expression.value);
|
|
75
|
-
editor = (_jsx(Combobox, { className: "ObFilterEditor-value", "data-size": size, readOnly: readOnly, placeholder: getLocalizedString("Select value"), "aria-label": getLocalizedString("Value"), options: options, getOptionLabel: (option) => option.label ?? option.value, isOptionEqualToValue: (a, b) => a.value === b.value, value: current ? (options.find((option) => option.value === current) ?? { value: current }) : null, onChange: (_event, selected) => setValue(selected?.value ?? "") }));
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
editor = (_jsx(Textfield, { className: "ObFilterEditor-value", "aria-label": getLocalizedString("Value"), "data-size": size, readOnly: readOnly, type: inputType, value: toStringValue(expression.value), onChange: (event) => setValue(event.target.value) }));
|
|
79
|
-
}
|
|
80
|
-
// Dynamic values are resolved server side, so they can only replace the whole
|
|
81
|
-
// value. Pairs would need one toggle per side, which the Windows editor does
|
|
82
|
-
// not offer either.
|
|
83
|
-
let canToggleDynamic = !readOnly && dynamicValues.length > 0 && arity === "single";
|
|
84
|
-
return (_jsxs("div", { className: "ObFilterEditor-valueCell", children: [editor, canToggleDynamic && (_jsx("button", { type: "button", className: "ObFilterEditor-iconButton", "aria-pressed": isDynamic, title: getLocalizedString("Use a relative value"), "aria-label": getLocalizedString("Use a relative value"), onClick: () => setDynamic(!isDynamic), children: _jsx(PencilIcon, { "aria-hidden": true }) }))] }));
|
|
85
|
-
}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Colours use the contextual `--ds-color-*` aliases so the tree follows the
|
|
3
|
-
* active colour scheme. Never add hex fallbacks — they only encode the light
|
|
4
|
-
* theme and silently mask misspelled tokens.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
.ObSavedFilterTree-root,
|
|
8
|
-
.ObSavedFilterTree-children {
|
|
9
|
-
list-style: none;
|
|
10
|
-
margin: 0;
|
|
11
|
-
padding: 0;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
.ObSavedFilterTree-children {
|
|
15
|
-
/*
|
|
16
|
-
* A branch is chevron + icon, a child only an icon, so matching the branch
|
|
17
|
-
* indent would put a child's icon under its parent's icon and make the two
|
|
18
|
-
* levels look like one. Indent past the branch icon instead, so a child's
|
|
19
|
-
* icon starts where its parent's label does.
|
|
20
|
-
*/
|
|
21
|
-
margin-inline-start: calc(var(--ds-size-6) + var(--ds-size-1) + var(--ds-size-6));
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
.ObSavedFilterTree-item {
|
|
25
|
-
display: flex;
|
|
26
|
-
align-items: center;
|
|
27
|
-
gap: var(--ds-size-1);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
.ObSavedFilterTree-node {
|
|
31
|
-
display: flex;
|
|
32
|
-
align-items: center;
|
|
33
|
-
gap: var(--ds-size-1);
|
|
34
|
-
flex: 1;
|
|
35
|
-
min-inline-size: 0;
|
|
36
|
-
padding: var(--ds-size-1) var(--ds-size-2);
|
|
37
|
-
border: none;
|
|
38
|
-
border-radius: var(--ds-border-radius-sm);
|
|
39
|
-
background: none;
|
|
40
|
-
color: var(--ds-color-text-default);
|
|
41
|
-
font: inherit;
|
|
42
|
-
text-align: start;
|
|
43
|
-
cursor: pointer;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
.ObSavedFilterTree-node:hover {
|
|
47
|
-
background: var(--ds-color-surface-hover);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
.ObSavedFilterTree-node:focus-visible {
|
|
51
|
-
outline: var(--ds-border-width-focus) solid var(--ds-color-focus-outer);
|
|
52
|
-
outline-offset: var(--ds-border-width-focus);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
.ObSavedFilterTree-selected {
|
|
56
|
-
background: var(--ds-color-surface-active);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
.ObSavedFilterTree-dirty .ObSavedFilterTree-label {
|
|
60
|
-
font-weight: var(--ds-font-weight-semibold);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
.ObSavedFilterTree-chevron,
|
|
64
|
-
.ObSavedFilterTree-icon {
|
|
65
|
-
display: inline-flex;
|
|
66
|
-
flex: none;
|
|
67
|
-
align-items: center;
|
|
68
|
-
justify-content: center;
|
|
69
|
-
inline-size: var(--ds-size-6);
|
|
70
|
-
block-size: var(--ds-size-6);
|
|
71
|
-
color: var(--ds-color-text-subtle);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
.ObSavedFilterTree-chevron > *,
|
|
75
|
-
.ObSavedFilterTree-icon > * {
|
|
76
|
-
inline-size: 100%;
|
|
77
|
-
block-size: 100%;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
.ObSavedFilterTree-label {
|
|
81
|
-
overflow: hidden;
|
|
82
|
-
text-overflow: ellipsis;
|
|
83
|
-
white-space: nowrap;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
.ObSavedFilterTree-empty {
|
|
87
|
-
/* Lines up with the child labels, past their icon. */
|
|
88
|
-
padding: var(--ds-size-1) var(--ds-size-2) var(--ds-size-1)
|
|
89
|
-
calc(var(--ds-size-2) + var(--ds-size-6) + var(--ds-size-1));
|
|
90
|
-
color: var(--ds-color-text-subtle);
|
|
91
|
-
font-style: italic;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/*
|
|
95
|
-
* The menu button only appears on hover/focus on pointer devices; on touch it is
|
|
96
|
-
* always visible because there is no hover to reveal it.
|
|
97
|
-
*/
|
|
98
|
-
@media (hover: hover) {
|
|
99
|
-
.ObSavedFilterTree-menuButton {
|
|
100
|
-
visibility: hidden;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
.ObSavedFilterTree-item:hover .ObSavedFilterTree-menuButton,
|
|
104
|
-
.ObSavedFilterTree-item:focus-within .ObSavedFilterTree-menuButton {
|
|
105
|
-
visibility: visible;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { type SavedFilter } from "@olenbetong/appframe-core";
|
|
2
|
-
import "./SavedFilterTree.css";
|
|
3
|
-
/** `null` is the "new filter" node, i.e. no saved filter selected. */
|
|
4
|
-
export type SavedFilterSelection = number | null;
|
|
5
|
-
export type SavedFilterTreeProps = {
|
|
6
|
-
mine: SavedFilter[];
|
|
7
|
-
shared: SavedFilter[];
|
|
8
|
-
/** `FilterID` of the selected filter, or `null` for "new filter". */
|
|
9
|
-
value: SavedFilterSelection;
|
|
10
|
-
onChange: (filterId: SavedFilterSelection) => void;
|
|
11
|
-
/**
|
|
12
|
-
* Marks the selected filter as having unsaved changes; it is then rendered
|
|
13
|
-
* in bold, like the Windows client does.
|
|
14
|
-
*/
|
|
15
|
-
dirty?: boolean;
|
|
16
|
-
onRename?: (filter: SavedFilter) => void;
|
|
17
|
-
onDelete?: (filter: SavedFilter) => void;
|
|
18
|
-
/** Shows an "info" item in the context menu when supplied. */
|
|
19
|
-
onShowInfo?: (filter: SavedFilter) => void;
|
|
20
|
-
loading?: boolean;
|
|
21
|
-
className?: string;
|
|
22
|
-
"data-size"?: "sm" | "md" | "lg";
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* The saved-filter list of the filter builder: a "new filter" entry followed by
|
|
26
|
-
* the user's own filters and the filters shared with them.
|
|
27
|
-
*
|
|
28
|
-
* Which actions a filter offers depends on the access the database resolved for
|
|
29
|
-
* it — renaming and deleting are restricted to filters the user created, even
|
|
30
|
-
* when they manage a filter someone else made.
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```jsx
|
|
34
|
-
* let { mine, shared, rename, remove } = useSavedFilters({ dbObjectId: "aviw_Personnel_Persons" });
|
|
35
|
-
*
|
|
36
|
-
* <SavedFilterTree
|
|
37
|
-
* mine={mine}
|
|
38
|
-
* shared={shared}
|
|
39
|
-
* value={selected}
|
|
40
|
-
* onChange={setSelected}
|
|
41
|
-
* onRename={(filter) => rename(filter.filterId, prompt("Name", filter.name))}
|
|
42
|
-
* />
|
|
43
|
-
* ```
|
|
44
|
-
*/
|
|
45
|
-
export declare function SavedFilterTree({ mine, shared, value, onChange, dirty, onRename, onDelete, onShowInfo, loading, className, "data-size": size, }: SavedFilterTreeProps): import("react").JSX.Element;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Dropdown } from "@digdir/designsystemet-react";
|
|
3
|
-
import { canDeleteSavedFilter, canRenameSavedFilter, getLocalizedString, } from "@olenbetong/appframe-core";
|
|
4
|
-
import { ChevronDownIcon, ChevronRightIcon, FilesIcon, FileTextIcon, MenuElipsisVerticalIcon, PadlockLockedIcon, PencilIcon, StarIcon, TrashIcon, } from "@navikt/aksel-icons";
|
|
5
|
-
import clsx from "clsx";
|
|
6
|
-
import { useState } from "react";
|
|
7
|
-
import "./SavedFilterTree.css";
|
|
8
|
-
/**
|
|
9
|
-
* The saved-filter list of the filter builder: a "new filter" entry followed by
|
|
10
|
-
* the user's own filters and the filters shared with them.
|
|
11
|
-
*
|
|
12
|
-
* Which actions a filter offers depends on the access the database resolved for
|
|
13
|
-
* it — renaming and deleting are restricted to filters the user created, even
|
|
14
|
-
* when they manage a filter someone else made.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```jsx
|
|
18
|
-
* let { mine, shared, rename, remove } = useSavedFilters({ dbObjectId: "aviw_Personnel_Persons" });
|
|
19
|
-
*
|
|
20
|
-
* <SavedFilterTree
|
|
21
|
-
* mine={mine}
|
|
22
|
-
* shared={shared}
|
|
23
|
-
* value={selected}
|
|
24
|
-
* onChange={setSelected}
|
|
25
|
-
* onRename={(filter) => rename(filter.filterId, prompt("Name", filter.name))}
|
|
26
|
-
* />
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
export function SavedFilterTree({ mine, shared, value, onChange, dirty, onRename, onDelete, onShowInfo, loading, className, "data-size": size = "sm", }) {
|
|
30
|
-
let [expanded, setExpanded] = useState({ mine: true, shared: true });
|
|
31
|
-
function renderBranch(key, label, icon, filters) {
|
|
32
|
-
let isExpanded = expanded[key];
|
|
33
|
-
return (_jsxs("li", { className: "ObSavedFilterTree-branch", children: [_jsxs("button", { type: "button", className: "ObSavedFilterTree-node", "aria-expanded": isExpanded, onClick: () => setExpanded((state) => ({ ...state, [key]: !state[key] })), children: [_jsx("span", { className: "ObSavedFilterTree-chevron", "aria-hidden": true, children: isExpanded ? _jsx(ChevronDownIcon, {}) : _jsx(ChevronRightIcon, {}) }), _jsx("span", { className: "ObSavedFilterTree-icon", "aria-hidden": true, children: icon }), _jsx("span", { className: "ObSavedFilterTree-label", children: label })] }), isExpanded && (_jsxs("ul", { className: "ObSavedFilterTree-children", children: [filters.length === 0 && !loading && (_jsx("li", { className: "ObSavedFilterTree-empty", children: getLocalizedString("No filters") })), filters.map((filter) => (_jsx(SavedFilterNode, { filter: filter, selected: filter.filterId === value, dirty: dirty && filter.filterId === value, onSelect: () => onChange(filter.filterId), onRename: onRename, onDelete: onDelete, onShowInfo: onShowInfo }, filter.filterId)))] }))] }));
|
|
34
|
-
}
|
|
35
|
-
return (_jsxs("ul", { className: clsx("ObSavedFilterTree-root", className), "data-size": size, children: [_jsx("li", { children: _jsxs("button", { type: "button", className: clsx("ObSavedFilterTree-node", value === null && "ObSavedFilterTree-selected"), "aria-current": value === null, onClick: () => onChange(null), children: [_jsx("span", { className: "ObSavedFilterTree-chevron", "aria-hidden": true }), _jsx("span", { className: "ObSavedFilterTree-icon", "aria-hidden": true, children: _jsx(FileTextIcon, {}) }), _jsx("span", { className: "ObSavedFilterTree-label", children: getLocalizedString("New Filter") })] }) }), renderBranch("mine", getLocalizedString("My Filters"), _jsx(StarIcon, {}), mine), renderBranch("shared", getLocalizedString("Shared With Me"), _jsx(FilesIcon, {}), shared)] }));
|
|
36
|
-
}
|
|
37
|
-
function SavedFilterNode({ filter, selected, dirty, onSelect, onRename, onDelete, onShowInfo }) {
|
|
38
|
-
let canRename = Boolean(onRename) && canRenameSavedFilter(filter);
|
|
39
|
-
let canDelete = Boolean(onDelete) && canDeleteSavedFilter(filter);
|
|
40
|
-
let hasMenu = canRename || canDelete || Boolean(onShowInfo);
|
|
41
|
-
// A shared filter the user may not change; the Windows client shows a lock.
|
|
42
|
-
let isReadOnly = !filter.createdByUser && filter.accessLevel === "Reader";
|
|
43
|
-
return (_jsxs("li", { className: "ObSavedFilterTree-item", children: [_jsxs("button", { type: "button", className: clsx("ObSavedFilterTree-node", selected && "ObSavedFilterTree-selected", dirty && "ObSavedFilterTree-dirty"), "aria-current": selected, onClick: onSelect, children: [_jsx("span", { className: "ObSavedFilterTree-icon", "aria-hidden": true, children: isReadOnly ? _jsx(PadlockLockedIcon, {}) : _jsx(FileTextIcon, {}) }), _jsx("span", { className: "ObSavedFilterTree-label", children: filter.name })] }), hasMenu && (_jsxs(Dropdown.TriggerContext, { children: [_jsx(Dropdown.Trigger, { variant: "tertiary", icon: true, className: "ObSavedFilterTree-menuButton", "aria-label": getLocalizedString("Options for {0}").replace("{0}", filter.name), children: _jsx(MenuElipsisVerticalIcon, { "aria-hidden": true }) }), _jsx(Dropdown, { children: _jsxs(Dropdown.List, { children: [canRename && (_jsx(Dropdown.Item, { children: _jsxs(Dropdown.Button, { onClick: () => onRename?.(filter), children: [_jsx(PencilIcon, { "aria-hidden": true }), getLocalizedString("Rename")] }) })), onShowInfo && (_jsx(Dropdown.Item, { children: _jsx(Dropdown.Button, { onClick: () => onShowInfo(filter), children: getLocalizedString("Information") }) })), canDelete && (_jsx(Dropdown.Item, { children: _jsxs(Dropdown.Button, { "data-color": "danger", onClick: () => onDelete?.(filter), children: [_jsx(TrashIcon, { "aria-hidden": true }), getLocalizedString("Delete")] }) }))] }) })] }))] }));
|
|
44
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,75 +0,0 @@
|
|
|
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 { SavedFilterTree } from "./SavedFilterTree.js";
|
|
6
|
-
function savedFilter(overrides) {
|
|
7
|
-
return {
|
|
8
|
-
primKey: `pk-${overrides.filterId}`,
|
|
9
|
-
criteria: "",
|
|
10
|
-
dbObjectId: "aviw_Test_View",
|
|
11
|
-
accessLevel: "Manager",
|
|
12
|
-
createdByUser: true,
|
|
13
|
-
createdBy: "bvh",
|
|
14
|
-
domain: "OB",
|
|
15
|
-
crossDomain: false,
|
|
16
|
-
isPersonallyShared: false,
|
|
17
|
-
hideCriteria: false,
|
|
18
|
-
headerText: null,
|
|
19
|
-
comment: null,
|
|
20
|
-
parameters: null,
|
|
21
|
-
reportTitle: null,
|
|
22
|
-
created: null,
|
|
23
|
-
updated: null,
|
|
24
|
-
...overrides,
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
const MINE = [savedFilter({ filterId: 1, name: "Agder" })];
|
|
28
|
-
const SHARED = [
|
|
29
|
-
savedFilter({ filterId: 2, name: "Alle ledere", createdByUser: false, createdBy: "ola", accessLevel: "Reader" }),
|
|
30
|
-
];
|
|
31
|
-
function renderTree(props = {}) {
|
|
32
|
-
let onChange = vi.fn();
|
|
33
|
-
render(_jsx(SavedFilterTree, { mine: MINE, shared: SHARED, value: null, onChange: onChange, ...props }));
|
|
34
|
-
return { onChange };
|
|
35
|
-
}
|
|
36
|
-
describe("SavedFilterTree", () => {
|
|
37
|
-
it("renders the three fixed nodes and their filters", () => {
|
|
38
|
-
renderTree();
|
|
39
|
-
expect(screen.getByRole("button", { name: "New Filter" })).toBeTruthy();
|
|
40
|
-
expect(screen.getByRole("button", { name: /My Filters/ })).toBeTruthy();
|
|
41
|
-
expect(screen.getByRole("button", { name: /Shared With Me/ })).toBeTruthy();
|
|
42
|
-
expect(screen.getByRole("button", { name: "Agder" })).toBeTruthy();
|
|
43
|
-
expect(screen.getByRole("button", { name: "Alle ledere" })).toBeTruthy();
|
|
44
|
-
});
|
|
45
|
-
it("reports the selected filter id", async () => {
|
|
46
|
-
let { onChange } = renderTree();
|
|
47
|
-
await userEvent.click(screen.getByRole("button", { name: "Agder" }));
|
|
48
|
-
expect(onChange).toHaveBeenCalledWith(1);
|
|
49
|
-
});
|
|
50
|
-
it("reports null when the new filter node is selected", async () => {
|
|
51
|
-
let { onChange } = renderTree({ value: 1 });
|
|
52
|
-
await userEvent.click(screen.getByRole("button", { name: "New Filter" }));
|
|
53
|
-
expect(onChange).toHaveBeenCalledWith(null);
|
|
54
|
-
});
|
|
55
|
-
it("collapses a branch", async () => {
|
|
56
|
-
renderTree();
|
|
57
|
-
await userEvent.click(screen.getByRole("button", { name: /My Filters/ }));
|
|
58
|
-
expect(screen.queryByRole("button", { name: "Agder" })).toBeNull();
|
|
59
|
-
});
|
|
60
|
-
it("offers rename and delete for the user's own filters", async () => {
|
|
61
|
-
let onRename = vi.fn();
|
|
62
|
-
renderTree({ onRename, onDelete: vi.fn() });
|
|
63
|
-
await userEvent.click(screen.getByRole("button", { name: "Options for Agder" }));
|
|
64
|
-
await userEvent.click(screen.getByRole("button", { name: "Rename" }));
|
|
65
|
-
expect(onRename).toHaveBeenCalledWith(MINE[0]);
|
|
66
|
-
});
|
|
67
|
-
it("does not offer rename or delete for filters created by someone else", () => {
|
|
68
|
-
renderTree({ onRename: vi.fn(), onDelete: vi.fn() });
|
|
69
|
-
expect(screen.queryByRole("button", { name: "Options for Alle ledere" })).toBeNull();
|
|
70
|
-
});
|
|
71
|
-
it("still offers info for filters created by someone else", () => {
|
|
72
|
-
renderTree({ onShowInfo: vi.fn() });
|
|
73
|
-
expect(screen.getByRole("button", { name: "Options for Alle ledere" })).toBeTruthy();
|
|
74
|
-
});
|
|
75
|
-
});
|
package/es/filter/types.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { FieldMetadata, FilterTree } from "@olenbetong/appframe-core";
|
|
2
|
-
/** A selectable value for a field that has a fixed list of values. */
|
|
3
|
-
export type FilterValueOption = {
|
|
4
|
-
value: string;
|
|
5
|
-
label?: string;
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* Resolves the list of values offered in the value editor for a field. Return
|
|
9
|
-
* `undefined` to fall back to a free text editor.
|
|
10
|
-
*
|
|
11
|
-
* Lookup fields carry a `valueListRecordSource` in their metadata, but loading
|
|
12
|
-
* that record source needs a data object, which is out of scope for this
|
|
13
|
-
* component. Supply the options from the outside instead.
|
|
14
|
-
*/
|
|
15
|
-
export type GetFieldOptions = (field: FieldMetadata) => FilterValueOption[] | undefined;
|
|
16
|
-
export type FilterEditorSize = "sm" | "md" | "lg";
|
|
17
|
-
export type FilterEditorProps = {
|
|
18
|
-
/** The fields the user can filter on. Fields with `excludeFromFilter` are hidden. */
|
|
19
|
-
fields: FieldMetadata[];
|
|
20
|
-
/** The filter tree. Use together with `onChange` for a controlled component. */
|
|
21
|
-
value?: FilterTree | null;
|
|
22
|
-
/** The initial filter tree when uncontrolled. */
|
|
23
|
-
defaultValue?: FilterTree | null;
|
|
24
|
-
onChange?: (filter: FilterTree) => void;
|
|
25
|
-
/** Renders the tree without any editing affordances. */
|
|
26
|
-
readOnly?: boolean;
|
|
27
|
-
/** Shows the filter string below the tree, editable unless `readOnly`. */
|
|
28
|
-
showFilterString?: boolean;
|
|
29
|
-
/** View the filter applies to. Passed to the conversion endpoint. */
|
|
30
|
-
viewName?: string;
|
|
31
|
-
getFieldOptions?: GetFieldOptions;
|
|
32
|
-
className?: string;
|
|
33
|
-
"data-size"?: FilterEditorSize;
|
|
34
|
-
};
|
package/es/filter/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { ChipRemovable, Textfield } from "@digdir/designsystemet-react";
|
|
2
|
-
import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
3
|
-
import { useState } from "react";
|
|
4
|
-
|
|
5
|
-
export type ChipListInputProps = {
|
|
6
|
-
value: string[];
|
|
7
|
-
onChange: (value: string[]) => void;
|
|
8
|
-
readOnly?: boolean;
|
|
9
|
-
"aria-label": string;
|
|
10
|
-
"data-size"?: "sm" | "md" | "lg";
|
|
11
|
-
type?: "text" | "number" | "date" | "datetime-local";
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Free text editor for the list operators. Values are added with Enter and
|
|
16
|
-
* rendered as removable chips.
|
|
17
|
-
*/
|
|
18
|
-
export function ChipListInput({
|
|
19
|
-
value,
|
|
20
|
-
onChange,
|
|
21
|
-
readOnly,
|
|
22
|
-
type = "text",
|
|
23
|
-
"aria-label": ariaLabel,
|
|
24
|
-
"data-size": size,
|
|
25
|
-
}: ChipListInputProps) {
|
|
26
|
-
let [draft, setDraft] = useState("");
|
|
27
|
-
|
|
28
|
-
function commit() {
|
|
29
|
-
let trimmed = draft.trim();
|
|
30
|
-
if (!trimmed || value.includes(trimmed)) {
|
|
31
|
-
setDraft("");
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
onChange([...value, trimmed]);
|
|
36
|
-
setDraft("");
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function handleKeyDown(event: React.KeyboardEvent<HTMLInputElement>) {
|
|
40
|
-
if (event.key === "Enter") {
|
|
41
|
-
// The editor is often rendered inside a dialog; committing a value
|
|
42
|
-
// must not submit or close it.
|
|
43
|
-
event.preventDefault();
|
|
44
|
-
commit();
|
|
45
|
-
} else if (event.key === "Backspace" && draft === "" && value.length > 0) {
|
|
46
|
-
onChange(value.slice(0, -1));
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return (
|
|
51
|
-
<div className="ObFilterEditor-chipList">
|
|
52
|
-
{value.map((item, index) => (
|
|
53
|
-
<ChipRemovable
|
|
54
|
-
// Values are deduplicated on add, so the value is a stable key.
|
|
55
|
-
key={item}
|
|
56
|
-
data-size={size}
|
|
57
|
-
disabled={readOnly}
|
|
58
|
-
aria-label={`${getLocalizedString("Remove")} ${item}`}
|
|
59
|
-
onClick={() => onChange(value.filter((_, i) => i !== index))}
|
|
60
|
-
>
|
|
61
|
-
{item}
|
|
62
|
-
</ChipRemovable>
|
|
63
|
-
))}
|
|
64
|
-
{!readOnly && (
|
|
65
|
-
<Textfield
|
|
66
|
-
className="ObFilterEditor-chipListInput"
|
|
67
|
-
aria-label={ariaLabel}
|
|
68
|
-
data-size={size}
|
|
69
|
-
type={type}
|
|
70
|
-
value={draft}
|
|
71
|
-
placeholder={getLocalizedString("Add value")}
|
|
72
|
-
onChange={(event) => setDraft(event.target.value)}
|
|
73
|
-
onKeyDown={handleKeyDown}
|
|
74
|
-
onBlur={commit}
|
|
75
|
-
/>
|
|
76
|
-
)}
|
|
77
|
-
</div>
|
|
78
|
-
);
|
|
79
|
-
}
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Colours use the contextual `--ds-color-*` aliases so the builder follows the
|
|
3
|
-
* active colour scheme. Never add hex fallbacks.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
.ObFilterBuilder-root {
|
|
7
|
-
display: grid;
|
|
8
|
-
gap: var(--ds-size-4);
|
|
9
|
-
/*
|
|
10
|
-
* The saved-filter list sits beside the editor. The buttons acting on the
|
|
11
|
-
* selected filter share the bottom row with OK/Cancel rather than being
|
|
12
|
-
* confined to the list's column, so they have room to stay on one line.
|
|
13
|
-
* On narrow viewports everything stacks.
|
|
14
|
-
*/
|
|
15
|
-
grid-template:
|
|
16
|
-
"sidebar main" 1fr
|
|
17
|
-
"error error" auto
|
|
18
|
-
"footer footer" auto
|
|
19
|
-
/ minmax(14rem, 22rem) minmax(0, 1fr);
|
|
20
|
-
block-size: 100%;
|
|
21
|
-
min-block-size: 0;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
.ObFilterBuilder-sidebar {
|
|
25
|
-
grid-area: sidebar;
|
|
26
|
-
overflow: auto;
|
|
27
|
-
padding: var(--ds-size-2);
|
|
28
|
-
border: var(--ds-border-width-default) solid var(--ds-color-border-subtle);
|
|
29
|
-
border-radius: var(--ds-border-radius-md);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/*
|
|
33
|
-
* The editor manages its own scrolling — the conditions scroll, the filter
|
|
34
|
-
* string stays put — so this only has to hand it the available height. A caller
|
|
35
|
-
* that replaces the editor through `renderMain` gets the same treatment.
|
|
36
|
-
*/
|
|
37
|
-
.ObFilterBuilder-main {
|
|
38
|
-
grid-area: main;
|
|
39
|
-
display: flex;
|
|
40
|
-
flex-direction: column;
|
|
41
|
-
gap: var(--ds-size-3);
|
|
42
|
-
min-inline-size: 0;
|
|
43
|
-
min-block-size: 0;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
.ObFilterBuilder-main > * {
|
|
47
|
-
flex: 1 1 auto;
|
|
48
|
-
min-inline-size: 0;
|
|
49
|
-
min-block-size: 0;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
.ObFilterBuilder-error {
|
|
53
|
-
grid-area: error;
|
|
54
|
-
margin: 0;
|
|
55
|
-
color: var(--ds-color-danger-text-default);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
.ObFilterBuilder-footer {
|
|
59
|
-
grid-area: footer;
|
|
60
|
-
display: flex;
|
|
61
|
-
flex-wrap: wrap;
|
|
62
|
-
align-items: center;
|
|
63
|
-
justify-content: space-between;
|
|
64
|
-
gap: var(--ds-size-4);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
.ObFilterBuilder-toolbar,
|
|
68
|
-
.ObFilterBuilder-actions {
|
|
69
|
-
display: flex;
|
|
70
|
-
flex-wrap: wrap;
|
|
71
|
-
align-items: center;
|
|
72
|
-
gap: var(--ds-size-2);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
.ObFilterBuilder-actions {
|
|
76
|
-
margin-inline-start: auto;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/*
|
|
80
|
-
* Without the saved-filter list there are no buttons acting on one either, so
|
|
81
|
-
* the editor takes the full width.
|
|
82
|
-
*/
|
|
83
|
-
.ObFilterBuilder-root--noSavedFilters {
|
|
84
|
-
grid-template:
|
|
85
|
-
"main" 1fr
|
|
86
|
-
"error" auto
|
|
87
|
-
"footer" auto
|
|
88
|
-
/ minmax(0, 1fr);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/*
|
|
92
|
-
* `Dialog` caps itself at `--dsc-dialog-max-width` (40rem), so setting a width
|
|
93
|
-
* here would have no effect — the variable has to be raised instead. It needs
|
|
94
|
-
* to be wide enough that a condition — field, operator, value and the group
|
|
95
|
-
* buttons — fits on one line next to the saved-filter column.
|
|
96
|
-
*/
|
|
97
|
-
.ObFilterBuilder-dialog {
|
|
98
|
-
--dsc-dialog-max-width: 84rem;
|
|
99
|
-
--dsc-dialog-max-height: 90dvh;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/*
|
|
103
|
-
* A fixed height keeps the dialog from resizing as conditions are added and
|
|
104
|
-
* removed, and gives the saved-filter column and the editor a height to fill.
|
|
105
|
-
* The dialog itself must not scroll — the body does — or the heading would
|
|
106
|
-
* scroll away and the OK/Cancel row would not stay at the bottom.
|
|
107
|
-
*/
|
|
108
|
-
.ObFilterBuilder-dialog[open] {
|
|
109
|
-
display: flex;
|
|
110
|
-
flex-direction: column;
|
|
111
|
-
block-size: 48rem;
|
|
112
|
-
overflow: hidden;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/*
|
|
116
|
-
* The heading and the close button share the header row.
|
|
117
|
-
*/
|
|
118
|
-
.ObFilterBuilder-dialogHeader {
|
|
119
|
-
display: flex;
|
|
120
|
-
align-items: center;
|
|
121
|
-
justify-content: space-between;
|
|
122
|
-
gap: var(--ds-size-2);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
.ObFilterBuilder-dialogBody {
|
|
126
|
-
flex: 1 1 auto;
|
|
127
|
-
min-block-size: 0;
|
|
128
|
-
overflow: hidden;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
@media (width < 48rem) {
|
|
132
|
-
.ObFilterBuilder-root:not(.ObFilterBuilder-root--noSavedFilters) {
|
|
133
|
-
grid-template:
|
|
134
|
-
"sidebar" auto
|
|
135
|
-
"main" 1fr
|
|
136
|
-
"error" auto
|
|
137
|
-
"footer" auto
|
|
138
|
-
/ minmax(0, 1fr);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/*
|
|
142
|
-
* Stacked, the dialog body is the scroll container: the editor cannot give
|
|
143
|
-
* both the list and the conditions a useful height in the space left over.
|
|
144
|
-
*/
|
|
145
|
-
.ObFilterBuilder-dialogBody {
|
|
146
|
-
overflow: auto;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
.ObFilterBuilder-sidebar {
|
|
150
|
-
max-block-size: 12rem;
|
|
151
|
-
}
|
|
152
|
-
}
|