@bigbinary/neeto-filters-frontend 3.0.4 → 3.0.6

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 CHANGED
@@ -1,8 +1,13 @@
1
- # @bigbinary/neeto-filters-frontend
1
+ # neeto-filters-nano
2
+
3
+ 1. [Engine and package installation](./docs/engine-and-package-installation.md)
4
+ 2. [Building and releasing](./docs/building-and-releasing.md)
5
+
6
+ ## @bigbinary/neeto-filters-frontend
2
7
 
3
8
  neetoFilters is the library that manages filters across neeto products.
4
9
 
5
- ## Installation
10
+ ### Installation
6
11
 
7
12
  ```bash
8
13
  yarn add @bigbinary/neeto-filters-frontend
@@ -16,12 +21,12 @@ command:
16
21
  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
17
22
  ```
18
23
 
19
- ## Usage
24
+ ### Usage
20
25
 
21
26
  neeto-filters-frontend exports 2 components (`Filters` & `Bar`) and 2 functions
22
27
  (`buildFiltersFromURL()` & `buildSelectorsFromURL()`).
23
28
 
24
- ### 1. `Filters` component
29
+ #### 1. `Filters` component
25
30
 
26
31
  #### Props
27
32
 
@@ -175,7 +180,7 @@ When user selects a value from this dropdown we get that value in the
175
180
  `selectors` state. This can be used for further computations outside the
176
181
  neeto-filters.
177
182
 
178
- ### 2. `Bar` component
183
+ #### 2. `Bar` component
179
184
 
180
185
  #### Props
181
186
 
@@ -193,12 +198,14 @@ neeto-filters.
193
198
  7. **childrenKeys** The list of keys which has to be cleared from url during
194
199
  clear filters operation.
195
200
  8. **entity**: The entity associated with the filters.
201
+ 9. **defaultSegmentName**: The name of segment which results all entities
202
+ without applying any filter. Default name is "All results".
196
203
 
197
204
  All these props must be same as that passed to the `Filters` component. The
198
205
  option to save filters as segments will be enabled only when the entity prop is
199
206
  passed to the component.
200
207
 
201
- ### 3. `Segments` component
208
+ #### 3. `Segments` component
202
209
 
203
210
  #### Props
204
211
 
@@ -206,13 +213,15 @@ passed to the component.
206
213
  filters pane.
207
214
  2. **entity**: The entity associated with the segments.
208
215
  3. **setIsPaneOpen**: To trigger the isOpen state of the filters pane.
216
+ 4. **defaultSegmentName**: The name of segment which results all entities
217
+ without applying any filter. Default name is "All results".
209
218
 
210
219
  The "columns" prop must be same as that passed to the `Filters` component. To
211
220
  set up the neeto-filters-engine with support for Segments, please follow the
212
221
  instructions provided in the installation
213
222
  [documentation](https://github.com/bigbinary/neeto-filters-engine#installation).
214
223
 
215
- ### 3. `buildFiltersFromURL` function
224
+ #### 3. `buildFiltersFromURL` function
216
225
 
217
226
  - This function takes a list as argument.
218
227
  - This list should contains all the filter columns/fields and the value passed
@@ -226,7 +235,7 @@ const [filters, setFilters] = useState(() =>
226
235
  );
227
236
  ```
228
237
 
229
- ### 4. `buildSelectorsFromURL` function
238
+ #### 4. `buildSelectorsFromURL` function
230
239
 
231
240
  - By `selectors` we mean the filter fields which doesn't have any relation
232
241
  (`node`) to a DB table column.
@@ -249,7 +258,7 @@ const [selectors, setSelectors] = useState(() =>
249
258
  );
250
259
  ```
251
260
 
252
- ### 5. `buildFilterColumnsFromFields` function
261
+ #### 5. `buildFilterColumnsFromFields` function
253
262
 
254
263
  The `buildFilterColumnsFromFields` function is used to generate an array of
255
264
  filter columns based on the provided fields (often referred as custom fields)
@@ -285,44 +294,212 @@ const selectedFields = ["name", "age"];
285
294
  const filterColumns = buildFilterColumnsFromFields({ fields, selectedFields });
286
295
  ```
287
296
 
288
- ## Development
297
+ ## neeto-filters-engine
289
298
 
290
- Install all the dependencies by executing the following command
299
+ neeto_filters is a Ruby gem that manages filters across neeto products. It
300
+ allows the users to filter entities with respect to its columns, associated
301
+ columns, or custom attributes. It is best used along with the
302
+ [neeto-filters-frontend](https://github.com/bigbinary/neeto-filters-frontend)
303
+ npm package.
291
304
 
292
- ```bash
293
- yarn install
305
+ ### Installation
306
+
307
+ 1. Add the following line to your application's Gemfile:
308
+
309
+ ```zsh
310
+ gem "neeto-filters-engine", git: "https://github.com/bigbinary/neeto-filters-engine", branch: "stable"
294
311
  ```
295
312
 
296
- Start the development server using the `yarn start` command. In order to run the
297
- application you need to run the Rails server of the
298
- [neeto-filters-engine](https://github.com/bigbinary/neeto-filters-engine)'s
299
- dummy application as well. This is necessary to make sure that all the APIs and
300
- React Query hooks are working as per the requirement.
313
+ 2. Execute the following command:
301
314
 
302
- ```bash
303
- git clone https://github.com/bigbinary/neeto-filters-engine.git
304
- ./test/dummy/bin/setup
305
- rails server
315
+ ```zsh
316
+ bundle install
317
+ ```
318
+
319
+ 3. Add the following line to `config/routes.rb` file to mount the engine at
320
+ `/neeto_filters` route.
321
+
322
+ ```ruby
323
+ mount NeetoFiltersEngine::Engine, at: "/neeto_filters"
324
+ ```
325
+
326
+ 4. Add the following line to `models/organization.rb` file.
327
+
328
+ ```ruby
329
+ has_many :segments, class_name: "NeetoFiltersEngine::Segment", dependent: :destroy
330
+ ```
331
+
332
+ 5. Execute the following command to generate the migration to generate the
333
+ `neeto_filters_engine_segments` table. This table stores all the saved
334
+ segments.
335
+
336
+ ```zsh
337
+ rails g neeto_filters_engine:install
338
+ ```
339
+
340
+ #### Verify that the installation is successful.
341
+
342
+ - Assume that there is a `users` table with the `User` model associated with it.
343
+ It a `email` column of type `string` or `text`.
344
+ - Open Rails console and add the following lines:
345
+
346
+ ```ruby
347
+ filters = [
348
+ {
349
+ "conditions": [
350
+ {
351
+ "node": "email",
352
+ "label": "Email Address",
353
+ "type": "text",
354
+ "rule": "contains",
355
+ "value": "example",
356
+ "conditions_join_type": "AND"
357
+ },
358
+ ],
359
+ "group_join_type": "OR"
360
+ },
361
+ ]
362
+
363
+ User.all.apply_neeto_filters(filters)
306
364
  ```
307
365
 
308
- # Building and releasing.
309
-
310
- The `@bigbinary/neeto-filters-frontend` package gets published to NPM when we
311
- merge a PR with `patch`, `minor` or `major` label to the `main` branch. The
312
- `patch` label is used for bug fixes, `minor` label is used for new features and
313
- `major` label is used for breaking changes. You can checkout the
314
- `Create and publish releases` workflow in GitHub Actions to get a live update.
315
-
316
- In case if you missed to add the label, you can manually publish the package.
317
- For that first you need to create a PR to update the version number in the
318
- `package.json` file and merge it to the `main` branch. After merging the PR, you
319
- need to create a
320
- [new github release](https://github.com/bigbinary/neeto-filters-frontend/releases/new)
321
- from main branch. Whenever a new release is created with a new version number,
322
- the github actions will automatically publish the built package to npm. You can
323
- checkout the `Publish to npm` workflow in GitHub Actions to get a live update.
324
-
325
- Please note that before publishing the package, you need to verify the
326
- functionality in some of the neeto web-apps locally using `yalc` package
327
- manager. The usage of yalc is explained in this video:
328
- https://youtu.be/QBiYGP0Rhe0
366
+ - If the above lines returns zero or more users, the installation is successful.
367
+
368
+ ### Usage
369
+
370
+ Here is an example of how to use the `neeto-filters-engine` gem assuming that
371
+ the `users` table has been created.
372
+
373
+ ```rb
374
+ class HomeController < ApplicationController
375
+ before_action :load_users
376
+
377
+ def index
378
+ @filtered_users = @users.apply_neeto_filters(params[:filters])
379
+ @total_count = @filtered_users.count
380
+ end
381
+
382
+ private
383
+
384
+ def load_users
385
+ @users = @organization.users
386
+ end
387
+ end
388
+ ```
389
+
390
+ Note: If you wish to use `select()` method after calling
391
+ `apply_neeto_filters()`, please note to use `reselect()` since neeto-filters
392
+ itself performs a 'select' operation internally.
393
+
394
+ Here, the param `filters` is a hash with the following structure, where each
395
+ `node` corresponds to a column in the `users` table.
396
+
397
+ ```json
398
+ [
399
+ {
400
+ "conditions": [
401
+ {
402
+ "node": "email",
403
+ "label": "Email Address",
404
+ "type": "text",
405
+ "rule": "contains",
406
+ "value": "bigbinary",
407
+ "conditions_join_type": "AND"
408
+ },
409
+ {
410
+ "node": "timezone",
411
+ "label": "Timezone",
412
+ "type": "text",
413
+ "rule": "is",
414
+ "value": "Asia/Kolkata",
415
+ "conditions_join_type": "AND"
416
+ }
417
+ ],
418
+ "group_join_type": "OR"
419
+ },
420
+ {
421
+ "conditions": [
422
+ {
423
+ "node": "age",
424
+ "label": "Age",
425
+ "type": "number",
426
+ "rule": "greater_than",
427
+ "value": "18",
428
+ "conditions_join_type": "AND"
429
+ }
430
+ ],
431
+ "group_join_type": "AND"
432
+ }
433
+ ]
434
+ ```
435
+
436
+ The gem filters the users based on the conditions in the `filters` param. In
437
+ this case, all the users whose email address contains `bigbinary` in the
438
+ `Asia/Kolkata` timezone or whose age is greater than 18 will be filtered.
439
+
440
+ ### How It Works
441
+
442
+ #### Base Types
443
+
444
+ - Base Types refers to the columns that are directly present in the table on
445
+ which the `apply_neeto_filters` method is called.
446
+ - Refer to this video for an overview of the same.
447
+
448
+ https://vimeo.com/724478910/e349e361bd
449
+
450
+ #### Custom Types
451
+
452
+ - Some projects will have custom attributes to the tables that will be added or
453
+ updated dynamically. `NeetoFiltersEngine` can handle these attributes by
454
+ passing the proper filters to the `apply_neeto_filters` method.
455
+ - The implementation of custom attributes is different for different projects.
456
+ `NeetoFiltersEngine` is built in the same way as `neetoCRM`. If the custom
457
+ attributes feature needs to be added to a project where the custom attributes
458
+ implementation is different, you need to override the
459
+ `NeetoFiltersEngine::Custom::BaseSearchService` class specifiying the proper
460
+ join operations.
461
+ - Refer to the below video for an overview of the same.
462
+
463
+ https://vimeo.com/724489868/94dfc6cd43
464
+
465
+ #### Associated Types
466
+
467
+ - Associated types refer to the the columns that are not directly present in the
468
+ table on which the `apply_neeto_filters` method is applied. Instead these will
469
+ be present in another table to which the first table has a foreign key to. For
470
+ instance, the `deals` table can have an association with the `companies` table
471
+ and the company name can be displayed in the UI. `NeetoFiltersEngine` can be
472
+ used to filter these columns by properly specifying the filters.
473
+ - Refer to te below video for an overview of the same.
474
+
475
+ https://vimeo.com/724484259/f305257f37
476
+
477
+ #### Adding a new type
478
+
479
+ - `NeetoFiltersEngine` provides the following types: `text`, `number`,
480
+ `single_option`, `multi_option`, `date`, `time`, `datetime`, `date_range`, and
481
+ `time_range`.
482
+ - Sometimes we need to filter attributes that are not present in the available
483
+ types. In this case a new type needs to be created.
484
+ - In this case, the type needs to be specified to the NPM package by passing the
485
+ `type` name and `filters` prop in the list of columns. The corresponding
486
+ search service must be created in the `app/services/neeto_filters/` folder as
487
+ well.
488
+ - Refer to te below video for an overview of the same.
489
+
490
+ https://vimeo.com/724499299/09e2231780
491
+
492
+ #### Working with Dates
493
+
494
+ - Working with dates is tricky due to the involvement of timezones.
495
+ - Refer to the below video for a quick overview of the same.
496
+
497
+ https://vimeo.com/724495909/034668f738
498
+
499
+ ## Integrations
500
+
501
+ | Project | Routes |
502
+ | -------------- | --------------------------------------------- |
503
+ | neeto-chat-web | /admin/contacts |
504
+ | neeto-crm-web | /deals, /contacts, /companies, /tasks, /mails |
505
+ | neeto-cal-web | /meetings, /scheduled-meetings |
@@ -14,7 +14,8 @@
14
14
  "userCount": "{{count}} Users",
15
15
  "yes": "Yes",
16
16
  "update": "Update",
17
- "searchTerm": "Search term"
17
+ "searchTerm": "Search term",
18
+ "allResults": "All results"
18
19
  },
19
20
  "messages": {
20
21
  "enterResource": "Enter {{resource}}",
@@ -58,7 +59,8 @@
58
59
  "showLess": "See less",
59
60
  "showMoreNumbers": "See {{entity}} more",
60
61
  "updateSegment": "Update segment?",
61
- "updateSegmentMessage": "You are trying to update the current segment."
62
+ "updateSegmentMessage": "You are trying to update the current segment.",
63
+ "reservedNameErrorMessage": "This name is reserved. Please choose another name."
62
64
  },
63
65
  "labels": {
64
66
  "keyword": "Keyword"