@bigbinary/neeto-rules-frontend 0.4.0 → 0.4.2

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.cjs.js CHANGED
@@ -20,6 +20,7 @@ var reactI18next = require('react-i18next');
20
20
  var neetoIcons = require('@bigbinary/neeto-icons');
21
21
  var ramda = require('ramda');
22
22
  var utils = require('@bigbinary/neeto-commons-frontend/utils');
23
+ var useHotkeys = require('@bigbinary/neeto-hotkeys');
23
24
 
24
25
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
25
26
 
@@ -45,6 +46,7 @@ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
45
46
  var classNames__default = /*#__PURE__*/_interopDefaultLegacy(classNames);
46
47
  var yup__namespace = /*#__PURE__*/_interopNamespace(yup);
47
48
  var PageLoader__default = /*#__PURE__*/_interopDefaultLegacy(PageLoader);
49
+ var useHotkeys__default = /*#__PURE__*/_interopDefaultLegacy(useHotkeys);
48
50
 
49
51
  function _objectDestructuringEmpty(obj) {
50
52
  if (obj == null) throw new TypeError("Cannot destructure " + obj);
@@ -1095,7 +1097,7 @@ var useOnButtonPressed = function useOnButtonPressed(ref, handler) {
1095
1097
  var buttonPressed = function buttonPressed() {
1096
1098
  var keysPressed = {};
1097
1099
  var listener = function listener(event) {
1098
- if (!ref.current) return;
1100
+ if (ramda.isNil(event.key)) return;
1099
1101
  keysPressed[event.key] = true;
1100
1102
  if ((keysPressed["Meta"] || keysPressed["Control"]) && event.key === "Enter") {
1101
1103
  handler();
@@ -1856,10 +1858,10 @@ var InlineInput = /*#__PURE__*/React__default["default"].forwardRef(function (pr
1856
1858
  useOnClickOutside(inputWrapperRef, function () {
1857
1859
  return handleCancel(inputValue);
1858
1860
  });
1859
- var inputFieldEscapeHotkeyRef = reactUtils.useHotKeys(SHORTCUTS.cancel.sequence, handleCancel, {
1861
+ var inputFieldEscapeHotkeyRef = useHotkeys__default["default"](SHORTCUTS.cancel.sequence, handleCancel, {
1860
1862
  mode: "scoped"
1861
1863
  });
1862
- var inputFieldEnterHotkeyRef = reactUtils.useHotKeys(SHORTCUTS.submit.sequence, onSubmit, {
1864
+ var inputFieldEnterHotkeyRef = useHotkeys__default["default"](SHORTCUTS.submit.sequence, onSubmit, {
1863
1865
  mode: "scoped"
1864
1866
  });
1865
1867
  React.useEffect(function () {
@@ -2353,8 +2355,10 @@ var ActionItem = function ActionItem(_ref) {
2353
2355
  elementProps = _ref.elementProps,
2354
2356
  onSelectAction = _ref.onSelectAction,
2355
2357
  selectedActionOptions = _ref.selectedActionOptions;
2358
+ var _useTranslation = reactI18next.useTranslation(),
2359
+ t = _useTranslation.t;
2356
2360
  var _useState = React.useState({
2357
- label: i18next.t("neetoRules.form.doThis")
2361
+ label: t("neetoRules.form.doThis")
2358
2362
  }),
2359
2363
  _useState2 = _slicedToArray(_useState, 2),
2360
2364
  selectedOption = _useState2[0],
@@ -2374,9 +2378,9 @@ var ActionItem = function ActionItem(_ref) {
2374
2378
  touched = _useFormikContext.touched;
2375
2379
  var optionList = elementProps.actionOptions;
2376
2380
  var actions = values[parentName].value || [];
2377
- var label = index ? i18next.t("neetoRules.common.and", {
2378
- what: i18next.t("neetoRules.common.then").toLowerCase()
2379
- }) : i18next.t("neetoRules.common.then");
2381
+ var label = index ? t("neetoRules.common.and", {
2382
+ what: t("neetoRules.common.then")
2383
+ }) : t("neetoRules.common.then");
2380
2384
  var actionOptions = React.useMemo(function () {
2381
2385
  return getActionOptions(action, actions, optionList);
2382
2386
  }, [action, actions]);
@@ -2384,7 +2388,7 @@ var ActionItem = function ActionItem(_ref) {
2384
2388
  return getFieldDetails$1(action.name, actionOptions);
2385
2389
  }, [action, actionOptions]);
2386
2390
  var searchedOptions = getSearchedOptions$3(actionOptions, searchTerm);
2387
- var isActionSelected = (selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.label) === i18next.t("neetoRules.form.doThis") && errors.actions && touched.actions && ramda.isNotNil((_errors$actions = errors.actions) === null || _errors$actions === void 0 || (_errors$actions = _errors$actions.value) === null || _errors$actions === void 0 ? void 0 : _errors$actions[index]) && ramda.isNotNil((_touched$actions = touched.actions) === null || _touched$actions === void 0 || (_touched$actions = _touched$actions.value) === null || _touched$actions === void 0 ? void 0 : _touched$actions[index]);
2391
+ var isActionSelected = (selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.label) === t("neetoRules.form.doThis") && errors.actions && touched.actions && ramda.isNotNil((_errors$actions = errors.actions) === null || _errors$actions === void 0 || (_errors$actions = _errors$actions.value) === null || _errors$actions === void 0 ? void 0 : _errors$actions[index]) && ramda.isNotNil((_touched$actions = touched.actions) === null || _touched$actions === void 0 || (_touched$actions = _touched$actions.value) === null || _touched$actions === void 0 ? void 0 : _touched$actions[index]);
2388
2392
  var handleSelectOption = function handleSelectOption(option) {
2389
2393
  setFieldValue("".concat(name, ".name"), option.value);
2390
2394
  setFieldValue("".concat(name, ".metadata"), {});
@@ -2404,7 +2408,8 @@ var ActionItem = function ActionItem(_ref) {
2404
2408
  }
2405
2409
  return [];
2406
2410
  };
2407
- var _ref2 = (action === null || action === void 0 ? void 0 : action.name) === "message_to_slack" && getSlackChannelErrors(getSelectedFieldOptions(), action),
2411
+ var isMessageToSlackAction = (action === null || action === void 0 ? void 0 : action.name) === "message_to_slack";
2412
+ var _ref2 = isMessageToSlackAction && getSlackChannelErrors(getSelectedFieldOptions(), action),
2408
2413
  selectDropDownHasError = _ref2.error,
2409
2414
  selectDropDownErrorMessage = _ref2.message;
2410
2415
  var findSelectedOption = function findSelectedOption() {
@@ -2412,18 +2417,35 @@ var ActionItem = function ActionItem(_ref) {
2412
2417
  value: selectedField === null || selectedField === void 0 ? void 0 : selectedField.value,
2413
2418
  label: selectedField === null || selectedField === void 0 ? void 0 : selectedField.label
2414
2419
  }) : setSelectedOption({
2415
- label: i18next.t("neetoRules.form.doThis")
2420
+ label: t("neetoRules.form.doThis")
2416
2421
  });
2417
2422
  };
2423
+ var _ref3 = selectedField || {},
2424
+ _ref3$isDisabled = _ref3.isDisabled,
2425
+ isDisabled = _ref3$isDisabled === void 0 ? false : _ref3$isDisabled,
2426
+ _ref3$disabledReason = _ref3.disabledReason,
2427
+ disabledReason = _ref3$disabledReason === void 0 ? "" : _ref3$disabledReason;
2428
+ var renderErrorCallout = function renderErrorCallout(message) {
2429
+ return /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
2430
+ className: "neeto-ui-text-white neeto-ui-bg-error-500 neeto-ui-rounded-sm -mx-4 w-full p-3",
2431
+ style: "h5"
2432
+ }, message);
2433
+ };
2434
+ var renderDisabledReason = function renderDisabledReason() {
2435
+ if (typeof disabledReason === "function") {
2436
+ return disabledReason(selectedField);
2437
+ }
2438
+ if (typeof disabledReason === "string" && neetoCist.isPresent(disabledReason)) {
2439
+ return renderErrorCallout(disabledReason);
2440
+ }
2441
+ return null;
2442
+ };
2418
2443
  React.useEffect(function () {
2419
2444
  findSelectedOption();
2420
2445
  }, [selectedField]);
2421
2446
  return /*#__PURE__*/React__default["default"].createElement("div", {
2422
2447
  className: "mb-1 flex max-w-2xl flex-wrap gap-x-1 gap-y-2"
2423
- }, selectDropDownHasError && /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
2424
- className: "neeto-ui-text-white neeto-ui-bg-error-500 neeto-ui-rounded-sm -mx-4 w-full p-3",
2425
- style: "h5"
2426
- }, selectDropDownErrorMessage), /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
2448
+ }, selectDropDownHasError && renderErrorCallout(selectDropDownErrorMessage), !isMessageToSlackAction && isDisabled && renderDisabledReason(), /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
2427
2449
  className: "neeto-ui-text-gray-700 mt-1",
2428
2450
  style: "h5",
2429
2451
  weight: "normal"
@@ -2452,7 +2474,7 @@ var ActionItem = function ActionItem(_ref) {
2452
2474
  autoFocus: true,
2453
2475
  className: "mb-1",
2454
2476
  "data-cy": "search-text-field",
2455
- placeholder: i18next.t("neetoRules.common.search"),
2477
+ placeholder: t("neetoRules.common.search"),
2456
2478
  prefix: /*#__PURE__*/React__default["default"].createElement(neetoIcons.Search, null),
2457
2479
  value: searchTerm,
2458
2480
  onChange: function onChange(e) {
@@ -2476,7 +2498,7 @@ var ActionItem = function ActionItem(_ref) {
2476
2498
  }, option.label);
2477
2499
  })), ramda.isEmpty(actionOptions) && /*#__PURE__*/React__default["default"].createElement(MenuItem$7.Button, {
2478
2500
  "data-cy": "no-options-menu-item"
2479
- }, i18next.t("neetoRules.common.noOptions")))), /*#__PURE__*/React__default["default"].createElement(ActionSubItem, {
2501
+ }, t("neetoRules.common.noOptions")))), /*#__PURE__*/React__default["default"].createElement(ActionSubItem, {
2480
2502
  action: action,
2481
2503
  index: index,
2482
2504
  selectedField: selectedField,