@bigbinary/neeto-filters-frontend 1.4.1 → 2.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/README.md +52 -213
- package/dist/index.js +1 -1
- package/package.json +7 -8
- package/CHANGELOG.md +0 -34
package/README.md
CHANGED
|
@@ -2,17 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
neetoFilters is the library that manages filters across neeto products.
|
|
4
4
|
|
|
5
|
-
## Integrations
|
|
6
|
-
|
|
7
|
-
| Project | Routes |
|
|
8
|
-
| -------------- | --------------------------------------------- |
|
|
9
|
-
| neeto-chat-web | /admin/contacts |
|
|
10
|
-
| neeto-crm-web | /deals, /contacts, /companies, /tasks, /mails |
|
|
11
|
-
| neeto-cal-web | /meetings, /scheduled-meetings |
|
|
12
|
-
|
|
13
5
|
## Installation
|
|
14
6
|
|
|
15
|
-
```
|
|
7
|
+
```bash
|
|
16
8
|
yarn add @bigbinary/neeto-filters-frontend
|
|
17
9
|
```
|
|
18
10
|
|
|
@@ -20,228 +12,75 @@ yarn add @bigbinary/neeto-filters-frontend
|
|
|
20
12
|
functioning of the package. Install all the peer dependencies using the below
|
|
21
13
|
command:
|
|
22
14
|
|
|
23
|
-
```
|
|
15
|
+
```bash
|
|
24
16
|
yarn add @bigbinary/neetoui @bigbinary/neeto-icons axios@0.27.2 classnames@2.3.1 dayjs@1.11.1 formik@2.2.0 ramda@0.28.0 react-router-dom@5.3.0 react-router-nav-prompt@0.4.1 react-toastify@9.0.1 yup@0.32.11
|
|
25
17
|
```
|
|
26
18
|
|
|
27
19
|
## Usage
|
|
28
20
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
{
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
segment={segment}
|
|
67
|
-
onChange={handleChange}
|
|
68
|
-
/>
|
|
69
|
-
);
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
export default FilterComponent;
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
The types that are available by default are `text`, `number`, `date`, `time`,
|
|
76
|
-
`datetime`, `date_range`, `time_range`, `single_option`, and `multi_option`. For
|
|
77
|
-
adding types other than the default types, you can pass the `filters` prop along
|
|
78
|
-
with the available logical filters as an array. You can change the input type
|
|
79
|
-
for the filter by passing the `inputType` prop. By default the input type is
|
|
80
|
-
`text`.
|
|
81
|
-
|
|
82
|
-
This is an example payload for the `handleChange` method. This will be passed on
|
|
83
|
-
to the `NeetoFilters::FilterService` in the `neeto_filters` gem.
|
|
84
|
-
|
|
85
|
-
```json
|
|
86
|
-
{
|
|
87
|
-
"segment": {
|
|
88
|
-
"id": "<uuid>",
|
|
89
|
-
"name": "Backlog",
|
|
90
|
-
"filters": [
|
|
91
|
-
{
|
|
92
|
-
"conditions": [
|
|
93
|
-
{
|
|
94
|
-
"node": "email",
|
|
95
|
-
"label": "Email Address",
|
|
96
|
-
"type": "text",
|
|
97
|
-
"rule": "contains",
|
|
98
|
-
"value": "bigbinary",
|
|
99
|
-
"conditionsJoinType": "and"
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
"node": "session",
|
|
103
|
-
"label": "Sessions",
|
|
104
|
-
"type": "number",
|
|
105
|
-
"rule": "greater_than",
|
|
106
|
-
"value": "10",
|
|
107
|
-
"conditionsJoinType": "and"
|
|
108
|
-
}
|
|
109
|
-
],
|
|
110
|
-
"groupJoinType": "or"
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
"conditions": [
|
|
114
|
-
{
|
|
115
|
-
"node": "ticket",
|
|
116
|
-
"label": "Tickets",
|
|
117
|
-
"type": "number",
|
|
118
|
-
"rule": "greater_than",
|
|
119
|
-
"value": "5",
|
|
120
|
-
"conditionsJoinType": "and"
|
|
121
|
-
}
|
|
122
|
-
],
|
|
123
|
-
"groupJoinType": "and"
|
|
124
|
-
}
|
|
125
|
-
]
|
|
126
|
-
}
|
|
127
|
-
}
|
|
21
|
+
> The documentation for dropdown-type filters UI has been moved to https://github.com/bigbinary/neeto-filters-frontend/blob/main/src/components/DropdownFilter/README.md
|
|
22
|
+
|
|
23
|
+
### 1. Filters component
|
|
24
|
+
|
|
25
|
+
#### Props
|
|
26
|
+
1. **isOpen**: To specify whether the Pane component is open or not.
|
|
27
|
+
2. **setIsOpen**: To trigger the isOpen state.
|
|
28
|
+
3. **columns**: The list of columns that needs to be represented in the filters pane.
|
|
29
|
+
4. **onChange**: To specify the function that is triggered whenever a filter is applied or cleared.
|
|
30
|
+
5. **buttonProps**: To specify the props to be passed to the button component.
|
|
31
|
+
6. **paneProps**: To specify the props to be passed to the pane component.
|
|
32
|
+
7. **isSearchable**: To specify whether the Select input is searchable.
|
|
33
|
+
|
|
34
|
+
Here is an example for the `columns` prop:
|
|
35
|
+
```js
|
|
36
|
+
export const SAMPLE_FILTER_COLUMNS = [
|
|
37
|
+
{
|
|
38
|
+
key: "name",
|
|
39
|
+
node: "first_name,last_name",
|
|
40
|
+
label: "Name",
|
|
41
|
+
type: "single_option",
|
|
42
|
+
values: [{label: "Oliver Smith", value: "f6a64081-85e5-4ed9-b1a0-7b2ac3ff289b"} , {label: "Eve Smith", value: "d378abe3-0c96-4a57-86dc-bea7c77d3ba0"}],
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
key: "email",
|
|
46
|
+
node: "email",
|
|
47
|
+
label: "Email",
|
|
48
|
+
type: "multi_option",
|
|
49
|
+
values: [{label: "oliver@example.com", value: "f6a64081-85e5-4ed9-b1a0-7b2ac3ff289b"} , {label: "eve@example.com", value: "d378abe3-0c96-4a57-86dc-bea7c77d3ba0"}],
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
key: "created_at",
|
|
53
|
+
node: "created_at",
|
|
54
|
+
label: "Created At",
|
|
55
|
+
type: "date",
|
|
56
|
+
},
|
|
57
|
+
];
|
|
128
58
|
```
|
|
129
59
|
|
|
130
|
-
###
|
|
131
|
-
|
|
132
|
-
- Some columns like `name` are actually combination of two columns `first_name`
|
|
133
|
-
and `last_name`. For this example, the node must be provided as
|
|
134
|
-
`"first_name,last_name"`. Here, both the nodes are separated by comma. On the
|
|
135
|
-
Rails side, they will be separated by space by default.
|
|
136
|
-
- Note that this feature will not be supported for `date_range` and `time_range`
|
|
137
|
-
types.
|
|
60
|
+
### 2. Bar component
|
|
138
61
|
|
|
139
|
-
|
|
62
|
+
#### Props
|
|
140
63
|
|
|
141
|
-
1. **columns**:
|
|
142
|
-
|
|
143
|
-
|
|
64
|
+
1. **columns**: The list of columns that needs to be represented in the filters pane.
|
|
65
|
+
2. **onChange**: To specify the function that is triggered whenever a filter is applied or cleared.
|
|
66
|
+
3. **setIsPaneOpen**: To trigger the isOpen state.
|
|
144
67
|
|
|
145
|
-
|
|
146
|
-
- **label\***: The label of the column that needs to be displayed in the
|
|
147
|
-
`Filters` component.
|
|
148
|
-
- **type\***: The type of the column. It can be one of the following:
|
|
149
|
-
- `text`: A text input.
|
|
150
|
-
- `number`: A number input.
|
|
151
|
-
- `date`: A date input.
|
|
152
|
-
- `time`: A time input.
|
|
153
|
-
- `single_option`: A single option select input.
|
|
154
|
-
- `multi_option`: A multi option select input.
|
|
155
|
-
- `boolean`: Radio buttons.
|
|
156
|
-
- **inputType**: If a new data type not in the above list needs to be added, you
|
|
157
|
-
can pass the `inputType` prop along with the `type` prop. It can take the
|
|
158
|
-
following values:
|
|
159
|
-
- `text`: A text input.
|
|
160
|
-
- `number`: A number input.
|
|
161
|
-
- `date`: A date input.
|
|
162
|
-
- `time`: A time input.
|
|
163
|
-
- `single_option`: A single option select input.
|
|
164
|
-
- `multi_option`: A multi option select input.
|
|
165
|
-
- `radio`: Radio buttons.
|
|
166
|
-
- **filters**: If a new data type not in the above list is added, you need to
|
|
167
|
-
pass an array of strings that define the available logical filters for the
|
|
168
|
-
column.
|
|
169
|
-
- **hidden**: If a column need not be shown in the dropdown, but should be
|
|
170
|
-
filterable via the URL, pass a truthy value to the `hidden` prop.
|
|
171
|
-
- **model**: While dealing with associated types, it is mandatory to pass the
|
|
172
|
-
class name of the model of the associated column.
|
|
68
|
+
All these props must be same as that passed to the `Filters` component.
|
|
173
69
|
|
|
174
|
-
|
|
175
|
-
takes the segment as an argument.
|
|
176
|
-
3. **hideActionButtons**: A boolean that determines whether the action buttons
|
|
177
|
-
(submit and delete) are hidden or not. It is set to `true` by default.
|
|
178
|
-
4. **submitButtonProps**: An object that defines the additional props for the
|
|
179
|
-
submit button.
|
|
180
|
-
5. **deleteButtonProps**: An object that defines the additional props for the
|
|
181
|
-
delete button.
|
|
182
|
-
6. **segmentsEnabled**: By default, neetoFilters calls the segments API to fetch
|
|
183
|
-
all the stored segments. If neetoFilters is used without saving filters as
|
|
184
|
-
segments, set the `segmentsEnabled` prop as `false`.
|
|
70
|
+
### 3. buildFiltersFromURL function
|
|
185
71
|
|
|
186
|
-
|
|
72
|
+
- This function takes the list of all filter columns as argument.
|
|
73
|
+
- It builds the filter payload from the URL search params. This function should be called for initizing the `filters` state.
|
|
187
74
|
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
<SegmentMenu entity="User" />
|
|
191
|
-
</MenuBar>
|
|
75
|
+
```js
|
|
76
|
+
const [filters, setFilters] = useState(() => buildFiltersFromURL(SAMPLE_FILTER_COLUMNS));
|
|
192
77
|
```
|
|
193
78
|
|
|
194
|
-
- The `SegmentMenu` component renders the list of all segments on the `MenuBar`.
|
|
195
|
-
It provides the functionality of searching and managing the segments.
|
|
196
|
-
- It must only be used within the `MenuBar` component.
|
|
197
|
-
- It expects only one prop: `entity`. It is the name of the model on which the
|
|
198
|
-
segments are defined on.
|
|
199
|
-
|
|
200
|
-
### 3. Controlling the filters programatically
|
|
201
|
-
|
|
202
|
-
- Filters can be programatically modified by updating the `neeto-filters` search
|
|
203
|
-
param in the URL.
|
|
204
|
-
- For the example payload given above, the URL will be translated to:
|
|
205
|
-
```
|
|
206
|
-
https://<base-url>/?neeto-filters=email-contains-bigbinary-text-and-session-greater_than-10-number-gor-ticket-greater_than-5-number
|
|
207
|
-
```
|
|
208
|
-
- The search param can be programatically built using the `encodeFilters` method
|
|
209
|
-
exported by the package. It accepts the `filters` are argument and returns the
|
|
210
|
-
search param associated with it.
|
|
211
|
-
- Here is a sample usage:
|
|
212
|
-
|
|
213
|
-
```js
|
|
214
|
-
const handleUpdateUrl = filters => {
|
|
215
|
-
const searchParams = new URLSearchParams(window.location.search);
|
|
216
|
-
|
|
217
|
-
if (searchParams.get("segmentId")) return;
|
|
218
|
-
|
|
219
|
-
isEmpty(filters)
|
|
220
|
-
? searchParams.delete("neeto-filters")
|
|
221
|
-
: searchParams.set("neeto-filters", encodeFilters(filters));
|
|
222
|
-
|
|
223
|
-
history.push({ search: searchParams.toString() });
|
|
224
|
-
};
|
|
225
|
-
```
|
|
226
|
-
|
|
227
|
-
- Similarly, there is a `decodeFilters` method which can be used to decode the
|
|
228
|
-
URL and obtain the corresponding filters.
|
|
229
|
-
|
|
230
|
-
### 4. Handling inverse polymorphic relations
|
|
231
|
-
|
|
232
|
-
- Let's say there is a polymorphic relationship between `bookings` and
|
|
233
|
-
`transactions` where the relation is defined inside the `bookings` table as
|
|
234
|
-
`has_one :payment, as: :payable`.
|
|
235
|
-
- If we need to filter all `payments` from the `bookings` table, it can be done
|
|
236
|
-
in the normal way by setting the node as "booking.payment.column_name". If we
|
|
237
|
-
need to access it the other way round, the node should be set as
|
|
238
|
-
"bookings:payable.column_name".
|
|
239
|
-
|
|
240
79
|
## Development
|
|
241
80
|
|
|
242
81
|
Install all the dependencies by executing the following command
|
|
243
82
|
|
|
244
|
-
```
|
|
83
|
+
```bash
|
|
245
84
|
yarn install
|
|
246
85
|
```
|
|
247
86
|
|
|
@@ -251,7 +90,7 @@ In order to run the application you need to run the Rails server of the
|
|
|
251
90
|
neetoFilters engine's dummy application as well. This is necessary to make sure
|
|
252
91
|
that all the APIs and React Query hooks are working as per the requirement.
|
|
253
92
|
|
|
254
|
-
```
|
|
93
|
+
```bash
|
|
255
94
|
git clone https://github.com/bigbinary/neeto-filters-engine.git
|
|
256
95
|
./test/dummy/bin/setup
|
|
257
96
|
rails server
|