1.0.61 • Published 3 years ago

filterpanel v1.0.61

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

This is a Next.js project bootstrapped with create-next-app.

filterpanel

This is an npm package that exports a react component that generates a filter panel from a table of data. Filter panels are used by Amazon, Walmart, and many other e-commerce sites.

Installation:

  npm install filterpanel --save

Intro and examples

https://filterpanel-csv.vercel.app/

Definitions

Feature filters are the blocks of checkboxes in the filter panel UI.

The filter panel is the container for all the feature filters.

The problem

This looks easy at first glance. If nothing is checked, a feature filter passes everything. If any categories are checked, it passes only the items that match one or more of them. The features must all pass an item for it to be in the working set.

So far, this can be handled by a straightforward SQL query.

The problem is due to other requirements. The feature filters are not supposed to be static. They react to the selections made on other filters. Every click on a checkbox changes the working set, which means the counts in each feature filter must be updated.

A subtle point is that the filter must not update itself. Clicking on checkboxes within a feature filter should not change the filter's own display. The same checkboxes need to remain on screen, allowing the user to combine the current selection with other values to increase the working set.

The solution here assigns some responsibilities to the panel, which contains the feature filters, and others to the filters themselves. The panel is responsible for aggregating the results of the feature filters and updating them with the aggregated data. The "no-self-update" requirement means that each filter needs to get its own version of the working set, leaving out any restrictions caused by that filter.

The feature filters need to update counts using the data received from the panel. They also need to scan the working set to add or remove items.

It would be possible, but awkward and probably slow, to do this using arrays of items. Add or remove items from the array. Make different arrays for each filter.

Instead, it's done here using document masks, which are boolean arrays with one element for each input record. The value is true if the item belongs in the working set, false if not. This makes it quick to flip items on or off and easy to merge the results of several filters. Each filter has one such array for logging its output, the output mask. This array is managed by React useState, and sent up to the panel using a callback. The panel has an array of arrays, one for each filter, also managed by useState. From the filter's point of view, these are the input masks. When a filter's input mask changes, it will render the new counts.

1.0.61

3 years ago

1.0.60

3 years ago

1.0.59

3 years ago

1.0.58

3 years ago

1.0.57

3 years ago

1.0.56

3 years ago

1.0.55

3 years ago

1.0.54

3 years ago

1.0.44

3 years ago

1.0.43

3 years ago

1.0.42

3 years ago

1.0.48

3 years ago

1.0.47

3 years ago

1.0.46

3 years ago

1.0.45

3 years ago

1.0.49

3 years ago

1.0.51

3 years ago

1.0.50

3 years ago

1.0.53

3 years ago

1.0.52

3 years ago

1.0.41

3 years ago

1.0.39

3 years ago

1.0.38

3 years ago

1.0.40

3 years ago

1.0.37

3 years ago

1.0.36

3 years ago

1.0.35

3 years ago

1.0.34

3 years ago

1.0.33

3 years ago

1.0.32

3 years ago

1.0.31

3 years ago

1.0.30

3 years ago

1.0.29

3 years ago

1.0.28

3 years ago

1.0.27

3 years ago

1.0.26

3 years ago

1.0.25

3 years ago

1.0.24

3 years ago

1.0.23

3 years ago

1.0.22

3 years ago

1.0.21

3 years ago

1.0.20

3 years ago

1.0.19

3 years ago

1.0.18

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago