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

react-filter-generator-form

v1.0.2

Published

Build your own filter query, define fields and type of content.

Downloads

9

Readme

React filter generator

This plugin is filter generator. You can create own fields and build logic by graphic creator. Live Preview: http://filtergenerator.wokay.me/

alt text

Quick start

1. Install Plugin

npm install react-filter-generator-form

2. Import component to script

import FilterBuilder from 'react-filter-generator-form'

3. Define fields to filter builder
 fieldsToFilter = [
     {
         label: "Name",
         name: "name",
         type: 'text'
     },
     {
         label: "Surname",
         name: "surname",
         type: 'text'
     },
     {
         label: "Id number",
         name: "id_number",
         type: 'number'
     }
 ]
4. Display/render component(filter generator) with added fields
          <FilterBuilder 
            fieldsToFilter={this.fieldsToFilter} />

Component 'FilterBuilder options'

fieldsToFilter - Here you can pass all fields and their types for generator. Example of use upper.

jsonLoad - You can pass previous generated json to recreate filter in creator

extraFields - Here you can define your own type of filter field or add operator for existing field. Example of value this option:

 extraFields = {
 //update existing type of field:
     "text": {
                "new operator" : {
                     "inputs": [
                         'value of new operator'
                     ]
                 },
             },
 //define new type of field
     someNewType:{
         "operator 1" : {
             "inputs": [
                 'subfield'
             ]
         },
         "operator 2" : {
             "inputs": [
                 'another sub field'
             ]
         },
     },
 }

Methods

Get Json Callback jsonCallback - Function which get data from existing form generator filter as argument. IMPORTANT YOU NEED TO USE REFS TO CONNECT TO FORM, EXAMPLE OF USE UNDER makeActionWhenJsonChange - Function which is autorun where you add/edit or delete sth in generator, function get in argument actuall json form

Examples

Example of use methods


 getJsonCallback(json){
        console.log("get actuall filter")
        console.log(this.refs.queryBuilder.getJson());
 }
 makeActionWhenJsonChange = (json) => {
        console.log("get changed filter")
 }
 
            <FilterBuilder
                ref="queryBuilder"
                makeActionWhenJsonChange={this.makeActionWhenJsonChange}
                jsonCallback={this.getJsonCallback}
                fieldsToFilter={this.fieldsToFilter} />
            <button onClick={()=>console.log(this.getJsonCallback())}>Show fields in console</button>

Example of use existing filter to recreate

Example of use custom fields

jsonToLoad = {
     "typeOfObject": "group",
     "condition": "AND",
     "organizationNumber": 1,
     "rules": [
         {
             "typeOfObject": "field",
             "operator": "between",
             "type": "date",
             "name": "birth_date",
             "organizationNumber": 2,
             "date": "",
             "from date": "12.09.2017",
             "to date": "11.09.2017"
         },
         {
             "typeOfObject": "group",
             "condition": "AND",
             "organizationNumber": 3,
             "rules": [
                 {
                     "typeOfObject": "field",
                     "operator": "equal",
                     "type": "text",
                     "name": "surname",
                     "organizationNumber": 4,
                     "value": "some surname"
                 },
                 {
                     "typeOfObject": "group",
                     "condition": "OR",
                     "organizationNumber": 15,
                     "rules": [
                         {
                             "typeOfObject": "field",
                             "operator": "less",
                             "type": "number",
                             "name": "id_number",
                             "organizationNumber": 16,
                             "number": "1"
                         },
                         {
                             "typeOfObject": "field",
                             "operator": "less",
                             "type": "number",
                             "name": "id_number",
                             "organizationNumber": 17,
                             "number": "2"
                         }
                     ]
                 }
             ]
         }
     ]
 }
    // jsonToLoad = {}
 fieldsToFilter = [
     {
         label: "Name",
         name: "name",
         type: 'text'
     },
     {
         label: "Another",
         name: "another",
         type: 'someNewType'
     },
 ]

 extraFields = {
     someNewType:{
         "another" : {
             "inputs": [
                 'value'
             ]
         },
         "some" : {
             "inputs": [
                 'value'
             ]
         },
     }
 }
 
 <FilterBuilder 
      json_load={this.jsonToLoad}
      extraFields={this.extraFields}
      fieldsToFilter={this.fieldsToFilter} />
             

License

GNU 3.0

Author

Krzysztof Łokaj "Wokay"

  • Blog https://wokay.me/
  • Twitter https://twitter.com/_Wokay
  • Linkedin https://www.linkedin.com/in/wokay/

Inspired by

jQuery-QueryBuilder - https://github.com/mistic100/jQuery-QueryBuilder

P.S. I found to late(after i finish write whole code) because there wasn't any connection on main website. User pavanpodila did it before me: https://www.npmjs.com/package/react-querybuilder using that jquery plugin. Check out his solution. Good job mate!