@bigbinary/neeto-rules-frontend 0.4.1 → 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,7 +3,7 @@ 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';
@@ -14,7 +14,7 @@ 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
19
  import useHotkeys from '@bigbinary/neeto-hotkeys';
20
20
 
@@ -1067,7 +1067,7 @@ var useOnButtonPressed = function useOnButtonPressed(ref, handler) {
1067
1067
  var buttonPressed = function buttonPressed() {
1068
1068
  var keysPressed = {};
1069
1069
  var listener = function listener(event) {
1070
- if (!ref.current) return;
1070
+ if (isNil(event.key)) return;
1071
1071
  keysPressed[event.key] = true;
1072
1072
  if ((keysPressed["Meta"] || keysPressed["Control"]) && event.key === "Enter") {
1073
1073
  handler();
@@ -2325,8 +2325,10 @@ var ActionItem = function ActionItem(_ref) {
2325
2325
  elementProps = _ref.elementProps,
2326
2326
  onSelectAction = _ref.onSelectAction,
2327
2327
  selectedActionOptions = _ref.selectedActionOptions;
2328
+ var _useTranslation = useTranslation(),
2329
+ t = _useTranslation.t;
2328
2330
  var _useState = useState({
2329
- label: t$1("neetoRules.form.doThis")
2331
+ label: t("neetoRules.form.doThis")
2330
2332
  }),
2331
2333
  _useState2 = _slicedToArray(_useState, 2),
2332
2334
  selectedOption = _useState2[0],
@@ -2346,9 +2348,9 @@ var ActionItem = function ActionItem(_ref) {
2346
2348
  touched = _useFormikContext.touched;
2347
2349
  var optionList = elementProps.actionOptions;
2348
2350
  var actions = values[parentName].value || [];
2349
- var label = index ? t$1("neetoRules.common.and", {
2350
- what: t$1("neetoRules.common.then").toLowerCase()
2351
- }) : t$1("neetoRules.common.then");
2351
+ var label = index ? t("neetoRules.common.and", {
2352
+ what: t("neetoRules.common.then")
2353
+ }) : t("neetoRules.common.then");
2352
2354
  var actionOptions = useMemo(function () {
2353
2355
  return getActionOptions(action, actions, optionList);
2354
2356
  }, [action, actions]);
@@ -2356,7 +2358,7 @@ var ActionItem = function ActionItem(_ref) {
2356
2358
  return getFieldDetails$1(action.name, actionOptions);
2357
2359
  }, [action, actionOptions]);
2358
2360
  var searchedOptions = getSearchedOptions$3(actionOptions, searchTerm);
2359
- 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]);
2360
2362
  var handleSelectOption = function handleSelectOption(option) {
2361
2363
  setFieldValue("".concat(name, ".name"), option.value);
2362
2364
  setFieldValue("".concat(name, ".metadata"), {});
@@ -2376,7 +2378,8 @@ var ActionItem = function ActionItem(_ref) {
2376
2378
  }
2377
2379
  return [];
2378
2380
  };
2379
- 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),
2380
2383
  selectDropDownHasError = _ref2.error,
2381
2384
  selectDropDownErrorMessage = _ref2.message;
2382
2385
  var findSelectedOption = function findSelectedOption() {
@@ -2384,18 +2387,35 @@ var ActionItem = function ActionItem(_ref) {
2384
2387
  value: selectedField === null || selectedField === void 0 ? void 0 : selectedField.value,
2385
2388
  label: selectedField === null || selectedField === void 0 ? void 0 : selectedField.label
2386
2389
  }) : setSelectedOption({
2387
- label: t$1("neetoRules.form.doThis")
2390
+ label: t("neetoRules.form.doThis")
2388
2391
  });
2389
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
+ };
2390
2413
  useEffect(function () {
2391
2414
  findSelectedOption();
2392
2415
  }, [selectedField]);
2393
2416
  return /*#__PURE__*/React.createElement("div", {
2394
2417
  className: "mb-1 flex max-w-2xl flex-wrap gap-x-1 gap-y-2"
2395
- }, selectDropDownHasError && /*#__PURE__*/React.createElement(Typography, {
2396
- className: "neeto-ui-text-white neeto-ui-bg-error-500 neeto-ui-rounded-sm -mx-4 w-full p-3",
2397
- style: "h5"
2398
- }, selectDropDownErrorMessage), /*#__PURE__*/React.createElement(Typography, {
2418
+ }, selectDropDownHasError && renderErrorCallout(selectDropDownErrorMessage), !isMessageToSlackAction && isDisabled && renderDisabledReason(), /*#__PURE__*/React.createElement(Typography, {
2399
2419
  className: "neeto-ui-text-gray-700 mt-1",
2400
2420
  style: "h5",
2401
2421
  weight: "normal"
@@ -2424,7 +2444,7 @@ var ActionItem = function ActionItem(_ref) {
2424
2444
  autoFocus: true,
2425
2445
  className: "mb-1",
2426
2446
  "data-cy": "search-text-field",
2427
- placeholder: t$1("neetoRules.common.search"),
2447
+ placeholder: t("neetoRules.common.search"),
2428
2448
  prefix: /*#__PURE__*/React.createElement(Search, null),
2429
2449
  value: searchTerm,
2430
2450
  onChange: function onChange(e) {
@@ -2448,7 +2468,7 @@ var ActionItem = function ActionItem(_ref) {
2448
2468
  }, option.label);
2449
2469
  })), isEmpty(actionOptions) && /*#__PURE__*/React.createElement(MenuItem$7.Button, {
2450
2470
  "data-cy": "no-options-menu-item"
2451
- }, t$1("neetoRules.common.noOptions")))), /*#__PURE__*/React.createElement(ActionSubItem, {
2471
+ }, t("neetoRules.common.noOptions")))), /*#__PURE__*/React.createElement(ActionSubItem, {
2452
2472
  action: action,
2453
2473
  index: index,
2454
2474
  selectedField: selectedField,