@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,160 +0,0 @@
|
|
|
1
|
-
import { Button, Select } from "@digdir/designsystemet-react";
|
|
2
|
-
import { FolderPlusIcon, TrashIcon } from "@navikt/aksel-icons";
|
|
3
|
-
import {
|
|
4
|
-
addGroupAtPath,
|
|
5
|
-
createExpression,
|
|
6
|
-
type FieldMetadata,
|
|
7
|
-
type FilterExpression,
|
|
8
|
-
type FilterGroup,
|
|
9
|
-
type FilterNode,
|
|
10
|
-
type FilterPath,
|
|
11
|
-
type FilterTree,
|
|
12
|
-
getLocalizedString,
|
|
13
|
-
getNodeAtPath,
|
|
14
|
-
insertNodeAtPath,
|
|
15
|
-
isExpression,
|
|
16
|
-
isGroup,
|
|
17
|
-
removeNodeAtPath,
|
|
18
|
-
setGroupMode,
|
|
19
|
-
updateNodeAtPath,
|
|
20
|
-
} from "@olenbetong/appframe-core";
|
|
21
|
-
import { Combobox } from "@olenbetong/appframe-ds";
|
|
22
|
-
|
|
23
|
-
import { FilterRow, getFieldLabel } from "./FilterRow.js";
|
|
24
|
-
import type { FilterEditorSize, GetFieldOptions } from "./types.js";
|
|
25
|
-
|
|
26
|
-
export type FilterGroupEditorProps = {
|
|
27
|
-
/** The whole tree. Groups edit it through their own `path`. */
|
|
28
|
-
filter: FilterTree;
|
|
29
|
-
/** Path to the group this editor renders. The root group is the empty path. */
|
|
30
|
-
path: FilterPath;
|
|
31
|
-
fields: FieldMetadata[];
|
|
32
|
-
onChange: (filter: FilterTree) => void;
|
|
33
|
-
getFieldOptions?: GetFieldOptions;
|
|
34
|
-
readOnly?: boolean;
|
|
35
|
-
"data-size"?: FilterEditorSize;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* One group of the filter tree. Groups can be nested and each one combines its
|
|
40
|
-
* items with either `and` or `or`, matching the advanced (DevExpress) filter
|
|
41
|
-
* editor in the Windows client.
|
|
42
|
-
*
|
|
43
|
-
* A blank row is always rendered at the end; picking a field in it appends a
|
|
44
|
-
* real condition to the group.
|
|
45
|
-
*/
|
|
46
|
-
export function FilterGroupEditor({
|
|
47
|
-
filter,
|
|
48
|
-
path,
|
|
49
|
-
fields,
|
|
50
|
-
onChange,
|
|
51
|
-
getFieldOptions,
|
|
52
|
-
readOnly,
|
|
53
|
-
"data-size": size = "sm",
|
|
54
|
-
}: FilterGroupEditorProps) {
|
|
55
|
-
let node = getNodeAtPath(filter, path);
|
|
56
|
-
if (!node || !isGroup(node)) return null;
|
|
57
|
-
|
|
58
|
-
let group: FilterGroup = node;
|
|
59
|
-
let isRoot = path.length === 0;
|
|
60
|
-
|
|
61
|
-
return (
|
|
62
|
-
<div className="ObFilterEditor-group" data-root={isRoot ? "" : undefined}>
|
|
63
|
-
<div className="ObFilterEditor-groupHeader">
|
|
64
|
-
<Select
|
|
65
|
-
className="ObFilterEditor-groupMode"
|
|
66
|
-
data-size={size}
|
|
67
|
-
disabled={readOnly}
|
|
68
|
-
aria-label={getLocalizedString("Group operator")}
|
|
69
|
-
value={group.mode}
|
|
70
|
-
onChange={(event) => onChange(setGroupMode(filter, path, event.target.value as FilterGroup["mode"]))}
|
|
71
|
-
>
|
|
72
|
-
<Select.Option value="and">{getLocalizedString("And")}</Select.Option>
|
|
73
|
-
<Select.Option value="or">{getLocalizedString("Or")}</Select.Option>
|
|
74
|
-
</Select>
|
|
75
|
-
{!readOnly && (
|
|
76
|
-
<>
|
|
77
|
-
<Button
|
|
78
|
-
type="button"
|
|
79
|
-
variant="tertiary"
|
|
80
|
-
data-size={size}
|
|
81
|
-
className="ObFilterEditor-groupButton"
|
|
82
|
-
aria-label={getLocalizedString("Add group")}
|
|
83
|
-
onClick={() => onChange(addGroupAtPath(filter, path))}
|
|
84
|
-
>
|
|
85
|
-
<FolderPlusIcon aria-hidden />
|
|
86
|
-
<span className="ObFilterEditor-groupButtonLabel">{getLocalizedString("Add group")}</span>
|
|
87
|
-
</Button>
|
|
88
|
-
{!isRoot && (
|
|
89
|
-
<Button
|
|
90
|
-
type="button"
|
|
91
|
-
variant="tertiary"
|
|
92
|
-
data-color="danger"
|
|
93
|
-
data-size={size}
|
|
94
|
-
className="ObFilterEditor-groupButton"
|
|
95
|
-
aria-label={getLocalizedString("Remove group")}
|
|
96
|
-
onClick={() => onChange(removeNodeAtPath(filter, path))}
|
|
97
|
-
>
|
|
98
|
-
<TrashIcon aria-hidden />
|
|
99
|
-
<span className="ObFilterEditor-groupButtonLabel">{getLocalizedString("Remove group")}</span>
|
|
100
|
-
</Button>
|
|
101
|
-
)}
|
|
102
|
-
</>
|
|
103
|
-
)}
|
|
104
|
-
</div>
|
|
105
|
-
<div className="ObFilterEditor-groupItems">
|
|
106
|
-
{group.items.map((item, index) =>
|
|
107
|
-
isExpression(item) ? (
|
|
108
|
-
<FilterRow
|
|
109
|
-
// Rows have no stable identity, and reordering is not supported,
|
|
110
|
-
// so the index is the only key available.
|
|
111
|
-
// oxlint-disable-next-line no-array-index-key -- see above
|
|
112
|
-
key={index}
|
|
113
|
-
expression={item}
|
|
114
|
-
fields={fields}
|
|
115
|
-
getFieldOptions={getFieldOptions}
|
|
116
|
-
readOnly={readOnly}
|
|
117
|
-
data-size={size}
|
|
118
|
-
onChange={(next) => onChange(replaceNode(filter, [...path, index], next))}
|
|
119
|
-
onRemove={() => onChange(removeNodeAtPath(filter, [...path, index]))}
|
|
120
|
-
/>
|
|
121
|
-
) : (
|
|
122
|
-
<FilterGroupEditor
|
|
123
|
-
// oxlint-disable-next-line no-array-index-key -- see above
|
|
124
|
-
key={index}
|
|
125
|
-
filter={filter}
|
|
126
|
-
path={[...path, index]}
|
|
127
|
-
fields={fields}
|
|
128
|
-
getFieldOptions={getFieldOptions}
|
|
129
|
-
readOnly={readOnly}
|
|
130
|
-
data-size={size}
|
|
131
|
-
onChange={onChange}
|
|
132
|
-
/>
|
|
133
|
-
),
|
|
134
|
-
)}
|
|
135
|
-
{!readOnly && (
|
|
136
|
-
<div className="ObFilterEditor-row ObFilterEditor-draftRow">
|
|
137
|
-
<Combobox
|
|
138
|
-
className="ObFilterEditor-field"
|
|
139
|
-
data-size={size}
|
|
140
|
-
aria-label={getLocalizedString("Add condition")}
|
|
141
|
-
placeholder={getLocalizedString("Add condition")}
|
|
142
|
-
options={fields}
|
|
143
|
-
getOptionLabel={getFieldLabel}
|
|
144
|
-
getOptionKey={(option) => option.name}
|
|
145
|
-
isOptionEqualToValue={(a, b) => a.name === b.name}
|
|
146
|
-
value={null}
|
|
147
|
-
onChange={(_event, field) => {
|
|
148
|
-
if (field) onChange(insertNodeAtPath(filter, path, createExpression(field)));
|
|
149
|
-
}}
|
|
150
|
-
/>
|
|
151
|
-
</div>
|
|
152
|
-
)}
|
|
153
|
-
</div>
|
|
154
|
-
</div>
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
function replaceNode(filter: FilterTree, path: FilterPath, node: FilterExpression): FilterTree {
|
|
159
|
-
return updateNodeAtPath<FilterNode>(filter, path, () => node) as FilterTree;
|
|
160
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Colours use the contextual `--ds-color-*` aliases so the dialog follows the
|
|
3
|
-
* active colour scheme. Never add hex fallbacks.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/*
|
|
7
|
-
* Designsystemet drops the dialog's own padding when its children are blocks,
|
|
8
|
-
* but the rule only looks at direct children, and the blocks here are wrapped
|
|
9
|
-
* in the form. Without this the blocks are inset and their dividers stop short
|
|
10
|
-
* of the dialog's edges.
|
|
11
|
-
*/
|
|
12
|
-
.ObFilterNameDialog-root {
|
|
13
|
-
inline-size: min(28rem, 100%);
|
|
14
|
-
padding: 0;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
.ObFilterNameDialog-actions {
|
|
18
|
-
display: flex;
|
|
19
|
-
flex-direction: row;
|
|
20
|
-
justify-content: flex-end;
|
|
21
|
-
gap: var(--ds-size-2);
|
|
22
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import "./FilterNameDialog.css";
|
|
2
|
-
|
|
3
|
-
import { Button, Dialog, Heading, Textfield } from "@digdir/designsystemet-react";
|
|
4
|
-
import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
5
|
-
import { useEffect, useState } from "react";
|
|
6
|
-
|
|
7
|
-
export type FilterNameDialogProps = {
|
|
8
|
-
open: boolean;
|
|
9
|
-
/** Pre-fills the field, e.g. with the current filter's name. */
|
|
10
|
-
defaultName?: string;
|
|
11
|
-
/** Names already in use; entering one asks the user to confirm the overwrite. */
|
|
12
|
-
existingNames?: string[];
|
|
13
|
-
onCancel: () => void;
|
|
14
|
-
onSubmit: (name: string) => void;
|
|
15
|
-
"data-size"?: "sm" | "md" | "lg";
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Asks for the name to save a filter under.
|
|
20
|
-
*
|
|
21
|
-
* Reusing an existing name overwrites that filter, so the dialog warns before
|
|
22
|
-
* submitting rather than silently creating a second filter with the same name.
|
|
23
|
-
*/
|
|
24
|
-
export function FilterNameDialog({
|
|
25
|
-
open,
|
|
26
|
-
defaultName = "",
|
|
27
|
-
existingNames = [],
|
|
28
|
-
onCancel,
|
|
29
|
-
onSubmit,
|
|
30
|
-
"data-size": size = "sm",
|
|
31
|
-
}: FilterNameDialogProps) {
|
|
32
|
-
let [name, setName] = useState(defaultName);
|
|
33
|
-
|
|
34
|
-
useEffect(() => {
|
|
35
|
-
if (open) setName(defaultName);
|
|
36
|
-
}, [open, defaultName]);
|
|
37
|
-
|
|
38
|
-
let trimmed = name.trim();
|
|
39
|
-
// A filter keeping its own name is an update, not a collision.
|
|
40
|
-
let collides = trimmed !== defaultName && existingNames.some((existing) => existing === trimmed);
|
|
41
|
-
|
|
42
|
-
function handleSubmit(event: React.FormEvent) {
|
|
43
|
-
event.preventDefault();
|
|
44
|
-
if (!trimmed) return;
|
|
45
|
-
|
|
46
|
-
onSubmit(trimmed);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return (
|
|
50
|
-
<Dialog open={open} closedby="any" data-size={size} className="ObFilterNameDialog-root" onClose={onCancel}>
|
|
51
|
-
<form onSubmit={handleSubmit}>
|
|
52
|
-
<Dialog.Block>
|
|
53
|
-
<Heading level={2} data-size="xs">
|
|
54
|
-
{getLocalizedString("Save filter")}
|
|
55
|
-
</Heading>
|
|
56
|
-
</Dialog.Block>
|
|
57
|
-
<Dialog.Block>
|
|
58
|
-
<Textfield
|
|
59
|
-
// oxlint-disable-next-line jsx-a11y/no-autofocus -- the field is the only control in the dialog
|
|
60
|
-
autoFocus
|
|
61
|
-
data-size={size}
|
|
62
|
-
label={getLocalizedString("Filter name")}
|
|
63
|
-
value={name}
|
|
64
|
-
error={
|
|
65
|
-
collides ? getLocalizedString("A filter with this name already exists and will be replaced.") : undefined
|
|
66
|
-
}
|
|
67
|
-
onChange={(event) => setName(event.currentTarget.value)}
|
|
68
|
-
/>
|
|
69
|
-
</Dialog.Block>
|
|
70
|
-
<Dialog.Block className="ObFilterNameDialog-actions">
|
|
71
|
-
<Button type="submit" data-size={size} disabled={!trimmed}>
|
|
72
|
-
{collides ? getLocalizedString("Replace") : getLocalizedString("Save")}
|
|
73
|
-
</Button>
|
|
74
|
-
<Button type="button" variant="secondary" data-size={size} onClick={onCancel}>
|
|
75
|
-
{getLocalizedString("Cancel")}
|
|
76
|
-
</Button>
|
|
77
|
-
</Dialog.Block>
|
|
78
|
-
</form>
|
|
79
|
-
</Dialog>
|
|
80
|
-
);
|
|
81
|
-
}
|
package/src/filter/FilterRow.tsx
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { Select } from "@digdir/designsystemet-react";
|
|
2
|
-
import { XMarkIcon } from "@navikt/aksel-icons";
|
|
3
|
-
import {
|
|
4
|
-
changeOperator,
|
|
5
|
-
createExpression,
|
|
6
|
-
type FieldMetadata,
|
|
7
|
-
type FilterExpression,
|
|
8
|
-
type FilterOperator,
|
|
9
|
-
getLocalizedString,
|
|
10
|
-
getOperatorLabel,
|
|
11
|
-
getOperatorsForField,
|
|
12
|
-
normalizeOperator,
|
|
13
|
-
} from "@olenbetong/appframe-core";
|
|
14
|
-
import { Combobox } from "@olenbetong/appframe-ds";
|
|
15
|
-
|
|
16
|
-
import { FilterValueEditor } from "./FilterValueEditor.js";
|
|
17
|
-
import type { FilterEditorSize, GetFieldOptions } from "./types.js";
|
|
18
|
-
|
|
19
|
-
export function getFieldLabel(field: FieldMetadata) {
|
|
20
|
-
return field.caption || field.name;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export type FilterRowProps = {
|
|
24
|
-
expression: FilterExpression;
|
|
25
|
-
fields: FieldMetadata[];
|
|
26
|
-
onChange: (expression: FilterExpression) => void;
|
|
27
|
-
onRemove: () => void;
|
|
28
|
-
getFieldOptions?: GetFieldOptions;
|
|
29
|
-
readOnly?: boolean;
|
|
30
|
-
"data-size"?: FilterEditorSize;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
/** A single `field operator value` row. */
|
|
34
|
-
export function FilterRow({
|
|
35
|
-
expression,
|
|
36
|
-
fields,
|
|
37
|
-
onChange,
|
|
38
|
-
onRemove,
|
|
39
|
-
getFieldOptions,
|
|
40
|
-
readOnly,
|
|
41
|
-
"data-size": size = "sm",
|
|
42
|
-
}: FilterRowProps) {
|
|
43
|
-
let field = fields.find((item) => item.name === expression.column);
|
|
44
|
-
let operator = normalizeOperator(expression.operator);
|
|
45
|
-
// A filter can reference a field that is no longer in the view. Keep the row
|
|
46
|
-
// editable by falling back to a string field rather than dropping it.
|
|
47
|
-
let effectiveField: FieldMetadata = field ?? { name: expression.column, type: "string" };
|
|
48
|
-
let operators = getOperatorsForField(effectiveField);
|
|
49
|
-
|
|
50
|
-
if (!operators.includes(operator)) {
|
|
51
|
-
operators = [...operators, operator];
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function handleFieldChange(next: FieldMetadata | null) {
|
|
55
|
-
if (!next) return;
|
|
56
|
-
|
|
57
|
-
// Keep the operator when the new field supports it, so switching between
|
|
58
|
-
// two fields of the same type does not reset the row.
|
|
59
|
-
let operators = getOperatorsForField(next);
|
|
60
|
-
let keep = operators.includes(operator) ? operator : undefined;
|
|
61
|
-
let created = createExpression(next, keep);
|
|
62
|
-
|
|
63
|
-
onChange(keep ? { ...created, value: expression.value, valueType: expression.valueType } : created);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return (
|
|
67
|
-
<div className="ObFilterEditor-row">
|
|
68
|
-
<Combobox
|
|
69
|
-
className="ObFilterEditor-field"
|
|
70
|
-
data-size={size}
|
|
71
|
-
readOnly={readOnly}
|
|
72
|
-
disableClearable
|
|
73
|
-
aria-label={getLocalizedString("Field")}
|
|
74
|
-
placeholder={getLocalizedString("Select field")}
|
|
75
|
-
options={fields}
|
|
76
|
-
getOptionLabel={getFieldLabel}
|
|
77
|
-
getOptionKey={(option) => option.name}
|
|
78
|
-
isOptionEqualToValue={(a, b) => a.name === b.name}
|
|
79
|
-
value={effectiveField}
|
|
80
|
-
onChange={(_event, next) => handleFieldChange(next)}
|
|
81
|
-
/>
|
|
82
|
-
<Select
|
|
83
|
-
className="ObFilterEditor-operator"
|
|
84
|
-
data-size={size}
|
|
85
|
-
disabled={readOnly}
|
|
86
|
-
aria-label={getLocalizedString("Operator")}
|
|
87
|
-
value={operator}
|
|
88
|
-
onChange={(event) => onChange(changeOperator(expression, event.target.value as FilterOperator, effectiveField))}
|
|
89
|
-
>
|
|
90
|
-
{operators.map((item) => (
|
|
91
|
-
<Select.Option key={item} value={item}>
|
|
92
|
-
{getOperatorLabel(item, effectiveField.type)}
|
|
93
|
-
</Select.Option>
|
|
94
|
-
))}
|
|
95
|
-
</Select>
|
|
96
|
-
<FilterValueEditor
|
|
97
|
-
expression={expression}
|
|
98
|
-
field={effectiveField}
|
|
99
|
-
options={field ? getFieldOptions?.(field) : undefined}
|
|
100
|
-
onChange={onChange}
|
|
101
|
-
readOnly={readOnly}
|
|
102
|
-
data-size={size}
|
|
103
|
-
/>
|
|
104
|
-
{!readOnly && (
|
|
105
|
-
<button
|
|
106
|
-
type="button"
|
|
107
|
-
className="ObFilterEditor-iconButton"
|
|
108
|
-
title={getLocalizedString("Remove condition")}
|
|
109
|
-
aria-label={getLocalizedString("Remove condition")}
|
|
110
|
-
onClick={onRemove}
|
|
111
|
-
>
|
|
112
|
-
<XMarkIcon aria-hidden />
|
|
113
|
-
</button>
|
|
114
|
-
)}
|
|
115
|
-
</div>
|
|
116
|
-
);
|
|
117
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Colours use the contextual `--ds-color-*` aliases so the dialog follows the
|
|
3
|
-
* active colour scheme. Never add hex fallbacks.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
.ObFilterShareDialog-root {
|
|
7
|
-
inline-size: min(40rem, 100%);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
.ObFilterShareDialog-candidate {
|
|
11
|
-
display: flex;
|
|
12
|
-
align-items: center;
|
|
13
|
-
gap: var(--ds-size-2);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
.ObFilterShareDialog-candidateLogin {
|
|
17
|
-
margin-inline-start: auto;
|
|
18
|
-
color: var(--ds-color-text-subtle);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
.ObFilterShareDialog-table {
|
|
22
|
-
inline-size: 100%;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
.ObFilterShareDialog-error {
|
|
26
|
-
margin: 0 0 var(--ds-size-2);
|
|
27
|
-
color: var(--ds-color-danger-text-default);
|
|
28
|
-
}
|
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
import { Button, Dialog, Heading, Select, Table } from "@digdir/designsystemet-react";
|
|
2
|
-
import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
3
|
-
import { type FilterPermission, useDebounce, useFilterPermissions } from "@olenbetong/appframe-react";
|
|
4
|
-
import { Combobox } from "@olenbetong/appframe-ds";
|
|
5
|
-
import { PersonGroupIcon, PersonIcon, TrashIcon } from "@navikt/aksel-icons";
|
|
6
|
-
import { useEffect, useState } from "react";
|
|
7
|
-
|
|
8
|
-
import "./FilterShareDialog.css";
|
|
9
|
-
|
|
10
|
-
type PermissionCandidate = {
|
|
11
|
-
primKey: string;
|
|
12
|
-
name: string;
|
|
13
|
-
login: string;
|
|
14
|
-
type: string;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export type FilterShareDialogProps = {
|
|
18
|
-
open: boolean;
|
|
19
|
-
onClose: () => void;
|
|
20
|
-
/** `FilterID` of the filter to manage sharing for. */
|
|
21
|
-
filterId: number | null;
|
|
22
|
-
/** Shown in the dialog heading. */
|
|
23
|
-
filterName?: string;
|
|
24
|
-
"data-size"?: "sm" | "md" | "lg";
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Manages who a saved filter is shared with.
|
|
29
|
-
*
|
|
30
|
-
* Only a manager of the filter can load or change the grants — for anyone else
|
|
31
|
-
* `sstp_WebSiteCMS_FilterBuilder_GetPermissions` returns nothing, so the list
|
|
32
|
-
* simply stays empty.
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* ```jsx
|
|
36
|
-
* <FilterShareDialog open={sharing} filterId={selected} filterName={name} onClose={() => setSharing(false)} />
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
export function FilterShareDialog({
|
|
40
|
-
open,
|
|
41
|
-
onClose,
|
|
42
|
-
filterId,
|
|
43
|
-
filterName,
|
|
44
|
-
"data-size": size = "sm",
|
|
45
|
-
}: FilterShareDialogProps) {
|
|
46
|
-
let { permissions, loading, error, setPermission, removePermission, search } = useFilterPermissions(
|
|
47
|
-
open ? filterId : null,
|
|
48
|
-
);
|
|
49
|
-
let [candidates, setCandidates] = useState<PermissionCandidate[]>([]);
|
|
50
|
-
let [searchText, setSearchText] = useState("");
|
|
51
|
-
let query = useDebounce(searchText, 300);
|
|
52
|
-
|
|
53
|
-
useEffect(() => {
|
|
54
|
-
if (!open || query.length < 2) {
|
|
55
|
-
setCandidates([]);
|
|
56
|
-
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
let isCancelled = false;
|
|
61
|
-
search(query)
|
|
62
|
-
.then((results) => {
|
|
63
|
-
if (isCancelled) return;
|
|
64
|
-
// Anyone who already has a grant is not a candidate for a new one.
|
|
65
|
-
let granted = new Set(permissions.map((permission) => permission.groupRef));
|
|
66
|
-
setCandidates(results.filter((result) => !granted.has(result.primKey)));
|
|
67
|
-
})
|
|
68
|
-
.catch(() => {
|
|
69
|
-
if (!isCancelled) setCandidates([]);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
return () => {
|
|
73
|
-
isCancelled = true;
|
|
74
|
-
};
|
|
75
|
-
}, [open, query, search, permissions]);
|
|
76
|
-
|
|
77
|
-
function handleAdd(candidate: PermissionCandidate | null) {
|
|
78
|
-
if (!candidate) return;
|
|
79
|
-
|
|
80
|
-
setSearchText("");
|
|
81
|
-
void setPermission(candidate.primKey, "Reader");
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return (
|
|
85
|
-
<Dialog open={open} closedby="any" data-size={size} onClose={onClose} className="ObFilterShareDialog-root">
|
|
86
|
-
<Dialog.Block>
|
|
87
|
-
<Heading level={2} data-size="xs">
|
|
88
|
-
{filterName ? getLocalizedString("Sharing - {0}").replace("{0}", filterName) : getLocalizedString("Sharing")}
|
|
89
|
-
</Heading>
|
|
90
|
-
</Dialog.Block>
|
|
91
|
-
<Dialog.Block>
|
|
92
|
-
<Combobox<PermissionCandidate>
|
|
93
|
-
options={candidates}
|
|
94
|
-
value={null}
|
|
95
|
-
inputValue={searchText}
|
|
96
|
-
loading={loading}
|
|
97
|
-
data-size={size}
|
|
98
|
-
label={getLocalizedString("Add user or group")}
|
|
99
|
-
placeholder={getLocalizedString("Search...")}
|
|
100
|
-
getOptionLabel={(option) => option.name}
|
|
101
|
-
getOptionKey={(option) => option.primKey}
|
|
102
|
-
// The procedure searches both name and login, so filtering again on
|
|
103
|
-
// the label would drop everything matched by login.
|
|
104
|
-
filterOptions={(options) => [...options]}
|
|
105
|
-
noOptionsText={query.length < 2 ? getLocalizedString("Type to search") : getLocalizedString("No matches")}
|
|
106
|
-
renderOption={(option) => (
|
|
107
|
-
<span className="ObFilterShareDialog-candidate">
|
|
108
|
-
{option.type === "User" ? <PersonIcon aria-hidden /> : <PersonGroupIcon aria-hidden />}
|
|
109
|
-
<span>{option.name}</span>
|
|
110
|
-
<span className="ObFilterShareDialog-candidateLogin">{option.login}</span>
|
|
111
|
-
</span>
|
|
112
|
-
)}
|
|
113
|
-
// The picker never keeps a selection; picking an option adds a grant.
|
|
114
|
-
onInputChange={(_event, value) => setSearchText(value)}
|
|
115
|
-
onChange={(_event, value) => handleAdd(value)}
|
|
116
|
-
/>
|
|
117
|
-
</Dialog.Block>
|
|
118
|
-
<Dialog.Block>
|
|
119
|
-
{error && <p className="ObFilterShareDialog-error">{String(error.message ?? error)}</p>}
|
|
120
|
-
<Table data-size={size} className="ObFilterShareDialog-table">
|
|
121
|
-
<Table.Head>
|
|
122
|
-
<Table.Row>
|
|
123
|
-
<Table.HeaderCell>{getLocalizedString("Name")}</Table.HeaderCell>
|
|
124
|
-
<Table.HeaderCell>{getLocalizedString("Login")}</Table.HeaderCell>
|
|
125
|
-
<Table.HeaderCell>{getLocalizedString("Access")}</Table.HeaderCell>
|
|
126
|
-
<Table.HeaderCell />
|
|
127
|
-
</Table.Row>
|
|
128
|
-
</Table.Head>
|
|
129
|
-
<Table.Body>
|
|
130
|
-
{permissions.length === 0 && (
|
|
131
|
-
<Table.Row>
|
|
132
|
-
<Table.Cell colSpan={4}>
|
|
133
|
-
{loading ? getLocalizedString("Loading...") : getLocalizedString("Not shared with anyone")}
|
|
134
|
-
</Table.Cell>
|
|
135
|
-
</Table.Row>
|
|
136
|
-
)}
|
|
137
|
-
{permissions.map((permission) => (
|
|
138
|
-
<PermissionRow
|
|
139
|
-
key={permission.primKey}
|
|
140
|
-
permission={permission}
|
|
141
|
-
size={size}
|
|
142
|
-
onChangeAccess={(accessLevel) => void setPermission(permission.groupRef, accessLevel)}
|
|
143
|
-
onRemove={() => void removePermission(permission.groupRef)}
|
|
144
|
-
/>
|
|
145
|
-
))}
|
|
146
|
-
</Table.Body>
|
|
147
|
-
</Table>
|
|
148
|
-
</Dialog.Block>
|
|
149
|
-
<Dialog.Block>
|
|
150
|
-
<Button type="button" variant="secondary" data-size={size} onClick={onClose}>
|
|
151
|
-
{getLocalizedString("Close")}
|
|
152
|
-
</Button>
|
|
153
|
-
</Dialog.Block>
|
|
154
|
-
</Dialog>
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
type PermissionRowProps = {
|
|
159
|
-
permission: FilterPermission;
|
|
160
|
-
size: "sm" | "md" | "lg";
|
|
161
|
-
onChangeAccess: (accessLevel: "Reader" | "Manager") => void;
|
|
162
|
-
onRemove: () => void;
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
function PermissionRow({ permission, size, onChangeAccess, onRemove }: PermissionRowProps) {
|
|
166
|
-
return (
|
|
167
|
-
<Table.Row>
|
|
168
|
-
<Table.Cell>
|
|
169
|
-
<span className="ObFilterShareDialog-candidate">
|
|
170
|
-
{permission.type === "User" ? <PersonIcon aria-hidden /> : <PersonGroupIcon aria-hidden />}
|
|
171
|
-
{permission.name}
|
|
172
|
-
</span>
|
|
173
|
-
</Table.Cell>
|
|
174
|
-
<Table.Cell>{permission.login}</Table.Cell>
|
|
175
|
-
<Table.Cell>
|
|
176
|
-
<Select
|
|
177
|
-
data-size={size}
|
|
178
|
-
value={permission.accessLevel}
|
|
179
|
-
aria-label={getLocalizedString("Access for {0}").replace("{0}", permission.name)}
|
|
180
|
-
onChange={(event) => onChangeAccess(event.currentTarget.value as "Reader" | "Manager")}
|
|
181
|
-
>
|
|
182
|
-
<Select.Option value="Reader">{getLocalizedString("Reader")}</Select.Option>
|
|
183
|
-
<Select.Option value="Manager">{getLocalizedString("Manager")}</Select.Option>
|
|
184
|
-
</Select>
|
|
185
|
-
</Table.Cell>
|
|
186
|
-
<Table.Cell>
|
|
187
|
-
<Button
|
|
188
|
-
type="button"
|
|
189
|
-
variant="tertiary"
|
|
190
|
-
data-color="danger"
|
|
191
|
-
data-size={size}
|
|
192
|
-
icon
|
|
193
|
-
aria-label={getLocalizedString("Remove access for {0}").replace("{0}", permission.name)}
|
|
194
|
-
onClick={onRemove}
|
|
195
|
-
>
|
|
196
|
-
<TrashIcon aria-hidden />
|
|
197
|
-
</Button>
|
|
198
|
-
</Table.Cell>
|
|
199
|
-
</Table.Row>
|
|
200
|
-
);
|
|
201
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { Textfield, ValidationMessage } from "@digdir/designsystemet-react";
|
|
2
|
-
import { type FilterTree, getLocalizedString, toFilterTree } from "@olenbetong/appframe-core";
|
|
3
|
-
import { useFilterConversion } from "@olenbetong/appframe-react";
|
|
4
|
-
import { useEffect, useState } from "react";
|
|
5
|
-
|
|
6
|
-
import type { FilterEditorSize } from "./types.js";
|
|
7
|
-
|
|
8
|
-
export type FilterStringFieldProps = {
|
|
9
|
-
filter: FilterTree;
|
|
10
|
-
onChange: (filter: FilterTree) => void;
|
|
11
|
-
viewName?: string;
|
|
12
|
-
readOnly?: boolean;
|
|
13
|
-
"data-size"?: FilterEditorSize;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Two-way filter string editor. The tree is the source of truth: it is
|
|
18
|
-
* converted to a string whenever it changes. Editing the string and leaving the
|
|
19
|
-
* field parses it back into a tree.
|
|
20
|
-
*/
|
|
21
|
-
export function FilterStringField({
|
|
22
|
-
filter,
|
|
23
|
-
onChange,
|
|
24
|
-
viewName,
|
|
25
|
-
readOnly,
|
|
26
|
-
"data-size": size = "sm",
|
|
27
|
-
}: FilterStringFieldProps) {
|
|
28
|
-
let { filterString, isConverting, error, warning, parseFilterString } = useFilterConversion(filter, { viewName });
|
|
29
|
-
let [draft, setDraft] = useState<string | null>(null);
|
|
30
|
-
let [parseError, setParseError] = useState<string | null>(null);
|
|
31
|
-
|
|
32
|
-
// The tree changed underneath us, so any half-typed string is stale.
|
|
33
|
-
useEffect(() => {
|
|
34
|
-
setDraft(null);
|
|
35
|
-
setParseError(null);
|
|
36
|
-
}, [filter]);
|
|
37
|
-
|
|
38
|
-
async function commit() {
|
|
39
|
-
if (draft === null || draft === filterString) {
|
|
40
|
-
setDraft(null);
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
let parsed = await parseFilterString(draft);
|
|
45
|
-
|
|
46
|
-
if (parsed) {
|
|
47
|
-
setDraft(null);
|
|
48
|
-
setParseError(null);
|
|
49
|
-
onChange(toFilterTree(parsed));
|
|
50
|
-
} else {
|
|
51
|
-
setParseError(getLocalizedString("The filter could not be parsed"));
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
let message = parseError ?? error?.message ?? warning;
|
|
56
|
-
|
|
57
|
-
return (
|
|
58
|
-
<div className="ObFilterEditor-filterString">
|
|
59
|
-
<Textfield
|
|
60
|
-
multiline
|
|
61
|
-
rows={3}
|
|
62
|
-
data-size={size}
|
|
63
|
-
readOnly={readOnly}
|
|
64
|
-
label={
|
|
65
|
-
<span className="ObFilterEditor-filterStringLabel">
|
|
66
|
-
{getLocalizedString("Filter string")}
|
|
67
|
-
{isConverting && <span className="ObFilterEditor-hint">{getLocalizedString("Converting…")}</span>}
|
|
68
|
-
</span>
|
|
69
|
-
}
|
|
70
|
-
value={draft ?? filterString}
|
|
71
|
-
onChange={(event) => setDraft(event.target.value)}
|
|
72
|
-
onBlur={commit}
|
|
73
|
-
/>
|
|
74
|
-
{message && <ValidationMessage data-color={parseError ? "danger" : "warning"}>{message}</ValidationMessage>}
|
|
75
|
-
</div>
|
|
76
|
-
);
|
|
77
|
-
}
|