@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.js CHANGED
@@ -3,19 +3,20 @@ import { BrowserRouter } from 'react-router-dom';
3
3
  import { shallow } from 'zustand/shallow';
4
4
  import classNames from 'classnames';
5
5
  import { useFormikContext, Formik, Form, useField, FieldArray, ErrorMessage } from 'formik';
6
- import { findBy, noop, isNotEmpty, toLabelAndValue, removeBy } from '@bigbinary/neeto-cist';
6
+ import { findBy, noop, isNotEmpty, isPresent, toLabelAndValue, removeBy } from '@bigbinary/neeto-cist';
7
7
  import { ActionBlock, Textarea, MultiEmailInput, Input as Input$2, Select as Select$1, Radio } from '@bigbinary/neetoui/formik';
8
8
  import { t as t$1 } from 'i18next';
9
9
  import * as yup from 'yup';
10
10
  import { isEditorEmpty, FormikEditor } from '@bigbinary/neeto-editor';
11
- import { withImmutableActions, useDebounce, useHotKeys } from '@bigbinary/neeto-commons-frontend/react-utils';
11
+ import { withImmutableActions, useDebounce } from '@bigbinary/neeto-commons-frontend/react-utils';
12
12
  import { create } from 'zustand';
13
13
  import PageLoader from '@bigbinary/neeto-molecules/PageLoader';
14
14
  import { Typography, Button, Pane, DatePicker, Dropdown as Dropdown$1, Input as Input$1, Checkbox, Select, Label } from '@bigbinary/neetoui';
15
15
  import { useTranslation } from 'react-i18next';
16
16
  import { Down, Up, Check, Search, Close, Delete, Plus, Refresh, Eye } from '@bigbinary/neeto-icons';
17
- import { pluck, isNotNil, assocPath, toLower, isEmpty, isNil, without, append, pipe, partition } from 'ramda';
17
+ import { pluck, isNil, isNotNil, assocPath, toLower, isEmpty, without, append, pipe, partition } from 'ramda';
18
18
  import { joinHyphenCase } from '@bigbinary/neeto-commons-frontend/utils';
19
+ import useHotkeys from '@bigbinary/neeto-hotkeys';
19
20
 
20
21
  function _objectDestructuringEmpty(obj) {
21
22
  if (obj == null) throw new TypeError("Cannot destructure " + obj);
@@ -1066,7 +1067,7 @@ var useOnButtonPressed = function useOnButtonPressed(ref, handler) {
1066
1067
  var buttonPressed = function buttonPressed() {
1067
1068
  var keysPressed = {};
1068
1069
  var listener = function listener(event) {
1069
- if (!ref.current) return;
1070
+ if (isNil(event.key)) return;
1070
1071
  keysPressed[event.key] = true;
1071
1072
  if ((keysPressed["Meta"] || keysPressed["Control"]) && event.key === "Enter") {
1072
1073
  handler();
@@ -1827,10 +1828,10 @@ var InlineInput = /*#__PURE__*/React.forwardRef(function (props, ref) {
1827
1828
  useOnClickOutside(inputWrapperRef, function () {
1828
1829
  return handleCancel(inputValue);
1829
1830
  });
1830
- var inputFieldEscapeHotkeyRef = useHotKeys(SHORTCUTS.cancel.sequence, handleCancel, {
1831
+ var inputFieldEscapeHotkeyRef = useHotkeys(SHORTCUTS.cancel.sequence, handleCancel, {
1831
1832
  mode: "scoped"
1832
1833
  });
1833
- var inputFieldEnterHotkeyRef = useHotKeys(SHORTCUTS.submit.sequence, onSubmit, {
1834
+ var inputFieldEnterHotkeyRef = useHotkeys(SHORTCUTS.submit.sequence, onSubmit, {
1834
1835
  mode: "scoped"
1835
1836
  });
1836
1837
  useEffect(function () {
@@ -2324,8 +2325,10 @@ var ActionItem = function ActionItem(_ref) {
2324
2325
  elementProps = _ref.elementProps,
2325
2326
  onSelectAction = _ref.onSelectAction,
2326
2327
  selectedActionOptions = _ref.selectedActionOptions;
2328
+ var _useTranslation = useTranslation(),
2329
+ t = _useTranslation.t;
2327
2330
  var _useState = useState({
2328
- label: t$1("neetoRules.form.doThis")
2331
+ label: t("neetoRules.form.doThis")
2329
2332
  }),
2330
2333
  _useState2 = _slicedToArray(_useState, 2),
2331
2334
  selectedOption = _useState2[0],
@@ -2345,9 +2348,9 @@ var ActionItem = function ActionItem(_ref) {
2345
2348
  touched = _useFormikContext.touched;
2346
2349
  var optionList = elementProps.actionOptions;
2347
2350
  var actions = values[parentName].value || [];
2348
- var label = index ? t$1("neetoRules.common.and", {
2349
- what: t$1("neetoRules.common.then").toLowerCase()
2350
- }) : t$1("neetoRules.common.then");
2351
+ var label = index ? t("neetoRules.common.and", {
2352
+ what: t("neetoRules.common.then")
2353
+ }) : t("neetoRules.common.then");
2351
2354
  var actionOptions = useMemo(function () {
2352
2355
  return getActionOptions(action, actions, optionList);
2353
2356
  }, [action, actions]);
@@ -2355,7 +2358,7 @@ var ActionItem = function ActionItem(_ref) {
2355
2358
  return getFieldDetails$1(action.name, actionOptions);
2356
2359
  }, [action, actionOptions]);
2357
2360
  var searchedOptions = getSearchedOptions$3(actionOptions, searchTerm);
2358
- var isActionSelected = (selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.label) === t$1("neetoRules.form.doThis") && errors.actions && touched.actions && 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]) && 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]);
2361
+ var isActionSelected = (selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.label) === t("neetoRules.form.doThis") && errors.actions && touched.actions && 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]) && 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]);
2359
2362
  var handleSelectOption = function handleSelectOption(option) {
2360
2363
  setFieldValue("".concat(name, ".name"), option.value);
2361
2364
  setFieldValue("".concat(name, ".metadata"), {});
@@ -2375,7 +2378,8 @@ var ActionItem = function ActionItem(_ref) {
2375
2378
  }
2376
2379
  return [];
2377
2380
  };
2378
- var _ref2 = (action === null || action === void 0 ? void 0 : action.name) === "message_to_slack" && getSlackChannelErrors(getSelectedFieldOptions(), action),
2381
+ var isMessageToSlackAction = (action === null || action === void 0 ? void 0 : action.name) === "message_to_slack";
2382
+ var _ref2 = isMessageToSlackAction && getSlackChannelErrors(getSelectedFieldOptions(), action),
2379
2383
  selectDropDownHasError = _ref2.error,
2380
2384
  selectDropDownErrorMessage = _ref2.message;
2381
2385
  var findSelectedOption = function findSelectedOption() {
@@ -2383,18 +2387,35 @@ var ActionItem = function ActionItem(_ref) {
2383
2387
  value: selectedField === null || selectedField === void 0 ? void 0 : selectedField.value,
2384
2388
  label: selectedField === null || selectedField === void 0 ? void 0 : selectedField.label
2385
2389
  }) : setSelectedOption({
2386
- label: t$1("neetoRules.form.doThis")
2390
+ label: t("neetoRules.form.doThis")
2387
2391
  });
2388
2392
  };
2393
+ var _ref3 = selectedField || {},
2394
+ _ref3$isDisabled = _ref3.isDisabled,
2395
+ isDisabled = _ref3$isDisabled === void 0 ? false : _ref3$isDisabled,
2396
+ _ref3$disabledReason = _ref3.disabledReason,
2397
+ disabledReason = _ref3$disabledReason === void 0 ? "" : _ref3$disabledReason;
2398
+ var renderErrorCallout = function renderErrorCallout(message) {
2399
+ return /*#__PURE__*/React.createElement(Typography, {
2400
+ className: "neeto-ui-text-white neeto-ui-bg-error-500 neeto-ui-rounded-sm -mx-4 w-full p-3",
2401
+ style: "h5"
2402
+ }, message);
2403
+ };
2404
+ var renderDisabledReason = function renderDisabledReason() {
2405
+ if (typeof disabledReason === "function") {
2406
+ return disabledReason(selectedField);
2407
+ }
2408
+ if (typeof disabledReason === "string" && isPresent(disabledReason)) {
2409
+ return renderErrorCallout(disabledReason);
2410
+ }
2411
+ return null;
2412
+ };
2389
2413
  useEffect(function () {
2390
2414
  findSelectedOption();
2391
2415
  }, [selectedField]);
2392
2416
  return /*#__PURE__*/React.createElement("div", {
2393
2417
  className: "mb-1 flex max-w-2xl flex-wrap gap-x-1 gap-y-2"
2394
- }, selectDropDownHasError && /*#__PURE__*/React.createElement(Typography, {
2395
- className: "neeto-ui-text-white neeto-ui-bg-error-500 neeto-ui-rounded-sm -mx-4 w-full p-3",
2396
- style: "h5"
2397
- }, selectDropDownErrorMessage), /*#__PURE__*/React.createElement(Typography, {
2418
+ }, selectDropDownHasError && renderErrorCallout(selectDropDownErrorMessage), !isMessageToSlackAction && isDisabled && renderDisabledReason(), /*#__PURE__*/React.createElement(Typography, {
2398
2419
  className: "neeto-ui-text-gray-700 mt-1",
2399
2420
  style: "h5",
2400
2421
  weight: "normal"
@@ -2423,7 +2444,7 @@ var ActionItem = function ActionItem(_ref) {
2423
2444
  autoFocus: true,
2424
2445
  className: "mb-1",
2425
2446
  "data-cy": "search-text-field",
2426
- placeholder: t$1("neetoRules.common.search"),
2447
+ placeholder: t("neetoRules.common.search"),
2427
2448
  prefix: /*#__PURE__*/React.createElement(Search, null),
2428
2449
  value: searchTerm,
2429
2450
  onChange: function onChange(e) {
@@ -2447,7 +2468,7 @@ var ActionItem = function ActionItem(_ref) {
2447
2468
  }, option.label);
2448
2469
  })), isEmpty(actionOptions) && /*#__PURE__*/React.createElement(MenuItem$7.Button, {
2449
2470
  "data-cy": "no-options-menu-item"
2450
- }, t$1("neetoRules.common.noOptions")))), /*#__PURE__*/React.createElement(ActionSubItem, {
2471
+ }, t("neetoRules.common.noOptions")))), /*#__PURE__*/React.createElement(ActionSubItem, {
2451
2472
  action: action,
2452
2473
  index: index,
2453
2474
  selectedField: selectedField,