@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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type FilterObject } from "../types";
|
|
2
|
-
export declare
|
|
2
|
+
export declare function FilterEdit({ filter, onRemove, onChange, }: {
|
|
3
3
|
filter?: FilterObject;
|
|
4
4
|
onRemove?: () => void;
|
|
5
5
|
onChange: (filter: FilterObject) => void;
|
|
6
|
-
})
|
|
6
|
+
}): import("react").JSX.Element;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare
|
|
1
|
+
import type { FilterObject } from "../types";
|
|
2
|
+
export declare function FilterForm({ filter, onChange, onRemove, }: {
|
|
3
3
|
filter?: FilterObject;
|
|
4
4
|
onRemove?: () => void;
|
|
5
5
|
onChange?: (filter: FilterObject) => void;
|
|
6
|
-
})
|
|
6
|
+
}): import("react").JSX.Element;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { type FilterField, type FilterObject } from "../types";
|
|
2
|
-
export declare
|
|
2
|
+
export declare function FilterMenu({ filter, editable, onChange, onRemove, }: {
|
|
3
3
|
fields?: FilterField[];
|
|
4
|
+
editable?: boolean;
|
|
4
5
|
filter: FilterObject;
|
|
5
6
|
onRemove: () => void;
|
|
6
7
|
onChange: (filter: FilterObject) => void;
|
|
7
|
-
})
|
|
8
|
+
}): import("react").JSX.Element;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type FilterBarProps, type FilterObject } from "../types";
|
|
2
|
-
export declare
|
|
2
|
+
export declare function 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
|
-
} & Pick<FilterBarProps, "fields" | "includedColor" | "excludedColor">)
|
|
7
|
+
} & Pick<FilterBarProps, "fields" | "includedColor" | "excludedColor">): import("react").JSX.Element;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type FilterObject } from "../types";
|
|
2
|
-
export declare
|
|
2
|
+
export declare function FilterView({ filter, onRemove }: {
|
|
3
3
|
filter: FilterObject;
|
|
4
4
|
onRemove: () => void;
|
|
5
|
-
})
|
|
5
|
+
}): import("react").JSX.Element;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type FilterObject } from "../types";
|
|
2
|
-
export declare
|
|
2
|
+
export declare function QueryForm({ filter, onChange, onRemove, }: {
|
|
3
3
|
filter?: FilterObject;
|
|
4
4
|
onRemove?: () => void;
|
|
5
5
|
onChange?: (filter: FilterObject) => void;
|
|
6
|
-
})
|
|
6
|
+
}): import("react").JSX.Element;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Fabric
|
|
3
|
+
* @version 1.0.0
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright 2024 Adarsh Pastakia
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
export declare const SEARCHBAR_PACKAGE = "@react-fabric/searchbar";
|
|
26
|
+
export declare const SEARCHBAR_VERSION = "1.0.0";
|
|
1
27
|
import "./i18n";
|
|
2
28
|
export { FilterBar } from "./filterbar/FilterBar";
|
|
3
29
|
export { SearchBar } from "./searchbar/SearchBar";
|
|
4
|
-
export { FIELD_TYPE, OPERATOR, type FilterObject } from "./types";
|
|
30
|
+
export { FIELD_TYPE, OPERATOR, type FilterObject, type SearchObject } from "./types";
|
|
@@ -1,2 +1,31 @@
|
|
|
1
1
|
import { type FilterBarProps, type SearchBarProps } from "../types";
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* This component provides a search input with autocomplete functionality,
|
|
4
|
+
* a button to trigger search, and an optional filter bar.
|
|
5
|
+
* It supports history of search queries, multiple selection, and custom decorations.
|
|
6
|
+
* It can be collapsed to hide filters and has options for customization.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```jsx
|
|
10
|
+
* <SearchBar
|
|
11
|
+
* historyKey="myApp:searchHistory"
|
|
12
|
+
* historyCount={10}
|
|
13
|
+
* defaultQueryList={["example", "test"]}
|
|
14
|
+
* prepend={<span>Prepend</span>}
|
|
15
|
+
* append={<span>Append</span>}
|
|
16
|
+
* decorateEnd={<span>End Decoration</span>}
|
|
17
|
+
* decorateStart={<span>Start Decoration</span>}
|
|
18
|
+
* hideFilters={false}
|
|
19
|
+
* defaultCollapsed={false}
|
|
20
|
+
* disabled={false}
|
|
21
|
+
* onCollapsed={(collapsed) => console.log("Collapsed:", collapsed)}
|
|
22
|
+
* onQuery={(query) => console.log("Query:", query)}
|
|
23
|
+
* onSearch={({ query, filters }) => console.log("Search:", query, filters)}
|
|
24
|
+
* query={""}
|
|
25
|
+
* ref={searchInputRef}
|
|
26
|
+
* multiple={false}
|
|
27
|
+
* filters={[{ name: "filter1", value: "value1" }]}
|
|
28
|
+
* />
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function SearchBar({ historyKey, historyCount, defaultQueryList, prepend, append, decorateEnd, decorateStart, children, hideFilters, defaultCollapsed, disabled, onSearch, query, ref, multiple, filters, ...filterProps }: SearchBarProps & Omit<FilterBarProps, "onFilterChanged">): import("react").JSX.Element;
|
|
@@ -1,22 +1,27 @@
|
|
|
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",
|
|
5
5
|
STRING = "STRING",
|
|
6
|
+
TEXT = "TEXT",
|
|
6
7
|
NUMBER = "NUMBER",
|
|
7
8
|
DECIMAL = "DECIMAL",
|
|
8
9
|
BOOLEAN = "BOOLEAN",
|
|
10
|
+
DATE = "DATE",
|
|
11
|
+
DATETIME = "DATETIME",
|
|
9
12
|
NONE = "NONE"
|
|
10
13
|
}
|
|
11
14
|
export declare enum OPERATOR {
|
|
12
15
|
EXISTS = "EXISTS",
|
|
13
16
|
IS = "IS",
|
|
14
|
-
|
|
17
|
+
ALL = "ALL",
|
|
18
|
+
ANY = "ANY",
|
|
19
|
+
EQ = "EQ",
|
|
15
20
|
LT = "LT",
|
|
16
21
|
GT = "GT",
|
|
17
22
|
LTE = "LTE",
|
|
18
23
|
GTE = "GTE",
|
|
19
|
-
|
|
24
|
+
LIKE = "LIKE",
|
|
20
25
|
STARTS = "STARTS",
|
|
21
26
|
ENDS = "ENDS",
|
|
22
27
|
WITHIN = "WITHIN",
|
|
@@ -30,6 +35,9 @@ export declare const TypeOperators: {
|
|
|
30
35
|
};
|
|
31
36
|
/**
|
|
32
37
|
* @internal
|
|
38
|
+
* 0 single value
|
|
39
|
+
* 1 many values
|
|
40
|
+
* 2 two values
|
|
33
41
|
*/
|
|
34
42
|
export declare const OperatorValueType: {
|
|
35
43
|
[key in OPERATOR]: 0 | 1 | 2;
|
|
@@ -46,25 +54,25 @@ interface BaseFilter {
|
|
|
46
54
|
color?: string;
|
|
47
55
|
value?: FilterValue;
|
|
48
56
|
pinned?: boolean;
|
|
49
|
-
negate?: boolean;
|
|
50
57
|
disabled?: boolean;
|
|
51
58
|
required?: boolean;
|
|
52
59
|
canPin?: boolean;
|
|
53
60
|
canEdit?: boolean;
|
|
54
|
-
canInvert?: boolean;
|
|
55
61
|
canDisable?: boolean;
|
|
56
62
|
}
|
|
57
63
|
export type FilterObject = BaseFilter & ({
|
|
58
64
|
field: string;
|
|
59
|
-
type?: FIELD_TYPE;
|
|
60
65
|
operator: OPERATOR;
|
|
61
66
|
value?: FilterValue;
|
|
67
|
+
negate?: boolean;
|
|
68
|
+
canInvert?: boolean;
|
|
62
69
|
query?: never;
|
|
70
|
+
type?: string;
|
|
63
71
|
} | {
|
|
64
72
|
field?: never;
|
|
65
|
-
type?: never;
|
|
66
73
|
operator?: never;
|
|
67
74
|
label: string;
|
|
75
|
+
canInvert?: false;
|
|
68
76
|
query: string;
|
|
69
77
|
});
|
|
70
78
|
export interface SearchObject<T = string> {
|
|
@@ -84,11 +92,11 @@ export interface FilterField {
|
|
|
84
92
|
defaultOperator?: OPERATOR;
|
|
85
93
|
onSearch?: (q: string) => Promise<FieldValue[]> | FieldValue[];
|
|
86
94
|
}
|
|
87
|
-
interface BaseSearchBarProps extends Partial<ChildrenProp> {
|
|
95
|
+
interface BaseSearchBarProps extends Partial<ChildrenProp>, RefProp<HTMLTextAreaElement> {
|
|
88
96
|
/**
|
|
89
97
|
* Query string
|
|
90
98
|
*/
|
|
91
|
-
query?:
|
|
99
|
+
query?: string | string[];
|
|
92
100
|
/**
|
|
93
101
|
* Search history count
|
|
94
102
|
* @default 20
|
|
@@ -127,11 +135,11 @@ interface BaseSearchBarProps extends Partial<ChildrenProp> {
|
|
|
127
135
|
/**
|
|
128
136
|
*
|
|
129
137
|
*/
|
|
130
|
-
decorateStart?:
|
|
138
|
+
decorateStart?: React.ReactElement | string | number | boolean;
|
|
131
139
|
/**
|
|
132
140
|
*
|
|
133
141
|
*/
|
|
134
|
-
decorateEnd?:
|
|
142
|
+
decorateEnd?: React.ReactElement | string | number | boolean;
|
|
135
143
|
/**
|
|
136
144
|
* On filter collapsed
|
|
137
145
|
* @param collapsed
|
|
@@ -152,7 +160,7 @@ export type SearchBarProps = BaseSearchBarProps & ({
|
|
|
152
160
|
*/
|
|
153
161
|
onSearch?: (queryObject: SearchObject<string[]>) => void;
|
|
154
162
|
} | {
|
|
155
|
-
multiple?:
|
|
163
|
+
multiple?: false;
|
|
156
164
|
query?: string;
|
|
157
165
|
/**
|
|
158
166
|
* On search event
|
|
@@ -174,11 +182,11 @@ export interface FilterBarProps {
|
|
|
174
182
|
/**
|
|
175
183
|
* Editable filters
|
|
176
184
|
*/
|
|
177
|
-
|
|
185
|
+
editable?: boolean;
|
|
178
186
|
/**
|
|
179
187
|
* Disable component
|
|
180
188
|
*/
|
|
181
|
-
|
|
189
|
+
disabled?: boolean;
|
|
182
190
|
/**
|
|
183
191
|
* Message for empty field list
|
|
184
192
|
*/
|
|
@@ -192,6 +200,7 @@ export interface FilterBarProps {
|
|
|
192
200
|
*/
|
|
193
201
|
excludedColor?: string;
|
|
194
202
|
allowAdd?: boolean;
|
|
203
|
+
queryLanguage?: "text" | "json";
|
|
195
204
|
querySchema?: Array<{
|
|
196
205
|
uri: string;
|
|
197
206
|
schema: KeyValue;
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-fabric/searchbar",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "RUF: Searchbar with filters package",
|
|
5
5
|
"author": "Adarsh Pastakia <adarshpastakia@outlook.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"repository": "https://github.com/adarshpastakia/react-
|
|
7
|
+
"repository": "https://github.com/adarshpastakia/react-fabric/tree/main/packages/searchbar",
|
|
8
8
|
"source": "src/index.ts",
|
|
9
9
|
"main": "dist/cjs/index.js",
|
|
10
10
|
"module": "dist/esm/index.js",
|
|
@@ -22,8 +22,6 @@
|
|
|
22
22
|
"registry": "https://registry.npmjs.org/"
|
|
23
23
|
},
|
|
24
24
|
"scripts": {
|
|
25
|
-
"makelink": "yarn link",
|
|
26
|
-
"removelink": "yarn unlink",
|
|
27
25
|
"prebuild": "rm -rf ./dist",
|
|
28
26
|
"build:dts": "tsc -p ./tsconfig.build.json",
|
|
29
27
|
"build:rollup": "rollup -c ../../rollup.config.mjs",
|
|
@@ -33,24 +31,23 @@
|
|
|
33
31
|
"watch": "npm-run-all -p watch:rollup watch:dts"
|
|
34
32
|
},
|
|
35
33
|
"dependencies": {
|
|
36
|
-
"@floating-ui/react": "0.
|
|
37
|
-
"@
|
|
38
|
-
"@react-fabric/
|
|
39
|
-
"@react-fabric/form": "^1.0.
|
|
40
|
-
"@react-fabric/monaco": "^1.0.
|
|
41
|
-
"@react-fabric/
|
|
42
|
-
"
|
|
43
|
-
"react-hook-form": "^7.52.1"
|
|
34
|
+
"@floating-ui/react": "~0.27.20",
|
|
35
|
+
"@hookform/resolvers": "~5.9.1",
|
|
36
|
+
"@react-fabric/core": "^1.0.1",
|
|
37
|
+
"@react-fabric/form": "^1.0.1",
|
|
38
|
+
"@react-fabric/monaco": "^1.0.1",
|
|
39
|
+
"@react-fabric/superdate": "^1.0.1",
|
|
40
|
+
"@react-fabric/utilities": "^1.0.1"
|
|
44
41
|
},
|
|
45
42
|
"peerDependencies": {
|
|
46
|
-
"i18next": "
|
|
47
|
-
"react": "
|
|
48
|
-
"react-dom": "
|
|
49
|
-
"react-i18next": "
|
|
43
|
+
"i18next": "~26.3.6",
|
|
44
|
+
"react": "~19.3.0",
|
|
45
|
+
"react-dom": "~19.3.0",
|
|
46
|
+
"react-i18next": "~17.0.11"
|
|
50
47
|
},
|
|
51
48
|
"engines": {
|
|
52
|
-
"node": ">=
|
|
53
|
-
"npm": ">=
|
|
49
|
+
"node": ">=24.0.0",
|
|
50
|
+
"npm": ">=11.0.0"
|
|
54
51
|
},
|
|
55
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "1419a9df05b5e3850e1d2b4e896ab63df702c7e8"
|
|
56
53
|
}
|
|
@@ -21,11 +21,11 @@
|
|
|
21
21
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
import { createContext,
|
|
24
|
+
import { createContext, use } from "react";
|
|
25
25
|
import { type FilterBarProps } from "../types";
|
|
26
26
|
|
|
27
|
-
export const FilterContext = createContext<
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
export const FilterContext = createContext<Pick<FilterBarProps, "querySchema" | "queryLanguage" | "defaultQuery" | "fields">>(
|
|
28
|
+
{},
|
|
29
|
+
);
|
|
30
30
|
|
|
31
|
-
export const useFilterContext = () =>
|
|
31
|
+
export const useFilterContext = () => use(FilterContext);
|
|
@@ -21,34 +21,49 @@
|
|
|
21
21
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
import {
|
|
25
|
-
|
|
26
|
-
CoreIcons,
|
|
27
|
-
Divider,
|
|
28
|
-
Dropdown,
|
|
29
|
-
Icon,
|
|
30
|
-
Menu,
|
|
31
|
-
MenuItem,
|
|
32
|
-
} from "@react-fabric/core";
|
|
33
|
-
import { isEmpty, isNil } from "@react-fabric/utilities";
|
|
24
|
+
import { Chip, Divider, Dropdown, Icon, Menu, MenuItem } from "@react-fabric/core";
|
|
25
|
+
import { cn, isEmpty, isNil } from "@react-fabric/utilities";
|
|
34
26
|
import { useCallback, useMemo } from "react";
|
|
35
27
|
import { useTranslation } from "react-i18next";
|
|
36
28
|
import { type FilterBarProps, type FilterObject } from "../types";
|
|
29
|
+
import { FilterContext } from "./Context";
|
|
37
30
|
import { FilterEdit } from "./FilterEdit";
|
|
38
31
|
import { FilterTag } from "./FilterTag";
|
|
39
|
-
import classNames from "classnames";
|
|
40
|
-
import { FilterContext } from "./Context";
|
|
41
32
|
|
|
42
|
-
|
|
33
|
+
/**
|
|
34
|
+
* FilterBar component allows users to manage a list of filters.
|
|
35
|
+
* It provides options to add, remove, and modify filters,
|
|
36
|
+
* as well as to enable or disable all filters at once.
|
|
37
|
+
* It also supports toggling between included and excluded filters.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```jsx
|
|
41
|
+
* <FilterBar
|
|
42
|
+
* filters={filters}
|
|
43
|
+
* allowAdd={true}
|
|
44
|
+
* fields={fields}
|
|
45
|
+
* editable={true}
|
|
46
|
+
* querySchema={querySchema}
|
|
47
|
+
* queryLanguage="lucene"
|
|
48
|
+
* defaultQuery="*"
|
|
49
|
+
* includedColor="green"
|
|
50
|
+
* excludedColor="red"
|
|
51
|
+
* onFilterChanged={(newFilters) => console.log(newFilters)}
|
|
52
|
+
* />
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export function FilterBar({
|
|
43
56
|
filters = [],
|
|
44
57
|
allowAdd,
|
|
45
58
|
fields,
|
|
59
|
+
editable,
|
|
46
60
|
querySchema,
|
|
61
|
+
queryLanguage,
|
|
47
62
|
defaultQuery,
|
|
48
63
|
includedColor,
|
|
49
64
|
excludedColor,
|
|
50
65
|
onFilterChanged,
|
|
51
|
-
}: FilterBarProps)
|
|
66
|
+
}: FilterBarProps) {
|
|
52
67
|
const { t } = useTranslation("searchbar");
|
|
53
68
|
|
|
54
69
|
const handleRemove = useCallback(
|
|
@@ -57,27 +72,19 @@ export const FilterBar = ({
|
|
|
57
72
|
list.splice(index, 1);
|
|
58
73
|
onFilterChanged?.(list);
|
|
59
74
|
},
|
|
60
|
-
[filters],
|
|
75
|
+
[filters, onFilterChanged],
|
|
61
76
|
);
|
|
62
77
|
const handleChange = useCallback(
|
|
63
78
|
(filter: FilterObject, index?: number) => {
|
|
64
79
|
const list = [...filters];
|
|
65
|
-
isNil(index)
|
|
80
|
+
if (isNil(index)) list.push(filter);
|
|
81
|
+
else list.splice(index, 1, filter);
|
|
66
82
|
onFilterChanged?.(list);
|
|
67
83
|
},
|
|
68
|
-
[filters],
|
|
84
|
+
[filters, onFilterChanged],
|
|
69
85
|
);
|
|
70
86
|
const handleToggle = useCallback(
|
|
71
|
-
(
|
|
72
|
-
type:
|
|
73
|
-
| "disableAll"
|
|
74
|
-
| "enableAll"
|
|
75
|
-
| "toggleDisable"
|
|
76
|
-
| "excludeAll"
|
|
77
|
-
| "includeAll"
|
|
78
|
-
| "invertAll"
|
|
79
|
-
| "removeAll",
|
|
80
|
-
) => {
|
|
87
|
+
(type: string) => {
|
|
81
88
|
const list = [];
|
|
82
89
|
if (type === "removeAll") {
|
|
83
90
|
list.push(...filters.filter((filter) => filter.required));
|
|
@@ -88,16 +95,16 @@ export const FilterBar = ({
|
|
|
88
95
|
if (type === "disableAll") filter.disabled = true;
|
|
89
96
|
if (type === "enableAll") filter.disabled = false;
|
|
90
97
|
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") filter.negate = !filter.negate;
|
|
98
|
+
if (type === "excludeAll" && filter.field) filter.negate = true;
|
|
99
|
+
if (type === "includeAll" && filter.field) filter.negate = false;
|
|
100
|
+
if (type === "invertAll" && filter.field) filter.negate = !filter.negate;
|
|
94
101
|
return { ...filter };
|
|
95
102
|
}),
|
|
96
103
|
);
|
|
97
104
|
}
|
|
98
105
|
onFilterChanged?.(list);
|
|
99
106
|
},
|
|
100
|
-
[filters],
|
|
107
|
+
[filters, onFilterChanged],
|
|
101
108
|
);
|
|
102
109
|
|
|
103
110
|
const menuItems = useMemo(() => {
|
|
@@ -109,59 +116,37 @@ export const FilterBar = ({
|
|
|
109
116
|
canRemoveAll: false,
|
|
110
117
|
};
|
|
111
118
|
filters.forEach((filter) => {
|
|
112
|
-
if (filter.disabled && filter.canDisable !== false && !key.someDisabled)
|
|
113
|
-
|
|
114
|
-
if (
|
|
115
|
-
|
|
116
|
-
if (filter.negate && filter.canInvert !== false && !key.someExcluded)
|
|
117
|
-
key.someExcluded = true;
|
|
118
|
-
if (!filter.negate && filter.canInvert !== false && !key.someIncluded)
|
|
119
|
-
key.someIncluded = true;
|
|
119
|
+
if (filter.disabled && filter.canDisable !== false && !key.someDisabled) key.someDisabled = true;
|
|
120
|
+
if (!filter.disabled && filter.canDisable !== false && !key.someEnabled) key.someEnabled = true;
|
|
121
|
+
if (filter.field && filter.negate && filter.canInvert !== false && !key.someExcluded) key.someExcluded = true;
|
|
122
|
+
if (filter.field && !filter.negate && filter.canInvert !== false && !key.someIncluded) key.someIncluded = true;
|
|
120
123
|
if (!filter.required && !key.canRemoveAll) key.canRemoveAll = true;
|
|
121
124
|
});
|
|
122
125
|
return key;
|
|
123
126
|
}, [filters]);
|
|
124
127
|
|
|
125
128
|
return (
|
|
126
|
-
<FilterContext
|
|
129
|
+
<FilterContext value={{ defaultQuery, querySchema, queryLanguage, fields }}>
|
|
127
130
|
<div className="flex flex-wrap gap-1 items-center">
|
|
128
131
|
<Dropdown showArrow disabled={isEmpty(filters)}>
|
|
129
132
|
<Icon
|
|
130
|
-
icon=
|
|
131
|
-
className={
|
|
132
|
-
isEmpty(filters) && "pointer-events-none opacity-30",
|
|
133
|
-
)}
|
|
133
|
+
icon="icon-[mdi--cog-outline]"
|
|
134
|
+
className={cn(isEmpty(filters) && "pointer-events-none opacity-30")}
|
|
134
135
|
color={!isEmpty(filters) ? "primary" : undefined}
|
|
135
136
|
/>
|
|
136
|
-
<Menu className="text-sm" onClick={handleToggle
|
|
137
|
-
{menuItems.someDisabled && (
|
|
138
|
-
|
|
139
|
-
)}
|
|
140
|
-
{menuItems.someEnabled && (
|
|
141
|
-
<MenuItem id="disableAll" label={t("label.disableAll")} />
|
|
142
|
-
)}
|
|
143
|
-
<MenuItem
|
|
144
|
-
icon={CoreIcons.invertDisable}
|
|
145
|
-
id="toggleDisable"
|
|
146
|
-
label={t("label.toggleDisable")}
|
|
147
|
-
/>
|
|
137
|
+
<Menu className="text-sm" onClick={handleToggle}>
|
|
138
|
+
{menuItems.someDisabled && <MenuItem id="enableAll" label={t("label.enableAll")} />}
|
|
139
|
+
{menuItems.someEnabled && <MenuItem id="disableAll" label={t("label.disableAll")} />}
|
|
140
|
+
<MenuItem icon="icon-[mdi--checkbox-intermediate-variant]" id="toggleDisable" label={t("label.toggleDisable")} />
|
|
148
141
|
<Divider />
|
|
149
|
-
{menuItems.someExcluded && (
|
|
150
|
-
|
|
151
|
-
)}
|
|
152
|
-
{menuItems.someIncluded && (
|
|
153
|
-
<MenuItem id="excludeAll" label={t("label.excludeAll")} />
|
|
154
|
-
)}
|
|
155
|
-
<MenuItem
|
|
156
|
-
id="invertAll"
|
|
157
|
-
icon={CoreIcons.invertExclude}
|
|
158
|
-
label={t("label.invertAll")}
|
|
159
|
-
/>
|
|
142
|
+
{menuItems.someExcluded && <MenuItem id="includeAll" label={t("label.includeAll")} />}
|
|
143
|
+
{menuItems.someIncluded && <MenuItem id="excludeAll" label={t("label.excludeAll")} />}
|
|
144
|
+
<MenuItem id="invertAll" icon="icon-[mdi--set-left]" label={t("label.invertAll")} />
|
|
160
145
|
<Divider />
|
|
161
146
|
<MenuItem
|
|
162
147
|
id="removeAll"
|
|
163
148
|
color="danger"
|
|
164
|
-
icon=
|
|
149
|
+
icon="icon-[mdi--minus-circle-outline]"
|
|
165
150
|
label={t("label.removeAll")}
|
|
166
151
|
disabled={!menuItems.canRemoveAll}
|
|
167
152
|
/>
|
|
@@ -169,8 +154,10 @@ export const FilterBar = ({
|
|
|
169
154
|
</Dropdown>
|
|
170
155
|
{filters?.map((filter, idx) => (
|
|
171
156
|
<FilterTag
|
|
157
|
+
// eslint-disable-next-line @eslint-react/no-array-index-key
|
|
172
158
|
key={idx}
|
|
173
159
|
filter={filter}
|
|
160
|
+
editable={editable}
|
|
174
161
|
includedColor={includedColor}
|
|
175
162
|
excludedColor={excludedColor}
|
|
176
163
|
onRemove={() => handleRemove(idx)}
|
|
@@ -179,17 +166,13 @@ export const FilterBar = ({
|
|
|
179
166
|
))}
|
|
180
167
|
{allowAdd && (
|
|
181
168
|
<Dropdown showArrow>
|
|
182
|
-
<Chip
|
|
183
|
-
size="sm"
|
|
184
|
-
className="!outline-dashed !outline-tint-400"
|
|
185
|
-
icon={CoreIcons.insert}
|
|
186
|
-
>
|
|
169
|
+
<Chip size="sm" className="outline-dashed! outline-tint-400!" icon="icon-[mdi--plus-circle-outline]">
|
|
187
170
|
{t("label.add")}
|
|
188
171
|
</Chip>
|
|
189
172
|
<FilterEdit onChange={handleChange} />
|
|
190
173
|
</Dropdown>
|
|
191
174
|
)}
|
|
192
175
|
</div>
|
|
193
|
-
</FilterContext
|
|
176
|
+
</FilterContext>
|
|
194
177
|
);
|
|
195
|
-
}
|
|
178
|
+
}
|
|
@@ -29,7 +29,7 @@ import { useFilterContext } from "./Context";
|
|
|
29
29
|
import { FilterForm } from "./FilterForm";
|
|
30
30
|
import { QueryForm } from "./QueryForm";
|
|
31
31
|
|
|
32
|
-
export
|
|
32
|
+
export function FilterEdit({
|
|
33
33
|
filter,
|
|
34
34
|
onRemove,
|
|
35
35
|
onChange,
|
|
@@ -37,34 +37,27 @@ export const FilterEdit = ({
|
|
|
37
37
|
filter?: FilterObject;
|
|
38
38
|
onRemove?: () => void;
|
|
39
39
|
onChange: (filter: FilterObject) => void;
|
|
40
|
-
})
|
|
40
|
+
}) {
|
|
41
41
|
const { t } = useTranslation("searchbar");
|
|
42
42
|
const { fields } = useFilterContext();
|
|
43
|
-
const [queryEdit, setQueryEdit] = useState(isEmpty(fields));
|
|
43
|
+
const [queryEdit, setQueryEdit] = useState(() => isEmpty(fields));
|
|
44
44
|
|
|
45
45
|
useEffect(() => {
|
|
46
|
+
// eslint-disable-next-line @eslint-react/set-state-in-effect
|
|
46
47
|
setQueryEdit(!!filter && "query" in filter);
|
|
47
48
|
}, [filter]);
|
|
48
49
|
|
|
49
50
|
return (
|
|
50
|
-
<div className="px-2 py-1 bg-
|
|
51
|
+
<div className="px-2 py-1 bg-default outline min-w-108 rounded-capped">
|
|
51
52
|
{!isEmpty(fields) && (
|
|
52
53
|
<div className="pb-4 flex justify-end">
|
|
53
|
-
<span
|
|
54
|
-
role="none"
|
|
55
|
-
className="text-sm link"
|
|
56
|
-
onClick={() => setQueryEdit(!queryEdit)}
|
|
57
|
-
>
|
|
54
|
+
<span role="none" className="text-sm link" onClick={() => setQueryEdit(!queryEdit)}>
|
|
58
55
|
{t(queryEdit ? "label.basicFilter" : "label.customQuery")}
|
|
59
56
|
</span>
|
|
60
57
|
</div>
|
|
61
58
|
)}
|
|
62
|
-
{!queryEdit &&
|
|
63
|
-
|
|
64
|
-
)}
|
|
65
|
-
{queryEdit && (
|
|
66
|
-
<QueryForm filter={filter} onRemove={onRemove} onChange={onChange} />
|
|
67
|
-
)}
|
|
59
|
+
{!queryEdit && <FilterForm filter={filter} onRemove={onRemove} onChange={onChange} />}
|
|
60
|
+
{queryEdit && <QueryForm filter={filter} onRemove={onRemove} onChange={onChange} />}
|
|
68
61
|
</div>
|
|
69
62
|
);
|
|
70
|
-
}
|
|
63
|
+
}
|