@navikt/ds-react 8.5.2 → 8.6.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/cjs/data/token-filter/AutoSuggest.js +2 -5
- package/cjs/data/token-filter/AutoSuggest.js.map +1 -1
- package/cjs/data/token-filter/AutoSuggest.types.d.ts +0 -1
- package/cjs/data/token-filter/TokenFilter.d.ts +5 -0
- package/cjs/data/token-filter/TokenFilter.js +7 -8
- package/cjs/data/token-filter/TokenFilter.js.map +1 -1
- package/cjs/data/token-filter/TokenFilter.types.d.ts +0 -2
- package/cjs/data/token-filter/helpers/generate-autocomplete-options.d.ts +2 -4
- package/cjs/data/token-filter/helpers/generate-autocomplete-options.js +16 -25
- package/cjs/data/token-filter/helpers/generate-autocomplete-options.js.map +1 -1
- package/cjs/toggle-group/useToggleGroup.js +5 -3
- package/cjs/toggle-group/useToggleGroup.js.map +1 -1
- package/esm/data/token-filter/AutoSuggest.js +2 -5
- package/esm/data/token-filter/AutoSuggest.js.map +1 -1
- package/esm/data/token-filter/AutoSuggest.types.d.ts +0 -1
- package/esm/data/token-filter/TokenFilter.d.ts +5 -0
- package/esm/data/token-filter/TokenFilter.js +7 -8
- package/esm/data/token-filter/TokenFilter.js.map +1 -1
- package/esm/data/token-filter/TokenFilter.types.d.ts +0 -2
- package/esm/data/token-filter/helpers/generate-autocomplete-options.d.ts +2 -4
- package/esm/data/token-filter/helpers/generate-autocomplete-options.js +16 -25
- package/esm/data/token-filter/helpers/generate-autocomplete-options.js.map +1 -1
- package/esm/toggle-group/useToggleGroup.js +6 -4
- package/esm/toggle-group/useToggleGroup.js.map +1 -1
- package/package.json +3 -3
- package/src/data/token-filter/AutoSuggest.tsx +2 -8
- package/src/data/token-filter/AutoSuggest.types.ts +0 -1
- package/src/data/token-filter/TokenFilter.tsx +6 -3
- package/src/data/token-filter/TokenFilter.types.ts +0 -2
- package/src/data/token-filter/helpers/generate-autocomplete-options.test.ts +0 -60
- package/src/data/token-filter/helpers/generate-autocomplete-options.ts +27 -17
- package/src/toggle-group/useToggleGroup.ts +6 -5
|
@@ -42,12 +42,9 @@ const AutoSuggest = (0, react_1.forwardRef)(({ options, onSelect }, ref) => {
|
|
|
42
42
|
return (react_1.default.createElement(box_1.Box, { ref: ref, padding: "space-6" }, options.map((group) => (react_1.default.createElement("div", { key: group.label },
|
|
43
43
|
react_1.default.createElement(typography_1.Label, { as: "div" }, group.label),
|
|
44
44
|
react_1.default.createElement(stack_1.VStack, { gap: "space-4" }, group.options.map((option) => {
|
|
45
|
-
var _a, _b;
|
|
46
45
|
return (react_1.default.createElement("div", { key: option.value },
|
|
47
|
-
react_1.default.createElement("button", { type: "button", onClick: () =>
|
|
48
|
-
|
|
49
|
-
return onSelect((_a = option.value) !== null && _a !== void 0 ? _a : option.propertyKey); } },
|
|
50
|
-
react_1.default.createElement("span", null, (_b = (_a = option.value) !== null && _a !== void 0 ? _a : option.label) !== null && _b !== void 0 ? _b : option.propertyLabel),
|
|
46
|
+
react_1.default.createElement("button", { type: "button", onClick: () => onSelect(option.value) },
|
|
47
|
+
react_1.default.createElement("span", null, option.label),
|
|
51
48
|
option.description && react_1.default.createElement("span", null, option.description),
|
|
52
49
|
option.tags && option.tags.length > 0 && (react_1.default.createElement("div", null, option.tags.map((tag) => (react_1.default.createElement("span", { key: tag }, tag))))))));
|
|
53
50
|
})))))));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutoSuggest.js","sourceRoot":"","sources":["../../../src/data/token-filter/AutoSuggest.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAA0C;AAC1C,8CAA2C;AAC3C,kDAAgD;AAChD,iDAAyC;AASzC,MAAM,WAAW,GAAG,IAAA,kBAAU,EAC5B,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,GAAG,EAAE,EAAE;IAC7B,OAAO,CACL,8BAAC,SAAG,IAAC,GAAG,EAA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MAAM,CAAC,WAAW,CAAQ;oBACvD,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,CACxC,2CACG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CACxB,wCAAM,GAAG,EAAE,GAAG,IAAG,GAAG,CAAQ,CAC7B,CAAC,CACE,CACP,CACM,CACL,CACP,CAAC;QACJ,CAAC,CAAC,CACK,CACL,CACP,CAAC,CACE,CACP,CAAC;AACJ,CAAC,CACF,CAAC;AAEO,kCAAW"}
|
|
@@ -7,5 +7,10 @@ type TokenFilterProps = {
|
|
|
7
7
|
filteringOptions: QueryFilteringOptions;
|
|
8
8
|
filteringProperties: QueryFilteringProperties;
|
|
9
9
|
};
|
|
10
|
+
/**
|
|
11
|
+
* TODO:
|
|
12
|
+
* - Implement onChange handler to update query state when user selects an autocomplete option.
|
|
13
|
+
* - Handle token rendering and editing (e.g., show tokens for matched properties/operators/values, allow deleting tokens).
|
|
14
|
+
*/
|
|
10
15
|
export declare const TokenFilter: React.ForwardRefExoticComponent<TokenFilterProps & React.RefAttributes<HTMLDivElement>>;
|
|
11
16
|
export {};
|
|
@@ -40,6 +40,11 @@ const helpers_1 = require("../../utils/helpers");
|
|
|
40
40
|
const AutoSuggest_1 = require("./AutoSuggest");
|
|
41
41
|
const generate_autocomplete_options_1 = require("./helpers/generate-autocomplete-options");
|
|
42
42
|
const parse_query_text_1 = require("./helpers/parse-query-text");
|
|
43
|
+
/**
|
|
44
|
+
* TODO:
|
|
45
|
+
* - Implement onChange handler to update query state when user selects an autocomplete option.
|
|
46
|
+
* - Handle token rendering and editing (e.g., show tokens for matched properties/operators/values, allow deleting tokens).
|
|
47
|
+
*/
|
|
43
48
|
exports.TokenFilter = (0, react_1.forwardRef)(({ query, className, filteringProperties, filteringOptions }, ref) => {
|
|
44
49
|
const [inputAnchor, setInputAnchor] = (0, react_1.useState)(null);
|
|
45
50
|
const [filterText, setFilterText] = (0, react_1.useState)("");
|
|
@@ -57,11 +62,7 @@ exports.TokenFilter = (0, react_1.forwardRef)(({ query, className, filteringProp
|
|
|
57
62
|
setFilterText("");
|
|
58
63
|
setCustomOpen(false);
|
|
59
64
|
} },
|
|
60
|
-
react_1.default.createElement(AutoSuggest_1.AutoSuggest
|
|
61
|
-
/* @ts-expect-error TODO: handle conversion better */
|
|
62
|
-
, {
|
|
63
|
-
/* @ts-expect-error TODO: handle conversion better */
|
|
64
|
-
options: autoCompleteOptions.options, onSelect: handleSelectOption })),
|
|
65
|
+
react_1.default.createElement(AutoSuggest_1.AutoSuggest, { options: autoCompleteOptions.options, onSelect: handleSelectOption })),
|
|
65
66
|
query.tokens.map((token, index) => {
|
|
66
67
|
return (react_1.default.createElement("div", { key: index, className: "aksel-property-filter__token" },
|
|
67
68
|
react_1.default.createElement("strong", null, token.propertyKey),
|
|
@@ -70,7 +71,6 @@ exports.TokenFilter = (0, react_1.forwardRef)(({ query, className, filteringProp
|
|
|
70
71
|
" "));
|
|
71
72
|
}),
|
|
72
73
|
react_1.default.createElement("ul", null, filteringProperties.map((prop) => (react_1.default.createElement("li", { key: prop.key }, prop.propertyLabel)))),
|
|
73
|
-
react_1.default.createElement("pre", null, JSON.stringify(queryState, null, 2)),
|
|
74
74
|
react_1.default.createElement("pre", null, JSON.stringify(autoCompleteOptions, null, 2))));
|
|
75
75
|
});
|
|
76
76
|
function derrivedFilterState(filteringProperties, filteringOptions) {
|
|
@@ -88,13 +88,12 @@ function derrivedFilterState(filteringProperties, filteringOptions) {
|
|
|
88
88
|
});
|
|
89
89
|
}
|
|
90
90
|
const internalOptions = filteringOptions.map((option) => {
|
|
91
|
-
var _a, _b, _c, _d
|
|
91
|
+
var _a, _b, _c, _d;
|
|
92
92
|
return ({
|
|
93
93
|
property: (_a = propertyMap.get(option.propertyKey)) !== null && _a !== void 0 ? _a : null,
|
|
94
94
|
value: option.value,
|
|
95
95
|
label: (_c = (_b = option.label) !== null && _b !== void 0 ? _b : option.value) !== null && _c !== void 0 ? _c : "",
|
|
96
96
|
tags: (_d = option.tags) !== null && _d !== void 0 ? _d : [],
|
|
97
|
-
filteringTags: (_e = option.filteringTags) !== null && _e !== void 0 ? _e : [],
|
|
98
97
|
});
|
|
99
98
|
});
|
|
100
99
|
return { properties: [...propertyMap.values()], options: internalOptions };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TokenFilter.js","sourceRoot":"","sources":["../../../src/data/token-filter/TokenFilter.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAoD;AACpD,2CAAwC;AACxC,iDAAyC;AACzC,+CAA4C;AAQ5C,2FAAsF;AACtF,iEAA4D;
|
|
1
|
+
{"version":3,"file":"TokenFilter.js","sourceRoot":"","sources":["../../../src/data/token-filter/TokenFilter.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAoD;AACpD,2CAAwC;AACxC,iDAAyC;AACzC,+CAA4C;AAQ5C,2FAAsF;AACtF,iEAA4D;AAU5D;;;;GAIG;AACU,QAAA,WAAW,GAAG,IAAA,kBAAU,EACnC,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,EAAE,GAAG,EAAE,EAAE;IACnE,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,IAAA,gBAAQ,EAC5C,IAAI,CACL,CAAC;IAEF,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,IAAA,gBAAQ,EAAS,EAAE,CAAC,CAAC;IACzD,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,mBAAmB,CACjD,mBAAmB,EACnB,gBAAgB,CACjB,CAAC;IAEF,MAAM,UAAU,GAAG,IAAA,iCAAc,EAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAE1D,MAAM,mBAAmB,GAAG,IAAA,2DAA2B,EACrD,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zC,IAAI,EAAE,MAAA,MAAM,CAAC,IAAI,mCAAI,EAAE;SACxB,CAAC,CAAA;KAAA,CAAC,CAAC;IAEJ,OAAO,EAAE,UAAU,EAAE,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,CAAC;AAC7E,CAAC"}
|
|
@@ -14,7 +14,6 @@ type QueryFilteringOption = {
|
|
|
14
14
|
value: any;
|
|
15
15
|
label?: string;
|
|
16
16
|
tags?: string[];
|
|
17
|
-
filteringTags?: string[];
|
|
18
17
|
disabled?: boolean;
|
|
19
18
|
};
|
|
20
19
|
type QueryFilteringOptions = QueryFilteringOption[];
|
|
@@ -47,6 +46,5 @@ type ParsedOption = {
|
|
|
47
46
|
value: any;
|
|
48
47
|
label: string;
|
|
49
48
|
tags: string[];
|
|
50
|
-
filteringTags: string[];
|
|
51
49
|
};
|
|
52
50
|
export type { QueryFilterOperator, QueryFilterQuery, QueryFilteringOptions, QueryFilteringProperty, QueryFilterOperation, QueryFilteringProperties, ParsedProperty, ParsedOption, QueryFilteringOption, QueryFilteringOptionGroup, };
|
|
@@ -14,11 +14,9 @@ import { type ParsedText } from "./parse-query-text";
|
|
|
14
14
|
* Used by the UI to determine cursor position and input replacement.
|
|
15
15
|
* - options: Grouped suggestions to display (properties, operators, or values).
|
|
16
16
|
*/
|
|
17
|
-
|
|
17
|
+
type AutoCompleteResult = {
|
|
18
18
|
value: string;
|
|
19
19
|
options: OptionGroup<AutoCompleteOption>[];
|
|
20
|
-
} | {
|
|
21
|
-
value: string;
|
|
22
|
-
options: OptionGroup<ParsedProperty>[];
|
|
23
20
|
};
|
|
21
|
+
declare function generateAutoCompleteOptions(queryState: ParsedText, filteringProperties?: ParsedProperty[], filteringOptions?: ParsedOption[]): AutoCompleteResult;
|
|
24
22
|
export { generateAutoCompleteOptions };
|
|
@@ -5,19 +5,6 @@ const grouping_1 = require("./grouping");
|
|
|
5
5
|
const operators_1 = require("./operators");
|
|
6
6
|
const query_builder_1 = require("./query-builder");
|
|
7
7
|
const text_matching_1 = require("./text-matching");
|
|
8
|
-
/**
|
|
9
|
-
* Generates "options" to be used as autosuggest-ottion based on the current query state.
|
|
10
|
-
*
|
|
11
|
-
* The query parser recognizes three states:
|
|
12
|
-
* - "property": User has selected/matched a property and operator ("Status = active")
|
|
13
|
-
* - "operator": User has matched a property but is typing the operator ("Status" or "Status !")
|
|
14
|
-
* - "free-text": User is typing freely without a property match (e.g., "act" or "!: test")
|
|
15
|
-
*
|
|
16
|
-
* @returns
|
|
17
|
-
* - value: The canonical query string representation for the current state.
|
|
18
|
-
* Used by the UI to determine cursor position and input replacement.
|
|
19
|
-
* - options: Grouped suggestions to display (properties, operators, or values).
|
|
20
|
-
*/
|
|
21
8
|
function generateAutoCompleteOptions(queryState, filteringProperties = [], filteringOptions = []) {
|
|
22
9
|
var _a;
|
|
23
10
|
/* State: Property and operator are matched, suggest values */
|
|
@@ -36,9 +23,6 @@ function generateAutoCompleteOptions(queryState, filteringProperties = [], filte
|
|
|
36
23
|
* Edge case: User typed an invalid operator prefix that doesn't match any operators.
|
|
37
24
|
* This can happen when typing characters that don't start any valid operator.
|
|
38
25
|
* Return empty suggestions gracefully - the UI will show "no results".
|
|
39
|
-
*
|
|
40
|
-
* TODO: When per-property operator configuration is implemented,
|
|
41
|
-
* this could also occur when a property restricts which operators are valid.
|
|
42
26
|
*/
|
|
43
27
|
if (operators.length === 0) {
|
|
44
28
|
return {
|
|
@@ -74,7 +58,10 @@ function generateAutoCompleteOptions(queryState, filteringProperties = [], filte
|
|
|
74
58
|
*/
|
|
75
59
|
return {
|
|
76
60
|
value: queryState.value,
|
|
77
|
-
options:
|
|
61
|
+
options: [
|
|
62
|
+
...generatePropertySuggestions(filteringProperties, queryState.value),
|
|
63
|
+
...createValueSuggestions(filteringOptions, (_a = queryState.operator) !== null && _a !== void 0 ? _a : "=", queryState.value),
|
|
64
|
+
],
|
|
78
65
|
};
|
|
79
66
|
}
|
|
80
67
|
/**
|
|
@@ -128,7 +115,14 @@ function generatePropertySuggestions(filteringProperties = [], filterText = "")
|
|
|
128
115
|
filteredProperties.push(property);
|
|
129
116
|
}
|
|
130
117
|
}
|
|
131
|
-
|
|
118
|
+
const groups = (0, grouping_1.createGroups)(filteredProperties, (property) => property.propertyGroup, "Properties");
|
|
119
|
+
return groups.map((group) => ({
|
|
120
|
+
label: group.label,
|
|
121
|
+
options: group.options.map((property) => ({
|
|
122
|
+
value: (0, query_builder_1.buildQueryString)(property.propertyLabel, "", ""),
|
|
123
|
+
label: property.propertyLabel,
|
|
124
|
+
})),
|
|
125
|
+
}));
|
|
132
126
|
}
|
|
133
127
|
function generateOperatorSuggestions(property, operatorPrefix = "") {
|
|
134
128
|
const operators = filterOperatorsByPrefix(getValidOperatorsForProperty(property), operatorPrefix);
|
|
@@ -153,9 +147,11 @@ function generateOperatorSuggestions(property, operatorPrefix = "") {
|
|
|
153
147
|
* Creates value suggestions for autocomplete.
|
|
154
148
|
* When scopedProperty is provided, only shows values for that property (single group).
|
|
155
149
|
* When scopedProperty is omitted, searches across all properties (multiple groups).
|
|
150
|
+
* TODO: This could potentially contain an unlimited number of options if there are many values across properties.
|
|
151
|
+
* May need virtualization/async or other filtering mechanism.
|
|
156
152
|
*/
|
|
157
153
|
function createValueSuggestions(filteringOptions = [], operator, filterText = "", scopedProperty) {
|
|
158
|
-
var _a
|
|
154
|
+
var _a;
|
|
159
155
|
const groups = {};
|
|
160
156
|
for (const option of filteringOptions) {
|
|
161
157
|
if (!(option === null || option === void 0 ? void 0 : option.property)) {
|
|
@@ -166,11 +162,7 @@ function createValueSuggestions(filteringOptions = [], operator, filterText = ""
|
|
|
166
162
|
continue;
|
|
167
163
|
}
|
|
168
164
|
/* Build search fields */
|
|
169
|
-
const searchFields = [
|
|
170
|
-
option.label,
|
|
171
|
-
...((_a = option.tags) !== null && _a !== void 0 ? _a : []),
|
|
172
|
-
...((_b = option.filteringTags) !== null && _b !== void 0 ? _b : []),
|
|
173
|
-
];
|
|
165
|
+
const searchFields = [option.label, ...((_a = option.tags) !== null && _a !== void 0 ? _a : [])];
|
|
174
166
|
if (!scopedProperty) {
|
|
175
167
|
searchFields.push(option.property.propertyLabel);
|
|
176
168
|
}
|
|
@@ -189,7 +181,6 @@ function createValueSuggestions(filteringOptions = [], operator, filterText = ""
|
|
|
189
181
|
value: (0, query_builder_1.buildQueryString)(option.property.propertyLabel, operator, option.value),
|
|
190
182
|
label: option.label,
|
|
191
183
|
tags: option.tags,
|
|
192
|
-
filteringTags: option.filteringTags,
|
|
193
184
|
});
|
|
194
185
|
}
|
|
195
186
|
return Object.values(groups).filter((group) => group.options.length > 0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-autocomplete-options.js","sourceRoot":"","sources":["../../../../src/data/token-filter/helpers/generate-autocomplete-options.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"generate-autocomplete-options.js","sourceRoot":"","sources":["../../../../src/data/token-filter/helpers/generate-autocomplete-options.ts"],"names":[],"mappings":";;AA0SS,kEAA2B;AApSpC,yCAA0C;AAC1C,2CAA8C;AAE9C,mDAAoE;AACpE,mDAAoD;AAoBpD,SAAS,2BAA2B,CAClC,UAAsB,EACtB,sBAAwC,EAAE,EAC1C,mBAAmC,EAAE;;IAErC,8DAA8D;IAC9D,IAAI,UAAU,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;QACnC,MAAM,UAAU,GAAG,UAAU,CAAC,KAAK,IAAI,EAAE,CAAC;QAE1C,OAAO;YACL,KAAK,EAAE,UAAU,CAAC,KAAK;YACvB,OAAO,EAAE,sBAAsB,CAC7B,gBAAgB,EAChB,UAAU,CAAC,QAAQ,EACnB,UAAU,EACV,UAAU,CAAC,QAAQ,CACpB;SACF,CAAC;IACJ,CAAC;IAED,yDAAyD;IACzD,IAAI,UAAU,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;QACnC,MAAM,SAAS,GAAG,uBAAuB,CACvC,4BAA4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AAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAC3E,CAAC"}
|
|
@@ -11,9 +11,11 @@ function useToggleGroup({ onChange, value, defaultValue = "", }) {
|
|
|
11
11
|
onChange,
|
|
12
12
|
});
|
|
13
13
|
/* Sync focused `value` with controlled `selectedValue` */
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
(0, react_1.useEffect)(() => {
|
|
15
|
+
if (value != null) {
|
|
16
|
+
setFocusedValue(value);
|
|
17
|
+
}
|
|
18
|
+
}, [value]);
|
|
17
19
|
return {
|
|
18
20
|
selectedValue,
|
|
19
21
|
setSelectedValue,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useToggleGroup.js","sourceRoot":"","sources":["../../src/toggle-group/useToggleGroup.ts"],"names":[],"mappings":";;AAIA,
|
|
1
|
+
{"version":3,"file":"useToggleGroup.js","sourceRoot":"","sources":["../../src/toggle-group/useToggleGroup.ts"],"names":[],"mappings":";;AAIA,wCAyBC;AA7BD,iCAA4C;AAC5C,0CAAsD;AAGtD,SAAgB,cAAc,CAAC,EAC7B,QAAQ,EACR,KAAK,EACL,YAAY,GAAG,EAAE,GAC6C;IAC9D,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,IAAA,gBAAQ,EAAC,YAAY,CAAC,CAAC;IAC/D,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,IAAA,4BAAoB,EAAC;QAC7D,YAAY;QACZ,KAAK;QACL,QAAQ;KACT,CAAC,CAAC;IAEH,0DAA0D;IAC1D,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;YAClB,eAAe,CAAC,KAAK,CAAC,CAAC;QACzB,CAAC;IACH,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEZ,OAAO;QACL,aAAa;QACb,gBAAgB;QAChB,YAAY;QACZ,eAAe;KAChB,CAAC;AACJ,CAAC"}
|
|
@@ -6,12 +6,9 @@ const AutoSuggest = forwardRef(({ options, onSelect }, ref) => {
|
|
|
6
6
|
return (React.createElement(Box, { ref: ref, padding: "space-6" }, options.map((group) => (React.createElement("div", { key: group.label },
|
|
7
7
|
React.createElement(Label, { as: "div" }, group.label),
|
|
8
8
|
React.createElement(VStack, { gap: "space-4" }, group.options.map((option) => {
|
|
9
|
-
var _a, _b;
|
|
10
9
|
return (React.createElement("div", { key: option.value },
|
|
11
|
-
React.createElement("button", { type: "button", onClick: () =>
|
|
12
|
-
|
|
13
|
-
return onSelect((_a = option.value) !== null && _a !== void 0 ? _a : option.propertyKey); } },
|
|
14
|
-
React.createElement("span", null, (_b = (_a = option.value) !== null && _a !== void 0 ? _a : option.label) !== null && _b !== void 0 ? _b : option.propertyLabel),
|
|
10
|
+
React.createElement("button", { type: "button", onClick: () => onSelect(option.value) },
|
|
11
|
+
React.createElement("span", null, option.label),
|
|
15
12
|
option.description && React.createElement("span", null, option.description),
|
|
16
13
|
option.tags && option.tags.length > 0 && (React.createElement("div", null, option.tags.map((tag) => (React.createElement("span", { key: tag }, tag))))))));
|
|
17
14
|
})))))));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutoSuggest.js","sourceRoot":"","sources":["../../../src/data/token-filter/AutoSuggest.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AASzC,MAAM,WAAW,GAAG,UAAU,CAC5B,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,GAAG,EAAE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AQ,EACb,OAAO,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC;oBAErC,kCAAO,MAAM,CAAC,KAAK,CAAQ;oBAC1B,MAAM,CAAC,WAAW,IAAI,kCAAO,MAAM,CAAC,WAAW,CAAQ;oBACvD,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,CACxC,iCACG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CACxB,8BAAM,GAAG,EAAE,GAAG,IAAG,GAAG,CAAQ,CAC7B,CAAC,CACE,CACP,CACM,CACL,CACP,CAAC;QACJ,CAAC,CAAC,CACK,CACL,CACP,CAAC,CACE,CACP,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -7,5 +7,10 @@ type TokenFilterProps = {
|
|
|
7
7
|
filteringOptions: QueryFilteringOptions;
|
|
8
8
|
filteringProperties: QueryFilteringProperties;
|
|
9
9
|
};
|
|
10
|
+
/**
|
|
11
|
+
* TODO:
|
|
12
|
+
* - Implement onChange handler to update query state when user selects an autocomplete option.
|
|
13
|
+
* - Handle token rendering and editing (e.g., show tokens for matched properties/operators/values, allow deleting tokens).
|
|
14
|
+
*/
|
|
10
15
|
export declare const TokenFilter: React.ForwardRefExoticComponent<TokenFilterProps & React.RefAttributes<HTMLDivElement>>;
|
|
11
16
|
export {};
|
|
@@ -4,6 +4,11 @@ import { cl } from "../../utils/helpers/index.js";
|
|
|
4
4
|
import { AutoSuggest } from "./AutoSuggest.js";
|
|
5
5
|
import { generateAutoCompleteOptions } from "./helpers/generate-autocomplete-options.js";
|
|
6
6
|
import { parseQueryText } from "./helpers/parse-query-text.js";
|
|
7
|
+
/**
|
|
8
|
+
* TODO:
|
|
9
|
+
* - Implement onChange handler to update query state when user selects an autocomplete option.
|
|
10
|
+
* - Handle token rendering and editing (e.g., show tokens for matched properties/operators/values, allow deleting tokens).
|
|
11
|
+
*/
|
|
7
12
|
export const TokenFilter = forwardRef(({ query, className, filteringProperties, filteringOptions }, ref) => {
|
|
8
13
|
const [inputAnchor, setInputAnchor] = useState(null);
|
|
9
14
|
const [filterText, setFilterText] = useState("");
|
|
@@ -21,11 +26,7 @@ export const TokenFilter = forwardRef(({ query, className, filteringProperties,
|
|
|
21
26
|
setFilterText("");
|
|
22
27
|
setCustomOpen(false);
|
|
23
28
|
} },
|
|
24
|
-
React.createElement(AutoSuggest
|
|
25
|
-
/* @ts-expect-error TODO: handle conversion better */
|
|
26
|
-
, {
|
|
27
|
-
/* @ts-expect-error TODO: handle conversion better */
|
|
28
|
-
options: autoCompleteOptions.options, onSelect: handleSelectOption })),
|
|
29
|
+
React.createElement(AutoSuggest, { options: autoCompleteOptions.options, onSelect: handleSelectOption })),
|
|
29
30
|
query.tokens.map((token, index) => {
|
|
30
31
|
return (React.createElement("div", { key: index, className: "aksel-property-filter__token" },
|
|
31
32
|
React.createElement("strong", null, token.propertyKey),
|
|
@@ -34,7 +35,6 @@ export const TokenFilter = forwardRef(({ query, className, filteringProperties,
|
|
|
34
35
|
" "));
|
|
35
36
|
}),
|
|
36
37
|
React.createElement("ul", null, filteringProperties.map((prop) => (React.createElement("li", { key: prop.key }, prop.propertyLabel)))),
|
|
37
|
-
React.createElement("pre", null, JSON.stringify(queryState, null, 2)),
|
|
38
38
|
React.createElement("pre", null, JSON.stringify(autoCompleteOptions, null, 2))));
|
|
39
39
|
});
|
|
40
40
|
function derrivedFilterState(filteringProperties, filteringOptions) {
|
|
@@ -52,13 +52,12 @@ function derrivedFilterState(filteringProperties, filteringOptions) {
|
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
54
|
const internalOptions = filteringOptions.map((option) => {
|
|
55
|
-
var _a, _b, _c, _d
|
|
55
|
+
var _a, _b, _c, _d;
|
|
56
56
|
return ({
|
|
57
57
|
property: (_a = propertyMap.get(option.propertyKey)) !== null && _a !== void 0 ? _a : null,
|
|
58
58
|
value: option.value,
|
|
59
59
|
label: (_c = (_b = option.label) !== null && _b !== void 0 ? _b : option.value) !== null && _c !== void 0 ? _c : "",
|
|
60
60
|
tags: (_d = option.tags) !== null && _d !== void 0 ? _d : [],
|
|
61
|
-
filteringTags: (_e = option.filteringTags) !== null && _e !== void 0 ? _e : [],
|
|
62
61
|
});
|
|
63
62
|
});
|
|
64
63
|
return { properties: [...propertyMap.values()], options: internalOptions };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TokenFilter.js","sourceRoot":"","sources":["../../../src/data/token-filter/TokenFilter.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,EAAE,EAAE,MAAM,qBAAqB,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAQ5C,OAAO,EAAE,2BAA2B,EAAE,MAAM,yCAAyC,CAAC;AACtF,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAU5D,MAAM,CAAC,MAAM,WAAW,GAAG,UAAU,CACnC,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,EAAE,GAAG,EAAE,EAAE;IACnE,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,CAC5C,IAAI,CACL,CAAC;IAEF,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAS,EAAE,CAAC,CAAC;IACzD,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,mBAAmB,CACjD,mBAAmB,EACnB,gBAAgB,CACjB,CAAC;IAEF,MAAM,UAAU,GAAG,cAAc,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAE1D,MAAM,mBAAmB,GAAG,2BAA2B,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AQ,uBAAR,QAAQ,CAAE,gBAAgB,mCAAI,EAAE;YAClD,aAAa,EAAE,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,KAAK;YAC9B,SAAS,EAAE,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,SAAS,mCAAI,EAAE;YACpC,wDAAwD;YACxD,gBAAgB,EAAE,QAAQ;SAC3B,CAAC,CAAC;IACL,CAAC;IAED,MAAM,eAAe,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;;QAAC,OAAA,CAAC;YACxD,QAAQ,EAAE,MAAA,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,mCAAI,IAAI;YACrD,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,KAAK,EAAE,MAAA,MAAA,MAAM,CAAC,KAAK,mCAAI,MAAM,CAAC,KAAK,mCAAI,EAAE;YACzC,IAAI,EAAE,MAAA,MAAM,CAAC,IAAI,mCAAI,EAAE;SACxB,CAAC,CAAA;KAAA,CAAC,CAAC;IAEJ,OAAO,EAAE,UAAU,EAAE,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,CAAC;AAC7E,CAAC"}
|
|
@@ -14,7 +14,6 @@ type QueryFilteringOption = {
|
|
|
14
14
|
value: any;
|
|
15
15
|
label?: string;
|
|
16
16
|
tags?: string[];
|
|
17
|
-
filteringTags?: string[];
|
|
18
17
|
disabled?: boolean;
|
|
19
18
|
};
|
|
20
19
|
type QueryFilteringOptions = QueryFilteringOption[];
|
|
@@ -47,6 +46,5 @@ type ParsedOption = {
|
|
|
47
46
|
value: any;
|
|
48
47
|
label: string;
|
|
49
48
|
tags: string[];
|
|
50
|
-
filteringTags: string[];
|
|
51
49
|
};
|
|
52
50
|
export type { QueryFilterOperator, QueryFilterQuery, QueryFilteringOptions, QueryFilteringProperty, QueryFilterOperation, QueryFilteringProperties, ParsedProperty, ParsedOption, QueryFilteringOption, QueryFilteringOptionGroup, };
|
|
@@ -14,11 +14,9 @@ import { type ParsedText } from "./parse-query-text.js";
|
|
|
14
14
|
* Used by the UI to determine cursor position and input replacement.
|
|
15
15
|
* - options: Grouped suggestions to display (properties, operators, or values).
|
|
16
16
|
*/
|
|
17
|
-
|
|
17
|
+
type AutoCompleteResult = {
|
|
18
18
|
value: string;
|
|
19
19
|
options: OptionGroup<AutoCompleteOption>[];
|
|
20
|
-
} | {
|
|
21
|
-
value: string;
|
|
22
|
-
options: OptionGroup<ParsedProperty>[];
|
|
23
20
|
};
|
|
21
|
+
declare function generateAutoCompleteOptions(queryState: ParsedText, filteringProperties?: ParsedProperty[], filteringOptions?: ParsedOption[]): AutoCompleteResult;
|
|
24
22
|
export { generateAutoCompleteOptions };
|
|
@@ -2,19 +2,6 @@ import { createGroups } from "./grouping.js";
|
|
|
2
2
|
import { QUERY_OPERATORS } from "./operators.js";
|
|
3
3
|
import { OPERATOR_LABELS, buildQueryString } from "./query-builder.js";
|
|
4
4
|
import { matchesFilterText } from "./text-matching.js";
|
|
5
|
-
/**
|
|
6
|
-
* Generates "options" to be used as autosuggest-ottion based on the current query state.
|
|
7
|
-
*
|
|
8
|
-
* The query parser recognizes three states:
|
|
9
|
-
* - "property": User has selected/matched a property and operator ("Status = active")
|
|
10
|
-
* - "operator": User has matched a property but is typing the operator ("Status" or "Status !")
|
|
11
|
-
* - "free-text": User is typing freely without a property match (e.g., "act" or "!: test")
|
|
12
|
-
*
|
|
13
|
-
* @returns
|
|
14
|
-
* - value: The canonical query string representation for the current state.
|
|
15
|
-
* Used by the UI to determine cursor position and input replacement.
|
|
16
|
-
* - options: Grouped suggestions to display (properties, operators, or values).
|
|
17
|
-
*/
|
|
18
5
|
function generateAutoCompleteOptions(queryState, filteringProperties = [], filteringOptions = []) {
|
|
19
6
|
var _a;
|
|
20
7
|
/* State: Property and operator are matched, suggest values */
|
|
@@ -33,9 +20,6 @@ function generateAutoCompleteOptions(queryState, filteringProperties = [], filte
|
|
|
33
20
|
* Edge case: User typed an invalid operator prefix that doesn't match any operators.
|
|
34
21
|
* This can happen when typing characters that don't start any valid operator.
|
|
35
22
|
* Return empty suggestions gracefully - the UI will show "no results".
|
|
36
|
-
*
|
|
37
|
-
* TODO: When per-property operator configuration is implemented,
|
|
38
|
-
* this could also occur when a property restricts which operators are valid.
|
|
39
23
|
*/
|
|
40
24
|
if (operators.length === 0) {
|
|
41
25
|
return {
|
|
@@ -71,7 +55,10 @@ function generateAutoCompleteOptions(queryState, filteringProperties = [], filte
|
|
|
71
55
|
*/
|
|
72
56
|
return {
|
|
73
57
|
value: queryState.value,
|
|
74
|
-
options:
|
|
58
|
+
options: [
|
|
59
|
+
...generatePropertySuggestions(filteringProperties, queryState.value),
|
|
60
|
+
...createValueSuggestions(filteringOptions, (_a = queryState.operator) !== null && _a !== void 0 ? _a : "=", queryState.value),
|
|
61
|
+
],
|
|
75
62
|
};
|
|
76
63
|
}
|
|
77
64
|
/**
|
|
@@ -125,7 +112,14 @@ function generatePropertySuggestions(filteringProperties = [], filterText = "")
|
|
|
125
112
|
filteredProperties.push(property);
|
|
126
113
|
}
|
|
127
114
|
}
|
|
128
|
-
|
|
115
|
+
const groups = createGroups(filteredProperties, (property) => property.propertyGroup, "Properties");
|
|
116
|
+
return groups.map((group) => ({
|
|
117
|
+
label: group.label,
|
|
118
|
+
options: group.options.map((property) => ({
|
|
119
|
+
value: buildQueryString(property.propertyLabel, "", ""),
|
|
120
|
+
label: property.propertyLabel,
|
|
121
|
+
})),
|
|
122
|
+
}));
|
|
129
123
|
}
|
|
130
124
|
function generateOperatorSuggestions(property, operatorPrefix = "") {
|
|
131
125
|
const operators = filterOperatorsByPrefix(getValidOperatorsForProperty(property), operatorPrefix);
|
|
@@ -150,9 +144,11 @@ function generateOperatorSuggestions(property, operatorPrefix = "") {
|
|
|
150
144
|
* Creates value suggestions for autocomplete.
|
|
151
145
|
* When scopedProperty is provided, only shows values for that property (single group).
|
|
152
146
|
* When scopedProperty is omitted, searches across all properties (multiple groups).
|
|
147
|
+
* TODO: This could potentially contain an unlimited number of options if there are many values across properties.
|
|
148
|
+
* May need virtualization/async or other filtering mechanism.
|
|
153
149
|
*/
|
|
154
150
|
function createValueSuggestions(filteringOptions = [], operator, filterText = "", scopedProperty) {
|
|
155
|
-
var _a
|
|
151
|
+
var _a;
|
|
156
152
|
const groups = {};
|
|
157
153
|
for (const option of filteringOptions) {
|
|
158
154
|
if (!(option === null || option === void 0 ? void 0 : option.property)) {
|
|
@@ -163,11 +159,7 @@ function createValueSuggestions(filteringOptions = [], operator, filterText = ""
|
|
|
163
159
|
continue;
|
|
164
160
|
}
|
|
165
161
|
/* Build search fields */
|
|
166
|
-
const searchFields = [
|
|
167
|
-
option.label,
|
|
168
|
-
...((_a = option.tags) !== null && _a !== void 0 ? _a : []),
|
|
169
|
-
...((_b = option.filteringTags) !== null && _b !== void 0 ? _b : []),
|
|
170
|
-
];
|
|
162
|
+
const searchFields = [option.label, ...((_a = option.tags) !== null && _a !== void 0 ? _a : [])];
|
|
171
163
|
if (!scopedProperty) {
|
|
172
164
|
searchFields.push(option.property.propertyLabel);
|
|
173
165
|
}
|
|
@@ -186,7 +178,6 @@ function createValueSuggestions(filteringOptions = [], operator, filterText = ""
|
|
|
186
178
|
value: buildQueryString(option.property.propertyLabel, operator, option.value),
|
|
187
179
|
label: option.label,
|
|
188
180
|
tags: option.tags,
|
|
189
|
-
filteringTags: option.filteringTags,
|
|
190
181
|
});
|
|
191
182
|
}
|
|
192
183
|
return Object.values(groups).filter((group) => group.options.length > 0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-autocomplete-options.js","sourceRoot":"","sources":["../../../../src/data/token-filter/helpers/generate-autocomplete-options.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"generate-autocomplete-options.js","sourceRoot":"","sources":["../../../../src/data/token-filter/helpers/generate-autocomplete-options.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAoBpD,SAAS,2BAA2B,CAClC,UAAsB,EACtB,sBAAwC,EAAE,EAC1C,mBAAmC,EAAE;;IAErC,8DAA8D;IAC9D,IAAI,UAAU,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;QACnC,MAAM,UAAU,GAAG,UAAU,CAAC,KAAK,IAAI,EAAE,CAAC;QAE1C,OAAO;YACL,KAAK,EAAE,UAAU,CAAC,KAAK;YACvB,OAAO,EAAE,sBAAsB,CAC7B,gBAAgB,EAChB,UAAU,CAAC,QAAQ,EACnB,UAAU,EACV,UAAU,CAAC,QAAQ,CACpB;SACF,CAAC;IACJ,CAAC;IAED,yDAAyD;IACzD,IAAI,UAAU,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;QACnC,MAAM,SAAS,GAAG,uBAAuB,CACvC,4BAA4B,CAAC,UAAU,CAAC,QAAQ,CAAC,EACjD,UAAU,CAAC,cAAc,CAC1B,CAAC;QAEF,MAAM,YAAY,GAAG,gBAAgB,CACnC,UAAU,CAAC,QAAQ,CAAC,aAAa,EACjC,UAAU,CAAC,cAAc,EACzB,EAAE,CACH,CAAC;QAEF;;;;WAIG;QACH,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC3B,OAAO;gBACL,KAAK,EAAE,YAAY;gBACnB,OAAO,E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AAK,EAAE,GAAG,CAAC,MAAA,MAAM,CAAC,IAAI,mCAAI,EAAE,CAAC,CAAC,CAAC;QAE5D,IAAI,CAAC,cAAc,EAAE,CAAC;YACpB,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;QACnD,CAAC;QAED,MAAM,OAAO,GAAG,iBAAiB,CAAC,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,UAAU,CAAC,CAAC;QAE5E,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,SAAS;QACX,CAAC;QAED,MAAM,UAAU,GAAG,MAAM,CAAC,QAAQ,CAAC,gBAAgB,IAAI,QAAQ,CAAC;QAEhE,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;YACxB,MAAM,CAAC,UAAU,CAAC,GAAG;gBACnB,KAAK,EAAE,UAAU;gBACjB,OAAO,EAAE,EAAE;aACZ,CAAC;QACJ,CAAC;QAED,MAAM,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC;YAC9B,KAAK,EAAE,gBAAgB,CACrB,MAAM,CAAC,QAAQ,CAAC,aAAa,EAC7B,QAAQ,EACR,MAAM,CAAC,KAAK,CACb;YACD,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,IAAI,EAAE,MAAM,CAAC,IAAI;SAClB,CAAC,CAAC;IACL,CAAC;IAED,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAC3E,CAAC;AAED,OAAO,EAAE,2BAA2B,EAAE,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useState } from "react";
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
2
|
import { useControllableState } from "../utils/hooks/index.js";
|
|
3
3
|
export function useToggleGroup({ onChange, value, defaultValue = "", }) {
|
|
4
4
|
const [focusedValue, setFocusedValue] = useState(defaultValue);
|
|
@@ -8,9 +8,11 @@ export function useToggleGroup({ onChange, value, defaultValue = "", }) {
|
|
|
8
8
|
onChange,
|
|
9
9
|
});
|
|
10
10
|
/* Sync focused `value` with controlled `selectedValue` */
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
if (value != null) {
|
|
13
|
+
setFocusedValue(value);
|
|
14
|
+
}
|
|
15
|
+
}, [value]);
|
|
14
16
|
return {
|
|
15
17
|
selectedValue,
|
|
16
18
|
setSelectedValue,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useToggleGroup.js","sourceRoot":"","sources":["../../src/toggle-group/useToggleGroup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"useToggleGroup.js","sourceRoot":"","sources":["../../src/toggle-group/useToggleGroup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAGtD,MAAM,UAAU,cAAc,CAAC,EAC7B,QAAQ,EACR,KAAK,EACL,YAAY,GAAG,EAAE,GAC6C;IAC9D,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAC;IAC/D,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,oBAAoB,CAAC;QAC7D,YAAY;QACZ,KAAK;QACL,QAAQ;KACT,CAAC,CAAC;IAEH,0DAA0D;IAC1D,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;YAClB,eAAe,CAAC,KAAK,CAAC,CAAC;QACzB,CAAC;IACH,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEZ,OAAO;QACL,aAAa;QACb,gBAAgB;QAChB,YAAY;QACZ,eAAe;KAChB,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@navikt/ds-react",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.6.0",
|
|
4
4
|
"description": "React components from the Norwegian Labour and Welfare Administration.",
|
|
5
5
|
"author": "Aksel, a team part of the Norwegian Labour and Welfare Administration.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -705,8 +705,8 @@
|
|
|
705
705
|
"dependencies": {
|
|
706
706
|
"@floating-ui/react": "0.27.8",
|
|
707
707
|
"@floating-ui/react-dom": "^2.1.6",
|
|
708
|
-
"@navikt/aksel-icons": "^8.
|
|
709
|
-
"@navikt/ds-tokens": "^8.
|
|
708
|
+
"@navikt/aksel-icons": "^8.6.0",
|
|
709
|
+
"@navikt/ds-tokens": "^8.6.0",
|
|
710
710
|
"date-fns": "^4.0.0",
|
|
711
711
|
"react-day-picker": "9.7.0"
|
|
712
712
|
},
|
|
@@ -23,15 +23,9 @@ const AutoSuggest = forwardRef<HTMLDivElement, AutoSuggestProps>(
|
|
|
23
23
|
<div key={option.value}>
|
|
24
24
|
<button
|
|
25
25
|
type="button"
|
|
26
|
-
onClick={() =>
|
|
27
|
-
/* @ts-expect-error TODO: We need to convert the data properly */
|
|
28
|
-
onSelect(option.value ?? option.propertyKey)
|
|
29
|
-
}
|
|
26
|
+
onClick={() => onSelect(option.value)}
|
|
30
27
|
>
|
|
31
|
-
<span>
|
|
32
|
-
{/* @ts-expect-error TODO: We need to convert the data properly */}
|
|
33
|
-
{option.value ?? option.label ?? option.propertyLabel}
|
|
34
|
-
</span>
|
|
28
|
+
<span>{option.label}</span>
|
|
35
29
|
{option.description && <span>{option.description}</span>}
|
|
36
30
|
{option.tags && option.tags.length > 0 && (
|
|
37
31
|
<div>
|
|
@@ -20,6 +20,11 @@ type TokenFilterProps = {
|
|
|
20
20
|
filteringProperties: QueryFilteringProperties;
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
+
/**
|
|
24
|
+
* TODO:
|
|
25
|
+
* - Implement onChange handler to update query state when user selects an autocomplete option.
|
|
26
|
+
* - Handle token rendering and editing (e.g., show tokens for matched properties/operators/values, allow deleting tokens).
|
|
27
|
+
*/
|
|
23
28
|
export const TokenFilter = forwardRef<HTMLDivElement, TokenFilterProps>(
|
|
24
29
|
({ query, className, filteringProperties, filteringOptions }, ref) => {
|
|
25
30
|
const [inputAnchor, setInputAnchor] = useState<HTMLInputElement | null>(
|
|
@@ -71,7 +76,6 @@ export const TokenFilter = forwardRef<HTMLDivElement, TokenFilterProps>(
|
|
|
71
76
|
}}
|
|
72
77
|
>
|
|
73
78
|
<AutoSuggest
|
|
74
|
-
/* @ts-expect-error TODO: handle conversion better */
|
|
75
79
|
options={autoCompleteOptions.options}
|
|
76
80
|
onSelect={handleSelectOption}
|
|
77
81
|
/>
|
|
@@ -88,7 +92,7 @@ export const TokenFilter = forwardRef<HTMLDivElement, TokenFilterProps>(
|
|
|
88
92
|
<li key={prop.key}>{prop.propertyLabel}</li>
|
|
89
93
|
))}
|
|
90
94
|
</ul>
|
|
91
|
-
<pre>{JSON.stringify(queryState, null, 2)}</pre>
|
|
95
|
+
{/* <pre>{JSON.stringify(queryState, null, 2)}</pre> */}
|
|
92
96
|
<pre>{JSON.stringify(autoCompleteOptions, null, 2)}</pre>
|
|
93
97
|
</div>
|
|
94
98
|
);
|
|
@@ -122,7 +126,6 @@ function derrivedFilterState(
|
|
|
122
126
|
value: option.value,
|
|
123
127
|
label: option.label ?? option.value ?? "",
|
|
124
128
|
tags: option.tags ?? [],
|
|
125
|
-
filteringTags: option.filteringTags ?? [],
|
|
126
129
|
}));
|
|
127
130
|
|
|
128
131
|
return { properties: [...propertyMap.values()], options: internalOptions };
|
|
@@ -29,7 +29,6 @@ type QueryFilteringOption = {
|
|
|
29
29
|
value: any;
|
|
30
30
|
label?: string;
|
|
31
31
|
tags?: string[];
|
|
32
|
-
filteringTags?: string[];
|
|
33
32
|
disabled?: boolean;
|
|
34
33
|
};
|
|
35
34
|
|
|
@@ -68,7 +67,6 @@ type ParsedOption = {
|
|
|
68
67
|
value: any;
|
|
69
68
|
label: string;
|
|
70
69
|
tags: string[];
|
|
71
|
-
filteringTags: string[];
|
|
72
70
|
};
|
|
73
71
|
|
|
74
72
|
export type {
|
|
@@ -71,7 +71,6 @@ const parsedOptions: ParsedOption[] = allOptions.map((option) => {
|
|
|
71
71
|
value: option.value,
|
|
72
72
|
label: option.label || String(option.value),
|
|
73
73
|
tags: option.tags || [],
|
|
74
|
-
filteringTags: option.filteringTags || [],
|
|
75
74
|
};
|
|
76
75
|
});
|
|
77
76
|
|
|
@@ -671,63 +670,6 @@ describe("generateAutoCompleteOptions v2", () => {
|
|
|
671
670
|
});
|
|
672
671
|
});
|
|
673
672
|
|
|
674
|
-
describe("filtering tags and metadata", () => {
|
|
675
|
-
test("should match filteringTags in search", () => {
|
|
676
|
-
const optionsWithFilteringTags: ParsedOption[] = [
|
|
677
|
-
{
|
|
678
|
-
property: parsedProperties[1],
|
|
679
|
-
value: "special-region",
|
|
680
|
-
label: "Special Region",
|
|
681
|
-
tags: [],
|
|
682
|
-
filteringTags: ["premium", "exclusive"],
|
|
683
|
-
},
|
|
684
|
-
];
|
|
685
|
-
|
|
686
|
-
const queryState: ParsedText = {
|
|
687
|
-
step: "free-text",
|
|
688
|
-
value: "premium",
|
|
689
|
-
};
|
|
690
|
-
|
|
691
|
-
const result = generateAutoCompleteOptions(
|
|
692
|
-
queryState,
|
|
693
|
-
parsedProperties,
|
|
694
|
-
optionsWithFilteringTags,
|
|
695
|
-
);
|
|
696
|
-
|
|
697
|
-
const regionGroup = result.options.find(
|
|
698
|
-
(g) => g.label === "Region values",
|
|
699
|
-
);
|
|
700
|
-
expect(regionGroup?.options).toHaveLength(1);
|
|
701
|
-
expect((regionGroup?.options[0] as AutoCompleteOption).label).toBe(
|
|
702
|
-
"Special Region",
|
|
703
|
-
);
|
|
704
|
-
});
|
|
705
|
-
|
|
706
|
-
test("should preserve tags and filteringTags in suggestions", () => {
|
|
707
|
-
const queryState: ParsedText = {
|
|
708
|
-
step: "free-text",
|
|
709
|
-
value: "region",
|
|
710
|
-
};
|
|
711
|
-
|
|
712
|
-
const result = generateAutoCompleteOptions(
|
|
713
|
-
queryState,
|
|
714
|
-
parsedProperties,
|
|
715
|
-
parsedOptions,
|
|
716
|
-
);
|
|
717
|
-
|
|
718
|
-
const regionGroup = result.options.find(
|
|
719
|
-
(g) => g.label === "Region values",
|
|
720
|
-
);
|
|
721
|
-
const usEastOption = regionGroup?.options.find(
|
|
722
|
-
(o) => (o as AutoCompleteOption).label === "US East",
|
|
723
|
-
) as AutoCompleteOption;
|
|
724
|
-
|
|
725
|
-
expect(usEastOption).toBeDefined();
|
|
726
|
-
expect(usEastOption.tags).toContain("north america");
|
|
727
|
-
expect(usEastOption.tags).toContain("usa");
|
|
728
|
-
});
|
|
729
|
-
});
|
|
730
|
-
|
|
731
673
|
describe("properties with no groupValuesLabel", () => {
|
|
732
674
|
test("should default to 'Values' when groupValuesLabel is empty", () => {
|
|
733
675
|
const propertyWithoutGroupLabel: ParsedProperty = {
|
|
@@ -748,7 +690,6 @@ describe("generateAutoCompleteOptions v2", () => {
|
|
|
748
690
|
value: "val1",
|
|
749
691
|
label: "Value 1",
|
|
750
692
|
tags: [],
|
|
751
|
-
filteringTags: [],
|
|
752
693
|
},
|
|
753
694
|
];
|
|
754
695
|
|
|
@@ -777,7 +718,6 @@ describe("generateAutoCompleteOptions v2", () => {
|
|
|
777
718
|
value: "orphaned",
|
|
778
719
|
label: "Orphaned Value",
|
|
779
720
|
tags: [],
|
|
780
|
-
filteringTags: [],
|
|
781
721
|
},
|
|
782
722
|
...parsedOptions,
|
|
783
723
|
];
|
|
@@ -23,11 +23,16 @@ import { matchesFilterText } from "./text-matching";
|
|
|
23
23
|
* Used by the UI to determine cursor position and input replacement.
|
|
24
24
|
* - options: Grouped suggestions to display (properties, operators, or values).
|
|
25
25
|
*/
|
|
26
|
+
type AutoCompleteResult = {
|
|
27
|
+
value: string;
|
|
28
|
+
options: OptionGroup<AutoCompleteOption>[];
|
|
29
|
+
};
|
|
30
|
+
|
|
26
31
|
function generateAutoCompleteOptions(
|
|
27
32
|
queryState: ParsedText,
|
|
28
33
|
filteringProperties: ParsedProperty[] = [],
|
|
29
34
|
filteringOptions: ParsedOption[] = [],
|
|
30
|
-
) {
|
|
35
|
+
): AutoCompleteResult {
|
|
31
36
|
/* State: Property and operator are matched, suggest values */
|
|
32
37
|
if (queryState.step === "property") {
|
|
33
38
|
const filterText = queryState.value || "";
|
|
@@ -60,9 +65,6 @@ function generateAutoCompleteOptions(
|
|
|
60
65
|
* Edge case: User typed an invalid operator prefix that doesn't match any operators.
|
|
61
66
|
* This can happen when typing characters that don't start any valid operator.
|
|
62
67
|
* Return empty suggestions gracefully - the UI will show "no results".
|
|
63
|
-
*
|
|
64
|
-
* TODO: When per-property operator configuration is implemented,
|
|
65
|
-
* this could also occur when a property restricts which operators are valid.
|
|
66
68
|
*/
|
|
67
69
|
if (operators.length === 0) {
|
|
68
70
|
return {
|
|
@@ -105,11 +107,14 @@ function generateAutoCompleteOptions(
|
|
|
105
107
|
*/
|
|
106
108
|
return {
|
|
107
109
|
value: queryState.value,
|
|
108
|
-
options:
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
110
|
+
options: [
|
|
111
|
+
...generatePropertySuggestions(filteringProperties, queryState.value),
|
|
112
|
+
...createValueSuggestions(
|
|
113
|
+
filteringOptions,
|
|
114
|
+
queryState.operator ?? "=",
|
|
115
|
+
queryState.value,
|
|
116
|
+
),
|
|
117
|
+
],
|
|
113
118
|
};
|
|
114
119
|
}
|
|
115
120
|
|
|
@@ -168,7 +173,7 @@ function filterOperatorsByPrefix(
|
|
|
168
173
|
function generatePropertySuggestions(
|
|
169
174
|
filteringProperties: ParsedProperty[] = [],
|
|
170
175
|
filterText = "",
|
|
171
|
-
): OptionGroup<
|
|
176
|
+
): OptionGroup<AutoCompleteOption>[] {
|
|
172
177
|
const filteredProperties: ParsedProperty[] = [];
|
|
173
178
|
|
|
174
179
|
for (const property of filteringProperties) {
|
|
@@ -190,11 +195,19 @@ function generatePropertySuggestions(
|
|
|
190
195
|
}
|
|
191
196
|
}
|
|
192
197
|
|
|
193
|
-
|
|
198
|
+
const groups = createGroups(
|
|
194
199
|
filteredProperties,
|
|
195
200
|
(property) => property.propertyGroup,
|
|
196
201
|
"Properties",
|
|
197
202
|
);
|
|
203
|
+
|
|
204
|
+
return groups.map((group) => ({
|
|
205
|
+
label: group.label,
|
|
206
|
+
options: group.options.map((property) => ({
|
|
207
|
+
value: buildQueryString(property.propertyLabel, "", ""),
|
|
208
|
+
label: property.propertyLabel,
|
|
209
|
+
})),
|
|
210
|
+
}));
|
|
198
211
|
}
|
|
199
212
|
|
|
200
213
|
function generateOperatorSuggestions(
|
|
@@ -226,6 +239,8 @@ function generateOperatorSuggestions(
|
|
|
226
239
|
* Creates value suggestions for autocomplete.
|
|
227
240
|
* When scopedProperty is provided, only shows values for that property (single group).
|
|
228
241
|
* When scopedProperty is omitted, searches across all properties (multiple groups).
|
|
242
|
+
* TODO: This could potentially contain an unlimited number of options if there are many values across properties.
|
|
243
|
+
* May need virtualization/async or other filtering mechanism.
|
|
229
244
|
*/
|
|
230
245
|
function createValueSuggestions(
|
|
231
246
|
filteringOptions: ParsedOption[] = [],
|
|
@@ -246,11 +261,7 @@ function createValueSuggestions(
|
|
|
246
261
|
}
|
|
247
262
|
|
|
248
263
|
/* Build search fields */
|
|
249
|
-
const searchFields = [
|
|
250
|
-
option.label,
|
|
251
|
-
...(option.tags ?? []),
|
|
252
|
-
...(option.filteringTags ?? []),
|
|
253
|
-
];
|
|
264
|
+
const searchFields = [option.label, ...(option.tags ?? [])];
|
|
254
265
|
|
|
255
266
|
if (!scopedProperty) {
|
|
256
267
|
searchFields.push(option.property.propertyLabel);
|
|
@@ -279,7 +290,6 @@ function createValueSuggestions(
|
|
|
279
290
|
),
|
|
280
291
|
label: option.label,
|
|
281
292
|
tags: option.tags,
|
|
282
|
-
filteringTags: option.filteringTags,
|
|
283
293
|
});
|
|
284
294
|
}
|
|
285
295
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useState } from "react";
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
2
|
import { useControllableState } from "../utils/hooks";
|
|
3
3
|
import { ToggleGroupProps } from "./ToggleGroup.types";
|
|
4
4
|
|
|
@@ -8,7 +8,6 @@ export function useToggleGroup({
|
|
|
8
8
|
defaultValue = "",
|
|
9
9
|
}: Pick<ToggleGroupProps, "onChange" | "value" | "defaultValue">) {
|
|
10
10
|
const [focusedValue, setFocusedValue] = useState(defaultValue);
|
|
11
|
-
|
|
12
11
|
const [selectedValue, setSelectedValue] = useControllableState({
|
|
13
12
|
defaultValue,
|
|
14
13
|
value,
|
|
@@ -16,9 +15,11 @@ export function useToggleGroup({
|
|
|
16
15
|
});
|
|
17
16
|
|
|
18
17
|
/* Sync focused `value` with controlled `selectedValue` */
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (value != null) {
|
|
20
|
+
setFocusedValue(value);
|
|
21
|
+
}
|
|
22
|
+
}, [value]);
|
|
22
23
|
|
|
23
24
|
return {
|
|
24
25
|
selectedValue,
|