@react-awesome-query-builder-dev/ui
Version:
User-friendly query builder for React. Core React UI
79 lines • 3.49 kB
JavaScript
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _inherits from "@babel/runtime/helpers/inherits";
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
import { Utils } from "@react-awesome-query-builder-dev/core";
import React, { Component } from "react";
import PropTypes from "prop-types";
import { Item } from "./item/Item";
import SortableContainer from "./containers/SortableContainer";
import { pureShouldComponentUpdate } from "../utils/reactUtils";
var _Utils$TreeUtils = Utils.TreeUtils,
getTotalReordableNodesCountInTree = _Utils$TreeUtils.getTotalReordableNodesCountInTree,
getTotalRulesCountInTree = _Utils$TreeUtils.getTotalRulesCountInTree;
var _Utils$DefaultUtils = Utils.DefaultUtils,
createListWithOneElement = _Utils$DefaultUtils.createListWithOneElement,
emptyProperties = _Utils$DefaultUtils.emptyProperties;
var Builder = /*#__PURE__*/function (_Component) {
function Builder(props) {
var _this;
_classCallCheck(this, Builder);
_this = _callSuper(this, Builder, [props]);
_this.pureShouldComponentUpdate = pureShouldComponentUpdate(_this);
_this._updPath(props);
return _this;
}
_inherits(Builder, _Component);
return _createClass(Builder, [{
key: "shouldComponentUpdate",
value: function shouldComponentUpdate(nextProps, nextState) {
var should = this.pureShouldComponentUpdate(nextProps, nextState);
return should;
}
}, {
key: "_updPath",
value: function _updPath(props) {
var id = props.tree.get("id");
this.path = createListWithOneElement(id);
}
}, {
key: "render",
value: function render() {
var _this$props = this.props,
tree = _this$props.tree,
config = _this$props.config,
actions = _this$props.actions,
onDragStart = _this$props.onDragStart;
var rootType = tree.get("type");
var isTernary = rootType == "switch_group";
var reordableNodesCnt = isTernary ? null : getTotalReordableNodesCountInTree(tree);
var totalRulesCnt = isTernary ? null : getTotalRulesCountInTree(tree);
var id = tree.get("id");
return /*#__PURE__*/React.createElement(Item, {
key: id,
id: id,
path: this.path,
type: rootType,
properties: tree.get("properties") || emptyProperties(),
config: config,
actions: actions,
children1: tree.get("children1") || emptyProperties(),
reordableNodesCnt: reordableNodesCnt,
totalRulesCnt: totalRulesCnt,
parentReordableNodesCnt: 0,
onDragStart: onDragStart
});
}
}]);
}(Component);
Builder.propTypes = {
tree: PropTypes.any.isRequired,
//instanceOf(Immutable.Map)
config: PropTypes.object.isRequired,
actions: PropTypes.object.isRequired,
onDragStart: PropTypes.func
};
export default SortableContainer(Builder);