strategyUtil.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.SHOW_PARENT = exports.SHOW_CHILD = exports.SHOW_ALL = void 0;
  6. exports.formatStrategyValues = formatStrategyValues;
  7. var _valueUtil = require("./valueUtil");
  8. const SHOW_ALL = exports.SHOW_ALL = 'SHOW_ALL';
  9. const SHOW_PARENT = exports.SHOW_PARENT = 'SHOW_PARENT';
  10. const SHOW_CHILD = exports.SHOW_CHILD = 'SHOW_CHILD';
  11. function formatStrategyValues(values, strategy, keyEntities, fieldNames) {
  12. const valueSet = new Set(values);
  13. if (strategy === SHOW_CHILD) {
  14. return values.filter(key => {
  15. const entity = keyEntities[key];
  16. if (entity && entity.children && entity.children.some(_ref => {
  17. let {
  18. node
  19. } = _ref;
  20. return valueSet.has(node[fieldNames.value]);
  21. }) && entity.children.every(_ref2 => {
  22. let {
  23. node
  24. } = _ref2;
  25. return (0, _valueUtil.isCheckDisabled)(node) || valueSet.has(node[fieldNames.value]);
  26. })) {
  27. return false;
  28. }
  29. return true;
  30. });
  31. }
  32. if (strategy === SHOW_PARENT) {
  33. return values.filter(key => {
  34. const entity = keyEntities[key];
  35. const parent = entity ? entity.parent : null;
  36. if (parent && !(0, _valueUtil.isCheckDisabled)(parent.node) && valueSet.has(parent.key)) {
  37. return false;
  38. }
  39. return true;
  40. });
  41. }
  42. return values;
  43. }