@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
|
@@ -27,7 +27,7 @@ var react = require('react');
|
|
|
27
27
|
|
|
28
28
|
var FilterContext = /*#__PURE__*/react.createContext({});
|
|
29
29
|
var useFilterContext = function useFilterContext() {
|
|
30
|
-
return react.
|
|
30
|
+
return react.use(FilterContext);
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
exports.FilterContext = FilterContext;
|
|
@@ -6,20 +6,21 @@ var core = require('@react-fabric/core');
|
|
|
6
6
|
var utilities = require('@react-fabric/utilities');
|
|
7
7
|
var react = require('react');
|
|
8
8
|
var reactI18next = require('react-i18next');
|
|
9
|
+
var Context = require('./Context.js');
|
|
9
10
|
var FilterEdit = require('./FilterEdit.js');
|
|
10
11
|
var FilterTag = require('./FilterTag.js');
|
|
11
|
-
var classNames = require('classnames');
|
|
12
|
-
var Context = require('./Context.js');
|
|
13
12
|
var jsxRuntime = require('react/jsx-runtime');
|
|
14
13
|
|
|
15
14
|
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; }
|
|
16
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t),
|
|
17
|
-
|
|
15
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).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; }
|
|
16
|
+
function FilterBar(_ref) {
|
|
18
17
|
var _ref$filters = _ref.filters,
|
|
19
18
|
filters = _ref$filters === void 0 ? [] : _ref$filters,
|
|
20
19
|
allowAdd = _ref.allowAdd,
|
|
21
20
|
fields = _ref.fields,
|
|
21
|
+
editable = _ref.editable,
|
|
22
22
|
querySchema = _ref.querySchema,
|
|
23
|
+
queryLanguage = _ref.queryLanguage,
|
|
23
24
|
defaultQuery = _ref.defaultQuery,
|
|
24
25
|
includedColor = _ref.includedColor,
|
|
25
26
|
excludedColor = _ref.excludedColor,
|
|
@@ -30,12 +31,12 @@ var FilterBar = function FilterBar(_ref) {
|
|
|
30
31
|
var list = _toConsumableArray(filters);
|
|
31
32
|
list.splice(index, 1);
|
|
32
33
|
onFilterChanged === null || onFilterChanged === void 0 || onFilterChanged(list);
|
|
33
|
-
}, [filters]);
|
|
34
|
+
}, [filters, onFilterChanged]);
|
|
34
35
|
var handleChange = react.useCallback(function (filter, index) {
|
|
35
36
|
var list = _toConsumableArray(filters);
|
|
36
|
-
utilities.isNil(index)
|
|
37
|
+
if (utilities.isNil(index)) list.push(filter);else list.splice(index, 1, filter);
|
|
37
38
|
onFilterChanged === null || onFilterChanged === void 0 || onFilterChanged(list);
|
|
38
|
-
}, [filters]);
|
|
39
|
+
}, [filters, onFilterChanged]);
|
|
39
40
|
var handleToggle = react.useCallback(function (type) {
|
|
40
41
|
var list = [];
|
|
41
42
|
if (type === "removeAll") {
|
|
@@ -48,14 +49,14 @@ var FilterBar = function FilterBar(_ref) {
|
|
|
48
49
|
if (type === "disableAll") filter.disabled = true;
|
|
49
50
|
if (type === "enableAll") filter.disabled = false;
|
|
50
51
|
if (type === "toggleDisable") filter.disabled = !filter.disabled;
|
|
51
|
-
if (type === "excludeAll") filter.negate = true;
|
|
52
|
-
if (type === "includeAll") filter.negate = false;
|
|
53
|
-
if (type === "invertAll") filter.negate = !filter.negate;
|
|
52
|
+
if (type === "excludeAll" && filter.field) filter.negate = true;
|
|
53
|
+
if (type === "includeAll" && filter.field) filter.negate = false;
|
|
54
|
+
if (type === "invertAll" && filter.field) filter.negate = !filter.negate;
|
|
54
55
|
return _objectSpread({}, filter);
|
|
55
56
|
})));
|
|
56
57
|
}
|
|
57
58
|
onFilterChanged === null || onFilterChanged === void 0 || onFilterChanged(list);
|
|
58
|
-
}, [filters]);
|
|
59
|
+
}, [filters, onFilterChanged]);
|
|
59
60
|
var menuItems = react.useMemo(function () {
|
|
60
61
|
var key = {
|
|
61
62
|
someDisabled: false,
|
|
@@ -67,16 +68,17 @@ var FilterBar = function FilterBar(_ref) {
|
|
|
67
68
|
filters.forEach(function (filter) {
|
|
68
69
|
if (filter.disabled && filter.canDisable !== false && !key.someDisabled) key.someDisabled = true;
|
|
69
70
|
if (!filter.disabled && filter.canDisable !== false && !key.someEnabled) key.someEnabled = true;
|
|
70
|
-
if (filter.negate && filter.canInvert !== false && !key.someExcluded) key.someExcluded = true;
|
|
71
|
-
if (!filter.negate && filter.canInvert !== false && !key.someIncluded) key.someIncluded = true;
|
|
71
|
+
if (filter.field && filter.negate && filter.canInvert !== false && !key.someExcluded) key.someExcluded = true;
|
|
72
|
+
if (filter.field && !filter.negate && filter.canInvert !== false && !key.someIncluded) key.someIncluded = true;
|
|
72
73
|
if (!filter.required && !key.canRemoveAll) key.canRemoveAll = true;
|
|
73
74
|
});
|
|
74
75
|
return key;
|
|
75
76
|
}, [filters]);
|
|
76
|
-
return /*#__PURE__*/jsxRuntime.jsx(Context.FilterContext
|
|
77
|
+
return /*#__PURE__*/jsxRuntime.jsx(Context.FilterContext, {
|
|
77
78
|
value: {
|
|
78
79
|
defaultQuery: defaultQuery,
|
|
79
80
|
querySchema: querySchema,
|
|
81
|
+
queryLanguage: queryLanguage,
|
|
80
82
|
fields: fields
|
|
81
83
|
},
|
|
82
84
|
children: /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
@@ -85,8 +87,8 @@ var FilterBar = function FilterBar(_ref) {
|
|
|
85
87
|
showArrow: true,
|
|
86
88
|
disabled: utilities.isEmpty(filters),
|
|
87
89
|
children: [/*#__PURE__*/jsxRuntime.jsx(core.Icon, {
|
|
88
|
-
icon:
|
|
89
|
-
className:
|
|
90
|
+
icon: "icon-[mdi--cog-outline]",
|
|
91
|
+
className: utilities.cn(utilities.isEmpty(filters) && "pointer-events-none opacity-30"),
|
|
90
92
|
color: !utilities.isEmpty(filters) ? "primary" : undefined
|
|
91
93
|
}), /*#__PURE__*/jsxRuntime.jsxs(core.Menu, {
|
|
92
94
|
className: "text-sm",
|
|
@@ -98,7 +100,7 @@ var FilterBar = function FilterBar(_ref) {
|
|
|
98
100
|
id: "disableAll",
|
|
99
101
|
label: t("label.disableAll")
|
|
100
102
|
}), /*#__PURE__*/jsxRuntime.jsx(core.MenuItem, {
|
|
101
|
-
icon:
|
|
103
|
+
icon: "icon-[mdi--checkbox-intermediate-variant]",
|
|
102
104
|
id: "toggleDisable",
|
|
103
105
|
label: t("label.toggleDisable")
|
|
104
106
|
}), /*#__PURE__*/jsxRuntime.jsx(core.Divider, {}), menuItems.someExcluded && /*#__PURE__*/jsxRuntime.jsx(core.MenuItem, {
|
|
@@ -109,19 +111,22 @@ var FilterBar = function FilterBar(_ref) {
|
|
|
109
111
|
label: t("label.excludeAll")
|
|
110
112
|
}), /*#__PURE__*/jsxRuntime.jsx(core.MenuItem, {
|
|
111
113
|
id: "invertAll",
|
|
112
|
-
icon:
|
|
114
|
+
icon: "icon-[mdi--set-left]",
|
|
113
115
|
label: t("label.invertAll")
|
|
114
116
|
}), /*#__PURE__*/jsxRuntime.jsx(core.Divider, {}), /*#__PURE__*/jsxRuntime.jsx(core.MenuItem, {
|
|
115
117
|
id: "removeAll",
|
|
116
118
|
color: "danger",
|
|
117
|
-
icon:
|
|
119
|
+
icon: "icon-[mdi--minus-circle-outline]",
|
|
118
120
|
label: t("label.removeAll"),
|
|
119
121
|
disabled: !menuItems.canRemoveAll
|
|
120
122
|
})]
|
|
121
123
|
})]
|
|
122
124
|
}), filters === null || filters === void 0 ? void 0 : filters.map(function (filter, idx) {
|
|
123
|
-
return /*#__PURE__*/jsxRuntime.jsx(FilterTag.FilterTag
|
|
125
|
+
return /*#__PURE__*/jsxRuntime.jsx(FilterTag.FilterTag
|
|
126
|
+
// eslint-disable-next-line @eslint-react/no-array-index-key
|
|
127
|
+
, {
|
|
124
128
|
filter: filter,
|
|
129
|
+
editable: editable,
|
|
125
130
|
includedColor: includedColor,
|
|
126
131
|
excludedColor: excludedColor,
|
|
127
132
|
onRemove: function onRemove() {
|
|
@@ -135,8 +140,8 @@ var FilterBar = function FilterBar(_ref) {
|
|
|
135
140
|
showArrow: true,
|
|
136
141
|
children: [/*#__PURE__*/jsxRuntime.jsx(core.Chip, {
|
|
137
142
|
size: "sm",
|
|
138
|
-
className: "
|
|
139
|
-
icon:
|
|
143
|
+
className: "outline-dashed! outline-tint-400!",
|
|
144
|
+
icon: "icon-[mdi--plus-circle-outline]",
|
|
140
145
|
children: t("label.add")
|
|
141
146
|
}), /*#__PURE__*/jsxRuntime.jsx(FilterEdit.FilterEdit, {
|
|
142
147
|
onChange: handleChange
|
|
@@ -144,6 +149,6 @@ var FilterBar = function FilterBar(_ref) {
|
|
|
144
149
|
})]
|
|
145
150
|
})
|
|
146
151
|
});
|
|
147
|
-
}
|
|
152
|
+
}
|
|
148
153
|
|
|
149
154
|
exports.FilterBar = FilterBar;
|
|
@@ -9,7 +9,7 @@ var FilterForm = require('./FilterForm.js');
|
|
|
9
9
|
var QueryForm = require('./QueryForm.js');
|
|
10
10
|
var jsxRuntime = require('react/jsx-runtime');
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
function FilterEdit(_ref) {
|
|
13
13
|
var filter = _ref.filter,
|
|
14
14
|
onRemove = _ref.onRemove,
|
|
15
15
|
onChange = _ref.onChange;
|
|
@@ -17,15 +17,18 @@ var FilterEdit = function FilterEdit(_ref) {
|
|
|
17
17
|
t = _useTranslation.t;
|
|
18
18
|
var _useFilterContext = Context.useFilterContext(),
|
|
19
19
|
fields = _useFilterContext.fields;
|
|
20
|
-
var _useState = react.useState(
|
|
20
|
+
var _useState = react.useState(function () {
|
|
21
|
+
return utilities.isEmpty(fields);
|
|
22
|
+
}),
|
|
21
23
|
_useState2 = _slicedToArray(_useState, 2),
|
|
22
24
|
queryEdit = _useState2[0],
|
|
23
25
|
setQueryEdit = _useState2[1];
|
|
24
26
|
react.useEffect(function () {
|
|
27
|
+
// eslint-disable-next-line @eslint-react/set-state-in-effect
|
|
25
28
|
setQueryEdit(!!filter && "query" in filter);
|
|
26
29
|
}, [filter]);
|
|
27
30
|
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
28
|
-
className: "px-2 py-1 bg-
|
|
31
|
+
className: "px-2 py-1 bg-default outline min-w-108 rounded-capped",
|
|
29
32
|
children: [!utilities.isEmpty(fields) && /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
30
33
|
className: "pb-4 flex justify-end",
|
|
31
34
|
children: /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
@@ -46,6 +49,6 @@ var FilterEdit = function FilterEdit(_ref) {
|
|
|
46
49
|
onChange: onChange
|
|
47
50
|
})]
|
|
48
51
|
});
|
|
49
|
-
}
|
|
52
|
+
}
|
|
50
53
|
|
|
51
54
|
exports.FilterEdit = FilterEdit;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
|
|
4
4
|
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
5
5
|
var react = require('@floating-ui/react');
|
|
6
|
+
var yup = require('@hookform/resolvers/yup');
|
|
6
7
|
var core = require('@react-fabric/core');
|
|
7
8
|
var form = require('@react-fabric/form');
|
|
8
9
|
var utilities = require('@react-fabric/utilities');
|
|
@@ -15,9 +16,9 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
15
16
|
var FilterSchema = new utilities.yup.ObjectSchema({
|
|
16
17
|
id: utilities.yup.string().required(),
|
|
17
18
|
field: utilities.yup.string().required(),
|
|
18
|
-
type:
|
|
19
|
+
// type: yup.string().oneOf(Object.values(FIELD_TYPE)),
|
|
19
20
|
operator: utilities.yup.string().required().oneOf(Object.values(index.OPERATOR)),
|
|
20
|
-
negate: utilities.yup["boolean"](),
|
|
21
|
+
negate: utilities.yup["boolean"]().optional(),
|
|
21
22
|
label: utilities.yup.string(),
|
|
22
23
|
value: utilities.yup.mixed().when("operator", {
|
|
23
24
|
is: index.OPERATOR.EXISTS,
|
|
@@ -28,20 +29,56 @@ var FilterSchema = new utilities.yup.ObjectSchema({
|
|
|
28
29
|
return schema.required();
|
|
29
30
|
}
|
|
30
31
|
}).when("operator", {
|
|
31
|
-
is: index.OPERATOR.
|
|
32
|
+
is: index.OPERATOR.ANY,
|
|
32
33
|
then: function then(schema) {
|
|
33
34
|
return schema.test({
|
|
34
35
|
name: "array-check",
|
|
35
36
|
message: "${path} is a required field",
|
|
36
37
|
test: function test() {
|
|
37
38
|
var val = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
38
|
-
return
|
|
39
|
+
return val.length > 0;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}).when("operator", {
|
|
44
|
+
is: index.OPERATOR.ALL,
|
|
45
|
+
then: function then(schema) {
|
|
46
|
+
return schema.test({
|
|
47
|
+
name: "array-check",
|
|
48
|
+
message: "${path} is a required field",
|
|
49
|
+
test: function test() {
|
|
50
|
+
var val = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
51
|
+
return val.length > 0;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}).when("operator", {
|
|
56
|
+
is: index.OPERATOR.BETWEEN,
|
|
57
|
+
then: function then(schema) {
|
|
58
|
+
return schema.test({
|
|
59
|
+
name: "array-check",
|
|
60
|
+
message: "${path} is a required field",
|
|
61
|
+
test: function test() {
|
|
62
|
+
var val = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
63
|
+
return val.length > 0 && utilities.isDefined(val[0]) && utilities.isDefined(val[1]);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}).when("operator", {
|
|
68
|
+
is: index.OPERATOR.BETWEEN,
|
|
69
|
+
then: function then(schema) {
|
|
70
|
+
return schema.test({
|
|
71
|
+
name: "array-check",
|
|
72
|
+
message: "${path} min max",
|
|
73
|
+
test: function test() {
|
|
74
|
+
var val = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
75
|
+
return val.length > 0 && val[0] < val[1];
|
|
39
76
|
}
|
|
40
77
|
});
|
|
41
78
|
}
|
|
42
79
|
})
|
|
43
80
|
});
|
|
44
|
-
|
|
81
|
+
function FilterForm(_ref) {
|
|
45
82
|
var filter = _ref.filter,
|
|
46
83
|
onChange = _ref.onChange,
|
|
47
84
|
onRemove = _ref.onRemove;
|
|
@@ -53,31 +90,41 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
53
90
|
fields = _useFilterContext$fie === void 0 ? [] : _useFilterContext$fie;
|
|
54
91
|
var inputRef = react$1.useRef(null);
|
|
55
92
|
var formRef = react$1.useRef(null);
|
|
56
|
-
var _useState = react$1.useState(
|
|
93
|
+
var _useState = react$1.useState(function () {
|
|
94
|
+
return filter;
|
|
95
|
+
}),
|
|
57
96
|
_useState2 = _slicedToArray(_useState, 2),
|
|
58
97
|
values = _useState2[0],
|
|
59
98
|
setValues = _useState2[1];
|
|
99
|
+
console.log(values);
|
|
60
100
|
react$1.useEffect(function () {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
101
|
+
if (filter && "field" in filter && filter.field) {
|
|
102
|
+
var _formRef$current;
|
|
103
|
+
(_formRef$current = formRef.current) === null || _formRef$current === void 0 || _formRef$current.setValues(filter);
|
|
104
|
+
} else {
|
|
105
|
+
var _formRef$current2;
|
|
106
|
+
(_formRef$current2 = formRef.current) === null || _formRef$current2 === void 0 || _formRef$current2.setValues({
|
|
107
|
+
id: utilities.shortHash(),
|
|
108
|
+
field: "",
|
|
109
|
+
operator: index.OPERATOR.EXISTS
|
|
110
|
+
});
|
|
111
|
+
}
|
|
69
112
|
}, [filter]);
|
|
70
113
|
react$1.useEffect(function () {
|
|
71
|
-
setTimeout(function () {
|
|
114
|
+
var tmr = setTimeout(function () {
|
|
72
115
|
var _inputRef$current;
|
|
73
116
|
(_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 || _inputRef$current.focus();
|
|
74
117
|
}, 100);
|
|
118
|
+
return function () {
|
|
119
|
+
clearTimeout(tmr);
|
|
120
|
+
};
|
|
75
121
|
}, []);
|
|
76
122
|
var field = react$1.useMemo(function () {
|
|
77
123
|
if (!(values !== null && values !== void 0 && values.field)) return undefined;
|
|
78
124
|
return fields.find(function (f) {
|
|
79
125
|
return f.field === (values === null || values === void 0 ? void 0 : values.field);
|
|
80
126
|
});
|
|
127
|
+
// eslint-disable-next-line @eslint-react/exhaustive-deps
|
|
81
128
|
}, [values]);
|
|
82
129
|
var operators = react$1.useMemo(function () {
|
|
83
130
|
var _formRef$current3;
|
|
@@ -91,24 +138,24 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
91
138
|
(_formRef$current4 = formRef.current) === null || _formRef$current4 === void 0 || _formRef$current4.setValue("value", undefined);
|
|
92
139
|
}
|
|
93
140
|
if ((field === null || field === void 0 ? void 0 : field.type) === index.FIELD_TYPE.STRING) {
|
|
94
|
-
if (
|
|
141
|
+
if (values !== null && values !== void 0 && values.operator && [index.OPERATOR.ALL, index.OPERATOR.ANY].includes(values.operator)) {
|
|
95
142
|
var _formRef$current5;
|
|
96
|
-
!utilities.isArray(values.value)
|
|
143
|
+
if (!utilities.isArray(values === null || values === void 0 ? void 0 : values.value)) (_formRef$current5 = formRef.current) === null || _formRef$current5 === void 0 || _formRef$current5.setValue("value", []);
|
|
97
144
|
} else {
|
|
98
145
|
var _formRef$current6;
|
|
99
|
-
utilities.isArray(values.value)
|
|
146
|
+
if (utilities.isArray(values === null || values === void 0 ? void 0 : values.value)) (_formRef$current6 = formRef.current) === null || _formRef$current6 === void 0 || _formRef$current6.setValue("value", undefined);
|
|
100
147
|
}
|
|
101
148
|
}
|
|
102
|
-
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) {
|
|
149
|
+
if ((field === null || field === void 0 ? void 0 : field.type) === index.FIELD_TYPE.DATE || (field === null || field === void 0 ? void 0 : field.type) === index.FIELD_TYPE.DATETIME || (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) {
|
|
103
150
|
if ((values === null || values === void 0 ? void 0 : values.operator) === index.OPERATOR.BETWEEN) {
|
|
104
151
|
var _formRef$current7;
|
|
105
|
-
!utilities.isArray(values.value)
|
|
152
|
+
if (!utilities.isArray(values.value)) (_formRef$current7 = formRef.current) === null || _formRef$current7 === void 0 || _formRef$current7.setValue("value", []);
|
|
106
153
|
} else {
|
|
107
154
|
var _formRef$current8;
|
|
108
|
-
utilities.isArray(values.value)
|
|
155
|
+
if (utilities.isArray(values === null || values === void 0 ? void 0 : values.value)) (_formRef$current8 = formRef.current) === null || _formRef$current8 === void 0 || _formRef$current8.setValue("value", undefined);
|
|
109
156
|
}
|
|
110
157
|
}
|
|
111
|
-
if ((field === null || field === void 0 ? void 0 : field.type) === index.FIELD_TYPE.BOOLEAN &&
|
|
158
|
+
if ((field === null || field === void 0 ? void 0 : field.type) === index.FIELD_TYPE.BOOLEAN && values !== null && values !== void 0 && values.operator && [index.OPERATOR.IS, index.OPERATOR.EQ].includes(values.operator) && (values === null || values === void 0 ? void 0 : values.value) === undefined) {
|
|
112
159
|
var _formRef$current9;
|
|
113
160
|
(_formRef$current9 = formRef.current) === null || _formRef$current9 === void 0 || _formRef$current9.setValue("value", false);
|
|
114
161
|
}
|
|
@@ -125,7 +172,8 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
125
172
|
});
|
|
126
173
|
}
|
|
127
174
|
if ((field === null || field === void 0 ? void 0 : field.type) === index.FIELD_TYPE.STRING || (field === null || field === void 0 ? void 0 : field.type) === index.FIELD_TYPE.ID) {
|
|
128
|
-
|
|
175
|
+
var _field$values2;
|
|
176
|
+
if ([index.OPERATOR.ALL, index.OPERATOR.ANY].includes(values === null || values === void 0 ? void 0 : values.operator)) {
|
|
129
177
|
var _field$values;
|
|
130
178
|
return /*#__PURE__*/jsxRuntime.jsx(form.Controller, {
|
|
131
179
|
name: "value",
|
|
@@ -139,6 +187,19 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
139
187
|
onQuery: field.onSearch
|
|
140
188
|
})
|
|
141
189
|
});
|
|
190
|
+
} else if (!!field.onSearch || (_field$values2 = field.values) !== null && _field$values2 !== void 0 && _field$values2.length) {
|
|
191
|
+
var _field$values3;
|
|
192
|
+
return /*#__PURE__*/jsxRuntime.jsx(form.Controller, {
|
|
193
|
+
name: "value",
|
|
194
|
+
children: /*#__PURE__*/jsxRuntime.jsx(form.Select, {
|
|
195
|
+
searchable: true,
|
|
196
|
+
allowCreate: true,
|
|
197
|
+
allowClear: true,
|
|
198
|
+
options: (_field$values3 = field.values) !== null && _field$values3 !== void 0 ? _field$values3 : [],
|
|
199
|
+
label: t("label.value"),
|
|
200
|
+
onQuery: field.onSearch
|
|
201
|
+
})
|
|
202
|
+
});
|
|
142
203
|
} else {
|
|
143
204
|
return /*#__PURE__*/jsxRuntime.jsx(form.Controller, {
|
|
144
205
|
name: "value",
|
|
@@ -149,27 +210,40 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
149
210
|
});
|
|
150
211
|
}
|
|
151
212
|
}
|
|
213
|
+
if (field.type === index.FIELD_TYPE.TEXT) {
|
|
214
|
+
return /*#__PURE__*/jsxRuntime.jsx(form.Controller, {
|
|
215
|
+
name: "value",
|
|
216
|
+
children: /*#__PURE__*/jsxRuntime.jsx(form.Textarea, {
|
|
217
|
+
rows: 3,
|
|
218
|
+
label: t("label.value"),
|
|
219
|
+
allowClear: true
|
|
220
|
+
})
|
|
221
|
+
});
|
|
222
|
+
}
|
|
152
223
|
if ((field === null || field === void 0 ? void 0 : field.type) === index.FIELD_TYPE.DECIMAL || (field === null || field === void 0 ? void 0 : field.type) === index.FIELD_TYPE.NUMBER) {
|
|
153
224
|
var step = field.type === index.FIELD_TYPE.DECIMAL ? 0.1 : 1;
|
|
154
225
|
if ((values === null || values === void 0 ? void 0 : values.operator) === index.OPERATOR.BETWEEN) {
|
|
155
|
-
return /*#__PURE__*/jsxRuntime.
|
|
156
|
-
|
|
157
|
-
children:
|
|
158
|
-
|
|
159
|
-
children: /*#__PURE__*/jsxRuntime.jsx(form.
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
226
|
+
return /*#__PURE__*/jsxRuntime.jsx(form.Controller, {
|
|
227
|
+
name: "value",
|
|
228
|
+
children: /*#__PURE__*/jsxRuntime.jsxs(form.Field, {
|
|
229
|
+
label: t("label.value"),
|
|
230
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(form.Controller, {
|
|
231
|
+
name: "value[0]",
|
|
232
|
+
children: /*#__PURE__*/jsxRuntime.jsx(form.Number, {
|
|
233
|
+
step: step,
|
|
234
|
+
allowClear: true
|
|
235
|
+
})
|
|
236
|
+
}), /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
237
|
+
className: "p-2 text-muted",
|
|
238
|
+
children: "\u2277"
|
|
239
|
+
}), /*#__PURE__*/jsxRuntime.jsx(form.Controller, {
|
|
240
|
+
name: "value[1]",
|
|
241
|
+
children: /*#__PURE__*/jsxRuntime.jsx(form.Number, {
|
|
242
|
+
step: step,
|
|
243
|
+
allowClear: true
|
|
244
|
+
})
|
|
245
|
+
})]
|
|
246
|
+
})
|
|
173
247
|
});
|
|
174
248
|
} else {
|
|
175
249
|
return /*#__PURE__*/jsxRuntime.jsx(form.Controller, {
|
|
@@ -182,28 +256,66 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
182
256
|
});
|
|
183
257
|
}
|
|
184
258
|
}
|
|
185
|
-
|
|
259
|
+
if ((field === null || field === void 0 ? void 0 : field.type) === index.FIELD_TYPE.DATE || (field === null || field === void 0 ? void 0 : field.type) === index.FIELD_TYPE.DATETIME) {
|
|
260
|
+
var type = field.type === index.FIELD_TYPE.DATETIME ? "datetime" : "date";
|
|
261
|
+
if ((values === null || values === void 0 ? void 0 : values.operator) === index.OPERATOR.BETWEEN) {
|
|
262
|
+
return /*#__PURE__*/jsxRuntime.jsx(form.Controller, {
|
|
263
|
+
name: "value",
|
|
264
|
+
children: /*#__PURE__*/jsxRuntime.jsxs(form.Field, {
|
|
265
|
+
label: t("label.value"),
|
|
266
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(form.Controller, {
|
|
267
|
+
name: "value[0]",
|
|
268
|
+
children: /*#__PURE__*/jsxRuntime.jsx(form.DateInput, {
|
|
269
|
+
type: type,
|
|
270
|
+
allowClear: true
|
|
271
|
+
})
|
|
272
|
+
}), /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
273
|
+
className: "p-2 text-muted",
|
|
274
|
+
children: "\u2277"
|
|
275
|
+
}), /*#__PURE__*/jsxRuntime.jsx(form.Controller, {
|
|
276
|
+
name: "value[1]",
|
|
277
|
+
children: /*#__PURE__*/jsxRuntime.jsx(form.DateInput, {
|
|
278
|
+
type: type,
|
|
279
|
+
allowClear: true
|
|
280
|
+
})
|
|
281
|
+
})]
|
|
282
|
+
})
|
|
283
|
+
});
|
|
284
|
+
} else {
|
|
285
|
+
return /*#__PURE__*/jsxRuntime.jsx(form.Controller, {
|
|
286
|
+
name: "value",
|
|
287
|
+
children: /*#__PURE__*/jsxRuntime.jsx(form.DateInput, {
|
|
288
|
+
type: type,
|
|
289
|
+
allowClear: true
|
|
290
|
+
})
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
// eslint-disable-next-line @eslint-react/exhaustive-deps
|
|
295
|
+
}, [field, values]);
|
|
186
296
|
var handleSubmit = react$1.useCallback(function (model) {
|
|
187
297
|
var filter = {
|
|
188
298
|
id: model.id,
|
|
189
299
|
field: model.field,
|
|
190
|
-
type: model.type,
|
|
191
300
|
negate: model.negate,
|
|
192
301
|
operator: model.operator,
|
|
193
302
|
value: model.value,
|
|
194
|
-
label: model.label
|
|
303
|
+
label: model.label,
|
|
304
|
+
type: field === null || field === void 0 ? void 0 : field.type
|
|
195
305
|
};
|
|
196
306
|
onChange === null || onChange === void 0 || onChange(filter);
|
|
197
307
|
tree === null || tree === void 0 || tree.events.emit("close");
|
|
198
|
-
},
|
|
308
|
+
},
|
|
309
|
+
// eslint-disable-next-line @eslint-react/exhaustive-deps
|
|
310
|
+
[field, onChange]);
|
|
199
311
|
return /*#__PURE__*/jsxRuntime.jsx(form.Form, {
|
|
200
312
|
formRef: formRef,
|
|
201
|
-
|
|
313
|
+
resolver: yup.yupResolver(FilterSchema),
|
|
202
314
|
defaultValues: values,
|
|
203
315
|
onChange: setValues,
|
|
204
316
|
onSubmit: handleSubmit,
|
|
205
317
|
children: /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
206
|
-
className: "w-
|
|
318
|
+
className: "w-lg",
|
|
207
319
|
children: [/*#__PURE__*/jsxRuntime.jsxs(core.Row, {
|
|
208
320
|
children: [/*#__PURE__*/jsxRuntime.jsx(core.Col, {
|
|
209
321
|
flex: "fill",
|
|
@@ -211,20 +323,17 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
211
323
|
name: "field",
|
|
212
324
|
children: /*#__PURE__*/jsxRuntime.jsx(form.Select, {
|
|
213
325
|
required: true,
|
|
326
|
+
searchable: true,
|
|
214
327
|
ref: inputRef,
|
|
215
328
|
label: t("label.field"),
|
|
216
329
|
options: fields,
|
|
217
330
|
labelProperty: "label",
|
|
218
331
|
valueProperty: "field",
|
|
219
|
-
groupProperty: "type"
|
|
220
|
-
onSelect: function onSelect(field) {
|
|
221
|
-
var _formRef$current10;
|
|
222
|
-
return (_formRef$current10 = formRef.current) === null || _formRef$current10 === void 0 ? void 0 : _formRef$current10.setValue("type", field.type);
|
|
223
|
-
}
|
|
332
|
+
groupProperty: "type"
|
|
224
333
|
})
|
|
225
334
|
})
|
|
226
335
|
}), /*#__PURE__*/jsxRuntime.jsxs(core.Col, {
|
|
227
|
-
flex: "
|
|
336
|
+
flex: "content",
|
|
228
337
|
className: "text-center",
|
|
229
338
|
children: [/*#__PURE__*/jsxRuntime.jsx("label", {
|
|
230
339
|
className: "block py-0.5 text-sm",
|
|
@@ -236,7 +345,7 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
236
345
|
})
|
|
237
346
|
})]
|
|
238
347
|
}), /*#__PURE__*/jsxRuntime.jsx(core.Col, {
|
|
239
|
-
flex: "
|
|
348
|
+
flex: "content",
|
|
240
349
|
className: "basis-28",
|
|
241
350
|
children: /*#__PURE__*/jsxRuntime.jsx(form.Controller, {
|
|
242
351
|
name: "operator",
|
|
@@ -260,22 +369,26 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
260
369
|
})
|
|
261
370
|
})
|
|
262
371
|
}), /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
263
|
-
className: "flex
|
|
372
|
+
className: "flex mt-4 justify-end gap-1 sticky bottom-1 bg-default",
|
|
264
373
|
children: [onRemove && /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
265
374
|
className: "flex-1",
|
|
375
|
+
children: /*#__PURE__*/jsxRuntime.jsx(core.DropdownDismiss, {
|
|
376
|
+
children: /*#__PURE__*/jsxRuntime.jsx(core.Button, {
|
|
377
|
+
"data-dropdown-dismiss": "true",
|
|
378
|
+
variant: "link",
|
|
379
|
+
size: "sm",
|
|
380
|
+
color: "danger",
|
|
381
|
+
onClick: onRemove,
|
|
382
|
+
children: t("label.remove")
|
|
383
|
+
})
|
|
384
|
+
})
|
|
385
|
+
}), /*#__PURE__*/jsxRuntime.jsx(core.DropdownDismiss, {
|
|
266
386
|
children: /*#__PURE__*/jsxRuntime.jsx(core.Button, {
|
|
267
387
|
"data-dropdown-dismiss": "true",
|
|
268
388
|
variant: "link",
|
|
269
389
|
size: "sm",
|
|
270
|
-
|
|
271
|
-
onClick: onRemove,
|
|
272
|
-
children: t("label.remove")
|
|
390
|
+
children: t("label.cancel")
|
|
273
391
|
})
|
|
274
|
-
}), /*#__PURE__*/jsxRuntime.jsx(core.Button, {
|
|
275
|
-
"data-dropdown-dismiss": "true",
|
|
276
|
-
variant: "link",
|
|
277
|
-
size: "sm",
|
|
278
|
-
children: t("label.cancel")
|
|
279
392
|
}), /*#__PURE__*/jsxRuntime.jsx(core.Button, {
|
|
280
393
|
type: "submit",
|
|
281
394
|
variant: "solid",
|
|
@@ -285,6 +398,6 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
285
398
|
})]
|
|
286
399
|
})
|
|
287
400
|
});
|
|
288
|
-
}
|
|
401
|
+
}
|
|
289
402
|
|
|
290
403
|
exports.FilterForm = FilterForm;
|