@react-fabric/searchbar 1.0.0-beta.47 → 1.0.0-beta.49
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/FilterBar.js +9 -5
- package/dist/cjs/filterbar/FilterForm.js +82 -20
- package/dist/cjs/filterbar/FilterMenu.js +4 -3
- package/dist/cjs/filterbar/FilterTag.js +5 -3
- package/dist/cjs/filterbar/QueryForm.js +3 -2
- package/dist/cjs/i18n/en.json.js +1 -0
- package/dist/cjs/searchbar/SearchBar.js +3 -1
- package/dist/cjs/types/index.js +8 -2
- package/dist/esm/filterbar/FilterBar.js +9 -5
- package/dist/esm/filterbar/FilterForm.js +83 -21
- package/dist/esm/filterbar/FilterMenu.js +4 -3
- package/dist/esm/filterbar/FilterTag.js +5 -3
- package/dist/esm/filterbar/QueryForm.js +3 -2
- package/dist/esm/i18n/en.json.js +1 -0
- package/dist/esm/searchbar/SearchBar.js +3 -1
- package/dist/esm/types/index.js +8 -2
- package/dist/types/filterbar/Context.d.ts +2 -2
- package/dist/types/filterbar/FilterBar.d.ts +1 -1
- package/dist/types/filterbar/FilterMenu.d.ts +2 -1
- package/dist/types/filterbar/FilterTag.d.ts +2 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/searchbar/SearchBar.d.ts +1 -1
- package/dist/types/types/index.d.ts +14 -6
- package/package.json +9 -9
- package/src/filterbar/Context.tsx +4 -1
- package/src/filterbar/FilterBar.tsx +22 -6
- package/src/filterbar/FilterForm.tsx +60 -10
- package/src/filterbar/FilterMenu.tsx +4 -2
- package/src/filterbar/FilterTag.tsx +12 -3
- package/src/filterbar/QueryForm.tsx +2 -2
- package/src/i18n/en.json +1 -0
- package/src/index.ts +6 -1
- package/src/searchbar/SearchBar.tsx +2 -0
- package/src/types/index.ts +42 -25
|
@@ -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", "children", "hideFilters", "defaultCollapsed", "disabled", "onCollapsed", "onQuery", "onSearch", "query", "multiple", "filters"];
|
|
15
|
+
var _excluded = ["historyKey", "historyCount", "defaultQueryList", "prepend", "append", "decorateEnd", "decorateStart", "children", "hideFilters", "defaultCollapsed", "disabled", "onCollapsed", "onQuery", "onSearch", "query", "ref", "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) {
|
|
@@ -34,6 +34,7 @@ var SearchBar = function SearchBar(_ref) {
|
|
|
34
34
|
_ref.onQuery;
|
|
35
35
|
var onSearch = _ref.onSearch,
|
|
36
36
|
query = _ref.query,
|
|
37
|
+
ref = _ref.ref,
|
|
37
38
|
multiple = _ref.multiple,
|
|
38
39
|
_ref$filters = _ref.filters,
|
|
39
40
|
filters = _ref$filters === void 0 ? EMPTY_ARRAY : _ref$filters,
|
|
@@ -137,6 +138,7 @@ var SearchBar = function SearchBar(_ref) {
|
|
|
137
138
|
}), prepend, /*#__PURE__*/jsx(AutoComplete, {
|
|
138
139
|
allowClear: true,
|
|
139
140
|
expandOnEdit: true,
|
|
141
|
+
ref: ref,
|
|
140
142
|
multiple: multiple,
|
|
141
143
|
history: history,
|
|
142
144
|
value: state.query,
|
package/dist/esm/types/index.js
CHANGED
|
@@ -32,6 +32,8 @@ var FIELD_TYPE = /*#__PURE__*/function (FIELD_TYPE) {
|
|
|
32
32
|
FIELD_TYPE["NUMBER"] = "NUMBER";
|
|
33
33
|
FIELD_TYPE["DECIMAL"] = "DECIMAL";
|
|
34
34
|
FIELD_TYPE["BOOLEAN"] = "BOOLEAN";
|
|
35
|
+
FIELD_TYPE["DATE"] = "DATE";
|
|
36
|
+
FIELD_TYPE["DATETIME"] = "DATETIME";
|
|
35
37
|
FIELD_TYPE["NONE"] = "NONE";
|
|
36
38
|
return FIELD_TYPE;
|
|
37
39
|
}({});
|
|
@@ -39,6 +41,7 @@ var OPERATOR = /*#__PURE__*/function (OPERATOR) {
|
|
|
39
41
|
OPERATOR["EXISTS"] = "EXISTS";
|
|
40
42
|
OPERATOR["IS"] = "IS";
|
|
41
43
|
OPERATOR["IN"] = "IN";
|
|
44
|
+
OPERATOR["EQ"] = "EQ";
|
|
42
45
|
OPERATOR["LT"] = "LT";
|
|
43
46
|
OPERATOR["GT"] = "GT";
|
|
44
47
|
OPERATOR["LTE"] = "LTE";
|
|
@@ -54,12 +57,15 @@ var OPERATOR = /*#__PURE__*/function (OPERATOR) {
|
|
|
54
57
|
/**
|
|
55
58
|
* @internal
|
|
56
59
|
*/
|
|
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.
|
|
60
|
+
var TypeOperators = _defineProperty(_defineProperty(_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.EQ, OPERATOR.BETWEEN, OPERATOR.LT, OPERATOR.GT, OPERATOR.LTE, OPERATOR.GTE]), FIELD_TYPE.DECIMAL, [OPERATOR.EXISTS, OPERATOR.EQ, OPERATOR.BETWEEN, OPERATOR.LT, OPERATOR.GT, OPERATOR.LTE, OPERATOR.GTE]), FIELD_TYPE.BOOLEAN, [OPERATOR.EXISTS, OPERATOR.EQ]), FIELD_TYPE.DATE, [OPERATOR.EXISTS, OPERATOR.EQ, OPERATOR.BETWEEN, OPERATOR.LT, OPERATOR.GT, OPERATOR.LTE, OPERATOR.GTE]), FIELD_TYPE.DATETIME, [OPERATOR.EXISTS, OPERATOR.EQ, OPERATOR.BETWEEN, OPERATOR.LT, OPERATOR.GT, OPERATOR.LTE, OPERATOR.GTE]), FIELD_TYPE.NONE, [OPERATOR.EXISTS]);
|
|
58
61
|
|
|
59
62
|
/**
|
|
60
63
|
* @internal
|
|
64
|
+
* 0 single value
|
|
65
|
+
* 1 many values
|
|
66
|
+
* 2 two values
|
|
61
67
|
*/
|
|
62
|
-
(_OperatorValueType = {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_OperatorValueType, OPERATOR.EXISTS, 0), OPERATOR.IS, 0), OPERATOR.IN, 1), OPERATOR.BETWEEN, 2), OPERATOR.WITHIN, 0), OPERATOR.STARTS, 0), OPERATOR.ENDS, 0), OPERATOR.INCLUDES, 0), OPERATOR.
|
|
68
|
+
(_OperatorValueType = {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_OperatorValueType, OPERATOR.EXISTS, 0), OPERATOR.IS, 0), OPERATOR.IN, 1), OPERATOR.BETWEEN, 2), OPERATOR.WITHIN, 0), OPERATOR.STARTS, 0), OPERATOR.ENDS, 0), OPERATOR.INCLUDES, 0), OPERATOR.EQ, 0), OPERATOR.LT, 0), _defineProperty(_defineProperty(_defineProperty(_OperatorValueType, OPERATOR.GT, 0), OPERATOR.LTE, 0), OPERATOR.GTE, 0));
|
|
63
69
|
|
|
64
70
|
/**
|
|
65
71
|
* @internal
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { type FilterBarProps } from "../types";
|
|
3
|
-
export declare const FilterContext: import("react").Context<Pick<FilterBarProps, "querySchema" | "defaultQuery" | "fields">>;
|
|
4
|
-
export declare const useFilterContext: () => Pick<FilterBarProps, "querySchema" | "defaultQuery" | "fields">;
|
|
3
|
+
export declare const FilterContext: import("react").Context<Pick<FilterBarProps, "querySchema" | "queryLanguage" | "defaultQuery" | "fields">>;
|
|
4
|
+
export declare const useFilterContext: () => Pick<FilterBarProps, "querySchema" | "queryLanguage" | "defaultQuery" | "fields">;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { type FilterBarProps } from "../types";
|
|
2
|
-
export declare const FilterBar: ({ filters, allowAdd, fields, querySchema, defaultQuery, includedColor, excludedColor, onFilterChanged, }: FilterBarProps) => import("react/jsx-runtime").JSX.Element;
|
|
2
|
+
export declare const FilterBar: ({ filters, allowAdd, fields, editable, querySchema, queryLanguage, defaultQuery, includedColor, excludedColor, onFilterChanged, }: FilterBarProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type FilterField, type FilterObject } from "../types";
|
|
2
|
-
export declare const FilterMenu: ({ filter, fields, onChange, onRemove, }: {
|
|
2
|
+
export declare const FilterMenu: ({ filter, fields, editable, onChange, onRemove, }: {
|
|
3
3
|
fields?: FilterField[];
|
|
4
|
+
editable?: boolean;
|
|
4
5
|
filter: FilterObject;
|
|
5
6
|
onRemove: () => void;
|
|
6
7
|
onChange: (filter: FilterObject) => void;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type FilterBarProps, type FilterObject } from "../types";
|
|
2
|
-
export declare const FilterTag: ({ filter, fields, includedColor, excludedColor, onChange, onRemove, }: {
|
|
2
|
+
export declare const FilterTag: ({ filter, fields, editable, includedColor, excludedColor, onChange, onRemove, }: {
|
|
3
3
|
filter: FilterObject;
|
|
4
|
+
editable?: boolean;
|
|
4
5
|
onRemove: () => void;
|
|
5
6
|
onChange: (filter: FilterObject) => void;
|
|
6
7
|
} & Pick<FilterBarProps, "fields" | "includedColor" | "excludedColor">) => import("react/jsx-runtime").JSX.Element;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import "./i18n";
|
|
2
2
|
export { FilterBar } from "./filterbar/FilterBar";
|
|
3
3
|
export { SearchBar } from "./searchbar/SearchBar";
|
|
4
|
-
export { FIELD_TYPE, OPERATOR, type FilterObject } from "./types";
|
|
4
|
+
export { FIELD_TYPE, OPERATOR, type FilterObject, type SearchObject, } 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, children, hideFilters, defaultCollapsed, disabled, onCollapsed, onQuery, onSearch, query, multiple, filters, ...filterProps }: SearchBarProps & Omit<FilterBarProps, "onFilterChanged">) => import("react/jsx-runtime").JSX.Element;
|
|
2
|
+
export declare const SearchBar: ({ historyKey, historyCount, defaultQueryList, prepend, append, decorateEnd, decorateStart, children, hideFilters, defaultCollapsed, disabled, onCollapsed, onQuery, onSearch, query, ref, multiple, filters, ...filterProps }: SearchBarProps & Omit<FilterBarProps, "onFilterChanged">) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ChildrenProp } from "@react-fabric/core/dist/types/types";
|
|
1
|
+
import { type ChildrenProp, type RefProp } from "@react-fabric/core/dist/types/types";
|
|
2
2
|
import { type ReactElement } from "react";
|
|
3
3
|
export declare enum FIELD_TYPE {
|
|
4
4
|
ID = "ID",
|
|
@@ -6,12 +6,15 @@ export declare enum FIELD_TYPE {
|
|
|
6
6
|
NUMBER = "NUMBER",
|
|
7
7
|
DECIMAL = "DECIMAL",
|
|
8
8
|
BOOLEAN = "BOOLEAN",
|
|
9
|
+
DATE = "DATE",
|
|
10
|
+
DATETIME = "DATETIME",
|
|
9
11
|
NONE = "NONE"
|
|
10
12
|
}
|
|
11
13
|
export declare enum OPERATOR {
|
|
12
14
|
EXISTS = "EXISTS",
|
|
13
15
|
IS = "IS",
|
|
14
16
|
IN = "IN",
|
|
17
|
+
EQ = "EQ",
|
|
15
18
|
LT = "LT",
|
|
16
19
|
GT = "GT",
|
|
17
20
|
LTE = "LTE",
|
|
@@ -30,6 +33,9 @@ export declare const TypeOperators: {
|
|
|
30
33
|
};
|
|
31
34
|
/**
|
|
32
35
|
* @internal
|
|
36
|
+
* 0 single value
|
|
37
|
+
* 1 many values
|
|
38
|
+
* 2 two values
|
|
33
39
|
*/
|
|
34
40
|
export declare const OperatorValueType: {
|
|
35
41
|
[key in OPERATOR]: 0 | 1 | 2;
|
|
@@ -46,23 +52,24 @@ interface BaseFilter {
|
|
|
46
52
|
color?: string;
|
|
47
53
|
value?: FilterValue;
|
|
48
54
|
pinned?: boolean;
|
|
49
|
-
negate?: boolean;
|
|
50
55
|
disabled?: boolean;
|
|
51
56
|
required?: boolean;
|
|
52
57
|
canPin?: boolean;
|
|
53
58
|
canEdit?: boolean;
|
|
54
|
-
canInvert?: boolean;
|
|
55
59
|
canDisable?: boolean;
|
|
56
60
|
}
|
|
57
61
|
export type FilterObject = BaseFilter & ({
|
|
58
62
|
field: string;
|
|
59
63
|
operator: OPERATOR;
|
|
60
64
|
value?: FilterValue;
|
|
65
|
+
negate?: boolean;
|
|
66
|
+
canInvert?: boolean;
|
|
61
67
|
query?: never;
|
|
62
68
|
} | {
|
|
63
69
|
field?: never;
|
|
64
70
|
operator?: never;
|
|
65
71
|
label: string;
|
|
72
|
+
canInvert?: false;
|
|
66
73
|
query: string;
|
|
67
74
|
});
|
|
68
75
|
export interface SearchObject<T = string> {
|
|
@@ -82,7 +89,7 @@ export interface FilterField {
|
|
|
82
89
|
defaultOperator?: OPERATOR;
|
|
83
90
|
onSearch?: (q: string) => Promise<FieldValue[]> | FieldValue[];
|
|
84
91
|
}
|
|
85
|
-
interface BaseSearchBarProps extends Partial<ChildrenProp> {
|
|
92
|
+
interface BaseSearchBarProps extends Partial<ChildrenProp>, RefProp<HTMLInputElement> {
|
|
86
93
|
/**
|
|
87
94
|
* Query string
|
|
88
95
|
*/
|
|
@@ -172,11 +179,11 @@ export interface FilterBarProps {
|
|
|
172
179
|
/**
|
|
173
180
|
* Editable filters
|
|
174
181
|
*/
|
|
175
|
-
|
|
182
|
+
editable?: boolean;
|
|
176
183
|
/**
|
|
177
184
|
* Disable component
|
|
178
185
|
*/
|
|
179
|
-
|
|
186
|
+
disabled?: boolean;
|
|
180
187
|
/**
|
|
181
188
|
* Message for empty field list
|
|
182
189
|
*/
|
|
@@ -190,6 +197,7 @@ export interface FilterBarProps {
|
|
|
190
197
|
*/
|
|
191
198
|
excludedColor?: string;
|
|
192
199
|
allowAdd?: boolean;
|
|
200
|
+
queryLanguage?: "text" | "json";
|
|
193
201
|
querySchema?: Array<{
|
|
194
202
|
uri: string;
|
|
195
203
|
schema: KeyValue;
|
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.49",
|
|
4
4
|
"description": "RUF: Searchbar with filters package",
|
|
5
5
|
"author": "Adarsh Pastakia <adarshpastakia@outlook.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,13 +33,13 @@
|
|
|
33
33
|
"watch": "npm-run-all -p watch:rollup watch:dts"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@floating-ui/react": "^0.
|
|
37
|
-
"@react-fabric/core": "^1.0.0-beta.
|
|
38
|
-
"@react-fabric/form": "^1.0.0-beta.
|
|
39
|
-
"@react-fabric/monaco": "^1.0.0-beta.
|
|
40
|
-
"@react-fabric/utilities": "^1.0.0-beta.
|
|
36
|
+
"@floating-ui/react": "^0.27.9",
|
|
37
|
+
"@react-fabric/core": "^1.0.0-beta.49",
|
|
38
|
+
"@react-fabric/form": "^1.0.0-beta.49",
|
|
39
|
+
"@react-fabric/monaco": "^1.0.0-beta.49",
|
|
40
|
+
"@react-fabric/utilities": "^1.0.0-beta.49",
|
|
41
41
|
"classnames": "^2.5.1",
|
|
42
|
-
"react-hook-form": "^7.
|
|
42
|
+
"react-hook-form": "^7.56.4"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"i18next": "^23.15.1",
|
|
@@ -48,11 +48,11 @@
|
|
|
48
48
|
"react-i18next": "^15.0.2"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@react-fabric/superdate": "^1.0.0-beta.
|
|
51
|
+
"@react-fabric/superdate": "^1.0.0-beta.49"
|
|
52
52
|
},
|
|
53
53
|
"engines": {
|
|
54
54
|
"node": ">=18.12.0",
|
|
55
55
|
"npm": ">=8.19.0"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "29b3ed65e9f9687d738dd7c6facdb9fedafb4219"
|
|
58
58
|
}
|
|
@@ -25,7 +25,10 @@ import { createContext, useContext } from "react";
|
|
|
25
25
|
import { type FilterBarProps } from "../types";
|
|
26
26
|
|
|
27
27
|
export const FilterContext = createContext<
|
|
28
|
-
Pick<
|
|
28
|
+
Pick<
|
|
29
|
+
FilterBarProps,
|
|
30
|
+
"querySchema" | "queryLanguage" | "defaultQuery" | "fields"
|
|
31
|
+
>
|
|
29
32
|
>({});
|
|
30
33
|
|
|
31
34
|
export const useFilterContext = () => useContext(FilterContext);
|
|
@@ -43,7 +43,9 @@ export const FilterBar = ({
|
|
|
43
43
|
filters = [],
|
|
44
44
|
allowAdd,
|
|
45
45
|
fields,
|
|
46
|
+
editable,
|
|
46
47
|
querySchema,
|
|
48
|
+
queryLanguage,
|
|
47
49
|
defaultQuery,
|
|
48
50
|
includedColor,
|
|
49
51
|
excludedColor,
|
|
@@ -88,9 +90,10 @@ export const FilterBar = ({
|
|
|
88
90
|
if (type === "disableAll") filter.disabled = true;
|
|
89
91
|
if (type === "enableAll") filter.disabled = false;
|
|
90
92
|
if (type === "toggleDisable") filter.disabled = !filter.disabled;
|
|
91
|
-
if (type === "excludeAll") filter.negate = true;
|
|
92
|
-
if (type === "includeAll") filter.negate = false;
|
|
93
|
-
if (type === "invertAll"
|
|
93
|
+
if (type === "excludeAll" && filter.field) filter.negate = true;
|
|
94
|
+
if (type === "includeAll" && filter.field) filter.negate = false;
|
|
95
|
+
if (type === "invertAll" && filter.field)
|
|
96
|
+
filter.negate = !filter.negate;
|
|
94
97
|
return { ...filter };
|
|
95
98
|
}),
|
|
96
99
|
);
|
|
@@ -113,9 +116,19 @@ export const FilterBar = ({
|
|
|
113
116
|
key.someDisabled = true;
|
|
114
117
|
if (!filter.disabled && filter.canDisable !== false && !key.someEnabled)
|
|
115
118
|
key.someEnabled = true;
|
|
116
|
-
if (
|
|
119
|
+
if (
|
|
120
|
+
filter.field &&
|
|
121
|
+
filter.negate &&
|
|
122
|
+
filter.canInvert !== false &&
|
|
123
|
+
!key.someExcluded
|
|
124
|
+
)
|
|
117
125
|
key.someExcluded = true;
|
|
118
|
-
if (
|
|
126
|
+
if (
|
|
127
|
+
filter.field &&
|
|
128
|
+
!filter.negate &&
|
|
129
|
+
filter.canInvert !== false &&
|
|
130
|
+
!key.someIncluded
|
|
131
|
+
)
|
|
119
132
|
key.someIncluded = true;
|
|
120
133
|
if (!filter.required && !key.canRemoveAll) key.canRemoveAll = true;
|
|
121
134
|
});
|
|
@@ -123,7 +136,9 @@ export const FilterBar = ({
|
|
|
123
136
|
}, [filters]);
|
|
124
137
|
|
|
125
138
|
return (
|
|
126
|
-
<FilterContext.Provider
|
|
139
|
+
<FilterContext.Provider
|
|
140
|
+
value={{ defaultQuery, querySchema, queryLanguage, fields }}
|
|
141
|
+
>
|
|
127
142
|
<div className="flex flex-wrap gap-1 items-center">
|
|
128
143
|
<Dropdown showArrow disabled={isEmpty(filters)}>
|
|
129
144
|
<Icon
|
|
@@ -171,6 +186,7 @@ export const FilterBar = ({
|
|
|
171
186
|
<FilterTag
|
|
172
187
|
key={idx}
|
|
173
188
|
filter={filter}
|
|
189
|
+
editable={editable}
|
|
174
190
|
includedColor={includedColor}
|
|
175
191
|
excludedColor={excludedColor}
|
|
176
192
|
onRemove={() => handleRemove(idx)}
|
|
@@ -25,6 +25,7 @@ import { useFloatingTree } from "@floating-ui/react";
|
|
|
25
25
|
import { Button, Col, Row } from "@react-fabric/core";
|
|
26
26
|
import {
|
|
27
27
|
Controller,
|
|
28
|
+
DateInput,
|
|
28
29
|
Field,
|
|
29
30
|
Form,
|
|
30
31
|
Input,
|
|
@@ -67,6 +68,24 @@ const FilterSchema = new yup.ObjectSchema({
|
|
|
67
68
|
message: `\${path} is a required field`,
|
|
68
69
|
test: (val: AnyObject = []) => val?.length > 0,
|
|
69
70
|
}),
|
|
71
|
+
})
|
|
72
|
+
.when("operator", {
|
|
73
|
+
is: OPERATOR.BETWEEN,
|
|
74
|
+
then: (schema) =>
|
|
75
|
+
schema.test({
|
|
76
|
+
name: "array-check",
|
|
77
|
+
message: `\${path} is a required field`,
|
|
78
|
+
test: (val: AnyObject = []) => val?.length > 0 && val[0] && val[1],
|
|
79
|
+
}),
|
|
80
|
+
})
|
|
81
|
+
.when("operator", {
|
|
82
|
+
is: OPERATOR.BETWEEN,
|
|
83
|
+
then: (schema) =>
|
|
84
|
+
schema.test({
|
|
85
|
+
name: "array-check",
|
|
86
|
+
message: `\${path} min max`,
|
|
87
|
+
test: (val: AnyObject = []) => val?.length > 0 && val[0] < val[1],
|
|
88
|
+
}),
|
|
70
89
|
}),
|
|
71
90
|
});
|
|
72
91
|
|
|
@@ -129,6 +148,8 @@ export const FilterForm = ({
|
|
|
129
148
|
}
|
|
130
149
|
}
|
|
131
150
|
if (
|
|
151
|
+
field?.type === FIELD_TYPE.DATE ||
|
|
152
|
+
field?.type === FIELD_TYPE.DATETIME ||
|
|
132
153
|
field?.type === FIELD_TYPE.NUMBER ||
|
|
133
154
|
field?.type === FIELD_TYPE.DECIMAL
|
|
134
155
|
) {
|
|
@@ -140,7 +161,7 @@ export const FilterForm = ({
|
|
|
140
161
|
}
|
|
141
162
|
if (
|
|
142
163
|
field?.type === FIELD_TYPE.BOOLEAN &&
|
|
143
|
-
values?.operator
|
|
164
|
+
[OPERATOR.IS, OPERATOR.EQ].includes(values?.operator) &&
|
|
144
165
|
values?.value === undefined
|
|
145
166
|
) {
|
|
146
167
|
formRef.current?.setValue("value", false);
|
|
@@ -200,15 +221,17 @@ export const FilterForm = ({
|
|
|
200
221
|
const step = field.type === FIELD_TYPE.DECIMAL ? 0.1 : 1;
|
|
201
222
|
if (values?.operator === OPERATOR.BETWEEN) {
|
|
202
223
|
return (
|
|
203
|
-
<
|
|
204
|
-
<
|
|
205
|
-
<
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
<
|
|
210
|
-
|
|
211
|
-
|
|
224
|
+
<Controller name="value">
|
|
225
|
+
<Field label={t("label.value")}>
|
|
226
|
+
<Controller name="value[0]">
|
|
227
|
+
<Number step={step} allowClear />
|
|
228
|
+
</Controller>
|
|
229
|
+
<span className="p-2 text-muted">{`≷`}</span>
|
|
230
|
+
<Controller name="value[1]">
|
|
231
|
+
<Number step={step} allowClear />
|
|
232
|
+
</Controller>
|
|
233
|
+
</Field>
|
|
234
|
+
</Controller>
|
|
212
235
|
);
|
|
213
236
|
} else {
|
|
214
237
|
return (
|
|
@@ -218,6 +241,33 @@ export const FilterForm = ({
|
|
|
218
241
|
);
|
|
219
242
|
}
|
|
220
243
|
}
|
|
244
|
+
if (
|
|
245
|
+
field?.type === FIELD_TYPE.DATE ||
|
|
246
|
+
field?.type === FIELD_TYPE.DATETIME
|
|
247
|
+
) {
|
|
248
|
+
const type = field.type === FIELD_TYPE.DATETIME ? "datetime" : "date";
|
|
249
|
+
if (values?.operator === OPERATOR.BETWEEN) {
|
|
250
|
+
return (
|
|
251
|
+
<Controller name="value">
|
|
252
|
+
<Field label={t("label.value")}>
|
|
253
|
+
<Controller name="value[0]">
|
|
254
|
+
<DateInput type={type} allowClear />
|
|
255
|
+
</Controller>
|
|
256
|
+
<span className="p-2 text-muted">{`≷`}</span>
|
|
257
|
+
<Controller name="value[1]">
|
|
258
|
+
<DateInput type={type} allowClear />
|
|
259
|
+
</Controller>
|
|
260
|
+
</Field>
|
|
261
|
+
</Controller>
|
|
262
|
+
);
|
|
263
|
+
} else {
|
|
264
|
+
return (
|
|
265
|
+
<Controller name="value">
|
|
266
|
+
<DateInput type={type} allowClear />
|
|
267
|
+
</Controller>
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
221
271
|
}, [field, values?.operator]);
|
|
222
272
|
|
|
223
273
|
const handleSubmit = useCallback(
|
|
@@ -31,10 +31,12 @@ import { FilterView } from "./FilterView";
|
|
|
31
31
|
export const FilterMenu = ({
|
|
32
32
|
filter,
|
|
33
33
|
fields,
|
|
34
|
+
editable,
|
|
34
35
|
onChange,
|
|
35
36
|
onRemove,
|
|
36
37
|
}: {
|
|
37
38
|
fields?: FilterField[];
|
|
39
|
+
editable?: boolean;
|
|
38
40
|
filter: FilterObject;
|
|
39
41
|
onRemove: () => void;
|
|
40
42
|
onChange: (filter: FilterObject) => void;
|
|
@@ -48,7 +50,7 @@ export const FilterMenu = ({
|
|
|
48
50
|
<FilterView filter={filter} onRemove={onRemove} />
|
|
49
51
|
) : (
|
|
50
52
|
<Menu className="text-sm">
|
|
51
|
-
{filter.canEdit !== false ? (
|
|
53
|
+
{editable && filter.canEdit !== false ? (
|
|
52
54
|
<MenuItem
|
|
53
55
|
icon={CoreIcons.edit}
|
|
54
56
|
label={t("label.edit")}
|
|
@@ -74,7 +76,7 @@ export const FilterMenu = ({
|
|
|
74
76
|
onClick={() => onChange({ ...filter, pinned: !filter.pinned })}
|
|
75
77
|
/>
|
|
76
78
|
)}
|
|
77
|
-
{filter.canInvert !== false && (
|
|
79
|
+
{filter.canInvert !== false && filter.field && (
|
|
78
80
|
<MenuItem
|
|
79
81
|
label={t(filter.negate ? "label.include" : "label.exclude")}
|
|
80
82
|
onClick={() => onChange({ ...filter, negate: !filter.negate })}
|
|
@@ -32,12 +32,14 @@ import { FilterMenu } from "./FilterMenu";
|
|
|
32
32
|
export const FilterTag = ({
|
|
33
33
|
filter,
|
|
34
34
|
fields,
|
|
35
|
+
editable,
|
|
35
36
|
includedColor = "primary-500",
|
|
36
37
|
excludedColor = "danger-500",
|
|
37
38
|
onChange,
|
|
38
39
|
onRemove,
|
|
39
40
|
}: {
|
|
40
41
|
filter: FilterObject;
|
|
42
|
+
editable?: boolean;
|
|
41
43
|
onRemove: () => void;
|
|
42
44
|
onChange: (filter: FilterObject) => void;
|
|
43
45
|
} & Pick<FilterBarProps, "fields" | "includedColor" | "excludedColor">) => {
|
|
@@ -46,14 +48,18 @@ export const FilterTag = ({
|
|
|
46
48
|
if (filter.label)
|
|
47
49
|
return (
|
|
48
50
|
<Fragment>
|
|
49
|
-
{filter.negate &&
|
|
51
|
+
{filter.field && filter.negate && (
|
|
52
|
+
<span className="font-semibold">NOT</span>
|
|
53
|
+
)}
|
|
50
54
|
<span>{filter.label}</span>
|
|
51
55
|
</Fragment>
|
|
52
56
|
);
|
|
53
57
|
|
|
54
58
|
return (
|
|
55
59
|
<Fragment>
|
|
56
|
-
{filter.negate &&
|
|
60
|
+
{filter.field && filter.negate && (
|
|
61
|
+
<span className="font-semibold">NOT</span>
|
|
62
|
+
)}
|
|
57
63
|
<span>{filter.field}</span>
|
|
58
64
|
<span className="font-semibold">
|
|
59
65
|
{t(`operator.${filter.operator}`, { defaultValue: filter.operator })}
|
|
@@ -68,7 +74,9 @@ export const FilterTag = ({
|
|
|
68
74
|
}, [filter]);
|
|
69
75
|
|
|
70
76
|
const color = useMemo(
|
|
71
|
-
() =>
|
|
77
|
+
() =>
|
|
78
|
+
filter.color ??
|
|
79
|
+
(filter.field && filter.negate ? excludedColor : includedColor),
|
|
72
80
|
[filter, includedColor, excludedColor],
|
|
73
81
|
);
|
|
74
82
|
|
|
@@ -116,6 +124,7 @@ export const FilterTag = ({
|
|
|
116
124
|
<FilterMenu
|
|
117
125
|
filter={filter}
|
|
118
126
|
fields={fields}
|
|
127
|
+
editable={editable}
|
|
119
128
|
onChange={onChange}
|
|
120
129
|
onRemove={onRemove}
|
|
121
130
|
/>
|
|
@@ -60,7 +60,7 @@ export const QueryForm = ({
|
|
|
60
60
|
}) => {
|
|
61
61
|
const { t } = useTranslation("searchbar");
|
|
62
62
|
const tree = useFloatingTree();
|
|
63
|
-
const { defaultQuery = "", querySchema } = useFilterContext();
|
|
63
|
+
const { defaultQuery = "", querySchema, queryLanguage } = useFilterContext();
|
|
64
64
|
const inputRef = useRef<HTMLInputElement>(null);
|
|
65
65
|
|
|
66
66
|
const filterValue = useMemo(() => {
|
|
@@ -126,7 +126,7 @@ export const QueryForm = ({
|
|
|
126
126
|
}}
|
|
127
127
|
>
|
|
128
128
|
<CodeEditor
|
|
129
|
-
language="
|
|
129
|
+
language={queryLanguage ?? "text"}
|
|
130
130
|
minimal
|
|
131
131
|
required
|
|
132
132
|
{...field}
|
package/src/i18n/en.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -25,4 +25,9 @@ import "./i18n";
|
|
|
25
25
|
|
|
26
26
|
export { FilterBar } from "./filterbar/FilterBar";
|
|
27
27
|
export { SearchBar } from "./searchbar/SearchBar";
|
|
28
|
-
export {
|
|
28
|
+
export {
|
|
29
|
+
FIELD_TYPE,
|
|
30
|
+
OPERATOR,
|
|
31
|
+
type FilterObject,
|
|
32
|
+
type SearchObject,
|
|
33
|
+
} from "./types";
|
|
@@ -61,6 +61,7 @@ export const SearchBar = ({
|
|
|
61
61
|
onQuery,
|
|
62
62
|
onSearch,
|
|
63
63
|
query,
|
|
64
|
+
ref,
|
|
64
65
|
multiple,
|
|
65
66
|
filters = EMPTY_ARRAY,
|
|
66
67
|
...filterProps
|
|
@@ -146,6 +147,7 @@ export const SearchBar = ({
|
|
|
146
147
|
<AutoComplete
|
|
147
148
|
allowClear
|
|
148
149
|
expandOnEdit
|
|
150
|
+
ref={ref}
|
|
149
151
|
multiple={multiple}
|
|
150
152
|
history={history}
|
|
151
153
|
value={state.query}
|