@react-fabric/searchbar 1.0.0-beta.5 → 1.0.0-beta.52
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/cjs/filterbar/FilterBar.js +9 -5
- package/dist/cjs/filterbar/FilterForm.js +138 -33
- package/dist/cjs/filterbar/FilterMenu.js +16 -4
- package/dist/cjs/filterbar/FilterTag.js +9 -4
- package/dist/cjs/filterbar/FilterView.js +5 -1
- package/dist/cjs/filterbar/QueryForm.js +8 -5
- package/dist/cjs/i18n/ar.json.js +42 -39
- package/dist/cjs/i18n/en.json.js +43 -39
- package/dist/cjs/searchbar/SearchBar.js +58 -4
- package/dist/cjs/types/index.js +12 -4
- package/dist/esm/filterbar/FilterBar.js +9 -5
- package/dist/esm/filterbar/FilterForm.js +139 -34
- package/dist/esm/filterbar/FilterMenu.js +16 -4
- package/dist/esm/filterbar/FilterTag.js +9 -4
- package/dist/esm/filterbar/FilterView.js +5 -1
- package/dist/esm/filterbar/QueryForm.js +8 -5
- package/dist/esm/i18n/ar.json.js +42 -39
- package/dist/esm/i18n/en.json.js +43 -39
- package/dist/esm/searchbar/SearchBar.js +59 -5
- package/dist/esm/types/index.js +12 -4
- package/dist/types/filterbar/Context.d.ts +2 -3
- package/dist/types/filterbar/FilterBar.d.ts +27 -1
- package/dist/types/filterbar/FilterMenu.d.ts +2 -1
- package/dist/types/filterbar/FilterTag.d.ts +2 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/searchbar/SearchBar.d.ts +35 -1
- package/dist/types/types/index.d.ts +19 -10
- package/package.json +15 -13
- package/src/filterbar/Context.tsx +4 -1
- package/src/filterbar/FilterBar.tsx +48 -6
- package/src/filterbar/FilterForm.tsx +107 -22
- package/src/filterbar/FilterMenu.tsx +30 -3
- package/src/filterbar/FilterTag.tsx +25 -6
- package/src/filterbar/FilterView.tsx +4 -1
- package/src/filterbar/QueryForm.tsx +10 -4
- package/src/i18n/ar.json +42 -39
- package/src/i18n/en.json +43 -39
- package/src/index.ts +6 -1
- package/src/searchbar/SearchBar.tsx +52 -2
- package/src/types/index.ts +57 -34
|
@@ -1,22 +1,27 @@
|
|
|
1
|
-
import { type ChildrenProp } from "@react-fabric/core/dist/types/types";
|
|
1
|
+
import { type ChildrenProp, type RefProp } from "@react-fabric/core/dist/types/types";
|
|
2
2
|
import { type ReactElement } from "react";
|
|
3
3
|
export declare enum FIELD_TYPE {
|
|
4
4
|
ID = "ID",
|
|
5
5
|
STRING = "STRING",
|
|
6
|
+
TEXT = "TEXT",
|
|
6
7
|
NUMBER = "NUMBER",
|
|
7
8
|
DECIMAL = "DECIMAL",
|
|
8
9
|
BOOLEAN = "BOOLEAN",
|
|
10
|
+
DATE = "DATE",
|
|
11
|
+
DATETIME = "DATETIME",
|
|
9
12
|
NONE = "NONE"
|
|
10
13
|
}
|
|
11
14
|
export declare enum OPERATOR {
|
|
12
15
|
EXISTS = "EXISTS",
|
|
13
16
|
IS = "IS",
|
|
14
|
-
|
|
17
|
+
ALL = "ALL",
|
|
18
|
+
ANY = "ANY",
|
|
19
|
+
EQ = "EQ",
|
|
15
20
|
LT = "LT",
|
|
16
21
|
GT = "GT",
|
|
17
22
|
LTE = "LTE",
|
|
18
23
|
GTE = "GTE",
|
|
19
|
-
|
|
24
|
+
LIKE = "LIKE",
|
|
20
25
|
STARTS = "STARTS",
|
|
21
26
|
ENDS = "ENDS",
|
|
22
27
|
WITHIN = "WITHIN",
|
|
@@ -30,6 +35,9 @@ export declare const TypeOperators: {
|
|
|
30
35
|
};
|
|
31
36
|
/**
|
|
32
37
|
* @internal
|
|
38
|
+
* 0 single value
|
|
39
|
+
* 1 many values
|
|
40
|
+
* 2 two values
|
|
33
41
|
*/
|
|
34
42
|
export declare const OperatorValueType: {
|
|
35
43
|
[key in OPERATOR]: 0 | 1 | 2;
|
|
@@ -46,25 +54,25 @@ interface BaseFilter {
|
|
|
46
54
|
color?: string;
|
|
47
55
|
value?: FilterValue;
|
|
48
56
|
pinned?: boolean;
|
|
49
|
-
negate?: boolean;
|
|
50
57
|
disabled?: boolean;
|
|
51
58
|
required?: boolean;
|
|
52
59
|
canPin?: boolean;
|
|
53
60
|
canEdit?: boolean;
|
|
54
|
-
canInvert?: boolean;
|
|
55
61
|
canDisable?: boolean;
|
|
56
62
|
}
|
|
57
63
|
export type FilterObject = BaseFilter & ({
|
|
58
64
|
field: string;
|
|
59
|
-
type?: FIELD_TYPE;
|
|
60
65
|
operator: OPERATOR;
|
|
61
66
|
value?: FilterValue;
|
|
67
|
+
negate?: boolean;
|
|
68
|
+
canInvert?: boolean;
|
|
62
69
|
query?: never;
|
|
70
|
+
type?: string;
|
|
63
71
|
} | {
|
|
64
72
|
field?: never;
|
|
65
|
-
type?: never;
|
|
66
73
|
operator?: never;
|
|
67
74
|
label: string;
|
|
75
|
+
canInvert?: false;
|
|
68
76
|
query: string;
|
|
69
77
|
});
|
|
70
78
|
export interface SearchObject<T = string> {
|
|
@@ -84,7 +92,7 @@ export interface FilterField {
|
|
|
84
92
|
defaultOperator?: OPERATOR;
|
|
85
93
|
onSearch?: (q: string) => Promise<FieldValue[]> | FieldValue[];
|
|
86
94
|
}
|
|
87
|
-
interface BaseSearchBarProps extends Partial<ChildrenProp> {
|
|
95
|
+
interface BaseSearchBarProps extends Partial<ChildrenProp>, RefProp<HTMLInputElement> {
|
|
88
96
|
/**
|
|
89
97
|
* Query string
|
|
90
98
|
*/
|
|
@@ -174,11 +182,11 @@ export interface FilterBarProps {
|
|
|
174
182
|
/**
|
|
175
183
|
* Editable filters
|
|
176
184
|
*/
|
|
177
|
-
|
|
185
|
+
editable?: boolean;
|
|
178
186
|
/**
|
|
179
187
|
* Disable component
|
|
180
188
|
*/
|
|
181
|
-
|
|
189
|
+
disabled?: boolean;
|
|
182
190
|
/**
|
|
183
191
|
* Message for empty field list
|
|
184
192
|
*/
|
|
@@ -192,6 +200,7 @@ export interface FilterBarProps {
|
|
|
192
200
|
*/
|
|
193
201
|
excludedColor?: string;
|
|
194
202
|
allowAdd?: boolean;
|
|
203
|
+
queryLanguage?: "text" | "json";
|
|
195
204
|
querySchema?: Array<{
|
|
196
205
|
uri: string;
|
|
197
206
|
schema: KeyValue;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-fabric/searchbar",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.52",
|
|
4
4
|
"description": "RUF: Searchbar with filters package",
|
|
5
5
|
"author": "Adarsh Pastakia <adarshpastakia@outlook.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,24 +33,26 @@
|
|
|
33
33
|
"watch": "npm-run-all -p watch:rollup watch:dts"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@floating-ui/react": "0.
|
|
37
|
-
"@react-fabric/core": "^1.0.0-beta.
|
|
38
|
-
"@react-fabric/
|
|
39
|
-
"@react-fabric/
|
|
40
|
-
"@react-fabric/
|
|
41
|
-
"@react-fabric/utilities": "^1.0.0-beta.5",
|
|
36
|
+
"@floating-ui/react": "^0.27.9",
|
|
37
|
+
"@react-fabric/core": "^1.0.0-beta.52",
|
|
38
|
+
"@react-fabric/form": "^1.0.0-beta.52",
|
|
39
|
+
"@react-fabric/monaco": "^1.0.0-beta.52",
|
|
40
|
+
"@react-fabric/utilities": "^1.0.0-beta.52",
|
|
42
41
|
"classnames": "^2.5.1",
|
|
43
|
-
"react-hook-form": "^7.
|
|
42
|
+
"react-hook-form": "^7.56.4"
|
|
44
43
|
},
|
|
45
44
|
"peerDependencies": {
|
|
46
|
-
"i18next": "^
|
|
47
|
-
"react": "
|
|
48
|
-
"react-dom": "
|
|
49
|
-
"react-i18next": "^15.
|
|
45
|
+
"i18next": "^25.2.1",
|
|
46
|
+
"react": "^19.0.0",
|
|
47
|
+
"react-dom": "^19.0.0",
|
|
48
|
+
"react-i18next": "^15.5.2"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@react-fabric/superdate": "^1.0.0-beta.52"
|
|
50
52
|
},
|
|
51
53
|
"engines": {
|
|
52
54
|
"node": ">=18.12.0",
|
|
53
55
|
"npm": ">=8.19.0"
|
|
54
56
|
},
|
|
55
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "0eabb9d88d91af93d657bcc209b226fd576e8260"
|
|
56
58
|
}
|
|
@@ -25,7 +25,10 @@ import { createContext, useContext } from "react";
|
|
|
25
25
|
import { type FilterBarProps } from "../types";
|
|
26
26
|
|
|
27
27
|
export const FilterContext = createContext<
|
|
28
|
-
Pick<
|
|
28
|
+
Pick<
|
|
29
|
+
FilterBarProps,
|
|
30
|
+
"querySchema" | "queryLanguage" | "defaultQuery" | "fields"
|
|
31
|
+
>
|
|
29
32
|
>({});
|
|
30
33
|
|
|
31
34
|
export const useFilterContext = () => useContext(FilterContext);
|
|
@@ -39,11 +39,39 @@ import { FilterTag } from "./FilterTag";
|
|
|
39
39
|
import classNames from "classnames";
|
|
40
40
|
import { FilterContext } from "./Context";
|
|
41
41
|
|
|
42
|
+
/**
|
|
43
|
+
* FilterBar component allows users to manage a list of filters.
|
|
44
|
+
* It provides options to add, remove, and modify filters,
|
|
45
|
+
* as well as to enable or disable all filters at once.
|
|
46
|
+
* It also supports toggling between included and excluded filters.
|
|
47
|
+
*
|
|
48
|
+
* @param {FilterBarProps} props - The properties for the FilterBar component.
|
|
49
|
+
* @returns {JSX.Element} The rendered FilterBar component.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```jsx
|
|
53
|
+
* <FilterBar
|
|
54
|
+
* filters={filters}
|
|
55
|
+
* allowAdd={true}
|
|
56
|
+
* fields={fields}
|
|
57
|
+
* editable={true}
|
|
58
|
+
* querySchema={querySchema}
|
|
59
|
+
* queryLanguage="lucene"
|
|
60
|
+
* defaultQuery="*"
|
|
61
|
+
* includedColor="green"
|
|
62
|
+
* excludedColor="red"
|
|
63
|
+
* onFilterChanged={(newFilters) => console.log(newFilters)}
|
|
64
|
+
* />
|
|
65
|
+
* ```
|
|
66
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/story/searchbar-searchbar--search-bar} for more details on the properties.
|
|
67
|
+
*/
|
|
42
68
|
export const FilterBar = ({
|
|
43
69
|
filters = [],
|
|
44
70
|
allowAdd,
|
|
45
71
|
fields,
|
|
72
|
+
editable,
|
|
46
73
|
querySchema,
|
|
74
|
+
queryLanguage,
|
|
47
75
|
defaultQuery,
|
|
48
76
|
includedColor,
|
|
49
77
|
excludedColor,
|
|
@@ -88,9 +116,10 @@ export const FilterBar = ({
|
|
|
88
116
|
if (type === "disableAll") filter.disabled = true;
|
|
89
117
|
if (type === "enableAll") filter.disabled = false;
|
|
90
118
|
if (type === "toggleDisable") filter.disabled = !filter.disabled;
|
|
91
|
-
if (type === "excludeAll") filter.negate = true;
|
|
92
|
-
if (type === "includeAll") filter.negate = false;
|
|
93
|
-
if (type === "invertAll"
|
|
119
|
+
if (type === "excludeAll" && filter.field) filter.negate = true;
|
|
120
|
+
if (type === "includeAll" && filter.field) filter.negate = false;
|
|
121
|
+
if (type === "invertAll" && filter.field)
|
|
122
|
+
filter.negate = !filter.negate;
|
|
94
123
|
return { ...filter };
|
|
95
124
|
}),
|
|
96
125
|
);
|
|
@@ -113,9 +142,19 @@ export const FilterBar = ({
|
|
|
113
142
|
key.someDisabled = true;
|
|
114
143
|
if (!filter.disabled && filter.canDisable !== false && !key.someEnabled)
|
|
115
144
|
key.someEnabled = true;
|
|
116
|
-
if (
|
|
145
|
+
if (
|
|
146
|
+
filter.field &&
|
|
147
|
+
filter.negate &&
|
|
148
|
+
filter.canInvert !== false &&
|
|
149
|
+
!key.someExcluded
|
|
150
|
+
)
|
|
117
151
|
key.someExcluded = true;
|
|
118
|
-
if (
|
|
152
|
+
if (
|
|
153
|
+
filter.field &&
|
|
154
|
+
!filter.negate &&
|
|
155
|
+
filter.canInvert !== false &&
|
|
156
|
+
!key.someIncluded
|
|
157
|
+
)
|
|
119
158
|
key.someIncluded = true;
|
|
120
159
|
if (!filter.required && !key.canRemoveAll) key.canRemoveAll = true;
|
|
121
160
|
});
|
|
@@ -123,7 +162,9 @@ export const FilterBar = ({
|
|
|
123
162
|
}, [filters]);
|
|
124
163
|
|
|
125
164
|
return (
|
|
126
|
-
<FilterContext.Provider
|
|
165
|
+
<FilterContext.Provider
|
|
166
|
+
value={{ defaultQuery, querySchema, queryLanguage, fields }}
|
|
167
|
+
>
|
|
127
168
|
<div className="flex flex-wrap gap-1 items-center">
|
|
128
169
|
<Dropdown showArrow disabled={isEmpty(filters)}>
|
|
129
170
|
<Icon
|
|
@@ -171,6 +212,7 @@ export const FilterBar = ({
|
|
|
171
212
|
<FilterTag
|
|
172
213
|
key={idx}
|
|
173
214
|
filter={filter}
|
|
215
|
+
editable={editable}
|
|
174
216
|
includedColor={includedColor}
|
|
175
217
|
excludedColor={excludedColor}
|
|
176
218
|
onRemove={() => handleRemove(idx)}
|
|
@@ -25,12 +25,14 @@ import { useFloatingTree } from "@floating-ui/react";
|
|
|
25
25
|
import { Button, Col, Row } from "@react-fabric/core";
|
|
26
26
|
import {
|
|
27
27
|
Controller,
|
|
28
|
+
DateInput,
|
|
28
29
|
Field,
|
|
29
30
|
Form,
|
|
30
31
|
Input,
|
|
31
32
|
Number,
|
|
32
33
|
Select,
|
|
33
34
|
Switch,
|
|
35
|
+
Textarea,
|
|
34
36
|
type FormRef,
|
|
35
37
|
} from "@react-fabric/form";
|
|
36
38
|
import { isArray, shortHash, yup } from "@react-fabric/utilities";
|
|
@@ -48,6 +50,7 @@ import { useFilterContext } from "./Context";
|
|
|
48
50
|
const FilterSchema = new yup.ObjectSchema({
|
|
49
51
|
id: yup.string().required(),
|
|
50
52
|
field: yup.string().required(),
|
|
53
|
+
// type: yup.string().oneOf(Object.values(FIELD_TYPE)),
|
|
51
54
|
operator: yup.string().required().oneOf(Object.values(OPERATOR)),
|
|
52
55
|
negate: yup.boolean(),
|
|
53
56
|
label: yup.string(),
|
|
@@ -59,13 +62,40 @@ const FilterSchema = new yup.ObjectSchema({
|
|
|
59
62
|
otherwise: (schema) => schema.required(),
|
|
60
63
|
})
|
|
61
64
|
.when("operator", {
|
|
62
|
-
is: OPERATOR.
|
|
65
|
+
is: OPERATOR.ANY,
|
|
63
66
|
then: (schema) =>
|
|
64
67
|
schema.test({
|
|
65
68
|
name: "array-check",
|
|
66
69
|
message: `\${path} is a required field`,
|
|
67
70
|
test: (val: AnyObject = []) => val?.length > 0,
|
|
68
71
|
}),
|
|
72
|
+
})
|
|
73
|
+
.when("operator", {
|
|
74
|
+
is: OPERATOR.ALL,
|
|
75
|
+
then: (schema) =>
|
|
76
|
+
schema.test({
|
|
77
|
+
name: "array-check",
|
|
78
|
+
message: `\${path} is a required field`,
|
|
79
|
+
test: (val: AnyObject = []) => val?.length > 0,
|
|
80
|
+
}),
|
|
81
|
+
})
|
|
82
|
+
.when("operator", {
|
|
83
|
+
is: OPERATOR.BETWEEN,
|
|
84
|
+
then: (schema) =>
|
|
85
|
+
schema.test({
|
|
86
|
+
name: "array-check",
|
|
87
|
+
message: `\${path} is a required field`,
|
|
88
|
+
test: (val: AnyObject = []) => val?.length > 0 && val[0] && val[1],
|
|
89
|
+
}),
|
|
90
|
+
})
|
|
91
|
+
.when("operator", {
|
|
92
|
+
is: OPERATOR.BETWEEN,
|
|
93
|
+
then: (schema) =>
|
|
94
|
+
schema.test({
|
|
95
|
+
name: "array-check",
|
|
96
|
+
message: `\${path} min max`,
|
|
97
|
+
test: (val: AnyObject = []) => val?.length > 0 && val[0] < val[1],
|
|
98
|
+
}),
|
|
69
99
|
}),
|
|
70
100
|
});
|
|
71
101
|
|
|
@@ -88,13 +118,15 @@ export const FilterForm = ({
|
|
|
88
118
|
const [values, setValues] = useState<FilterSchemaType>(filter as AnyObject);
|
|
89
119
|
|
|
90
120
|
useEffect(() => {
|
|
91
|
-
if (filter && "field" in filter && filter.field)
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
121
|
+
if (filter && "field" in filter && filter.field) {
|
|
122
|
+
formRef.current?.setValues(filter);
|
|
123
|
+
} else {
|
|
124
|
+
formRef.current?.setValues({
|
|
125
|
+
id: shortHash(),
|
|
126
|
+
field: "",
|
|
127
|
+
operator: OPERATOR.EXISTS,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
98
130
|
}, [filter]);
|
|
99
131
|
|
|
100
132
|
useEffect(() => {
|
|
@@ -119,13 +151,15 @@ export const FilterForm = ({
|
|
|
119
151
|
formRef.current?.setValue("value", undefined);
|
|
120
152
|
}
|
|
121
153
|
if (field?.type === FIELD_TYPE.STRING) {
|
|
122
|
-
if (values?.operator
|
|
154
|
+
if ([OPERATOR.ALL, OPERATOR.ANY].includes(values?.operator)) {
|
|
123
155
|
!isArray(values.value) && formRef.current?.setValue("value", []);
|
|
124
156
|
} else {
|
|
125
157
|
isArray(values.value) && formRef.current?.setValue("value", undefined);
|
|
126
158
|
}
|
|
127
159
|
}
|
|
128
160
|
if (
|
|
161
|
+
field?.type === FIELD_TYPE.DATE ||
|
|
162
|
+
field?.type === FIELD_TYPE.DATETIME ||
|
|
129
163
|
field?.type === FIELD_TYPE.NUMBER ||
|
|
130
164
|
field?.type === FIELD_TYPE.DECIMAL
|
|
131
165
|
) {
|
|
@@ -137,7 +171,7 @@ export const FilterForm = ({
|
|
|
137
171
|
}
|
|
138
172
|
if (
|
|
139
173
|
field?.type === FIELD_TYPE.BOOLEAN &&
|
|
140
|
-
values?.operator
|
|
174
|
+
[OPERATOR.IS, OPERATOR.EQ].includes(values?.operator) &&
|
|
141
175
|
values?.value === undefined
|
|
142
176
|
) {
|
|
143
177
|
formRef.current?.setValue("value", false);
|
|
@@ -155,7 +189,7 @@ export const FilterForm = ({
|
|
|
155
189
|
);
|
|
156
190
|
}
|
|
157
191
|
if (field?.type === FIELD_TYPE.STRING || field?.type === FIELD_TYPE.ID) {
|
|
158
|
-
if (values?.operator
|
|
192
|
+
if ([OPERATOR.ALL, OPERATOR.ANY].includes(values?.operator)) {
|
|
159
193
|
return (
|
|
160
194
|
<Controller name="value">
|
|
161
195
|
<Select
|
|
@@ -169,6 +203,19 @@ export const FilterForm = ({
|
|
|
169
203
|
/>
|
|
170
204
|
</Controller>
|
|
171
205
|
);
|
|
206
|
+
} else if (!!field.onSearch || field.values?.length) {
|
|
207
|
+
return (
|
|
208
|
+
<Controller name="value">
|
|
209
|
+
<Select
|
|
210
|
+
searchable
|
|
211
|
+
allowCreate
|
|
212
|
+
allowClear
|
|
213
|
+
options={field.values ?? []}
|
|
214
|
+
label={t("label.value")}
|
|
215
|
+
onQuery={field.onSearch}
|
|
216
|
+
/>
|
|
217
|
+
</Controller>
|
|
218
|
+
);
|
|
172
219
|
} else {
|
|
173
220
|
return (
|
|
174
221
|
<Controller name="value">
|
|
@@ -177,6 +224,13 @@ export const FilterForm = ({
|
|
|
177
224
|
);
|
|
178
225
|
}
|
|
179
226
|
}
|
|
227
|
+
if (field.type === FIELD_TYPE.TEXT) {
|
|
228
|
+
return (
|
|
229
|
+
<Controller name="value">
|
|
230
|
+
<Textarea rows={3} label={t("label.value")} allowClear />
|
|
231
|
+
</Controller>
|
|
232
|
+
);
|
|
233
|
+
}
|
|
180
234
|
if (
|
|
181
235
|
field?.type === FIELD_TYPE.DECIMAL ||
|
|
182
236
|
field?.type === FIELD_TYPE.NUMBER
|
|
@@ -184,15 +238,17 @@ export const FilterForm = ({
|
|
|
184
238
|
const step = field.type === FIELD_TYPE.DECIMAL ? 0.1 : 1;
|
|
185
239
|
if (values?.operator === OPERATOR.BETWEEN) {
|
|
186
240
|
return (
|
|
187
|
-
<
|
|
188
|
-
<
|
|
189
|
-
<
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
<
|
|
194
|
-
|
|
195
|
-
|
|
241
|
+
<Controller name="value">
|
|
242
|
+
<Field label={t("label.value")}>
|
|
243
|
+
<Controller name="value[0]">
|
|
244
|
+
<Number step={step} allowClear />
|
|
245
|
+
</Controller>
|
|
246
|
+
<span className="p-2 text-muted">{`≷`}</span>
|
|
247
|
+
<Controller name="value[1]">
|
|
248
|
+
<Number step={step} allowClear />
|
|
249
|
+
</Controller>
|
|
250
|
+
</Field>
|
|
251
|
+
</Controller>
|
|
196
252
|
);
|
|
197
253
|
} else {
|
|
198
254
|
return (
|
|
@@ -202,6 +258,33 @@ export const FilterForm = ({
|
|
|
202
258
|
);
|
|
203
259
|
}
|
|
204
260
|
}
|
|
261
|
+
if (
|
|
262
|
+
field?.type === FIELD_TYPE.DATE ||
|
|
263
|
+
field?.type === FIELD_TYPE.DATETIME
|
|
264
|
+
) {
|
|
265
|
+
const type = field.type === FIELD_TYPE.DATETIME ? "datetime" : "date";
|
|
266
|
+
if (values?.operator === OPERATOR.BETWEEN) {
|
|
267
|
+
return (
|
|
268
|
+
<Controller name="value">
|
|
269
|
+
<Field label={t("label.value")}>
|
|
270
|
+
<Controller name="value[0]">
|
|
271
|
+
<DateInput type={type} allowClear />
|
|
272
|
+
</Controller>
|
|
273
|
+
<span className="p-2 text-muted">{`≷`}</span>
|
|
274
|
+
<Controller name="value[1]">
|
|
275
|
+
<DateInput type={type} allowClear />
|
|
276
|
+
</Controller>
|
|
277
|
+
</Field>
|
|
278
|
+
</Controller>
|
|
279
|
+
);
|
|
280
|
+
} else {
|
|
281
|
+
return (
|
|
282
|
+
<Controller name="value">
|
|
283
|
+
<DateInput type={type} allowClear />
|
|
284
|
+
</Controller>
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
205
288
|
}, [field, values?.operator]);
|
|
206
289
|
|
|
207
290
|
const handleSubmit = useCallback(
|
|
@@ -213,11 +296,12 @@ export const FilterForm = ({
|
|
|
213
296
|
operator: model.operator,
|
|
214
297
|
value: model.value as AnyObject,
|
|
215
298
|
label: model.label,
|
|
299
|
+
type: field?.type,
|
|
216
300
|
};
|
|
217
301
|
onChange?.(filter);
|
|
218
302
|
tree?.events.emit("close");
|
|
219
303
|
},
|
|
220
|
-
[onChange],
|
|
304
|
+
[field, onChange],
|
|
221
305
|
);
|
|
222
306
|
|
|
223
307
|
return (
|
|
@@ -234,6 +318,7 @@ export const FilterForm = ({
|
|
|
234
318
|
<Controller name="field">
|
|
235
319
|
<Select<FilterField>
|
|
236
320
|
required
|
|
321
|
+
searchable
|
|
237
322
|
ref={inputRef}
|
|
238
323
|
label={t("label.field")}
|
|
239
324
|
options={fields}
|
|
@@ -273,7 +358,7 @@ export const FilterForm = ({
|
|
|
273
358
|
}
|
|
274
359
|
/>
|
|
275
360
|
</Controller>
|
|
276
|
-
<div className="flex
|
|
361
|
+
<div className="flex mt-4 justify-end gap-1 sticky bottom-1 bg-base">
|
|
277
362
|
{onRemove && (
|
|
278
363
|
<div className="flex-1">
|
|
279
364
|
<Button
|
|
@@ -24,17 +24,24 @@
|
|
|
24
24
|
import { CoreIcons, Divider, Menu, MenuItem } from "@react-fabric/core";
|
|
25
25
|
import { useState } from "react";
|
|
26
26
|
import { useTranslation } from "react-i18next";
|
|
27
|
-
import { type FilterField, type FilterObject } from "../types";
|
|
27
|
+
import { OPERATOR, type FilterField, type FilterObject } from "../types";
|
|
28
28
|
import { FilterEdit } from "./FilterEdit";
|
|
29
29
|
import { FilterView } from "./FilterView";
|
|
30
30
|
|
|
31
|
+
const MATCH_ALL =
|
|
32
|
+
"M9,5C10.04,5 11.06,5.24 12,5.68C12.94,5.24 13.96,5 15,5A7,7 0 0,1 22,12A7,7 0 0,1 15,19C13.96,19 12.94,18.76 12,18.32C11.06,18.76 10.04,19 9,19A7,7 0 0,1 2,12A7,7 0 0,1 9,5M8.5,12C8.5,13.87 9.29,15.56 10.56,16.75L11.56,16.29C10.31,15.29 9.5,13.74 9.5,12C9.5,10.26 10.31,8.71 11.56,7.71L10.56,7.25C9.29,8.44 8.5,10.13 8.5,12M15.5,12C15.5,10.13 14.71,8.44 13.44,7.25L12.44,7.71C13.69,8.71 14.5,10.26 14.5,12C14.5,13.74 13.69,15.29 12.44,16.29L13.44,16.75C14.71,15.56 15.5,13.87 15.5,12Z";
|
|
33
|
+
const MATCH_ANY =
|
|
34
|
+
"M9,5A7,7 0 0,0 2,12A7,7 0 0,0 9,19C10.04,19 11.06,18.76 12,18.32C12.94,18.76 13.96,19 15,19A7,7 0 0,0 22,12A7,7 0 0,0 15,5C13.96,5 12.94,5.24 12,5.68C11.06,5.24 10.04,5 9,5M9,7C9.34,7 9.67,7.03 10,7.1C8.72,8.41 8,10.17 8,12C8,13.83 8.72,15.59 10,16.89C9.67,16.96 9.34,17 9,17A5,5 0 0,1 4,12A5,5 0 0,1 9,7M15,7A5,5 0 0,1 20,12A5,5 0 0,1 15,17C14.66,17 14.33,16.97 14,16.9C15.28,15.59 16,13.83 16,12C16,10.17 15.28,8.41 14,7.11C14.33,7.04 14.66,7 15,7Z";
|
|
35
|
+
|
|
31
36
|
export const FilterMenu = ({
|
|
32
37
|
filter,
|
|
33
38
|
fields,
|
|
39
|
+
editable,
|
|
34
40
|
onChange,
|
|
35
41
|
onRemove,
|
|
36
42
|
}: {
|
|
37
43
|
fields?: FilterField[];
|
|
44
|
+
editable?: boolean;
|
|
38
45
|
filter: FilterObject;
|
|
39
46
|
onRemove: () => void;
|
|
40
47
|
onChange: (filter: FilterObject) => void;
|
|
@@ -48,7 +55,7 @@ export const FilterMenu = ({
|
|
|
48
55
|
<FilterView filter={filter} onRemove={onRemove} />
|
|
49
56
|
) : (
|
|
50
57
|
<Menu className="text-sm">
|
|
51
|
-
{filter.canEdit !== false ? (
|
|
58
|
+
{editable && filter.canEdit !== false ? (
|
|
52
59
|
<MenuItem
|
|
53
60
|
icon={CoreIcons.edit}
|
|
54
61
|
label={t("label.edit")}
|
|
@@ -68,13 +75,33 @@ export const FilterMenu = ({
|
|
|
68
75
|
/>
|
|
69
76
|
)}
|
|
70
77
|
<Divider />
|
|
78
|
+
{filter.operator &&
|
|
79
|
+
[OPERATOR.ALL, OPERATOR.ANY].includes(filter.operator) && (
|
|
80
|
+
<MenuItem
|
|
81
|
+
label={t(
|
|
82
|
+
filter.operator === OPERATOR.ALL
|
|
83
|
+
? "label.matchAny"
|
|
84
|
+
: "label.matchAll",
|
|
85
|
+
)}
|
|
86
|
+
icon={t(filter.operator === OPERATOR.ALL ? MATCH_ANY : MATCH_ALL)}
|
|
87
|
+
onClick={() =>
|
|
88
|
+
onChange({
|
|
89
|
+
...filter,
|
|
90
|
+
operator:
|
|
91
|
+
filter.operator === OPERATOR.ALL
|
|
92
|
+
? OPERATOR.ANY
|
|
93
|
+
: OPERATOR.ALL,
|
|
94
|
+
})
|
|
95
|
+
}
|
|
96
|
+
/>
|
|
97
|
+
)}
|
|
71
98
|
{filter.canPin !== false && (
|
|
72
99
|
<MenuItem
|
|
73
100
|
label={t(filter.pinned ? "label.unpin" : "label.pin")}
|
|
74
101
|
onClick={() => onChange({ ...filter, pinned: !filter.pinned })}
|
|
75
102
|
/>
|
|
76
103
|
)}
|
|
77
|
-
{filter.canInvert !== false && (
|
|
104
|
+
{filter.canInvert !== false && filter.field && (
|
|
78
105
|
<MenuItem
|
|
79
106
|
label={t(filter.negate ? "label.include" : "label.exclude")}
|
|
80
107
|
onClick={() => onChange({ ...filter, negate: !filter.negate })}
|
|
@@ -26,18 +26,20 @@ import { isNil } from "@react-fabric/utilities";
|
|
|
26
26
|
import classNames from "classnames";
|
|
27
27
|
import { Fragment, useMemo } from "react";
|
|
28
28
|
import { useTranslation } from "react-i18next";
|
|
29
|
-
import { type FilterBarProps, type FilterObject } from "../types";
|
|
29
|
+
import { OPERATOR, type FilterBarProps, type FilterObject } from "../types";
|
|
30
30
|
import { FilterMenu } from "./FilterMenu";
|
|
31
31
|
|
|
32
32
|
export const FilterTag = ({
|
|
33
33
|
filter,
|
|
34
34
|
fields,
|
|
35
|
+
editable,
|
|
35
36
|
includedColor = "primary-500",
|
|
36
37
|
excludedColor = "danger-500",
|
|
37
38
|
onChange,
|
|
38
39
|
onRemove,
|
|
39
40
|
}: {
|
|
40
41
|
filter: FilterObject;
|
|
42
|
+
editable?: boolean;
|
|
41
43
|
onRemove: () => void;
|
|
42
44
|
onChange: (filter: FilterObject) => void;
|
|
43
45
|
} & Pick<FilterBarProps, "fields" | "includedColor" | "excludedColor">) => {
|
|
@@ -46,14 +48,18 @@ export const FilterTag = ({
|
|
|
46
48
|
if (filter.label)
|
|
47
49
|
return (
|
|
48
50
|
<Fragment>
|
|
49
|
-
{filter.negate &&
|
|
51
|
+
{filter.field && filter.negate && (
|
|
52
|
+
<span className="font-semibold">NOT</span>
|
|
53
|
+
)}
|
|
50
54
|
<span>{filter.label}</span>
|
|
51
55
|
</Fragment>
|
|
52
56
|
);
|
|
53
57
|
|
|
54
58
|
return (
|
|
55
59
|
<Fragment>
|
|
56
|
-
{filter.negate &&
|
|
60
|
+
{filter.field && filter.negate && (
|
|
61
|
+
<span className="font-semibold">NOT</span>
|
|
62
|
+
)}
|
|
57
63
|
<span>{filter.field}</span>
|
|
58
64
|
<span className="font-semibold">
|
|
59
65
|
{t(`operator.${filter.operator}`, { defaultValue: filter.operator })}
|
|
@@ -68,7 +74,9 @@ export const FilterTag = ({
|
|
|
68
74
|
}, [filter]);
|
|
69
75
|
|
|
70
76
|
const color = useMemo(
|
|
71
|
-
() =>
|
|
77
|
+
() =>
|
|
78
|
+
filter.color ??
|
|
79
|
+
(filter.field && filter.negate ? excludedColor : includedColor),
|
|
72
80
|
[filter, includedColor, excludedColor],
|
|
73
81
|
);
|
|
74
82
|
|
|
@@ -82,7 +90,10 @@ export const FilterTag = ({
|
|
|
82
90
|
<Chip
|
|
83
91
|
size="sm"
|
|
84
92
|
color={color}
|
|
85
|
-
className=
|
|
93
|
+
className={classNames(
|
|
94
|
+
"outline max-w-60",
|
|
95
|
+
filter.disabled && "opacity-65",
|
|
96
|
+
)}
|
|
86
97
|
variant={filter.pinned ? "solid" : undefined}
|
|
87
98
|
icon={icon}
|
|
88
99
|
iconColor={color}
|
|
@@ -90,6 +101,8 @@ export const FilterTag = ({
|
|
|
90
101
|
onChange({ ...filter, disabled: !filter.disabled }),
|
|
91
102
|
e.stopPropagation(),
|
|
92
103
|
]}
|
|
104
|
+
data-ref="filterTag"
|
|
105
|
+
data-test-value={filter.id}
|
|
93
106
|
stopPropagation
|
|
94
107
|
onRemove={filter.required ? undefined : () => onRemove()}
|
|
95
108
|
>
|
|
@@ -99,13 +112,19 @@ export const FilterTag = ({
|
|
|
99
112
|
filter.disabled && "line-through opacity-65",
|
|
100
113
|
)}
|
|
101
114
|
>
|
|
102
|
-
{filter.pinned &&
|
|
115
|
+
{filter.pinned && (
|
|
116
|
+
<Icon
|
|
117
|
+
className="flex-content"
|
|
118
|
+
icon={filter.icon ?? CoreIcons.pin}
|
|
119
|
+
/>
|
|
120
|
+
)}
|
|
103
121
|
{label}
|
|
104
122
|
</div>
|
|
105
123
|
</Chip>
|
|
106
124
|
<FilterMenu
|
|
107
125
|
filter={filter}
|
|
108
126
|
fields={fields}
|
|
127
|
+
editable={editable}
|
|
109
128
|
onChange={onChange}
|
|
110
129
|
onRemove={onRemove}
|
|
111
130
|
/>
|
|
@@ -47,9 +47,12 @@ export const FilterView = ({
|
|
|
47
47
|
value = `[${filter.value?.join(" - ")}]`;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
if (filter.operator === OPERATOR.
|
|
50
|
+
if (filter.operator === OPERATOR.ANY && isArray(filter.value)) {
|
|
51
51
|
value = `[${filter.value?.join(", ")}]`;
|
|
52
52
|
}
|
|
53
|
+
if (filter.operator === OPERATOR.ALL && isArray(filter.value)) {
|
|
54
|
+
value = `(${filter.value?.join(", ")})`;
|
|
55
|
+
}
|
|
53
56
|
|
|
54
57
|
return (
|
|
55
58
|
<Fragment>
|