@react-fabric/searchbar 1.0.0-beta.5 → 1.0.0-beta.51
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 +123 -30
- package/dist/cjs/filterbar/FilterMenu.js +4 -3
- package/dist/cjs/filterbar/FilterTag.js +9 -4
- package/dist/cjs/filterbar/QueryForm.js +8 -5
- package/dist/cjs/i18n/en.json.js +1 -0
- package/dist/cjs/searchbar/SearchBar.js +24 -4
- package/dist/cjs/types/index.js +9 -2
- package/dist/esm/filterbar/FilterBar.js +9 -5
- package/dist/esm/filterbar/FilterForm.js +124 -31
- package/dist/esm/filterbar/FilterMenu.js +4 -3
- package/dist/esm/filterbar/FilterTag.js +9 -4
- package/dist/esm/filterbar/QueryForm.js +8 -5
- package/dist/esm/i18n/en.json.js +1 -0
- package/dist/esm/searchbar/SearchBar.js +25 -5
- package/dist/esm/types/index.js +9 -2
- package/dist/types/filterbar/Context.d.ts +2 -2
- package/dist/types/filterbar/FilterBar.d.ts +1 -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 +1 -1
- package/dist/types/types/index.d.ts +16 -8
- package/package.json +15 -13
- package/src/filterbar/Context.tsx +4 -1
- package/src/filterbar/FilterBar.tsx +22 -6
- package/src/filterbar/FilterForm.tsx +95 -19
- package/src/filterbar/FilterMenu.tsx +4 -2
- package/src/filterbar/FilterTag.tsx +24 -5
- package/src/filterbar/QueryForm.tsx +10 -4
- package/src/i18n/en.json +1 -0
- package/src/index.ts +6 -1
- package/src/searchbar/SearchBar.tsx +18 -2
- package/src/types/index.ts +46 -30
|
@@ -1,17 +1,21 @@
|
|
|
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
|
IN = "IN",
|
|
18
|
+
EQ = "EQ",
|
|
15
19
|
LT = "LT",
|
|
16
20
|
GT = "GT",
|
|
17
21
|
LTE = "LTE",
|
|
@@ -30,6 +34,9 @@ export declare const TypeOperators: {
|
|
|
30
34
|
};
|
|
31
35
|
/**
|
|
32
36
|
* @internal
|
|
37
|
+
* 0 single value
|
|
38
|
+
* 1 many values
|
|
39
|
+
* 2 two values
|
|
33
40
|
*/
|
|
34
41
|
export declare const OperatorValueType: {
|
|
35
42
|
[key in OPERATOR]: 0 | 1 | 2;
|
|
@@ -46,25 +53,25 @@ interface BaseFilter {
|
|
|
46
53
|
color?: string;
|
|
47
54
|
value?: FilterValue;
|
|
48
55
|
pinned?: boolean;
|
|
49
|
-
negate?: boolean;
|
|
50
56
|
disabled?: boolean;
|
|
51
57
|
required?: boolean;
|
|
52
58
|
canPin?: boolean;
|
|
53
59
|
canEdit?: boolean;
|
|
54
|
-
canInvert?: boolean;
|
|
55
60
|
canDisable?: boolean;
|
|
56
61
|
}
|
|
57
62
|
export type FilterObject = BaseFilter & ({
|
|
58
63
|
field: string;
|
|
59
|
-
type?: FIELD_TYPE;
|
|
60
64
|
operator: OPERATOR;
|
|
61
65
|
value?: FilterValue;
|
|
66
|
+
negate?: boolean;
|
|
67
|
+
canInvert?: boolean;
|
|
62
68
|
query?: never;
|
|
69
|
+
type?: string;
|
|
63
70
|
} | {
|
|
64
71
|
field?: never;
|
|
65
|
-
type?: never;
|
|
66
72
|
operator?: never;
|
|
67
73
|
label: string;
|
|
74
|
+
canInvert?: false;
|
|
68
75
|
query: string;
|
|
69
76
|
});
|
|
70
77
|
export interface SearchObject<T = string> {
|
|
@@ -84,7 +91,7 @@ export interface FilterField {
|
|
|
84
91
|
defaultOperator?: OPERATOR;
|
|
85
92
|
onSearch?: (q: string) => Promise<FieldValue[]> | FieldValue[];
|
|
86
93
|
}
|
|
87
|
-
interface BaseSearchBarProps extends Partial<ChildrenProp> {
|
|
94
|
+
interface BaseSearchBarProps extends Partial<ChildrenProp>, RefProp<HTMLInputElement> {
|
|
88
95
|
/**
|
|
89
96
|
* Query string
|
|
90
97
|
*/
|
|
@@ -174,11 +181,11 @@ export interface FilterBarProps {
|
|
|
174
181
|
/**
|
|
175
182
|
* Editable filters
|
|
176
183
|
*/
|
|
177
|
-
|
|
184
|
+
editable?: boolean;
|
|
178
185
|
/**
|
|
179
186
|
* Disable component
|
|
180
187
|
*/
|
|
181
|
-
|
|
188
|
+
disabled?: boolean;
|
|
182
189
|
/**
|
|
183
190
|
* Message for empty field list
|
|
184
191
|
*/
|
|
@@ -192,6 +199,7 @@ export interface FilterBarProps {
|
|
|
192
199
|
*/
|
|
193
200
|
excludedColor?: string;
|
|
194
201
|
allowAdd?: boolean;
|
|
202
|
+
queryLanguage?: "text" | "json";
|
|
195
203
|
querySchema?: Array<{
|
|
196
204
|
uri: string;
|
|
197
205
|
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.51",
|
|
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.51",
|
|
38
|
+
"@react-fabric/form": "^1.0.0-beta.51",
|
|
39
|
+
"@react-fabric/monaco": "^1.0.0-beta.51",
|
|
40
|
+
"@react-fabric/utilities": "^1.0.0-beta.50",
|
|
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.51"
|
|
50
52
|
},
|
|
51
53
|
"engines": {
|
|
52
54
|
"node": ">=18.12.0",
|
|
53
55
|
"npm": ">=8.19.0"
|
|
54
56
|
},
|
|
55
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "a1b04de4663045f82992bff2aef8db26608eac74"
|
|
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);
|
|
@@ -43,7 +43,9 @@ export const FilterBar = ({
|
|
|
43
43
|
filters = [],
|
|
44
44
|
allowAdd,
|
|
45
45
|
fields,
|
|
46
|
+
editable,
|
|
46
47
|
querySchema,
|
|
48
|
+
queryLanguage,
|
|
47
49
|
defaultQuery,
|
|
48
50
|
includedColor,
|
|
49
51
|
excludedColor,
|
|
@@ -88,9 +90,10 @@ export const FilterBar = ({
|
|
|
88
90
|
if (type === "disableAll") filter.disabled = true;
|
|
89
91
|
if (type === "enableAll") filter.disabled = false;
|
|
90
92
|
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"
|
|
93
|
+
if (type === "excludeAll" && filter.field) filter.negate = true;
|
|
94
|
+
if (type === "includeAll" && filter.field) filter.negate = false;
|
|
95
|
+
if (type === "invertAll" && filter.field)
|
|
96
|
+
filter.negate = !filter.negate;
|
|
94
97
|
return { ...filter };
|
|
95
98
|
}),
|
|
96
99
|
);
|
|
@@ -113,9 +116,19 @@ export const FilterBar = ({
|
|
|
113
116
|
key.someDisabled = true;
|
|
114
117
|
if (!filter.disabled && filter.canDisable !== false && !key.someEnabled)
|
|
115
118
|
key.someEnabled = true;
|
|
116
|
-
if (
|
|
119
|
+
if (
|
|
120
|
+
filter.field &&
|
|
121
|
+
filter.negate &&
|
|
122
|
+
filter.canInvert !== false &&
|
|
123
|
+
!key.someExcluded
|
|
124
|
+
)
|
|
117
125
|
key.someExcluded = true;
|
|
118
|
-
if (
|
|
126
|
+
if (
|
|
127
|
+
filter.field &&
|
|
128
|
+
!filter.negate &&
|
|
129
|
+
filter.canInvert !== false &&
|
|
130
|
+
!key.someIncluded
|
|
131
|
+
)
|
|
119
132
|
key.someIncluded = true;
|
|
120
133
|
if (!filter.required && !key.canRemoveAll) key.canRemoveAll = true;
|
|
121
134
|
});
|
|
@@ -123,7 +136,9 @@ export const FilterBar = ({
|
|
|
123
136
|
}, [filters]);
|
|
124
137
|
|
|
125
138
|
return (
|
|
126
|
-
<FilterContext.Provider
|
|
139
|
+
<FilterContext.Provider
|
|
140
|
+
value={{ defaultQuery, querySchema, queryLanguage, fields }}
|
|
141
|
+
>
|
|
127
142
|
<div className="flex flex-wrap gap-1 items-center">
|
|
128
143
|
<Dropdown showArrow disabled={isEmpty(filters)}>
|
|
129
144
|
<Icon
|
|
@@ -171,6 +186,7 @@ export const FilterBar = ({
|
|
|
171
186
|
<FilterTag
|
|
172
187
|
key={idx}
|
|
173
188
|
filter={filter}
|
|
189
|
+
editable={editable}
|
|
174
190
|
includedColor={includedColor}
|
|
175
191
|
excludedColor={excludedColor}
|
|
176
192
|
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(),
|
|
@@ -66,6 +69,24 @@ const FilterSchema = new yup.ObjectSchema({
|
|
|
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.BETWEEN,
|
|
75
|
+
then: (schema) =>
|
|
76
|
+
schema.test({
|
|
77
|
+
name: "array-check",
|
|
78
|
+
message: `\${path} is a required field`,
|
|
79
|
+
test: (val: AnyObject = []) => val?.length > 0 && val[0] && val[1],
|
|
80
|
+
}),
|
|
81
|
+
})
|
|
82
|
+
.when("operator", {
|
|
83
|
+
is: OPERATOR.BETWEEN,
|
|
84
|
+
then: (schema) =>
|
|
85
|
+
schema.test({
|
|
86
|
+
name: "array-check",
|
|
87
|
+
message: `\${path} min max`,
|
|
88
|
+
test: (val: AnyObject = []) => val?.length > 0 && val[0] < val[1],
|
|
89
|
+
}),
|
|
69
90
|
}),
|
|
70
91
|
});
|
|
71
92
|
|
|
@@ -88,13 +109,15 @@ export const FilterForm = ({
|
|
|
88
109
|
const [values, setValues] = useState<FilterSchemaType>(filter as AnyObject);
|
|
89
110
|
|
|
90
111
|
useEffect(() => {
|
|
91
|
-
if (filter && "field" in filter && filter.field)
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
112
|
+
if (filter && "field" in filter && filter.field) {
|
|
113
|
+
formRef.current?.setValues(filter);
|
|
114
|
+
} else {
|
|
115
|
+
formRef.current?.setValues({
|
|
116
|
+
id: shortHash(),
|
|
117
|
+
field: "",
|
|
118
|
+
operator: OPERATOR.EXISTS,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
98
121
|
}, [filter]);
|
|
99
122
|
|
|
100
123
|
useEffect(() => {
|
|
@@ -126,6 +149,8 @@ export const FilterForm = ({
|
|
|
126
149
|
}
|
|
127
150
|
}
|
|
128
151
|
if (
|
|
152
|
+
field?.type === FIELD_TYPE.DATE ||
|
|
153
|
+
field?.type === FIELD_TYPE.DATETIME ||
|
|
129
154
|
field?.type === FIELD_TYPE.NUMBER ||
|
|
130
155
|
field?.type === FIELD_TYPE.DECIMAL
|
|
131
156
|
) {
|
|
@@ -137,7 +162,7 @@ export const FilterForm = ({
|
|
|
137
162
|
}
|
|
138
163
|
if (
|
|
139
164
|
field?.type === FIELD_TYPE.BOOLEAN &&
|
|
140
|
-
values?.operator
|
|
165
|
+
[OPERATOR.IS, OPERATOR.EQ].includes(values?.operator) &&
|
|
141
166
|
values?.value === undefined
|
|
142
167
|
) {
|
|
143
168
|
formRef.current?.setValue("value", false);
|
|
@@ -169,6 +194,19 @@ export const FilterForm = ({
|
|
|
169
194
|
/>
|
|
170
195
|
</Controller>
|
|
171
196
|
);
|
|
197
|
+
} else if (!!field.onSearch || field.values?.length) {
|
|
198
|
+
return (
|
|
199
|
+
<Controller name="value">
|
|
200
|
+
<Select
|
|
201
|
+
searchable
|
|
202
|
+
allowCreate
|
|
203
|
+
allowClear
|
|
204
|
+
options={field.values ?? []}
|
|
205
|
+
label={t("label.value")}
|
|
206
|
+
onQuery={field.onSearch}
|
|
207
|
+
/>
|
|
208
|
+
</Controller>
|
|
209
|
+
);
|
|
172
210
|
} else {
|
|
173
211
|
return (
|
|
174
212
|
<Controller name="value">
|
|
@@ -177,6 +215,13 @@ export const FilterForm = ({
|
|
|
177
215
|
);
|
|
178
216
|
}
|
|
179
217
|
}
|
|
218
|
+
if (field.type === FIELD_TYPE.TEXT) {
|
|
219
|
+
return (
|
|
220
|
+
<Controller name="value">
|
|
221
|
+
<Textarea rows={3} label={t("label.value")} allowClear />
|
|
222
|
+
</Controller>
|
|
223
|
+
);
|
|
224
|
+
}
|
|
180
225
|
if (
|
|
181
226
|
field?.type === FIELD_TYPE.DECIMAL ||
|
|
182
227
|
field?.type === FIELD_TYPE.NUMBER
|
|
@@ -184,15 +229,17 @@ export const FilterForm = ({
|
|
|
184
229
|
const step = field.type === FIELD_TYPE.DECIMAL ? 0.1 : 1;
|
|
185
230
|
if (values?.operator === OPERATOR.BETWEEN) {
|
|
186
231
|
return (
|
|
187
|
-
<
|
|
188
|
-
<
|
|
189
|
-
<
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
<
|
|
194
|
-
|
|
195
|
-
|
|
232
|
+
<Controller name="value">
|
|
233
|
+
<Field label={t("label.value")}>
|
|
234
|
+
<Controller name="value[0]">
|
|
235
|
+
<Number step={step} allowClear />
|
|
236
|
+
</Controller>
|
|
237
|
+
<span className="p-2 text-muted">{`≷`}</span>
|
|
238
|
+
<Controller name="value[1]">
|
|
239
|
+
<Number step={step} allowClear />
|
|
240
|
+
</Controller>
|
|
241
|
+
</Field>
|
|
242
|
+
</Controller>
|
|
196
243
|
);
|
|
197
244
|
} else {
|
|
198
245
|
return (
|
|
@@ -202,6 +249,33 @@ export const FilterForm = ({
|
|
|
202
249
|
);
|
|
203
250
|
}
|
|
204
251
|
}
|
|
252
|
+
if (
|
|
253
|
+
field?.type === FIELD_TYPE.DATE ||
|
|
254
|
+
field?.type === FIELD_TYPE.DATETIME
|
|
255
|
+
) {
|
|
256
|
+
const type = field.type === FIELD_TYPE.DATETIME ? "datetime" : "date";
|
|
257
|
+
if (values?.operator === OPERATOR.BETWEEN) {
|
|
258
|
+
return (
|
|
259
|
+
<Controller name="value">
|
|
260
|
+
<Field label={t("label.value")}>
|
|
261
|
+
<Controller name="value[0]">
|
|
262
|
+
<DateInput type={type} allowClear />
|
|
263
|
+
</Controller>
|
|
264
|
+
<span className="p-2 text-muted">{`≷`}</span>
|
|
265
|
+
<Controller name="value[1]">
|
|
266
|
+
<DateInput type={type} allowClear />
|
|
267
|
+
</Controller>
|
|
268
|
+
</Field>
|
|
269
|
+
</Controller>
|
|
270
|
+
);
|
|
271
|
+
} else {
|
|
272
|
+
return (
|
|
273
|
+
<Controller name="value">
|
|
274
|
+
<DateInput type={type} allowClear />
|
|
275
|
+
</Controller>
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
205
279
|
}, [field, values?.operator]);
|
|
206
280
|
|
|
207
281
|
const handleSubmit = useCallback(
|
|
@@ -213,11 +287,12 @@ export const FilterForm = ({
|
|
|
213
287
|
operator: model.operator,
|
|
214
288
|
value: model.value as AnyObject,
|
|
215
289
|
label: model.label,
|
|
290
|
+
type: field?.type,
|
|
216
291
|
};
|
|
217
292
|
onChange?.(filter);
|
|
218
293
|
tree?.events.emit("close");
|
|
219
294
|
},
|
|
220
|
-
[onChange],
|
|
295
|
+
[field, onChange],
|
|
221
296
|
);
|
|
222
297
|
|
|
223
298
|
return (
|
|
@@ -234,6 +309,7 @@ export const FilterForm = ({
|
|
|
234
309
|
<Controller name="field">
|
|
235
310
|
<Select<FilterField>
|
|
236
311
|
required
|
|
312
|
+
searchable
|
|
237
313
|
ref={inputRef}
|
|
238
314
|
label={t("label.field")}
|
|
239
315
|
options={fields}
|
|
@@ -273,7 +349,7 @@ export const FilterForm = ({
|
|
|
273
349
|
}
|
|
274
350
|
/>
|
|
275
351
|
</Controller>
|
|
276
|
-
<div className="flex
|
|
352
|
+
<div className="flex mt-4 justify-end gap-1 sticky bottom-1 bg-base">
|
|
277
353
|
{onRemove && (
|
|
278
354
|
<div className="flex-1">
|
|
279
355
|
<Button
|
|
@@ -31,10 +31,12 @@ import { FilterView } from "./FilterView";
|
|
|
31
31
|
export const FilterMenu = ({
|
|
32
32
|
filter,
|
|
33
33
|
fields,
|
|
34
|
+
editable,
|
|
34
35
|
onChange,
|
|
35
36
|
onRemove,
|
|
36
37
|
}: {
|
|
37
38
|
fields?: FilterField[];
|
|
39
|
+
editable?: boolean;
|
|
38
40
|
filter: FilterObject;
|
|
39
41
|
onRemove: () => void;
|
|
40
42
|
onChange: (filter: FilterObject) => void;
|
|
@@ -48,7 +50,7 @@ export const FilterMenu = ({
|
|
|
48
50
|
<FilterView filter={filter} onRemove={onRemove} />
|
|
49
51
|
) : (
|
|
50
52
|
<Menu className="text-sm">
|
|
51
|
-
{filter.canEdit !== false ? (
|
|
53
|
+
{editable && filter.canEdit !== false ? (
|
|
52
54
|
<MenuItem
|
|
53
55
|
icon={CoreIcons.edit}
|
|
54
56
|
label={t("label.edit")}
|
|
@@ -74,7 +76,7 @@ export const FilterMenu = ({
|
|
|
74
76
|
onClick={() => onChange({ ...filter, pinned: !filter.pinned })}
|
|
75
77
|
/>
|
|
76
78
|
)}
|
|
77
|
-
{filter.canInvert !== false && (
|
|
79
|
+
{filter.canInvert !== false && filter.field && (
|
|
78
80
|
<MenuItem
|
|
79
81
|
label={t(filter.negate ? "label.include" : "label.exclude")}
|
|
80
82
|
onClick={() => onChange({ ...filter, negate: !filter.negate })}
|
|
@@ -32,12 +32,14 @@ import { FilterMenu } from "./FilterMenu";
|
|
|
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
|
/>
|
|
@@ -60,7 +60,7 @@ export const QueryForm = ({
|
|
|
60
60
|
}) => {
|
|
61
61
|
const { t } = useTranslation("searchbar");
|
|
62
62
|
const tree = useFloatingTree();
|
|
63
|
-
const { defaultQuery = "", querySchema } = useFilterContext();
|
|
63
|
+
const { defaultQuery = "", querySchema, queryLanguage } = useFilterContext();
|
|
64
64
|
const inputRef = useRef<HTMLInputElement>(null);
|
|
65
65
|
|
|
66
66
|
const filterValue = useMemo(() => {
|
|
@@ -112,7 +112,7 @@ export const QueryForm = ({
|
|
|
112
112
|
/>
|
|
113
113
|
</Controller>
|
|
114
114
|
<Controller name="query">
|
|
115
|
-
{({ checked, error, invalid, ...field }) => (
|
|
115
|
+
{({ checked, error, invalid, ref, ...field }) => (
|
|
116
116
|
<div className="my-2">
|
|
117
117
|
<label
|
|
118
118
|
className={classNames("block px-2", invalid && "text-danger-600")}
|
|
@@ -125,12 +125,18 @@ export const QueryForm = ({
|
|
|
125
125
|
gridTemplate: '"content" 1fr/1fr',
|
|
126
126
|
}}
|
|
127
127
|
>
|
|
128
|
-
<CodeEditor
|
|
128
|
+
<CodeEditor
|
|
129
|
+
language={queryLanguage ?? "text"}
|
|
130
|
+
minimal
|
|
131
|
+
required
|
|
132
|
+
{...field}
|
|
133
|
+
schema={querySchema}
|
|
134
|
+
/>
|
|
129
135
|
</div>
|
|
130
136
|
</div>
|
|
131
137
|
)}
|
|
132
138
|
</Controller>
|
|
133
|
-
<div className="flex justify-end gap-1">
|
|
139
|
+
<div className="flex mt-4 justify-end gap-1 sticky bottom-1 bg-base">
|
|
134
140
|
{onRemove && (
|
|
135
141
|
<div className="flex-1">
|
|
136
142
|
<Button
|
package/src/i18n/en.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -25,4 +25,9 @@ import "./i18n";
|
|
|
25
25
|
|
|
26
26
|
export { FilterBar } from "./filterbar/FilterBar";
|
|
27
27
|
export { SearchBar } from "./searchbar/SearchBar";
|
|
28
|
-
export {
|
|
28
|
+
export {
|
|
29
|
+
FIELD_TYPE,
|
|
30
|
+
OPERATOR,
|
|
31
|
+
type FilterObject,
|
|
32
|
+
type SearchObject,
|
|
33
|
+
} from "./types";
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
import { Button, useDebounce, useLocalStorage } from "@react-fabric/core";
|
|
25
25
|
import { AutoComplete, Field } from "@react-fabric/form";
|
|
26
26
|
import { dedupe, EMPTY_ARRAY, isArray } from "@react-fabric/utilities";
|
|
27
|
-
import { useMemo, useReducer, useState } from "react";
|
|
27
|
+
import { useEffect, useMemo, useReducer, useState } from "react";
|
|
28
28
|
import { useTranslation } from "react-i18next";
|
|
29
29
|
import { FilterBar } from "../filterbar/FilterBar";
|
|
30
30
|
import {
|
|
@@ -40,6 +40,7 @@ interface SearchState {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
type SearchActions =
|
|
43
|
+
| { type: "reset"; query: string | string[]; filters: FilterObject[] }
|
|
43
44
|
| { type: "dirty"; dirty: boolean }
|
|
44
45
|
| { type: "query"; query: string | string[] }
|
|
45
46
|
| { type: "filter"; filters: FilterObject[] };
|
|
@@ -60,6 +61,7 @@ export const SearchBar = ({
|
|
|
60
61
|
onQuery,
|
|
61
62
|
onSearch,
|
|
62
63
|
query,
|
|
64
|
+
ref,
|
|
63
65
|
multiple,
|
|
64
66
|
filters = EMPTY_ARRAY,
|
|
65
67
|
...filterProps
|
|
@@ -75,6 +77,7 @@ export const SearchBar = ({
|
|
|
75
77
|
|
|
76
78
|
const fireSearch = useDebounce(
|
|
77
79
|
(query: AnyObject, filters: FilterObject[]) => {
|
|
80
|
+
dispatch({ type: "dirty", dirty: false });
|
|
78
81
|
onSearch?.({
|
|
79
82
|
query,
|
|
80
83
|
filters,
|
|
@@ -85,6 +88,14 @@ export const SearchBar = ({
|
|
|
85
88
|
|
|
86
89
|
const [state, dispatch] = useReducer(
|
|
87
90
|
(state: SearchState, action: SearchActions) => {
|
|
91
|
+
if (action.type === "reset") {
|
|
92
|
+
return {
|
|
93
|
+
...state,
|
|
94
|
+
dirty: false,
|
|
95
|
+
query: action.query,
|
|
96
|
+
filters: action.filters,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
88
99
|
if (action.type === "dirty") {
|
|
89
100
|
return { ...state, dirty: action.dirty };
|
|
90
101
|
}
|
|
@@ -105,6 +116,10 @@ export const SearchBar = ({
|
|
|
105
116
|
},
|
|
106
117
|
);
|
|
107
118
|
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
dispatch({ type: "reset", filters, query });
|
|
121
|
+
}, [filters, query]);
|
|
122
|
+
|
|
108
123
|
const updateHistory = (value: string | string[]) => {
|
|
109
124
|
const historyEntry = isArray(value) ? value : [value];
|
|
110
125
|
setHistory(dedupe([...historyEntry, ...history]).slice(0, historyCount));
|
|
@@ -132,6 +147,7 @@ export const SearchBar = ({
|
|
|
132
147
|
<AutoComplete
|
|
133
148
|
allowClear
|
|
134
149
|
expandOnEdit
|
|
150
|
+
ref={ref}
|
|
135
151
|
multiple={multiple}
|
|
136
152
|
history={history}
|
|
137
153
|
value={state.query}
|
|
@@ -139,7 +155,7 @@ export const SearchBar = ({
|
|
|
139
155
|
decorateStart={decorateStart}
|
|
140
156
|
onInput={() => dispatch({ type: "dirty", dirty: true })}
|
|
141
157
|
onSelect={updateHistory}
|
|
142
|
-
|
|
158
|
+
data-ref="searchbarInput"
|
|
143
159
|
onEnterPressed={() => fireSearch(state.query, state.filters)}
|
|
144
160
|
/>
|
|
145
161
|
{append}
|