@react-fabric/searchbar 1.0.0-beta.6 → 1.0.0-beta.61
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 +17 -13
- package/dist/cjs/filterbar/FilterForm.js +144 -38
- package/dist/cjs/filterbar/FilterMenu.js +19 -7
- package/dist/cjs/filterbar/FilterTag.js +18 -10
- package/dist/cjs/filterbar/FilterView.js +6 -2
- package/dist/cjs/filterbar/QueryForm.js +11 -8
- package/dist/cjs/i18n/ar.json.js +42 -39
- package/dist/cjs/i18n/en.json.js +43 -39
- package/dist/cjs/searchbar/SearchBar.js +60 -7
- package/dist/cjs/types/index.js +12 -4
- package/dist/esm/filterbar/FilterBar.js +18 -14
- package/dist/esm/filterbar/FilterForm.js +145 -39
- package/dist/esm/filterbar/FilterMenu.js +20 -8
- package/dist/esm/filterbar/FilterTag.js +19 -11
- package/dist/esm/filterbar/FilterView.js +6 -2
- package/dist/esm/filterbar/QueryForm.js +11 -8
- package/dist/esm/i18n/ar.json.js +42 -39
- package/dist/esm/i18n/en.json.js +43 -39
- package/dist/esm/searchbar/SearchBar.js +61 -8
- 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 +17 -14
- package/src/filterbar/Context.tsx +4 -1
- package/src/filterbar/FilterBar.tsx +56 -15
- package/src/filterbar/FilterForm.tsx +113 -27
- package/src/filterbar/FilterMenu.tsx +34 -7
- package/src/filterbar/FilterTag.tsx +29 -11
- package/src/filterbar/FilterView.tsx +5 -2
- package/src/filterbar/QueryForm.tsx +7 -6
- 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 +58 -5
- package/src/types/index.ts +57 -34
|
@@ -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);
|
|
@@ -23,7 +23,6 @@
|
|
|
23
23
|
|
|
24
24
|
import {
|
|
25
25
|
Chip,
|
|
26
|
-
CoreIcons,
|
|
27
26
|
Divider,
|
|
28
27
|
Dropdown,
|
|
29
28
|
Icon,
|
|
@@ -31,19 +30,47 @@ import {
|
|
|
31
30
|
MenuItem,
|
|
32
31
|
} from "@react-fabric/core";
|
|
33
32
|
import { isEmpty, isNil } from "@react-fabric/utilities";
|
|
33
|
+
import classNames from "classnames";
|
|
34
34
|
import { useCallback, useMemo } from "react";
|
|
35
35
|
import { useTranslation } from "react-i18next";
|
|
36
36
|
import { type FilterBarProps, type FilterObject } from "../types";
|
|
37
|
+
import { FilterContext } from "./Context";
|
|
37
38
|
import { FilterEdit } from "./FilterEdit";
|
|
38
39
|
import { FilterTag } from "./FilterTag";
|
|
39
|
-
import classNames from "classnames";
|
|
40
|
-
import { FilterContext } from "./Context";
|
|
41
40
|
|
|
41
|
+
/**
|
|
42
|
+
* FilterBar component allows users to manage a list of filters.
|
|
43
|
+
* It provides options to add, remove, and modify filters,
|
|
44
|
+
* as well as to enable or disable all filters at once.
|
|
45
|
+
* It also supports toggling between included and excluded filters.
|
|
46
|
+
*
|
|
47
|
+
* @param {FilterBarProps} props - The properties for the FilterBar component.
|
|
48
|
+
* @returns {JSX.Element} The rendered FilterBar component.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```jsx
|
|
52
|
+
* <FilterBar
|
|
53
|
+
* filters={filters}
|
|
54
|
+
* allowAdd={true}
|
|
55
|
+
* fields={fields}
|
|
56
|
+
* editable={true}
|
|
57
|
+
* querySchema={querySchema}
|
|
58
|
+
* queryLanguage="lucene"
|
|
59
|
+
* defaultQuery="*"
|
|
60
|
+
* includedColor="green"
|
|
61
|
+
* excludedColor="red"
|
|
62
|
+
* onFilterChanged={(newFilters) => console.log(newFilters)}
|
|
63
|
+
* />
|
|
64
|
+
* ```
|
|
65
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/story/searchbar-searchbar--search-bar} for more details on the properties.
|
|
66
|
+
*/
|
|
42
67
|
export const FilterBar = ({
|
|
43
68
|
filters = [],
|
|
44
69
|
allowAdd,
|
|
45
70
|
fields,
|
|
71
|
+
editable,
|
|
46
72
|
querySchema,
|
|
73
|
+
queryLanguage,
|
|
47
74
|
defaultQuery,
|
|
48
75
|
includedColor,
|
|
49
76
|
excludedColor,
|
|
@@ -88,9 +115,10 @@ export const FilterBar = ({
|
|
|
88
115
|
if (type === "disableAll") filter.disabled = true;
|
|
89
116
|
if (type === "enableAll") filter.disabled = false;
|
|
90
117
|
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"
|
|
118
|
+
if (type === "excludeAll" && filter.field) filter.negate = true;
|
|
119
|
+
if (type === "includeAll" && filter.field) filter.negate = false;
|
|
120
|
+
if (type === "invertAll" && filter.field)
|
|
121
|
+
filter.negate = !filter.negate;
|
|
94
122
|
return { ...filter };
|
|
95
123
|
}),
|
|
96
124
|
);
|
|
@@ -113,9 +141,19 @@ export const FilterBar = ({
|
|
|
113
141
|
key.someDisabled = true;
|
|
114
142
|
if (!filter.disabled && filter.canDisable !== false && !key.someEnabled)
|
|
115
143
|
key.someEnabled = true;
|
|
116
|
-
if (
|
|
144
|
+
if (
|
|
145
|
+
filter.field &&
|
|
146
|
+
filter.negate &&
|
|
147
|
+
filter.canInvert !== false &&
|
|
148
|
+
!key.someExcluded
|
|
149
|
+
)
|
|
117
150
|
key.someExcluded = true;
|
|
118
|
-
if (
|
|
151
|
+
if (
|
|
152
|
+
filter.field &&
|
|
153
|
+
!filter.negate &&
|
|
154
|
+
filter.canInvert !== false &&
|
|
155
|
+
!key.someIncluded
|
|
156
|
+
)
|
|
119
157
|
key.someIncluded = true;
|
|
120
158
|
if (!filter.required && !key.canRemoveAll) key.canRemoveAll = true;
|
|
121
159
|
});
|
|
@@ -123,11 +161,13 @@ export const FilterBar = ({
|
|
|
123
161
|
}, [filters]);
|
|
124
162
|
|
|
125
163
|
return (
|
|
126
|
-
<FilterContext.Provider
|
|
164
|
+
<FilterContext.Provider
|
|
165
|
+
value={{ defaultQuery, querySchema, queryLanguage, fields }}
|
|
166
|
+
>
|
|
127
167
|
<div className="flex flex-wrap gap-1 items-center">
|
|
128
168
|
<Dropdown showArrow disabled={isEmpty(filters)}>
|
|
129
169
|
<Icon
|
|
130
|
-
icon=
|
|
170
|
+
icon="icon-[mdi--cog-outline]"
|
|
131
171
|
className={classNames(
|
|
132
172
|
isEmpty(filters) && "pointer-events-none opacity-30",
|
|
133
173
|
)}
|
|
@@ -141,7 +181,7 @@ export const FilterBar = ({
|
|
|
141
181
|
<MenuItem id="disableAll" label={t("label.disableAll")} />
|
|
142
182
|
)}
|
|
143
183
|
<MenuItem
|
|
144
|
-
icon=
|
|
184
|
+
icon="icon-[mdi--checkbox-intermediate-variant]"
|
|
145
185
|
id="toggleDisable"
|
|
146
186
|
label={t("label.toggleDisable")}
|
|
147
187
|
/>
|
|
@@ -154,14 +194,14 @@ export const FilterBar = ({
|
|
|
154
194
|
)}
|
|
155
195
|
<MenuItem
|
|
156
196
|
id="invertAll"
|
|
157
|
-
icon=
|
|
197
|
+
icon="icon-[mdi--set-left]"
|
|
158
198
|
label={t("label.invertAll")}
|
|
159
199
|
/>
|
|
160
200
|
<Divider />
|
|
161
201
|
<MenuItem
|
|
162
202
|
id="removeAll"
|
|
163
203
|
color="danger"
|
|
164
|
-
icon=
|
|
204
|
+
icon="icon-[mdi--minus-circle-outline]"
|
|
165
205
|
label={t("label.removeAll")}
|
|
166
206
|
disabled={!menuItems.canRemoveAll}
|
|
167
207
|
/>
|
|
@@ -171,6 +211,7 @@ export const FilterBar = ({
|
|
|
171
211
|
<FilterTag
|
|
172
212
|
key={idx}
|
|
173
213
|
filter={filter}
|
|
214
|
+
editable={editable}
|
|
174
215
|
includedColor={includedColor}
|
|
175
216
|
excludedColor={excludedColor}
|
|
176
217
|
onRemove={() => handleRemove(idx)}
|
|
@@ -181,8 +222,8 @@ export const FilterBar = ({
|
|
|
181
222
|
<Dropdown showArrow>
|
|
182
223
|
<Chip
|
|
183
224
|
size="sm"
|
|
184
|
-
className="
|
|
185
|
-
icon=
|
|
225
|
+
className="outline-dashed! outline-tint-400!"
|
|
226
|
+
icon="icon-[mdi--plus-circle-outline]"
|
|
186
227
|
>
|
|
187
228
|
{t("label.add")}
|
|
188
229
|
</Chip>
|
|
@@ -22,15 +22,18 @@
|
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
24
|
import { useFloatingTree } from "@floating-ui/react";
|
|
25
|
+
import { yupResolver } from "@hookform/resolvers/yup";
|
|
25
26
|
import { Button, Col, Row } from "@react-fabric/core";
|
|
26
27
|
import {
|
|
27
28
|
Controller,
|
|
29
|
+
DateInput,
|
|
28
30
|
Field,
|
|
29
31
|
Form,
|
|
30
32
|
Input,
|
|
31
33
|
Number,
|
|
32
34
|
Select,
|
|
33
35
|
Switch,
|
|
36
|
+
Textarea,
|
|
34
37
|
type FormRef,
|
|
35
38
|
} from "@react-fabric/form";
|
|
36
39
|
import { isArray, shortHash, yup } from "@react-fabric/utilities";
|
|
@@ -48,8 +51,9 @@ import { useFilterContext } from "./Context";
|
|
|
48
51
|
const FilterSchema = new yup.ObjectSchema({
|
|
49
52
|
id: yup.string().required(),
|
|
50
53
|
field: yup.string().required(),
|
|
54
|
+
// type: yup.string().oneOf(Object.values(FIELD_TYPE)),
|
|
51
55
|
operator: yup.string().required().oneOf(Object.values(OPERATOR)),
|
|
52
|
-
negate: yup.boolean(),
|
|
56
|
+
negate: yup.boolean().optional(),
|
|
53
57
|
label: yup.string(),
|
|
54
58
|
value: yup
|
|
55
59
|
.mixed()
|
|
@@ -59,13 +63,40 @@ const FilterSchema = new yup.ObjectSchema({
|
|
|
59
63
|
otherwise: (schema) => schema.required(),
|
|
60
64
|
})
|
|
61
65
|
.when("operator", {
|
|
62
|
-
is: OPERATOR.
|
|
66
|
+
is: OPERATOR.ANY,
|
|
63
67
|
then: (schema) =>
|
|
64
68
|
schema.test({
|
|
65
69
|
name: "array-check",
|
|
66
70
|
message: `\${path} is a required field`,
|
|
67
71
|
test: (val: AnyObject = []) => val?.length > 0,
|
|
68
72
|
}),
|
|
73
|
+
})
|
|
74
|
+
.when("operator", {
|
|
75
|
+
is: OPERATOR.ALL,
|
|
76
|
+
then: (schema) =>
|
|
77
|
+
schema.test({
|
|
78
|
+
name: "array-check",
|
|
79
|
+
message: `\${path} is a required field`,
|
|
80
|
+
test: (val: AnyObject = []) => val?.length > 0,
|
|
81
|
+
}),
|
|
82
|
+
})
|
|
83
|
+
.when("operator", {
|
|
84
|
+
is: OPERATOR.BETWEEN,
|
|
85
|
+
then: (schema) =>
|
|
86
|
+
schema.test({
|
|
87
|
+
name: "array-check",
|
|
88
|
+
message: `\${path} is a required field`,
|
|
89
|
+
test: (val: AnyObject = []) => val?.length > 0 && val[0] && val[1],
|
|
90
|
+
}),
|
|
91
|
+
})
|
|
92
|
+
.when("operator", {
|
|
93
|
+
is: OPERATOR.BETWEEN,
|
|
94
|
+
then: (schema) =>
|
|
95
|
+
schema.test({
|
|
96
|
+
name: "array-check",
|
|
97
|
+
message: `\${path} min max`,
|
|
98
|
+
test: (val: AnyObject = []) => val?.length > 0 && val[0] < val[1],
|
|
99
|
+
}),
|
|
69
100
|
}),
|
|
70
101
|
});
|
|
71
102
|
|
|
@@ -88,13 +119,15 @@ export const FilterForm = ({
|
|
|
88
119
|
const [values, setValues] = useState<FilterSchemaType>(filter as AnyObject);
|
|
89
120
|
|
|
90
121
|
useEffect(() => {
|
|
91
|
-
if (filter && "field" in filter && filter.field)
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
122
|
+
if (filter && "field" in filter && filter.field) {
|
|
123
|
+
formRef.current?.setValues(filter);
|
|
124
|
+
} else {
|
|
125
|
+
formRef.current?.setValues({
|
|
126
|
+
id: shortHash(),
|
|
127
|
+
field: "",
|
|
128
|
+
operator: OPERATOR.EXISTS,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
98
131
|
}, [filter]);
|
|
99
132
|
|
|
100
133
|
useEffect(() => {
|
|
@@ -119,13 +152,15 @@ export const FilterForm = ({
|
|
|
119
152
|
formRef.current?.setValue("value", undefined);
|
|
120
153
|
}
|
|
121
154
|
if (field?.type === FIELD_TYPE.STRING) {
|
|
122
|
-
if (values?.operator
|
|
155
|
+
if ([OPERATOR.ALL, OPERATOR.ANY].includes(values?.operator)) {
|
|
123
156
|
!isArray(values.value) && formRef.current?.setValue("value", []);
|
|
124
157
|
} else {
|
|
125
158
|
isArray(values.value) && formRef.current?.setValue("value", undefined);
|
|
126
159
|
}
|
|
127
160
|
}
|
|
128
161
|
if (
|
|
162
|
+
field?.type === FIELD_TYPE.DATE ||
|
|
163
|
+
field?.type === FIELD_TYPE.DATETIME ||
|
|
129
164
|
field?.type === FIELD_TYPE.NUMBER ||
|
|
130
165
|
field?.type === FIELD_TYPE.DECIMAL
|
|
131
166
|
) {
|
|
@@ -137,7 +172,7 @@ export const FilterForm = ({
|
|
|
137
172
|
}
|
|
138
173
|
if (
|
|
139
174
|
field?.type === FIELD_TYPE.BOOLEAN &&
|
|
140
|
-
values?.operator
|
|
175
|
+
[OPERATOR.IS, OPERATOR.EQ].includes(values?.operator) &&
|
|
141
176
|
values?.value === undefined
|
|
142
177
|
) {
|
|
143
178
|
formRef.current?.setValue("value", false);
|
|
@@ -155,7 +190,7 @@ export const FilterForm = ({
|
|
|
155
190
|
);
|
|
156
191
|
}
|
|
157
192
|
if (field?.type === FIELD_TYPE.STRING || field?.type === FIELD_TYPE.ID) {
|
|
158
|
-
if (values?.operator
|
|
193
|
+
if ([OPERATOR.ALL, OPERATOR.ANY].includes(values?.operator)) {
|
|
159
194
|
return (
|
|
160
195
|
<Controller name="value">
|
|
161
196
|
<Select
|
|
@@ -169,6 +204,19 @@ export const FilterForm = ({
|
|
|
169
204
|
/>
|
|
170
205
|
</Controller>
|
|
171
206
|
);
|
|
207
|
+
} else if (!!field.onSearch || field.values?.length) {
|
|
208
|
+
return (
|
|
209
|
+
<Controller name="value">
|
|
210
|
+
<Select
|
|
211
|
+
searchable
|
|
212
|
+
allowCreate
|
|
213
|
+
allowClear
|
|
214
|
+
options={field.values ?? []}
|
|
215
|
+
label={t("label.value")}
|
|
216
|
+
onQuery={field.onSearch}
|
|
217
|
+
/>
|
|
218
|
+
</Controller>
|
|
219
|
+
);
|
|
172
220
|
} else {
|
|
173
221
|
return (
|
|
174
222
|
<Controller name="value">
|
|
@@ -177,6 +225,13 @@ export const FilterForm = ({
|
|
|
177
225
|
);
|
|
178
226
|
}
|
|
179
227
|
}
|
|
228
|
+
if (field.type === FIELD_TYPE.TEXT) {
|
|
229
|
+
return (
|
|
230
|
+
<Controller name="value">
|
|
231
|
+
<Textarea rows={3} label={t("label.value")} allowClear />
|
|
232
|
+
</Controller>
|
|
233
|
+
);
|
|
234
|
+
}
|
|
180
235
|
if (
|
|
181
236
|
field?.type === FIELD_TYPE.DECIMAL ||
|
|
182
237
|
field?.type === FIELD_TYPE.NUMBER
|
|
@@ -184,15 +239,17 @@ export const FilterForm = ({
|
|
|
184
239
|
const step = field.type === FIELD_TYPE.DECIMAL ? 0.1 : 1;
|
|
185
240
|
if (values?.operator === OPERATOR.BETWEEN) {
|
|
186
241
|
return (
|
|
187
|
-
<
|
|
188
|
-
<
|
|
189
|
-
<
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
<
|
|
194
|
-
|
|
195
|
-
|
|
242
|
+
<Controller name="value">
|
|
243
|
+
<Field label={t("label.value")}>
|
|
244
|
+
<Controller name="value[0]">
|
|
245
|
+
<Number step={step} allowClear />
|
|
246
|
+
</Controller>
|
|
247
|
+
<span className="p-2 text-muted">{`≷`}</span>
|
|
248
|
+
<Controller name="value[1]">
|
|
249
|
+
<Number step={step} allowClear />
|
|
250
|
+
</Controller>
|
|
251
|
+
</Field>
|
|
252
|
+
</Controller>
|
|
196
253
|
);
|
|
197
254
|
} else {
|
|
198
255
|
return (
|
|
@@ -202,6 +259,33 @@ export const FilterForm = ({
|
|
|
202
259
|
);
|
|
203
260
|
}
|
|
204
261
|
}
|
|
262
|
+
if (
|
|
263
|
+
field?.type === FIELD_TYPE.DATE ||
|
|
264
|
+
field?.type === FIELD_TYPE.DATETIME
|
|
265
|
+
) {
|
|
266
|
+
const type = field.type === FIELD_TYPE.DATETIME ? "datetime" : "date";
|
|
267
|
+
if (values?.operator === OPERATOR.BETWEEN) {
|
|
268
|
+
return (
|
|
269
|
+
<Controller name="value">
|
|
270
|
+
<Field label={t("label.value")}>
|
|
271
|
+
<Controller name="value[0]">
|
|
272
|
+
<DateInput type={type} allowClear />
|
|
273
|
+
</Controller>
|
|
274
|
+
<span className="p-2 text-muted">{`≷`}</span>
|
|
275
|
+
<Controller name="value[1]">
|
|
276
|
+
<DateInput type={type} allowClear />
|
|
277
|
+
</Controller>
|
|
278
|
+
</Field>
|
|
279
|
+
</Controller>
|
|
280
|
+
);
|
|
281
|
+
} else {
|
|
282
|
+
return (
|
|
283
|
+
<Controller name="value">
|
|
284
|
+
<DateInput type={type} allowClear />
|
|
285
|
+
</Controller>
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
205
289
|
}, [field, values?.operator]);
|
|
206
290
|
|
|
207
291
|
const handleSubmit = useCallback(
|
|
@@ -213,27 +297,29 @@ export const FilterForm = ({
|
|
|
213
297
|
operator: model.operator,
|
|
214
298
|
value: model.value as AnyObject,
|
|
215
299
|
label: model.label,
|
|
300
|
+
type: field?.type,
|
|
216
301
|
};
|
|
217
302
|
onChange?.(filter);
|
|
218
303
|
tree?.events.emit("close");
|
|
219
304
|
},
|
|
220
|
-
[onChange],
|
|
305
|
+
[field, onChange],
|
|
221
306
|
);
|
|
222
307
|
|
|
223
308
|
return (
|
|
224
309
|
<Form<FilterSchemaType>
|
|
225
310
|
formRef={formRef}
|
|
226
|
-
|
|
311
|
+
resolver={yupResolver(FilterSchema) as any}
|
|
227
312
|
defaultValues={values}
|
|
228
313
|
onChange={setValues}
|
|
229
314
|
onSubmit={handleSubmit}
|
|
230
315
|
>
|
|
231
|
-
<div className="w-
|
|
316
|
+
<div className="w-lg">
|
|
232
317
|
<Row>
|
|
233
318
|
<Col flex="fill">
|
|
234
319
|
<Controller name="field">
|
|
235
320
|
<Select<FilterField>
|
|
236
321
|
required
|
|
322
|
+
searchable
|
|
237
323
|
ref={inputRef}
|
|
238
324
|
label={t("label.field")}
|
|
239
325
|
options={fields}
|
|
@@ -243,13 +329,13 @@ export const FilterForm = ({
|
|
|
243
329
|
/>
|
|
244
330
|
</Controller>
|
|
245
331
|
</Col>
|
|
246
|
-
<Col flex="
|
|
332
|
+
<Col flex="content" className="text-center">
|
|
247
333
|
<label className="block py-0.5 text-sm">{t("label.exclude")}</label>
|
|
248
334
|
<Controller name="negate">
|
|
249
335
|
<Switch color="danger" />
|
|
250
336
|
</Controller>
|
|
251
337
|
</Col>
|
|
252
|
-
<Col flex="
|
|
338
|
+
<Col flex="content" className="basis-28">
|
|
253
339
|
<Controller name="operator">
|
|
254
340
|
<Select
|
|
255
341
|
label={t("label.operator")}
|
|
@@ -273,7 +359,7 @@ export const FilterForm = ({
|
|
|
273
359
|
}
|
|
274
360
|
/>
|
|
275
361
|
</Controller>
|
|
276
|
-
<div className="flex
|
|
362
|
+
<div className="flex mt-4 justify-end gap-1 sticky bottom-1 bg-base">
|
|
277
363
|
{onRemove && (
|
|
278
364
|
<div className="flex-1">
|
|
279
365
|
<Button
|
|
@@ -21,20 +21,27 @@
|
|
|
21
21
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
import {
|
|
24
|
+
import { 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,9 +55,9 @@ 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
|
-
icon=
|
|
60
|
+
icon="icon-[mdi--lead-pencil]"
|
|
54
61
|
label={t("label.edit")}
|
|
55
62
|
data-dropdown-dismiss="false"
|
|
56
63
|
onClick={() => {
|
|
@@ -59,7 +66,7 @@ export const FilterMenu = ({
|
|
|
59
66
|
/>
|
|
60
67
|
) : (
|
|
61
68
|
<MenuItem
|
|
62
|
-
icon=
|
|
69
|
+
icon="icon-[mdi--eye]"
|
|
63
70
|
label={t("label.view")}
|
|
64
71
|
data-dropdown-dismiss="false"
|
|
65
72
|
onClick={() => {
|
|
@@ -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 })}
|
|
@@ -90,7 +117,7 @@ export const FilterMenu = ({
|
|
|
90
117
|
{!filter.required && (
|
|
91
118
|
<MenuItem
|
|
92
119
|
color="danger"
|
|
93
|
-
icon=
|
|
120
|
+
icon="icon-[mdi--minus-circle-outline]"
|
|
94
121
|
label={t("label.remove")}
|
|
95
122
|
onClick={() => onRemove()}
|
|
96
123
|
/>
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
import { Chip,
|
|
24
|
+
import { Chip, Dropdown, Icon } from "@react-fabric/core";
|
|
25
25
|
import { isNil } from "@react-fabric/utilities";
|
|
26
26
|
import classNames from "classnames";
|
|
27
27
|
import { Fragment, useMemo } from "react";
|
|
@@ -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,13 +74,17 @@ 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
|
|
|
75
83
|
const icon = useMemo(() => {
|
|
76
84
|
if (filter.canDisable === false) return undefined;
|
|
77
|
-
return filter.disabled
|
|
85
|
+
return filter.disabled
|
|
86
|
+
? "icon-[mdi--checkbox-blank-outline]"
|
|
87
|
+
: "icon-[mdi--checkbox-marked]";
|
|
78
88
|
}, [filter]);
|
|
79
89
|
|
|
80
90
|
return (
|
|
@@ -82,15 +92,17 @@ export const FilterTag = ({
|
|
|
82
92
|
<Chip
|
|
83
93
|
size="sm"
|
|
84
94
|
color={color}
|
|
85
|
-
className=
|
|
95
|
+
className={classNames(
|
|
96
|
+
"outline max-w-60",
|
|
97
|
+
filter.disabled && "opacity-65",
|
|
98
|
+
)}
|
|
86
99
|
variant={filter.pinned ? "solid" : undefined}
|
|
87
|
-
icon={icon}
|
|
88
|
-
iconColor={color}
|
|
100
|
+
icon={icon && { icon, color }}
|
|
89
101
|
onIconClick={(e) => [
|
|
90
102
|
onChange({ ...filter, disabled: !filter.disabled }),
|
|
91
103
|
e.stopPropagation(),
|
|
92
104
|
]}
|
|
93
|
-
data-
|
|
105
|
+
data-ref="filterTag"
|
|
94
106
|
data-test-value={filter.id}
|
|
95
107
|
stopPropagation
|
|
96
108
|
onRemove={filter.required ? undefined : () => onRemove()}
|
|
@@ -101,13 +113,19 @@ export const FilterTag = ({
|
|
|
101
113
|
filter.disabled && "line-through opacity-65",
|
|
102
114
|
)}
|
|
103
115
|
>
|
|
104
|
-
{filter.pinned &&
|
|
105
|
-
|
|
116
|
+
{filter.pinned && (
|
|
117
|
+
<Icon
|
|
118
|
+
className="flex-content"
|
|
119
|
+
icon={filter.icon ?? "icon-[mdi--pin]"}
|
|
120
|
+
/>
|
|
121
|
+
)}
|
|
122
|
+
<div className="truncate flex gap-x-0.5 flex-nowrap">{label}</div>
|
|
106
123
|
</div>
|
|
107
124
|
</Chip>
|
|
108
125
|
<FilterMenu
|
|
109
126
|
filter={filter}
|
|
110
127
|
fields={fields}
|
|
128
|
+
editable={editable}
|
|
111
129
|
onChange={onChange}
|
|
112
130
|
onRemove={onRemove}
|
|
113
131
|
/>
|
|
@@ -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>
|
|
@@ -70,7 +73,7 @@ export const FilterView = ({
|
|
|
70
73
|
<Copy size="sm" text={view as AnyObject} />
|
|
71
74
|
</div>
|
|
72
75
|
)}
|
|
73
|
-
<pre className="overflow-auto bg-base outline text-sm p-2 max-h-
|
|
76
|
+
<pre className="overflow-auto bg-base outline text-sm p-2 max-h-96 max-w-3xl min-w-[24rem]">
|
|
74
77
|
{view}
|
|
75
78
|
</pre>
|
|
76
79
|
{!filter.required && (
|