@bigbinary/neeto-filters-frontend 1.4.1 → 2.0.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/CHANGELOG.md CHANGED
@@ -22,7 +22,11 @@ Prefix the change with one of these keywords:
22
22
  - *Fixed*: for any bug fixes.
23
23
  - *Security*: in case of vulnerabilities.
24
24
 
25
- ## [Unreleased](https://github.com/bigbinary/neeto-filters-frontend/compare/b77f80ed12e31627aa786452b20b86925309dfc3...HEAD)
25
+ ## [Unreleased](https://github.com/bigbinary/neeto-filters-frontend/compare/38783bf03081bc51ec623032d7c4fec0e15b632d...HEAD)
26
+
27
+ ## [2.0.0](https://github.com/bigbinary/neeto-filters-frontend/compare/b77f80ed12e31627aa786452b20b86925309dfc3...38783bf03081bc51ec623032d7c4fec0e15b632d) - 2022-11-10
28
+
29
+ - Added: a new UI for handling filters. It consists of the `Filters` component for selecting the filters and the `Bar` component for displaying them.
26
30
 
27
31
  ## [1.4.1](https://github.com/bigbinary/neeto-filters-frontend/compare/c0b99b4212b89b4b02e7f6d1a3c5e4b2d23b45bf...b77f80ed12e31627aa786452b20b86925309dfc3) - 2022-10-11
28
32
 
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
- ```zsh
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
- ```zsh
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
- ### 1. NeetoFilters Component
30
-
31
- ```jsx
32
- import React from "react";
33
-
34
- import Filters from "@bigbinary/neeto-filters-frontend";
35
-
36
- import segmentsApi from "apis/segments";
37
-
38
- const FilterComponent = ({ segment, loadTableContent }) => {
39
- const columns = [
40
- {
41
- node: "email",
42
- label: "Email Address",
43
- type: "text",
44
- },
45
- {
46
- node: "ticket",
47
- label: "Tickets",
48
- type: "number",
49
- },
50
- {
51
- node: "timezone",
52
- label: "Timezone",
53
- type: "timezone",
54
- inputType: "text"
55
- filters: ["is", "is_not", "greater_than", "less_than", "has_any_value", "is_unknown"],
56
- }
57
- ];
58
-
59
- const handleChange = payload => {
60
- loadTableContent(payload);
61
- };
62
-
63
- return (
64
- <Filters
65
- columns={columns}
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: ["Oliver Smith", "Eve Smith"],
43
+ },
44
+ {
45
+ key: "email",
46
+ node: "email",
47
+ label: "Email",
48
+ type: "multi_option",
49
+ values: ["oliver@example.com", "eve@example.com"],
50
+ },
51
+ {
52
+ key: "created_at",
53
+ node: "created_at",
54
+ label: "Created At",
55
+ type: "date",
56
+ },
57
+ ];
128
58
  ```
129
59
 
130
- ### Handling combination of two columns
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
- ## Props
62
+ #### Props
140
63
 
141
- 1. **columns**: An array of objects that define the columns in which the filters
142
- need to be applied. It requires the following the following keys (The columns
143
- marked with \* are required):
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
- - **node\***: The name of the column in the entity table.
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
- 2. **onChange**: A function that is called when the user updates the filters. It
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
- ### 2. SegmentMenu Component
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
- ```jsx
189
- <MenuBar showMenu={isMenuBarOpen} title="Neeto Filters">
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
- ```zsh
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
- ```zsh
93
+ ```bash
255
94
  git clone https://github.com/bigbinary/neeto-filters-engine.git
256
95
  ./test/dummy/bin/setup
257
96
  rails server