@bigbinary/neeto-filters-frontend 2.7.3 → 2.8.0
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/README.md +47 -7
- package/dist/index.cjs.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -2
- package/types.d.ts +22 -7
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ yarn add @bigbinary/neetoui @bigbinary/neeto-icons axios@0.27.2 classnames@2.3.1
|
|
|
17
17
|
```
|
|
18
18
|
## Usage
|
|
19
19
|
|
|
20
|
-
neeto-filters-frontend exports 2 components (`Filters` & `Bar`) and
|
|
20
|
+
neeto-filters-frontend exports 2 components (`Filters` & `Bar`) and 2 functions (`buildFiltersFromURL()` & `buildSelectorsFromURL()`).
|
|
21
21
|
### 1. `Filters` component
|
|
22
22
|
|
|
23
23
|
#### Props
|
|
@@ -26,11 +26,12 @@ neeto-filters-frontend exports 2 components (`Filters` & `Bar`) and a function,
|
|
|
26
26
|
2. **setIsOpen**: To trigger the isOpen state.
|
|
27
27
|
3. **columns**: The list of columns/fields that needs to be represented in the filters pane.
|
|
28
28
|
4. **onChange**: To specify the callback function that is triggered whenever a filter is applied or cleared. This function will get the updated filters as argument.
|
|
29
|
-
5.
|
|
30
|
-
6. **
|
|
31
|
-
7. **
|
|
32
|
-
8. **
|
|
33
|
-
9.
|
|
29
|
+
5. **onSelectorsChange**: To specify the callback function that is triggered whenever a selector value is changed. This function will get the updated selectors as argument.
|
|
30
|
+
6. **buttonProps**: To specify the props to be passed to the button component.
|
|
31
|
+
7. **paneProps**: To specify the props to be passed to the pane component.
|
|
32
|
+
8. **isSearchable**: To specify whether you need a search bar in filters pane to search through filter fields.
|
|
33
|
+
9. **className**: To specify classes to the Filters component.
|
|
34
|
+
10. **keyword**: To specify the props related to searching.
|
|
34
35
|
|
|
35
36
|
Here is an example of `keyword` prop:
|
|
36
37
|
```js
|
|
@@ -103,6 +104,31 @@ Then the node will be `address.line_1,line_2`. In such cases we need to pass thi
|
|
|
103
104
|
- `values`: The list of label-value pair to be shown in dropdown, if the `type` provided is `single_option` or `multi_option`.
|
|
104
105
|
- `showRuleSelector` : Boolean value, which determines whether to show a rule selector above the `text` , `number` and `decimal` type fields. `false` by default.
|
|
105
106
|
- `hidden`: Boolean value, which determines to show or hide field from filter pane. `false ` by default.
|
|
107
|
+
- `defaultValue`: The default value that should appear as chosen one in the filter fields.
|
|
108
|
+
- `isClearable`: Boolean value which specifies whether the field can be cleared or not.
|
|
109
|
+
|
|
110
|
+
- By `selectors` we mean the filter fields which doesn't have any relation (`node`) to a DB >table column.
|
|
111
|
+
- For example, consider a field in filter pane called `Group by`. We cannot provide a `node` to associate it with a column in DB table. Still it can provide an important value which can be used for the computation as if by telling a means by which the records can be grouped after filtering.
|
|
112
|
+
- Fields without a `node`, among the ones passed as value to the `column` prop of `Filters` are >considered as selectors.
|
|
113
|
+
```js
|
|
114
|
+
{
|
|
115
|
+
key: "groupBy",
|
|
116
|
+
label: "Group by",
|
|
117
|
+
type: "single_option",
|
|
118
|
+
values: [
|
|
119
|
+
{
|
|
120
|
+
label: "Team",
|
|
121
|
+
value: "team"
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
label: "Location",
|
|
125
|
+
value: "location"
|
|
126
|
+
}
|
|
127
|
+
],
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
When user selects a value from this dropdown we get that value in the `selectors` state. This can be used for further computations outside the neeto-filters.
|
|
131
|
+
|
|
106
132
|
|
|
107
133
|
### 2. `Bar` component
|
|
108
134
|
|
|
@@ -113,6 +139,7 @@ Then the node will be `address.line_1,line_2`. In such cases we need to pass thi
|
|
|
113
139
|
3. **setIsPaneOpen**: To trigger the isOpen state.
|
|
114
140
|
4. **className**: To specify classes to the Bar component.
|
|
115
141
|
5. **keyword**: To specify the props related to searching.
|
|
142
|
+
6. **onSelectorsChange**: To specify the callback function that is triggered whenever a selector value is changed. This function will get the updated selectors as argument.
|
|
116
143
|
|
|
117
144
|
All these props must be same as that passed to the `Filters` component.
|
|
118
145
|
|
|
@@ -120,11 +147,24 @@ All these props must be same as that passed to the `Filters` component.
|
|
|
120
147
|
|
|
121
148
|
- This function takes a list as argument.
|
|
122
149
|
- This list should contains all the filter columns/fields and the value passed to `keyword` prop of `Filters` and `Bar`.
|
|
123
|
-
- It builds the filter payload from the URL search params. This function should be called for
|
|
150
|
+
- It builds the filter payload from the URL search params. This function should be called for initializing the `filters` state.
|
|
124
151
|
```js
|
|
125
152
|
const [filters, setFilters] = useState(() => buildFiltersFromURL([...SAMPLE_FILTER_COLUMNS, searchKeywordProps]));
|
|
126
153
|
```
|
|
127
154
|
|
|
155
|
+
### 4. `buildSelectorsFromURL` function
|
|
156
|
+
|
|
157
|
+
- By `selectors` we mean the filter fields which doesn't have any relation (`node`) to a DB table column.
|
|
158
|
+
- For example, consider a field in filter pane called `Group by`. We cannot provide a `node` to associate it with a column in DB table. Still it can provide an important value which can be used for the computation as if by telling a means by which the records can be grouped after filtering.
|
|
159
|
+
- Fields without a `node`, among the ones passed as value to the `column` prop of `Filters` are considered as selectors.
|
|
160
|
+
- This function takes a list as argument.
|
|
161
|
+
- This list should contains all the filter columns/fields.
|
|
162
|
+
- It builds the selectors' value from the URL search params. This function should be called for initializing the `selectors` state.
|
|
163
|
+
- `selectors` will be an object with keys same as provided in filter fields and selected value as its value.
|
|
164
|
+
```js
|
|
165
|
+
const [selectors, setSelectors] = useState(() => buildSelectorsFromURL(FILTER_COLUMNS));
|
|
166
|
+
```
|
|
167
|
+
|
|
128
168
|
## Development
|
|
129
169
|
|
|
130
170
|
Install all the dependencies by executing the following command
|