@wallarm-org/design-system 1.0.0-rc-feature-AS-877-fix-filter-code.2 → 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.
@@ -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,7 @@ 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
- import { applyFieldPresets } from "./lib/applyFieldPresets.js";
9
+ import { applyKnownFieldHelpers } from "./lib/applyKnownFieldHelpers.js";
10
10
  const FilterInput = ({ fields: rawFields = [], value, onChange, placeholder = 'Type to filter...', error = false, showKeyboardHint = false, className, ...props })=>{
11
11
  const inputRef = useRef(null);
12
12
  const containerRef = useRef(null);
@@ -16,7 +16,7 @@ const FilterInput = ({ fields: rawFields = [], value, onChange, placeholder = 'T
16
16
  if (el) chipRegistryRef.current.set(id, el);
17
17
  else chipRegistryRef.current.delete(id);
18
18
  }, []);
19
- const fields = useMemo(()=>applyFieldPresets(rawFields), [
19
+ const fields = useMemo(()=>applyKnownFieldHelpers(rawFields), [
20
20
  rawFields
21
21
  ]);
22
22
  const { conditions, connectors, chips, upsertCondition, removeCondition, removeConditionAtIndex, clearAll, setConnectorValue } = useFilterInputExpression({
@@ -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, FieldPreset, FieldType, FieldValueOption, FilterInputChipData, FilterInputChipVariant, FilterOperator, Group, } from './types';
5
+ export type { Condition, ExprNode, FieldMetadata, FieldType, FieldValueOption, FilterInputChipData, FilterInputChipVariant, FilterOperator, Group, } from './types';
@@ -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[];
@@ -1,5 +1,5 @@
1
1
  import { createStatusCodeInputFilter, createStatusCodeNormalizer, createStatusCodeSuggestions, createStatusCodeValidator } from "./statusCode/index.js";
2
- const PRESET_HELPERS = {
2
+ const KNOWN_FIELD_HELPERS = {
3
3
  status_code: ()=>({
4
4
  acceptChar: createStatusCodeInputFilter(),
5
5
  normalize: createStatusCodeNormalizer(),
@@ -7,12 +7,12 @@ const PRESET_HELPERS = {
7
7
  validate: createStatusCodeValidator()
8
8
  })
9
9
  };
10
- const applyFieldPresets = (fields)=>{
10
+ const applyKnownFieldHelpers = (fields)=>{
11
11
  let changed = false;
12
12
  const out = fields.map((field)=>{
13
- if (!field.preset) return field;
14
- const helpers = PRESET_HELPERS[field.preset]?.();
15
- if (!helpers) return field;
13
+ const factory = KNOWN_FIELD_HELPERS[field.name];
14
+ if (!factory) return field;
15
+ const helpers = factory();
16
16
  changed = true;
17
17
  return {
18
18
  ...field,
@@ -24,4 +24,4 @@ const applyFieldPresets = (fields)=>{
24
24
  });
25
25
  return changed ? out : fields;
26
26
  };
27
- export { applyFieldPresets };
27
+ export { applyKnownFieldHelpers };
@@ -1,7 +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
+ export { applyKnownFieldHelpers } from './applyKnownFieldHelpers';
5
5
  export { chipIdToConditionIndex, findChipSplitIndex } from './conditions';
6
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';
7
7
  export { buildContainerAnchoredRect, isMenuRelated } from './dom';
@@ -1,6 +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
+ import { applyKnownFieldHelpers } from "./applyKnownFieldHelpers.js";
4
4
  import { chipIdToConditionIndex, findChipSplitIndex } from "./conditions.js";
5
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";
6
6
  import { buildContainerAnchoredRect, isMenuRelated } from "./dom.js";
@@ -11,4 +11,4 @@ import { getOperatorFromLabel, getOperatorLabel, isBetweenOperator, isMultiSelec
11
11
  import { isFilterParseError, parseExpression } from "./parseExpression/index.js";
12
12
  import { serializeExpression } from "./serializeExpression.js";
13
13
  import { createStatusCodeInputFilter, createStatusCodeNormalizer, createStatusCodeSuggestions, createStatusCodeValidator } from "./statusCode/index.js";
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 };
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 };
@@ -44,13 +44,6 @@ 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';
54
47
  /**
55
48
  * Field Metadata Interface
56
49
  * Matches backend structure for field definitions
@@ -63,12 +56,6 @@ export interface FieldMetadata {
63
56
  operators?: FilterOperator[];
64
57
  default?: string | number | boolean;
65
58
  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;
72
59
  /**
73
60
  * Shorthand for simple string values (e.g. `["GET", "POST", "PUT"]`).
74
61
  * Automatically converted to `FieldValueOption[]` where `value === label`.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": "0.27.0",
3
- "generatedAt": "2026-04-20T14:56:46.717Z",
3
+ "generatedAt": "2026-04-20T15:59:19.454Z",
4
4
  "components": [
5
5
  {
6
6
  "name": "Alert",
@@ -15197,7 +15197,8 @@
15197
15197
  {
15198
15198
  "name": "fields",
15199
15199
  "type": "FieldMetadata[] | undefined",
15200
- "required": false
15200
+ "required": false,
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."
15201
15202
  },
15202
15203
  {
15203
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.2",
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",
@@ -1,8 +0,0 @@
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[];