@react-fabric/searchbar 1.0.0-beta.9 → 1.0.2
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 +177 -64
- 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 +181 -68
- 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 -91
- 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
|
@@ -29,7 +29,7 @@ import { useFilterContext } from "./Context";
|
|
|
29
29
|
import { FilterForm } from "./FilterForm";
|
|
30
30
|
import { QueryForm } from "./QueryForm";
|
|
31
31
|
|
|
32
|
-
export
|
|
32
|
+
export function FilterEdit({
|
|
33
33
|
filter,
|
|
34
34
|
onRemove,
|
|
35
35
|
onChange,
|
|
@@ -37,34 +37,27 @@ export const FilterEdit = ({
|
|
|
37
37
|
filter?: FilterObject;
|
|
38
38
|
onRemove?: () => void;
|
|
39
39
|
onChange: (filter: FilterObject) => void;
|
|
40
|
-
})
|
|
40
|
+
}) {
|
|
41
41
|
const { t } = useTranslation("searchbar");
|
|
42
42
|
const { fields } = useFilterContext();
|
|
43
|
-
const [queryEdit, setQueryEdit] = useState(isEmpty(fields));
|
|
43
|
+
const [queryEdit, setQueryEdit] = useState(() => isEmpty(fields));
|
|
44
44
|
|
|
45
45
|
useEffect(() => {
|
|
46
|
+
// eslint-disable-next-line @eslint-react/set-state-in-effect
|
|
46
47
|
setQueryEdit(!!filter && "query" in filter);
|
|
47
48
|
}, [filter]);
|
|
48
49
|
|
|
49
50
|
return (
|
|
50
|
-
<div className="px-2 py-1 bg-
|
|
51
|
+
<div className="px-2 py-1 bg-default outline min-w-108 rounded-capped">
|
|
51
52
|
{!isEmpty(fields) && (
|
|
52
53
|
<div className="pb-4 flex justify-end">
|
|
53
|
-
<span
|
|
54
|
-
role="none"
|
|
55
|
-
className="text-sm link"
|
|
56
|
-
onClick={() => setQueryEdit(!queryEdit)}
|
|
57
|
-
>
|
|
54
|
+
<span role="none" className="text-sm link" onClick={() => setQueryEdit(!queryEdit)}>
|
|
58
55
|
{t(queryEdit ? "label.basicFilter" : "label.customQuery")}
|
|
59
56
|
</span>
|
|
60
57
|
</div>
|
|
61
58
|
)}
|
|
62
|
-
{!queryEdit &&
|
|
63
|
-
|
|
64
|
-
)}
|
|
65
|
-
{queryEdit && (
|
|
66
|
-
<QueryForm filter={filter} onRemove={onRemove} onChange={onChange} />
|
|
67
|
-
)}
|
|
59
|
+
{!queryEdit && <FilterForm filter={filter} onRemove={onRemove} onChange={onChange} />}
|
|
60
|
+
{queryEdit && <QueryForm filter={filter} onRemove={onRemove} onChange={onChange} />}
|
|
68
61
|
</div>
|
|
69
62
|
);
|
|
70
|
-
}
|
|
63
|
+
}
|
|
@@ -22,57 +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(),
|
|
51
|
-
type: yup.string().
|
|
38
|
+
// type: yup.string().oneOf(Object.values(FIELD_TYPE)),
|
|
52
39
|
operator: yup.string().required().oneOf(Object.values(OPERATOR)),
|
|
53
|
-
negate: yup.boolean(),
|
|
40
|
+
negate: yup.boolean().optional(),
|
|
54
41
|
label: yup.string(),
|
|
55
42
|
value: yup
|
|
56
|
-
.mixed()
|
|
43
|
+
.mixed<AnyObject[]>()
|
|
57
44
|
.when("operator", {
|
|
58
45
|
is: OPERATOR.EXISTS,
|
|
59
46
|
then: (schema) => schema.optional(),
|
|
60
47
|
otherwise: (schema) => schema.required(),
|
|
61
48
|
})
|
|
62
49
|
.when("operator", {
|
|
63
|
-
is: OPERATOR.
|
|
50
|
+
is: OPERATOR.ANY,
|
|
64
51
|
then: (schema) =>
|
|
65
52
|
schema.test({
|
|
66
53
|
name: "array-check",
|
|
67
54
|
message: `\${path} is a required field`,
|
|
68
|
-
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],
|
|
69
83
|
}),
|
|
70
84
|
}),
|
|
71
85
|
});
|
|
72
86
|
|
|
73
87
|
type FilterSchemaType = yup.InferType<typeof FilterSchema>;
|
|
74
88
|
|
|
75
|
-
export
|
|
89
|
+
export function FilterForm({
|
|
76
90
|
filter,
|
|
77
91
|
onChange,
|
|
78
92
|
onRemove,
|
|
@@ -80,34 +94,42 @@ export const FilterForm = ({
|
|
|
80
94
|
filter?: FilterObject;
|
|
81
95
|
onRemove?: () => void;
|
|
82
96
|
onChange?: (filter: FilterObject) => void;
|
|
83
|
-
})
|
|
97
|
+
}) {
|
|
84
98
|
const { t } = useTranslation("searchbar");
|
|
85
99
|
const tree = useFloatingTree();
|
|
86
100
|
const { fields = [] } = useFilterContext();
|
|
87
101
|
const inputRef = useRef<HTMLInputElement>(null);
|
|
88
102
|
const formRef = useRef<FormRef<FilterSchemaType>>(null);
|
|
89
|
-
const [values, setValues] = useState<FilterSchemaType>(filter as
|
|
103
|
+
const [values, setValues] = useState<FilterSchemaType | undefined>(() => filter as never);
|
|
104
|
+
|
|
105
|
+
console.log(values);
|
|
90
106
|
|
|
91
107
|
useEffect(() => {
|
|
92
|
-
if (filter && "field" in filter && filter.field)
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
+
}
|
|
100
117
|
}, [filter]);
|
|
101
118
|
|
|
102
119
|
useEffect(() => {
|
|
103
|
-
setTimeout(() => {
|
|
120
|
+
const tmr = setTimeout(() => {
|
|
104
121
|
inputRef.current?.focus();
|
|
105
122
|
}, 100);
|
|
123
|
+
|
|
124
|
+
return () => {
|
|
125
|
+
clearTimeout(tmr);
|
|
126
|
+
};
|
|
106
127
|
}, []);
|
|
107
128
|
|
|
108
129
|
const field = useMemo<FilterField | undefined>(() => {
|
|
109
130
|
if (!values?.field) return undefined;
|
|
110
131
|
return fields.find((f) => f.field === values?.field);
|
|
132
|
+
// eslint-disable-next-line @eslint-react/exhaustive-deps
|
|
111
133
|
}, [values]);
|
|
112
134
|
|
|
113
135
|
const operators = useMemo(() => {
|
|
@@ -121,25 +143,28 @@ export const FilterForm = ({
|
|
|
121
143
|
formRef.current?.setValue("value", undefined);
|
|
122
144
|
}
|
|
123
145
|
if (field?.type === FIELD_TYPE.STRING) {
|
|
124
|
-
if (values?.operator
|
|
125
|
-
!isArray(values
|
|
146
|
+
if (values?.operator && [OPERATOR.ALL, OPERATOR.ANY].includes(values.operator)) {
|
|
147
|
+
if (!isArray(values?.value)) formRef.current?.setValue("value", []);
|
|
126
148
|
} else {
|
|
127
|
-
isArray(values
|
|
149
|
+
if (isArray(values?.value)) formRef.current?.setValue("value", undefined);
|
|
128
150
|
}
|
|
129
151
|
}
|
|
130
152
|
if (
|
|
153
|
+
field?.type === FIELD_TYPE.DATE ||
|
|
154
|
+
field?.type === FIELD_TYPE.DATETIME ||
|
|
131
155
|
field?.type === FIELD_TYPE.NUMBER ||
|
|
132
156
|
field?.type === FIELD_TYPE.DECIMAL
|
|
133
157
|
) {
|
|
134
158
|
if (values?.operator === OPERATOR.BETWEEN) {
|
|
135
|
-
!isArray(values.value)
|
|
159
|
+
if (!isArray(values.value)) formRef.current?.setValue("value", []);
|
|
136
160
|
} else {
|
|
137
|
-
isArray(values
|
|
161
|
+
if (isArray(values?.value)) formRef.current?.setValue("value", undefined);
|
|
138
162
|
}
|
|
139
163
|
}
|
|
140
164
|
if (
|
|
141
165
|
field?.type === FIELD_TYPE.BOOLEAN &&
|
|
142
|
-
values?.operator
|
|
166
|
+
values?.operator &&
|
|
167
|
+
[OPERATOR.IS, OPERATOR.EQ].includes(values.operator) &&
|
|
143
168
|
values?.value === undefined
|
|
144
169
|
) {
|
|
145
170
|
formRef.current?.setValue("value", false);
|
|
@@ -157,7 +182,7 @@ export const FilterForm = ({
|
|
|
157
182
|
);
|
|
158
183
|
}
|
|
159
184
|
if (field?.type === FIELD_TYPE.STRING || field?.type === FIELD_TYPE.ID) {
|
|
160
|
-
if (values?.operator
|
|
185
|
+
if ([OPERATOR.ALL, OPERATOR.ANY].includes(values?.operator)) {
|
|
161
186
|
return (
|
|
162
187
|
<Controller name="value">
|
|
163
188
|
<Select
|
|
@@ -171,6 +196,19 @@ export const FilterForm = ({
|
|
|
171
196
|
/>
|
|
172
197
|
</Controller>
|
|
173
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
|
+
);
|
|
174
212
|
} else {
|
|
175
213
|
return (
|
|
176
214
|
<Controller name="value">
|
|
@@ -179,22 +217,28 @@ export const FilterForm = ({
|
|
|
179
217
|
);
|
|
180
218
|
}
|
|
181
219
|
}
|
|
182
|
-
if (
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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) {
|
|
186
228
|
const step = field.type === FIELD_TYPE.DECIMAL ? 0.1 : 1;
|
|
187
229
|
if (values?.operator === OPERATOR.BETWEEN) {
|
|
188
230
|
return (
|
|
189
|
-
<
|
|
190
|
-
<
|
|
191
|
-
<
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
<
|
|
196
|
-
|
|
197
|
-
|
|
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>
|
|
198
242
|
);
|
|
199
243
|
} else {
|
|
200
244
|
return (
|
|
@@ -204,64 +248,84 @@ export const FilterForm = ({
|
|
|
204
248
|
);
|
|
205
249
|
}
|
|
206
250
|
}
|
|
207
|
-
|
|
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]);
|
|
208
277
|
|
|
209
278
|
const handleSubmit = useCallback(
|
|
210
279
|
(model: FilterSchemaType) => {
|
|
211
280
|
const filter: FilterObject = {
|
|
212
281
|
id: model.id,
|
|
213
282
|
field: model.field,
|
|
214
|
-
type: model.type,
|
|
215
283
|
negate: model.negate,
|
|
216
284
|
operator: model.operator,
|
|
217
|
-
value: model.value as
|
|
285
|
+
value: model.value as FilterValue,
|
|
218
286
|
label: model.label,
|
|
287
|
+
type: field?.type,
|
|
219
288
|
};
|
|
220
289
|
onChange?.(filter);
|
|
221
290
|
tree?.events.emit("close");
|
|
222
291
|
},
|
|
223
|
-
|
|
292
|
+
// eslint-disable-next-line @eslint-react/exhaustive-deps
|
|
293
|
+
[field, onChange],
|
|
224
294
|
);
|
|
225
295
|
|
|
226
296
|
return (
|
|
227
297
|
<Form<FilterSchemaType>
|
|
228
298
|
formRef={formRef}
|
|
229
|
-
|
|
299
|
+
resolver={yupResolver(FilterSchema)}
|
|
230
300
|
defaultValues={values}
|
|
231
301
|
onChange={setValues}
|
|
232
302
|
onSubmit={handleSubmit}
|
|
233
303
|
>
|
|
234
|
-
<div className="w-
|
|
304
|
+
<div className="w-lg">
|
|
235
305
|
<Row>
|
|
236
306
|
<Col flex="fill">
|
|
237
307
|
<Controller name="field">
|
|
238
308
|
<Select<FilterField>
|
|
239
309
|
required
|
|
310
|
+
searchable
|
|
240
311
|
ref={inputRef}
|
|
241
312
|
label={t("label.field")}
|
|
242
313
|
options={fields}
|
|
243
314
|
labelProperty="label"
|
|
244
315
|
valueProperty="field"
|
|
245
316
|
groupProperty="type"
|
|
246
|
-
onSelect={(field) =>
|
|
247
|
-
formRef.current?.setValue("type", field.type)
|
|
248
|
-
}
|
|
249
317
|
/>
|
|
250
318
|
</Controller>
|
|
251
319
|
</Col>
|
|
252
|
-
<Col flex="
|
|
320
|
+
<Col flex="content" className="text-center">
|
|
253
321
|
<label className="block py-0.5 text-sm">{t("label.exclude")}</label>
|
|
254
322
|
<Controller name="negate">
|
|
255
323
|
<Switch color="danger" />
|
|
256
324
|
</Controller>
|
|
257
325
|
</Col>
|
|
258
|
-
<Col flex="
|
|
326
|
+
<Col flex="content" className="basis-28">
|
|
259
327
|
<Controller name="operator">
|
|
260
|
-
<Select
|
|
261
|
-
label={t("label.operator")}
|
|
262
|
-
options={operators}
|
|
263
|
-
renderer={(v) => t(`operator.${v}`)}
|
|
264
|
-
/>
|
|
328
|
+
<Select label={t("label.operator")} options={operators} renderer={(v) => t(`operator.${v}`)} />
|
|
265
329
|
</Controller>
|
|
266
330
|
</Col>
|
|
267
331
|
</Row>
|
|
@@ -272,30 +336,24 @@ export const FilterForm = ({
|
|
|
272
336
|
<Input
|
|
273
337
|
label={t("label.label")}
|
|
274
338
|
placeholder={t("label.label")}
|
|
275
|
-
decorateEnd={
|
|
276
|
-
!filter?.label && (
|
|
277
|
-
<span className="text-sm opacity-65 pe-4">Optional</span>
|
|
278
|
-
)
|
|
279
|
-
}
|
|
339
|
+
decorateEnd={!filter?.label && <span className="text-sm opacity-65 pe-4">Optional</span>}
|
|
280
340
|
/>
|
|
281
341
|
</Controller>
|
|
282
|
-
<div className="flex
|
|
342
|
+
<div className="flex mt-4 justify-end gap-1 sticky bottom-1 bg-default">
|
|
283
343
|
{onRemove && (
|
|
284
344
|
<div className="flex-1">
|
|
285
|
-
<
|
|
286
|
-
data-dropdown-dismiss="true"
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
onClick={onRemove}
|
|
291
|
-
>
|
|
292
|
-
{t("label.remove")}
|
|
293
|
-
</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>
|
|
294
350
|
</div>
|
|
295
351
|
)}
|
|
296
|
-
<
|
|
297
|
-
|
|
298
|
-
|
|
352
|
+
<DropdownDismiss>
|
|
353
|
+
<Button data-dropdown-dismiss="true" variant="link" size="sm">
|
|
354
|
+
{t("label.cancel")}
|
|
355
|
+
</Button>
|
|
356
|
+
</DropdownDismiss>
|
|
299
357
|
<Button type="submit" variant="solid" size="sm">
|
|
300
358
|
{t("label.apply")}
|
|
301
359
|
</Button>
|
|
@@ -303,4 +361,4 @@ export const FilterForm = ({
|
|
|
303
361
|
</div>
|
|
304
362
|
</Form>
|
|
305
363
|
);
|
|
306
|
-
}
|
|
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
|
+
}
|