@wallarm-org/design-system 1.0.0-rc-feature-AS-877-fix-filter-code.1 → 1.0.0-rc-feature-AS-877-fix-filter-code.2
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/dist/components/FilterInput/FilterInput.js +5 -1
- package/dist/components/FilterInput/index.d.ts +1 -1
- package/dist/components/FilterInput/lib/applyFieldPresets.d.ts +8 -0
- package/dist/components/FilterInput/lib/applyFieldPresets.js +27 -0
- package/dist/components/FilterInput/lib/index.d.ts +1 -0
- package/dist/components/FilterInput/lib/index.js +2 -1
- package/dist/components/FilterInput/types.d.ts +13 -0
- package/dist/metadata/components.json +2 -3
- package/package.json +1 -1
|
@@ -6,7 +6,8 @@ import { FilterInputErrors, parseFilterInputErrors } from "./FilterInputErrors/i
|
|
|
6
6
|
import { FilterInputField } from "./FilterInputField/index.js";
|
|
7
7
|
import { FilterInputMenu } from "./FilterInputMenu/FilterInputMenu.js";
|
|
8
8
|
import { useFilterInputAutocomplete, useFilterInputExpression, useFilterInputSelection } from "./hooks/index.js";
|
|
9
|
-
|
|
9
|
+
import { applyFieldPresets } from "./lib/applyFieldPresets.js";
|
|
10
|
+
const FilterInput = ({ fields: rawFields = [], value, onChange, placeholder = 'Type to filter...', error = false, showKeyboardHint = false, className, ...props })=>{
|
|
10
11
|
const inputRef = useRef(null);
|
|
11
12
|
const containerRef = useRef(null);
|
|
12
13
|
const buildingChipRef = useRef(null);
|
|
@@ -15,6 +16,9 @@ const FilterInput = ({ fields = [], value, onChange, placeholder = 'Type to filt
|
|
|
15
16
|
if (el) chipRegistryRef.current.set(id, el);
|
|
16
17
|
else chipRegistryRef.current.delete(id);
|
|
17
18
|
}, []);
|
|
19
|
+
const fields = useMemo(()=>applyFieldPresets(rawFields), [
|
|
20
|
+
rawFields
|
|
21
|
+
]);
|
|
18
22
|
const { conditions, connectors, chips, upsertCondition, removeCondition, removeConditionAtIndex, clearAll, setConnectorValue } = useFilterInputExpression({
|
|
19
23
|
fields,
|
|
20
24
|
value,
|
|
@@ -2,4 +2,4 @@ export { FilterInput, type FilterInputProps } from './FilterInput';
|
|
|
2
2
|
export { FilterInputChip, type FilterInputChipProps } from './FilterInputField';
|
|
3
3
|
export { FilterInputFieldMenu, type FilterInputFieldMenuProps, FilterInputOperatorMenu, type FilterInputOperatorMenuProps, FilterInputValueMenu, type FilterInputValueMenuProps, type ValueOption, } from './FilterInputMenu';
|
|
4
4
|
export { createStatusCodeInputFilter, createStatusCodeNormalizer, createStatusCodeSuggestions, createStatusCodeValidator, type FilterParseError, isFilterParseError, parseExpression, serializeExpression, } from './lib';
|
|
5
|
-
export type { Condition, ExprNode, FieldMetadata, FieldType, FieldValueOption, FilterInputChipData, FilterInputChipVariant, FilterOperator, Group, } from './types';
|
|
5
|
+
export type { Condition, ExprNode, FieldMetadata, FieldPreset, FieldType, FieldValueOption, FilterInputChipData, FilterInputChipVariant, FilterOperator, Group, } from './types';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { FieldMetadata } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Resolve `FieldMetadata.preset` into concrete helpers. Consumer-supplied
|
|
4
|
+
* callbacks (`acceptChar` / `normalize` / `getSuggestions` / `validate`)
|
|
5
|
+
* always win over the preset so individual fields can still override parts
|
|
6
|
+
* of a preset when needed.
|
|
7
|
+
*/
|
|
8
|
+
export declare const applyFieldPresets: (fields: FieldMetadata[]) => FieldMetadata[];
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createStatusCodeInputFilter, createStatusCodeNormalizer, createStatusCodeSuggestions, createStatusCodeValidator } from "./statusCode/index.js";
|
|
2
|
+
const PRESET_HELPERS = {
|
|
3
|
+
status_code: ()=>({
|
|
4
|
+
acceptChar: createStatusCodeInputFilter(),
|
|
5
|
+
normalize: createStatusCodeNormalizer(),
|
|
6
|
+
getSuggestions: createStatusCodeSuggestions(),
|
|
7
|
+
validate: createStatusCodeValidator()
|
|
8
|
+
})
|
|
9
|
+
};
|
|
10
|
+
const applyFieldPresets = (fields)=>{
|
|
11
|
+
let changed = false;
|
|
12
|
+
const out = fields.map((field)=>{
|
|
13
|
+
if (!field.preset) return field;
|
|
14
|
+
const helpers = PRESET_HELPERS[field.preset]?.();
|
|
15
|
+
if (!helpers) return field;
|
|
16
|
+
changed = true;
|
|
17
|
+
return {
|
|
18
|
+
...field,
|
|
19
|
+
acceptChar: field.acceptChar ?? helpers.acceptChar,
|
|
20
|
+
normalize: field.normalize ?? helpers.normalize,
|
|
21
|
+
getSuggestions: field.getSuggestions ?? helpers.getSuggestions,
|
|
22
|
+
validate: field.validate ?? helpers.validate
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
return changed ? out : fields;
|
|
26
|
+
};
|
|
27
|
+
export { applyFieldPresets };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export type { DatePreset } from '../FilterInputMenu/FilterInputDateValueMenu/constants';
|
|
2
2
|
export { DATE_PRESETS, formatDateForChip, getDateDisplayLabel, isDatePreset, } from '../FilterInputMenu/FilterInputDateValueMenu/constants';
|
|
3
3
|
export { applyAcceptChar } from './applyAcceptChar';
|
|
4
|
+
export { applyFieldPresets } from './applyFieldPresets';
|
|
4
5
|
export { chipIdToConditionIndex, findChipSplitIndex } from './conditions';
|
|
5
6
|
export { CONNECTOR_ID_PATTERN, NO_VALUE_OPERATORS, OPERATOR_LABELS, OPERATOR_LABELS_BY_TYPE, OPERATOR_SYMBOLS, OPERATORS_BY_TYPE, QUERY_BAR_SELECTOR, VARIANT_LABELS, } from './constants';
|
|
6
7
|
export { buildContainerAnchoredRect, isMenuRelated } from './dom';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DATE_PRESETS, formatDateForChip, getDateDisplayLabel, isDatePreset } from "../FilterInputMenu/FilterInputDateValueMenu/constants.js";
|
|
2
2
|
import { applyAcceptChar } from "./applyAcceptChar.js";
|
|
3
|
+
import { applyFieldPresets } from "./applyFieldPresets.js";
|
|
3
4
|
import { chipIdToConditionIndex, findChipSplitIndex } from "./conditions.js";
|
|
4
5
|
import { CONNECTOR_ID_PATTERN, NO_VALUE_OPERATORS, OPERATORS_BY_TYPE, OPERATOR_LABELS, OPERATOR_LABELS_BY_TYPE, OPERATOR_SYMBOLS, QUERY_BAR_SELECTOR, VARIANT_LABELS } from "./constants.js";
|
|
5
6
|
import { buildContainerAnchoredRect, isMenuRelated } from "./dom.js";
|
|
@@ -10,4 +11,4 @@ import { getOperatorFromLabel, getOperatorLabel, isBetweenOperator, isMultiSelec
|
|
|
10
11
|
import { isFilterParseError, parseExpression } from "./parseExpression/index.js";
|
|
11
12
|
import { serializeExpression } from "./serializeExpression.js";
|
|
12
13
|
import { createStatusCodeInputFilter, createStatusCodeNormalizer, createStatusCodeSuggestions, createStatusCodeValidator } from "./statusCode/index.js";
|
|
13
|
-
export { CONNECTOR_ID_PATTERN, DATE_PRESETS, NO_VALUE_OPERATORS, OPERATORS_BY_TYPE, OPERATOR_LABELS, OPERATOR_LABELS_BY_TYPE, OPERATOR_SYMBOLS, QUERY_BAR_SELECTOR, VARIANT_LABELS, applyAcceptChar, buildContainerAnchoredRect, chipIdToConditionIndex, createStatusCodeInputFilter, createStatusCodeNormalizer, createStatusCodeSuggestions, createStatusCodeValidator, filterAndSort, findChipSplitIndex, formatDateForChip, getCurrentValueTokenText, getDateDisplayLabel, getFieldValues, getOperatorFromLabel, getOperatorLabel, getValueFilterText, hasFieldValues, hasStaticAllowlist, isBetweenOperator, isDatePreset, isFilterParseError, isMenuRelated, isMultiSelectOperator, isNoValueOperator, parseExpression, serializeExpression };
|
|
14
|
+
export { CONNECTOR_ID_PATTERN, DATE_PRESETS, NO_VALUE_OPERATORS, OPERATORS_BY_TYPE, OPERATOR_LABELS, OPERATOR_LABELS_BY_TYPE, OPERATOR_SYMBOLS, QUERY_BAR_SELECTOR, VARIANT_LABELS, applyAcceptChar, applyFieldPresets, buildContainerAnchoredRect, chipIdToConditionIndex, createStatusCodeInputFilter, createStatusCodeNormalizer, createStatusCodeSuggestions, createStatusCodeValidator, filterAndSort, findChipSplitIndex, formatDateForChip, getCurrentValueTokenText, getDateDisplayLabel, getFieldValues, getOperatorFromLabel, getOperatorLabel, getValueFilterText, hasFieldValues, hasStaticAllowlist, isBetweenOperator, isDatePreset, isFilterParseError, isMenuRelated, isMultiSelectOperator, isNoValueOperator, parseExpression, serializeExpression };
|
|
@@ -44,6 +44,13 @@ export interface FieldValueOption {
|
|
|
44
44
|
text: string;
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Built-in field presets. Setting `preset` on a `FieldMetadata` wires the
|
|
49
|
+
* corresponding factory helpers into `acceptChar` / `normalize` /
|
|
50
|
+
* `getSuggestions` / `validate` automatically. Consumer-supplied callbacks
|
|
51
|
+
* always win over the preset.
|
|
52
|
+
*/
|
|
53
|
+
export type FieldPreset = 'status_code';
|
|
47
54
|
/**
|
|
48
55
|
* Field Metadata Interface
|
|
49
56
|
* Matches backend structure for field definitions
|
|
@@ -56,6 +63,12 @@ export interface FieldMetadata {
|
|
|
56
63
|
operators?: FilterOperator[];
|
|
57
64
|
default?: string | number | boolean;
|
|
58
65
|
values?: FieldValueOption[];
|
|
66
|
+
/**
|
|
67
|
+
* Built-in DS preset that wires masking / validation / suggestions without
|
|
68
|
+
* requiring the consumer to import the factory helpers themselves. Any
|
|
69
|
+
* callback explicitly provided on this `FieldMetadata` wins over the preset.
|
|
70
|
+
*/
|
|
71
|
+
preset?: FieldPreset;
|
|
59
72
|
/**
|
|
60
73
|
* Shorthand for simple string values (e.g. `["GET", "POST", "PUT"]`).
|
|
61
74
|
* Automatically converted to `FieldValueOption[]` where `value === label`.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": "0.27.0",
|
|
3
|
-
"generatedAt": "2026-04-20T14:
|
|
3
|
+
"generatedAt": "2026-04-20T14:56:46.717Z",
|
|
4
4
|
"components": [
|
|
5
5
|
{
|
|
6
6
|
"name": "Alert",
|
|
@@ -15197,8 +15197,7 @@
|
|
|
15197
15197
|
{
|
|
15198
15198
|
"name": "fields",
|
|
15199
15199
|
"type": "FieldMetadata[] | undefined",
|
|
15200
|
-
"required": false
|
|
15201
|
-
"defaultValue": "[]"
|
|
15200
|
+
"required": false
|
|
15202
15201
|
},
|
|
15203
15202
|
{
|
|
15204
15203
|
"name": "value",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wallarm-org/design-system",
|
|
3
|
-
"version": "1.0.0-rc-feature-AS-877-fix-filter-code.
|
|
3
|
+
"version": "1.0.0-rc-feature-AS-877-fix-filter-code.2",
|
|
4
4
|
"description": "Core design system library with React components and Storybook documentation",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|