@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,220 +0,0 @@
|
|
|
1
|
-
import { Select, Textfield } from "@digdir/designsystemet-react";
|
|
2
|
-
import { PencilIcon } from "@navikt/aksel-icons";
|
|
3
|
-
import {
|
|
4
|
-
type DynamicValue,
|
|
5
|
-
type FieldMetadata,
|
|
6
|
-
type FilterExpression,
|
|
7
|
-
type FilterOperator,
|
|
8
|
-
getDynamicValueLabel,
|
|
9
|
-
getDynamicValuesForField,
|
|
10
|
-
getLocalizedString,
|
|
11
|
-
getOperatorArity,
|
|
12
|
-
getValueType,
|
|
13
|
-
normalizeOperator,
|
|
14
|
-
} from "@olenbetong/appframe-core";
|
|
15
|
-
import { Combobox } from "@olenbetong/appframe-ds";
|
|
16
|
-
|
|
17
|
-
import { ChipListInput } from "./ChipListInput.js";
|
|
18
|
-
import type { FilterEditorSize, FilterValueOption } from "./types.js";
|
|
19
|
-
|
|
20
|
-
export type FilterValueEditorProps = {
|
|
21
|
-
expression: FilterExpression;
|
|
22
|
-
field?: FieldMetadata;
|
|
23
|
-
options?: FilterValueOption[];
|
|
24
|
-
onChange: (expression: FilterExpression) => void;
|
|
25
|
-
readOnly?: boolean;
|
|
26
|
-
"data-size"?: FilterEditorSize;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
/** The `input` type used for a field's scalar editor. */
|
|
30
|
-
function getInputType(field: FieldMetadata | undefined): "text" | "number" | "date" | "datetime-local" {
|
|
31
|
-
switch (field?.type) {
|
|
32
|
-
case "number":
|
|
33
|
-
return "number";
|
|
34
|
-
case "date":
|
|
35
|
-
return "date";
|
|
36
|
-
case "datetime":
|
|
37
|
-
return "datetime-local";
|
|
38
|
-
default:
|
|
39
|
-
return "text";
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function toStringValue(value: FilterExpression["value"]): string {
|
|
44
|
-
if (value === null || value === undefined) return "";
|
|
45
|
-
if (value instanceof Date) return value.toISOString();
|
|
46
|
-
|
|
47
|
-
return String(value);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function toArrayValue(value: FilterExpression["value"], length?: number): string[] {
|
|
51
|
-
let array = Array.isArray(value) ? value.map(toStringValue) : [];
|
|
52
|
-
if (length === undefined) return array;
|
|
53
|
-
|
|
54
|
-
// Pair editors always render two inputs, even before both are filled in.
|
|
55
|
-
return Array.from({ length }, (_, index) => array[index] ?? "");
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* The value part of a filter row. Which editor is rendered depends on the
|
|
60
|
-
* operator's arity, the field's type, and whether the value is a dynamic
|
|
61
|
-
* ("special") value such as `Today` or `CurrentUser`.
|
|
62
|
-
*/
|
|
63
|
-
export function FilterValueEditor({
|
|
64
|
-
expression,
|
|
65
|
-
field,
|
|
66
|
-
options,
|
|
67
|
-
onChange,
|
|
68
|
-
readOnly,
|
|
69
|
-
"data-size": size = "sm",
|
|
70
|
-
}: FilterValueEditorProps) {
|
|
71
|
-
let operator = normalizeOperator(expression.operator);
|
|
72
|
-
let arity = getOperatorArity(operator);
|
|
73
|
-
let isDynamic = expression.valueType === "special";
|
|
74
|
-
let dynamicValues = field ? getDynamicValuesForField(field) : [];
|
|
75
|
-
let inputType = getInputType(field);
|
|
76
|
-
|
|
77
|
-
function setValue(value: FilterExpression["value"]) {
|
|
78
|
-
onChange({ ...expression, value });
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function setDynamic(enabled: boolean) {
|
|
82
|
-
if (enabled) {
|
|
83
|
-
onChange({ ...expression, value: dynamicValues[0] ?? null, valueType: "special" });
|
|
84
|
-
} else {
|
|
85
|
-
onChange({
|
|
86
|
-
...expression,
|
|
87
|
-
value: arity === "pair" ? ["", ""] : arity === "list" ? [] : "",
|
|
88
|
-
valueType: field ? getValueType(field, operator as FilterOperator) : "string",
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (arity === "none") return null;
|
|
94
|
-
|
|
95
|
-
let editor: React.ReactNode;
|
|
96
|
-
|
|
97
|
-
if (isDynamic) {
|
|
98
|
-
editor = (
|
|
99
|
-
<Select
|
|
100
|
-
className="ObFilterEditor-value"
|
|
101
|
-
aria-label={getLocalizedString("Value")}
|
|
102
|
-
data-size={size}
|
|
103
|
-
disabled={readOnly}
|
|
104
|
-
value={toStringValue(expression.value)}
|
|
105
|
-
onChange={(event) => setValue(event.target.value)}
|
|
106
|
-
>
|
|
107
|
-
{dynamicValues.map((dynamicValue) => (
|
|
108
|
-
<Select.Option key={dynamicValue} value={dynamicValue}>
|
|
109
|
-
{getDynamicValueLabel(dynamicValue as DynamicValue)}
|
|
110
|
-
</Select.Option>
|
|
111
|
-
))}
|
|
112
|
-
</Select>
|
|
113
|
-
);
|
|
114
|
-
} else if (arity === "list") {
|
|
115
|
-
editor = options ? (
|
|
116
|
-
<Combobox
|
|
117
|
-
className="ObFilterEditor-value"
|
|
118
|
-
multiple
|
|
119
|
-
data-size={size}
|
|
120
|
-
readOnly={readOnly}
|
|
121
|
-
placeholder={getLocalizedString("Select values")}
|
|
122
|
-
aria-label={getLocalizedString("Value")}
|
|
123
|
-
options={options}
|
|
124
|
-
getOptionLabel={(option) => option.label ?? option.value}
|
|
125
|
-
isOptionEqualToValue={(a, b) => a.value === b.value}
|
|
126
|
-
value={toArrayValue(expression.value).map(
|
|
127
|
-
(item) => options.find((option) => option.value === item) ?? { value: item },
|
|
128
|
-
)}
|
|
129
|
-
onChange={(_event, selected) => setValue(selected.map((option) => option.value))}
|
|
130
|
-
/>
|
|
131
|
-
) : (
|
|
132
|
-
<ChipListInput
|
|
133
|
-
aria-label={getLocalizedString("Value")}
|
|
134
|
-
data-size={size}
|
|
135
|
-
readOnly={readOnly}
|
|
136
|
-
type={inputType}
|
|
137
|
-
value={toArrayValue(expression.value)}
|
|
138
|
-
onChange={setValue}
|
|
139
|
-
/>
|
|
140
|
-
);
|
|
141
|
-
} else if (arity === "pair") {
|
|
142
|
-
let [from, to] = toArrayValue(expression.value, 2);
|
|
143
|
-
|
|
144
|
-
editor = (
|
|
145
|
-
<div className="ObFilterEditor-pair">
|
|
146
|
-
<Textfield
|
|
147
|
-
className="ObFilterEditor-value"
|
|
148
|
-
aria-label={getLocalizedString("From")}
|
|
149
|
-
data-size={size}
|
|
150
|
-
readOnly={readOnly}
|
|
151
|
-
type={inputType}
|
|
152
|
-
value={from}
|
|
153
|
-
onChange={(event) => setValue([event.target.value, to])}
|
|
154
|
-
/>
|
|
155
|
-
<span className="ObFilterEditor-pairSeparator">{getLocalizedString("and")}</span>
|
|
156
|
-
<Textfield
|
|
157
|
-
className="ObFilterEditor-value"
|
|
158
|
-
aria-label={getLocalizedString("To")}
|
|
159
|
-
data-size={size}
|
|
160
|
-
readOnly={readOnly}
|
|
161
|
-
type={inputType}
|
|
162
|
-
value={to}
|
|
163
|
-
onChange={(event) => setValue([from, event.target.value])}
|
|
164
|
-
/>
|
|
165
|
-
</div>
|
|
166
|
-
);
|
|
167
|
-
} else if (options) {
|
|
168
|
-
let current = toStringValue(expression.value);
|
|
169
|
-
|
|
170
|
-
editor = (
|
|
171
|
-
<Combobox
|
|
172
|
-
className="ObFilterEditor-value"
|
|
173
|
-
data-size={size}
|
|
174
|
-
readOnly={readOnly}
|
|
175
|
-
placeholder={getLocalizedString("Select value")}
|
|
176
|
-
aria-label={getLocalizedString("Value")}
|
|
177
|
-
options={options}
|
|
178
|
-
getOptionLabel={(option) => option.label ?? option.value}
|
|
179
|
-
isOptionEqualToValue={(a, b) => a.value === b.value}
|
|
180
|
-
value={current ? (options.find((option) => option.value === current) ?? { value: current }) : null}
|
|
181
|
-
onChange={(_event, selected) => setValue(selected?.value ?? "")}
|
|
182
|
-
/>
|
|
183
|
-
);
|
|
184
|
-
} else {
|
|
185
|
-
editor = (
|
|
186
|
-
<Textfield
|
|
187
|
-
className="ObFilterEditor-value"
|
|
188
|
-
aria-label={getLocalizedString("Value")}
|
|
189
|
-
data-size={size}
|
|
190
|
-
readOnly={readOnly}
|
|
191
|
-
type={inputType}
|
|
192
|
-
value={toStringValue(expression.value)}
|
|
193
|
-
onChange={(event) => setValue(event.target.value)}
|
|
194
|
-
/>
|
|
195
|
-
);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// Dynamic values are resolved server side, so they can only replace the whole
|
|
199
|
-
// value. Pairs would need one toggle per side, which the Windows editor does
|
|
200
|
-
// not offer either.
|
|
201
|
-
let canToggleDynamic = !readOnly && dynamicValues.length > 0 && arity === "single";
|
|
202
|
-
|
|
203
|
-
return (
|
|
204
|
-
<div className="ObFilterEditor-valueCell">
|
|
205
|
-
{editor}
|
|
206
|
-
{canToggleDynamic && (
|
|
207
|
-
<button
|
|
208
|
-
type="button"
|
|
209
|
-
className="ObFilterEditor-iconButton"
|
|
210
|
-
aria-pressed={isDynamic}
|
|
211
|
-
title={getLocalizedString("Use a relative value")}
|
|
212
|
-
aria-label={getLocalizedString("Use a relative value")}
|
|
213
|
-
onClick={() => setDynamic(!isDynamic)}
|
|
214
|
-
>
|
|
215
|
-
<PencilIcon aria-hidden />
|
|
216
|
-
</button>
|
|
217
|
-
)}
|
|
218
|
-
</div>
|
|
219
|
-
);
|
|
220
|
-
}
|
|
@@ -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,94 +0,0 @@
|
|
|
1
|
-
import type { SavedFilter } from "@olenbetong/appframe-core";
|
|
2
|
-
import { render, screen } from "@testing-library/react";
|
|
3
|
-
import userEvent from "@testing-library/user-event";
|
|
4
|
-
import { describe, expect, it, vi } from "vitest";
|
|
5
|
-
|
|
6
|
-
import { SavedFilterTree } from "./SavedFilterTree.js";
|
|
7
|
-
|
|
8
|
-
function savedFilter(overrides: Partial<SavedFilter> & Pick<SavedFilter, "filterId" | "name">): SavedFilter {
|
|
9
|
-
return {
|
|
10
|
-
primKey: `pk-${overrides.filterId}`,
|
|
11
|
-
criteria: "",
|
|
12
|
-
dbObjectId: "aviw_Test_View",
|
|
13
|
-
accessLevel: "Manager",
|
|
14
|
-
createdByUser: true,
|
|
15
|
-
createdBy: "bvh",
|
|
16
|
-
domain: "OB",
|
|
17
|
-
crossDomain: false,
|
|
18
|
-
isPersonallyShared: false,
|
|
19
|
-
hideCriteria: false,
|
|
20
|
-
headerText: null,
|
|
21
|
-
comment: null,
|
|
22
|
-
parameters: null,
|
|
23
|
-
reportTitle: null,
|
|
24
|
-
created: null,
|
|
25
|
-
updated: null,
|
|
26
|
-
...overrides,
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const MINE = [savedFilter({ filterId: 1, name: "Agder" })];
|
|
31
|
-
const SHARED = [
|
|
32
|
-
savedFilter({ filterId: 2, name: "Alle ledere", createdByUser: false, createdBy: "ola", accessLevel: "Reader" }),
|
|
33
|
-
];
|
|
34
|
-
|
|
35
|
-
function renderTree(props: Partial<React.ComponentProps<typeof SavedFilterTree>> = {}) {
|
|
36
|
-
let onChange = vi.fn();
|
|
37
|
-
render(<SavedFilterTree mine={MINE} shared={SHARED} value={null} onChange={onChange} {...props} />);
|
|
38
|
-
|
|
39
|
-
return { onChange };
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
describe("SavedFilterTree", () => {
|
|
43
|
-
it("renders the three fixed nodes and their filters", () => {
|
|
44
|
-
renderTree();
|
|
45
|
-
|
|
46
|
-
expect(screen.getByRole("button", { name: "New Filter" })).toBeTruthy();
|
|
47
|
-
expect(screen.getByRole("button", { name: /My Filters/ })).toBeTruthy();
|
|
48
|
-
expect(screen.getByRole("button", { name: /Shared With Me/ })).toBeTruthy();
|
|
49
|
-
expect(screen.getByRole("button", { name: "Agder" })).toBeTruthy();
|
|
50
|
-
expect(screen.getByRole("button", { name: "Alle ledere" })).toBeTruthy();
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it("reports the selected filter id", async () => {
|
|
54
|
-
let { onChange } = renderTree();
|
|
55
|
-
await userEvent.click(screen.getByRole("button", { name: "Agder" }));
|
|
56
|
-
|
|
57
|
-
expect(onChange).toHaveBeenCalledWith(1);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("reports null when the new filter node is selected", async () => {
|
|
61
|
-
let { onChange } = renderTree({ value: 1 });
|
|
62
|
-
await userEvent.click(screen.getByRole("button", { name: "New Filter" }));
|
|
63
|
-
|
|
64
|
-
expect(onChange).toHaveBeenCalledWith(null);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it("collapses a branch", async () => {
|
|
68
|
-
renderTree();
|
|
69
|
-
await userEvent.click(screen.getByRole("button", { name: /My Filters/ }));
|
|
70
|
-
|
|
71
|
-
expect(screen.queryByRole("button", { name: "Agder" })).toBeNull();
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it("offers rename and delete for the user's own filters", async () => {
|
|
75
|
-
let onRename = vi.fn();
|
|
76
|
-
renderTree({ onRename, onDelete: vi.fn() });
|
|
77
|
-
await userEvent.click(screen.getByRole("button", { name: "Options for Agder" }));
|
|
78
|
-
await userEvent.click(screen.getByRole("button", { name: "Rename" }));
|
|
79
|
-
|
|
80
|
-
expect(onRename).toHaveBeenCalledWith(MINE[0]);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it("does not offer rename or delete for filters created by someone else", () => {
|
|
84
|
-
renderTree({ onRename: vi.fn(), onDelete: vi.fn() });
|
|
85
|
-
|
|
86
|
-
expect(screen.queryByRole("button", { name: "Options for Alle ledere" })).toBeNull();
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it("still offers info for filters created by someone else", () => {
|
|
90
|
-
renderTree({ onShowInfo: vi.fn() });
|
|
91
|
-
|
|
92
|
-
expect(screen.getByRole("button", { name: "Options for Alle ledere" })).toBeTruthy();
|
|
93
|
-
});
|
|
94
|
-
});
|
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
import { Dropdown } from "@digdir/designsystemet-react";
|
|
2
|
-
import {
|
|
3
|
-
canDeleteSavedFilter,
|
|
4
|
-
canRenameSavedFilter,
|
|
5
|
-
getLocalizedString,
|
|
6
|
-
type SavedFilter,
|
|
7
|
-
} from "@olenbetong/appframe-core";
|
|
8
|
-
import {
|
|
9
|
-
ChevronDownIcon,
|
|
10
|
-
ChevronRightIcon,
|
|
11
|
-
FilesIcon,
|
|
12
|
-
FileTextIcon,
|
|
13
|
-
MenuElipsisVerticalIcon,
|
|
14
|
-
PadlockLockedIcon,
|
|
15
|
-
PencilIcon,
|
|
16
|
-
StarIcon,
|
|
17
|
-
TrashIcon,
|
|
18
|
-
} from "@navikt/aksel-icons";
|
|
19
|
-
import clsx from "clsx";
|
|
20
|
-
import { useState } from "react";
|
|
21
|
-
|
|
22
|
-
import "./SavedFilterTree.css";
|
|
23
|
-
|
|
24
|
-
/** `null` is the "new filter" node, i.e. no saved filter selected. */
|
|
25
|
-
export type SavedFilterSelection = number | null;
|
|
26
|
-
|
|
27
|
-
export type SavedFilterTreeProps = {
|
|
28
|
-
mine: SavedFilter[];
|
|
29
|
-
shared: SavedFilter[];
|
|
30
|
-
/** `FilterID` of the selected filter, or `null` for "new filter". */
|
|
31
|
-
value: SavedFilterSelection;
|
|
32
|
-
onChange: (filterId: SavedFilterSelection) => void;
|
|
33
|
-
/**
|
|
34
|
-
* Marks the selected filter as having unsaved changes; it is then rendered
|
|
35
|
-
* in bold, like the Windows client does.
|
|
36
|
-
*/
|
|
37
|
-
dirty?: boolean;
|
|
38
|
-
onRename?: (filter: SavedFilter) => void;
|
|
39
|
-
onDelete?: (filter: SavedFilter) => void;
|
|
40
|
-
/** Shows an "info" item in the context menu when supplied. */
|
|
41
|
-
onShowInfo?: (filter: SavedFilter) => void;
|
|
42
|
-
loading?: boolean;
|
|
43
|
-
className?: string;
|
|
44
|
-
"data-size"?: "sm" | "md" | "lg";
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* The saved-filter list of the filter builder: a "new filter" entry followed by
|
|
49
|
-
* the user's own filters and the filters shared with them.
|
|
50
|
-
*
|
|
51
|
-
* Which actions a filter offers depends on the access the database resolved for
|
|
52
|
-
* it — renaming and deleting are restricted to filters the user created, even
|
|
53
|
-
* when they manage a filter someone else made.
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* ```jsx
|
|
57
|
-
* let { mine, shared, rename, remove } = useSavedFilters({ dbObjectId: "aviw_Personnel_Persons" });
|
|
58
|
-
*
|
|
59
|
-
* <SavedFilterTree
|
|
60
|
-
* mine={mine}
|
|
61
|
-
* shared={shared}
|
|
62
|
-
* value={selected}
|
|
63
|
-
* onChange={setSelected}
|
|
64
|
-
* onRename={(filter) => rename(filter.filterId, prompt("Name", filter.name))}
|
|
65
|
-
* />
|
|
66
|
-
* ```
|
|
67
|
-
*/
|
|
68
|
-
export function SavedFilterTree({
|
|
69
|
-
mine,
|
|
70
|
-
shared,
|
|
71
|
-
value,
|
|
72
|
-
onChange,
|
|
73
|
-
dirty,
|
|
74
|
-
onRename,
|
|
75
|
-
onDelete,
|
|
76
|
-
onShowInfo,
|
|
77
|
-
loading,
|
|
78
|
-
className,
|
|
79
|
-
"data-size": size = "sm",
|
|
80
|
-
}: SavedFilterTreeProps) {
|
|
81
|
-
let [expanded, setExpanded] = useState({ mine: true, shared: true });
|
|
82
|
-
|
|
83
|
-
function renderBranch(key: "mine" | "shared", label: string, icon: React.ReactNode, filters: SavedFilter[]) {
|
|
84
|
-
let isExpanded = expanded[key];
|
|
85
|
-
|
|
86
|
-
return (
|
|
87
|
-
<li className="ObSavedFilterTree-branch">
|
|
88
|
-
<button
|
|
89
|
-
type="button"
|
|
90
|
-
className="ObSavedFilterTree-node"
|
|
91
|
-
aria-expanded={isExpanded}
|
|
92
|
-
onClick={() => setExpanded((state) => ({ ...state, [key]: !state[key] }))}
|
|
93
|
-
>
|
|
94
|
-
<span className="ObSavedFilterTree-chevron" aria-hidden>
|
|
95
|
-
{isExpanded ? <ChevronDownIcon /> : <ChevronRightIcon />}
|
|
96
|
-
</span>
|
|
97
|
-
<span className="ObSavedFilterTree-icon" aria-hidden>
|
|
98
|
-
{icon}
|
|
99
|
-
</span>
|
|
100
|
-
<span className="ObSavedFilterTree-label">{label}</span>
|
|
101
|
-
</button>
|
|
102
|
-
{isExpanded && (
|
|
103
|
-
<ul className="ObSavedFilterTree-children">
|
|
104
|
-
{filters.length === 0 && !loading && (
|
|
105
|
-
<li className="ObSavedFilterTree-empty">{getLocalizedString("No filters")}</li>
|
|
106
|
-
)}
|
|
107
|
-
{filters.map((filter) => (
|
|
108
|
-
<SavedFilterNode
|
|
109
|
-
key={filter.filterId}
|
|
110
|
-
filter={filter}
|
|
111
|
-
selected={filter.filterId === value}
|
|
112
|
-
dirty={dirty && filter.filterId === value}
|
|
113
|
-
onSelect={() => onChange(filter.filterId)}
|
|
114
|
-
onRename={onRename}
|
|
115
|
-
onDelete={onDelete}
|
|
116
|
-
onShowInfo={onShowInfo}
|
|
117
|
-
/>
|
|
118
|
-
))}
|
|
119
|
-
</ul>
|
|
120
|
-
)}
|
|
121
|
-
</li>
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return (
|
|
126
|
-
<ul className={clsx("ObSavedFilterTree-root", className)} data-size={size}>
|
|
127
|
-
<li>
|
|
128
|
-
<button
|
|
129
|
-
type="button"
|
|
130
|
-
className={clsx("ObSavedFilterTree-node", value === null && "ObSavedFilterTree-selected")}
|
|
131
|
-
aria-current={value === null}
|
|
132
|
-
onClick={() => onChange(null)}
|
|
133
|
-
>
|
|
134
|
-
<span className="ObSavedFilterTree-chevron" aria-hidden />
|
|
135
|
-
<span className="ObSavedFilterTree-icon" aria-hidden>
|
|
136
|
-
<FileTextIcon />
|
|
137
|
-
</span>
|
|
138
|
-
<span className="ObSavedFilterTree-label">{getLocalizedString("New Filter")}</span>
|
|
139
|
-
</button>
|
|
140
|
-
</li>
|
|
141
|
-
{renderBranch("mine", getLocalizedString("My Filters"), <StarIcon />, mine)}
|
|
142
|
-
{renderBranch("shared", getLocalizedString("Shared With Me"), <FilesIcon />, shared)}
|
|
143
|
-
</ul>
|
|
144
|
-
);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
type SavedFilterNodeProps = {
|
|
148
|
-
filter: SavedFilter;
|
|
149
|
-
selected: boolean;
|
|
150
|
-
dirty?: boolean;
|
|
151
|
-
onSelect: () => void;
|
|
152
|
-
onRename?: (filter: SavedFilter) => void;
|
|
153
|
-
onDelete?: (filter: SavedFilter) => void;
|
|
154
|
-
onShowInfo?: (filter: SavedFilter) => void;
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
function SavedFilterNode({ filter, selected, dirty, onSelect, onRename, onDelete, onShowInfo }: SavedFilterNodeProps) {
|
|
158
|
-
let canRename = Boolean(onRename) && canRenameSavedFilter(filter);
|
|
159
|
-
let canDelete = Boolean(onDelete) && canDeleteSavedFilter(filter);
|
|
160
|
-
let hasMenu = canRename || canDelete || Boolean(onShowInfo);
|
|
161
|
-
// A shared filter the user may not change; the Windows client shows a lock.
|
|
162
|
-
let isReadOnly = !filter.createdByUser && filter.accessLevel === "Reader";
|
|
163
|
-
|
|
164
|
-
return (
|
|
165
|
-
<li className="ObSavedFilterTree-item">
|
|
166
|
-
<button
|
|
167
|
-
type="button"
|
|
168
|
-
className={clsx(
|
|
169
|
-
"ObSavedFilterTree-node",
|
|
170
|
-
selected && "ObSavedFilterTree-selected",
|
|
171
|
-
dirty && "ObSavedFilterTree-dirty",
|
|
172
|
-
)}
|
|
173
|
-
aria-current={selected}
|
|
174
|
-
onClick={onSelect}
|
|
175
|
-
>
|
|
176
|
-
<span className="ObSavedFilterTree-icon" aria-hidden>
|
|
177
|
-
{isReadOnly ? <PadlockLockedIcon /> : <FileTextIcon />}
|
|
178
|
-
</span>
|
|
179
|
-
<span className="ObSavedFilterTree-label">{filter.name}</span>
|
|
180
|
-
</button>
|
|
181
|
-
{hasMenu && (
|
|
182
|
-
<Dropdown.TriggerContext>
|
|
183
|
-
<Dropdown.Trigger
|
|
184
|
-
variant="tertiary"
|
|
185
|
-
icon
|
|
186
|
-
className="ObSavedFilterTree-menuButton"
|
|
187
|
-
aria-label={getLocalizedString("Options for {0}").replace("{0}", filter.name)}
|
|
188
|
-
>
|
|
189
|
-
<MenuElipsisVerticalIcon aria-hidden />
|
|
190
|
-
</Dropdown.Trigger>
|
|
191
|
-
<Dropdown>
|
|
192
|
-
<Dropdown.List>
|
|
193
|
-
{canRename && (
|
|
194
|
-
<Dropdown.Item>
|
|
195
|
-
<Dropdown.Button onClick={() => onRename?.(filter)}>
|
|
196
|
-
<PencilIcon aria-hidden />
|
|
197
|
-
{getLocalizedString("Rename")}
|
|
198
|
-
</Dropdown.Button>
|
|
199
|
-
</Dropdown.Item>
|
|
200
|
-
)}
|
|
201
|
-
{onShowInfo && (
|
|
202
|
-
<Dropdown.Item>
|
|
203
|
-
<Dropdown.Button onClick={() => onShowInfo(filter)}>
|
|
204
|
-
{getLocalizedString("Information")}
|
|
205
|
-
</Dropdown.Button>
|
|
206
|
-
</Dropdown.Item>
|
|
207
|
-
)}
|
|
208
|
-
{canDelete && (
|
|
209
|
-
<Dropdown.Item>
|
|
210
|
-
<Dropdown.Button data-color="danger" onClick={() => onDelete?.(filter)}>
|
|
211
|
-
<TrashIcon aria-hidden />
|
|
212
|
-
{getLocalizedString("Delete")}
|
|
213
|
-
</Dropdown.Button>
|
|
214
|
-
</Dropdown.Item>
|
|
215
|
-
)}
|
|
216
|
-
</Dropdown.List>
|
|
217
|
-
</Dropdown>
|
|
218
|
-
</Dropdown.TriggerContext>
|
|
219
|
-
)}
|
|
220
|
-
</li>
|
|
221
|
-
);
|
|
222
|
-
}
|
package/src/filter/types.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { FieldMetadata, FilterTree } from "@olenbetong/appframe-core";
|
|
2
|
-
|
|
3
|
-
/** A selectable value for a field that has a fixed list of values. */
|
|
4
|
-
export type FilterValueOption = {
|
|
5
|
-
value: string;
|
|
6
|
-
label?: string;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Resolves the list of values offered in the value editor for a field. Return
|
|
11
|
-
* `undefined` to fall back to a free text editor.
|
|
12
|
-
*
|
|
13
|
-
* Lookup fields carry a `valueListRecordSource` in their metadata, but loading
|
|
14
|
-
* that record source needs a data object, which is out of scope for this
|
|
15
|
-
* component. Supply the options from the outside instead.
|
|
16
|
-
*/
|
|
17
|
-
export type GetFieldOptions = (field: FieldMetadata) => FilterValueOption[] | undefined;
|
|
18
|
-
|
|
19
|
-
export type FilterEditorSize = "sm" | "md" | "lg";
|
|
20
|
-
|
|
21
|
-
export type FilterEditorProps = {
|
|
22
|
-
/** The fields the user can filter on. Fields with `excludeFromFilter` are hidden. */
|
|
23
|
-
fields: FieldMetadata[];
|
|
24
|
-
/** The filter tree. Use together with `onChange` for a controlled component. */
|
|
25
|
-
value?: FilterTree | null;
|
|
26
|
-
/** The initial filter tree when uncontrolled. */
|
|
27
|
-
defaultValue?: FilterTree | null;
|
|
28
|
-
onChange?: (filter: FilterTree) => void;
|
|
29
|
-
/** Renders the tree without any editing affordances. */
|
|
30
|
-
readOnly?: boolean;
|
|
31
|
-
/** Shows the filter string below the tree, editable unless `readOnly`. */
|
|
32
|
-
showFilterString?: boolean;
|
|
33
|
-
/** View the filter applies to. Passed to the conversion endpoint. */
|
|
34
|
-
viewName?: string;
|
|
35
|
-
getFieldOptions?: GetFieldOptions;
|
|
36
|
-
className?: string;
|
|
37
|
-
"data-size"?: FilterEditorSize;
|
|
38
|
-
};
|