@servicetitan/table 25.5.0 → 25.7.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/filters/select-filter/operators.d.ts +11 -0
- package/dist/filters/select-filter/operators.d.ts.map +1 -0
- package/dist/filters/select-filter/operators.js +12 -0
- package/dist/filters/select-filter/operators.js.map +1 -0
- package/dist/filters/select-filter/select-filter.d.ts +2 -0
- package/dist/filters/select-filter/select-filter.d.ts.map +1 -1
- package/dist/filters/select-filter/select-filter.js +9 -4
- package/dist/filters/select-filter/select-filter.js.map +1 -1
- package/package.json +6 -6
- package/src/filters/select-filter/operators.ts +22 -0
- package/src/filters/select-filter/select-filter.tsx +13 -8
@@ -0,0 +1,11 @@
|
|
1
|
+
import { IdType } from '@servicetitan/data-query';
|
2
|
+
interface OperatorOpts<TO> {
|
3
|
+
valueSelector?: (item: TO) => IdType;
|
4
|
+
rowValueSelector?: (item: any) => IdType | undefined;
|
5
|
+
}
|
6
|
+
export declare const selectColumnMenuFilterOperators: {
|
7
|
+
getContains: <TO>(opts?: OperatorOpts<TO> | undefined) => (value: any, options?: TO[] | undefined) => boolean | undefined;
|
8
|
+
getEquals: <TO_1>(opts?: OperatorOpts<TO_1> | undefined) => (value: any, option?: TO_1 | undefined) => boolean;
|
9
|
+
};
|
10
|
+
export {};
|
11
|
+
//# sourceMappingURL=operators.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"operators.d.ts","sourceRoot":"","sources":["../../../src/filters/select-filter/operators.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAElD,UAAU,YAAY,CAAC,EAAE;IACrB,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,KAAK,MAAM,CAAC;IACrC,gBAAgB,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,MAAM,GAAG,SAAS,CAAC;CACxD;AAED,eAAO,MAAM,+BAA+B;sEAIrB,GAAG;wEAMH,GAAG;CAGzB,CAAC"}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { getSimpleValue } from './value-getter';
|
2
|
+
export const selectColumnMenuFilterOperators = {
|
3
|
+
getContains: (opts) => {
|
4
|
+
const { valueSelector = getSimpleValue, rowValueSelector = getSimpleValue } = opts !== null && opts !== void 0 ? opts : {};
|
5
|
+
return (value, options) => options === null || options === void 0 ? void 0 : options.some(opt => valueSelector(opt) === rowValueSelector(value));
|
6
|
+
},
|
7
|
+
getEquals: (opts) => {
|
8
|
+
const { valueSelector = getSimpleValue, rowValueSelector = getSimpleValue } = opts !== null && opts !== void 0 ? opts : {};
|
9
|
+
return (value, option) => option === undefined ? false : valueSelector(option) === rowValueSelector(value);
|
10
|
+
},
|
11
|
+
};
|
12
|
+
//# sourceMappingURL=operators.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"operators.js","sourceRoot":"","sources":["../../../src/filters/select-filter/operators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAQhD,MAAM,CAAC,MAAM,+BAA+B,GAAG;IAC3C,WAAW,EAAE,CAAK,IAAuB,EAAE,EAAE;QACzC,MAAM,EAAE,aAAa,GAAG,cAAc,EAAE,gBAAgB,GAAG,cAAc,EAAE,GAAG,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,EAAE,CAAC;QAEzF,OAAO,CAAC,KAAU,EAAE,OAAc,EAAE,EAAE,CAClC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,gBAAgB,CAAC,KAAK,CAAC,CAAC,CAAC;IAC7E,CAAC;IACD,SAAS,EAAE,CAAK,IAAuB,EAAE,EAAE;QACvC,MAAM,EAAE,aAAa,GAAG,cAAc,EAAE,gBAAgB,GAAG,cAAc,EAAE,GAAG,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,EAAE,CAAC;QAEzF,OAAO,CAAC,KAAU,EAAE,MAAW,EAAE,EAAE,CAC/B,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,KAAK,gBAAgB,CAAC,KAAK,CAAC,CAAC;IACzF,CAAC;CACJ,CAAC"}
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { ReactNode } from 'react';
|
2
2
|
import { IdType } from '@servicetitan/data-query';
|
3
3
|
import { CustomColumnMenuFilterSingleOpts } from '../column-menu-filters';
|
4
|
+
import { selectColumnMenuFilterOperators } from './operators';
|
4
5
|
export declare type SelectFilterDataFetcher<TO> = (opts: {
|
5
6
|
search?: string;
|
6
7
|
}) => Promise<{
|
@@ -29,4 +30,5 @@ export interface SelectFilterOptions<TO> extends CustomColumnMenuFilterSingleOpt
|
|
29
30
|
renderItem?(item: TO): ReactNode;
|
30
31
|
}
|
31
32
|
export declare function selectColumnMenuFilter<TO>({ dataFetcher, data, search, multiple, valueSelector, rowValueSelector, renderItem, operator, ...opts }: SelectFilterOptions<TO>): (props: import("@servicetitan/design-system").TableColumnMenuProps) => JSX.Element;
|
33
|
+
export { selectColumnMenuFilterOperators };
|
32
34
|
//# sourceMappingURL=select-filter.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"select-filter.d.ts","sourceRoot":"","sources":["../../../src/filters/select-filter/select-filter.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA6B,SAAS,EAA+B,MAAM,OAAO,CAAC;AAU1F,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAElD,OAAO,EACH,gCAAgC,EAEnC,MAAM,wBAAwB,CAAC;
|
1
|
+
{"version":3,"file":"select-filter.d.ts","sourceRoot":"","sources":["../../../src/filters/select-filter/select-filter.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA6B,SAAS,EAA+B,MAAM,OAAO,CAAC;AAU1F,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAElD,OAAO,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SAAS,CAAC;CACpC;AAMD,wBAAgB,sBAAsB,CAAC,EAAE,EAAE,EACvC,WAAW,EACX,IAAI,EACJ,MAAM,EACN,QAAQ,EACR,aAA8B,EAC9B,gBAAiC,EACjC,UAAU,EACV,QAAQ,EACR,GAAG,IAAI,EACV,EAAE,mBAAmB,CAAC,EAAE,CAAC,sFAiFzB;AAED,OAAO,EAAE,+BAA+B,EAAE,CAAC"}
|
@@ -35,6 +35,7 @@ import { makeObservable, observable, runInAction, toJS } from 'mobx';
|
|
35
35
|
import { observer } from 'mobx-react';
|
36
36
|
import { getSimpleValue } from './value-getter';
|
37
37
|
import { objectSearch } from './object-search';
|
38
|
+
import { selectColumnMenuFilterOperators } from './operators';
|
38
39
|
let SelectorAsync = class SelectorAsync extends Component {
|
39
40
|
constructor(props) {
|
40
41
|
super(props);
|
@@ -177,8 +178,6 @@ const SelectorItemMultiple = ({ option, renderer, checked, onChange, }) => {
|
|
177
178
|
export function selectColumnMenuFilter(_a) {
|
178
179
|
var { dataFetcher, data, search, multiple, valueSelector = getSimpleValue, rowValueSelector = getSimpleValue, renderItem, operator } = _a, opts = __rest(_a, ["dataFetcher", "data", "search", "multiple", "valueSelector", "rowValueSelector", "renderItem", "operator"]);
|
179
180
|
const renderer = renderItem !== null && renderItem !== void 0 ? renderItem : (item => valueSelector(item));
|
180
|
-
const contains = (value, options) => options === null || options === void 0 ? void 0 : options.some(opt => valueSelector(opt) === rowValueSelector(value));
|
181
|
-
const equals = (value, option) => option === undefined ? false : valueSelector(option) === rowValueSelector(value);
|
182
181
|
const searchOptions = search
|
183
182
|
? Object.assign({ filter: objectSearch }, (typeof search === 'boolean' ? {} : search)) : undefined;
|
184
183
|
if (multiple) {
|
@@ -191,7 +190,12 @@ export function selectColumnMenuFilter(_a) {
|
|
191
190
|
: option !== opt);
|
192
191
|
onChange({
|
193
192
|
value: val.length ? toJS(val) : undefined,
|
194
|
-
operator: val.length
|
193
|
+
operator: val.length
|
194
|
+
? operator !== null && operator !== void 0 ? operator : selectColumnMenuFilterOperators.getContains({
|
195
|
+
valueSelector,
|
196
|
+
rowValueSelector,
|
197
|
+
})
|
198
|
+
: '',
|
195
199
|
syntheticEvent: event,
|
196
200
|
});
|
197
201
|
};
|
@@ -203,7 +207,7 @@ export function selectColumnMenuFilter(_a) {
|
|
203
207
|
const handleChange = (option, _, event) => {
|
204
208
|
onChange({
|
205
209
|
value: toJS(option),
|
206
|
-
operator: operator !== null && operator !== void 0 ? operator :
|
210
|
+
operator: operator !== null && operator !== void 0 ? operator : selectColumnMenuFilterOperators.getEquals({ valueSelector, rowValueSelector }),
|
207
211
|
syntheticEvent: event,
|
208
212
|
});
|
209
213
|
};
|
@@ -211,4 +215,5 @@ export function selectColumnMenuFilter(_a) {
|
|
211
215
|
};
|
212
216
|
return renderCustomColumnMenuFilter(FilterCell, opts);
|
213
217
|
}
|
218
|
+
export { selectColumnMenuFilterOperators };
|
214
219
|
//# sourceMappingURL=select-filter.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"select-filter.js","sourceRoot":"","sources":["../../../src/filters/select-filter/select-filter.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAA6B,QAAQ,EAAqB,MAAM,OAAO,CAAC;AAE1F,OAAO,EACH,QAAQ,EAER,KAAK,EACL,KAAK,EACL,OAAO,EACP,QAAQ,GACX,MAAM,6BAA6B,CAAC;AAGrC,OAAO,EAEH,4BAA4B,GAC/B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AACrE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;
|
1
|
+
{"version":3,"file":"select-filter.js","sourceRoot":"","s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ACV,aAAa,EAAE,aAAa,GAC9B,CACL,CAAC;QACN,CAAC,CAAC;QAEF,OAAO,4BAA4B,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;KACzD;IAED,MAAM,UAAU,GAAG,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAiC,EAAE,EAAE;QACtE,MAAM,YAAY,GAAG,CAAC,MAAU,EAAE,CAAU,EAAE,KAAuC,EAAE,EAAE;YACrF,QAAQ,CAAC;gBACL,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC;gBACnB,QAAQ,EACJ,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GACR,+BAA+B,CAAC,SAAS,CAAC,EAAE,aAAa,EAAE,gBAAgB,EAAE,CAAC;gBAClF,cAAc,EAAE,KAAK;aACxB,CAAC,CAAC;QACP,CAAC,CAAC;QAEF,OAAO,CACH,KAAC,aAAa,IACV,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,EAC9B,QAAQ,EAAE,YAAY,EACtB,aAAa,EAAE,kBAAkB,EACjC,MAAM,EAAE,aAAa,EACrB,UAAU,EAAE,QAAQ,EACpB,WAAW,EAAE,WAAW,EACxB,IAAI,EAAE,IAAI,EACV,aAAa,EAAE,aAAa,GAC9B,CACL,CAAC;IACN,CAAC,CAAC;IAEF,OAAO,4BAA4B,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;AAC1D,CAAC;AAED,OAAO,EAAE,+BAA+B,EAAE,CAAC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@servicetitan/table",
|
3
|
-
"version": "25.
|
3
|
+
"version": "25.7.0",
|
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": "^25.
|
40
|
+
"@servicetitan/data-query": "^25.7.0",
|
41
41
|
"@servicetitan/design-system": ">=12.4.1",
|
42
|
-
"@servicetitan/form": "^25.
|
42
|
+
"@servicetitan/form": "^25.7.0",
|
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": "^25.
|
56
|
+
"@servicetitan/data-query": "^25.7.0",
|
57
57
|
"@servicetitan/design-system": ">=12.4.1",
|
58
|
-
"@servicetitan/form": "^25.
|
58
|
+
"@servicetitan/form": "^25.7.0",
|
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": "
|
75
|
+
"gitHead": "3e0aaed77a4a1cbdc7675d2f47bcc8f144cd16c3"
|
76
76
|
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import { getSimpleValue } from './value-getter';
|
2
|
+
import { IdType } from '@servicetitan/data-query';
|
3
|
+
|
4
|
+
interface OperatorOpts<TO> {
|
5
|
+
valueSelector?: (item: TO) => IdType;
|
6
|
+
rowValueSelector?: (item: any) => IdType | undefined;
|
7
|
+
}
|
8
|
+
|
9
|
+
export const selectColumnMenuFilterOperators = {
|
10
|
+
getContains: <TO>(opts?: OperatorOpts<TO>) => {
|
11
|
+
const { valueSelector = getSimpleValue, rowValueSelector = getSimpleValue } = opts ?? {};
|
12
|
+
|
13
|
+
return (value: any, options?: TO[]) =>
|
14
|
+
options?.some(opt => valueSelector(opt) === rowValueSelector(value));
|
15
|
+
},
|
16
|
+
getEquals: <TO>(opts?: OperatorOpts<TO>) => {
|
17
|
+
const { valueSelector = getSimpleValue, rowValueSelector = getSimpleValue } = opts ?? {};
|
18
|
+
|
19
|
+
return (value: any, option?: TO) =>
|
20
|
+
option === undefined ? false : valueSelector(option) === rowValueSelector(value);
|
21
|
+
},
|
22
|
+
};
|
@@ -18,6 +18,7 @@ import { makeObservable, observable, runInAction, toJS } from 'mobx';
|
|
18
18
|
import { observer } from 'mobx-react';
|
19
19
|
import { getSimpleValue } from './value-getter';
|
20
20
|
import { objectSearch } from './object-search';
|
21
|
+
import { selectColumnMenuFilterOperators } from './operators';
|
21
22
|
|
22
23
|
export type SelectFilterDataFetcher<TO> = (opts: { search?: string }) => Promise<{ data: TO[] }>;
|
23
24
|
|
@@ -241,12 +242,6 @@ export function selectColumnMenuFilter<TO>({
|
|
241
242
|
}: SelectFilterOptions<TO>) {
|
242
243
|
const renderer = renderItem ?? (item => valueSelector(item));
|
243
244
|
|
244
|
-
const contains = (value: any, options?: TO[]) =>
|
245
|
-
options?.some(opt => valueSelector(opt) === rowValueSelector(value));
|
246
|
-
|
247
|
-
const equals = (value: any, option?: TO) =>
|
248
|
-
option === undefined ? false : valueSelector(option) === rowValueSelector(value);
|
249
|
-
|
250
245
|
const searchOptions = search
|
251
246
|
? {
|
252
247
|
filter: objectSearch,
|
@@ -271,7 +266,13 @@ export function selectColumnMenuFilter<TO>({
|
|
271
266
|
|
272
267
|
onChange({
|
273
268
|
value: val.length ? toJS(val) : undefined,
|
274
|
-
operator: val.length
|
269
|
+
operator: val.length
|
270
|
+
? operator ??
|
271
|
+
selectColumnMenuFilterOperators.getContains({
|
272
|
+
valueSelector,
|
273
|
+
rowValueSelector,
|
274
|
+
})
|
275
|
+
: '',
|
275
276
|
syntheticEvent: event,
|
276
277
|
});
|
277
278
|
};
|
@@ -297,7 +298,9 @@ export function selectColumnMenuFilter<TO>({
|
|
297
298
|
const handleChange = (option: TO, _: boolean, event: SyntheticEvent<HTMLInputElement>) => {
|
298
299
|
onChange({
|
299
300
|
value: toJS(option),
|
300
|
-
operator:
|
301
|
+
operator:
|
302
|
+
operator ??
|
303
|
+
selectColumnMenuFilterOperators.getEquals({ valueSelector, rowValueSelector }),
|
301
304
|
syntheticEvent: event,
|
302
305
|
});
|
303
306
|
};
|
@@ -318,3 +321,5 @@ export function selectColumnMenuFilter<TO>({
|
|
318
321
|
|
319
322
|
return renderCustomColumnMenuFilter(FilterCell, opts);
|
320
323
|
}
|
324
|
+
|
325
|
+
export { selectColumnMenuFilterOperators };
|