@react-fabric/searchbar 1.0.0-beta.8 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/filterbar/Context.js +1 -1
- package/dist/cjs/filterbar/FilterBar.js +28 -23
- package/dist/cjs/filterbar/FilterEdit.js +7 -4
- package/dist/cjs/filterbar/FilterForm.js +176 -56
- package/dist/cjs/filterbar/FilterMenu.js +23 -12
- package/dist/cjs/filterbar/FilterTag.js +30 -20
- package/dist/cjs/filterbar/FilterView.js +11 -6
- package/dist/cjs/filterbar/QueryForm.js +47 -24
- package/dist/cjs/i18n/{ar.json.js → ar/searchbar.json.js} +43 -39
- package/dist/cjs/i18n/{en.json.js → en/searchbar.json.js} +43 -39
- package/dist/cjs/i18n/index.js +4 -4
- package/dist/cjs/index.js +28 -0
- package/dist/cjs/searchbar/SearchBar.js +58 -16
- package/dist/cjs/types/index.js +13 -4
- package/dist/esm/filterbar/Context.js +2 -2
- package/dist/esm/filterbar/FilterBar.js +30 -25
- package/dist/esm/filterbar/FilterEdit.js +7 -4
- package/dist/esm/filterbar/FilterForm.js +179 -59
- package/dist/esm/filterbar/FilterMenu.js +24 -13
- package/dist/esm/filterbar/FilterTag.js +32 -22
- package/dist/esm/filterbar/FilterView.js +11 -6
- package/dist/esm/filterbar/QueryForm.js +48 -25
- package/dist/esm/i18n/{ar.json.js → ar/searchbar.json.js} +43 -39
- package/dist/esm/i18n/{en.json.js → en/searchbar.json.js} +43 -39
- package/dist/esm/i18n/index.js +2 -2
- package/dist/esm/index.js +30 -0
- package/dist/esm/searchbar/SearchBar.js +59 -17
- package/dist/esm/types/index.js +13 -4
- package/dist/types/filterbar/Context.d.ts +2 -3
- package/dist/types/filterbar/FilterBar.d.ts +23 -1
- package/dist/types/filterbar/FilterEdit.d.ts +2 -2
- package/dist/types/filterbar/FilterForm.d.ts +3 -3
- package/dist/types/filterbar/FilterMenu.d.ts +3 -2
- package/dist/types/filterbar/FilterTag.d.ts +3 -2
- package/dist/types/filterbar/FilterView.d.ts +2 -2
- package/dist/types/filterbar/QueryForm.d.ts +2 -2
- package/dist/types/index.d.ts +27 -1
- package/dist/types/searchbar/SearchBar.d.ts +30 -1
- package/dist/types/types/index.d.ts +23 -14
- package/package.json +16 -19
- package/src/filterbar/Context.tsx +5 -5
- package/src/filterbar/FilterBar.tsx +58 -75
- package/src/filterbar/FilterEdit.tsx +9 -16
- package/src/filterbar/FilterForm.tsx +149 -85
- package/src/filterbar/FilterMenu.tsx +29 -16
- package/src/filterbar/FilterTag.tsx +30 -43
- package/src/filterbar/FilterView.tsx +13 -24
- package/src/filterbar/QueryForm.tsx +26 -43
- package/src/i18n/{ar.json → ar/searchbar.json} +43 -39
- package/src/i18n/{en.json → en/searchbar.json} +43 -39
- package/src/i18n/index.ts +2 -2
- package/src/index.ts +23 -18
- package/src/searchbar/SearchBar.tsx +67 -40
- package/src/types/index.ts +38 -70
|
@@ -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,8 +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(),
|
|
19
|
+
// type: yup.string().oneOf(Object.values(FIELD_TYPE)),
|
|
18
20
|
operator: utilities.yup.string().required().oneOf(Object.values(index.OPERATOR)),
|
|
19
|
-
negate: utilities.yup["boolean"](),
|
|
21
|
+
negate: utilities.yup["boolean"]().optional(),
|
|
20
22
|
label: utilities.yup.string(),
|
|
21
23
|
value: utilities.yup.mixed().when("operator", {
|
|
22
24
|
is: index.OPERATOR.EXISTS,
|
|
@@ -27,20 +29,56 @@ var FilterSchema = new utilities.yup.ObjectSchema({
|
|
|
27
29
|
return schema.required();
|
|
28
30
|
}
|
|
29
31
|
}).when("operator", {
|
|
30
|
-
is: index.OPERATOR.
|
|
32
|
+
is: index.OPERATOR.ANY,
|
|
31
33
|
then: function then(schema) {
|
|
32
34
|
return schema.test({
|
|
33
35
|
name: "array-check",
|
|
34
36
|
message: "${path} is a required field",
|
|
35
37
|
test: function test() {
|
|
36
38
|
var val = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
37
|
-
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];
|
|
38
76
|
}
|
|
39
77
|
});
|
|
40
78
|
}
|
|
41
79
|
})
|
|
42
80
|
});
|
|
43
|
-
|
|
81
|
+
function FilterForm(_ref) {
|
|
44
82
|
var filter = _ref.filter,
|
|
45
83
|
onChange = _ref.onChange,
|
|
46
84
|
onRemove = _ref.onRemove;
|
|
@@ -52,30 +90,41 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
52
90
|
fields = _useFilterContext$fie === void 0 ? [] : _useFilterContext$fie;
|
|
53
91
|
var inputRef = react$1.useRef(null);
|
|
54
92
|
var formRef = react$1.useRef(null);
|
|
55
|
-
var _useState = react$1.useState(
|
|
93
|
+
var _useState = react$1.useState(function () {
|
|
94
|
+
return filter;
|
|
95
|
+
}),
|
|
56
96
|
_useState2 = _slicedToArray(_useState, 2),
|
|
57
97
|
values = _useState2[0],
|
|
58
98
|
setValues = _useState2[1];
|
|
99
|
+
console.log(values);
|
|
59
100
|
react$1.useEffect(function () {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
+
}
|
|
67
112
|
}, [filter]);
|
|
68
113
|
react$1.useEffect(function () {
|
|
69
|
-
setTimeout(function () {
|
|
114
|
+
var tmr = setTimeout(function () {
|
|
70
115
|
var _inputRef$current;
|
|
71
116
|
(_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 || _inputRef$current.focus();
|
|
72
117
|
}, 100);
|
|
118
|
+
return function () {
|
|
119
|
+
clearTimeout(tmr);
|
|
120
|
+
};
|
|
73
121
|
}, []);
|
|
74
122
|
var field = react$1.useMemo(function () {
|
|
75
123
|
if (!(values !== null && values !== void 0 && values.field)) return undefined;
|
|
76
124
|
return fields.find(function (f) {
|
|
77
125
|
return f.field === (values === null || values === void 0 ? void 0 : values.field);
|
|
78
126
|
});
|
|
127
|
+
// eslint-disable-next-line @eslint-react/exhaustive-deps
|
|
79
128
|
}, [values]);
|
|
80
129
|
var operators = react$1.useMemo(function () {
|
|
81
130
|
var _formRef$current3;
|
|
@@ -89,24 +138,24 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
89
138
|
(_formRef$current4 = formRef.current) === null || _formRef$current4 === void 0 || _formRef$current4.setValue("value", undefined);
|
|
90
139
|
}
|
|
91
140
|
if ((field === null || field === void 0 ? void 0 : field.type) === index.FIELD_TYPE.STRING) {
|
|
92
|
-
if (
|
|
141
|
+
if (values !== null && values !== void 0 && values.operator && [index.OPERATOR.ALL, index.OPERATOR.ANY].includes(values.operator)) {
|
|
93
142
|
var _formRef$current5;
|
|
94
|
-
!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", []);
|
|
95
144
|
} else {
|
|
96
145
|
var _formRef$current6;
|
|
97
|
-
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);
|
|
98
147
|
}
|
|
99
148
|
}
|
|
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) {
|
|
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) {
|
|
101
150
|
if ((values === null || values === void 0 ? void 0 : values.operator) === index.OPERATOR.BETWEEN) {
|
|
102
151
|
var _formRef$current7;
|
|
103
|
-
!utilities.isArray(values.value)
|
|
152
|
+
if (!utilities.isArray(values.value)) (_formRef$current7 = formRef.current) === null || _formRef$current7 === void 0 || _formRef$current7.setValue("value", []);
|
|
104
153
|
} else {
|
|
105
154
|
var _formRef$current8;
|
|
106
|
-
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);
|
|
107
156
|
}
|
|
108
157
|
}
|
|
109
|
-
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) {
|
|
110
159
|
var _formRef$current9;
|
|
111
160
|
(_formRef$current9 = formRef.current) === null || _formRef$current9 === void 0 || _formRef$current9.setValue("value", false);
|
|
112
161
|
}
|
|
@@ -123,7 +172,8 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
123
172
|
});
|
|
124
173
|
}
|
|
125
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) {
|
|
126
|
-
|
|
175
|
+
var _field$values2;
|
|
176
|
+
if ([index.OPERATOR.ALL, index.OPERATOR.ANY].includes(values === null || values === void 0 ? void 0 : values.operator)) {
|
|
127
177
|
var _field$values;
|
|
128
178
|
return /*#__PURE__*/jsxRuntime.jsx(form.Controller, {
|
|
129
179
|
name: "value",
|
|
@@ -137,6 +187,19 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
137
187
|
onQuery: field.onSearch
|
|
138
188
|
})
|
|
139
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
|
+
});
|
|
140
203
|
} else {
|
|
141
204
|
return /*#__PURE__*/jsxRuntime.jsx(form.Controller, {
|
|
142
205
|
name: "value",
|
|
@@ -147,27 +210,40 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
147
210
|
});
|
|
148
211
|
}
|
|
149
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
|
+
}
|
|
150
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) {
|
|
151
224
|
var step = field.type === index.FIELD_TYPE.DECIMAL ? 0.1 : 1;
|
|
152
225
|
if ((values === null || values === void 0 ? void 0 : values.operator) === index.OPERATOR.BETWEEN) {
|
|
153
|
-
return /*#__PURE__*/jsxRuntime.
|
|
154
|
-
|
|
155
|
-
children:
|
|
156
|
-
|
|
157
|
-
children: /*#__PURE__*/jsxRuntime.jsx(form.
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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
|
+
})
|
|
171
247
|
});
|
|
172
248
|
} else {
|
|
173
249
|
return /*#__PURE__*/jsxRuntime.jsx(form.Controller, {
|
|
@@ -180,7 +256,43 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
180
256
|
});
|
|
181
257
|
}
|
|
182
258
|
}
|
|
183
|
-
|
|
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]);
|
|
184
296
|
var handleSubmit = react$1.useCallback(function (model) {
|
|
185
297
|
var filter = {
|
|
186
298
|
id: model.id,
|
|
@@ -188,19 +300,22 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
188
300
|
negate: model.negate,
|
|
189
301
|
operator: model.operator,
|
|
190
302
|
value: model.value,
|
|
191
|
-
label: model.label
|
|
303
|
+
label: model.label,
|
|
304
|
+
type: field === null || field === void 0 ? void 0 : field.type
|
|
192
305
|
};
|
|
193
306
|
onChange === null || onChange === void 0 || onChange(filter);
|
|
194
307
|
tree === null || tree === void 0 || tree.events.emit("close");
|
|
195
|
-
},
|
|
308
|
+
},
|
|
309
|
+
// eslint-disable-next-line @eslint-react/exhaustive-deps
|
|
310
|
+
[field, onChange]);
|
|
196
311
|
return /*#__PURE__*/jsxRuntime.jsx(form.Form, {
|
|
197
312
|
formRef: formRef,
|
|
198
|
-
|
|
313
|
+
resolver: yup.yupResolver(FilterSchema),
|
|
199
314
|
defaultValues: values,
|
|
200
315
|
onChange: setValues,
|
|
201
316
|
onSubmit: handleSubmit,
|
|
202
317
|
children: /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
203
|
-
className: "w-
|
|
318
|
+
className: "w-lg",
|
|
204
319
|
children: [/*#__PURE__*/jsxRuntime.jsxs(core.Row, {
|
|
205
320
|
children: [/*#__PURE__*/jsxRuntime.jsx(core.Col, {
|
|
206
321
|
flex: "fill",
|
|
@@ -208,6 +323,7 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
208
323
|
name: "field",
|
|
209
324
|
children: /*#__PURE__*/jsxRuntime.jsx(form.Select, {
|
|
210
325
|
required: true,
|
|
326
|
+
searchable: true,
|
|
211
327
|
ref: inputRef,
|
|
212
328
|
label: t("label.field"),
|
|
213
329
|
options: fields,
|
|
@@ -217,7 +333,7 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
217
333
|
})
|
|
218
334
|
})
|
|
219
335
|
}), /*#__PURE__*/jsxRuntime.jsxs(core.Col, {
|
|
220
|
-
flex: "
|
|
336
|
+
flex: "content",
|
|
221
337
|
className: "text-center",
|
|
222
338
|
children: [/*#__PURE__*/jsxRuntime.jsx("label", {
|
|
223
339
|
className: "block py-0.5 text-sm",
|
|
@@ -229,7 +345,7 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
229
345
|
})
|
|
230
346
|
})]
|
|
231
347
|
}), /*#__PURE__*/jsxRuntime.jsx(core.Col, {
|
|
232
|
-
flex: "
|
|
348
|
+
flex: "content",
|
|
233
349
|
className: "basis-28",
|
|
234
350
|
children: /*#__PURE__*/jsxRuntime.jsx(form.Controller, {
|
|
235
351
|
name: "operator",
|
|
@@ -253,22 +369,26 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
253
369
|
})
|
|
254
370
|
})
|
|
255
371
|
}), /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
256
|
-
className: "flex
|
|
372
|
+
className: "flex mt-4 justify-end gap-1 sticky bottom-1 bg-default",
|
|
257
373
|
children: [onRemove && /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
258
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, {
|
|
259
386
|
children: /*#__PURE__*/jsxRuntime.jsx(core.Button, {
|
|
260
387
|
"data-dropdown-dismiss": "true",
|
|
261
388
|
variant: "link",
|
|
262
389
|
size: "sm",
|
|
263
|
-
|
|
264
|
-
onClick: onRemove,
|
|
265
|
-
children: t("label.remove")
|
|
390
|
+
children: t("label.cancel")
|
|
266
391
|
})
|
|
267
|
-
}), /*#__PURE__*/jsxRuntime.jsx(core.Button, {
|
|
268
|
-
"data-dropdown-dismiss": "true",
|
|
269
|
-
variant: "link",
|
|
270
|
-
size: "sm",
|
|
271
|
-
children: t("label.cancel")
|
|
272
392
|
}), /*#__PURE__*/jsxRuntime.jsx(core.Button, {
|
|
273
393
|
type: "submit",
|
|
274
394
|
variant: "solid",
|
|
@@ -278,6 +398,6 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
278
398
|
})]
|
|
279
399
|
})
|
|
280
400
|
});
|
|
281
|
-
}
|
|
401
|
+
}
|
|
282
402
|
|
|
283
403
|
exports.FilterForm = FilterForm;
|