@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.
Files changed (63) hide show
  1. package/es/filter/index.d.ts +8 -11
  2. package/es/filter/index.js +8 -10
  3. package/es/report/ReportLauncher.d.ts +1 -1
  4. package/es/report/ReportLauncher.js +1 -1
  5. package/es/report/ReportParameters.d.ts +1 -1
  6. package/package.json +6 -6
  7. package/src/components/ImageEditor/ImageEditor.css +5 -5
  8. package/src/components/ImageEditor/ImageEditor.tsx +1 -1
  9. package/src/filter/index.ts +34 -11
  10. package/src/report/ReportLauncher.tsx +1 -2
  11. package/src/report/ReportParameters.tsx +1 -1
  12. package/es/filter/ChipListInput.d.ts +0 -13
  13. package/es/filter/ChipListInput.js +0 -34
  14. package/es/filter/FilterBuilder.css +0 -152
  15. package/es/filter/FilterBuilder.d.ts +0 -115
  16. package/es/filter/FilterBuilder.js +0 -146
  17. package/es/filter/FilterBuilder.test.d.ts +0 -1
  18. package/es/filter/FilterBuilder.test.js +0 -120
  19. package/es/filter/FilterEditor.css +0 -231
  20. package/es/filter/FilterEditor.d.ts +0 -17
  21. package/es/filter/FilterEditor.js +0 -38
  22. package/es/filter/FilterEditor.test.d.ts +0 -1
  23. package/es/filter/FilterEditor.test.js +0 -183
  24. package/es/filter/FilterGroupEditor.d.ts +0 -22
  25. package/es/filter/FilterGroupEditor.js +0 -34
  26. package/es/filter/FilterNameDialog.css +0 -22
  27. package/es/filter/FilterNameDialog.d.ts +0 -18
  28. package/es/filter/FilterNameDialog.js +0 -32
  29. package/es/filter/FilterRow.d.ts +0 -14
  30. package/es/filter/FilterRow.js +0 -32
  31. package/es/filter/FilterShareDialog.css +0 -28
  32. package/es/filter/FilterShareDialog.d.ts +0 -23
  33. package/es/filter/FilterShareDialog.js +0 -63
  34. package/es/filter/FilterStringField.d.ts +0 -15
  35. package/es/filter/FilterStringField.js +0 -37
  36. package/es/filter/FilterValueEditor.d.ts +0 -16
  37. package/es/filter/FilterValueEditor.js +0 -85
  38. package/es/filter/SavedFilterTree.css +0 -107
  39. package/es/filter/SavedFilterTree.d.ts +0 -45
  40. package/es/filter/SavedFilterTree.js +0 -44
  41. package/es/filter/SavedFilterTree.test.d.ts +0 -1
  42. package/es/filter/SavedFilterTree.test.js +0 -75
  43. package/es/filter/types.d.ts +0 -34
  44. package/es/filter/types.js +0 -1
  45. package/src/filter/ChipListInput.tsx +0 -79
  46. package/src/filter/FilterBuilder.css +0 -152
  47. package/src/filter/FilterBuilder.test.tsx +0 -153
  48. package/src/filter/FilterBuilder.tsx +0 -435
  49. package/src/filter/FilterEditor.css +0 -231
  50. package/src/filter/FilterEditor.test.tsx +0 -259
  51. package/src/filter/FilterEditor.tsx +0 -74
  52. package/src/filter/FilterGroupEditor.tsx +0 -160
  53. package/src/filter/FilterNameDialog.css +0 -22
  54. package/src/filter/FilterNameDialog.tsx +0 -81
  55. package/src/filter/FilterRow.tsx +0 -117
  56. package/src/filter/FilterShareDialog.css +0 -28
  57. package/src/filter/FilterShareDialog.tsx +0 -201
  58. package/src/filter/FilterStringField.tsx +0 -77
  59. package/src/filter/FilterValueEditor.tsx +0 -220
  60. package/src/filter/SavedFilterTree.css +0 -107
  61. package/src/filter/SavedFilterTree.test.tsx +0 -94
  62. package/src/filter/SavedFilterTree.tsx +0 -222
  63. package/src/filter/types.ts +0 -38
@@ -1,183 +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 { FilterEditor } from "./FilterEditor.js";
6
- const FIELDS = [
7
- { name: "PersonID", caption: "Person ID", type: "string", nullable: true },
8
- { name: "Age", caption: "Age", type: "number" },
9
- { name: "Created", caption: "Created", type: "datetime" },
10
- { name: "IsActive", caption: "Is active", type: "boolean" },
11
- { name: "Secret", caption: "Secret", type: "string", excludeFromFilter: true },
12
- ];
13
- /** A tree with a single root `and` group holding one expression. */
14
- function filterWith(column, operator, value, valueType = "string") {
15
- return {
16
- type: "group",
17
- mode: "and",
18
- items: [{ type: "expression", column, operator, value, valueType }],
19
- };
20
- }
21
- function firstExpression(onChange, call = 0) {
22
- let [filter] = onChange.mock.calls[call];
23
- return filter.items[0];
24
- }
25
- describe("FilterEditor", () => {
26
- it("renders one row per expression", () => {
27
- render(_jsx(FilterEditor, { fields: FIELDS, value: filterWith("PersonID", "beginswith", "silv") }));
28
- expect(screen.getAllByLabelText("Field")).toHaveLength(1);
29
- expect(screen.getByLabelText("Operator")).toHaveValue("beginswith");
30
- expect(screen.getByLabelText("Value")).toHaveValue("silv");
31
- });
32
- it("wraps a bare expression in a group", () => {
33
- let filter = {
34
- type: "expression",
35
- column: "Age",
36
- operator: "equals",
37
- value: "42",
38
- valueType: "number",
39
- };
40
- render(_jsx(FilterEditor, { fields: FIELDS, value: filter }));
41
- expect(screen.getByLabelText("Value")).toHaveValue(42);
42
- });
43
- it("hides fields marked as excluded from the field picker", async () => {
44
- let user = userEvent.setup();
45
- render(_jsx(FilterEditor, { fields: FIELDS, value: { type: "group", mode: "and", items: [] } }));
46
- await user.click(screen.getByLabelText("Add condition"));
47
- expect(screen.queryByRole("option", { name: "Secret" })).not.toBeInTheDocument();
48
- expect(screen.getByRole("option", { name: "Person ID" })).toBeInTheDocument();
49
- });
50
- it("adds an expression when a field is picked in the blank row", async () => {
51
- let user = userEvent.setup();
52
- let onChange = vi.fn();
53
- render(_jsx(FilterEditor, { fields: FIELDS, value: filterWith("PersonID", "beginswith", "silv"), onChange: onChange }));
54
- await user.click(screen.getByLabelText("Add condition"));
55
- await user.click(screen.getByRole("option", { name: "Age" }));
56
- expect(onChange).toHaveBeenCalledTimes(1);
57
- let [filter] = onChange.mock.calls[0];
58
- expect(filter.items).toHaveLength(2);
59
- // Numbers default to "equals", strings to "begins with".
60
- expect(filter.items[1]).toMatchObject({ column: "Age", operator: "equals", valueType: "number" });
61
- });
62
- it("changes the operator and resets the value when the arity changes", async () => {
63
- let user = userEvent.setup();
64
- let onChange = vi.fn();
65
- render(_jsx(FilterEditor, { fields: FIELDS, value: filterWith("Age", "equals", "42", "number"), onChange: onChange }));
66
- await user.selectOptions(screen.getByLabelText("Operator"), "between");
67
- expect(firstExpression(onChange)).toMatchObject({ operator: "between", value: ["", ""] });
68
- });
69
- it("renders no value editor for parameterless operators", () => {
70
- render(_jsx(FilterEditor, { fields: FIELDS, value: filterWith("IsActive", "istrue", null, "null") }));
71
- expect(screen.queryByLabelText("Value")).not.toBeInTheDocument();
72
- });
73
- it("renders two inputs for range operators", () => {
74
- render(_jsx(FilterEditor, { fields: FIELDS, value: filterWith("Age", "between", ["1", "10"], "number") }));
75
- expect(screen.getByLabelText("From")).toHaveValue(1);
76
- expect(screen.getByLabelText("To")).toHaveValue(10);
77
- });
78
- it("renders one chip per value for list operators", () => {
79
- render(_jsx(FilterEditor, { fields: FIELDS, value: filterWith("PersonID", "inlist", ["a", "b"]) }));
80
- expect(screen.getByRole("button", { name: "Remove a" })).toBeInTheDocument();
81
- expect(screen.getByRole("button", { name: "Remove b" })).toBeInTheDocument();
82
- });
83
- it("adds a list value on Enter", async () => {
84
- let user = userEvent.setup();
85
- let onChange = vi.fn();
86
- render(_jsx(FilterEditor, { fields: FIELDS, value: filterWith("PersonID", "inlist", ["a"]), onChange: onChange }));
87
- await user.type(screen.getByLabelText("Value"), "b{Enter}");
88
- let [filter] = onChange.mock.calls.at(-1);
89
- expect(filter.items[0].value).toEqual(["a", "b"]);
90
- });
91
- it("switches a date value to a relative value", async () => {
92
- let user = userEvent.setup();
93
- let onChange = vi.fn();
94
- render(_jsx(FilterEditor, { fields: FIELDS, value: filterWith("Created", "equals", "", "datetime"), onChange: onChange }));
95
- await user.click(screen.getByRole("button", { name: "Use a relative value" }));
96
- expect(firstExpression(onChange)).toMatchObject({ value: "Yesterday", valueType: "special" });
97
- });
98
- it("does not offer relative values for numbers", () => {
99
- render(_jsx(FilterEditor, { fields: FIELDS, value: filterWith("Age", "equals", "1", "number") }));
100
- expect(screen.queryByRole("button", { name: "Use a relative value" })).not.toBeInTheDocument();
101
- });
102
- it("removes a condition", async () => {
103
- let user = userEvent.setup();
104
- let onChange = vi.fn();
105
- render(_jsx(FilterEditor, { fields: FIELDS, value: filterWith("PersonID", "beginswith", "silv"), onChange: onChange }));
106
- await user.click(screen.getByRole("button", { name: "Remove condition" }));
107
- let [filter] = onChange.mock.calls[0];
108
- expect(filter.items).toHaveLength(0);
109
- });
110
- it("hides every editing affordance when read only", () => {
111
- render(_jsx(FilterEditor, { fields: FIELDS, value: filterWith("PersonID", "beginswith", "silv"), readOnly: true }));
112
- expect(screen.queryByLabelText("Add condition")).not.toBeInTheDocument();
113
- expect(screen.queryByRole("button", { name: "Remove condition" })).not.toBeInTheDocument();
114
- expect(screen.queryByRole("button", { name: "Add group" })).not.toBeInTheDocument();
115
- expect(screen.getByLabelText("Group operator")).toBeDisabled();
116
- });
117
- it("keeps a row editable when the field is not in the view", () => {
118
- render(_jsx(FilterEditor, { fields: FIELDS, value: filterWith("Removed", "equals", "x") }));
119
- expect(screen.getByLabelText("Field")).toHaveValue("Removed");
120
- });
121
- it("uses supplied options as a value list", () => {
122
- render(_jsx(FilterEditor, { fields: FIELDS, value: filterWith("PersonID", "equals", "a"), getFieldOptions: (field) => field.name === "PersonID"
123
- ? [
124
- { value: "a", label: "Alpha" },
125
- { value: "b", label: "Bravo" },
126
- ]
127
- : undefined }));
128
- expect(screen.getByLabelText("Value")).toHaveValue("Alpha");
129
- });
130
- it("changes the mode of the root group", async () => {
131
- let user = userEvent.setup();
132
- let onChange = vi.fn();
133
- render(_jsx(FilterEditor, { fields: FIELDS, value: filterWith("PersonID", "beginswith", "silv"), onChange: onChange }));
134
- expect(screen.getByLabelText("Group operator")).toHaveValue("and");
135
- await user.selectOptions(screen.getByLabelText("Group operator"), "or");
136
- let [filter] = onChange.mock.calls[0];
137
- expect(filter.mode).toBe("or");
138
- });
139
- it("adds and removes nested groups", async () => {
140
- let user = userEvent.setup();
141
- let onChange = vi.fn();
142
- let { rerender } = render(_jsx(FilterEditor, { fields: FIELDS, value: filterWith("PersonID", "beginswith", "silv"), onChange: onChange }));
143
- expect(screen.queryByRole("button", { name: "Remove group" })).not.toBeInTheDocument();
144
- await user.click(screen.getByRole("button", { name: "Add group" }));
145
- let [withGroup] = onChange.mock.calls[0];
146
- expect(withGroup.items).toHaveLength(2);
147
- // A nested group defaults to the opposite mode of its parent.
148
- expect(withGroup.items[1]).toMatchObject({ type: "group", mode: "or", items: [] });
149
- rerender(_jsx(FilterEditor, { fields: FIELDS, value: withGroup, onChange: onChange }));
150
- expect(screen.getAllByLabelText("Group operator")).toHaveLength(2);
151
- await user.click(screen.getByRole("button", { name: "Remove group" }));
152
- let [removed] = onChange.mock.calls[1];
153
- expect(removed.items).toHaveLength(1);
154
- });
155
- it("edits a condition inside a nested group", async () => {
156
- let user = userEvent.setup();
157
- let onChange = vi.fn();
158
- let filter = {
159
- type: "group",
160
- mode: "and",
161
- items: [
162
- { type: "expression", column: "Age", operator: "equals", value: "1", valueType: "number" },
163
- {
164
- type: "group",
165
- mode: "or",
166
- items: [{ type: "expression", column: "PersonID", operator: "beginswith", value: "a", valueType: "string" }],
167
- },
168
- ],
169
- };
170
- render(_jsx(FilterEditor, { fields: FIELDS, value: filter, onChange: onChange }));
171
- await user.click(screen.getAllByRole("button", { name: "Remove condition" })[1]);
172
- let [next] = onChange.mock.calls[0];
173
- expect(next.items[0]).toMatchObject({ column: "Age" });
174
- expect(next.items[1]).toMatchObject({ type: "group", items: [] });
175
- });
176
- it("keeps its own state when uncontrolled", async () => {
177
- let user = userEvent.setup();
178
- render(_jsx(FilterEditor, { fields: FIELDS, defaultValue: filterWith("PersonID", "beginswith", "silv") }));
179
- await user.clear(screen.getByLabelText("Value"));
180
- await user.type(screen.getByLabelText("Value"), "gold");
181
- expect(screen.getByLabelText("Value")).toHaveValue("gold");
182
- });
183
- });
@@ -1,22 +0,0 @@
1
- import { type FieldMetadata, type FilterPath, type FilterTree } from "@olenbetong/appframe-core";
2
- import type { FilterEditorSize, GetFieldOptions } from "./types.js";
3
- export type FilterGroupEditorProps = {
4
- /** The whole tree. Groups edit it through their own `path`. */
5
- filter: FilterTree;
6
- /** Path to the group this editor renders. The root group is the empty path. */
7
- path: FilterPath;
8
- fields: FieldMetadata[];
9
- onChange: (filter: FilterTree) => void;
10
- getFieldOptions?: GetFieldOptions;
11
- readOnly?: boolean;
12
- "data-size"?: FilterEditorSize;
13
- };
14
- /**
15
- * One group of the filter tree. Groups can be nested and each one combines its
16
- * items with either `and` or `or`, matching the advanced (DevExpress) filter
17
- * editor in the Windows client.
18
- *
19
- * A blank row is always rendered at the end; picking a field in it appends a
20
- * real condition to the group.
21
- */
22
- export declare function FilterGroupEditor({ filter, path, fields, onChange, getFieldOptions, readOnly, "data-size": size, }: FilterGroupEditorProps): import("react").JSX.Element | null;
@@ -1,34 +0,0 @@
1
- import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Button, Select } from "@digdir/designsystemet-react";
3
- import { FolderPlusIcon, TrashIcon } from "@navikt/aksel-icons";
4
- import { addGroupAtPath, createExpression, getLocalizedString, getNodeAtPath, insertNodeAtPath, isExpression, isGroup, removeNodeAtPath, setGroupMode, updateNodeAtPath, } from "@olenbetong/appframe-core";
5
- import { Combobox } from "@olenbetong/appframe-ds";
6
- import { FilterRow, getFieldLabel } from "./FilterRow.js";
7
- /**
8
- * One group of the filter tree. Groups can be nested and each one combines its
9
- * items with either `and` or `or`, matching the advanced (DevExpress) filter
10
- * editor in the Windows client.
11
- *
12
- * A blank row is always rendered at the end; picking a field in it appends a
13
- * real condition to the group.
14
- */
15
- export function FilterGroupEditor({ filter, path, fields, onChange, getFieldOptions, readOnly, "data-size": size = "sm", }) {
16
- let node = getNodeAtPath(filter, path);
17
- if (!node || !isGroup(node))
18
- return null;
19
- let group = node;
20
- let isRoot = path.length === 0;
21
- return (_jsxs("div", { className: "ObFilterEditor-group", "data-root": isRoot ? "" : undefined, children: [_jsxs("div", { className: "ObFilterEditor-groupHeader", children: [_jsxs(Select, { className: "ObFilterEditor-groupMode", "data-size": size, disabled: readOnly, "aria-label": getLocalizedString("Group operator"), value: group.mode, onChange: (event) => onChange(setGroupMode(filter, path, event.target.value)), children: [_jsx(Select.Option, { value: "and", children: getLocalizedString("And") }), _jsx(Select.Option, { value: "or", children: getLocalizedString("Or") })] }), !readOnly && (_jsxs(_Fragment, { children: [_jsxs(Button, { type: "button", variant: "tertiary", "data-size": size, className: "ObFilterEditor-groupButton", "aria-label": getLocalizedString("Add group"), onClick: () => onChange(addGroupAtPath(filter, path)), children: [_jsx(FolderPlusIcon, { "aria-hidden": true }), _jsx("span", { className: "ObFilterEditor-groupButtonLabel", children: getLocalizedString("Add group") })] }), !isRoot && (_jsxs(Button, { type: "button", variant: "tertiary", "data-color": "danger", "data-size": size, className: "ObFilterEditor-groupButton", "aria-label": getLocalizedString("Remove group"), onClick: () => onChange(removeNodeAtPath(filter, path)), children: [_jsx(TrashIcon, { "aria-hidden": true }), _jsx("span", { className: "ObFilterEditor-groupButtonLabel", children: getLocalizedString("Remove group") })] }))] }))] }), _jsxs("div", { className: "ObFilterEditor-groupItems", children: [group.items.map((item, index) => isExpression(item) ? (_jsx(FilterRow
22
- // Rows have no stable identity, and reordering is not supported,
23
- // so the index is the only key available.
24
- // oxlint-disable-next-line no-array-index-key -- see above
25
- , { expression: item, fields: fields, getFieldOptions: getFieldOptions, readOnly: readOnly, "data-size": size, onChange: (next) => onChange(replaceNode(filter, [...path, index], next)), onRemove: () => onChange(removeNodeAtPath(filter, [...path, index])) }, index)) : (_jsx(FilterGroupEditor
26
- // oxlint-disable-next-line no-array-index-key -- see above
27
- , { filter: filter, path: [...path, index], fields: fields, getFieldOptions: getFieldOptions, readOnly: readOnly, "data-size": size, onChange: onChange }, index))), !readOnly && (_jsx("div", { className: "ObFilterEditor-row ObFilterEditor-draftRow", children: _jsx(Combobox, { className: "ObFilterEditor-field", "data-size": size, "aria-label": getLocalizedString("Add condition"), placeholder: getLocalizedString("Add condition"), options: fields, getOptionLabel: getFieldLabel, getOptionKey: (option) => option.name, isOptionEqualToValue: (a, b) => a.name === b.name, value: null, onChange: (_event, field) => {
28
- if (field)
29
- onChange(insertNodeAtPath(filter, path, createExpression(field)));
30
- } }) }))] })] }));
31
- }
32
- function replaceNode(filter, path, node) {
33
- return updateNodeAtPath(filter, path, () => node);
34
- }
@@ -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,18 +0,0 @@
1
- import "./FilterNameDialog.css";
2
- export type FilterNameDialogProps = {
3
- open: boolean;
4
- /** Pre-fills the field, e.g. with the current filter's name. */
5
- defaultName?: string;
6
- /** Names already in use; entering one asks the user to confirm the overwrite. */
7
- existingNames?: string[];
8
- onCancel: () => void;
9
- onSubmit: (name: string) => void;
10
- "data-size"?: "sm" | "md" | "lg";
11
- };
12
- /**
13
- * Asks for the name to save a filter under.
14
- *
15
- * Reusing an existing name overwrites that filter, so the dialog warns before
16
- * submitting rather than silently creating a second filter with the same name.
17
- */
18
- export declare function FilterNameDialog({ open, defaultName, existingNames, onCancel, onSubmit, "data-size": size, }: FilterNameDialogProps): import("react").JSX.Element;
@@ -1,32 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import "./FilterNameDialog.css";
3
- import { Button, Dialog, Heading, Textfield } from "@digdir/designsystemet-react";
4
- import { getLocalizedString } from "@olenbetong/appframe-core";
5
- import { useEffect, useState } from "react";
6
- /**
7
- * Asks for the name to save a filter under.
8
- *
9
- * Reusing an existing name overwrites that filter, so the dialog warns before
10
- * submitting rather than silently creating a second filter with the same name.
11
- */
12
- export function FilterNameDialog({ open, defaultName = "", existingNames = [], onCancel, onSubmit, "data-size": size = "sm", }) {
13
- let [name, setName] = useState(defaultName);
14
- useEffect(() => {
15
- if (open)
16
- setName(defaultName);
17
- }, [open, defaultName]);
18
- let trimmed = name.trim();
19
- // A filter keeping its own name is an update, not a collision.
20
- let collides = trimmed !== defaultName && existingNames.some((existing) => existing === trimmed);
21
- function handleSubmit(event) {
22
- event.preventDefault();
23
- if (!trimmed)
24
- return;
25
- onSubmit(trimmed);
26
- }
27
- return (_jsx(Dialog, { open: open, closedby: "any", "data-size": size, className: "ObFilterNameDialog-root", onClose: onCancel, children: _jsxs("form", { onSubmit: handleSubmit, children: [_jsx(Dialog.Block, { children: _jsx(Heading, { level: 2, "data-size": "xs", children: getLocalizedString("Save filter") }) }), _jsx(Dialog.Block, { children: _jsx(Textfield
28
- // oxlint-disable-next-line jsx-a11y/no-autofocus -- the field is the only control in the dialog
29
- , {
30
- // oxlint-disable-next-line jsx-a11y/no-autofocus -- the field is the only control in the dialog
31
- autoFocus: true, "data-size": size, label: getLocalizedString("Filter name"), value: name, error: collides ? getLocalizedString("A filter with this name already exists and will be replaced.") : undefined, onChange: (event) => setName(event.currentTarget.value) }) }), _jsxs(Dialog.Block, { className: "ObFilterNameDialog-actions", children: [_jsx(Button, { type: "submit", "data-size": size, disabled: !trimmed, children: collides ? getLocalizedString("Replace") : getLocalizedString("Save") }), _jsx(Button, { type: "button", variant: "secondary", "data-size": size, onClick: onCancel, children: getLocalizedString("Cancel") })] })] }) }));
32
- }
@@ -1,14 +0,0 @@
1
- import { type FieldMetadata, type FilterExpression } from "@olenbetong/appframe-core";
2
- import type { FilterEditorSize, GetFieldOptions } from "./types.js";
3
- export declare function getFieldLabel(field: FieldMetadata): string;
4
- export type FilterRowProps = {
5
- expression: FilterExpression;
6
- fields: FieldMetadata[];
7
- onChange: (expression: FilterExpression) => void;
8
- onRemove: () => void;
9
- getFieldOptions?: GetFieldOptions;
10
- readOnly?: boolean;
11
- "data-size"?: FilterEditorSize;
12
- };
13
- /** A single `field operator value` row. */
14
- export declare function FilterRow({ expression, fields, onChange, onRemove, getFieldOptions, readOnly, "data-size": size, }: FilterRowProps): import("react").JSX.Element;
@@ -1,32 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Select } from "@digdir/designsystemet-react";
3
- import { XMarkIcon } from "@navikt/aksel-icons";
4
- import { changeOperator, createExpression, getLocalizedString, getOperatorLabel, getOperatorsForField, normalizeOperator, } from "@olenbetong/appframe-core";
5
- import { Combobox } from "@olenbetong/appframe-ds";
6
- import { FilterValueEditor } from "./FilterValueEditor.js";
7
- export function getFieldLabel(field) {
8
- return field.caption || field.name;
9
- }
10
- /** A single `field operator value` row. */
11
- export function FilterRow({ expression, fields, onChange, onRemove, getFieldOptions, readOnly, "data-size": size = "sm", }) {
12
- let field = fields.find((item) => item.name === expression.column);
13
- let operator = normalizeOperator(expression.operator);
14
- // A filter can reference a field that is no longer in the view. Keep the row
15
- // editable by falling back to a string field rather than dropping it.
16
- let effectiveField = field ?? { name: expression.column, type: "string" };
17
- let operators = getOperatorsForField(effectiveField);
18
- if (!operators.includes(operator)) {
19
- operators = [...operators, operator];
20
- }
21
- function handleFieldChange(next) {
22
- if (!next)
23
- return;
24
- // Keep the operator when the new field supports it, so switching between
25
- // two fields of the same type does not reset the row.
26
- let operators = getOperatorsForField(next);
27
- let keep = operators.includes(operator) ? operator : undefined;
28
- let created = createExpression(next, keep);
29
- onChange(keep ? { ...created, value: expression.value, valueType: expression.valueType } : created);
30
- }
31
- return (_jsxs("div", { className: "ObFilterEditor-row", children: [_jsx(Combobox, { className: "ObFilterEditor-field", "data-size": size, readOnly: readOnly, disableClearable: true, "aria-label": getLocalizedString("Field"), placeholder: getLocalizedString("Select field"), options: fields, getOptionLabel: getFieldLabel, getOptionKey: (option) => option.name, isOptionEqualToValue: (a, b) => a.name === b.name, value: effectiveField, onChange: (_event, next) => handleFieldChange(next) }), _jsx(Select, { className: "ObFilterEditor-operator", "data-size": size, disabled: readOnly, "aria-label": getLocalizedString("Operator"), value: operator, onChange: (event) => onChange(changeOperator(expression, event.target.value, effectiveField)), children: operators.map((item) => (_jsx(Select.Option, { value: item, children: getOperatorLabel(item, effectiveField.type) }, item))) }), _jsx(FilterValueEditor, { expression: expression, field: effectiveField, options: field ? getFieldOptions?.(field) : undefined, onChange: onChange, readOnly: readOnly, "data-size": size }), !readOnly && (_jsx("button", { type: "button", className: "ObFilterEditor-iconButton", title: getLocalizedString("Remove condition"), "aria-label": getLocalizedString("Remove condition"), onClick: onRemove, children: _jsx(XMarkIcon, { "aria-hidden": true }) }))] }));
32
- }
@@ -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,23 +0,0 @@
1
- import "./FilterShareDialog.css";
2
- export type FilterShareDialogProps = {
3
- open: boolean;
4
- onClose: () => void;
5
- /** `FilterID` of the filter to manage sharing for. */
6
- filterId: number | null;
7
- /** Shown in the dialog heading. */
8
- filterName?: string;
9
- "data-size"?: "sm" | "md" | "lg";
10
- };
11
- /**
12
- * Manages who a saved filter is shared with.
13
- *
14
- * Only a manager of the filter can load or change the grants — for anyone else
15
- * `sstp_WebSiteCMS_FilterBuilder_GetPermissions` returns nothing, so the list
16
- * simply stays empty.
17
- *
18
- * @example
19
- * ```jsx
20
- * <FilterShareDialog open={sharing} filterId={selected} filterName={name} onClose={() => setSharing(false)} />
21
- * ```
22
- */
23
- export declare function FilterShareDialog({ open, onClose, filterId, filterName, "data-size": size, }: FilterShareDialogProps): import("react").JSX.Element;
@@ -1,63 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Button, Dialog, Heading, Select, Table } from "@digdir/designsystemet-react";
3
- import { getLocalizedString } from "@olenbetong/appframe-core";
4
- import { useDebounce, useFilterPermissions } from "@olenbetong/appframe-react";
5
- import { Combobox } from "@olenbetong/appframe-ds";
6
- import { PersonGroupIcon, PersonIcon, TrashIcon } from "@navikt/aksel-icons";
7
- import { useEffect, useState } from "react";
8
- import "./FilterShareDialog.css";
9
- /**
10
- * Manages who a saved filter is shared with.
11
- *
12
- * Only a manager of the filter can load or change the grants — for anyone else
13
- * `sstp_WebSiteCMS_FilterBuilder_GetPermissions` returns nothing, so the list
14
- * simply stays empty.
15
- *
16
- * @example
17
- * ```jsx
18
- * <FilterShareDialog open={sharing} filterId={selected} filterName={name} onClose={() => setSharing(false)} />
19
- * ```
20
- */
21
- export function FilterShareDialog({ open, onClose, filterId, filterName, "data-size": size = "sm", }) {
22
- let { permissions, loading, error, setPermission, removePermission, search } = useFilterPermissions(open ? filterId : null);
23
- let [candidates, setCandidates] = useState([]);
24
- let [searchText, setSearchText] = useState("");
25
- let query = useDebounce(searchText, 300);
26
- useEffect(() => {
27
- if (!open || query.length < 2) {
28
- setCandidates([]);
29
- return;
30
- }
31
- let isCancelled = false;
32
- search(query)
33
- .then((results) => {
34
- if (isCancelled)
35
- return;
36
- // Anyone who already has a grant is not a candidate for a new one.
37
- let granted = new Set(permissions.map((permission) => permission.groupRef));
38
- setCandidates(results.filter((result) => !granted.has(result.primKey)));
39
- })
40
- .catch(() => {
41
- if (!isCancelled)
42
- setCandidates([]);
43
- });
44
- return () => {
45
- isCancelled = true;
46
- };
47
- }, [open, query, search, permissions]);
48
- function handleAdd(candidate) {
49
- if (!candidate)
50
- return;
51
- setSearchText("");
52
- void setPermission(candidate.primKey, "Reader");
53
- }
54
- return (_jsxs(Dialog, { open: open, closedby: "any", "data-size": size, onClose: onClose, className: "ObFilterShareDialog-root", children: [_jsx(Dialog.Block, { children: _jsx(Heading, { level: 2, "data-size": "xs", children: filterName ? getLocalizedString("Sharing - {0}").replace("{0}", filterName) : getLocalizedString("Sharing") }) }), _jsx(Dialog.Block, { children: _jsx(Combobox, { options: candidates, value: null, inputValue: searchText, loading: loading, "data-size": size, label: getLocalizedString("Add user or group"), placeholder: getLocalizedString("Search..."), getOptionLabel: (option) => option.name, getOptionKey: (option) => option.primKey,
55
- // The procedure searches both name and login, so filtering again on
56
- // the label would drop everything matched by login.
57
- filterOptions: (options) => [...options], noOptionsText: query.length < 2 ? getLocalizedString("Type to search") : getLocalizedString("No matches"), renderOption: (option) => (_jsxs("span", { className: "ObFilterShareDialog-candidate", children: [option.type === "User" ? _jsx(PersonIcon, { "aria-hidden": true }) : _jsx(PersonGroupIcon, { "aria-hidden": true }), _jsx("span", { children: option.name }), _jsx("span", { className: "ObFilterShareDialog-candidateLogin", children: option.login })] })),
58
- // The picker never keeps a selection; picking an option adds a grant.
59
- onInputChange: (_event, value) => setSearchText(value), onChange: (_event, value) => handleAdd(value) }) }), _jsxs(Dialog.Block, { children: [error && _jsx("p", { className: "ObFilterShareDialog-error", children: String(error.message ?? error) }), _jsxs(Table, { "data-size": size, className: "ObFilterShareDialog-table", children: [_jsx(Table.Head, { children: _jsxs(Table.Row, { children: [_jsx(Table.HeaderCell, { children: getLocalizedString("Name") }), _jsx(Table.HeaderCell, { children: getLocalizedString("Login") }), _jsx(Table.HeaderCell, { children: getLocalizedString("Access") }), _jsx(Table.HeaderCell, {})] }) }), _jsxs(Table.Body, { children: [permissions.length === 0 && (_jsx(Table.Row, { children: _jsx(Table.Cell, { colSpan: 4, children: loading ? getLocalizedString("Loading...") : getLocalizedString("Not shared with anyone") }) })), permissions.map((permission) => (_jsx(PermissionRow, { permission: permission, size: size, onChangeAccess: (accessLevel) => void setPermission(permission.groupRef, accessLevel), onRemove: () => void removePermission(permission.groupRef) }, permission.primKey)))] })] })] }), _jsx(Dialog.Block, { children: _jsx(Button, { type: "button", variant: "secondary", "data-size": size, onClick: onClose, children: getLocalizedString("Close") }) })] }));
60
- }
61
- function PermissionRow({ permission, size, onChangeAccess, onRemove }) {
62
- return (_jsxs(Table.Row, { children: [_jsx(Table.Cell, { children: _jsxs("span", { className: "ObFilterShareDialog-candidate", children: [permission.type === "User" ? _jsx(PersonIcon, { "aria-hidden": true }) : _jsx(PersonGroupIcon, { "aria-hidden": true }), permission.name] }) }), _jsx(Table.Cell, { children: permission.login }), _jsx(Table.Cell, { children: _jsxs(Select, { "data-size": size, value: permission.accessLevel, "aria-label": getLocalizedString("Access for {0}").replace("{0}", permission.name), onChange: (event) => onChangeAccess(event.currentTarget.value), children: [_jsx(Select.Option, { value: "Reader", children: getLocalizedString("Reader") }), _jsx(Select.Option, { value: "Manager", children: getLocalizedString("Manager") })] }) }), _jsx(Table.Cell, { children: _jsx(Button, { type: "button", variant: "tertiary", "data-color": "danger", "data-size": size, icon: true, "aria-label": getLocalizedString("Remove access for {0}").replace("{0}", permission.name), onClick: onRemove, children: _jsx(TrashIcon, { "aria-hidden": true }) }) })] }));
63
- }
@@ -1,15 +0,0 @@
1
- import { type FilterTree } from "@olenbetong/appframe-core";
2
- import type { FilterEditorSize } from "./types.js";
3
- export type FilterStringFieldProps = {
4
- filter: FilterTree;
5
- onChange: (filter: FilterTree) => void;
6
- viewName?: string;
7
- readOnly?: boolean;
8
- "data-size"?: FilterEditorSize;
9
- };
10
- /**
11
- * Two-way filter string editor. The tree is the source of truth: it is
12
- * converted to a string whenever it changes. Editing the string and leaving the
13
- * field parses it back into a tree.
14
- */
15
- export declare function FilterStringField({ filter, onChange, viewName, readOnly, "data-size": size, }: FilterStringFieldProps): import("react").JSX.Element;
@@ -1,37 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Textfield, ValidationMessage } from "@digdir/designsystemet-react";
3
- import { getLocalizedString, toFilterTree } from "@olenbetong/appframe-core";
4
- import { useFilterConversion } from "@olenbetong/appframe-react";
5
- import { useEffect, useState } from "react";
6
- /**
7
- * Two-way filter string editor. The tree is the source of truth: it is
8
- * converted to a string whenever it changes. Editing the string and leaving the
9
- * field parses it back into a tree.
10
- */
11
- export function FilterStringField({ filter, onChange, viewName, readOnly, "data-size": size = "sm", }) {
12
- let { filterString, isConverting, error, warning, parseFilterString } = useFilterConversion(filter, { viewName });
13
- let [draft, setDraft] = useState(null);
14
- let [parseError, setParseError] = useState(null);
15
- // The tree changed underneath us, so any half-typed string is stale.
16
- useEffect(() => {
17
- setDraft(null);
18
- setParseError(null);
19
- }, [filter]);
20
- async function commit() {
21
- if (draft === null || draft === filterString) {
22
- setDraft(null);
23
- return;
24
- }
25
- let parsed = await parseFilterString(draft);
26
- if (parsed) {
27
- setDraft(null);
28
- setParseError(null);
29
- onChange(toFilterTree(parsed));
30
- }
31
- else {
32
- setParseError(getLocalizedString("The filter could not be parsed"));
33
- }
34
- }
35
- let message = parseError ?? error?.message ?? warning;
36
- return (_jsxs("div", { className: "ObFilterEditor-filterString", children: [_jsx(Textfield, { multiline: true, rows: 3, "data-size": size, readOnly: readOnly, label: _jsxs("span", { className: "ObFilterEditor-filterStringLabel", children: [getLocalizedString("Filter string"), isConverting && _jsx("span", { className: "ObFilterEditor-hint", children: getLocalizedString("Converting…") })] }), value: draft ?? filterString, onChange: (event) => setDraft(event.target.value), onBlur: commit }), message && _jsx(ValidationMessage, { "data-color": parseError ? "danger" : "warning", children: message })] }));
37
- }
@@ -1,16 +0,0 @@
1
- import { type FieldMetadata, type FilterExpression } from "@olenbetong/appframe-core";
2
- import type { FilterEditorSize, FilterValueOption } from "./types.js";
3
- export type FilterValueEditorProps = {
4
- expression: FilterExpression;
5
- field?: FieldMetadata;
6
- options?: FilterValueOption[];
7
- onChange: (expression: FilterExpression) => void;
8
- readOnly?: boolean;
9
- "data-size"?: FilterEditorSize;
10
- };
11
- /**
12
- * The value part of a filter row. Which editor is rendered depends on the
13
- * operator's arity, the field's type, and whether the value is a dynamic
14
- * ("special") value such as `Today` or `CurrentUser`.
15
- */
16
- export declare function FilterValueEditor({ expression, field, options, onChange, readOnly, "data-size": size, }: FilterValueEditorProps): import("react").JSX.Element | null;