Gathering detailed insights and metrics for zero-awesome-query-builder-test
Gathering detailed insights and metrics for zero-awesome-query-builder-test
npm install zero-awesome-query-builder-test
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (76.25%)
TypeScript (21.28%)
SCSS (2%)
Shell (0.43%)
HTML (0.05%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
7,590
Last Day
3
Last Week
242
Last Month
531
Last Year
5,641
2,049 Stars
875 Commits
503 Forks
32 Watching
26 Branches
83 Contributors
Minified
Minified + Gzipped
Latest Version
0.1.4
Package Id
zero-awesome-query-builder-test@0.1.4
Unpacked Size
1.61 MB
Size
291.59 kB
File Count
345
NPM Version
6.14.16
Node Version
12.22.12
Cumulative downloads
Total Downloads
Last day
-94.1%
3
Compared to previous day
Last week
-15.7%
242
Compared to previous week
Last month
1,731%
531
Compared to previous month
Last year
528.9%
5,641
Compared to previous year
10
8
76
User-friendly React component to build queries.
Inspired by jQuery QueryBuilder
Using awesome Ant Design v4 for widgets
Now Material-UI is also supported!
Install:
npm i react-awesome-query-builder --save
For AntDesign widgets only:
npm i antd --save
For Material-UI widgets only:
npm i @material-ui/core @material-ui/lab @material-ui/icons @material-ui/pickers material-ui-confirm --save
See basic usage for minimum code example.
See API and config for documentation.
Demo apps:
npm start
- demo app with hot reload of demo code and local library code, uses TS, uses complex config to demonstrate anvanced usage.npm run sandbox-ts
- demo app with hot reload of only demo code (uses latest version of library from npm), uses TS, uses AntDesign widgets.npm run sandbox-js
- demo app with hot reload of only demo code (uses latest version of library from npm), not uses TS, uses vanilla widgets.1import React, {Component} from 'react'; 2import {Query, Builder, BasicConfig, Utils as QbUtils} from 'react-awesome-query-builder'; 3 4// For AntDesign widgets only: 5import AntdConfig from 'react-awesome-query-builder/lib/config/antd'; 6import 'antd/dist/antd.css'; // or import "react-awesome-query-builder/css/antd.less"; 7// For Material-UI widgets only: 8import MaterialConfig from 'react-awesome-query-builder/lib/config/material'; 9 10import 'react-awesome-query-builder/lib/css/styles.css'; 11import 'react-awesome-query-builder/lib/css/compact_styles.css'; //optional, for more compact styles 12 13// Choose your skin (ant/material/vanilla): 14const InitialConfig = AntdConfig; // or MaterialConfig or BasicConfig 15 16// You need to provide your own config. See below 'Config format' 17const config = { 18 ...InitialConfig, 19 fields: { 20 qty: { 21 label: 'Qty', 22 type: 'number', 23 fieldSettings: { 24 min: 0, 25 }, 26 valueSources: ['value'], 27 preferWidgets: ['number'], 28 }, 29 price: { 30 label: 'Price', 31 type: 'number', 32 valueSources: ['value'], 33 fieldSettings: { 34 min: 10, 35 max: 100, 36 }, 37 preferWidgets: ['slider', 'rangeslider'], 38 }, 39 color: { 40 label: 'Color', 41 type: 'select', 42 valueSources: ['value'], 43 fieldSettings: { 44 listValues: [ 45 { value: 'yellow', title: 'Yellow' }, 46 { value: 'green', title: 'Green' }, 47 { value: 'orange', title: 'Orange' } 48 ], 49 } 50 }, 51 is_promotion: { 52 label: 'Promo?', 53 type: 'boolean', 54 operators: ['equal'], 55 valueSources: ['value'], 56 }, 57 } 58}; 59 60// You can load query value from your backend storage (for saving see `Query.onChange()`) 61const queryValue = {"id": QbUtils.uuid(), "type": "group"}; 62 63 64class DemoQueryBuilder extends Component { 65 state = { 66 tree: QbUtils.checkTree(QbUtils.loadTree(queryValue), config), 67 config: config 68 }; 69 70 render = () => ( 71 <div> 72 <Query 73 {...config} 74 value={this.state.tree} 75 onChange={this.onChange} 76 renderBuilder={this.renderBuilder} 77 /> 78 {this.renderResult(this.state)} 79 </div> 80 ) 81 82 renderBuilder = (props) => ( 83 <div className="query-builder-container" style={{padding: '10px'}}> 84 <div className="query-builder qb-lite"> 85 <Builder {...props} /> 86 </div> 87 </div> 88 ) 89 90 renderResult = ({tree: immutableTree, config}) => ( 91 <div className="query-builder-result"> 92 <div>Query string: <pre>{JSON.stringify(QbUtils.queryString(immutableTree, config))}</pre></div> 93 <div>MongoDb query: <pre>{JSON.stringify(QbUtils.mongodbFormat(immutableTree, config))}</pre></div> 94 <div>SQL where: <pre>{JSON.stringify(QbUtils.sqlFormat(immutableTree, config))}</pre></div> 95 <div>JsonLogic: <pre>{JSON.stringify(QbUtils.jsonLogicFormat(immutableTree, config))}</pre></div> 96 </div> 97 ) 98 99 onChange = (immutableTree, config) => { 100 // Tip: for better performance you can apply `throttle` - see `examples/demo` 101 this.setState({tree: immutableTree, config: config}); 102 103 const jsonTree = QbUtils.getTree(immutableTree); 104 console.log(jsonTree); 105 // `jsonTree` can be saved to backend, and later loaded to `queryValue` 106 } 107}
1import React, { useState } from "react"; 2import { Query, Builder, Utils as QbUtils } from "react-awesome-query-builder"; 3// types 4import { 5 JsonGroup, 6 Config, 7 ImmutableTree, 8 BuilderProps 9} from "react-awesome-query-builder"; 10 11// For AntDesign widgets only: 12import AntdConfig from "react-awesome-query-builder/lib/config/antd"; 13import "antd/dist/antd.css"; // or import "react-awesome-query-builder/css/antd.less"; 14// For Material-UI widgets only: 15//import MaterialConfig from "react-awesome-query-builder/lib/config/material"; 16 17import "react-awesome-query-builder/lib/css/styles.css"; 18import "react-awesome-query-builder/lib/css/compact_styles.css"; //optional, for more compact styles 19 20// Choose your skin (ant/material/vanilla): 21const InitialConfig = AntdConfig; // or MaterialConfig or BasicConfig 22 23// You need to provide your own config. See below 'Config format' 24const config: Config = { 25 ...InitialConfig, 26 fields: { 27 qty: { 28 label: "Qty", 29 type: "number", 30 fieldSettings: { 31 min: 0 32 }, 33 valueSources: ["value"], 34 preferWidgets: ["number"] 35 }, 36 price: { 37 label: "Price", 38 type: "number", 39 valueSources: ["value"], 40 fieldSettings: { 41 min: 10, 42 max: 100 43 }, 44 preferWidgets: ["slider", "rangeslider"] 45 }, 46 color: { 47 label: "Color", 48 type: "select", 49 valueSources: ["value"], 50 fieldSettings: { 51 listValues: [ 52 { value: "yellow", title: "Yellow" }, 53 { value: "green", title: "Green" }, 54 { value: "orange", title: "Orange" } 55 ] 56 } 57 }, 58 is_promotion: { 59 label: "Promo?", 60 type: "boolean", 61 operators: ["equal"], 62 valueSources: ["value"] 63 } 64 } 65}; 66 67// You can load query value from your backend storage (for saving see `Query.onChange()`) 68const queryValue: JsonGroup = { id: QbUtils.uuid(), type: "group" }; 69 70export const Demo: React.FC = () => { 71 const [state, setState] = useState({ 72 tree: QbUtils.checkTree(QbUtils.loadTree(queryValue), config), 73 config: config 74 }); 75 76 const onChange = (immutableTree: ImmutableTree, config: Config) => { 77 // Tip: for better performance you can apply `throttle` - see `examples/demo` 78 setState({ tree: immutableTree, config: config }); 79 80 const jsonTree = QbUtils.getTree(immutableTree); 81 console.log(jsonTree); 82 // `jsonTree` can be saved to backend, and later loaded to `queryValue` 83 }; 84 85 const renderBuilder = (props: BuilderProps) => ( 86 <div className="query-builder-container" style={{ padding: "10px" }}> 87 <div className="query-builder qb-lite"> 88 <Builder {...props} /> 89 </div> 90 </div> 91 ); 92 93 return ( 94 <div> 95 <Query 96 {...config} 97 value={state.tree} 98 onChange={onChange} 99 renderBuilder={renderBuilder} 100 /> 101 <div className="query-builder-result"> 102 <div> 103 Query string:{" "} 104 <pre> 105 {JSON.stringify(QbUtils.queryString(state.tree, state.config))} 106 </pre> 107 </div> 108 <div> 109 MongoDb query:{" "} 110 <pre> 111 {JSON.stringify(QbUtils.mongodbFormat(state.tree, state.config))} 112 </pre> 113 </div> 114 <div> 115 SQL where:{" "} 116 <pre> 117 {JSON.stringify(QbUtils.sqlFormat(state.tree, state.config))} 118 </pre> 119 </div> 120 <div> 121 JsonLogic:{" "} 122 <pre> 123 {JSON.stringify(QbUtils.jsonLogicFormat(state.tree, state.config))} 124 </pre> 125 </div> 126 </div> 127 </div> 128 ); 129};
<Query />
Props:
{...config}
- destructured query CONFIG
value
- query value in internal Immutable formatonChange
- callback when value changed. Params: value
(in Immutable format), config
.renderBuilder
- function to render query builder itself. Takes 1 param props
you need to pass into <Builder {...props} />
.Notes:
<Dialog />
or <Popover />
, please:
disableEnforceFocus={true}
for dialog or popver.MuiPopover-root, .MuiDialog-root { z-index: 900 !important; }
(or 1000 for AntDesign v3)<Builder />
Render this component only inside Query.renderBuilder()
like in example above:
1 renderBuilder = (props) => ( 2 <div className="query-builder-container"> 3 <div className="query-builder qb-lite"> 4 <Builder {...props} /> 5 </div> 6 </div> 7 )
Wrapping <Builder />
in div.query-builder
is necessary.
Optionally you can add class .qb-lite
to it for showing action buttons (like delete rule/group, add, etc.) only on hover, which will look cleaner.
Wrapping in div.query-builder-container
is necessary if you put query builder inside scrollable block.
Utils
onChange
callback of <Query>
.light = false
in case if you want to store query value in your state in JS format and pass it as value
of <Query>
after applying loadTree()
(which is not recommended because of double conversion). See issue #190
value
prop to <Query>
(don't forget to also apply checkTree()
).
validateValue
in config, bad ranges) will be deleted if showErrorMessage
is false OR marked with errors if showErrorMessage
is true.
showErrorMessage
in config.settings is true, use this method to check is query has bad values.isForDisplay
= true can be used to make string more "human readable".
errors
, logic
will be rule object and data
will contain all used fields with null values ("template" data).This library uses configarion driven aprroach.
Config defines what value types, operators are supported, how they are rendered, imported, exported.
At minimum, you need to provide your own set of fields as in basic usage.
See CONFIG
for full documentation.
Versions 4.x are backward-compatible with 2.x and 3.x. It's recommended to update your version.
Version | Supported |
---|---|
4.x | :white_check_mark: |
3.x | :white_check_mark: |
2.x | :white_check_mark: |
1.x | :warning: |
0.x | :x: |
See CHANGELOG
From v2.0 of this lib AntDesign is now optional (peer) dependency, so you need to explicitly include antd
(4.x) in package.json
of your project if you want to use AntDesign UI.
Please import AntdConfig
from react-awesome-query-builder/lib/config/antd
and use it as base for your config (see below in usage).
Alternatively you can use BasicConfig
for simple vanilla UI, which is by default.
Support of other UI frameworks (like Bootstrap) are planned for future, see Other UI frameworks.
Clone this repo and run npm start
.
Open http://localhost:3001/
in a browser.
You will see demo app with hot reload of demo code and local library code.
modules
- Main source code of library
components
- Core React components
widgets
- Components to render list of fields, operators, values of different types. Built with UI frameworksconfig
- Basic config lives here. See CONFIG
docs.export
- Code for export to JsonLogic, MongoDb, SQL, ElasticSearch, plain stringimport
- Code for import from JsonLogicactions
- Redux actionsstores/tree.js
- Redux storeindex.d.ts
- TS definitionscss
- Styles for query builderexamples
- Demo app with hot reload of demo code and local library code, uses TS, uses complex config to demonstrate anvanced usage.sandbox
- Demo app with hot reload of only demo code (uses latest version of library from npm), uses TS, uses AntDesign widgets.sandbox_simple
- Demo app with hot reload of only demo code (uses latest version of library from npm), not uses TS, uses vanilla widgets.tests
- All tests are here. Uses Karma, Mocha, Chai, Enzymenpm run install-all
- Install npm packages in root, examples, sandboxes. Required for other scripts!npm test
- Run tests with Karma and update coverage. Requires Node.js v10+npm run lint
- Run ESLint and TSC (in root, tests, examples, sandboxes)npm run lint-fix
- Run ESLint with --fix
option (in root, tests, examples, sandboxes)npm run clean
- Clean all data that can be re-generated (like node_modules
, build
, coverage
)npm run smoke
- Run tests, lint, build lib, build examples, build sandboxes. Recommended before making PRnpm run build
- Build npm module to lib
, build minified production package to build
npm run build-examples
- Build demo with webpack to examples/build
Feel free to open PR to add new reusable types/widgets/operators (eg., regex operator for string, IP type & widget).
Pull Requests are always welcomed :)
Currently there are 3 collections of widgets:
Let's say you want to create new collection of Bootstrap widgets to be used in this lib (and submit PR which is always welcomed!).
You can use vanilla widgets as skeleton.
Then to enable new widgets you need to create config overrides like this:
material config
This project exists thanks to all the people who contribute. [Contribute].
Become a financial contributor and help us sustain our community. [Contribute]
Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]
react-awesome-query-builder is being sponsored by the following tool; please help to support us by taking a look and signing up to a free trial
MIT. See also LICENSE.txt
Forked from https://github.com/fubhy/react-query-builder
No vulnerabilities found.
Reason
30 commit(s) and 10 issue activity found in the last 90 days -- score normalized to 10
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
no binaries found in the repo
Reason
3 existing vulnerabilities detected
Details
Reason
Found 0/24 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More