@bigbinary/neeto-rules-frontend 0.6.4 → 0.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -367,15 +367,13 @@ var getConditionsSchema = function getConditionsSchema(element) {
367
367
  field: yup.string().required(t$2("neetoRules.validations.required.condition")),
368
368
  metadata: yup.mixed().when(["field", "verb"], function (field, verb, schema) {
369
369
  var _selectedCondition$no;
370
- var selectedCondition = conditionOptions.find(function (option) {
371
- return option.value === field;
372
- });
370
+ var selectedCondition = findBy({
371
+ value: field
372
+ }, conditionOptions);
373
373
  var type = selectedCondition === null || selectedCondition === void 0 ? void 0 : selectedCondition.type;
374
374
  if (selectedCondition !== null && selectedCondition !== void 0 && selectedCondition.additionalData) {
375
375
  var value = selectedCondition === null || selectedCondition === void 0 ? void 0 : selectedCondition.additionalData[verb];
376
- if (value) {
377
- type = value;
378
- }
376
+ if (value) type = value;
379
377
  }
380
378
  if (selectedCondition !== null && selectedCondition !== void 0 && (_selectedCondition$no = selectedCondition.noValueForVerbs) !== null && _selectedCondition$no !== void 0 && _selectedCondition$no.includes(verb)) {
381
379
  return yup.object();
@@ -406,9 +404,11 @@ var getConditionsSchema = function getConditionsSchema(element) {
406
404
  }).required(t$2("neetoRules.validations.required.value"))
407
405
  });
408
406
  } else if ([CONDITION_VALUE_TYPES.number].includes(type)) {
409
- return yup.object().shape({
410
- value: yup.string().test("are-all-number", t$2("neetoRules.validations.positiveNumber"), function (value) {
411
- return POSITIVE_NUMBER_REGEX.test(value);
407
+ var message = selectedCondition !== null && selectedCondition !== void 0 && selectedCondition.onlyPositive ? t$2("neetoRules.validations.positiveNumber") : t$2("neetoRules.validations.number");
408
+ var regex = selectedCondition !== null && selectedCondition !== void 0 && selectedCondition.onlyPositive ? POSITIVE_NUMBER_REGEX : NUMBER_REGEX;
409
+ return yup.object({
410
+ value: yup.string().test("are-all-number", message, function (value) {
411
+ return regex.test(value);
412
412
  })
413
413
  });
414
414
  } else if ([CONDITION_VALUE_TYPES.url].includes(type)) {
@@ -423,9 +423,11 @@ var getConditionsSchema = function getConditionsSchema(element) {
423
423
  }).required(t$2("neetoRules.validations.required.value"))
424
424
  });
425
425
  } else if ([CONDITION_VALUE_TYPES.decimal].includes(type)) {
426
- return yup.object().shape({
427
- value: yup.string().test("are-all-number", t$2("neetoRules.validations.inValidDecimal"), function (value) {
428
- return DECIMAL_NUMBER_REGEX.test(value);
426
+ var _message = selectedCondition !== null && selectedCondition !== void 0 && selectedCondition.onlyPositive ? t$2("neetoRules.validations.positiveDecimal") : t$2("neetoRules.validations.decimal");
427
+ var _regex = selectedCondition !== null && selectedCondition !== void 0 && selectedCondition.onlyPositive ? POSITIVE_DECIMAL_NUMBER_REGEX : DECIMAL_NUMBER_REGEX;
428
+ return yup.object({
429
+ value: yup.string().test("are-all-number", _message, function (value) {
430
+ return _regex.test(value);
429
431
  }).required(t$2("neetoRules.validations.required.decimal"))
430
432
  });
431
433
  } else if ([CONDITION_VALUE_TYPES.textarea].includes(type)) {
@@ -509,15 +511,19 @@ var getActionsSchema = function getActionsSchema(element, customData) {
509
511
  }).required(t$2("neetoRules.validations.required.value"))
510
512
  });
511
513
  } else if ((selectedAction === null || selectedAction === void 0 ? void 0 : selectedAction.type) === ACTION_TYPES.number) {
514
+ var message = selectedAction !== null && selectedAction !== void 0 && selectedAction.onlyPositive ? t$2("neetoRules.validations.positiveNumber") : t$2("neetoRules.validations.number");
515
+ var regex = selectedAction !== null && selectedAction !== void 0 && selectedAction.onlyPositive ? POSITIVE_NUMBER_REGEX : NUMBER_REGEX;
512
516
  return yup.object({
513
- value: yup.string().test("are-all-number", t$2("neetoRules.validations.positiveNumber"), function (value) {
514
- return POSITIVE_NUMBER_REGEX.test(value);
517
+ value: yup.string().test("are-all-number", message, function (value) {
518
+ return regex.test(value);
515
519
  })
516
520
  });
517
521
  } else if ((selectedAction === null || selectedAction === void 0 ? void 0 : selectedAction.type) === ACTION_TYPES.decimal) {
522
+ var _message2 = selectedAction !== null && selectedAction !== void 0 && selectedAction.onlyPositive ? t$2("neetoRules.validations.positiveDecimal") : t$2("neetoRules.validations.decimal");
523
+ var _regex2 = selectedAction !== null && selectedAction !== void 0 && selectedAction.onlyPositive ? POSITIVE_DECIMAL_NUMBER_REGEX : DECIMAL_NUMBER_REGEX;
518
524
  return yup.object({
519
- value: yup.string().test("are-all-number", t$2("neetoRules.validations.inValidDecimal"), function (value) {
520
- return DECIMAL_NUMBER_REGEX.test(value);
525
+ value: yup.string().test("are-all-number", _message2, function (value) {
526
+ return _regex2.test(value);
521
527
  }).required(t$2("neetoRules.validations.required.decimal"))
522
528
  });
523
529
  } else if ((selectedAction === null || selectedAction === void 0 ? void 0 : selectedAction.type) === ACTION_TYPES.longText) {
@@ -569,8 +575,10 @@ var FIELD_TYPES = {
569
575
  };
570
576
  var MAXIMUM_OPTION_LENGTH$1 = 7;
571
577
  var VALIDATION_SCHEMA = (_VALIDATION_SCHEMA = {}, _defineProperty$1(_VALIDATION_SCHEMA, FIELD_TYPES.text, getSchemaForStrings), _defineProperty$1(_VALIDATION_SCHEMA, FIELD_TYPES.longText, getSchemaForStrings), _defineProperty$1(_VALIDATION_SCHEMA, FIELD_TYPES.dropdown, getSchemaForStrings), _defineProperty$1(_VALIDATION_SCHEMA, FIELD_TYPES.radio, getSchemaForStrings), _defineProperty$1(_VALIDATION_SCHEMA, FIELD_TYPES.events, getEventsSchema), _defineProperty$1(_VALIDATION_SCHEMA, FIELD_TYPES.condition, getConditionsSchema), _defineProperty$1(_VALIDATION_SCHEMA, FIELD_TYPES.actions, getActionsSchema), _defineProperty$1(_VALIDATION_SCHEMA, FIELD_TYPES.multiSelect, getSchemaForArray), _VALIDATION_SCHEMA);
572
- var DECIMAL_NUMBER_REGEX = /^\d*\.?\d+$/;
573
- var POSITIVE_NUMBER_REGEX = /^[0-9]+$/;
578
+ var DECIMAL_NUMBER_REGEX = /^-?\d*\.?\d+$/;
579
+ var NUMBER_REGEX = /^-?\d+$/;
580
+ var POSITIVE_DECIMAL_NUMBER_REGEX = /^\d*\.?\d+$/;
581
+ var POSITIVE_NUMBER_REGEX = /^\d+$/;
574
582
 
575
583
  function ownKeys$a(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; }
576
584
  function _objectSpread$9(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$a(Object(t), !0).forEach(function (r) { _defineProperty$1(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$a(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
@@ -12048,7 +12056,9 @@ var Conditions = function Conditions(_ref) {
12048
12056
  isCallback = _ref$isCallback === void 0 ? false : _ref$isCallback,
12049
12057
  previewCallback = _ref.previewCallback,
12050
12058
  _ref$isWithEvents = _ref.isWithEvents,
12051
- isWithEvents = _ref$isWithEvents === void 0 ? false : _ref$isWithEvents;
12059
+ isWithEvents = _ref$isWithEvents === void 0 ? false : _ref$isWithEvents,
12060
+ _ref$allowEmpty = _ref.allowEmpty,
12061
+ allowEmpty = _ref$allowEmpty === void 0 ? true : _ref$allowEmpty;
12052
12062
  var _useField = useField(name),
12053
12063
  _useField2 = _slicedToArray$1(_useField, 3),
12054
12064
  field = _useField2[0],
@@ -12113,8 +12123,8 @@ var Conditions = function Conditions(_ref) {
12113
12123
  }, index === conditions.length - 1 && /*#__PURE__*/React__default.createElement(Button, {
12114
12124
  "data-cy": "add-condition-button",
12115
12125
  icon: Plus,
12116
- size: 24,
12117
- style: "icon",
12126
+ size: "small",
12127
+ style: "text",
12118
12128
  tooltipProps: {
12119
12129
  content: t("neetoRules.form.addCondition"),
12120
12130
  position: "top"
@@ -12122,11 +12132,11 @@ var Conditions = function Conditions(_ref) {
12122
12132
  onClick: function onClick() {
12123
12133
  return handleAddCondition(arrayHelpers, condition.joinType);
12124
12134
  }
12125
- }), /*#__PURE__*/React__default.createElement(Button, {
12135
+ }), (allowEmpty || index !== 0) && /*#__PURE__*/React__default.createElement(Button, {
12126
12136
  "data-cy": "delete-condition-button-".concat(index),
12127
12137
  icon: Delete,
12128
- size: 24,
12129
- style: "icon",
12138
+ size: "small",
12139
+ style: "text",
12130
12140
  tooltipProps: {
12131
12141
  content: t("neetoRules.common.delete"),
12132
12142
  position: "top"