@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.3
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.d.ts +14 -0
- package/dist/components/FilterInput/FilterInput.js +5 -1
- package/dist/components/FilterInput/lib/applyKnownFieldHelpers.d.ts +21 -0
- package/dist/components/FilterInput/lib/applyKnownFieldHelpers.js +27 -0
- package/dist/components/FilterInput/lib/index.d.ts +1 -0
- package/dist/components/FilterInput/lib/index.js +2 -1
- package/dist/metadata/components.json +2 -2
- package/package.json +1 -1
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
import type { FC, HTMLAttributes } from 'react';
|
|
2
2
|
import type { ExprNode, FieldMetadata } from './types';
|
|
3
3
|
export interface FilterInputProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'onChange'> {
|
|
4
|
+
/**
|
|
5
|
+
* Filter-field configurations driving the autocomplete. Most fields are
|
|
6
|
+
* passed through as-is, but a few names are **reserved** and auto-wired
|
|
7
|
+
* with design-system helpers (`acceptChar` / `normalize` / `getSuggestions`
|
|
8
|
+
* / `validate`). Current reserved names:
|
|
9
|
+
*
|
|
10
|
+
* - `status_code` — HTTP status code field (mask suggestions, format
|
|
11
|
+
* validation, digit-or-X input filter, partial-input normalization).
|
|
12
|
+
*
|
|
13
|
+
* Consumer-supplied callbacks always override the auto-wiring, so you can
|
|
14
|
+
* opt out per-field. For the same helpers on a field with a different
|
|
15
|
+
* `name`, import the factories (`createStatusCodeSuggestions`, …) and
|
|
16
|
+
* attach them manually.
|
|
17
|
+
*/
|
|
4
18
|
fields?: FieldMetadata[];
|
|
5
19
|
value?: ExprNode | null;
|
|
6
20
|
onChange?: (expression: ExprNode | null) => void;
|
|
@@ -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 { applyKnownFieldHelpers } from "./lib/applyKnownFieldHelpers.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(()=>applyKnownFieldHelpers(rawFields), [
|
|
20
|
+
rawFields
|
|
21
|
+
]);
|
|
18
22
|
const { conditions, connectors, chips, upsertCondition, removeCondition, removeConditionAtIndex, clearAll, setConnectorValue } = useFilterInputExpression({
|
|
19
23
|
fields,
|
|
20
24
|
value,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { FieldMetadata } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Decorate `fields` in place with design-system helpers for known field names.
|
|
4
|
+
* `FilterInput` calls this on the `fields` prop before rendering.
|
|
5
|
+
*
|
|
6
|
+
* Reserved names and what they auto-attach (unless the consumer already
|
|
7
|
+
* provided a value for that slot):
|
|
8
|
+
*
|
|
9
|
+
* | `name` | Attaches |
|
|
10
|
+
* | ------------- | -------------------------------------------------------------------- |
|
|
11
|
+
* | `status_code` | HTTP status code: `acceptChar`, `normalize`, `getSuggestions`, `validate` |
|
|
12
|
+
*
|
|
13
|
+
* Consumer-supplied callbacks always win over the auto-wired ones. If the
|
|
14
|
+
* backend uses a different name (e.g. `http_status_code`), the helpers are
|
|
15
|
+
* NOT applied — the consumer must either rename the field to match or wire
|
|
16
|
+
* the factories (`createStatusCode*`) manually.
|
|
17
|
+
*
|
|
18
|
+
* The returned array has **reference-stable identity** when no field matches,
|
|
19
|
+
* so downstream `useMemo` that depends on it does not invalidate unnecessarily.
|
|
20
|
+
*/
|
|
21
|
+
export declare const applyKnownFieldHelpers: (fields: FieldMetadata[]) => FieldMetadata[];
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createStatusCodeInputFilter, createStatusCodeNormalizer, createStatusCodeSuggestions, createStatusCodeValidator } from "./statusCode/index.js";
|
|
2
|
+
const KNOWN_FIELD_HELPERS = {
|
|
3
|
+
status_code: ()=>({
|
|
4
|
+
acceptChar: createStatusCodeInputFilter(),
|
|
5
|
+
normalize: createStatusCodeNormalizer(),
|
|
6
|
+
getSuggestions: createStatusCodeSuggestions(),
|
|
7
|
+
validate: createStatusCodeValidator()
|
|
8
|
+
})
|
|
9
|
+
};
|
|
10
|
+
const applyKnownFieldHelpers = (fields)=>{
|
|
11
|
+
let changed = false;
|
|
12
|
+
const out = fields.map((field)=>{
|
|
13
|
+
const factory = KNOWN_FIELD_HELPERS[field.name];
|
|
14
|
+
if (!factory) return field;
|
|
15
|
+
const helpers = factory();
|
|
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 { applyKnownFieldHelpers };
|
|
@@ -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 { applyKnownFieldHelpers } from './applyKnownFieldHelpers';
|
|
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 { applyKnownFieldHelpers } from "./applyKnownFieldHelpers.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, applyKnownFieldHelpers, 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 };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": "0.27.0",
|
|
3
|
-
"generatedAt": "2026-04-
|
|
3
|
+
"generatedAt": "2026-04-20T15:59:19.454Z",
|
|
4
4
|
"components": [
|
|
5
5
|
{
|
|
6
6
|
"name": "Alert",
|
|
@@ -15198,7 +15198,7 @@
|
|
|
15198
15198
|
"name": "fields",
|
|
15199
15199
|
"type": "FieldMetadata[] | undefined",
|
|
15200
15200
|
"required": false,
|
|
15201
|
-
"
|
|
15201
|
+
"description": "Filter-field configurations driving the autocomplete. Most fields are\npassed through as-is, but a few names are **reserved** and auto-wired\nwith design-system helpers (`acceptChar` / `normalize` / `getSuggestions`\n/ `validate`). Current reserved names:\n\n - `status_code` — HTTP status code field (mask suggestions, format\n validation, digit-or-X input filter, partial-input normalization).\n\nConsumer-supplied callbacks always override the auto-wiring, so you can\nopt out per-field. For the same helpers on a field with a different\n`name`, import the factories (`createStatusCodeSuggestions`, …) and\nattach them manually."
|
|
15202
15202
|
},
|
|
15203
15203
|
{
|
|
15204
15204
|
"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.3",
|
|
4
4
|
"description": "Core design system library with React components and Storybook documentation",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|