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

@ebi-gene-expression-group/scxa-faceted-search-results

v4.1.7

Published

Faceted experiments list for Single Cell Expression Atlas gene search results

Downloads

8

Readme

Faceted Search Results for Single Cell Expression Atlas

Build Status Coverage Status

A lightweight and extensible component to list and filter lists of search results. It receives a URL (as a combination of host and resource) to async-fetch the results, and a React component class to visualise each element (e.g. a card).

The only imposed contract is that the JSON payload contains a results array where each element is an object containing, in turn, a mandatory element object of arbitrary shape (the result itself) with an optional array of facets (objects with the fields group, value and label). The facets are used to render a sidebar on the left as a set of filtering controls. Filter groups can be displayed either as searchable, multiselect dropdown lists (the default), or as checkboxes.

The prop ResultElementClass must be coupled to the shape of your element objects to be shown correctly.

Two more optional props, namely noResultsMessageFormatter and resultsMessageFormatter, return a string which is displayed when there are no results, and as a header on top of the search results, respectively. In many occasions it is useful to display such messages using information returned by the server; that’s the reason why both functions take the JSON payload as an argument, allowing for some customisation in that regard. For example, if in the case of no results the server returns a field reason you could have something like this:

<ReactFacetedSearch
  ...
  noResultsMessageFormatter={(data) => `Your search yielded no results: ${data.reason}`}

The sidebar disables/hides options in order to avoid combinations that would produce empty results. However it is not 100% foolproof since you can arrive at a no results state by unchecking options, but disabling an already chosen facet can potentially lock the user without no apparent reason, resulting in bad UX.

Requirements

You should have node version at least 7 or later. You can check your current installed version executing this command.

npm --version
8.5.6

How to execute the unit tests with Cypress

We are using the Cypress framework for unit testing this package. You can execute the existing tests in the following way:

  1. Type npx cypress open in the terminal in the root folder of this package.
  2. In the appearing browser window you have to click on Component Testing, select a browser and click on Start Component Testing in <browser name>.
  3. In the appearing list just click on the test you would like to run and check the results on the screen.

Try out the component with a given example

Just run webpack-dev-server:

npx webpack-dev-server --mode=development

How to run test with code coverage in the console

Run tests with:

npx cypress run --component

If you want to omit video recording:

npx cypress run --component --record false

Find coverage reports at: ./coverage/lcov-report/index.html

Add code coverage (in a nutshell)

This is an abridged version of https://docs.cypress.io/guides/tooling/code-coverage.

Add the following three packages:

npm install -D babel-plugin-transform-class-properties babel-plugin-istanbul @cypress/code-coverage

Add the two plugins to your .babelrc file:

{
  "presets": ["@babel/preset-react", "@babel/preset-env"],
  "plugins": [ "transform-class-properties", "istanbul" ]
}

Add @cypress/code-coverage in your cypress.config.js file so it looks like this:

const { defineConfig } = require(`cypress`)

module.exports = defineConfig({
  component: {
    setupNodeEvents(on, config) {
      require(`@cypress/code-coverage/task`)(on, config)
      // include any other plugin code...

      // It's IMPORTANT to return the config object
      // with any changed environment variables
      return config
    },
    devServer: {
      framework: `react`,
      bundler: `webpack`
    }
  }
})

Lastly, add the following import to cypress/support/component.js:

import '@cypress/code-coverage/support'

Combining with the EBI Visual Framework

React-Select allows you to style the div that encloses the input element, but not the input element itself. Therefore it’s convenient to add the snippet below to override the styling set by the EBI Visual Framework for input elements.

.input-clear input, .input-clear input:focus {
  height: unset;
  box-shadow: none;
  margin: 0;
}

At the time of writing this applies to the most recent version (v1.3). Wrapping these styles within the appropriate div selector is sufficient. See https://github.com/ebi-gene-expression-group/scxa-faceted-search-results/blob/master/html/filter-list.html for a working example.

A note about building with Webpack

The component uses async/await to fetch the JSON payload from the server. This requires to prefix the entry with @babel/polyfill. If you are already using an equivalent polyfill or Runtime transform you may skip this.

Example

Demo here.

<div style={{border: `2px solid grey`, marginBottom: `0.5rem`, borderRadius: `4px`, padding: `0.25rem`}}>
  {title}
</div>
[
  {
    "element": {
      "title": "Raising Gazorpazorp"
    },
    "facets": [
      {
        "group": "Planet",
        "value": "gazorpazorp",
        "label": "Gazorpazorp"
      },
      {
        "group": "Guest character",
        "value": "gwendolyn",
        "label": "Gwendolyn"
      },
      {
        "group": "Guest character",
        "value": "ma-sha",
        "label": "Ma-Sha"
      },
      {
        "group": "Season",
        "value": "1",
        "label": "1"
      }
    ]
  },
  {
    "element": {
      "title": "The wedding squanchers"
    },
    "facets": [
      {
        "group": "Planet",
        "value": "squanch",
        "label": "Squanch"
      },
      {
        "group": "Guest character",
        "value": "birdperson",
        "label": "Birdperson"
      },
      {
        "group": "Guest character",
        "value": "squanchy",
        "label": "Squanchy"
      },
      {
        "group": "Season",
        "value": "2",
        "label": "2"
      }
    ]
  },
  {
    "element": {
      "title": "The Rickshank redemption"
    },
    "facets": [
      {
        "group": "Guest character",
        "value": "birdperson",
        "label": "Birdperson"
      },
      {
        "group": "Planet",
        "value": "buttworld",
        "label": "Buttworld"
      },
      {
        "group": "Season",
        "value": "3",
        "label": "3"
      }
    ]
  },
  {
    "element": {
      "title": "Ricksy business"
    },
    "facets": [
      {
        "group": "Guest character",
        "value": "squanchy",
        "label": "Squanchy"
      },
      {
        "group": "Guest character",
        "value": "abradolf_lincler",
        "label": "Abradolf Lincler"
      },
      {
        "group": "Season",
        "value": "1",
        "label": "1"
      }
    ]
  },
  {
    "element": {
      "title": "Close Rick-counters of the Rick kind"
    },
    "facets": [
      {
        "group": "Guest character",
        "value": "ricktiminus_sancheziminius",
        "label": "Ricktiminus Sancheziminius"
      },
      {
        "group": "Guest character",
        "value": "abradolf_lincler",
        "label": "Abradolf Lincler"
      },
      {
        "group": "Planet",
        "value": "buttworld",
        "label": "Buttworld"
      },
      {
        "group": "Season",
        "value": "1",
        "label": "1"
      }
    ]
  }
]

TODO

  • Refactor FetchLoader as a HOC. This makes it highly reusable and will let clients of this component get the results however they prefer.