@react-fabric/searchbar 1.0.0-beta.7 → 1.0.0-beta.9
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 +8 -1
- package/dist/cjs/filterbar/FilterTag.js +1 -0
- package/dist/cjs/searchbar/SearchBar.js +15 -3
- package/dist/esm/filterbar/FilterForm.js +9 -2
- package/dist/esm/filterbar/FilterTag.js +1 -0
- package/dist/esm/searchbar/SearchBar.js +16 -4
- package/dist/types/types/index.d.ts +1 -1
- package/package.json +7 -7
- package/src/filterbar/FilterForm.tsx +6 -0
- package/src/filterbar/FilterTag.tsx +6 -1
- package/src/searchbar/SearchBar.tsx +9 -2
- package/src/types/index.ts +1 -1
|
@@ -15,6 +15,7 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
15
15
|
var FilterSchema = new utilities.yup.ObjectSchema({
|
|
16
16
|
id: utilities.yup.string().required(),
|
|
17
17
|
field: utilities.yup.string().required(),
|
|
18
|
+
type: utilities.yup.string().required().oneOf(Object.values(index.FIELD_TYPE)),
|
|
18
19
|
operator: utilities.yup.string().required().oneOf(Object.values(index.OPERATOR)),
|
|
19
20
|
negate: utilities.yup["boolean"](),
|
|
20
21
|
label: utilities.yup.string(),
|
|
@@ -62,6 +63,7 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
62
63
|
(_formRef$current2 = formRef.current) === null || _formRef$current2 === void 0 || _formRef$current2.setValues({
|
|
63
64
|
id: utilities.shortHash(),
|
|
64
65
|
field: "",
|
|
66
|
+
type: index.FIELD_TYPE.NONE,
|
|
65
67
|
operator: index.OPERATOR.EXISTS
|
|
66
68
|
});
|
|
67
69
|
}, [filter]);
|
|
@@ -185,6 +187,7 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
185
187
|
var filter = {
|
|
186
188
|
id: model.id,
|
|
187
189
|
field: model.field,
|
|
190
|
+
type: model.type,
|
|
188
191
|
negate: model.negate,
|
|
189
192
|
operator: model.operator,
|
|
190
193
|
value: model.value,
|
|
@@ -213,7 +216,11 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
213
216
|
options: fields,
|
|
214
217
|
labelProperty: "label",
|
|
215
218
|
valueProperty: "field",
|
|
216
|
-
groupProperty: "type"
|
|
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
|
+
}
|
|
217
224
|
})
|
|
218
225
|
})
|
|
219
226
|
}), /*#__PURE__*/jsxRuntime.jsxs(core.Col, {
|
|
@@ -81,6 +81,7 @@ var FilterTag = function FilterTag(_ref) {
|
|
|
81
81
|
children: /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
82
82
|
className: classNames("flex gap-1 items-center", filter.disabled && "line-through opacity-65"),
|
|
83
83
|
children: [filter.pinned && /*#__PURE__*/jsxRuntime.jsx(core.Icon, {
|
|
84
|
+
className: "flex-content",
|
|
84
85
|
icon: (_filter$icon = filter.icon) !== null && _filter$icon !== void 0 ? _filter$icon : core.CoreIcons.pin
|
|
85
86
|
}), label]
|
|
86
87
|
})
|
|
@@ -31,8 +31,8 @@ var SearchBar = function SearchBar(_ref) {
|
|
|
31
31
|
defaultCollapsed = _ref$defaultCollapsed === void 0 ? false : _ref$defaultCollapsed;
|
|
32
32
|
_ref.disabled;
|
|
33
33
|
_ref.onCollapsed;
|
|
34
|
-
|
|
35
|
-
onSearch = _ref.onSearch,
|
|
34
|
+
_ref.onQuery;
|
|
35
|
+
var onSearch = _ref.onSearch,
|
|
36
36
|
query = _ref.query,
|
|
37
37
|
multiple = _ref.multiple,
|
|
38
38
|
_ref$filters = _ref.filters,
|
|
@@ -58,6 +58,12 @@ var SearchBar = function SearchBar(_ref) {
|
|
|
58
58
|
});
|
|
59
59
|
}, []);
|
|
60
60
|
var _useReducer = react.useReducer(function (state, action) {
|
|
61
|
+
if (action.type === "reset") {
|
|
62
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
63
|
+
query: action.query,
|
|
64
|
+
filters: action.filters
|
|
65
|
+
});
|
|
66
|
+
}
|
|
61
67
|
if (action.type === "dirty") {
|
|
62
68
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
63
69
|
dirty: action.dirty
|
|
@@ -88,6 +94,13 @@ var SearchBar = function SearchBar(_ref) {
|
|
|
88
94
|
_useReducer2 = _slicedToArray(_useReducer, 2),
|
|
89
95
|
state = _useReducer2[0],
|
|
90
96
|
dispatch = _useReducer2[1];
|
|
97
|
+
react.useEffect(function () {
|
|
98
|
+
dispatch({
|
|
99
|
+
type: "reset",
|
|
100
|
+
filters: filters,
|
|
101
|
+
query: query
|
|
102
|
+
});
|
|
103
|
+
}, [filters, query]);
|
|
91
104
|
var updateHistory = function updateHistory(value) {
|
|
92
105
|
var historyEntry = utilities.isArray(value) ? value : [value];
|
|
93
106
|
setHistory(utilities.dedupe([].concat(_toConsumableArray(historyEntry), _toConsumableArray(history))).slice(0, historyCount));
|
|
@@ -131,7 +144,6 @@ var SearchBar = function SearchBar(_ref) {
|
|
|
131
144
|
});
|
|
132
145
|
},
|
|
133
146
|
onSelect: updateHistory,
|
|
134
|
-
onQuery: onQuery,
|
|
135
147
|
"data-testid": "searchbar-input",
|
|
136
148
|
onEnterPressed: function onEnterPressed() {
|
|
137
149
|
return fireSearch(state.query, state.filters);
|
|
@@ -8,13 +8,14 @@ import { Field, Controller, Switch, Select, Input, Number, Form } from '@react-f
|
|
|
8
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
|
-
import { OPERATOR, TypeOperators
|
|
11
|
+
import { FIELD_TYPE, OPERATOR, TypeOperators } from '../types/index.js';
|
|
12
12
|
import { useFilterContext } from './Context.js';
|
|
13
13
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
14
14
|
|
|
15
15
|
var FilterSchema = new yup.ObjectSchema({
|
|
16
16
|
id: yup.string().required(),
|
|
17
17
|
field: yup.string().required(),
|
|
18
|
+
type: yup.string().required().oneOf(Object.values(FIELD_TYPE)),
|
|
18
19
|
operator: yup.string().required().oneOf(Object.values(OPERATOR)),
|
|
19
20
|
negate: yup["boolean"](),
|
|
20
21
|
label: yup.string(),
|
|
@@ -62,6 +63,7 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
62
63
|
(_formRef$current2 = formRef.current) === null || _formRef$current2 === void 0 || _formRef$current2.setValues({
|
|
63
64
|
id: shortHash(),
|
|
64
65
|
field: "",
|
|
66
|
+
type: FIELD_TYPE.NONE,
|
|
65
67
|
operator: OPERATOR.EXISTS
|
|
66
68
|
});
|
|
67
69
|
}, [filter]);
|
|
@@ -185,6 +187,7 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
185
187
|
var filter = {
|
|
186
188
|
id: model.id,
|
|
187
189
|
field: model.field,
|
|
190
|
+
type: model.type,
|
|
188
191
|
negate: model.negate,
|
|
189
192
|
operator: model.operator,
|
|
190
193
|
value: model.value,
|
|
@@ -213,7 +216,11 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
213
216
|
options: fields,
|
|
214
217
|
labelProperty: "label",
|
|
215
218
|
valueProperty: "field",
|
|
216
|
-
groupProperty: "type"
|
|
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
|
+
}
|
|
217
224
|
})
|
|
218
225
|
})
|
|
219
226
|
}), /*#__PURE__*/jsxs(Col, {
|
|
@@ -81,6 +81,7 @@ var FilterTag = function FilterTag(_ref) {
|
|
|
81
81
|
children: /*#__PURE__*/jsxs("div", {
|
|
82
82
|
className: classNames("flex gap-1 items-center", filter.disabled && "line-through opacity-65"),
|
|
83
83
|
children: [filter.pinned && /*#__PURE__*/jsx(Icon, {
|
|
84
|
+
className: "flex-content",
|
|
84
85
|
icon: (_filter$icon = filter.icon) !== null && _filter$icon !== void 0 ? _filter$icon : CoreIcons.pin
|
|
85
86
|
}), label]
|
|
86
87
|
})
|
|
@@ -7,7 +7,7 @@ import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProper
|
|
|
7
7
|
import { useLocalStorage, useDebounce, Button } from '@react-fabric/core';
|
|
8
8
|
import { Field, AutoComplete } from '@react-fabric/form';
|
|
9
9
|
import { EMPTY_ARRAY, isArray, dedupe } from '@react-fabric/utilities';
|
|
10
|
-
import { useState, useMemo, useReducer } from 'react';
|
|
10
|
+
import { useState, useMemo, useReducer, useEffect } from 'react';
|
|
11
11
|
import { useTranslation } from 'react-i18next';
|
|
12
12
|
import { FilterBar } from '../filterbar/FilterBar.js';
|
|
13
13
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
@@ -31,8 +31,8 @@ var SearchBar = function SearchBar(_ref) {
|
|
|
31
31
|
defaultCollapsed = _ref$defaultCollapsed === void 0 ? false : _ref$defaultCollapsed;
|
|
32
32
|
_ref.disabled;
|
|
33
33
|
_ref.onCollapsed;
|
|
34
|
-
|
|
35
|
-
onSearch = _ref.onSearch,
|
|
34
|
+
_ref.onQuery;
|
|
35
|
+
var onSearch = _ref.onSearch,
|
|
36
36
|
query = _ref.query,
|
|
37
37
|
multiple = _ref.multiple,
|
|
38
38
|
_ref$filters = _ref.filters,
|
|
@@ -58,6 +58,12 @@ var SearchBar = function SearchBar(_ref) {
|
|
|
58
58
|
});
|
|
59
59
|
}, []);
|
|
60
60
|
var _useReducer = useReducer(function (state, action) {
|
|
61
|
+
if (action.type === "reset") {
|
|
62
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
63
|
+
query: action.query,
|
|
64
|
+
filters: action.filters
|
|
65
|
+
});
|
|
66
|
+
}
|
|
61
67
|
if (action.type === "dirty") {
|
|
62
68
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
63
69
|
dirty: action.dirty
|
|
@@ -88,6 +94,13 @@ var SearchBar = function SearchBar(_ref) {
|
|
|
88
94
|
_useReducer2 = _slicedToArray(_useReducer, 2),
|
|
89
95
|
state = _useReducer2[0],
|
|
90
96
|
dispatch = _useReducer2[1];
|
|
97
|
+
useEffect(function () {
|
|
98
|
+
dispatch({
|
|
99
|
+
type: "reset",
|
|
100
|
+
filters: filters,
|
|
101
|
+
query: query
|
|
102
|
+
});
|
|
103
|
+
}, [filters, query]);
|
|
91
104
|
var updateHistory = function updateHistory(value) {
|
|
92
105
|
var historyEntry = isArray(value) ? value : [value];
|
|
93
106
|
setHistory(dedupe([].concat(_toConsumableArray(historyEntry), _toConsumableArray(history))).slice(0, historyCount));
|
|
@@ -131,7 +144,6 @@ var SearchBar = function SearchBar(_ref) {
|
|
|
131
144
|
});
|
|
132
145
|
},
|
|
133
146
|
onSelect: updateHistory,
|
|
134
|
-
onQuery: onQuery,
|
|
135
147
|
"data-testid": "searchbar-input",
|
|
136
148
|
onEnterPressed: function onEnterPressed() {
|
|
137
149
|
return fireSearch(state.query, state.filters);
|
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.9",
|
|
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.9",
|
|
38
|
+
"@react-fabric/date": "^1.0.0-beta.9",
|
|
39
|
+
"@react-fabric/form": "^1.0.0-beta.9",
|
|
40
|
+
"@react-fabric/monaco": "^1.0.0-beta.9",
|
|
41
|
+
"@react-fabric/utilities": "^1.0.0-beta.9",
|
|
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": "3dde23444bcebf68c30198af5c2fef55572da38f"
|
|
56
56
|
}
|
|
@@ -48,6 +48,7 @@ import { useFilterContext } from "./Context";
|
|
|
48
48
|
const FilterSchema = new yup.ObjectSchema({
|
|
49
49
|
id: yup.string().required(),
|
|
50
50
|
field: yup.string().required(),
|
|
51
|
+
type: yup.string().required().oneOf(Object.values(FIELD_TYPE)),
|
|
51
52
|
operator: yup.string().required().oneOf(Object.values(OPERATOR)),
|
|
52
53
|
negate: yup.boolean(),
|
|
53
54
|
label: yup.string(),
|
|
@@ -93,6 +94,7 @@ export const FilterForm = ({
|
|
|
93
94
|
formRef.current?.setValues({
|
|
94
95
|
id: shortHash(),
|
|
95
96
|
field: "",
|
|
97
|
+
type: FIELD_TYPE.NONE,
|
|
96
98
|
operator: OPERATOR.EXISTS,
|
|
97
99
|
});
|
|
98
100
|
}, [filter]);
|
|
@@ -209,6 +211,7 @@ export const FilterForm = ({
|
|
|
209
211
|
const filter: FilterObject = {
|
|
210
212
|
id: model.id,
|
|
211
213
|
field: model.field,
|
|
214
|
+
type: model.type,
|
|
212
215
|
negate: model.negate,
|
|
213
216
|
operator: model.operator,
|
|
214
217
|
value: model.value as AnyObject,
|
|
@@ -240,6 +243,9 @@ export const FilterForm = ({
|
|
|
240
243
|
labelProperty="label"
|
|
241
244
|
valueProperty="field"
|
|
242
245
|
groupProperty="type"
|
|
246
|
+
onSelect={(field) =>
|
|
247
|
+
formRef.current?.setValue("type", field.type)
|
|
248
|
+
}
|
|
243
249
|
/>
|
|
244
250
|
</Controller>
|
|
245
251
|
</Col>
|
|
@@ -101,7 +101,12 @@ export const FilterTag = ({
|
|
|
101
101
|
filter.disabled && "line-through opacity-65",
|
|
102
102
|
)}
|
|
103
103
|
>
|
|
104
|
-
{filter.pinned &&
|
|
104
|
+
{filter.pinned && (
|
|
105
|
+
<Icon
|
|
106
|
+
className="flex-content"
|
|
107
|
+
icon={filter.icon ?? CoreIcons.pin}
|
|
108
|
+
/>
|
|
109
|
+
)}
|
|
105
110
|
{label}
|
|
106
111
|
</div>
|
|
107
112
|
</Chip>
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
import { Button, useDebounce, useLocalStorage } from "@react-fabric/core";
|
|
25
25
|
import { AutoComplete, Field } from "@react-fabric/form";
|
|
26
26
|
import { dedupe, EMPTY_ARRAY, isArray } from "@react-fabric/utilities";
|
|
27
|
-
import { useMemo, useReducer, useState } from "react";
|
|
27
|
+
import { useEffect, useMemo, useReducer, useState } from "react";
|
|
28
28
|
import { useTranslation } from "react-i18next";
|
|
29
29
|
import { FilterBar } from "../filterbar/FilterBar";
|
|
30
30
|
import {
|
|
@@ -40,6 +40,7 @@ interface SearchState {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
type SearchActions =
|
|
43
|
+
| { type: "reset"; query: string | string[]; filters: FilterObject[] }
|
|
43
44
|
| { type: "dirty"; dirty: boolean }
|
|
44
45
|
| { type: "query"; query: string | string[] }
|
|
45
46
|
| { type: "filter"; filters: FilterObject[] };
|
|
@@ -85,6 +86,9 @@ export const SearchBar = ({
|
|
|
85
86
|
|
|
86
87
|
const [state, dispatch] = useReducer(
|
|
87
88
|
(state: SearchState, action: SearchActions) => {
|
|
89
|
+
if (action.type === "reset") {
|
|
90
|
+
return { ...state, query: action.query, filters: action.filters };
|
|
91
|
+
}
|
|
88
92
|
if (action.type === "dirty") {
|
|
89
93
|
return { ...state, dirty: action.dirty };
|
|
90
94
|
}
|
|
@@ -105,6 +109,10 @@ export const SearchBar = ({
|
|
|
105
109
|
},
|
|
106
110
|
);
|
|
107
111
|
|
|
112
|
+
useEffect(() => {
|
|
113
|
+
dispatch({ type: "reset", filters, query });
|
|
114
|
+
}, [filters, query]);
|
|
115
|
+
|
|
108
116
|
const updateHistory = (value: string | string[]) => {
|
|
109
117
|
const historyEntry = isArray(value) ? value : [value];
|
|
110
118
|
setHistory(dedupe([...historyEntry, ...history]).slice(0, historyCount));
|
|
@@ -139,7 +147,6 @@ export const SearchBar = ({
|
|
|
139
147
|
decorateStart={decorateStart}
|
|
140
148
|
onInput={() => dispatch({ type: "dirty", dirty: true })}
|
|
141
149
|
onSelect={updateHistory}
|
|
142
|
-
onQuery={onQuery}
|
|
143
150
|
data-testid="searchbar-input"
|
|
144
151
|
onEnterPressed={() => fireSearch(state.query, state.filters)}
|
|
145
152
|
/>
|