@react-fabric/searchbar 1.0.0-beta.8 → 1.0.1
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/Context.js +1 -1
- package/dist/cjs/filterbar/FilterBar.js +28 -23
- package/dist/cjs/filterbar/FilterEdit.js +7 -4
- package/dist/cjs/filterbar/FilterForm.js +176 -56
- package/dist/cjs/filterbar/FilterMenu.js +23 -12
- package/dist/cjs/filterbar/FilterTag.js +30 -20
- package/dist/cjs/filterbar/FilterView.js +11 -6
- package/dist/cjs/filterbar/QueryForm.js +47 -24
- package/dist/cjs/i18n/{ar.json.js → ar/searchbar.json.js} +43 -39
- package/dist/cjs/i18n/{en.json.js → en/searchbar.json.js} +43 -39
- package/dist/cjs/i18n/index.js +4 -4
- package/dist/cjs/index.js +28 -0
- package/dist/cjs/searchbar/SearchBar.js +58 -16
- package/dist/cjs/types/index.js +13 -4
- package/dist/esm/filterbar/Context.js +2 -2
- package/dist/esm/filterbar/FilterBar.js +30 -25
- package/dist/esm/filterbar/FilterEdit.js +7 -4
- package/dist/esm/filterbar/FilterForm.js +179 -59
- package/dist/esm/filterbar/FilterMenu.js +24 -13
- package/dist/esm/filterbar/FilterTag.js +32 -22
- package/dist/esm/filterbar/FilterView.js +11 -6
- package/dist/esm/filterbar/QueryForm.js +48 -25
- package/dist/esm/i18n/{ar.json.js → ar/searchbar.json.js} +43 -39
- package/dist/esm/i18n/{en.json.js → en/searchbar.json.js} +43 -39
- package/dist/esm/i18n/index.js +2 -2
- package/dist/esm/index.js +30 -0
- package/dist/esm/searchbar/SearchBar.js +59 -17
- package/dist/esm/types/index.js +13 -4
- package/dist/types/filterbar/Context.d.ts +2 -3
- package/dist/types/filterbar/FilterBar.d.ts +23 -1
- package/dist/types/filterbar/FilterEdit.d.ts +2 -2
- package/dist/types/filterbar/FilterForm.d.ts +3 -3
- package/dist/types/filterbar/FilterMenu.d.ts +3 -2
- package/dist/types/filterbar/FilterTag.d.ts +3 -2
- package/dist/types/filterbar/FilterView.d.ts +2 -2
- package/dist/types/filterbar/QueryForm.d.ts +2 -2
- package/dist/types/index.d.ts +27 -1
- package/dist/types/searchbar/SearchBar.d.ts +30 -1
- package/dist/types/types/index.d.ts +23 -14
- package/package.json +16 -19
- package/src/filterbar/Context.tsx +5 -5
- package/src/filterbar/FilterBar.tsx +58 -75
- package/src/filterbar/FilterEdit.tsx +9 -16
- package/src/filterbar/FilterForm.tsx +149 -85
- package/src/filterbar/FilterMenu.tsx +29 -16
- package/src/filterbar/FilterTag.tsx +30 -43
- package/src/filterbar/FilterView.tsx +13 -24
- package/src/filterbar/QueryForm.tsx +26 -43
- package/src/i18n/{ar.json → ar/searchbar.json} +43 -39
- package/src/i18n/{en.json → en/searchbar.json} +43 -39
- package/src/i18n/index.ts +2 -2
- package/src/index.ts +23 -18
- package/src/searchbar/SearchBar.tsx +67 -40
- package/src/types/index.ts +38 -70
|
@@ -22,56 +22,71 @@
|
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
24
|
import { useFloatingTree } from "@floating-ui/react";
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
Form,
|
|
30
|
-
Input,
|
|
31
|
-
Number,
|
|
32
|
-
Select,
|
|
33
|
-
Switch,
|
|
34
|
-
type FormRef,
|
|
35
|
-
} from "@react-fabric/form";
|
|
36
|
-
import { isArray, shortHash, yup } from "@react-fabric/utilities";
|
|
25
|
+
import { yupResolver } from "@hookform/resolvers/yup";
|
|
26
|
+
import { Button, Col, DropdownDismiss, Row } from "@react-fabric/core";
|
|
27
|
+
import { Controller, DateInput, Field, Form, Input, Number, Select, Switch, Textarea, type FormRef } from "@react-fabric/form";
|
|
28
|
+
import { isArray, isDefined, shortHash, yup } from "@react-fabric/utilities";
|
|
37
29
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
38
30
|
import { useTranslation } from "react-i18next";
|
|
39
|
-
import {
|
|
40
|
-
|
|
41
|
-
OPERATOR,
|
|
42
|
-
TypeOperators,
|
|
43
|
-
type FilterField,
|
|
44
|
-
type FilterObject,
|
|
45
|
-
} from "../types";
|
|
31
|
+
import type { FilterField, FilterObject, FilterValue } from "../types";
|
|
32
|
+
import { FIELD_TYPE, OPERATOR, TypeOperators } from "../types";
|
|
46
33
|
import { useFilterContext } from "./Context";
|
|
47
34
|
|
|
48
35
|
const FilterSchema = new yup.ObjectSchema({
|
|
49
36
|
id: yup.string().required(),
|
|
50
37
|
field: yup.string().required(),
|
|
38
|
+
// type: yup.string().oneOf(Object.values(FIELD_TYPE)),
|
|
51
39
|
operator: yup.string().required().oneOf(Object.values(OPERATOR)),
|
|
52
|
-
negate: yup.boolean(),
|
|
40
|
+
negate: yup.boolean().optional(),
|
|
53
41
|
label: yup.string(),
|
|
54
42
|
value: yup
|
|
55
|
-
.mixed()
|
|
43
|
+
.mixed<AnyObject[]>()
|
|
56
44
|
.when("operator", {
|
|
57
45
|
is: OPERATOR.EXISTS,
|
|
58
46
|
then: (schema) => schema.optional(),
|
|
59
47
|
otherwise: (schema) => schema.required(),
|
|
60
48
|
})
|
|
61
49
|
.when("operator", {
|
|
62
|
-
is: OPERATOR.
|
|
50
|
+
is: OPERATOR.ANY,
|
|
63
51
|
then: (schema) =>
|
|
64
52
|
schema.test({
|
|
65
53
|
name: "array-check",
|
|
66
54
|
message: `\${path} is a required field`,
|
|
67
|
-
test: (val
|
|
55
|
+
test: (val = []) => val.length > 0,
|
|
56
|
+
}),
|
|
57
|
+
})
|
|
58
|
+
.when("operator", {
|
|
59
|
+
is: OPERATOR.ALL,
|
|
60
|
+
then: (schema) =>
|
|
61
|
+
schema.test({
|
|
62
|
+
name: "array-check",
|
|
63
|
+
message: `\${path} is a required field`,
|
|
64
|
+
test: (val = []) => val.length > 0,
|
|
65
|
+
}),
|
|
66
|
+
})
|
|
67
|
+
.when("operator", {
|
|
68
|
+
is: OPERATOR.BETWEEN,
|
|
69
|
+
then: (schema) =>
|
|
70
|
+
schema.test({
|
|
71
|
+
name: "array-check",
|
|
72
|
+
message: `\${path} is a required field`,
|
|
73
|
+
test: (val = []) => val.length > 0 && isDefined(val[0]) && isDefined(val[1]),
|
|
74
|
+
}),
|
|
75
|
+
})
|
|
76
|
+
.when("operator", {
|
|
77
|
+
is: OPERATOR.BETWEEN,
|
|
78
|
+
then: (schema) =>
|
|
79
|
+
schema.test({
|
|
80
|
+
name: "array-check",
|
|
81
|
+
message: `\${path} min max`,
|
|
82
|
+
test: (val = []) => val.length > 0 && val[0] < val[1],
|
|
68
83
|
}),
|
|
69
84
|
}),
|
|
70
85
|
});
|
|
71
86
|
|
|
72
87
|
type FilterSchemaType = yup.InferType<typeof FilterSchema>;
|
|
73
88
|
|
|
74
|
-
export
|
|
89
|
+
export function FilterForm({
|
|
75
90
|
filter,
|
|
76
91
|
onChange,
|
|
77
92
|
onRemove,
|
|
@@ -79,33 +94,42 @@ export const FilterForm = ({
|
|
|
79
94
|
filter?: FilterObject;
|
|
80
95
|
onRemove?: () => void;
|
|
81
96
|
onChange?: (filter: FilterObject) => void;
|
|
82
|
-
})
|
|
97
|
+
}) {
|
|
83
98
|
const { t } = useTranslation("searchbar");
|
|
84
99
|
const tree = useFloatingTree();
|
|
85
100
|
const { fields = [] } = useFilterContext();
|
|
86
101
|
const inputRef = useRef<HTMLInputElement>(null);
|
|
87
102
|
const formRef = useRef<FormRef<FilterSchemaType>>(null);
|
|
88
|
-
const [values, setValues] = useState<FilterSchemaType>(filter as
|
|
103
|
+
const [values, setValues] = useState<FilterSchemaType | undefined>(() => filter as never);
|
|
104
|
+
|
|
105
|
+
console.log(values);
|
|
89
106
|
|
|
90
107
|
useEffect(() => {
|
|
91
|
-
if (filter && "field" in filter && filter.field)
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
108
|
+
if (filter && "field" in filter && filter.field) {
|
|
109
|
+
formRef.current?.setValues(filter as never);
|
|
110
|
+
} else {
|
|
111
|
+
formRef.current?.setValues({
|
|
112
|
+
id: shortHash(),
|
|
113
|
+
field: "",
|
|
114
|
+
operator: OPERATOR.EXISTS,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
98
117
|
}, [filter]);
|
|
99
118
|
|
|
100
119
|
useEffect(() => {
|
|
101
|
-
setTimeout(() => {
|
|
120
|
+
const tmr = setTimeout(() => {
|
|
102
121
|
inputRef.current?.focus();
|
|
103
122
|
}, 100);
|
|
123
|
+
|
|
124
|
+
return () => {
|
|
125
|
+
clearTimeout(tmr);
|
|
126
|
+
};
|
|
104
127
|
}, []);
|
|
105
128
|
|
|
106
129
|
const field = useMemo<FilterField | undefined>(() => {
|
|
107
130
|
if (!values?.field) return undefined;
|
|
108
131
|
return fields.find((f) => f.field === values?.field);
|
|
132
|
+
// eslint-disable-next-line @eslint-react/exhaustive-deps
|
|
109
133
|
}, [values]);
|
|
110
134
|
|
|
111
135
|
const operators = useMemo(() => {
|
|
@@ -119,25 +143,28 @@ export const FilterForm = ({
|
|
|
119
143
|
formRef.current?.setValue("value", undefined);
|
|
120
144
|
}
|
|
121
145
|
if (field?.type === FIELD_TYPE.STRING) {
|
|
122
|
-
if (values?.operator
|
|
123
|
-
!isArray(values
|
|
146
|
+
if (values?.operator && [OPERATOR.ALL, OPERATOR.ANY].includes(values.operator)) {
|
|
147
|
+
if (!isArray(values?.value)) formRef.current?.setValue("value", []);
|
|
124
148
|
} else {
|
|
125
|
-
isArray(values
|
|
149
|
+
if (isArray(values?.value)) formRef.current?.setValue("value", undefined);
|
|
126
150
|
}
|
|
127
151
|
}
|
|
128
152
|
if (
|
|
153
|
+
field?.type === FIELD_TYPE.DATE ||
|
|
154
|
+
field?.type === FIELD_TYPE.DATETIME ||
|
|
129
155
|
field?.type === FIELD_TYPE.NUMBER ||
|
|
130
156
|
field?.type === FIELD_TYPE.DECIMAL
|
|
131
157
|
) {
|
|
132
158
|
if (values?.operator === OPERATOR.BETWEEN) {
|
|
133
|
-
!isArray(values.value)
|
|
159
|
+
if (!isArray(values.value)) formRef.current?.setValue("value", []);
|
|
134
160
|
} else {
|
|
135
|
-
isArray(values
|
|
161
|
+
if (isArray(values?.value)) formRef.current?.setValue("value", undefined);
|
|
136
162
|
}
|
|
137
163
|
}
|
|
138
164
|
if (
|
|
139
165
|
field?.type === FIELD_TYPE.BOOLEAN &&
|
|
140
|
-
values?.operator
|
|
166
|
+
values?.operator &&
|
|
167
|
+
[OPERATOR.IS, OPERATOR.EQ].includes(values.operator) &&
|
|
141
168
|
values?.value === undefined
|
|
142
169
|
) {
|
|
143
170
|
formRef.current?.setValue("value", false);
|
|
@@ -155,7 +182,7 @@ export const FilterForm = ({
|
|
|
155
182
|
);
|
|
156
183
|
}
|
|
157
184
|
if (field?.type === FIELD_TYPE.STRING || field?.type === FIELD_TYPE.ID) {
|
|
158
|
-
if (values?.operator
|
|
185
|
+
if ([OPERATOR.ALL, OPERATOR.ANY].includes(values?.operator)) {
|
|
159
186
|
return (
|
|
160
187
|
<Controller name="value">
|
|
161
188
|
<Select
|
|
@@ -169,6 +196,19 @@ export const FilterForm = ({
|
|
|
169
196
|
/>
|
|
170
197
|
</Controller>
|
|
171
198
|
);
|
|
199
|
+
} else if (!!field.onSearch || field.values?.length) {
|
|
200
|
+
return (
|
|
201
|
+
<Controller name="value">
|
|
202
|
+
<Select
|
|
203
|
+
searchable
|
|
204
|
+
allowCreate
|
|
205
|
+
allowClear
|
|
206
|
+
options={field.values ?? []}
|
|
207
|
+
label={t("label.value")}
|
|
208
|
+
onQuery={field.onSearch}
|
|
209
|
+
/>
|
|
210
|
+
</Controller>
|
|
211
|
+
);
|
|
172
212
|
} else {
|
|
173
213
|
return (
|
|
174
214
|
<Controller name="value">
|
|
@@ -177,22 +217,28 @@ export const FilterForm = ({
|
|
|
177
217
|
);
|
|
178
218
|
}
|
|
179
219
|
}
|
|
180
|
-
if (
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
220
|
+
if (field.type === FIELD_TYPE.TEXT) {
|
|
221
|
+
return (
|
|
222
|
+
<Controller name="value">
|
|
223
|
+
<Textarea rows={3} label={t("label.value")} allowClear />
|
|
224
|
+
</Controller>
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
if (field?.type === FIELD_TYPE.DECIMAL || field?.type === FIELD_TYPE.NUMBER) {
|
|
184
228
|
const step = field.type === FIELD_TYPE.DECIMAL ? 0.1 : 1;
|
|
185
229
|
if (values?.operator === OPERATOR.BETWEEN) {
|
|
186
230
|
return (
|
|
187
|
-
<
|
|
188
|
-
<
|
|
189
|
-
<
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
<
|
|
194
|
-
|
|
195
|
-
|
|
231
|
+
<Controller name="value">
|
|
232
|
+
<Field label={t("label.value")}>
|
|
233
|
+
<Controller name="value[0]">
|
|
234
|
+
<Number step={step} allowClear />
|
|
235
|
+
</Controller>
|
|
236
|
+
<span className="p-2 text-muted">{`≷`}</span>
|
|
237
|
+
<Controller name="value[1]">
|
|
238
|
+
<Number step={step} allowClear />
|
|
239
|
+
</Controller>
|
|
240
|
+
</Field>
|
|
241
|
+
</Controller>
|
|
196
242
|
);
|
|
197
243
|
} else {
|
|
198
244
|
return (
|
|
@@ -202,7 +248,32 @@ export const FilterForm = ({
|
|
|
202
248
|
);
|
|
203
249
|
}
|
|
204
250
|
}
|
|
205
|
-
|
|
251
|
+
if (field?.type === FIELD_TYPE.DATE || field?.type === FIELD_TYPE.DATETIME) {
|
|
252
|
+
const type = field.type === FIELD_TYPE.DATETIME ? "datetime" : "date";
|
|
253
|
+
if (values?.operator === OPERATOR.BETWEEN) {
|
|
254
|
+
return (
|
|
255
|
+
<Controller name="value">
|
|
256
|
+
<Field label={t("label.value")}>
|
|
257
|
+
<Controller name="value[0]">
|
|
258
|
+
<DateInput type={type} allowClear />
|
|
259
|
+
</Controller>
|
|
260
|
+
<span className="p-2 text-muted">{`≷`}</span>
|
|
261
|
+
<Controller name="value[1]">
|
|
262
|
+
<DateInput type={type} allowClear />
|
|
263
|
+
</Controller>
|
|
264
|
+
</Field>
|
|
265
|
+
</Controller>
|
|
266
|
+
);
|
|
267
|
+
} else {
|
|
268
|
+
return (
|
|
269
|
+
<Controller name="value">
|
|
270
|
+
<DateInput type={type} allowClear />
|
|
271
|
+
</Controller>
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
// eslint-disable-next-line @eslint-react/exhaustive-deps
|
|
276
|
+
}, [field, values]);
|
|
206
277
|
|
|
207
278
|
const handleSubmit = useCallback(
|
|
208
279
|
(model: FilterSchemaType) => {
|
|
@@ -211,29 +282,32 @@ export const FilterForm = ({
|
|
|
211
282
|
field: model.field,
|
|
212
283
|
negate: model.negate,
|
|
213
284
|
operator: model.operator,
|
|
214
|
-
value: model.value as
|
|
285
|
+
value: model.value as FilterValue,
|
|
215
286
|
label: model.label,
|
|
287
|
+
type: field?.type,
|
|
216
288
|
};
|
|
217
289
|
onChange?.(filter);
|
|
218
290
|
tree?.events.emit("close");
|
|
219
291
|
},
|
|
220
|
-
|
|
292
|
+
// eslint-disable-next-line @eslint-react/exhaustive-deps
|
|
293
|
+
[field, onChange],
|
|
221
294
|
);
|
|
222
295
|
|
|
223
296
|
return (
|
|
224
297
|
<Form<FilterSchemaType>
|
|
225
298
|
formRef={formRef}
|
|
226
|
-
|
|
299
|
+
resolver={yupResolver(FilterSchema)}
|
|
227
300
|
defaultValues={values}
|
|
228
301
|
onChange={setValues}
|
|
229
302
|
onSubmit={handleSubmit}
|
|
230
303
|
>
|
|
231
|
-
<div className="w-
|
|
304
|
+
<div className="w-lg">
|
|
232
305
|
<Row>
|
|
233
306
|
<Col flex="fill">
|
|
234
307
|
<Controller name="field">
|
|
235
308
|
<Select<FilterField>
|
|
236
309
|
required
|
|
310
|
+
searchable
|
|
237
311
|
ref={inputRef}
|
|
238
312
|
label={t("label.field")}
|
|
239
313
|
options={fields}
|
|
@@ -243,19 +317,15 @@ export const FilterForm = ({
|
|
|
243
317
|
/>
|
|
244
318
|
</Controller>
|
|
245
319
|
</Col>
|
|
246
|
-
<Col flex="
|
|
320
|
+
<Col flex="content" className="text-center">
|
|
247
321
|
<label className="block py-0.5 text-sm">{t("label.exclude")}</label>
|
|
248
322
|
<Controller name="negate">
|
|
249
323
|
<Switch color="danger" />
|
|
250
324
|
</Controller>
|
|
251
325
|
</Col>
|
|
252
|
-
<Col flex="
|
|
326
|
+
<Col flex="content" className="basis-28">
|
|
253
327
|
<Controller name="operator">
|
|
254
|
-
<Select
|
|
255
|
-
label={t("label.operator")}
|
|
256
|
-
options={operators}
|
|
257
|
-
renderer={(v) => t(`operator.${v}`)}
|
|
258
|
-
/>
|
|
328
|
+
<Select label={t("label.operator")} options={operators} renderer={(v) => t(`operator.${v}`)} />
|
|
259
329
|
</Controller>
|
|
260
330
|
</Col>
|
|
261
331
|
</Row>
|
|
@@ -266,30 +336,24 @@ export const FilterForm = ({
|
|
|
266
336
|
<Input
|
|
267
337
|
label={t("label.label")}
|
|
268
338
|
placeholder={t("label.label")}
|
|
269
|
-
decorateEnd={
|
|
270
|
-
!filter?.label && (
|
|
271
|
-
<span className="text-sm opacity-65 pe-4">Optional</span>
|
|
272
|
-
)
|
|
273
|
-
}
|
|
339
|
+
decorateEnd={!filter?.label && <span className="text-sm opacity-65 pe-4">Optional</span>}
|
|
274
340
|
/>
|
|
275
341
|
</Controller>
|
|
276
|
-
<div className="flex
|
|
342
|
+
<div className="flex mt-4 justify-end gap-1 sticky bottom-1 bg-default">
|
|
277
343
|
{onRemove && (
|
|
278
344
|
<div className="flex-1">
|
|
279
|
-
<
|
|
280
|
-
data-dropdown-dismiss="true"
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
onClick={onRemove}
|
|
285
|
-
>
|
|
286
|
-
{t("label.remove")}
|
|
287
|
-
</Button>
|
|
345
|
+
<DropdownDismiss>
|
|
346
|
+
<Button data-dropdown-dismiss="true" variant="link" size="sm" color="danger" onClick={onRemove}>
|
|
347
|
+
{t("label.remove")}
|
|
348
|
+
</Button>
|
|
349
|
+
</DropdownDismiss>
|
|
288
350
|
</div>
|
|
289
351
|
)}
|
|
290
|
-
<
|
|
291
|
-
|
|
292
|
-
|
|
352
|
+
<DropdownDismiss>
|
|
353
|
+
<Button data-dropdown-dismiss="true" variant="link" size="sm">
|
|
354
|
+
{t("label.cancel")}
|
|
355
|
+
</Button>
|
|
356
|
+
</DropdownDismiss>
|
|
293
357
|
<Button type="submit" variant="solid" size="sm">
|
|
294
358
|
{t("label.apply")}
|
|
295
359
|
</Button>
|
|
@@ -297,4 +361,4 @@ export const FilterForm = ({
|
|
|
297
361
|
</div>
|
|
298
362
|
</Form>
|
|
299
363
|
);
|
|
300
|
-
}
|
|
364
|
+
}
|
|
@@ -21,24 +21,30 @@
|
|
|
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
|
-
|
|
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
|
+
|
|
36
|
+
export function FilterMenu({
|
|
32
37
|
filter,
|
|
33
|
-
|
|
38
|
+
editable,
|
|
34
39
|
onChange,
|
|
35
40
|
onRemove,
|
|
36
41
|
}: {
|
|
37
42
|
fields?: FilterField[];
|
|
43
|
+
editable?: boolean;
|
|
38
44
|
filter: FilterObject;
|
|
39
45
|
onRemove: () => void;
|
|
40
46
|
onChange: (filter: FilterObject) => void;
|
|
41
|
-
})
|
|
47
|
+
}) {
|
|
42
48
|
const { t } = useTranslation("searchbar");
|
|
43
49
|
const [view, setView] = useState<"view" | "edit">();
|
|
44
50
|
|
|
@@ -48,9 +54,9 @@ export const FilterMenu = ({
|
|
|
48
54
|
<FilterView filter={filter} onRemove={onRemove} />
|
|
49
55
|
) : (
|
|
50
56
|
<Menu className="text-sm">
|
|
51
|
-
{filter.canEdit !== false ? (
|
|
57
|
+
{editable && filter.canEdit !== false ? (
|
|
52
58
|
<MenuItem
|
|
53
|
-
icon=
|
|
59
|
+
icon="icon-[mdi--lead-pencil]"
|
|
54
60
|
label={t("label.edit")}
|
|
55
61
|
data-dropdown-dismiss="false"
|
|
56
62
|
onClick={() => {
|
|
@@ -59,7 +65,7 @@ export const FilterMenu = ({
|
|
|
59
65
|
/>
|
|
60
66
|
) : (
|
|
61
67
|
<MenuItem
|
|
62
|
-
icon=
|
|
68
|
+
icon="icon-[mdi--eye]"
|
|
63
69
|
label={t("label.view")}
|
|
64
70
|
data-dropdown-dismiss="false"
|
|
65
71
|
onClick={() => {
|
|
@@ -68,13 +74,25 @@ export const FilterMenu = ({
|
|
|
68
74
|
/>
|
|
69
75
|
)}
|
|
70
76
|
<Divider />
|
|
77
|
+
{filter.operator && [OPERATOR.ALL, OPERATOR.ANY].includes(filter.operator) && (
|
|
78
|
+
<MenuItem
|
|
79
|
+
label={t(filter.operator === OPERATOR.ALL ? "label.matchAny" : "label.matchAll")}
|
|
80
|
+
icon={t(filter.operator === OPERATOR.ALL ? MATCH_ANY : MATCH_ALL)}
|
|
81
|
+
onClick={() =>
|
|
82
|
+
onChange({
|
|
83
|
+
...filter,
|
|
84
|
+
operator: filter.operator === OPERATOR.ALL ? OPERATOR.ANY : OPERATOR.ALL,
|
|
85
|
+
})
|
|
86
|
+
}
|
|
87
|
+
/>
|
|
88
|
+
)}
|
|
71
89
|
{filter.canPin !== false && (
|
|
72
90
|
<MenuItem
|
|
73
91
|
label={t(filter.pinned ? "label.unpin" : "label.pin")}
|
|
74
92
|
onClick={() => onChange({ ...filter, pinned: !filter.pinned })}
|
|
75
93
|
/>
|
|
76
94
|
)}
|
|
77
|
-
{filter.canInvert !== false && (
|
|
95
|
+
{filter.canInvert !== false && filter.field && (
|
|
78
96
|
<MenuItem
|
|
79
97
|
label={t(filter.negate ? "label.include" : "label.exclude")}
|
|
80
98
|
onClick={() => onChange({ ...filter, negate: !filter.negate })}
|
|
@@ -88,13 +106,8 @@ export const FilterMenu = ({
|
|
|
88
106
|
)}
|
|
89
107
|
{!filter.required && <Divider />}
|
|
90
108
|
{!filter.required && (
|
|
91
|
-
<MenuItem
|
|
92
|
-
color="danger"
|
|
93
|
-
icon={CoreIcons.remove}
|
|
94
|
-
label={t("label.remove")}
|
|
95
|
-
onClick={() => onRemove()}
|
|
96
|
-
/>
|
|
109
|
+
<MenuItem color="danger" icon="icon-[mdi--minus-circle-outline]" label={t("label.remove")} onClick={() => onRemove()} />
|
|
97
110
|
)}
|
|
98
111
|
</Menu>
|
|
99
112
|
);
|
|
100
|
-
}
|
|
113
|
+
}
|
|
@@ -21,60 +21,58 @@
|
|
|
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,
|
|
25
|
-
import { isNil } from "@react-fabric/utilities";
|
|
26
|
-
import classNames from "classnames";
|
|
24
|
+
import { Chip, Dropdown, Icon } from "@react-fabric/core";
|
|
25
|
+
import { cn, isNil } from "@react-fabric/utilities";
|
|
27
26
|
import { Fragment, useMemo } from "react";
|
|
28
27
|
import { useTranslation } from "react-i18next";
|
|
29
28
|
import { type FilterBarProps, type FilterObject } from "../types";
|
|
30
29
|
import { FilterMenu } from "./FilterMenu";
|
|
31
30
|
|
|
32
|
-
export
|
|
31
|
+
export function FilterTag({
|
|
33
32
|
filter,
|
|
34
33
|
fields,
|
|
34
|
+
editable,
|
|
35
35
|
includedColor = "primary-500",
|
|
36
36
|
excludedColor = "danger-500",
|
|
37
37
|
onChange,
|
|
38
38
|
onRemove,
|
|
39
39
|
}: {
|
|
40
40
|
filter: FilterObject;
|
|
41
|
+
editable?: boolean;
|
|
41
42
|
onRemove: () => void;
|
|
42
43
|
onChange: (filter: FilterObject) => void;
|
|
43
|
-
} & Pick<FilterBarProps, "fields" | "includedColor" | "excludedColor">)
|
|
44
|
+
} & Pick<FilterBarProps, "fields" | "includedColor" | "excludedColor">) {
|
|
44
45
|
const { t } = useTranslation("searchbar");
|
|
45
46
|
const label = useMemo(() => {
|
|
46
47
|
if (filter.label)
|
|
47
48
|
return (
|
|
48
49
|
<Fragment>
|
|
49
|
-
{filter.negate && <span className="font-semibold">NOT</span>}
|
|
50
|
+
{filter.field && filter.negate && <span className="font-semibold">NOT</span>}
|
|
50
51
|
<span>{filter.label}</span>
|
|
51
52
|
</Fragment>
|
|
52
53
|
);
|
|
53
54
|
|
|
54
55
|
return (
|
|
55
56
|
<Fragment>
|
|
56
|
-
{filter.negate && <span className="font-semibold">NOT</span>}
|
|
57
|
+
{filter.field && filter.negate && <span className="font-semibold">NOT</span>}
|
|
57
58
|
<span>{filter.field}</span>
|
|
58
|
-
<span className="font-semibold">
|
|
59
|
-
{t(`operator.${filter.operator}`, { defaultValue: filter.operator })}
|
|
60
|
-
</span>
|
|
59
|
+
<span className="font-semibold">{t(`operator.${filter.operator}`, { defaultValue: filter.operator })}</span>
|
|
61
60
|
{"value" in filter && !isNil(filter.value) && (
|
|
62
|
-
<span className="truncate block">
|
|
63
|
-
{filter.value?.toString().substring(0, 24)}
|
|
64
|
-
</span>
|
|
61
|
+
<span className="truncate block">{filter.value?.toString().substring(0, 24)}</span>
|
|
65
62
|
)}
|
|
66
63
|
</Fragment>
|
|
67
64
|
);
|
|
65
|
+
// eslint-disable-next-line @eslint-react/exhaustive-deps
|
|
68
66
|
}, [filter]);
|
|
69
67
|
|
|
70
68
|
const color = useMemo(
|
|
71
|
-
() => filter.color ?? (filter.negate ? excludedColor : includedColor),
|
|
69
|
+
() => filter.color ?? (filter.field && filter.negate ? excludedColor : includedColor),
|
|
72
70
|
[filter, includedColor, excludedColor],
|
|
73
71
|
);
|
|
74
72
|
|
|
75
73
|
const icon = useMemo(() => {
|
|
76
74
|
if (filter.canDisable === false) return undefined;
|
|
77
|
-
return filter.disabled ?
|
|
75
|
+
return filter.disabled ? "icon-[mdi--checkbox-blank-outline]" : "icon-[mdi--checkbox-marked]";
|
|
78
76
|
}, [filter]);
|
|
79
77
|
|
|
80
78
|
return (
|
|
@@ -82,40 +80,29 @@ export const FilterTag = ({
|
|
|
82
80
|
<Chip
|
|
83
81
|
size="sm"
|
|
84
82
|
color={color}
|
|
85
|
-
className="outline
|
|
83
|
+
className={cn("outline max-w-60", filter.disabled && "opacity-65")}
|
|
86
84
|
variant={filter.pinned ? "solid" : undefined}
|
|
87
|
-
icon={
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
85
|
+
icon={
|
|
86
|
+
icon && (
|
|
87
|
+
<button
|
|
88
|
+
className="size-fit cursor-pointer"
|
|
89
|
+
onClick={(e) => [onChange({ ...filter, disabled: !filter.disabled }), e.stopPropagation()]}
|
|
90
|
+
>
|
|
91
|
+
<Icon icon={icon} color={color} />
|
|
92
|
+
</button>
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
data-ref="filterTag"
|
|
94
96
|
data-test-value={filter.id}
|
|
95
97
|
stopPropagation
|
|
96
98
|
onRemove={filter.required ? undefined : () => onRemove()}
|
|
97
99
|
>
|
|
98
|
-
<div
|
|
99
|
-
className={
|
|
100
|
-
|
|
101
|
-
filter.disabled && "line-through opacity-65",
|
|
102
|
-
)}
|
|
103
|
-
>
|
|
104
|
-
{filter.pinned && (
|
|
105
|
-
<Icon
|
|
106
|
-
className="flex-content"
|
|
107
|
-
icon={filter.icon ?? CoreIcons.pin}
|
|
108
|
-
/>
|
|
109
|
-
)}
|
|
110
|
-
{label}
|
|
100
|
+
<div className={cn("flex gap-1 items-center", filter.disabled && "line-through opacity-65")}>
|
|
101
|
+
{filter.pinned && <Icon className="flex-content" icon={filter.icon ?? "icon-[mdi--pin]"} />}
|
|
102
|
+
<div className="truncate flex gap-x-0.5 flex-nowrap">{label}</div>
|
|
111
103
|
</div>
|
|
112
104
|
</Chip>
|
|
113
|
-
<FilterMenu
|
|
114
|
-
filter={filter}
|
|
115
|
-
fields={fields}
|
|
116
|
-
onChange={onChange}
|
|
117
|
-
onRemove={onRemove}
|
|
118
|
-
/>
|
|
105
|
+
<FilterMenu filter={filter} fields={fields} editable={editable} onChange={onChange} onRemove={onRemove} />
|
|
119
106
|
</Dropdown>
|
|
120
107
|
);
|
|
121
|
-
}
|
|
108
|
+
}
|