UNPKG

@react-awesome-query-builder/core

Version:
150 lines (141 loc) 4.12 kB
import Immutable, { fromJS } from "immutable"; import { toImmutableList } from "../utils/stuff"; import * as constants from "../stores/constants"; import { defaultRuleProperties, defaultGroupProperties } from "../utils/defaultRuleUtils"; import uuid from "../utils/uuid"; /** * @param {object} config * @param {Immutable.Map} tree */ export var setTree = function setTree(config, tree) { return { type: constants.SET_TREE, tree: tree, config: config }; }; /** * @param {object} config * @param {Immutable.List} path * @param {Immutable.Map} properties */ export var addRule = function addRule(config, path, properties) { var ruleType = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "rule"; var children = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null; var parentRuleGroupField = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : null; return { type: constants.ADD_RULE, ruleType: ruleType, children: children, path: toImmutableList(path), id: uuid(), properties: defaultRuleProperties(config, parentRuleGroupField).merge(fromJS(properties) || {}), config: config, meta: { parentRuleGroupField: parentRuleGroupField } }; }; /** * @param {object} config * @param {Immutable.List} path */ export var removeRule = function removeRule(config, path) { return { type: constants.REMOVE_RULE, path: toImmutableList(path), config: config }; }; /** * @param {object} config * @param {Immutable.List} path * @param {Immutable.Map} properties */ export var addDefaultCaseGroup = function addDefaultCaseGroup(config, path, properties) { var children = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null; return { type: constants.ADD_CASE_GROUP, path: toImmutableList(path), children: children, id: uuid(), properties: defaultGroupProperties(config).merge(fromJS(properties) || {}), config: config, meta: { isDefaultCase: true } }; }; /** * @param {object} config * @param {Immutable.List} path * @param {Immutable.Map} properties */ export var addCaseGroup = function addCaseGroup(config, path, properties) { var children = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null; return { type: constants.ADD_CASE_GROUP, path: toImmutableList(path), children: children, id: uuid(), properties: defaultGroupProperties(config).merge(fromJS(properties) || {}), config: config }; }; /** * @param {object} config * @param {Immutable.List} path * @param {Immutable.Map} properties */ export var addGroup = function addGroup(config, path, properties) { var children = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null; var parentRuleGroupField = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null; return { type: constants.ADD_GROUP, path: toImmutableList(path), children: children, id: uuid(), properties: defaultGroupProperties(config, parentRuleGroupField).merge(fromJS(properties) || {}), config: config, meta: { parentRuleGroupField: parentRuleGroupField } }; }; /** * @param {object} config * @param {Immutable.List} path */ export var removeGroup = function removeGroup(config, path) { return { type: constants.REMOVE_GROUP, path: toImmutableList(path), config: config }; }; /** * @param {object} config * @param {Immutable.List} path */ export var removeGroupChildren = function removeGroupChildren(config, path) { return { type: constants.REMOVE_GROUP_CHILDREN, path: toImmutableList(path), config: config }; }; /** * @param {object} config * @param {Array} fromPath * @param {Array} toPath * @param {String} placement, see constants PLACEMENT_* */ export var moveItem = function moveItem(config, fromPath, toPath, placement) { return { type: constants.MOVE_ITEM, fromPath: toImmutableList(fromPath), toPath: toImmutableList(toPath), placement: placement, config: config }; };