@olenbetong/appframe-ds 1.0.3 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/package.json +8 -7
- package/scripts/copyAssets.mjs +27 -55
- package/src/AfLookup/Lookup.css +129 -125
- package/src/AfLookup/Lookup.tsx +184 -162
- package/src/AfLookup/LookupCombobox.css +78 -78
- package/src/AfLookup/LookupCombobox.tsx +237 -237
- package/src/AfLookup/LookupEdit.tsx +130 -130
- package/src/AfLookup/LookupGrid.tsx +124 -124
- package/src/AfLookup/index.ts +5 -5
- package/src/autocomplete/Autocomplete.css +256 -256
- package/src/autocomplete/Autocomplete.tsx +320 -320
- package/src/autocomplete/AutocompleteFrame.tsx +168 -168
- package/src/autocomplete/Combobox.tsx +286 -286
- package/src/autocomplete/index.ts +4 -4
- package/src/autocomplete/types.ts +204 -204
- package/src/autocomplete/utils.ts +183 -183
- package/src/binding/BoundNumericTextField.tsx +102 -102
- package/src/binding/BoundTextField.tsx +49 -49
- package/src/binding/CancelButton.tsx +30 -30
- package/src/binding/CancelIconButton.tsx +30 -30
- package/src/binding/DataEditToolbar.tsx +92 -92
- package/src/binding/DeleteButton.tsx +35 -35
- package/src/binding/DeleteIconButton.tsx +35 -35
- package/src/binding/RefreshButton.tsx +31 -31
- package/src/binding/RefreshIconButton.tsx +33 -33
- package/src/binding/RefreshRowIconButton.tsx +33 -33
- package/src/binding/SaveButton.tsx +37 -37
- package/src/binding/SaveIconButton.tsx +38 -38
- package/src/container/Container.tsx +49 -49
- package/src/container/index.ts +1 -1
- package/src/cutoff/CutOffPicker.css +12 -0
- package/src/cutoff/CutOffPicker.tsx +165 -0
- package/src/cutoff/context.tsx +194 -0
- package/src/cutoff/dsCutOffDates.ts +21 -0
- package/src/cutoff/index.ts +4 -0
- package/src/cutoff/utils.test.ts +59 -0
- package/src/cutoff/utils.ts +276 -0
- package/src/filter/ChipListInput.tsx +79 -79
- package/src/filter/FieldFilterPanel.css +150 -150
- package/src/filter/FieldFilterPanel.tsx +309 -309
- package/src/filter/FilterBuilder.css +152 -152
- package/src/filter/FilterBuilder.test.tsx +153 -153
- package/src/filter/FilterBuilder.tsx +435 -435
- package/src/filter/FilterEditor.css +231 -231
- package/src/filter/FilterEditor.test.tsx +259 -259
- package/src/filter/FilterEditor.tsx +75 -74
- package/src/filter/FilterGroupEditor.tsx +160 -160
- package/src/filter/FilterNameDialog.css +22 -22
- package/src/filter/FilterNameDialog.tsx +81 -81
- package/src/filter/FilterRow.tsx +117 -117
- package/src/filter/FilterShareDialog.css +28 -28
- package/src/filter/FilterShareDialog.tsx +201 -201
- package/src/filter/FilterStringField.tsx +78 -77
- package/src/filter/FilterValueEditor.tsx +220 -220
- package/src/filter/SavedFilterTree.css +107 -107
- package/src/filter/SavedFilterTree.test.tsx +94 -94
- package/src/filter/SavedFilterTree.tsx +218 -222
- package/src/filter/fieldFilter.test.ts +158 -158
- package/src/filter/fieldFilter.ts +139 -139
- package/src/filter/index.ts +27 -27
- package/src/filter/types.ts +38 -38
- package/src/filter/useDistinctValues.test.ts +102 -102
- package/src/filter/useDistinctValues.ts +230 -230
- package/src/global.d.ts +11 -11
- package/src/grid/AfGridColumnsPanel.tsx +118 -118
- package/src/grid/AfGridContext.tsx +51 -51
- package/src/grid/AfGridError.tsx +46 -46
- package/src/grid/AfHeaderFilterCell.tsx +147 -151
- package/src/grid/AfHeaderFilterPanel.tsx +111 -111
- package/src/grid/GridEditLookup.css +12 -0
- package/src/grid/GridEditLookup.tsx +121 -0
- package/src/grid/Toolbar.tsx +233 -233
- package/src/grid/editing.ts +100 -100
- package/src/grid/filter.ts +78 -78
- package/src/grid/formatters.ts +48 -48
- package/src/grid/index.css +245 -245
- package/src/grid/index.tsx +489 -484
- package/src/grid/license.ts +48 -48
- package/src/grid/localization.ts +369 -369
- package/src/grid/slots/index.tsx +307 -307
- package/src/grid/slots/slots.css +64 -64
- package/src/grid/theme.tsx +138 -138
- package/src/grid/useAfColumns.tsx +371 -371
- package/src/grid/useAfCurrentIndex.ts +63 -63
- package/src/grid/useAfData.ts +20 -20
- package/src/grid/useAfFilter.ts +160 -160
- package/src/grid/useAfFilterFields.ts +55 -55
- package/src/grid/useAfGridApi.ts +71 -71
- package/src/grid/useAfKeyBindings.ts +36 -36
- package/src/grid/useAfNewItemRow.ts +258 -258
- package/src/grid/useAfPagination.ts +53 -53
- package/src/grid/useAfPersistedState.ts +230 -230
- package/src/grid/useAfRowEditModel.ts +145 -145
- package/src/grid/useAfRowGrouping.ts +47 -47
- package/src/grid/useAfServerAggregation.ts +145 -145
- package/src/grid/useAfSortModel.ts +84 -84
- package/src/i18n.ts +13 -0
- package/src/index.ts +14 -12
- package/src/input/InputAdornments.css +75 -75
- package/src/input/InputAdornments.tsx +102 -102
- package/src/input/index.ts +1 -1
- package/src/layout/AppMenu.tsx +74 -75
- package/src/layout/AppMenuDrawer.css +70 -70
- package/src/layout/AppMenuDrawer.tsx +122 -122
- package/src/layout/ErrorBoundary.tsx +162 -162
- package/src/layout/ResponsiveDialog.css +86 -0
- package/src/layout/ResponsiveDialog.tsx +55 -0
- package/src/layout/index.tsx +69 -68
- package/src/link/Link.tsx +23 -0
- package/src/link/index.ts +1 -0
- package/src/mdi/Mdi.css +138 -138
- package/src/mdi/Mdi.test.tsx +91 -87
- package/src/mdi/Mdi.tsx +141 -141
- package/src/mdi/MdiConfirmCloseDialog.tsx +47 -47
- package/src/mdi/MdiContext.tsx +59 -59
- package/src/mdi/MdiDocumentContext.tsx +60 -60
- package/src/mdi/MdiPanel.tsx +61 -61
- package/src/mdi/MdiRestore.test.tsx +86 -82
- package/src/mdi/MdiTab.tsx +30 -30
- package/src/mdi/controller.test.ts +382 -382
- package/src/mdi/controller.ts +656 -656
- package/src/mdi/dockviewHost.ts +132 -132
- package/src/mdi/fakeHost.ts +200 -200
- package/src/mdi/host.ts +44 -44
- package/src/mdi/ids.test.ts +20 -20
- package/src/mdi/ids.ts +18 -18
- package/src/mdi/index.ts +31 -31
- package/src/mdi/layoutRestore.test.ts +156 -156
- package/src/mdi/layoutRestore.ts +311 -311
- package/src/mdi/layoutSpec.test.ts +143 -143
- package/src/mdi/layoutSpec.ts +214 -214
- package/src/mdi/layoutStore.test.ts +93 -93
- package/src/mdi/layoutStore.ts +99 -99
- package/src/mdi/memorySettingsStore.ts +21 -21
- package/src/mdi/registry.ts +34 -34
- package/src/mdi/testTypes.ts +37 -37
- package/src/mdi/theme.ts +22 -22
- package/src/mdi/types.ts +214 -214
- package/src/page/Page.css +53 -53
- package/src/page/PageBlock.css +64 -64
- package/src/page/PageBlock.tsx +92 -92
- package/src/page/PageHeader.css +88 -88
- package/src/page/PageHeader.tsx +115 -116
- package/src/page/PageTitle.css +5 -0
- package/src/page/PageTitle.tsx +21 -0
- package/src/page/index.ts +4 -3
- package/src/paper/Paper.tsx +52 -52
- package/src/progress/LinearProgress.css +93 -93
- package/src/progress/LinearProgress.tsx +104 -104
- package/src/progress/index.ts +1 -1
- package/src/report-downloader/ReportDownloader.css +67 -67
- package/src/report-downloader/components/StatusItem.tsx +87 -86
- package/src/report-downloader/components/StatusList.tsx +28 -28
- package/src/report-downloader/index.ts +41 -41
- package/src/report-downloader/status.tsx +92 -92
- package/src/sortable/DropIndicator.css +51 -51
- package/src/sortable/DropIndicator.tsx +27 -27
- package/src/sortable/SortableItemList.css +21 -21
- package/src/sortable/SortableItemList.tsx +264 -264
- package/src/sortable/index.ts +8 -8
- package/src/sortable/reorderSortOrder.ts +126 -126
- package/src/sortable/sortOrder.ts +101 -101
- package/src/sortable/types.ts +9 -9
- package/src/sortable/useSortableContainer.ts +53 -53
- package/src/sortable/useSortableItem.ts +95 -95
- package/src/sortable/useSortableList.ts +117 -117
- package/src/test/happy-dom-document-class.ts +24 -24
- package/src/test/setup.ts +12 -12
- package/src/theme/useDsColorScheme.ts +53 -53
- package/tsconfig.build.json +9 -9
- package/tsconfig.json +8 -8
- package/vitest.config.ts +10 -10
|
@@ -1,81 +1,81 @@
|
|
|
1
|
-
import "./FilterNameDialog.css";
|
|
2
|
-
|
|
3
|
-
import { Button, Dialog, Heading, Textfield } from "@digdir/designsystemet-react";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
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
|
-
}
|
|
1
|
+
import "./FilterNameDialog.css";
|
|
2
|
+
|
|
3
|
+
import { Button, Dialog, Heading, Textfield } from "@digdir/designsystemet-react";
|
|
4
|
+
import { useEffect, useState } from "react";
|
|
5
|
+
import { getLocalizedString } from "../i18n.js";
|
|
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
CHANGED
|
@@ -1,117 +1,117 @@
|
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
} from "
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
import {
|
|
17
|
-
import
|
|
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
|
+
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
|
+
getOperatorLabel,
|
|
10
|
+
getOperatorsForField,
|
|
11
|
+
normalizeOperator,
|
|
12
|
+
} from "@olenbetong/appframe-core";
|
|
13
|
+
import { Combobox } from "../autocomplete/index.js";
|
|
14
|
+
|
|
15
|
+
import { FilterValueEditor } from "./FilterValueEditor.js";
|
|
16
|
+
import type { FilterEditorSize, GetFieldOptions } from "./types.js";
|
|
17
|
+
import { getLocalizedString } from "../i18n.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 +1,28 @@
|
|
|
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-neutral-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
|
+
/*
|
|
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-neutral-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
|
+
}
|