@react-awesome-query-builder-dev/ui
Version:
User-friendly query builder for React. Core React UI
159 lines • 7.5 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/defineProperty";
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 _get from "@babel/runtime/helpers/get";
import _inherits from "@babel/runtime/helpers/inherits";
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
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; })(); }
function _superPropGet(t, o, e, r) { var p = _get(_getPrototypeOf(1 & r ? t.prototype : t), o, e); return 2 & r && "function" == typeof p ? function (t) { return p.apply(e, t); } : p; }
import React from "react";
import { Utils } from "@react-awesome-query-builder-dev/core";
import PropTypes from "prop-types";
import GroupContainer from "../containers/GroupContainer";
import Draggable from "../containers/Draggable";
import { BasicGroup } from "./Group";
import { SwitchGroupActions } from "./SwitchGroupActions";
import { Col, dummyFn, WithConfirmFn } from "../utils";
import classNames from "classnames";
var _Utils$TreeUtils = Utils.TreeUtils,
getTotalReordableNodesCountInTree = _Utils$TreeUtils.getTotalReordableNodesCountInTree,
getTotalRulesCountInTree = _Utils$TreeUtils.getTotalRulesCountInTree;
var SwitchGroup = /*#__PURE__*/function (_BasicGroup) {
function SwitchGroup(props) {
var _this;
_classCallCheck(this, SwitchGroup);
_this = _callSuper(this, SwitchGroup, [props]);
_this.childrenClassName = function () {
return "switch_group--children";
};
_this.renderFooterWrapper = function () {
return null;
};
_this.hasDefaultCase = function () {
var _this$props$children;
return ((_this$props$children = _this.props.children1) === null || _this$props$children === void 0 ? void 0 : _this$props$children.size) && _this.props.children1.filter(function (c) {
return c.get("children1") == null;
}).size > 0;
};
return _this;
}
_inherits(SwitchGroup, _BasicGroup);
return _createClass(SwitchGroup, [{
key: "onPropsChanged",
value: function onPropsChanged(nextProps) {
_superPropGet(SwitchGroup, "onPropsChanged", this, 3)([nextProps]);
}
}, {
key: "canAddGroup",
value: function canAddGroup() {
var _this$props$children2;
var maxNumberOfCases = this.props.config.settings.maxNumberOfCases;
var totalCasesCnt = ((_this$props$children2 = this.props.children1) === null || _this$props$children2 === void 0 ? void 0 : _this$props$children2.size) || 0;
if (maxNumberOfCases) {
return totalCasesCnt < maxNumberOfCases;
}
return true;
}
}, {
key: "canAddRule",
value: function canAddRule() {
return false;
}
}, {
key: "reordableNodesCnt",
value: function reordableNodesCnt() {
var _this$props$children3;
// result will be passed to each case's `parentReordableNodesCnt` prop
var totalCasesCnt = ((_this$props$children3 = this.props.children1) === null || _this$props$children3 === void 0 ? void 0 : _this$props$children3.size) || 0;
var casesToReorder = totalCasesCnt;
if (this.hasDefaultCase()) {
casesToReorder--;
}
return casesToReorder;
}
}, {
key: "totalRulesCntForItem",
value: function totalRulesCntForItem(item) {
return getTotalRulesCountInTree(item);
}
}, {
key: "reordableNodesCntForItem",
value: function reordableNodesCntForItem(item) {
var _this$props$children4;
if (this.props.isLocked) return 0;
var _this$props$config$se = this.props.config.settings,
canLeaveEmptyCase = _this$props$config$se.canLeaveEmptyCase,
canRegroupCases = _this$props$config$se.canRegroupCases;
var totalCasesCnt = ((_this$props$children4 = this.props.children1) === null || _this$props$children4 === void 0 ? void 0 : _this$props$children4.size) || 0;
var casesToReorder = totalCasesCnt;
if (this.hasDefaultCase()) {
casesToReorder--;
}
var nodesInCase = getTotalReordableNodesCountInTree(item);
var cnt = nodesInCase;
if (cnt == 1 && canRegroupCases && canLeaveEmptyCase && casesToReorder > 1) cnt = 111;
return cnt;
}
}, {
key: "showConjs",
value: function showConjs() {
// always show line from "If"
return true;
}
}, {
key: "renderHeaderWrapper",
value: function renderHeaderWrapper() {
return /*#__PURE__*/React.createElement("div", {
key: "group-header",
className: classNames("group--header", this.isOneChild() ? "one--child" : "", this.isOneChild() ? "hide--line" : "", this.isNoChildren() ? "no--children" : "", this.showDragIcon() ? "with--drag" : "hide--drag", this.showConjs() ? "with--conjs" : "hide--conjs")
}, this.renderHeader(), this.renderActions());
}
}, {
key: "renderHeader",
value: function renderHeader() {
return /*#__PURE__*/React.createElement("div", {
className: "group--conjunctions"
}, this.renderConjs(), this.renderDrag());
}
}, {
key: "renderConjs",
value: function renderConjs() {
var config = this.props.config;
var renderSwitchPrefix = config.settings.renderSwitchPrefix;
return renderSwitchPrefix || null;
}
}, {
key: "showNot",
value: function showNot() {
return false;
}
}, {
key: "renderActions",
value: function renderActions() {
var _this$props = this.props,
config = _this$props.config,
addCaseGroup = _this$props.addCaseGroup,
addDefaultCaseGroup = _this$props.addDefaultCaseGroup,
isLocked = _this$props.isLocked,
isTrueLocked = _this$props.isTrueLocked,
id = _this$props.id;
return /*#__PURE__*/React.createElement(SwitchGroupActions, {
config: config,
addCaseGroup: addCaseGroup,
addDefaultCaseGroup: addDefaultCaseGroup,
canAddDefault: !this.hasDefaultCase(),
canAddGroup: this.canAddGroup(),
setLock: this.setLock,
isLocked: isLocked,
isTrueLocked: isTrueLocked,
id: id
});
}
}]);
}(BasicGroup);
SwitchGroup.propTypes = _objectSpread({}, BasicGroup.propTypes);
export default GroupContainer(Draggable("group switch_group")(WithConfirmFn(SwitchGroup)), "switch_group");