/*eslint @typescript-eslint/no-unused-vars: ["off", {"varsIgnorePattern": "^_"}]*/ import React, {Component} from "react"; import { Query, Builder, Utils, //types: ImmutableTree, Config, BuilderProps, JsonTree, JsonLogicTree } from "react-awesome-query-builder"; import throttle from "lodash/throttle"; import loadedConfig from "./config_simple"; // <- you can try './config' for more complex examples import loadedInitValue from "./init_value"; import loadedInitLogic from "./init_logic"; const stringify = JSON.stringify; const {queryBuilderFormat, jsonLogicFormat, queryString, mongodbFormat, sqlFormat, getTree, checkTree, loadTree, uuid, loadFromJsonLogic} = Utils; const preStyle = { backgroundColor: "darkgrey", margin: "10px", padding: "10px" }; const preErrorStyle = { backgroundColor: "lightpink", margin: "10px", padding: "10px" }; const emptyInitValue: JsonTree = {"id": uuid(), "type": "group"}; // get init value in JsonTree format: const initValue: JsonTree = loadedInitValue && Object.keys(loadedInitValue).length > 0 ? loadedInitValue as JsonTree : emptyInitValue; const initTree: ImmutableTree = checkTree(loadTree(initValue), loadedConfig); // -OR- alternativaly get init value in JsonLogic format: //const initLogic: JsonLogicTree = loadedInitLogic && Object.keys(loadedInitLogic).length > 0 ? loadedInitLogic : undefined; //const initTree: ImmutableTree = checkTree(loadFromJsonLogic(initLogic, loadedConfig), loadedConfig); interface DemoQueryBuilderState { tree: ImmutableTree; config: Config; } export default class DemoQueryBuilder extends Component<{}, DemoQueryBuilderState> { private immutableTree: ImmutableTree; private config: Config; state = { tree: initTree, config: loadedConfig }; render = () => (
{stringify(queryString(immutableTree, config), undefined, 2)}
{stringify(queryString(immutableTree, config, true), undefined, 2)}
{stringify(sqlFormat(immutableTree, config), undefined, 2)}
{stringify(mongodbFormat(immutableTree, config), undefined, 2)}
{stringify(errors, undefined, 2)}
}
{ !!logic
&&
{"// Rule"}:
{stringify(logic, undefined, 2)}
{"// Data"}:
{stringify(data, undefined, 2)}
}
{stringify(getTree(immutableTree), undefined, 2)}