@react-fabric/searchbar 1.0.0-beta.4 → 1.0.0-beta.5
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/FilterForm.js +100 -79
- package/dist/cjs/filterbar/FilterTag.js +3 -2
- package/dist/cjs/filterbar/QueryForm.js +4 -1
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/searchbar/SearchBar.js +3 -3
- package/dist/cjs/types/index.js +1 -1
- package/dist/esm/filterbar/FilterForm.js +101 -80
- package/dist/esm/filterbar/FilterTag.js +3 -2
- package/dist/esm/filterbar/QueryForm.js +4 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/searchbar/SearchBar.js +3 -3
- package/dist/esm/types/index.js +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/searchbar/SearchBar.d.ts +1 -1
- package/dist/types/types/index.d.ts +15 -12
- package/package.json +7 -7
- package/src/filterbar/FilterForm.tsx +90 -71
- package/src/filterbar/FilterTag.tsx +2 -2
- package/src/filterbar/QueryForm.tsx +6 -1
- package/src/index.ts +2 -6
- package/src/searchbar/SearchBar.tsx +11 -8
- package/src/types/index.ts +26 -17
|
@@ -57,8 +57,9 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
57
57
|
values = _useState2[0],
|
|
58
58
|
setValues = _useState2[1];
|
|
59
59
|
react$1.useEffect(function () {
|
|
60
|
-
|
|
61
|
-
setValues(
|
|
60
|
+
var _formRef$current, _formRef$current2;
|
|
61
|
+
if (filter && "field" in filter && filter.field) return (_formRef$current = formRef.current) === null || _formRef$current === void 0 ? void 0 : _formRef$current.setValues(filter);
|
|
62
|
+
(_formRef$current2 = formRef.current) === null || _formRef$current2 === void 0 || _formRef$current2.setValues({
|
|
62
63
|
id: utilities.shortHash(),
|
|
63
64
|
field: "",
|
|
64
65
|
operator: index.OPERATOR.EXISTS
|
|
@@ -77,22 +78,38 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
77
78
|
});
|
|
78
79
|
}, [values]);
|
|
79
80
|
var operators = react$1.useMemo(function () {
|
|
80
|
-
var _formRef$
|
|
81
|
+
var _formRef$current3;
|
|
81
82
|
if (field == null) return [index.OPERATOR.EXISTS];
|
|
82
|
-
(_formRef$
|
|
83
|
+
(_formRef$current3 = formRef.current) === null || _formRef$current3 === void 0 || _formRef$current3.setValue("operator", index.TypeOperators[field.type][0]);
|
|
83
84
|
return _toConsumableArray(index.TypeOperators[field.type]);
|
|
84
85
|
}, [field]);
|
|
85
|
-
react$1.
|
|
86
|
+
var valueInput = react$1.useMemo(function () {
|
|
86
87
|
if ((values === null || values === void 0 ? void 0 : values.operator) === index.OPERATOR.EXISTS && (values === null || values === void 0 ? void 0 : values.value) !== undefined) {
|
|
87
|
-
var _formRef$
|
|
88
|
-
(_formRef$
|
|
88
|
+
var _formRef$current4;
|
|
89
|
+
(_formRef$current4 = formRef.current) === null || _formRef$current4 === void 0 || _formRef$current4.setValue("value", undefined);
|
|
90
|
+
}
|
|
91
|
+
if ((field === null || field === void 0 ? void 0 : field.type) === index.FIELD_TYPE.STRING) {
|
|
92
|
+
if ((values === null || values === void 0 ? void 0 : values.operator) === index.OPERATOR.IN) {
|
|
93
|
+
var _formRef$current5;
|
|
94
|
+
!utilities.isArray(values.value) && ((_formRef$current5 = formRef.current) === null || _formRef$current5 === void 0 ? void 0 : _formRef$current5.setValue("value", []));
|
|
95
|
+
} else {
|
|
96
|
+
var _formRef$current6;
|
|
97
|
+
utilities.isArray(values.value) && ((_formRef$current6 = formRef.current) === null || _formRef$current6 === void 0 ? void 0 : _formRef$current6.setValue("value", undefined));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if ((field === null || field === void 0 ? void 0 : field.type) === index.FIELD_TYPE.NUMBER || (field === null || field === void 0 ? void 0 : field.type) === index.FIELD_TYPE.DECIMAL) {
|
|
101
|
+
if ((values === null || values === void 0 ? void 0 : values.operator) === index.OPERATOR.BETWEEN) {
|
|
102
|
+
var _formRef$current7;
|
|
103
|
+
!utilities.isArray(values.value) && ((_formRef$current7 = formRef.current) === null || _formRef$current7 === void 0 ? void 0 : _formRef$current7.setValue("value", []));
|
|
104
|
+
} else {
|
|
105
|
+
var _formRef$current8;
|
|
106
|
+
utilities.isArray(values.value) && ((_formRef$current8 = formRef.current) === null || _formRef$current8 === void 0 ? void 0 : _formRef$current8.setValue("value", undefined));
|
|
107
|
+
}
|
|
89
108
|
}
|
|
90
109
|
if ((field === null || field === void 0 ? void 0 : field.type) === index.FIELD_TYPE.BOOLEAN && (values === null || values === void 0 ? void 0 : values.operator) === index.OPERATOR.IS && (values === null || values === void 0 ? void 0 : values.value) === undefined) {
|
|
91
|
-
var _formRef$
|
|
92
|
-
(_formRef$
|
|
110
|
+
var _formRef$current9;
|
|
111
|
+
(_formRef$current9 = formRef.current) === null || _formRef$current9 === void 0 || _formRef$current9.setValue("value", false);
|
|
93
112
|
}
|
|
94
|
-
}, [values, field]);
|
|
95
|
-
var valueInput = react$1.useMemo(function () {
|
|
96
113
|
if (field == null || !(values !== null && values !== void 0 && values.operator)) return null;
|
|
97
114
|
if ((values === null || values === void 0 ? void 0 : values.operator) === index.OPERATOR.EXISTS) return null;
|
|
98
115
|
if ((field === null || field === void 0 ? void 0 : field.type) === index.FIELD_TYPE.BOOLEAN) {
|
|
@@ -112,6 +129,7 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
112
129
|
name: "value",
|
|
113
130
|
children: /*#__PURE__*/jsxRuntime.jsx(form.Select, {
|
|
114
131
|
multiple: true,
|
|
132
|
+
searchable: true,
|
|
115
133
|
allowCreate: true,
|
|
116
134
|
allowClear: true,
|
|
117
135
|
options: (_field$values = field.values) !== null && _field$values !== void 0 ? _field$values : [],
|
|
@@ -142,7 +160,7 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
142
160
|
})
|
|
143
161
|
}), /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
144
162
|
className: "p-2 text-muted",
|
|
145
|
-
children: "
|
|
163
|
+
children: "\u2277"
|
|
146
164
|
}), /*#__PURE__*/jsxRuntime.jsx(form.Controller, {
|
|
147
165
|
name: "value[1]",
|
|
148
166
|
children: /*#__PURE__*/jsxRuntime.jsx(form.Number, {
|
|
@@ -175,87 +193,90 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
175
193
|
onChange === null || onChange === void 0 || onChange(filter);
|
|
176
194
|
tree === null || tree === void 0 || tree.events.emit("close");
|
|
177
195
|
}, [onChange]);
|
|
178
|
-
return /*#__PURE__*/jsxRuntime.
|
|
196
|
+
return /*#__PURE__*/jsxRuntime.jsx(form.Form, {
|
|
179
197
|
formRef: formRef,
|
|
180
198
|
schema: FilterSchema,
|
|
181
199
|
defaultValues: values,
|
|
182
200
|
onChange: setValues,
|
|
183
201
|
onSubmit: handleSubmit,
|
|
184
|
-
children:
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
children: /*#__PURE__*/jsxRuntime.jsx(
|
|
188
|
-
|
|
189
|
-
children: /*#__PURE__*/jsxRuntime.jsx(form.
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
202
|
+
children: /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
203
|
+
className: "w-[32rem]",
|
|
204
|
+
children: [/*#__PURE__*/jsxRuntime.jsxs(core.Row, {
|
|
205
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(core.Col, {
|
|
206
|
+
flex: "fill",
|
|
207
|
+
children: /*#__PURE__*/jsxRuntime.jsx(form.Controller, {
|
|
208
|
+
name: "field",
|
|
209
|
+
children: /*#__PURE__*/jsxRuntime.jsx(form.Select, {
|
|
210
|
+
required: true,
|
|
211
|
+
ref: inputRef,
|
|
212
|
+
label: t("label.field"),
|
|
213
|
+
options: fields,
|
|
214
|
+
labelProperty: "label",
|
|
215
|
+
valueProperty: "field",
|
|
216
|
+
groupProperty: "type"
|
|
217
|
+
})
|
|
197
218
|
})
|
|
198
|
-
})
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
219
|
+
}), /*#__PURE__*/jsxRuntime.jsxs(core.Col, {
|
|
220
|
+
flex: "auto",
|
|
221
|
+
className: "text-center",
|
|
222
|
+
children: [/*#__PURE__*/jsxRuntime.jsx("label", {
|
|
223
|
+
className: "block py-0.5 text-sm",
|
|
224
|
+
children: t("label.exclude")
|
|
225
|
+
}), /*#__PURE__*/jsxRuntime.jsx(form.Controller, {
|
|
226
|
+
name: "negate",
|
|
227
|
+
children: /*#__PURE__*/jsxRuntime.jsx(form.Switch, {
|
|
228
|
+
color: "danger"
|
|
229
|
+
})
|
|
230
|
+
})]
|
|
231
|
+
}), /*#__PURE__*/jsxRuntime.jsx(core.Col, {
|
|
232
|
+
flex: "auto",
|
|
233
|
+
className: "basis-28",
|
|
234
|
+
children: /*#__PURE__*/jsxRuntime.jsx(form.Controller, {
|
|
235
|
+
name: "operator",
|
|
236
|
+
children: /*#__PURE__*/jsxRuntime.jsx(form.Select, {
|
|
237
|
+
label: t("label.operator"),
|
|
238
|
+
options: operators,
|
|
239
|
+
renderer: function renderer(v) {
|
|
240
|
+
return t("operator.".concat(v));
|
|
241
|
+
}
|
|
242
|
+
})
|
|
209
243
|
})
|
|
210
244
|
})]
|
|
211
|
-
}), /*#__PURE__*/jsxRuntime.jsx(
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
renderer: function renderer(v) {
|
|
220
|
-
return t("operator.".concat(v));
|
|
221
|
-
}
|
|
245
|
+
}), /*#__PURE__*/jsxRuntime.jsx("br", {}), valueInput, /*#__PURE__*/jsxRuntime.jsx("br", {}), /*#__PURE__*/jsxRuntime.jsx(form.Controller, {
|
|
246
|
+
name: "label",
|
|
247
|
+
children: /*#__PURE__*/jsxRuntime.jsx(form.Input, {
|
|
248
|
+
label: t("label.label"),
|
|
249
|
+
placeholder: t("label.label"),
|
|
250
|
+
decorateEnd: !(filter !== null && filter !== void 0 && filter.label) && /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
251
|
+
className: "text-sm opacity-65 pe-4",
|
|
252
|
+
children: "Optional"
|
|
222
253
|
})
|
|
223
254
|
})
|
|
224
|
-
})
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
children: [onRemove && /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
238
|
-
className: "flex-1",
|
|
239
|
-
children: /*#__PURE__*/jsxRuntime.jsx(core.Button, {
|
|
255
|
+
}), /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
256
|
+
className: "flex pt-4 justify-end gap-1",
|
|
257
|
+
children: [onRemove && /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
258
|
+
className: "flex-1",
|
|
259
|
+
children: /*#__PURE__*/jsxRuntime.jsx(core.Button, {
|
|
260
|
+
"data-dropdown-dismiss": "true",
|
|
261
|
+
variant: "link",
|
|
262
|
+
size: "sm",
|
|
263
|
+
color: "danger",
|
|
264
|
+
onClick: onRemove,
|
|
265
|
+
children: t("label.remove")
|
|
266
|
+
})
|
|
267
|
+
}), /*#__PURE__*/jsxRuntime.jsx(core.Button, {
|
|
240
268
|
"data-dropdown-dismiss": "true",
|
|
241
269
|
variant: "link",
|
|
242
270
|
size: "sm",
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
size: "sm",
|
|
251
|
-
children: t("label.cancel")
|
|
252
|
-
}), /*#__PURE__*/jsxRuntime.jsx(core.Button, {
|
|
253
|
-
type: "submit",
|
|
254
|
-
variant: "solid",
|
|
255
|
-
size: "sm",
|
|
256
|
-
children: t("label.apply")
|
|
271
|
+
children: t("label.cancel")
|
|
272
|
+
}), /*#__PURE__*/jsxRuntime.jsx(core.Button, {
|
|
273
|
+
type: "submit",
|
|
274
|
+
variant: "solid",
|
|
275
|
+
size: "sm",
|
|
276
|
+
children: t("label.apply")
|
|
277
|
+
})]
|
|
257
278
|
})]
|
|
258
|
-
})
|
|
279
|
+
})
|
|
259
280
|
});
|
|
260
281
|
};
|
|
261
282
|
|
|
@@ -51,7 +51,8 @@ var FilterTag = function FilterTag(_ref) {
|
|
|
51
51
|
});
|
|
52
52
|
}, [filter]);
|
|
53
53
|
var color = react.useMemo(function () {
|
|
54
|
-
|
|
54
|
+
var _filter$color;
|
|
55
|
+
return (_filter$color = filter.color) !== null && _filter$color !== void 0 ? _filter$color : filter.negate ? excludedColor : includedColor;
|
|
55
56
|
}, [filter, includedColor, excludedColor]);
|
|
56
57
|
var icon = react.useMemo(function () {
|
|
57
58
|
if (filter.canDisable === false) return undefined;
|
|
@@ -76,7 +77,7 @@ var FilterTag = function FilterTag(_ref) {
|
|
|
76
77
|
return onRemove();
|
|
77
78
|
},
|
|
78
79
|
children: /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
79
|
-
className: classNames("flex gap-1", filter.disabled && "line-through opacity-65"),
|
|
80
|
+
className: classNames("flex gap-1 items-center", filter.disabled && "line-through opacity-65"),
|
|
80
81
|
children: [filter.pinned && /*#__PURE__*/jsxRuntime.jsx(core.Icon, {
|
|
81
82
|
icon: (_filter$icon = filter.icon) !== null && _filter$icon !== void 0 ? _filter$icon : core.CoreIcons.pin
|
|
82
83
|
}), label]
|
|
@@ -95,7 +95,10 @@ var QueryForm = function QueryForm(_ref) {
|
|
|
95
95
|
className: classNames("block px-2", invalid && "text-danger-600"),
|
|
96
96
|
children: t("label.query")
|
|
97
97
|
}), /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
98
|
-
className: "h-[
|
|
98
|
+
className: "h-[24rem] w-[36rem] grid outline place-content-start",
|
|
99
|
+
style: {
|
|
100
|
+
gridTemplate: '"content" 1fr/1fr'
|
|
101
|
+
},
|
|
99
102
|
children: /*#__PURE__*/jsxRuntime.jsx(monaco.CodeEditor, _objectSpread(_objectSpread({
|
|
100
103
|
minimal: true,
|
|
101
104
|
required: true
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
require('./i18n/index.js');
|
|
4
|
+
var FilterBar = require('./filterbar/FilterBar.js');
|
|
4
5
|
var SearchBar = require('./searchbar/SearchBar.js');
|
|
5
6
|
var index = require('./types/index.js');
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
|
|
10
|
+
exports.FilterBar = FilterBar.FilterBar;
|
|
9
11
|
exports.SearchBar = SearchBar.SearchBar;
|
|
10
12
|
exports.FIELD_TYPE = index.FIELD_TYPE;
|
|
11
13
|
exports.OPERATOR = index.OPERATOR;
|
|
@@ -12,7 +12,7 @@ var reactI18next = require('react-i18next');
|
|
|
12
12
|
var FilterBar = require('../filterbar/FilterBar.js');
|
|
13
13
|
var jsxRuntime = require('react/jsx-runtime');
|
|
14
14
|
|
|
15
|
-
var _excluded = ["historyKey", "historyCount", "defaultQueryList", "prepend", "append", "decorateEnd", "decorateStart", "
|
|
15
|
+
var _excluded = ["historyKey", "historyCount", "defaultQueryList", "prepend", "append", "decorateEnd", "decorateStart", "children", "hideFilters", "defaultCollapsed", "disabled", "onCollapsed", "onQuery", "onSearch", "query", "multiple", "filters"];
|
|
16
16
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
17
17
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
18
18
|
var SearchBar = function SearchBar(_ref) {
|
|
@@ -25,7 +25,7 @@ var SearchBar = function SearchBar(_ref) {
|
|
|
25
25
|
append = _ref.append,
|
|
26
26
|
decorateEnd = _ref.decorateEnd,
|
|
27
27
|
decorateStart = _ref.decorateStart,
|
|
28
|
-
|
|
28
|
+
children = _ref.children,
|
|
29
29
|
hideFilters = _ref.hideFilters,
|
|
30
30
|
_ref$defaultCollapsed = _ref.defaultCollapsed,
|
|
31
31
|
defaultCollapsed = _ref$defaultCollapsed === void 0 ? false : _ref$defaultCollapsed;
|
|
@@ -143,7 +143,7 @@ var SearchBar = function SearchBar(_ref) {
|
|
|
143
143
|
},
|
|
144
144
|
children: t(state.dirty ? "label.update" : "label.refresh")
|
|
145
145
|
})]
|
|
146
|
-
}),
|
|
146
|
+
}), children]
|
|
147
147
|
}), !hideFilters && !collapsed && /*#__PURE__*/jsxRuntime.jsx(FilterBar.FilterBar, _objectSpread(_objectSpread({}, filterProps), {}, {
|
|
148
148
|
filters: state.filters,
|
|
149
149
|
onFilterChanged: handleFilterChange
|
package/dist/cjs/types/index.js
CHANGED
|
@@ -54,7 +54,7 @@ var OPERATOR = /*#__PURE__*/function (OPERATOR) {
|
|
|
54
54
|
/**
|
|
55
55
|
* @internal
|
|
56
56
|
*/
|
|
57
|
-
var TypeOperators = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, FIELD_TYPE.ID, [OPERATOR.IS]), FIELD_TYPE.STRING, [OPERATOR.EXISTS, OPERATOR.IS, OPERATOR.IN, OPERATOR.INCLUDES, OPERATOR.STARTS, OPERATOR.ENDS]), FIELD_TYPE.NUMBER, [OPERATOR.EXISTS, OPERATOR.IS, OPERATOR.BETWEEN, OPERATOR.LT, OPERATOR.GT, OPERATOR.LTE, OPERATOR.GTE]), FIELD_TYPE.DECIMAL, [OPERATOR.EXISTS, OPERATOR.IS, OPERATOR.BETWEEN, OPERATOR.LT, OPERATOR.GT, OPERATOR.LTE, OPERATOR.GTE]), FIELD_TYPE.BOOLEAN, [OPERATOR.EXISTS, OPERATOR.IS]), FIELD_TYPE.NONE, [OPERATOR.EXISTS]);
|
|
57
|
+
var TypeOperators = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, FIELD_TYPE.ID, [OPERATOR.IS, OPERATOR.IN]), FIELD_TYPE.STRING, [OPERATOR.EXISTS, OPERATOR.IS, OPERATOR.IN, OPERATOR.INCLUDES, OPERATOR.STARTS, OPERATOR.ENDS]), FIELD_TYPE.NUMBER, [OPERATOR.EXISTS, OPERATOR.IS, OPERATOR.BETWEEN, OPERATOR.LT, OPERATOR.GT, OPERATOR.LTE, OPERATOR.GTE]), FIELD_TYPE.DECIMAL, [OPERATOR.EXISTS, OPERATOR.IS, OPERATOR.BETWEEN, OPERATOR.LT, OPERATOR.GT, OPERATOR.LTE, OPERATOR.GTE]), FIELD_TYPE.BOOLEAN, [OPERATOR.EXISTS, OPERATOR.IS]), FIELD_TYPE.NONE, [OPERATOR.EXISTS]);
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
60
|
* @internal
|
|
@@ -5,7 +5,7 @@ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
|
5
5
|
import { useFloatingTree } from '@floating-ui/react';
|
|
6
6
|
import { Row, Col, Button } from '@react-fabric/core';
|
|
7
7
|
import { Field, Controller, Switch, Select, Input, Number, Form } from '@react-fabric/form';
|
|
8
|
-
import { yup, shortHash } from '@react-fabric/utilities';
|
|
8
|
+
import { yup, shortHash, isArray } from '@react-fabric/utilities';
|
|
9
9
|
import { useRef, useState, useEffect, useMemo, useCallback } from 'react';
|
|
10
10
|
import { useTranslation } from 'react-i18next';
|
|
11
11
|
import { OPERATOR, TypeOperators, FIELD_TYPE } from '../types/index.js';
|
|
@@ -57,8 +57,9 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
57
57
|
values = _useState2[0],
|
|
58
58
|
setValues = _useState2[1];
|
|
59
59
|
useEffect(function () {
|
|
60
|
-
|
|
61
|
-
setValues(
|
|
60
|
+
var _formRef$current, _formRef$current2;
|
|
61
|
+
if (filter && "field" in filter && filter.field) return (_formRef$current = formRef.current) === null || _formRef$current === void 0 ? void 0 : _formRef$current.setValues(filter);
|
|
62
|
+
(_formRef$current2 = formRef.current) === null || _formRef$current2 === void 0 || _formRef$current2.setValues({
|
|
62
63
|
id: shortHash(),
|
|
63
64
|
field: "",
|
|
64
65
|
operator: OPERATOR.EXISTS
|
|
@@ -77,22 +78,38 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
77
78
|
});
|
|
78
79
|
}, [values]);
|
|
79
80
|
var operators = useMemo(function () {
|
|
80
|
-
var _formRef$
|
|
81
|
+
var _formRef$current3;
|
|
81
82
|
if (field == null) return [OPERATOR.EXISTS];
|
|
82
|
-
(_formRef$
|
|
83
|
+
(_formRef$current3 = formRef.current) === null || _formRef$current3 === void 0 || _formRef$current3.setValue("operator", TypeOperators[field.type][0]);
|
|
83
84
|
return _toConsumableArray(TypeOperators[field.type]);
|
|
84
85
|
}, [field]);
|
|
85
|
-
|
|
86
|
+
var valueInput = useMemo(function () {
|
|
86
87
|
if ((values === null || values === void 0 ? void 0 : values.operator) === OPERATOR.EXISTS && (values === null || values === void 0 ? void 0 : values.value) !== undefined) {
|
|
87
|
-
var _formRef$
|
|
88
|
-
(_formRef$
|
|
88
|
+
var _formRef$current4;
|
|
89
|
+
(_formRef$current4 = formRef.current) === null || _formRef$current4 === void 0 || _formRef$current4.setValue("value", undefined);
|
|
90
|
+
}
|
|
91
|
+
if ((field === null || field === void 0 ? void 0 : field.type) === FIELD_TYPE.STRING) {
|
|
92
|
+
if ((values === null || values === void 0 ? void 0 : values.operator) === OPERATOR.IN) {
|
|
93
|
+
var _formRef$current5;
|
|
94
|
+
!isArray(values.value) && ((_formRef$current5 = formRef.current) === null || _formRef$current5 === void 0 ? void 0 : _formRef$current5.setValue("value", []));
|
|
95
|
+
} else {
|
|
96
|
+
var _formRef$current6;
|
|
97
|
+
isArray(values.value) && ((_formRef$current6 = formRef.current) === null || _formRef$current6 === void 0 ? void 0 : _formRef$current6.setValue("value", undefined));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if ((field === null || field === void 0 ? void 0 : field.type) === FIELD_TYPE.NUMBER || (field === null || field === void 0 ? void 0 : field.type) === FIELD_TYPE.DECIMAL) {
|
|
101
|
+
if ((values === null || values === void 0 ? void 0 : values.operator) === OPERATOR.BETWEEN) {
|
|
102
|
+
var _formRef$current7;
|
|
103
|
+
!isArray(values.value) && ((_formRef$current7 = formRef.current) === null || _formRef$current7 === void 0 ? void 0 : _formRef$current7.setValue("value", []));
|
|
104
|
+
} else {
|
|
105
|
+
var _formRef$current8;
|
|
106
|
+
isArray(values.value) && ((_formRef$current8 = formRef.current) === null || _formRef$current8 === void 0 ? void 0 : _formRef$current8.setValue("value", undefined));
|
|
107
|
+
}
|
|
89
108
|
}
|
|
90
109
|
if ((field === null || field === void 0 ? void 0 : field.type) === FIELD_TYPE.BOOLEAN && (values === null || values === void 0 ? void 0 : values.operator) === OPERATOR.IS && (values === null || values === void 0 ? void 0 : values.value) === undefined) {
|
|
91
|
-
var _formRef$
|
|
92
|
-
(_formRef$
|
|
110
|
+
var _formRef$current9;
|
|
111
|
+
(_formRef$current9 = formRef.current) === null || _formRef$current9 === void 0 || _formRef$current9.setValue("value", false);
|
|
93
112
|
}
|
|
94
|
-
}, [values, field]);
|
|
95
|
-
var valueInput = useMemo(function () {
|
|
96
113
|
if (field == null || !(values !== null && values !== void 0 && values.operator)) return null;
|
|
97
114
|
if ((values === null || values === void 0 ? void 0 : values.operator) === OPERATOR.EXISTS) return null;
|
|
98
115
|
if ((field === null || field === void 0 ? void 0 : field.type) === FIELD_TYPE.BOOLEAN) {
|
|
@@ -112,6 +129,7 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
112
129
|
name: "value",
|
|
113
130
|
children: /*#__PURE__*/jsx(Select, {
|
|
114
131
|
multiple: true,
|
|
132
|
+
searchable: true,
|
|
115
133
|
allowCreate: true,
|
|
116
134
|
allowClear: true,
|
|
117
135
|
options: (_field$values = field.values) !== null && _field$values !== void 0 ? _field$values : [],
|
|
@@ -142,7 +160,7 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
142
160
|
})
|
|
143
161
|
}), /*#__PURE__*/jsx("span", {
|
|
144
162
|
className: "p-2 text-muted",
|
|
145
|
-
children: "
|
|
163
|
+
children: "\u2277"
|
|
146
164
|
}), /*#__PURE__*/jsx(Controller, {
|
|
147
165
|
name: "value[1]",
|
|
148
166
|
children: /*#__PURE__*/jsx(Number, {
|
|
@@ -175,87 +193,90 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
175
193
|
onChange === null || onChange === void 0 || onChange(filter);
|
|
176
194
|
tree === null || tree === void 0 || tree.events.emit("close");
|
|
177
195
|
}, [onChange]);
|
|
178
|
-
return /*#__PURE__*/
|
|
196
|
+
return /*#__PURE__*/jsx(Form, {
|
|
179
197
|
formRef: formRef,
|
|
180
198
|
schema: FilterSchema,
|
|
181
199
|
defaultValues: values,
|
|
182
200
|
onChange: setValues,
|
|
183
201
|
onSubmit: handleSubmit,
|
|
184
|
-
children:
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
children: /*#__PURE__*/jsx(
|
|
188
|
-
|
|
189
|
-
children: /*#__PURE__*/jsx(
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
202
|
+
children: /*#__PURE__*/jsxs("div", {
|
|
203
|
+
className: "w-[32rem]",
|
|
204
|
+
children: [/*#__PURE__*/jsxs(Row, {
|
|
205
|
+
children: [/*#__PURE__*/jsx(Col, {
|
|
206
|
+
flex: "fill",
|
|
207
|
+
children: /*#__PURE__*/jsx(Controller, {
|
|
208
|
+
name: "field",
|
|
209
|
+
children: /*#__PURE__*/jsx(Select, {
|
|
210
|
+
required: true,
|
|
211
|
+
ref: inputRef,
|
|
212
|
+
label: t("label.field"),
|
|
213
|
+
options: fields,
|
|
214
|
+
labelProperty: "label",
|
|
215
|
+
valueProperty: "field",
|
|
216
|
+
groupProperty: "type"
|
|
217
|
+
})
|
|
197
218
|
})
|
|
198
|
-
})
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
219
|
+
}), /*#__PURE__*/jsxs(Col, {
|
|
220
|
+
flex: "auto",
|
|
221
|
+
className: "text-center",
|
|
222
|
+
children: [/*#__PURE__*/jsx("label", {
|
|
223
|
+
className: "block py-0.5 text-sm",
|
|
224
|
+
children: t("label.exclude")
|
|
225
|
+
}), /*#__PURE__*/jsx(Controller, {
|
|
226
|
+
name: "negate",
|
|
227
|
+
children: /*#__PURE__*/jsx(Switch, {
|
|
228
|
+
color: "danger"
|
|
229
|
+
})
|
|
230
|
+
})]
|
|
231
|
+
}), /*#__PURE__*/jsx(Col, {
|
|
232
|
+
flex: "auto",
|
|
233
|
+
className: "basis-28",
|
|
234
|
+
children: /*#__PURE__*/jsx(Controller, {
|
|
235
|
+
name: "operator",
|
|
236
|
+
children: /*#__PURE__*/jsx(Select, {
|
|
237
|
+
label: t("label.operator"),
|
|
238
|
+
options: operators,
|
|
239
|
+
renderer: function renderer(v) {
|
|
240
|
+
return t("operator.".concat(v));
|
|
241
|
+
}
|
|
242
|
+
})
|
|
209
243
|
})
|
|
210
244
|
})]
|
|
211
|
-
}), /*#__PURE__*/jsx(
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
renderer: function renderer(v) {
|
|
220
|
-
return t("operator.".concat(v));
|
|
221
|
-
}
|
|
245
|
+
}), /*#__PURE__*/jsx("br", {}), valueInput, /*#__PURE__*/jsx("br", {}), /*#__PURE__*/jsx(Controller, {
|
|
246
|
+
name: "label",
|
|
247
|
+
children: /*#__PURE__*/jsx(Input, {
|
|
248
|
+
label: t("label.label"),
|
|
249
|
+
placeholder: t("label.label"),
|
|
250
|
+
decorateEnd: !(filter !== null && filter !== void 0 && filter.label) && /*#__PURE__*/jsx("span", {
|
|
251
|
+
className: "text-sm opacity-65 pe-4",
|
|
252
|
+
children: "Optional"
|
|
222
253
|
})
|
|
223
254
|
})
|
|
224
|
-
})
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
children: [onRemove && /*#__PURE__*/jsx("div", {
|
|
238
|
-
className: "flex-1",
|
|
239
|
-
children: /*#__PURE__*/jsx(Button, {
|
|
255
|
+
}), /*#__PURE__*/jsxs("div", {
|
|
256
|
+
className: "flex pt-4 justify-end gap-1",
|
|
257
|
+
children: [onRemove && /*#__PURE__*/jsx("div", {
|
|
258
|
+
className: "flex-1",
|
|
259
|
+
children: /*#__PURE__*/jsx(Button, {
|
|
260
|
+
"data-dropdown-dismiss": "true",
|
|
261
|
+
variant: "link",
|
|
262
|
+
size: "sm",
|
|
263
|
+
color: "danger",
|
|
264
|
+
onClick: onRemove,
|
|
265
|
+
children: t("label.remove")
|
|
266
|
+
})
|
|
267
|
+
}), /*#__PURE__*/jsx(Button, {
|
|
240
268
|
"data-dropdown-dismiss": "true",
|
|
241
269
|
variant: "link",
|
|
242
270
|
size: "sm",
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
size: "sm",
|
|
251
|
-
children: t("label.cancel")
|
|
252
|
-
}), /*#__PURE__*/jsx(Button, {
|
|
253
|
-
type: "submit",
|
|
254
|
-
variant: "solid",
|
|
255
|
-
size: "sm",
|
|
256
|
-
children: t("label.apply")
|
|
271
|
+
children: t("label.cancel")
|
|
272
|
+
}), /*#__PURE__*/jsx(Button, {
|
|
273
|
+
type: "submit",
|
|
274
|
+
variant: "solid",
|
|
275
|
+
size: "sm",
|
|
276
|
+
children: t("label.apply")
|
|
277
|
+
})]
|
|
257
278
|
})]
|
|
258
|
-
})
|
|
279
|
+
})
|
|
259
280
|
});
|
|
260
281
|
};
|
|
261
282
|
|
|
@@ -51,7 +51,8 @@ var FilterTag = function FilterTag(_ref) {
|
|
|
51
51
|
});
|
|
52
52
|
}, [filter]);
|
|
53
53
|
var color = useMemo(function () {
|
|
54
|
-
|
|
54
|
+
var _filter$color;
|
|
55
|
+
return (_filter$color = filter.color) !== null && _filter$color !== void 0 ? _filter$color : filter.negate ? excludedColor : includedColor;
|
|
55
56
|
}, [filter, includedColor, excludedColor]);
|
|
56
57
|
var icon = useMemo(function () {
|
|
57
58
|
if (filter.canDisable === false) return undefined;
|
|
@@ -76,7 +77,7 @@ var FilterTag = function FilterTag(_ref) {
|
|
|
76
77
|
return onRemove();
|
|
77
78
|
},
|
|
78
79
|
children: /*#__PURE__*/jsxs("div", {
|
|
79
|
-
className: classNames("flex gap-1", filter.disabled && "line-through opacity-65"),
|
|
80
|
+
className: classNames("flex gap-1 items-center", filter.disabled && "line-through opacity-65"),
|
|
80
81
|
children: [filter.pinned && /*#__PURE__*/jsx(Icon, {
|
|
81
82
|
icon: (_filter$icon = filter.icon) !== null && _filter$icon !== void 0 ? _filter$icon : CoreIcons.pin
|
|
82
83
|
}), label]
|
|
@@ -95,7 +95,10 @@ var QueryForm = function QueryForm(_ref) {
|
|
|
95
95
|
className: classNames("block px-2", invalid && "text-danger-600"),
|
|
96
96
|
children: t("label.query")
|
|
97
97
|
}), /*#__PURE__*/jsx("div", {
|
|
98
|
-
className: "h-[
|
|
98
|
+
className: "h-[24rem] w-[36rem] grid outline place-content-start",
|
|
99
|
+
style: {
|
|
100
|
+
gridTemplate: '"content" 1fr/1fr'
|
|
101
|
+
},
|
|
99
102
|
children: /*#__PURE__*/jsx(CodeEditor, _objectSpread(_objectSpread({
|
|
100
103
|
minimal: true,
|
|
101
104
|
required: true
|
package/dist/esm/index.js
CHANGED
|
@@ -12,7 +12,7 @@ import { useTranslation } from 'react-i18next';
|
|
|
12
12
|
import { FilterBar } from '../filterbar/FilterBar.js';
|
|
13
13
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
14
14
|
|
|
15
|
-
var _excluded = ["historyKey", "historyCount", "defaultQueryList", "prepend", "append", "decorateEnd", "decorateStart", "
|
|
15
|
+
var _excluded = ["historyKey", "historyCount", "defaultQueryList", "prepend", "append", "decorateEnd", "decorateStart", "children", "hideFilters", "defaultCollapsed", "disabled", "onCollapsed", "onQuery", "onSearch", "query", "multiple", "filters"];
|
|
16
16
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
17
17
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
18
18
|
var SearchBar = function SearchBar(_ref) {
|
|
@@ -25,7 +25,7 @@ var SearchBar = function SearchBar(_ref) {
|
|
|
25
25
|
append = _ref.append,
|
|
26
26
|
decorateEnd = _ref.decorateEnd,
|
|
27
27
|
decorateStart = _ref.decorateStart,
|
|
28
|
-
|
|
28
|
+
children = _ref.children,
|
|
29
29
|
hideFilters = _ref.hideFilters,
|
|
30
30
|
_ref$defaultCollapsed = _ref.defaultCollapsed,
|
|
31
31
|
defaultCollapsed = _ref$defaultCollapsed === void 0 ? false : _ref$defaultCollapsed;
|
|
@@ -143,7 +143,7 @@ var SearchBar = function SearchBar(_ref) {
|
|
|
143
143
|
},
|
|
144
144
|
children: t(state.dirty ? "label.update" : "label.refresh")
|
|
145
145
|
})]
|
|
146
|
-
}),
|
|
146
|
+
}), children]
|
|
147
147
|
}), !hideFilters && !collapsed && /*#__PURE__*/jsx(FilterBar, _objectSpread(_objectSpread({}, filterProps), {}, {
|
|
148
148
|
filters: state.filters,
|
|
149
149
|
onFilterChanged: handleFilterChange
|
package/dist/esm/types/index.js
CHANGED
|
@@ -54,7 +54,7 @@ var OPERATOR = /*#__PURE__*/function (OPERATOR) {
|
|
|
54
54
|
/**
|
|
55
55
|
* @internal
|
|
56
56
|
*/
|
|
57
|
-
var TypeOperators = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, FIELD_TYPE.ID, [OPERATOR.IS]), FIELD_TYPE.STRING, [OPERATOR.EXISTS, OPERATOR.IS, OPERATOR.IN, OPERATOR.INCLUDES, OPERATOR.STARTS, OPERATOR.ENDS]), FIELD_TYPE.NUMBER, [OPERATOR.EXISTS, OPERATOR.IS, OPERATOR.BETWEEN, OPERATOR.LT, OPERATOR.GT, OPERATOR.LTE, OPERATOR.GTE]), FIELD_TYPE.DECIMAL, [OPERATOR.EXISTS, OPERATOR.IS, OPERATOR.BETWEEN, OPERATOR.LT, OPERATOR.GT, OPERATOR.LTE, OPERATOR.GTE]), FIELD_TYPE.BOOLEAN, [OPERATOR.EXISTS, OPERATOR.IS]), FIELD_TYPE.NONE, [OPERATOR.EXISTS]);
|
|
57
|
+
var TypeOperators = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, FIELD_TYPE.ID, [OPERATOR.IS, OPERATOR.IN]), FIELD_TYPE.STRING, [OPERATOR.EXISTS, OPERATOR.IS, OPERATOR.IN, OPERATOR.INCLUDES, OPERATOR.STARTS, OPERATOR.ENDS]), FIELD_TYPE.NUMBER, [OPERATOR.EXISTS, OPERATOR.IS, OPERATOR.BETWEEN, OPERATOR.LT, OPERATOR.GT, OPERATOR.LTE, OPERATOR.GTE]), FIELD_TYPE.DECIMAL, [OPERATOR.EXISTS, OPERATOR.IS, OPERATOR.BETWEEN, OPERATOR.LT, OPERATOR.GT, OPERATOR.LTE, OPERATOR.GTE]), FIELD_TYPE.BOOLEAN, [OPERATOR.EXISTS, OPERATOR.IS]), FIELD_TYPE.NONE, [OPERATOR.EXISTS]);
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
60
|
* @internal
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import "./i18n";
|
|
2
|
+
export { FilterBar } from "./filterbar/FilterBar";
|
|
2
3
|
export { SearchBar } from "./searchbar/SearchBar";
|
|
3
|
-
export { FIELD_TYPE, OPERATOR, type FilterObject
|
|
4
|
+
export { FIELD_TYPE, OPERATOR, type FilterObject } from "./types";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { type FilterBarProps, type SearchBarProps } from "../types";
|
|
2
|
-
export declare const SearchBar: ({ historyKey, historyCount, defaultQueryList, prepend, append, decorateEnd, decorateStart,
|
|
2
|
+
export declare const SearchBar: ({ historyKey, historyCount, defaultQueryList, prepend, append, decorateEnd, decorateStart, children, hideFilters, defaultCollapsed, disabled, onCollapsed, onQuery, onSearch, query, multiple, filters, ...filterProps }: SearchBarProps & Omit<FilterBarProps, "onFilterChanged">) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ChildrenProp } from "@react-fabric/core/dist/types/types";
|
|
1
2
|
import { type ReactElement } from "react";
|
|
2
3
|
export declare enum FIELD_TYPE {
|
|
3
4
|
ID = "ID",
|
|
@@ -42,6 +43,7 @@ interface BaseFilter {
|
|
|
42
43
|
icon?: string;
|
|
43
44
|
label?: string;
|
|
44
45
|
group?: string;
|
|
46
|
+
color?: string;
|
|
45
47
|
value?: FilterValue;
|
|
46
48
|
pinned?: boolean;
|
|
47
49
|
negate?: boolean;
|
|
@@ -65,8 +67,8 @@ export type FilterObject = BaseFilter & ({
|
|
|
65
67
|
label: string;
|
|
66
68
|
query: string;
|
|
67
69
|
});
|
|
68
|
-
export interface SearchObject {
|
|
69
|
-
query?:
|
|
70
|
+
export interface SearchObject<T = string> {
|
|
71
|
+
query?: T;
|
|
70
72
|
filters: FilterObject[];
|
|
71
73
|
}
|
|
72
74
|
export type FieldValue = string | {
|
|
@@ -82,7 +84,7 @@ export interface FilterField {
|
|
|
82
84
|
defaultOperator?: OPERATOR;
|
|
83
85
|
onSearch?: (q: string) => Promise<FieldValue[]> | FieldValue[];
|
|
84
86
|
}
|
|
85
|
-
interface BaseSearchBarProps {
|
|
87
|
+
interface BaseSearchBarProps extends Partial<ChildrenProp> {
|
|
86
88
|
/**
|
|
87
89
|
* Query string
|
|
88
90
|
*/
|
|
@@ -109,10 +111,6 @@ interface BaseSearchBarProps {
|
|
|
109
111
|
* Add-on after search input
|
|
110
112
|
*/
|
|
111
113
|
append?: ReactElement;
|
|
112
|
-
/**
|
|
113
|
-
* Additional actions menu
|
|
114
|
-
*/
|
|
115
|
-
actions?: ReactElement;
|
|
116
114
|
/**
|
|
117
115
|
* Hide filter bar
|
|
118
116
|
*/
|
|
@@ -139,11 +137,6 @@ interface BaseSearchBarProps {
|
|
|
139
137
|
* @param collapsed
|
|
140
138
|
*/
|
|
141
139
|
onCollapsed?: (collapsed: boolean) => void;
|
|
142
|
-
/**
|
|
143
|
-
* On search event
|
|
144
|
-
* @param queryObject
|
|
145
|
-
*/
|
|
146
|
-
onSearch?: (queryObject: SearchObject) => void;
|
|
147
140
|
/**
|
|
148
141
|
* On query string change event
|
|
149
142
|
* @param query
|
|
@@ -153,9 +146,19 @@ interface BaseSearchBarProps {
|
|
|
153
146
|
export type SearchBarProps = BaseSearchBarProps & ({
|
|
154
147
|
multiple: true;
|
|
155
148
|
query?: string[];
|
|
149
|
+
/**
|
|
150
|
+
* On search event
|
|
151
|
+
* @param queryObject
|
|
152
|
+
*/
|
|
153
|
+
onSearch?: (queryObject: SearchObject<string[]>) => void;
|
|
156
154
|
} | {
|
|
157
155
|
multiple?: never | false;
|
|
158
156
|
query?: string;
|
|
157
|
+
/**
|
|
158
|
+
* On search event
|
|
159
|
+
* @param queryObject
|
|
160
|
+
*/
|
|
161
|
+
onSearch?: (queryObject: SearchObject) => void;
|
|
159
162
|
});
|
|
160
163
|
export interface FilterBarProps {
|
|
161
164
|
/**
|
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.5",
|
|
4
4
|
"description": "RUF: Searchbar with filters package",
|
|
5
5
|
"author": "Adarsh Pastakia <adarshpastakia@outlook.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,11 +34,11 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@floating-ui/react": "0.26.24",
|
|
37
|
-
"@react-fabric/core": "^1.0.0-beta.
|
|
38
|
-
"@react-fabric/date": "^1.0.0-beta.
|
|
39
|
-
"@react-fabric/form": "^1.0.0-beta.
|
|
40
|
-
"@react-fabric/monaco": "^1.0.0-beta.
|
|
41
|
-
"@react-fabric/utilities": "^1.0.0-beta.
|
|
37
|
+
"@react-fabric/core": "^1.0.0-beta.5",
|
|
38
|
+
"@react-fabric/date": "^1.0.0-beta.5",
|
|
39
|
+
"@react-fabric/form": "^1.0.0-beta.5",
|
|
40
|
+
"@react-fabric/monaco": "^1.0.0-beta.5",
|
|
41
|
+
"@react-fabric/utilities": "^1.0.0-beta.5",
|
|
42
42
|
"classnames": "^2.5.1",
|
|
43
43
|
"react-hook-form": "^7.52.1"
|
|
44
44
|
},
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"node": ">=18.12.0",
|
|
53
53
|
"npm": ">=8.19.0"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "7d4a7ed1ea9890652826bef58d01c31280d761c8"
|
|
56
56
|
}
|
|
@@ -33,7 +33,7 @@ import {
|
|
|
33
33
|
Switch,
|
|
34
34
|
type FormRef,
|
|
35
35
|
} from "@react-fabric/form";
|
|
36
|
-
import { shortHash, yup } from "@react-fabric/utilities";
|
|
36
|
+
import { isArray, shortHash, yup } from "@react-fabric/utilities";
|
|
37
37
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
38
38
|
import { useTranslation } from "react-i18next";
|
|
39
39
|
import {
|
|
@@ -88,8 +88,9 @@ export const FilterForm = ({
|
|
|
88
88
|
const [values, setValues] = useState<FilterSchemaType>(filter as AnyObject);
|
|
89
89
|
|
|
90
90
|
useEffect(() => {
|
|
91
|
-
if (filter && "field" in filter && filter.field)
|
|
92
|
-
|
|
91
|
+
if (filter && "field" in filter && filter.field)
|
|
92
|
+
return formRef.current?.setValues(filter);
|
|
93
|
+
formRef.current?.setValues({
|
|
93
94
|
id: shortHash(),
|
|
94
95
|
field: "",
|
|
95
96
|
operator: OPERATOR.EXISTS,
|
|
@@ -113,10 +114,27 @@ export const FilterForm = ({
|
|
|
113
114
|
return [...TypeOperators[field.type]];
|
|
114
115
|
}, [field]);
|
|
115
116
|
|
|
116
|
-
|
|
117
|
+
const valueInput = useMemo(() => {
|
|
117
118
|
if (values?.operator === OPERATOR.EXISTS && values?.value !== undefined) {
|
|
118
119
|
formRef.current?.setValue("value", undefined);
|
|
119
120
|
}
|
|
121
|
+
if (field?.type === FIELD_TYPE.STRING) {
|
|
122
|
+
if (values?.operator === OPERATOR.IN) {
|
|
123
|
+
!isArray(values.value) && formRef.current?.setValue("value", []);
|
|
124
|
+
} else {
|
|
125
|
+
isArray(values.value) && formRef.current?.setValue("value", undefined);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (
|
|
129
|
+
field?.type === FIELD_TYPE.NUMBER ||
|
|
130
|
+
field?.type === FIELD_TYPE.DECIMAL
|
|
131
|
+
) {
|
|
132
|
+
if (values?.operator === OPERATOR.BETWEEN) {
|
|
133
|
+
!isArray(values.value) && formRef.current?.setValue("value", []);
|
|
134
|
+
} else {
|
|
135
|
+
isArray(values.value) && formRef.current?.setValue("value", undefined);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
120
138
|
if (
|
|
121
139
|
field?.type === FIELD_TYPE.BOOLEAN &&
|
|
122
140
|
values?.operator === OPERATOR.IS &&
|
|
@@ -124,9 +142,7 @@ export const FilterForm = ({
|
|
|
124
142
|
) {
|
|
125
143
|
formRef.current?.setValue("value", false);
|
|
126
144
|
}
|
|
127
|
-
}, [values, field]);
|
|
128
145
|
|
|
129
|
-
const valueInput = useMemo(() => {
|
|
130
146
|
if (field == null || !values?.operator) return null;
|
|
131
147
|
if (values?.operator === OPERATOR.EXISTS) return null;
|
|
132
148
|
if (field?.type === FIELD_TYPE.BOOLEAN) {
|
|
@@ -144,6 +160,7 @@ export const FilterForm = ({
|
|
|
144
160
|
<Controller name="value">
|
|
145
161
|
<Select
|
|
146
162
|
multiple
|
|
163
|
+
searchable
|
|
147
164
|
allowCreate
|
|
148
165
|
allowClear
|
|
149
166
|
options={field.values ?? []}
|
|
@@ -171,7 +188,7 @@ export const FilterForm = ({
|
|
|
171
188
|
<Controller name="value[0]">
|
|
172
189
|
<Number step={step} allowClear />
|
|
173
190
|
</Controller>
|
|
174
|
-
<span className="p-2 text-muted">{
|
|
191
|
+
<span className="p-2 text-muted">{`≷`}</span>
|
|
175
192
|
<Controller name="value[1]">
|
|
176
193
|
<Number step={step} allowClear />
|
|
177
194
|
</Controller>
|
|
@@ -211,70 +228,72 @@ export const FilterForm = ({
|
|
|
211
228
|
onChange={setValues}
|
|
212
229
|
onSubmit={handleSubmit}
|
|
213
230
|
>
|
|
214
|
-
<
|
|
215
|
-
<
|
|
216
|
-
<
|
|
217
|
-
<
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
<
|
|
230
|
-
|
|
231
|
-
<
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
<
|
|
236
|
-
<
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
<
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
<
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
231
|
+
<div className="w-[32rem]">
|
|
232
|
+
<Row>
|
|
233
|
+
<Col flex="fill">
|
|
234
|
+
<Controller name="field">
|
|
235
|
+
<Select<FilterField>
|
|
236
|
+
required
|
|
237
|
+
ref={inputRef}
|
|
238
|
+
label={t("label.field")}
|
|
239
|
+
options={fields}
|
|
240
|
+
labelProperty="label"
|
|
241
|
+
valueProperty="field"
|
|
242
|
+
groupProperty="type"
|
|
243
|
+
/>
|
|
244
|
+
</Controller>
|
|
245
|
+
</Col>
|
|
246
|
+
<Col flex="auto" className="text-center">
|
|
247
|
+
<label className="block py-0.5 text-sm">{t("label.exclude")}</label>
|
|
248
|
+
<Controller name="negate">
|
|
249
|
+
<Switch color="danger" />
|
|
250
|
+
</Controller>
|
|
251
|
+
</Col>
|
|
252
|
+
<Col flex="auto" className="basis-28">
|
|
253
|
+
<Controller name="operator">
|
|
254
|
+
<Select
|
|
255
|
+
label={t("label.operator")}
|
|
256
|
+
options={operators}
|
|
257
|
+
renderer={(v) => t(`operator.${v}`)}
|
|
258
|
+
/>
|
|
259
|
+
</Controller>
|
|
260
|
+
</Col>
|
|
261
|
+
</Row>
|
|
262
|
+
<br />
|
|
263
|
+
{valueInput}
|
|
264
|
+
<br />
|
|
265
|
+
<Controller name="label">
|
|
266
|
+
<Input
|
|
267
|
+
label={t("label.label")}
|
|
268
|
+
placeholder={t("label.label")}
|
|
269
|
+
decorateEnd={
|
|
270
|
+
!filter?.label && (
|
|
271
|
+
<span className="text-sm opacity-65 pe-4">Optional</span>
|
|
272
|
+
)
|
|
273
|
+
}
|
|
274
|
+
/>
|
|
275
|
+
</Controller>
|
|
276
|
+
<div className="flex pt-4 justify-end gap-1">
|
|
277
|
+
{onRemove && (
|
|
278
|
+
<div className="flex-1">
|
|
279
|
+
<Button
|
|
280
|
+
data-dropdown-dismiss="true"
|
|
281
|
+
variant="link"
|
|
282
|
+
size="sm"
|
|
283
|
+
color="danger"
|
|
284
|
+
onClick={onRemove}
|
|
285
|
+
>
|
|
286
|
+
{t("label.remove")}
|
|
287
|
+
</Button>
|
|
288
|
+
</div>
|
|
289
|
+
)}
|
|
290
|
+
<Button data-dropdown-dismiss="true" variant="link" size="sm">
|
|
291
|
+
{t("label.cancel")}
|
|
292
|
+
</Button>
|
|
293
|
+
<Button type="submit" variant="solid" size="sm">
|
|
294
|
+
{t("label.apply")}
|
|
295
|
+
</Button>
|
|
296
|
+
</div>
|
|
278
297
|
</div>
|
|
279
298
|
</Form>
|
|
280
299
|
);
|
|
@@ -68,7 +68,7 @@ export const FilterTag = ({
|
|
|
68
68
|
}, [filter]);
|
|
69
69
|
|
|
70
70
|
const color = useMemo(
|
|
71
|
-
() => (filter.negate ? excludedColor : includedColor),
|
|
71
|
+
() => filter.color ?? (filter.negate ? excludedColor : includedColor),
|
|
72
72
|
[filter, includedColor, excludedColor],
|
|
73
73
|
);
|
|
74
74
|
|
|
@@ -95,7 +95,7 @@ export const FilterTag = ({
|
|
|
95
95
|
>
|
|
96
96
|
<div
|
|
97
97
|
className={classNames(
|
|
98
|
-
"flex gap-1",
|
|
98
|
+
"flex gap-1 items-center",
|
|
99
99
|
filter.disabled && "line-through opacity-65",
|
|
100
100
|
)}
|
|
101
101
|
>
|
|
@@ -119,7 +119,12 @@ export const QueryForm = ({
|
|
|
119
119
|
>
|
|
120
120
|
{t("label.query")}
|
|
121
121
|
</label>
|
|
122
|
-
<div
|
|
122
|
+
<div
|
|
123
|
+
className="h-[24rem] w-[36rem] grid outline place-content-start"
|
|
124
|
+
style={{
|
|
125
|
+
gridTemplate: '"content" 1fr/1fr',
|
|
126
|
+
}}
|
|
127
|
+
>
|
|
123
128
|
<CodeEditor minimal required {...field} schema={querySchema} />
|
|
124
129
|
</div>
|
|
125
130
|
</div>
|
package/src/index.ts
CHANGED
|
@@ -23,10 +23,6 @@
|
|
|
23
23
|
|
|
24
24
|
import "./i18n";
|
|
25
25
|
|
|
26
|
+
export { FilterBar } from "./filterbar/FilterBar";
|
|
26
27
|
export { SearchBar } from "./searchbar/SearchBar";
|
|
27
|
-
export {
|
|
28
|
-
FIELD_TYPE,
|
|
29
|
-
OPERATOR,
|
|
30
|
-
type FilterObject,
|
|
31
|
-
type SearchObject,
|
|
32
|
-
} from "./types";
|
|
28
|
+
export { FIELD_TYPE, OPERATOR, type FilterObject } from "./types";
|
|
@@ -52,7 +52,7 @@ export const SearchBar = ({
|
|
|
52
52
|
append,
|
|
53
53
|
decorateEnd,
|
|
54
54
|
decorateStart,
|
|
55
|
-
|
|
55
|
+
children,
|
|
56
56
|
hideFilters,
|
|
57
57
|
defaultCollapsed = false,
|
|
58
58
|
disabled,
|
|
@@ -73,12 +73,15 @@ export const SearchBar = ({
|
|
|
73
73
|
const [collapsed, setCollapsed] = useState(defaultCollapsed);
|
|
74
74
|
const emptyValue = useMemo(() => (multiple ? EMPTY_ARRAY : ""), [multiple]);
|
|
75
75
|
|
|
76
|
-
const fireSearch = useDebounce(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
76
|
+
const fireSearch = useDebounce(
|
|
77
|
+
(query: AnyObject, filters: FilterObject[]) => {
|
|
78
|
+
onSearch?.({
|
|
79
|
+
query,
|
|
80
|
+
filters,
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
[],
|
|
84
|
+
);
|
|
82
85
|
|
|
83
86
|
const [state, dispatch] = useReducer(
|
|
84
87
|
(state: SearchState, action: SearchActions) => {
|
|
@@ -148,7 +151,7 @@ export const SearchBar = ({
|
|
|
148
151
|
{t(state.dirty ? "label.update" : "label.refresh")}
|
|
149
152
|
</Button>
|
|
150
153
|
</Field>
|
|
151
|
-
{
|
|
154
|
+
{children}
|
|
152
155
|
</div>
|
|
153
156
|
{!hideFilters && !collapsed && (
|
|
154
157
|
<FilterBar
|
package/src/types/index.ts
CHANGED
|
@@ -21,6 +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 { type ChildrenProp } from "@react-fabric/core/dist/types/types";
|
|
24
25
|
import { type ReactElement } from "react";
|
|
25
26
|
|
|
26
27
|
export enum FIELD_TYPE {
|
|
@@ -54,7 +55,7 @@ export enum OPERATOR {
|
|
|
54
55
|
* @internal
|
|
55
56
|
*/
|
|
56
57
|
export const TypeOperators: { [key in FIELD_TYPE]: OPERATOR[] } = {
|
|
57
|
-
[FIELD_TYPE.ID]: [OPERATOR.IS],
|
|
58
|
+
[FIELD_TYPE.ID]: [OPERATOR.IS, OPERATOR.IN],
|
|
58
59
|
[FIELD_TYPE.STRING]: [
|
|
59
60
|
OPERATOR.EXISTS,
|
|
60
61
|
OPERATOR.IS,
|
|
@@ -136,6 +137,7 @@ interface BaseFilter {
|
|
|
136
137
|
icon?: string;
|
|
137
138
|
label?: string;
|
|
138
139
|
group?: string;
|
|
140
|
+
color?: string;
|
|
139
141
|
value?: FilterValue;
|
|
140
142
|
pinned?: boolean;
|
|
141
143
|
negate?: boolean;
|
|
@@ -165,8 +167,8 @@ export type FilterObject = BaseFilter &
|
|
|
165
167
|
}
|
|
166
168
|
);
|
|
167
169
|
|
|
168
|
-
export interface SearchObject {
|
|
169
|
-
query?:
|
|
170
|
+
export interface SearchObject<T = string> {
|
|
171
|
+
query?: T;
|
|
170
172
|
filters: FilterObject[];
|
|
171
173
|
}
|
|
172
174
|
|
|
@@ -183,7 +185,7 @@ export interface FilterField {
|
|
|
183
185
|
onSearch?: (q: string) => Promise<FieldValue[]> | FieldValue[];
|
|
184
186
|
}
|
|
185
187
|
|
|
186
|
-
interface BaseSearchBarProps {
|
|
188
|
+
interface BaseSearchBarProps extends Partial<ChildrenProp> {
|
|
187
189
|
/**
|
|
188
190
|
* Query string
|
|
189
191
|
*/
|
|
@@ -214,11 +216,6 @@ interface BaseSearchBarProps {
|
|
|
214
216
|
*/
|
|
215
217
|
append?: ReactElement;
|
|
216
218
|
|
|
217
|
-
/**
|
|
218
|
-
* Additional actions menu
|
|
219
|
-
*/
|
|
220
|
-
actions?: ReactElement;
|
|
221
|
-
|
|
222
219
|
/**
|
|
223
220
|
* Hide filter bar
|
|
224
221
|
*/
|
|
@@ -247,12 +244,6 @@ interface BaseSearchBarProps {
|
|
|
247
244
|
* @param collapsed
|
|
248
245
|
*/
|
|
249
246
|
onCollapsed?: (collapsed: boolean) => void;
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* On search event
|
|
253
|
-
* @param queryObject
|
|
254
|
-
*/
|
|
255
|
-
onSearch?: (queryObject: SearchObject) => void;
|
|
256
247
|
/**
|
|
257
248
|
* On query string change event
|
|
258
249
|
* @param query
|
|
@@ -262,8 +253,26 @@ interface BaseSearchBarProps {
|
|
|
262
253
|
|
|
263
254
|
export type SearchBarProps = BaseSearchBarProps &
|
|
264
255
|
(
|
|
265
|
-
| {
|
|
266
|
-
|
|
256
|
+
| {
|
|
257
|
+
multiple: true;
|
|
258
|
+
query?: string[];
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* On search event
|
|
262
|
+
* @param queryObject
|
|
263
|
+
*/
|
|
264
|
+
onSearch?: (queryObject: SearchObject<string[]>) => void;
|
|
265
|
+
}
|
|
266
|
+
| {
|
|
267
|
+
multiple?: never | false;
|
|
268
|
+
query?: string;
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* On search event
|
|
272
|
+
* @param queryObject
|
|
273
|
+
*/
|
|
274
|
+
onSearch?: (queryObject: SearchObject) => void;
|
|
275
|
+
}
|
|
267
276
|
);
|
|
268
277
|
|
|
269
278
|
export interface FilterBarProps {
|