@servicetitan/table 24.2.1 → 24.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,4 @@
1
1
  import { FC } from 'react';
2
2
  export declare const SingleSelectDefaultExample: FC;
3
+ export declare const SingleSelectCustomFilterExample: FC;
3
4
  //# sourceMappingURL=single-select-filter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"single-select-filter.d.ts","sourceRoot":"","sources":["../../../src/demo/filters/single-select-filter.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAW,EAAE,EAAY,MAAM,OAAO,CAAC;AAY9C,eAAO,MAAM,0BAA0B,EAAE,EAmDxC,CAAC"}
1
+ {"version":3,"file":"single-select-filter.d.ts","sourceRoot":"","sources":["../../../src/demo/filters/single-select-filter.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAW,EAAE,EAAY,MAAM,OAAO,CAAC;AAY9C,eAAO,MAAM,0BAA0B,EAAE,EAmDxC,CAAC;AAEF,eAAO,MAAM,+BAA+B,EAAE,EAuC7C,CAAC"}
@@ -18,4 +18,21 @@ export const SingleSelectDefaultExample = provide({
18
18
  }), []);
19
19
  return (_jsxs(Fragment, { children: [_jsxs(Banner, Object.assign({ title: "Default filter with single select", className: "m-b-2" }, { children: ["Single select filter allows to choose one option from the provided list. You can pass simple options (string or number) or complex objects", _jsx("br", {}), "Use it when options list is fixed and less than 20 items"] })), _jsxs(Table, Object.assign({ tableState: tableState, striped: false }, { children: [_jsx(TableColumn, { field: "ProductID", title: "ID", editable: false, width: "100px" }), _jsx(TableColumn, { field: "ProductName", title: "Product Name", width: "240px" }), _jsx(TableColumn, { field: "MadeIn", title: "Made In (simple single-select filter)", columnMenu: madeInColumnMenu }), _jsx(TableColumn, { field: "CategoryID", title: "Category (simple single-select filter)", columnMenu: categoryColumnMenu, cell: CategoryCell })] }))] }));
20
20
  }));
21
+ export const SingleSelectCustomFilterExample = provide({
22
+ singletons: [TableStore],
23
+ })(observer(() => {
24
+ const [{ tableState }] = useDependencies(TableStore);
25
+ const productNameCustomFilter = useMemo(() => {
26
+ const isVowel = (str) => /[aeiou]/i.test(str[0]);
27
+ return singleSelectColumnMenuFilter({
28
+ options: [0, 1],
29
+ renderItem: item => (item ? 'Start with Vowel' : 'Start with Consonants'),
30
+ filter: value => ({
31
+ value,
32
+ operator: (madeIn) => madeIn ? (value ? isVowel(madeIn) : !isVowel(madeIn)) : false,
33
+ }),
34
+ });
35
+ }, []);
36
+ return (_jsxs(Fragment, { children: [_jsxs(Banner, Object.assign({ title: "Default filter with single select", className: "m-b-2" }, { children: ["Single select filter allows to choose one option from the provided list. You can pass simple options (string or number) or complex objects", _jsx("br", {}), "Custom filter allows you to provide custom filtering options"] })), _jsxs(Table, Object.assign({ tableState: tableState, striped: false }, { children: [_jsx(TableColumn, { field: "ProductID", title: "ID", editable: false, width: "100px" }), _jsx(TableColumn, { field: "ProductName", title: "Product Name (custom single-select filter)", columnMenu: productNameCustomFilter })] }))] }));
37
+ }));
21
38
  //# sourceMappingURL=single-select-filter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"single-select-filter.js","sourceRoot":"","sources":["../../../src/demo/filters/single-select-filter.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAM,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE9C,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAEnE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,4BAA4B,EAAE,MAAM,OAAO,CAAC;AAEzE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAE/D,MAAM,CAAC,MAAM,0BAA0B,GAAO,OAAO,CAAC;IAClD,UAAU,EAAE,CAAC,UAAU,CAAC;C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,CAAC,CAAC,uBAAuB,CAAC;YACzE,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC;gBACd,KAAK;gBACL,QAAQ,EAAE,CAAC,MAAc,EAAE,EAAE,CACzB,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK;aACpE,CAAC;SACL,CAAC,CAAC;IACP,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CACH,MAAC,QAAQ,eACL,MAAC,MAAM,kBAAC,KAAK,EAAC,mCAAmC,EAAC,SAAS,EAAC,OAAO,+JAG/D,cAAM,qEAED,EACT,MAAC,KAAK,kBAAC,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,iBACzC,KAAC,WAAW,IAAC,KAAK,EAAC,WAAW,EAAC,KAAK,EAAC,IAAI,EAAC,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAC,OAAO,GAAG,EAC3E,KAAC,WAAW,IACR,KAAK,EAAC,aAAa,EACnB,KAAK,EAAC,4CAA4C,EAClD,UAAU,EAAE,uBAAuB,GACrC,KACE,IACD,CACd,CAAC;AACN,CAAC,CAAC,CACL,CAAC"}
@@ -4,6 +4,10 @@ export interface SingleSelectColumnMenuOptions<TV, TO = TV> {
4
4
  options: TO[];
5
5
  valueSelector?: (item: TO) => TV;
6
6
  renderItem?: (item: TO) => ReactNode | string;
7
+ filter?: (value: TV) => {
8
+ value: any;
9
+ operator: string | Function;
10
+ };
7
11
  }
8
12
  export declare function singleSelectColumnMenuFilter<TV extends IdType, TO = TV>(props: SingleSelectColumnMenuOptions<TV, TO>): (props: import("@servicetitan/design-system").TableColumnMenuProps) => JSX.Element;
9
13
  //# sourceMappingURL=single-select-filter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"single-select-filter.d.ts","sourceRoot":"","sources":["../../../src/filters/single-select/single-select-filter.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA6B,SAAS,EAAM,MAAM,OAAO,CAAC;AAKjE,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AA8BlD,MAAM,WAAW,6BAA6B,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE;IACtD,OAAO,EAAE,EAAE,EAAE,CAAC;IACd,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC;IACjC,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,KAAK,SAAS,GAAG,MAAM,CAAC;CACjD;AAED,wBAAgB,4BAA4B,CAAC,EAAE,SAAS,MAAM,EAAE,EAAE,GAAG,EAAE,EACnE,KAAK,EAAE,6BAA6B,CAAC,EAAE,EAAE,EAAE,CAAC,sFAuB/C"}
1
+ {"version":3,"file":"single-select-filter.d.ts","sourceRoot":"","sources":["../../../src/filters/single-select/single-select-filter.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA6B,SAAS,EAAM,MAAM,OAAO,CAAC;AAEjE,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAiClD,MAAM,WAAW,6BAA6B,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE;IACtD,OAAO,EAAE,EAAE,EAAE,CAAC;IACd,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC;IACjC,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,KAAK,SAAS,GAAG,MAAM,CAAC;IAC9C,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,KAAK;QACpB,KAAK,EAAE,GAAG,CAAC;QACX,QAAQ,EAAE,MAAM,GAAG,QAAQ,CAAC;KAC/B,CAAC;CACL;AAED,wBAAgB,4BAA4B,CAAC,EAAE,SAAS,MAAM,EAAE,EAAE,GAAG,EAAE,EACnE,KAAK,EAAE,6BAA6B,CAAC,EAAE,EAAE,EAAE,CAAC,sFAgC/C"}
@@ -17,11 +17,15 @@ export function singleSelectColumnMenuFilter(props) {
17
17
  const FilterCell = ({ value, onChange }) => {
18
18
  var _a;
19
19
  const handleChange = (value, event) => {
20
- onChange({
21
- value: value !== null && value !== void 0 ? value : '',
22
- operator: value ? 'equals' : '',
23
- syntheticEvent: event,
24
- });
20
+ const filter = value === undefined
21
+ ? { value: '', operator: '' }
22
+ : props.filter
23
+ ? props.filter(value)
24
+ : {
25
+ value,
26
+ operator: 'equals',
27
+ };
28
+ onChange(Object.assign(Object.assign({}, filter), { syntheticEvent: event }));
25
29
  };
26
30
  return (_jsx(SelectorRadio, { options: props.options, value: value === '' ? undefined : value, onChange: handleChange, renderer: props.renderItem, valueSelector: (_a = props.valueSelector) !== null && _a !== void 0 ? _a : (option => option) }));
27
31
  };
@@ -1 +1 @@
1
- {"version":3,"file":"single-select-filter.js","sourceRoot":"","sources":["../../../src/filters/single-select/single-select-filter.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAiC,MAAM,OAAO,CAAC;AAEjE,OAAO,EAAwB,KAAK,EAAE,MAAM,6BAA6B,CAAC;AAE1E,OAAO,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAC;AAWtE,MAAM,aAAsB,SAAQ,SAAgC;IAChE,MAAM;QACF,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QAEhD,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;YACjC,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;YACrD,OAAO;YACH,oDAAoD;YACpD,6BAAkB,SAAS,EAAC,sBAAsB,gBAC9C,KAAC,KAAK,IACF,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,EAAE,EAChD,OAAO,EAAE,KAAK,KAAK,WAAW,EAC9B,QAAQ,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,WAAW,EAAE,KAAK,CAAC,GACjE,KALK,KAAK,CAMT,CACV,CAAC;QACN,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAQD,MAAM,UAAU,4BAA4B,CACxC,KAA4C;IAE5C,MAAM,UAAU,GAA6B,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE;;QACjE,MAAM,YAAY,GAAG,CAAC,KAAqB,EAAE,KAAuC,EAAE,EAAE;YACpF,QAAQ,CAAC;gBACL,KAAK,EAAE,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,EAAE;gBAClB,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE;gBAC/B,cAAc,EAAE,KAAK;aACxB,CAAC,CAAC;QACP,CAAC,CAAC;QAEF,OAAO,CACH,KAAC,aAAa,IACV,OAAO,EAAE,KAAK,CAAC,OAAO,EACtB,KAAK,EAAE,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,EACvC,QAAQ,EAAE,YAAY,EACtB,QAAQ,EAAE,KAAK,CAAC,UAAU,EAC1B,aAAa,EAAE,MAAA,KAAK,CAAC,aAAa,mCAAI,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,GAC1D,CACL,CAAC;IACN,CAAC,CAAC;IAEF,OAAO,4BAA4B,CAAC,UAAU,CAAC,CAAC;AACpD,CAAC"}
1
+ {"version":3,"file":"single-select-filter.js","sourceRoot":"","sources":["../../../src/filters/single-select/single-select-filter.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAiC,MAAM,OAAO,CAAC;AAGjE,OAAO,EAAwB,KAAK,EAAE,MAAM,6BAA6B,CAAC;AAE1E,OAAO,EAAE,4BAA4B,E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IACvB,CAAC;QACP,CAAC,CAAC;QAEF,OAAO,CACH,KAAC,aAAa,IACV,OAAO,EAAE,KAAK,CAAC,OAAO,EACtB,KAAK,EAAE,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,EACvC,QAAQ,EAAE,YAAY,EACtB,QAAQ,EAAE,KAAK,CAAC,UAAU,EAC1B,aAAa,EAAE,MAAA,KAAK,CAAC,aAAa,mCAAI,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,GAC1D,CACL,CAAC;IACN,CAAC,CAAC;IAEF,OAAO,4BAA4B,CAAC,UAAU,CAAC,CAAC;AACpD,CAAC"}
@@ -3,5 +3,6 @@ declare const _default: {
3
3
  title: string;
4
4
  };
5
5
  export default _default;
6
- export declare const SingleSelect: () => JSX.Element;
6
+ export declare const DefaultSingleSelect: () => JSX.Element;
7
+ export declare const CustomFilterSingleSelect: () => JSX.Element;
7
8
  //# sourceMappingURL=single-select-filter.stories.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"single-select-filter.stories.d.ts","sourceRoot":"","sources":["../../../src/filters/single-select/single-select-filter.stories.tsx"],"names":[],"mappings":";;;;AAEA,wBAEE;AAEF,eAAO,MAAM,YAAY,mBAAuC,CAAC"}
1
+ {"version":3,"file":"single-select-filter.stories.d.ts","sourceRoot":"","sources":["../../../src/filters/single-select/single-select-filter.stories.tsx"],"names":[],"mappings":";;;;AAKA,wBAEE;AAEF,eAAO,MAAM,mBAAmB,mBAAuC,CAAC;AACxE,eAAO,MAAM,wBAAwB,mBAA4C,CAAC"}
@@ -1,7 +1,8 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { SingleSelectDefaultExample } from '../../demo/filters/single-select-filter';
2
+ import { SingleSelectDefaultExample, SingleSelectCustomFilterExample, } from '../../demo/filters/single-select-filter';
3
3
  export default {
4
4
  title: 'Table/Filters/SingleSelect',
5
5
  };
6
- export const SingleSelect = () => _jsx(SingleSelectDefaultExample, {});
6
+ export const DefaultSingleSelect = () => _jsx(SingleSelectDefaultExample, {});
7
+ export const CustomFilterSingleSelect = () => _jsx(SingleSelectCustomFilterExample, {});
7
8
  //# sourceMappingURL=single-select-filter.stories.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"single-select-filter.stories.js","sourceRoot":"","sources":["../../../src/filters/single-select/single-select-filter.stories.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,yCAAyC,CAAC;AAErF,eAAe;IACX,KAAK,EAAE,4BAA4B;CACtC,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,EAAE,CAAC,KAAC,0BAA0B,KAAG,CAAC"}
1
+ {"version":3,"file":"single-select-filter.stories.js","sourceRoot":"","sources":["../../../src/filters/single-select/single-select-filter.stories.tsx"],"names":[],"mappings":";AAAA,OAAO,EACH,0BAA0B,EAC1B,+BAA+B,GAClC,MAAM,yCAAyC,CAAC;AAEjD,eAAe;IACX,KAAK,EAAE,4BAA4B;CACtC,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,EAAE,CAAC,KAAC,0BAA0B,KAAG,CAAC;AACxE,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,EAAE,CAAC,KAAC,+BAA+B,KAAG,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@servicetitan/table",
3
- "version": "24.2.1",
3
+ "version": "24.3.1",
4
4
  "description": "",
5
5
  "homepage": "https://docs.st.dev/docs/frontend/table",
6
6
  "repository": {
@@ -37,9 +37,9 @@
37
37
  "memoize-one": "~6.0.0"
38
38
  },
39
39
  "devDependencies": {
40
- "@servicetitan/data-query": "^24.2.1",
40
+ "@servicetitan/data-query": "^24.3.1",
41
41
  "@servicetitan/design-system": ">=12.4.1",
42
- "@servicetitan/form": "^24.2.1",
42
+ "@servicetitan/form": "^24.3.1",
43
43
  "@servicetitan/react-ioc": "^21.6.0",
44
44
  "@servicetitan/suppress-warnings": "^21.6.0",
45
45
  "@types/accounting": "~0.4.2",
@@ -53,9 +53,9 @@
53
53
  "react": "~17.0.2"
54
54
  },
55
55
  "peerDependencies": {
56
- "@servicetitan/data-query": "^24.2.1",
56
+ "@servicetitan/data-query": "^24.3.1",
57
57
  "@servicetitan/design-system": ">=12.4.1",
58
- "@servicetitan/form": "^24.2.1",
58
+ "@servicetitan/form": "^24.3.1",
59
59
  "@servicetitan/react-ioc": ">21.0.0",
60
60
  "@servicetitan/suppress-warnings": ">21.0.0",
61
61
  "accounting": "~0.4.1",
@@ -72,5 +72,5 @@
72
72
  "cli": {
73
73
  "webpack": false
74
74
  },
75
- "gitHead": "4ada426e22cc2cb9c0573193136d61eaa1698d83"
75
+ "gitHead": "052613f8c4aa3b83703d7dcf79deb9b52763578a"
76
76
  }
@@ -62,3 +62,44 @@ export const SingleSelectDefaultExample: FC = provide({
62
62
  );
63
63
  })
64
64
  );
65
+
66
+ export const SingleSelectCustomFilterExample: FC = provide({
67
+ singletons: [TableStore],
68
+ })(
69
+ observer(() => {
70
+ const [{ tableState }] = useDependencies(TableStore);
71
+
72
+ const productNameCustomFilter = useMemo(() => {
73
+ const isVowel = (str: string) => /[aeiou]/i.test(str[0]);
74
+
75
+ return singleSelectColumnMenuFilter({
76
+ options: [0, 1],
77
+ renderItem: item => (item ? 'Start with Vowel' : 'Start with Consonants'),
78
+ filter: value => ({
79
+ value,
80
+ operator: (madeIn: string) =>
81
+ madeIn ? (value ? isVowel(madeIn) : !isVowel(madeIn)) : false,
82
+ }),
83
+ });
84
+ }, []);
85
+
86
+ return (
87
+ <Fragment>
88
+ <Banner title="Default filter with single select" className="m-b-2">
89
+ Single select filter allows to choose one option from the provided list. You can
90
+ pass simple options (string or number) or complex objects
91
+ <br />
92
+ Custom filter allows you to provide custom filtering options
93
+ </Banner>
94
+ <Table tableState={tableState} striped={false}>
95
+ <TableColumn field="ProductID" title="ID" editable={false} width="100px" />
96
+ <TableColumn
97
+ field="ProductName"
98
+ title="Product Name (custom single-select filter)"
99
+ columnMenu={productNameCustomFilter}
100
+ />
101
+ </Table>
102
+ </Fragment>
103
+ );
104
+ })
105
+ );
@@ -1,7 +1,11 @@
1
- import { SingleSelectDefaultExample } from '../../demo/filters/single-select-filter';
1
+ import {
2
+ SingleSelectDefaultExample,
3
+ SingleSelectCustomFilterExample,
4
+ } from '../../demo/filters/single-select-filter';
2
5
 
3
6
  export default {
4
7
  title: 'Table/Filters/SingleSelect',
5
8
  };
6
9
 
7
- export const SingleSelect = () => <SingleSelectDefaultExample />;
10
+ export const DefaultSingleSelect = () => <SingleSelectDefaultExample />;
11
+ export const CustomFilterSingleSelect = () => <SingleSelectCustomFilterExample />;
@@ -1,9 +1,9 @@
1
1
  import { Component, SyntheticEvent, ReactNode, FC } from 'react';
2
2
 
3
+ import { IdType } from '@servicetitan/data-query';
3
4
  import { TableFilterCellProps, Radio } from '@servicetitan/design-system';
4
5
 
5
6
  import { renderCustomColumnMenuFilter } from '../column-menu-filters';
6
- import { IdType } from '@servicetitan/data-query';
7
7
 
8
8
  interface SelectorProps<TV, TO> {
9
9
  options: TO[];
@@ -37,6 +37,10 @@ export interface SingleSelectColumnMenuOptions<TV, TO = TV> {
37
37
  options: TO[];
38
38
  valueSelector?: (item: TO) => TV;
39
39
  renderItem?: (item: TO) => ReactNode | string;
40
+ filter?: (value: TV) => {
41
+ value: any;
42
+ operator: string | Function;
43
+ };
40
44
  }
41
45
 
42
46
  export function singleSelectColumnMenuFilter<TV extends IdType, TO = TV>(
@@ -44,9 +48,18 @@ export function singleSelectColumnMenuFilter<TV extends IdType, TO = TV>(
44
48
  ) {
45
49
  const FilterCell: FC<TableFilterCellProps> = ({ value, onChange }) => {
46
50
  const handleChange = (value: TV | undefined, event: SyntheticEvent<HTMLInputElement>) => {
51
+ const filter =
52
+ value === undefined
53
+ ? { value: '', operator: '' }
54
+ : props.filter
55
+ ? props.filter(value)
56
+ : {
57
+ value,
58
+ operator: 'equals',
59
+ };
60
+
47
61
  onChange({
48
- value: value ?? '',
49
- operator: value ? 'equals' : '',
62
+ ...filter,
50
63
  syntheticEvent: event,
51
64
  });
52
65
  };