npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

filterpanel

v1.0.61

Published

Filter a list of items by their combined attributes.

Downloads

86

Readme

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.