@bigbinary/neeto-rules-frontend 2.5.65 → 2.6.0
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/README.md +7 -3
- package/app/javascript/src/translations/en.json +104 -1
- package/dist/.ready +1 -1
- package/dist/NeetoRules.js +3 -3
- package/dist/NeetoRules.js.map +1 -1
- package/dist/NeetoRulesBuilder.js +4341 -0
- package/dist/NeetoRulesBuilder.js.map +1 -0
- package/dist/NeetoRulesForm.js +114 -5534
- package/dist/NeetoRulesForm.js.map +1 -1
- package/dist/RulePreview.js +1 -1
- package/dist/cjs/NeetoRules.js +3 -3
- package/dist/cjs/NeetoRules.js.map +1 -1
- package/dist/cjs/NeetoRulesBuilder.js +4343 -0
- package/dist/cjs/NeetoRulesBuilder.js.map +1 -0
- package/dist/cjs/NeetoRulesForm.js +171 -5610
- package/dist/cjs/NeetoRulesForm.js.map +1 -1
- package/dist/cjs/RulePreview.js +1 -1
- package/dist/cjs/hooks.js +6 -6
- package/dist/cjs/index.js +17 -11
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/v2/NeetoRulesForm.js +9 -8
- package/dist/cjs/v2/NeetoRulesForm.js.map +1 -1
- package/dist/cjs/v2/index.js +2 -1
- package/dist/cjs/v2/index.js.map +1 -1
- package/dist/hooks.js +4 -4
- package/dist/index-3f8Yrbst.js +5561 -0
- package/dist/index-3f8Yrbst.js.map +1 -0
- package/dist/index-CkYo0ca_.js +5511 -0
- package/dist/index-CkYo0ca_.js.map +1 -0
- package/dist/index.js +15 -10
- package/dist/index.js.map +1 -1
- package/dist/keyboardShortcuts-BvIE6AHg.js +88 -0
- package/dist/keyboardShortcuts-BvIE6AHg.js.map +1 -0
- package/dist/keyboardShortcuts-NxcrOxzv.js +92 -0
- package/dist/keyboardShortcuts-NxcrOxzv.js.map +1 -0
- package/dist/{useActiveField-9aCscxu8.js → useCustomDataStore-BtKYtLVc.js} +12 -12
- package/dist/useCustomDataStore-BtKYtLVc.js.map +1 -0
- package/dist/{useActiveField-CPw24qyf.js → useCustomDataStore-DxFx8aCf.js} +12 -12
- package/dist/useCustomDataStore-DxFx8aCf.js.map +1 -0
- package/dist/useDebouncedUpdate-C4iFSO2Q.js +21 -0
- package/dist/useDebouncedUpdate-C4iFSO2Q.js.map +1 -0
- package/dist/useDebouncedUpdate-CroNcSyb.js +19 -0
- package/dist/useDebouncedUpdate-CroNcSyb.js.map +1 -0
- package/dist/{useUtilityStore-BV6jVHMM.js → useUtilityStore-CCUYS1mS.js} +9 -2
- package/dist/useUtilityStore-CCUYS1mS.js.map +1 -0
- package/dist/{useUtilityStore-_59l0Cmi.js → useUtilityStore-C_U20IMX.js} +9 -2
- package/dist/useUtilityStore-C_U20IMX.js.map +1 -0
- package/dist/v2/NeetoRulesForm.js +2 -1
- package/dist/v2/NeetoRulesForm.js.map +1 -1
- package/dist/v2/index.js +2 -1
- package/dist/v2/index.js.map +1 -1
- package/package.json +19 -19
- package/dist/useActiveField-9aCscxu8.js.map +0 -1
- package/dist/useActiveField-CPw24qyf.js.map +0 -1
- package/dist/useDebouncedUpdate-DDFcag0p.js +0 -108
- package/dist/useDebouncedUpdate-DDFcag0p.js.map +0 -1
- package/dist/useDebouncedUpdate-sW5WvXe0.js +0 -103
- package/dist/useDebouncedUpdate-sW5WvXe0.js.map +0 -1
- package/dist/useUtilityStore-BV6jVHMM.js.map +0 -1
- package/dist/useUtilityStore-_59l0Cmi.js.map +0 -1
|
@@ -0,0 +1,4341 @@
|
|
|
1
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
2
|
+
import _objectDestructuringEmpty from '@babel/runtime/helpers/objectDestructuringEmpty';
|
|
3
|
+
import { f as flatten } from './keyboardShortcuts-BvIE6AHg.js';
|
|
4
|
+
import { useShallow } from 'zustand/shallow';
|
|
5
|
+
import { useState, createElement, Fragment as Fragment$1, useCallback, useMemo, useRef, useEffect } from 'react';
|
|
6
|
+
import classNames from 'classnames';
|
|
7
|
+
import { useFormikContext, getIn, useField, Formik, Form as Form$1 } from 'formik';
|
|
8
|
+
import { isNotEmpty, toLabelAndValue, removeBy, isNot, findBy, noop } from '@bigbinary/neeto-cist';
|
|
9
|
+
import Container from '@bigbinary/neeto-molecules/Container';
|
|
10
|
+
import Header from '@bigbinary/neeto-molecules/Header';
|
|
11
|
+
import Spinner from '@bigbinary/neetoui/Spinner';
|
|
12
|
+
import ActionBlock from '@bigbinary/neetoui/formik/ActionBlock';
|
|
13
|
+
import { useTranslation } from 'react-i18next';
|
|
14
|
+
import { E as EditorAction, n as Panel, q as ErrorCallout, r as SmsFields, s as PhoneNumberField, k as formatData, u as usePollRuleName, T as TouchErrors, m as ScrollToErrorField, o as getValidationSchema, p as DEFAULT_INITIAL_VALUE, l as buildPayload } from './index-CkYo0ca_.js';
|
|
15
|
+
import { u as useCustomDataStore } from './useCustomDataStore-BtKYtLVc.js';
|
|
16
|
+
import { u as useUtilityStore } from './useUtilityStore-CCUYS1mS.js';
|
|
17
|
+
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
18
|
+
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
19
|
+
import Plus from '@bigbinary/neeto-icons/Plus';
|
|
20
|
+
import Button from '@bigbinary/neetoui/Button';
|
|
21
|
+
import { isNil, isEmpty, assoc, mergeDeepRight, pluck } from 'ramda';
|
|
22
|
+
import Delete from '@bigbinary/neeto-icons/Delete';
|
|
23
|
+
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
24
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
25
|
+
import { t } from 'i18next';
|
|
26
|
+
import { withT } from '@bigbinary/neeto-commons-frontend/react-utils';
|
|
27
|
+
import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
|
|
28
|
+
import Search from '@bigbinary/neeto-icons/Search';
|
|
29
|
+
import Input from '@bigbinary/neetoui/Input';
|
|
30
|
+
import Typography from '@bigbinary/neetoui/Typography';
|
|
31
|
+
import Checkbox from '@bigbinary/neetoui/Checkbox';
|
|
32
|
+
import Radio from '@bigbinary/neetoui/Radio';
|
|
33
|
+
import Textarea from '@bigbinary/neetoui/Textarea';
|
|
34
|
+
import Input$1 from '@bigbinary/neetoui/formik/Input';
|
|
35
|
+
import Select from '@bigbinary/neetoui/formik/Select';
|
|
36
|
+
import Select$1 from '@bigbinary/neetoui/Select';
|
|
37
|
+
import Up from '@bigbinary/neeto-icons/Up';
|
|
38
|
+
import Down from '@bigbinary/neeto-icons/Down';
|
|
39
|
+
import Tooltip from '@bigbinary/neetoui/Tooltip';
|
|
40
|
+
import MultiEmailInput from '@bigbinary/neetoui/MultiEmailInput';
|
|
41
|
+
import '@babel/runtime/helpers/typeof';
|
|
42
|
+
import './useAutomationRulesApi-C9I3wUZ8.js';
|
|
43
|
+
import '@tanstack/react-query';
|
|
44
|
+
import 'axios';
|
|
45
|
+
import './index-9h4B7JZZ.js';
|
|
46
|
+
import 'yup';
|
|
47
|
+
import '@bigbinary/neetoui/formik/Radio';
|
|
48
|
+
import '@bigbinary/neetoui/managers';
|
|
49
|
+
import '@bigbinary/neeto-icons/Close';
|
|
50
|
+
import '@bigbinary/neeto-icons/Collapse';
|
|
51
|
+
import '@bigbinary/neetoui/Callout';
|
|
52
|
+
import '@bigbinary/neeto-icons/Left';
|
|
53
|
+
import '@bigbinary/neetoui/formik/Textarea';
|
|
54
|
+
import '@bigbinary/neetoui/formik/Switch';
|
|
55
|
+
import '@monaco-editor/react';
|
|
56
|
+
import '@bigbinary/neeto-icons/Help';
|
|
57
|
+
import '@bigbinary/neeto-molecules/DynamicVariables';
|
|
58
|
+
import '@bigbinary/neetoui/Label';
|
|
59
|
+
import '@bigbinary/neeto-commons-frontend/utils';
|
|
60
|
+
import '@bigbinary/neetoui/DatePicker';
|
|
61
|
+
import './utils-CfCq6Ltz.js';
|
|
62
|
+
import '@bigbinary/neeto-commons-frontend/initializers';
|
|
63
|
+
import '@bigbinary/neetoui/formik/MultiEmailInput';
|
|
64
|
+
import '@bigbinary/neeto-editor/FormikEditor';
|
|
65
|
+
import '@bigbinary/neeto-icons/Refresh';
|
|
66
|
+
import '@bigbinary/neeto-hotkeys';
|
|
67
|
+
import '@bigbinary/neeto-icons/Check';
|
|
68
|
+
import 'react-select/creatable';
|
|
69
|
+
import '@babel/runtime/helpers/toArray';
|
|
70
|
+
import '@bigbinary/neeto-molecules/PhoneNumber';
|
|
71
|
+
import '@bigbinary/neetoui/Tag';
|
|
72
|
+
import 'react-select';
|
|
73
|
+
import './constants-C_bfl8XZ.js';
|
|
74
|
+
import '@bigbinary/neetoui/TimePicker';
|
|
75
|
+
import '@bigbinary/neeto-editor/utils';
|
|
76
|
+
import 'zustand';
|
|
77
|
+
|
|
78
|
+
var _TOKEN_TO_PANEL_TYPE;
|
|
79
|
+
var PARAM_KIND = {
|
|
80
|
+
ENUM_SINGLE: "enum-single",
|
|
81
|
+
ENUM_MULTI: "enum-multi"
|
|
82
|
+
};
|
|
83
|
+
var UNIT_MINUTES = {
|
|
84
|
+
minutes: 1,
|
|
85
|
+
hours: 60,
|
|
86
|
+
days: 1440
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/* eslint-disable @bigbinary/neeto/hard-coded-strings-should-be-localized */
|
|
90
|
+
/* eslint-disable @bigbinary/neeto/neetocommons-tips */
|
|
91
|
+
var TIME_UNITS = [{
|
|
92
|
+
label: "minutes",
|
|
93
|
+
value: "minutes"
|
|
94
|
+
}, {
|
|
95
|
+
label: "hours",
|
|
96
|
+
value: "hours"
|
|
97
|
+
}, {
|
|
98
|
+
label: "days",
|
|
99
|
+
value: "days"
|
|
100
|
+
}];
|
|
101
|
+
/* eslint-enable @bigbinary/neeto/hard-coded-strings-should-be-localized */
|
|
102
|
+
/* eslint-enable @bigbinary/neeto/neetocommons-tips */
|
|
103
|
+
|
|
104
|
+
var LEAD_TIME_UNITS = TIME_UNITS;
|
|
105
|
+
var CONDITION_VERBS = {
|
|
106
|
+
IS: "is",
|
|
107
|
+
IS_NOT: "is_not",
|
|
108
|
+
ANY_OF: "any_of",
|
|
109
|
+
NONE_OF: "none_of",
|
|
110
|
+
ALL_OF: "all_of",
|
|
111
|
+
LESS_THAN: "less_than",
|
|
112
|
+
GREATER_THAN: "greater_than"
|
|
113
|
+
};
|
|
114
|
+
var VERB_TOKENS = {
|
|
115
|
+
MULTI_VALUE: "_of",
|
|
116
|
+
CONTAINS: "contains"
|
|
117
|
+
};
|
|
118
|
+
var DEFAULT_SCHEMA = {
|
|
119
|
+
triggers: {
|
|
120
|
+
fieldKey: "events",
|
|
121
|
+
options: []
|
|
122
|
+
},
|
|
123
|
+
actor: {
|
|
124
|
+
enabled: false,
|
|
125
|
+
options: [],
|
|
126
|
+
fieldKey: "performer"
|
|
127
|
+
},
|
|
128
|
+
conditions: {
|
|
129
|
+
fields: [],
|
|
130
|
+
fieldKey: "conditions",
|
|
131
|
+
connectorMode: "shared"
|
|
132
|
+
},
|
|
133
|
+
actions: {
|
|
134
|
+
options: [],
|
|
135
|
+
channelMeta: {},
|
|
136
|
+
recipients: [],
|
|
137
|
+
fieldKey: "actions"
|
|
138
|
+
},
|
|
139
|
+
delay: {
|
|
140
|
+
enabled: false,
|
|
141
|
+
fieldKey: "execution_delay",
|
|
142
|
+
units: []
|
|
143
|
+
},
|
|
144
|
+
integrations: {},
|
|
145
|
+
slots: {}
|
|
146
|
+
};
|
|
147
|
+
var STATUS_KEYS = {
|
|
148
|
+
ENABLED: "enabled",
|
|
149
|
+
DISABLED: "disabled"
|
|
150
|
+
};
|
|
151
|
+
var JOIN_TYPE = {
|
|
152
|
+
and: "and_operator",
|
|
153
|
+
or: "or_operator"
|
|
154
|
+
};
|
|
155
|
+
var CONDITION_MODE = {
|
|
156
|
+
AND: "and",
|
|
157
|
+
OR: "or"
|
|
158
|
+
};
|
|
159
|
+
var BUILDER_PANEL_TYPES = {
|
|
160
|
+
TRIGGER: "builder-trigger",
|
|
161
|
+
ACTOR: "builder-actor",
|
|
162
|
+
CONDITION_FIELD: "builder-condition-field",
|
|
163
|
+
OPERATOR: "builder-operator",
|
|
164
|
+
CONNECTOR: "builder-connector",
|
|
165
|
+
CONDITION_VALUE: "builder-condition-value",
|
|
166
|
+
ACTION_CHANNEL: "builder-action-channel",
|
|
167
|
+
ACTION_CONFIG: "builder-action-config",
|
|
168
|
+
RECIPIENT: "builder-recipient",
|
|
169
|
+
DELAY: "builder-delay",
|
|
170
|
+
LEAD_TIME: "builder-lead-time",
|
|
171
|
+
NAME: "builder-name",
|
|
172
|
+
SCOPE: "builder-scope"
|
|
173
|
+
};
|
|
174
|
+
var BUILDER_ANCHORS = {
|
|
175
|
+
TRIGGER_ADD: "trigger-add",
|
|
176
|
+
TRIGGER_REPLACE: "trigger-replace",
|
|
177
|
+
TRIGGER_ACTOR: "trigger-actor",
|
|
178
|
+
TRIGGER_LEAD_TIME: "trigger-lead-time",
|
|
179
|
+
COND_FIELD: "cond-field",
|
|
180
|
+
COND_OP_TOGGLE: "cond-op-toggle",
|
|
181
|
+
COND_CONNECTOR: "cond-connector",
|
|
182
|
+
COND_VALUES: "cond-values",
|
|
183
|
+
ACTION_ADD: "action-add",
|
|
184
|
+
ACTION_CHANNEL: "action-channel",
|
|
185
|
+
ACTION_CONFIG: "action-config",
|
|
186
|
+
ACTION_RECIPIENT: "action-recipient",
|
|
187
|
+
RULE_DELAY: "rule-delay",
|
|
188
|
+
META_NAME: "meta-name",
|
|
189
|
+
SCOPE: "scope"
|
|
190
|
+
};
|
|
191
|
+
var TOKEN_TO_PANEL_TYPE = (_TOKEN_TO_PANEL_TYPE = {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_TOKEN_TO_PANEL_TYPE, BUILDER_ANCHORS.TRIGGER_ADD, BUILDER_PANEL_TYPES.TRIGGER), BUILDER_ANCHORS.TRIGGER_REPLACE, BUILDER_PANEL_TYPES.TRIGGER), BUILDER_ANCHORS.TRIGGER_ACTOR, BUILDER_PANEL_TYPES.ACTOR), BUILDER_ANCHORS.COND_FIELD, BUILDER_PANEL_TYPES.CONDITION_FIELD), BUILDER_ANCHORS.COND_OP_TOGGLE, BUILDER_PANEL_TYPES.OPERATOR), BUILDER_ANCHORS.COND_CONNECTOR, BUILDER_PANEL_TYPES.CONNECTOR), BUILDER_ANCHORS.COND_VALUES, BUILDER_PANEL_TYPES.CONDITION_VALUE), BUILDER_ANCHORS.ACTION_ADD, BUILDER_PANEL_TYPES.ACTION_CHANNEL), BUILDER_ANCHORS.ACTION_CHANNEL, BUILDER_PANEL_TYPES.ACTION_CHANNEL), BUILDER_ANCHORS.ACTION_CONFIG, BUILDER_PANEL_TYPES.ACTION_CONFIG), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_TOKEN_TO_PANEL_TYPE, BUILDER_ANCHORS.ACTION_RECIPIENT, BUILDER_PANEL_TYPES.RECIPIENT), BUILDER_ANCHORS.RULE_DELAY, BUILDER_PANEL_TYPES.DELAY), BUILDER_ANCHORS.TRIGGER_LEAD_TIME, BUILDER_PANEL_TYPES.LEAD_TIME), BUILDER_ANCHORS.META_NAME, BUILDER_PANEL_TYPES.NAME), BUILDER_ANCHORS.SCOPE, BUILDER_PANEL_TYPES.SCOPE));
|
|
192
|
+
var LARGE_PANEL_TYPES = [BUILDER_PANEL_TYPES.ACTION_CONFIG, BUILDER_PANEL_TYPES.SCOPE, BUILDER_PANEL_TYPES.NAME];
|
|
193
|
+
var CONDITION_ANCHORS = [BUILDER_ANCHORS.COND_FIELD, BUILDER_ANCHORS.COND_OP_TOGGLE, BUILDER_ANCHORS.COND_VALUES, BUILDER_ANCHORS.COND_CONNECTOR];
|
|
194
|
+
var ACTION_ANCHORS = [BUILDER_ANCHORS.ACTION_CHANNEL, BUILDER_ANCHORS.ACTION_CONFIG, BUILDER_ANCHORS.ACTION_RECIPIENT];
|
|
195
|
+
var PANE_SEARCH_THRESHOLD = 8;
|
|
196
|
+
var CONFIG_FOCUSABLE_SELECTOR = 'input:not([type="radio"]):not([type="checkbox"]), textarea, [contenteditable="true"]';
|
|
197
|
+
var SMS_TYPES = ["sms", "smsToNumbers"];
|
|
198
|
+
var RECIPIENT_FOCUSABLE_SELECTOR = 'input, textarea, [contenteditable="true"]';
|
|
199
|
+
var SMS_TO_NUMBERS = "smsToNumbers";
|
|
200
|
+
var SWAP_CHANNEL_ORDER = ["email", "sms", "slack", "webhook", "calendar_invite"];
|
|
201
|
+
var DEFAULT_DELAY_UNITS = TIME_UNITS;
|
|
202
|
+
|
|
203
|
+
var useClearingHover = function useClearingHover() {
|
|
204
|
+
var _useState = useState(false),
|
|
205
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
206
|
+
clearing = _useState2[0],
|
|
207
|
+
setClearing = _useState2[1];
|
|
208
|
+
var clearingHoverProps = {
|
|
209
|
+
onMouseEnter: function onMouseEnter() {
|
|
210
|
+
return setClearing(true);
|
|
211
|
+
},
|
|
212
|
+
onMouseLeave: function onMouseLeave() {
|
|
213
|
+
return setClearing(false);
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
var resetClearing = function resetClearing() {
|
|
217
|
+
return setClearing(false);
|
|
218
|
+
};
|
|
219
|
+
return {
|
|
220
|
+
clearing: clearing,
|
|
221
|
+
clearingHoverProps: clearingHoverProps,
|
|
222
|
+
resetClearing: resetClearing
|
|
223
|
+
};
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
var TOKEN_STATE = {
|
|
227
|
+
FILLED: "filled",
|
|
228
|
+
MUTED: "muted",
|
|
229
|
+
// eslint-disable-next-line @bigbinary/neeto/hard-coded-strings-should-be-localized
|
|
230
|
+
PLACEHOLDER: "placeholder",
|
|
231
|
+
PLACEHOLDER_NEXT: "placeholder-next",
|
|
232
|
+
DISABLED: "disabled"
|
|
233
|
+
};
|
|
234
|
+
var STATE_CLASS = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, TOKEN_STATE.PLACEHOLDER, "mb-placeholder"), TOKEN_STATE.PLACEHOLDER_NEXT, "mb-placeholder mb-placeholder-next"), TOKEN_STATE.DISABLED, "mb-placeholder mb-placeholder-disabled"), TOKEN_STATE.FILLED, "mb-tok"), TOKEN_STATE.MUTED, "mb-tok mb-tok-muted");
|
|
235
|
+
|
|
236
|
+
var _excluded = ["children", "state", "active", "invalid", "onClick", "className", "dataTestid"];
|
|
237
|
+
function ownKeys$c(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; }
|
|
238
|
+
function _objectSpread$c(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$c(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$c(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
239
|
+
var Token = function Token(_ref) {
|
|
240
|
+
var children = _ref.children,
|
|
241
|
+
_ref$state = _ref.state,
|
|
242
|
+
state = _ref$state === void 0 ? TOKEN_STATE.FILLED : _ref$state,
|
|
243
|
+
_ref$active = _ref.active,
|
|
244
|
+
active = _ref$active === void 0 ? false : _ref$active,
|
|
245
|
+
_ref$invalid = _ref.invalid,
|
|
246
|
+
invalid = _ref$invalid === void 0 ? false : _ref$invalid,
|
|
247
|
+
onClick = _ref.onClick,
|
|
248
|
+
className = _ref.className,
|
|
249
|
+
dataTestid = _ref.dataTestid,
|
|
250
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
251
|
+
var isInteractive = typeof onClick === "function" && state !== TOKEN_STATE.DISABLED;
|
|
252
|
+
return /*#__PURE__*/jsx("span", _objectSpread$c(_objectSpread$c({
|
|
253
|
+
"data-testid": dataTestid,
|
|
254
|
+
role: isInteractive ? "button" : undefined,
|
|
255
|
+
tabIndex: isInteractive ? 0 : undefined,
|
|
256
|
+
className: classNames(
|
|
257
|
+
// eslint-disable-next-line security/detect-object-injection
|
|
258
|
+
STATE_CLASS[state] || STATE_CLASS.filled, className, {
|
|
259
|
+
"mb-tok-active": active,
|
|
260
|
+
"mb-tok-invalid": invalid
|
|
261
|
+
}),
|
|
262
|
+
onClick: isInteractive ? onClick : undefined,
|
|
263
|
+
onKeyDown: isInteractive ? function (event) {
|
|
264
|
+
if (!(event.key === "Enter" || event.key === " ")) return;
|
|
265
|
+
event.preventDefault();
|
|
266
|
+
onClick(event);
|
|
267
|
+
} : undefined
|
|
268
|
+
}, rest), {}, {
|
|
269
|
+
children: children
|
|
270
|
+
}));
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
function ownKeys$b(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; }
|
|
274
|
+
function _objectSpread$b(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$b(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$b(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
275
|
+
var humanize = function humanize(value) {
|
|
276
|
+
return String(value !== null && value !== void 0 ? value : "").replace(/[._]/g, " ").trim();
|
|
277
|
+
};
|
|
278
|
+
var isContainsVerb = function isContainsVerb(verb) {
|
|
279
|
+
return verb.includes(VERB_TOKENS.MULTI_VALUE) && verb.includes(VERB_TOKENS.CONTAINS);
|
|
280
|
+
};
|
|
281
|
+
var isNumericVerb = function isNumericVerb(verb) {
|
|
282
|
+
return verb === CONDITION_VERBS.LESS_THAN || verb === CONDITION_VERBS.GREATER_THAN;
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
// eslint-disable-next-line @bigbinary/neeto/prefer-function-reference
|
|
286
|
+
var isExcludeVerb = function isExcludeVerb(verb) {
|
|
287
|
+
return [CONDITION_VERBS.IS, CONDITION_VERBS.IS_NOT, CONDITION_VERBS.ANY_OF, CONDITION_VERBS.NONE_OF].includes(verb);
|
|
288
|
+
};
|
|
289
|
+
var isMultiValueVerb = function isMultiValueVerb(verb) {
|
|
290
|
+
return String(verb).includes(VERB_TOKENS.MULTI_VALUE);
|
|
291
|
+
};
|
|
292
|
+
var sentencify = function sentencify(label) {
|
|
293
|
+
return label ? label.charAt(0).toLowerCase() + label.slice(1) : label;
|
|
294
|
+
};
|
|
295
|
+
var matchesTrigger = function matchesTrigger(name) {
|
|
296
|
+
return function (option) {
|
|
297
|
+
return option.eventValue === name || option.value === name || option.id === name;
|
|
298
|
+
};
|
|
299
|
+
};
|
|
300
|
+
var triggerOption = function triggerOption(_ref) {
|
|
301
|
+
var _schema$triggers;
|
|
302
|
+
var schema = _ref.schema,
|
|
303
|
+
name = _ref.name;
|
|
304
|
+
return ((schema === null || schema === void 0 || (_schema$triggers = schema.triggers) === null || _schema$triggers === void 0 ? void 0 : _schema$triggers.options) || []).find(matchesTrigger(name));
|
|
305
|
+
};
|
|
306
|
+
var triggerLabel = function triggerLabel(_ref2) {
|
|
307
|
+
var schema = _ref2.schema,
|
|
308
|
+
trigger = _ref2.trigger;
|
|
309
|
+
var option = triggerOption({
|
|
310
|
+
schema: schema,
|
|
311
|
+
name: trigger === null || trigger === void 0 ? void 0 : trigger.name
|
|
312
|
+
});
|
|
313
|
+
return (option === null || option === void 0 ? void 0 : option.plain) || sentencify((option === null || option === void 0 ? void 0 : option.label) || humanize(trigger === null || trigger === void 0 ? void 0 : trigger.name));
|
|
314
|
+
};
|
|
315
|
+
var performerLabel = function performerLabel(_ref3) {
|
|
316
|
+
var _schema$actor;
|
|
317
|
+
var schema = _ref3.schema,
|
|
318
|
+
performer = _ref3.performer;
|
|
319
|
+
var option = ((schema === null || schema === void 0 || (_schema$actor = schema.actor) === null || _schema$actor === void 0 ? void 0 : _schema$actor.options) || []).find(function (candidate) {
|
|
320
|
+
return candidate.value === performer || candidate.id === performer;
|
|
321
|
+
});
|
|
322
|
+
return sentencify((option === null || option === void 0 ? void 0 : option.label) || humanize(performer));
|
|
323
|
+
};
|
|
324
|
+
var conditionField = function conditionField(_ref4) {
|
|
325
|
+
var _schema$conditions;
|
|
326
|
+
var schema = _ref4.schema,
|
|
327
|
+
field = _ref4.field;
|
|
328
|
+
return ((schema === null || schema === void 0 || (_schema$conditions = schema.conditions) === null || _schema$conditions === void 0 ? void 0 : _schema$conditions.fields) || []).find(function (option) {
|
|
329
|
+
return option.value === field || option.id === field;
|
|
330
|
+
});
|
|
331
|
+
};
|
|
332
|
+
var conditionFieldLabel = function conditionFieldLabel(_ref5) {
|
|
333
|
+
var schema = _ref5.schema,
|
|
334
|
+
condition = _ref5.condition;
|
|
335
|
+
var field = conditionField({
|
|
336
|
+
schema: schema,
|
|
337
|
+
field: condition === null || condition === void 0 ? void 0 : condition.field
|
|
338
|
+
});
|
|
339
|
+
return String((field === null || field === void 0 ? void 0 : field.label) || humanize(condition === null || condition === void 0 ? void 0 : condition.field)).toLowerCase();
|
|
340
|
+
};
|
|
341
|
+
var operatorLabel = function operatorLabel(_ref6) {
|
|
342
|
+
var _schema$conditions2;
|
|
343
|
+
var schema = _ref6.schema,
|
|
344
|
+
condition = _ref6.condition;
|
|
345
|
+
var map = (schema === null || schema === void 0 || (_schema$conditions2 = schema.conditions) === null || _schema$conditions2 === void 0 ? void 0 : _schema$conditions2.operatorLabels) || {};
|
|
346
|
+
return map[condition === null || condition === void 0 ? void 0 : condition.verb] || humanize(condition === null || condition === void 0 ? void 0 : condition.verb);
|
|
347
|
+
};
|
|
348
|
+
var conditionNeedsValue = function conditionNeedsValue(_ref7) {
|
|
349
|
+
var schema = _ref7.schema,
|
|
350
|
+
condition = _ref7.condition;
|
|
351
|
+
var field = conditionField({
|
|
352
|
+
schema: schema,
|
|
353
|
+
field: condition === null || condition === void 0 ? void 0 : condition.field
|
|
354
|
+
});
|
|
355
|
+
return !((field === null || field === void 0 ? void 0 : field.noValueForVerbs) || []).includes(condition === null || condition === void 0 ? void 0 : condition.verb);
|
|
356
|
+
};
|
|
357
|
+
var conditionValueLabel = function conditionValueLabel(_ref8) {
|
|
358
|
+
var _ref9, _meta$value;
|
|
359
|
+
var schema = _ref8.schema,
|
|
360
|
+
condition = _ref8.condition;
|
|
361
|
+
var meta = (condition === null || condition === void 0 ? void 0 : condition.metadata) || {};
|
|
362
|
+
var raw = (_ref9 = (_meta$value = meta.value) !== null && _meta$value !== void 0 ? _meta$value : meta.values) !== null && _ref9 !== void 0 ? _ref9 : meta.label;
|
|
363
|
+
if (isNil(raw) || isEmpty(raw)) return null;
|
|
364
|
+
var field = conditionField({
|
|
365
|
+
schema: schema,
|
|
366
|
+
field: condition === null || condition === void 0 ? void 0 : condition.field
|
|
367
|
+
});
|
|
368
|
+
var options = (field === null || field === void 0 ? void 0 : field.values) || (field === null || field === void 0 ? void 0 : field.dropdownOptions) || (field === null || field === void 0 ? void 0 : field.options) || [];
|
|
369
|
+
var isEnum = isNotEmpty(options);
|
|
370
|
+
var labelFor = function labelFor(value) {
|
|
371
|
+
var _ref0, _option$label;
|
|
372
|
+
var option = options.find(function (candidate) {
|
|
373
|
+
var _candidate$value;
|
|
374
|
+
return ((_candidate$value = candidate.value) !== null && _candidate$value !== void 0 ? _candidate$value : candidate.id) === value;
|
|
375
|
+
});
|
|
376
|
+
var label = option ? (_ref0 = (_option$label = option.label) !== null && _option$label !== void 0 ? _option$label : option.value) !== null && _ref0 !== void 0 ? _ref0 : option.id : value;
|
|
377
|
+
return isEnum ? String(label).toLowerCase() : label;
|
|
378
|
+
};
|
|
379
|
+
var connector = String((condition === null || condition === void 0 ? void 0 : condition.verb) || "").includes(CONDITION_VERBS.ALL_OF) ? t("neetoRules.operators.and") : t("neetoRules.operators.or");
|
|
380
|
+
return Array.isArray(raw) ? raw.map(labelFor).join(" ".concat(connector, " ")) : String(labelFor(raw));
|
|
381
|
+
};
|
|
382
|
+
var actionOption = function actionOption(_ref1) {
|
|
383
|
+
var _schema$actions;
|
|
384
|
+
var schema = _ref1.schema,
|
|
385
|
+
name = _ref1.name;
|
|
386
|
+
return ((schema === null || schema === void 0 || (_schema$actions = schema.actions) === null || _schema$actions === void 0 ? void 0 : _schema$actions.options) || []).find(function (option) {
|
|
387
|
+
return option.value === name || option.id === name;
|
|
388
|
+
});
|
|
389
|
+
};
|
|
390
|
+
var channelOption = function channelOption(_ref10) {
|
|
391
|
+
var _schema$actions2;
|
|
392
|
+
var schema = _ref10.schema,
|
|
393
|
+
channel = _ref10.channel;
|
|
394
|
+
return ((schema === null || schema === void 0 || (_schema$actions2 = schema.actions) === null || _schema$actions2 === void 0 ? void 0 : _schema$actions2.options) || []).find(function (option) {
|
|
395
|
+
var _option$value;
|
|
396
|
+
return ((_option$value = option.value) !== null && _option$value !== void 0 ? _option$value : option.id) === channel;
|
|
397
|
+
});
|
|
398
|
+
};
|
|
399
|
+
var actionParts = function actionParts(_ref11) {
|
|
400
|
+
var _actions$actionForNam, _action$recipient, _actions$channelMeta, _find, _find2, _channelMeta$needsRec, _actions$configValueL;
|
|
401
|
+
var schema = _ref11.schema,
|
|
402
|
+
action = _ref11.action;
|
|
403
|
+
var actions = (schema === null || schema === void 0 ? void 0 : schema.actions) || {};
|
|
404
|
+
var resolved = action !== null && action !== void 0 && action.channel ? {
|
|
405
|
+
channel: action.channel,
|
|
406
|
+
recipient: action.recipient
|
|
407
|
+
} : ((_actions$actionForNam = actions.actionForName) === null || _actions$actionForNam === void 0 ? void 0 : _actions$actionForNam.call(actions, action === null || action === void 0 ? void 0 : action.name)) || {};
|
|
408
|
+
var channel = resolved.channel;
|
|
409
|
+
var recipientValue = (_action$recipient = action === null || action === void 0 ? void 0 : action.recipient) !== null && _action$recipient !== void 0 ? _action$recipient : resolved.recipient;
|
|
410
|
+
var option = channel ? channelOption({
|
|
411
|
+
schema: schema,
|
|
412
|
+
channel: channel
|
|
413
|
+
}) : actionOption({
|
|
414
|
+
schema: schema,
|
|
415
|
+
name: action === null || action === void 0 ? void 0 : action.name
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
// eslint-disable-next-line security/detect-object-injection
|
|
419
|
+
var channelMeta = ((_actions$channelMeta = actions.channelMeta) === null || _actions$channelMeta === void 0 ? void 0 : _actions$channelMeta[channel]) || {};
|
|
420
|
+
var matchesRecipient = function matchesRecipient(recipient) {
|
|
421
|
+
var _recipient$value;
|
|
422
|
+
return ((_recipient$value = recipient.value) !== null && _recipient$value !== void 0 ? _recipient$value : recipient.id) === recipientValue;
|
|
423
|
+
};
|
|
424
|
+
var recipientLabel = ((_find = (actions.recipients || []).find(matchesRecipient)) === null || _find === void 0 ? void 0 : _find.label) || ((_find2 = ((option === null || option === void 0 ? void 0 : option.recipients) || []).find(matchesRecipient)) === null || _find2 === void 0 ? void 0 : _find2.label) || recipientValue;
|
|
425
|
+
return {
|
|
426
|
+
option: option,
|
|
427
|
+
channel: channel,
|
|
428
|
+
label: (option === null || option === void 0 ? void 0 : option.label) || humanize(action === null || action === void 0 ? void 0 : action.name),
|
|
429
|
+
verb: channelMeta.verb || (channel ? t("neetoRules.builder.send") : (option === null || option === void 0 ? void 0 : option.plain) || (option === null || option === void 0 ? void 0 : option.label)) || humanize(action === null || action === void 0 ? void 0 : action.name),
|
|
430
|
+
paramKind: !channel && (option === null || option === void 0 ? void 0 : option.paramType),
|
|
431
|
+
valueNoun: option === null || option === void 0 ? void 0 : option.valueNoun,
|
|
432
|
+
valueNounPlural: option === null || option === void 0 ? void 0 : option.valueNounPlural,
|
|
433
|
+
mediumLabel: channelMeta.mediumLabel || (option === null || option === void 0 ? void 0 : option.mediumLabel),
|
|
434
|
+
icon: channelMeta.icon || (option === null || option === void 0 ? void 0 : option.icon),
|
|
435
|
+
needsRecipient: (_channelMeta$needsRec = channelMeta.needsRecipient) !== null && _channelMeta$needsRec !== void 0 ? _channelMeta$needsRec : option === null || option === void 0 ? void 0 : option.needsRecipient,
|
|
436
|
+
separator: channelMeta.separator || (option === null || option === void 0 ? void 0 : option.separator),
|
|
437
|
+
configValue: ((_actions$configValueL = actions.configValueLabel) === null || _actions$configValueL === void 0 ? void 0 : _actions$configValueL.call(actions, action)) || "",
|
|
438
|
+
configValuePlaceholder: channelMeta.valuePlaceholder || (option === null || option === void 0 ? void 0 : option.valuePlaceholder),
|
|
439
|
+
recipient: recipientValue,
|
|
440
|
+
recipientLabel: recipientLabel,
|
|
441
|
+
configTitle: channelMeta.configTitle || (option === null || option === void 0 ? void 0 : option.configTitle),
|
|
442
|
+
configSubtitle: channelMeta.configSubtitle || (option === null || option === void 0 ? void 0 : option.configSubtitle),
|
|
443
|
+
recipientTitle: channelMeta.recipientTitle || (option === null || option === void 0 ? void 0 : option.recipientTitle),
|
|
444
|
+
recipientSubtitle: channelMeta.recipientSubtitle || (option === null || option === void 0 ? void 0 : option.recipientSubtitle)
|
|
445
|
+
};
|
|
446
|
+
};
|
|
447
|
+
var hasTrigger = function hasTrigger(rule) {
|
|
448
|
+
return !isEmpty((rule === null || rule === void 0 ? void 0 : rule.triggers) || []);
|
|
449
|
+
};
|
|
450
|
+
var hasAction = function hasAction(rule) {
|
|
451
|
+
return ((rule === null || rule === void 0 ? void 0 : rule.actions) || []).some(function (action) {
|
|
452
|
+
return action === null || action === void 0 ? void 0 : action.name;
|
|
453
|
+
});
|
|
454
|
+
};
|
|
455
|
+
var isRuleComplete = function isRuleComplete(rule) {
|
|
456
|
+
return hasTrigger(rule) && hasAction(rule);
|
|
457
|
+
};
|
|
458
|
+
var invalidScopeIndexes = function invalidScopeIndexes(_ref12) {
|
|
459
|
+
var _scope$requiresPhone;
|
|
460
|
+
var rule = _ref12.rule,
|
|
461
|
+
schema = _ref12.schema;
|
|
462
|
+
var scope = schema === null || schema === void 0 ? void 0 : schema.scope;
|
|
463
|
+
if (!(scope !== null && scope !== void 0 && scope.enabled) || !((_scope$requiresPhone = scope.requiresPhone) !== null && _scope$requiresPhone !== void 0 && _scope$requiresPhone.call(scope, (rule === null || rule === void 0 ? void 0 : rule.actions) || []))) return [];
|
|
464
|
+
return ((rule === null || rule === void 0 ? void 0 : rule.scope) || []).reduce(function (indexes, item, index) {
|
|
465
|
+
var _item$value, _item$hasPhoneField;
|
|
466
|
+
var value = (_item$value = item === null || item === void 0 ? void 0 : item.value) !== null && _item$value !== void 0 ? _item$value : item;
|
|
467
|
+
var option = (scope.options || []).find(function (candidate) {
|
|
468
|
+
var _candidate$value2;
|
|
469
|
+
return ((_candidate$value2 = candidate.value) !== null && _candidate$value2 !== void 0 ? _candidate$value2 : candidate.id) === value;
|
|
470
|
+
});
|
|
471
|
+
var hasPhoneField = (_item$hasPhoneField = item === null || item === void 0 ? void 0 : item.hasPhoneField) !== null && _item$hasPhoneField !== void 0 ? _item$hasPhoneField : option === null || option === void 0 ? void 0 : option.hasPhoneField;
|
|
472
|
+
if (hasPhoneField === false) indexes.push(index);
|
|
473
|
+
return indexes;
|
|
474
|
+
}, []);
|
|
475
|
+
};
|
|
476
|
+
var minutesToParts = function minutesToParts(minutes) {
|
|
477
|
+
var total = Number(minutes) || 0;
|
|
478
|
+
if (total && total % UNIT_MINUTES.days === 0) {
|
|
479
|
+
return {
|
|
480
|
+
value: total / UNIT_MINUTES.days,
|
|
481
|
+
unit: "days"
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
if (total && total % UNIT_MINUTES.hours === 0) {
|
|
485
|
+
return {
|
|
486
|
+
value: total / UNIT_MINUTES.hours,
|
|
487
|
+
unit: "hours"
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
return {
|
|
491
|
+
value: total,
|
|
492
|
+
unit: "minutes"
|
|
493
|
+
};
|
|
494
|
+
};
|
|
495
|
+
var partsToMinutes = function partsToMinutes(_ref13) {
|
|
496
|
+
var value = _ref13.value,
|
|
497
|
+
unit = _ref13.unit;
|
|
498
|
+
return (
|
|
499
|
+
// eslint-disable-next-line security/detect-object-injection
|
|
500
|
+
(Number(value) || 0) * (UNIT_MINUTES[unit] || 1)
|
|
501
|
+
);
|
|
502
|
+
};
|
|
503
|
+
var leadTimeLabel = function leadTimeLabel(minutes) {
|
|
504
|
+
var _minutesToParts = minutesToParts(minutes),
|
|
505
|
+
value = _minutesToParts.value,
|
|
506
|
+
unit = _minutesToParts.unit;
|
|
507
|
+
var unitLabel = value === 1 ? unit.replace(/s$/, "") : unit;
|
|
508
|
+
return "".concat(value, " ").concat(unitLabel);
|
|
509
|
+
};
|
|
510
|
+
var normalizeTriggers = function normalizeTriggers(triggers) {
|
|
511
|
+
if (Array.isArray(triggers)) return {
|
|
512
|
+
options: triggers
|
|
513
|
+
};
|
|
514
|
+
return triggers || {};
|
|
515
|
+
};
|
|
516
|
+
var normalizeSchema = function normalizeSchema() {
|
|
517
|
+
var rawSchema = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
518
|
+
return mergeDeepRight(DEFAULT_SCHEMA, _objectSpread$b(_objectSpread$b({}, rawSchema), {}, {
|
|
519
|
+
triggers: normalizeTriggers(rawSchema.triggers)
|
|
520
|
+
}));
|
|
521
|
+
};
|
|
522
|
+
var joinTypeFor = function joinTypeFor(mode) {
|
|
523
|
+
return mode === CONDITION_MODE.OR ? JOIN_TYPE.or : JOIN_TYPE.and;
|
|
524
|
+
};
|
|
525
|
+
var modeFromJoinType = function modeFromJoinType(joinType) {
|
|
526
|
+
return joinType === JOIN_TYPE.or ? CONDITION_MODE.OR : CONDITION_MODE.AND;
|
|
527
|
+
};
|
|
528
|
+
|
|
529
|
+
// eslint-disable-next-line security/detect-object-injection
|
|
530
|
+
var valueAt = function valueAt(_ref14) {
|
|
531
|
+
var _values$key;
|
|
532
|
+
var values = _ref14.values,
|
|
533
|
+
key = _ref14.key;
|
|
534
|
+
return values === null || values === void 0 || (_values$key = values[key]) === null || _values$key === void 0 ? void 0 : _values$key.value;
|
|
535
|
+
};
|
|
536
|
+
var asArray = function asArray(maybeArray) {
|
|
537
|
+
return Array.isArray(maybeArray) ? maybeArray : [];
|
|
538
|
+
};
|
|
539
|
+
var fieldKeysFromSchema = function fieldKeysFromSchema() {
|
|
540
|
+
var _schema$triggers2, _schema$actor2, _schema$conditions3, _schema$actions3, _schema$delay, _schema$triggers3, _schema$scope;
|
|
541
|
+
var schema = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
542
|
+
return {
|
|
543
|
+
triggers: ((_schema$triggers2 = schema.triggers) === null || _schema$triggers2 === void 0 ? void 0 : _schema$triggers2.fieldKey) || "events",
|
|
544
|
+
performer: ((_schema$actor2 = schema.actor) === null || _schema$actor2 === void 0 ? void 0 : _schema$actor2.fieldKey) || "performer",
|
|
545
|
+
conditions: ((_schema$conditions3 = schema.conditions) === null || _schema$conditions3 === void 0 ? void 0 : _schema$conditions3.fieldKey) || "conditions",
|
|
546
|
+
actions: ((_schema$actions3 = schema.actions) === null || _schema$actions3 === void 0 ? void 0 : _schema$actions3.fieldKey) || "actions",
|
|
547
|
+
delay: ((_schema$delay = schema.delay) === null || _schema$delay === void 0 ? void 0 : _schema$delay.fieldKey) || "execution_delay",
|
|
548
|
+
leadTime: (_schema$triggers3 = schema.triggers) === null || _schema$triggers3 === void 0 || (_schema$triggers3 = _schema$triggers3.leadTime) === null || _schema$triggers3 === void 0 ? void 0 : _schema$triggers3.fieldKey,
|
|
549
|
+
scope: ((_schema$scope = schema.scope) === null || _schema$scope === void 0 ? void 0 : _schema$scope.fieldKey) || "meetingIds",
|
|
550
|
+
status: "status",
|
|
551
|
+
name: "name"
|
|
552
|
+
};
|
|
553
|
+
};
|
|
554
|
+
var valuesToRuleModel = function valuesToRuleModel() {
|
|
555
|
+
var _valueAt, _conditions$;
|
|
556
|
+
var _ref15 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
557
|
+
_ref15$values = _ref15.values,
|
|
558
|
+
values = _ref15$values === void 0 ? {} : _ref15$values,
|
|
559
|
+
_ref15$schema = _ref15.schema,
|
|
560
|
+
schema = _ref15$schema === void 0 ? {} : _ref15$schema;
|
|
561
|
+
var keys = fieldKeysFromSchema(schema);
|
|
562
|
+
var conditions = asArray(valueAt({
|
|
563
|
+
values: values,
|
|
564
|
+
key: keys.conditions
|
|
565
|
+
}));
|
|
566
|
+
var rawDelay = valueAt({
|
|
567
|
+
values: values,
|
|
568
|
+
key: keys.delay
|
|
569
|
+
});
|
|
570
|
+
return {
|
|
571
|
+
name: valueAt({
|
|
572
|
+
values: values,
|
|
573
|
+
key: keys.name
|
|
574
|
+
}) || "",
|
|
575
|
+
active: valueAt({
|
|
576
|
+
values: values,
|
|
577
|
+
key: keys.status
|
|
578
|
+
}) !== STATUS_KEYS.DISABLED,
|
|
579
|
+
triggers: asArray(valueAt({
|
|
580
|
+
values: values,
|
|
581
|
+
key: keys.triggers
|
|
582
|
+
})),
|
|
583
|
+
performer: (_valueAt = valueAt({
|
|
584
|
+
values: values,
|
|
585
|
+
key: keys.performer
|
|
586
|
+
})) !== null && _valueAt !== void 0 ? _valueAt : null,
|
|
587
|
+
conditions: conditions,
|
|
588
|
+
conditionMode: modeFromJoinType((_conditions$ = conditions[0]) === null || _conditions$ === void 0 ? void 0 : _conditions$.joinType),
|
|
589
|
+
delay: isNil(rawDelay) || isEmpty(rawDelay) ? null : rawDelay,
|
|
590
|
+
actions: asArray(valueAt({
|
|
591
|
+
values: values,
|
|
592
|
+
key: keys.actions
|
|
593
|
+
})),
|
|
594
|
+
leadTime: keys.leadTime ? valueAt({
|
|
595
|
+
values: values,
|
|
596
|
+
key: keys.leadTime
|
|
597
|
+
}) : null,
|
|
598
|
+
scope: asArray(valueAt({
|
|
599
|
+
values: values,
|
|
600
|
+
key: keys.scope
|
|
601
|
+
}))
|
|
602
|
+
};
|
|
603
|
+
};
|
|
604
|
+
var setTriggers = function setTriggers(_ref16) {
|
|
605
|
+
var schema = _ref16.schema,
|
|
606
|
+
triggers = _ref16.triggers;
|
|
607
|
+
return {
|
|
608
|
+
path: "".concat(fieldKeysFromSchema(schema).triggers, ".value"),
|
|
609
|
+
value: triggers
|
|
610
|
+
};
|
|
611
|
+
};
|
|
612
|
+
var setPerformer = function setPerformer(_ref17) {
|
|
613
|
+
var schema = _ref17.schema,
|
|
614
|
+
performer = _ref17.performer;
|
|
615
|
+
return {
|
|
616
|
+
path: "".concat(fieldKeysFromSchema(schema).performer, ".value"),
|
|
617
|
+
value: performer
|
|
618
|
+
};
|
|
619
|
+
};
|
|
620
|
+
var setActions = function setActions(_ref18) {
|
|
621
|
+
var schema = _ref18.schema,
|
|
622
|
+
actions = _ref18.actions;
|
|
623
|
+
return {
|
|
624
|
+
path: "".concat(fieldKeysFromSchema(schema).actions, ".value"),
|
|
625
|
+
value: actions
|
|
626
|
+
};
|
|
627
|
+
};
|
|
628
|
+
var setConditions = function setConditions(_ref19) {
|
|
629
|
+
var schema = _ref19.schema,
|
|
630
|
+
conditions = _ref19.conditions;
|
|
631
|
+
return {
|
|
632
|
+
path: "".concat(fieldKeysFromSchema(schema).conditions, ".value"),
|
|
633
|
+
value: conditions
|
|
634
|
+
};
|
|
635
|
+
};
|
|
636
|
+
var setConditionMode = function setConditionMode(_ref20) {
|
|
637
|
+
var schema = _ref20.schema,
|
|
638
|
+
conditions = _ref20.conditions,
|
|
639
|
+
joinType = _ref20.joinType;
|
|
640
|
+
return setConditions({
|
|
641
|
+
schema: schema,
|
|
642
|
+
conditions: conditions.map(function (condition) {
|
|
643
|
+
return assoc("joinType", joinTypeFor(joinType), condition);
|
|
644
|
+
})
|
|
645
|
+
});
|
|
646
|
+
};
|
|
647
|
+
var setDelay = function setDelay(_ref21) {
|
|
648
|
+
var schema = _ref21.schema,
|
|
649
|
+
delay = _ref21.delay;
|
|
650
|
+
return {
|
|
651
|
+
path: "".concat(fieldKeysFromSchema(schema).delay, ".value"),
|
|
652
|
+
value: delay !== null && delay !== void 0 ? delay : {}
|
|
653
|
+
};
|
|
654
|
+
};
|
|
655
|
+
var setActive = function setActive(_ref22) {
|
|
656
|
+
var schema = _ref22.schema,
|
|
657
|
+
active = _ref22.active;
|
|
658
|
+
return {
|
|
659
|
+
path: "".concat(fieldKeysFromSchema(schema).status, ".value"),
|
|
660
|
+
value: active ? STATUS_KEYS.ENABLED : STATUS_KEYS.DISABLED
|
|
661
|
+
};
|
|
662
|
+
};
|
|
663
|
+
var setScope = function setScope(_ref23) {
|
|
664
|
+
var schema = _ref23.schema,
|
|
665
|
+
scope = _ref23.scope;
|
|
666
|
+
return {
|
|
667
|
+
path: "".concat(fieldKeysFromSchema(schema).scope, ".value"),
|
|
668
|
+
value: scope
|
|
669
|
+
};
|
|
670
|
+
};
|
|
671
|
+
var removeArrayItem = function removeArrayItem(_ref24) {
|
|
672
|
+
var values = _ref24.values,
|
|
673
|
+
fieldKey = _ref24.fieldKey,
|
|
674
|
+
index = _ref24.index;
|
|
675
|
+
var list = asArray(valueAt({
|
|
676
|
+
values: values,
|
|
677
|
+
key: fieldKey
|
|
678
|
+
}));
|
|
679
|
+
// eslint-disable-next-line security/detect-object-injection
|
|
680
|
+
var removed = list[index];
|
|
681
|
+
var nextList = list.filter(function (_, i) {
|
|
682
|
+
return i !== index;
|
|
683
|
+
});
|
|
684
|
+
var result = [{
|
|
685
|
+
path: "".concat(fieldKey, ".value"),
|
|
686
|
+
value: nextList
|
|
687
|
+
}];
|
|
688
|
+
if (removed !== null && removed !== void 0 && removed.id) {
|
|
689
|
+
var _values$fieldKey;
|
|
690
|
+
// eslint-disable-next-line security/detect-object-injection
|
|
691
|
+
var deleted = asArray(values === null || values === void 0 || (_values$fieldKey = values[fieldKey]) === null || _values$fieldKey === void 0 ? void 0 : _values$fieldKey.deleted);
|
|
692
|
+
result.push({
|
|
693
|
+
path: "".concat(fieldKey, ".deleted"),
|
|
694
|
+
value: [].concat(_toConsumableArray(deleted), [_objectSpread$b(_objectSpread$b({}, removed), {}, {
|
|
695
|
+
_destroy: true
|
|
696
|
+
})])
|
|
697
|
+
});
|
|
698
|
+
}
|
|
699
|
+
return result;
|
|
700
|
+
};
|
|
701
|
+
|
|
702
|
+
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; }
|
|
703
|
+
function _objectSpread$a(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$a(Object(t), true).forEach(function (r) { _defineProperty(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; }
|
|
704
|
+
var ConditionRow = function ConditionRow(_ref) {
|
|
705
|
+
var _schema$conditions;
|
|
706
|
+
var rule = _ref.rule,
|
|
707
|
+
schema = _ref.schema,
|
|
708
|
+
condition = _ref.condition,
|
|
709
|
+
index = _ref.index,
|
|
710
|
+
handleToken = _ref.onToken,
|
|
711
|
+
handleAddCondition = _ref.onAddCondition,
|
|
712
|
+
handleRemove = _ref.onRemove,
|
|
713
|
+
_ref$isActive = _ref.isActive,
|
|
714
|
+
isActive = _ref$isActive === void 0 ? function () {
|
|
715
|
+
return false;
|
|
716
|
+
} : _ref$isActive,
|
|
717
|
+
_ref$isInvalid = _ref.isInvalid,
|
|
718
|
+
isInvalid = _ref$isInvalid === void 0 ? function () {
|
|
719
|
+
return false;
|
|
720
|
+
} : _ref$isInvalid;
|
|
721
|
+
var _useTranslation = useTranslation(),
|
|
722
|
+
t = _useTranslation.t;
|
|
723
|
+
var isFirst = index === 0;
|
|
724
|
+
var hasField = !!(condition !== null && condition !== void 0 && condition.field);
|
|
725
|
+
var hasVerb = !!(condition !== null && condition !== void 0 && condition.verb);
|
|
726
|
+
var conditionField = ((schema === null || schema === void 0 || (_schema$conditions = schema.conditions) === null || _schema$conditions === void 0 ? void 0 : _schema$conditions.fields) || []).find(function (field) {
|
|
727
|
+
var _field$value;
|
|
728
|
+
return ((_field$value = field.value) !== null && _field$value !== void 0 ? _field$value : field.id) === (condition === null || condition === void 0 ? void 0 : condition.field);
|
|
729
|
+
});
|
|
730
|
+
var operatorPlaceholder = (conditionField === null || conditionField === void 0 ? void 0 : conditionField.operatorPlaceholder) || t("neetoRules.builder.selectOperator");
|
|
731
|
+
var value = conditionValueLabel({
|
|
732
|
+
schema: schema,
|
|
733
|
+
condition: condition
|
|
734
|
+
});
|
|
735
|
+
var needsValue = conditionNeedsValue({
|
|
736
|
+
schema: schema,
|
|
737
|
+
condition: condition
|
|
738
|
+
});
|
|
739
|
+
var _useClearingHover = useClearingHover(),
|
|
740
|
+
clearing = _useClearingHover.clearing,
|
|
741
|
+
clearingHoverProps = _useClearingHover.clearingHoverProps;
|
|
742
|
+
return /*#__PURE__*/jsxs("div", {
|
|
743
|
+
className: classNames("mb-row", {
|
|
744
|
+
clearing: clearing
|
|
745
|
+
}),
|
|
746
|
+
children: [/*#__PURE__*/jsxs("div", {
|
|
747
|
+
className: "mb-sentence",
|
|
748
|
+
children: [isFirst ? /*#__PURE__*/jsx("span", {
|
|
749
|
+
className: "mb-fixed",
|
|
750
|
+
children: t("neetoRules.operators.and")
|
|
751
|
+
}) : /*#__PURE__*/jsx(Token, {
|
|
752
|
+
active: isActive({
|
|
753
|
+
type: BUILDER_ANCHORS.COND_CONNECTOR,
|
|
754
|
+
index: index
|
|
755
|
+
}),
|
|
756
|
+
className: "mb-tok-muted",
|
|
757
|
+
dataTestid: "cond-connector-".concat(index),
|
|
758
|
+
onClick: handleToken && function () {
|
|
759
|
+
return handleToken({
|
|
760
|
+
type: BUILDER_ANCHORS.COND_CONNECTOR,
|
|
761
|
+
index: index
|
|
762
|
+
});
|
|
763
|
+
},
|
|
764
|
+
children: rule.conditionMode === CONDITION_MODE.OR ? t("neetoRules.operators.or") : t("neetoRules.operators.and")
|
|
765
|
+
}), hasField ? /*#__PURE__*/jsxs(Fragment, {
|
|
766
|
+
children: [/*#__PURE__*/jsx(Token, {
|
|
767
|
+
active: isActive({
|
|
768
|
+
type: BUILDER_ANCHORS.COND_FIELD,
|
|
769
|
+
index: index
|
|
770
|
+
}),
|
|
771
|
+
dataTestid: "cond-field-".concat(index),
|
|
772
|
+
onClick: handleToken && function () {
|
|
773
|
+
return handleToken({
|
|
774
|
+
type: BUILDER_ANCHORS.COND_FIELD,
|
|
775
|
+
index: index
|
|
776
|
+
});
|
|
777
|
+
},
|
|
778
|
+
children: conditionFieldLabel({
|
|
779
|
+
schema: schema,
|
|
780
|
+
condition: condition
|
|
781
|
+
})
|
|
782
|
+
}), /*#__PURE__*/jsx(Token, {
|
|
783
|
+
active: isActive({
|
|
784
|
+
type: BUILDER_ANCHORS.COND_OP_TOGGLE,
|
|
785
|
+
index: index
|
|
786
|
+
}),
|
|
787
|
+
dataTestid: "cond-op-".concat(index),
|
|
788
|
+
state: hasVerb ? TOKEN_STATE.FILLED : TOKEN_STATE.MUTED,
|
|
789
|
+
invalid: isInvalid({
|
|
790
|
+
type: BUILDER_ANCHORS.COND_OP_TOGGLE,
|
|
791
|
+
index: index
|
|
792
|
+
}),
|
|
793
|
+
onClick: handleToken && function () {
|
|
794
|
+
return handleToken({
|
|
795
|
+
type: BUILDER_ANCHORS.COND_OP_TOGGLE,
|
|
796
|
+
index: index
|
|
797
|
+
});
|
|
798
|
+
},
|
|
799
|
+
children: hasVerb ? sentencify(operatorLabel({
|
|
800
|
+
schema: schema,
|
|
801
|
+
condition: condition
|
|
802
|
+
})) : operatorPlaceholder
|
|
803
|
+
}), hasVerb && needsValue && /*#__PURE__*/jsx(Token, {
|
|
804
|
+
active: isActive({
|
|
805
|
+
type: BUILDER_ANCHORS.COND_VALUES,
|
|
806
|
+
index: index
|
|
807
|
+
}),
|
|
808
|
+
dataTestid: "cond-values-".concat(index),
|
|
809
|
+
state: value ? TOKEN_STATE.FILLED : TOKEN_STATE.MUTED,
|
|
810
|
+
invalid: isInvalid({
|
|
811
|
+
type: BUILDER_ANCHORS.COND_VALUES,
|
|
812
|
+
index: index
|
|
813
|
+
}),
|
|
814
|
+
onClick: handleToken && function () {
|
|
815
|
+
return handleToken({
|
|
816
|
+
type: BUILDER_ANCHORS.COND_VALUES,
|
|
817
|
+
index: index
|
|
818
|
+
});
|
|
819
|
+
},
|
|
820
|
+
children: value || t("neetoRules.form.addValue")
|
|
821
|
+
})]
|
|
822
|
+
}) : /*#__PURE__*/jsx(Token, {
|
|
823
|
+
active: isActive({
|
|
824
|
+
type: BUILDER_ANCHORS.COND_FIELD,
|
|
825
|
+
index: index
|
|
826
|
+
}),
|
|
827
|
+
dataTestid: "cond-field-".concat(index),
|
|
828
|
+
invalid: isInvalid({
|
|
829
|
+
type: BUILDER_ANCHORS.COND_FIELD,
|
|
830
|
+
index: index
|
|
831
|
+
}),
|
|
832
|
+
state: TOKEN_STATE.PLACEHOLDER_NEXT,
|
|
833
|
+
onClick: handleToken && function () {
|
|
834
|
+
return handleToken({
|
|
835
|
+
type: BUILDER_ANCHORS.COND_FIELD,
|
|
836
|
+
index: index
|
|
837
|
+
});
|
|
838
|
+
},
|
|
839
|
+
children: t("neetoRules.builder.selectCondition")
|
|
840
|
+
})]
|
|
841
|
+
}), /*#__PURE__*/jsxs("div", {
|
|
842
|
+
className: "mb-row-actions",
|
|
843
|
+
children: [handleAddCondition && /*#__PURE__*/jsx(Button, {
|
|
844
|
+
"data-testid": "cond-add-".concat(index),
|
|
845
|
+
icon: Plus,
|
|
846
|
+
size: "small",
|
|
847
|
+
style: "text",
|
|
848
|
+
tooltipProps: {
|
|
849
|
+
content: t("neetoRules.builder.aria.addAnotherCondition"),
|
|
850
|
+
position: "top"
|
|
851
|
+
},
|
|
852
|
+
onClick: handleAddCondition
|
|
853
|
+
}), handleRemove && /*#__PURE__*/jsx(Button, _objectSpread$a({
|
|
854
|
+
"data-testid": "cond-remove-".concat(index),
|
|
855
|
+
icon: Delete,
|
|
856
|
+
size: "small",
|
|
857
|
+
style: "text",
|
|
858
|
+
tooltipProps: {
|
|
859
|
+
content: t("neetoRules.builder.aria.deleteCondition"),
|
|
860
|
+
position: "top"
|
|
861
|
+
},
|
|
862
|
+
onClick: handleRemove
|
|
863
|
+
}, clearingHoverProps))]
|
|
864
|
+
})]
|
|
865
|
+
});
|
|
866
|
+
};
|
|
867
|
+
|
|
868
|
+
var Connector = function Connector(_ref) {
|
|
869
|
+
var _ref$active = _ref.active,
|
|
870
|
+
active = _ref$active === void 0 ? false : _ref$active;
|
|
871
|
+
return /*#__PURE__*/jsx("div", {
|
|
872
|
+
"aria-hidden": true,
|
|
873
|
+
className: classNames("mb-arrow", {
|
|
874
|
+
"is-active": active
|
|
875
|
+
}),
|
|
876
|
+
children: /*#__PURE__*/jsx("svg", {
|
|
877
|
+
fill: "none",
|
|
878
|
+
height: "28",
|
|
879
|
+
viewBox: "0 0 24 28",
|
|
880
|
+
width: "24",
|
|
881
|
+
children: /*#__PURE__*/jsx("path", {
|
|
882
|
+
d: "M12 2 V22 M5 15 l7 7 l7 -7",
|
|
883
|
+
stroke: "currentColor",
|
|
884
|
+
strokeLinecap: "round",
|
|
885
|
+
strokeLinejoin: "round",
|
|
886
|
+
strokeWidth: "2"
|
|
887
|
+
})
|
|
888
|
+
})
|
|
889
|
+
});
|
|
890
|
+
};
|
|
891
|
+
|
|
892
|
+
function ownKeys$9(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; }
|
|
893
|
+
function _objectSpread$9(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$9(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$9(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
894
|
+
var DelayRow = function DelayRow(_ref) {
|
|
895
|
+
var rule = _ref.rule,
|
|
896
|
+
handleToken = _ref.onToken,
|
|
897
|
+
handleRemove = _ref.onRemove,
|
|
898
|
+
_ref$isActive = _ref.isActive,
|
|
899
|
+
isActive = _ref$isActive === void 0 ? function () {
|
|
900
|
+
return false;
|
|
901
|
+
} : _ref$isActive,
|
|
902
|
+
_ref$isInvalid = _ref.isInvalid,
|
|
903
|
+
isInvalid = _ref$isInvalid === void 0 ? function () {
|
|
904
|
+
return false;
|
|
905
|
+
} : _ref$isInvalid;
|
|
906
|
+
var _useTranslation = useTranslation(),
|
|
907
|
+
t = _useTranslation.t;
|
|
908
|
+
var delay = rule.delay;
|
|
909
|
+
var _useClearingHover = useClearingHover(),
|
|
910
|
+
clearing = _useClearingHover.clearing,
|
|
911
|
+
clearingHoverProps = _useClearingHover.clearingHoverProps;
|
|
912
|
+
if (!delay) return null;
|
|
913
|
+
var label = [delay.value, delay.unit].filter(function (part) {
|
|
914
|
+
return part !== "" && !isNil(part);
|
|
915
|
+
}).join(" ");
|
|
916
|
+
return /*#__PURE__*/jsxs("div", {
|
|
917
|
+
className: classNames("mb-row", {
|
|
918
|
+
clearing: clearing
|
|
919
|
+
}),
|
|
920
|
+
children: [/*#__PURE__*/jsxs("div", {
|
|
921
|
+
className: "mb-sentence",
|
|
922
|
+
children: [/*#__PURE__*/jsx("span", {
|
|
923
|
+
className: "mb-fixed",
|
|
924
|
+
children: t("neetoRules.form.delayExecutionBy")
|
|
925
|
+
}), /*#__PURE__*/jsx(Token, {
|
|
926
|
+
dataTestid: "rule-delay",
|
|
927
|
+
state: label ? TOKEN_STATE.FILLED : TOKEN_STATE.MUTED,
|
|
928
|
+
active: isActive({
|
|
929
|
+
type: BUILDER_ANCHORS.RULE_DELAY,
|
|
930
|
+
index: undefined
|
|
931
|
+
}),
|
|
932
|
+
invalid: isInvalid({
|
|
933
|
+
type: BUILDER_ANCHORS.RULE_DELAY,
|
|
934
|
+
index: undefined
|
|
935
|
+
}),
|
|
936
|
+
onClick: handleToken && function () {
|
|
937
|
+
return handleToken({
|
|
938
|
+
type: BUILDER_ANCHORS.RULE_DELAY
|
|
939
|
+
});
|
|
940
|
+
},
|
|
941
|
+
children: label || t("neetoRules.builder.setDelay")
|
|
942
|
+
})]
|
|
943
|
+
}), handleRemove && /*#__PURE__*/jsx("div", {
|
|
944
|
+
className: "mb-row-actions",
|
|
945
|
+
children: /*#__PURE__*/jsx(Button, _objectSpread$9({
|
|
946
|
+
"data-testid": "rule-delay-remove",
|
|
947
|
+
icon: Delete,
|
|
948
|
+
size: "small",
|
|
949
|
+
style: "text",
|
|
950
|
+
tooltipProps: {
|
|
951
|
+
content: t("neetoRules.builder.aria.removeDelay"),
|
|
952
|
+
position: "top"
|
|
953
|
+
},
|
|
954
|
+
onClick: handleRemove
|
|
955
|
+
}, clearingHoverProps))
|
|
956
|
+
})]
|
|
957
|
+
});
|
|
958
|
+
};
|
|
959
|
+
|
|
960
|
+
var MetaBlock = withT(function (_ref) {
|
|
961
|
+
var t = _ref.t,
|
|
962
|
+
rule = _ref.rule,
|
|
963
|
+
_ref$showName = _ref.showName,
|
|
964
|
+
showName = _ref$showName === void 0 ? true : _ref$showName,
|
|
965
|
+
_ref$isInvalid = _ref.isInvalid,
|
|
966
|
+
isInvalid = _ref$isInvalid === void 0 ? false : _ref$isInvalid,
|
|
967
|
+
handleEditName = _ref.onEditName,
|
|
968
|
+
handleToggleActive = _ref.onToggleActive;
|
|
969
|
+
return /*#__PURE__*/jsxs("div", {
|
|
970
|
+
className: "mb-meta",
|
|
971
|
+
children: [showName && /*#__PURE__*/jsxs("div", {
|
|
972
|
+
className: "mb-meta-field",
|
|
973
|
+
children: [/*#__PURE__*/jsx("span", {
|
|
974
|
+
className: "mb-meta-label",
|
|
975
|
+
children: t("neetoRules.builder.automationName")
|
|
976
|
+
}), /*#__PURE__*/jsxs("div", {
|
|
977
|
+
role: handleEditName ? "button" : undefined,
|
|
978
|
+
tabIndex: handleEditName ? 0 : undefined,
|
|
979
|
+
className: classNames("mb-meta-input-wrap", {
|
|
980
|
+
"mb-meta-invalid": isInvalid
|
|
981
|
+
}),
|
|
982
|
+
onClick: handleEditName,
|
|
983
|
+
children: [/*#__PURE__*/jsx("span", {
|
|
984
|
+
className: "mb-meta-name-display",
|
|
985
|
+
children: rule.name
|
|
986
|
+
}), /*#__PURE__*/jsx("span", {
|
|
987
|
+
"aria-hidden": true,
|
|
988
|
+
className: "mb-meta-edit",
|
|
989
|
+
children: /*#__PURE__*/jsx("svg", {
|
|
990
|
+
fill: "none",
|
|
991
|
+
height: "14",
|
|
992
|
+
viewBox: "0 0 24 24",
|
|
993
|
+
width: "14",
|
|
994
|
+
children: /*#__PURE__*/jsx("path", {
|
|
995
|
+
d: "M12 20h9 M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z",
|
|
996
|
+
stroke: "currentColor",
|
|
997
|
+
strokeLinecap: "round",
|
|
998
|
+
strokeLinejoin: "round",
|
|
999
|
+
strokeWidth: "2"
|
|
1000
|
+
})
|
|
1001
|
+
})
|
|
1002
|
+
})]
|
|
1003
|
+
})]
|
|
1004
|
+
}), /*#__PURE__*/jsxs("label", {
|
|
1005
|
+
className: "mb-meta-active",
|
|
1006
|
+
children: [/*#__PURE__*/jsx("input", {
|
|
1007
|
+
checked: rule.active,
|
|
1008
|
+
readOnly: !handleToggleActive,
|
|
1009
|
+
type: "checkbox",
|
|
1010
|
+
onChange: handleToggleActive || undefined
|
|
1011
|
+
}), /*#__PURE__*/jsx("span", {
|
|
1012
|
+
"aria-hidden": true,
|
|
1013
|
+
className: "mb-checkbox",
|
|
1014
|
+
children: /*#__PURE__*/jsx("svg", {
|
|
1015
|
+
fill: "none",
|
|
1016
|
+
height: "12",
|
|
1017
|
+
viewBox: "0 0 14 14",
|
|
1018
|
+
width: "12",
|
|
1019
|
+
children: /*#__PURE__*/jsx("path", {
|
|
1020
|
+
d: "M2 7l3.5 3.5L12 3.5"
|
|
1021
|
+
})
|
|
1022
|
+
})
|
|
1023
|
+
}), t("neetoRules.builder.activateThisAutomation")]
|
|
1024
|
+
})]
|
|
1025
|
+
});
|
|
1026
|
+
});
|
|
1027
|
+
|
|
1028
|
+
function ownKeys$8(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; }
|
|
1029
|
+
function _objectSpread$8(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$8(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$8(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
1030
|
+
var itemLabel = function itemLabel(item) {
|
|
1031
|
+
return (item === null || item === void 0 ? void 0 : item.label) || (item === null || item === void 0 ? void 0 : item.name) || (item === null || item === void 0 ? void 0 : item.value) || String(item !== null && item !== void 0 ? item : "");
|
|
1032
|
+
};
|
|
1033
|
+
var ScopeBlock = function ScopeBlock(_ref) {
|
|
1034
|
+
var _schema$scope;
|
|
1035
|
+
var rule = _ref.rule,
|
|
1036
|
+
schema = _ref.schema,
|
|
1037
|
+
handleToken = _ref.onToken,
|
|
1038
|
+
handleRemoveScope = _ref.onRemoveScope,
|
|
1039
|
+
_ref$isActive = _ref.isActive,
|
|
1040
|
+
isActive = _ref$isActive === void 0 ? function () {
|
|
1041
|
+
return false;
|
|
1042
|
+
} : _ref$isActive,
|
|
1043
|
+
_ref$isInvalid = _ref.isInvalid,
|
|
1044
|
+
isInvalid = _ref$isInvalid === void 0 ? function () {
|
|
1045
|
+
return false;
|
|
1046
|
+
} : _ref$isInvalid;
|
|
1047
|
+
var _useTranslation = useTranslation(),
|
|
1048
|
+
t = _useTranslation.t;
|
|
1049
|
+
var scope = rule.scope || [];
|
|
1050
|
+
var placeholder = (schema === null || schema === void 0 || (_schema$scope = schema.scope) === null || _schema$scope === void 0 ? void 0 : _schema$scope.placeholder) || t("neetoRules.builder.scope.placeholder");
|
|
1051
|
+
if (isEmpty(scope)) {
|
|
1052
|
+
return /*#__PURE__*/jsx("div", {
|
|
1053
|
+
className: "mb-row",
|
|
1054
|
+
children: /*#__PURE__*/jsx("div", {
|
|
1055
|
+
className: "mb-sentence",
|
|
1056
|
+
children: /*#__PURE__*/jsx(Token, {
|
|
1057
|
+
active: isActive({
|
|
1058
|
+
type: BUILDER_ANCHORS.SCOPE,
|
|
1059
|
+
index: undefined
|
|
1060
|
+
}),
|
|
1061
|
+
dataTestid: "scope-add",
|
|
1062
|
+
state: TOKEN_STATE.PLACEHOLDER_NEXT,
|
|
1063
|
+
onClick: handleToken && function () {
|
|
1064
|
+
return handleToken({
|
|
1065
|
+
type: BUILDER_ANCHORS.SCOPE
|
|
1066
|
+
});
|
|
1067
|
+
},
|
|
1068
|
+
children: placeholder
|
|
1069
|
+
})
|
|
1070
|
+
})
|
|
1071
|
+
});
|
|
1072
|
+
}
|
|
1073
|
+
return scope.map(function (item, index) {
|
|
1074
|
+
var _item$value;
|
|
1075
|
+
return /*#__PURE__*/createElement(ScopeRow, {
|
|
1076
|
+
index: index,
|
|
1077
|
+
isActive: isActive,
|
|
1078
|
+
isInvalid: isInvalid,
|
|
1079
|
+
item: item,
|
|
1080
|
+
schema: schema,
|
|
1081
|
+
isLast: index === scope.length - 1,
|
|
1082
|
+
key: ((_item$value = item === null || item === void 0 ? void 0 : item.value) !== null && _item$value !== void 0 ? _item$value : item) || index,
|
|
1083
|
+
onRemoveScope: handleRemoveScope,
|
|
1084
|
+
onToken: handleToken
|
|
1085
|
+
});
|
|
1086
|
+
});
|
|
1087
|
+
};
|
|
1088
|
+
var ScopeRow = function ScopeRow(_ref2) {
|
|
1089
|
+
var _schema$scope2;
|
|
1090
|
+
var schema = _ref2.schema,
|
|
1091
|
+
item = _ref2.item,
|
|
1092
|
+
index = _ref2.index,
|
|
1093
|
+
handleToken = _ref2.onToken,
|
|
1094
|
+
handleRemoveScope = _ref2.onRemoveScope,
|
|
1095
|
+
isActive = _ref2.isActive,
|
|
1096
|
+
isInvalid = _ref2.isInvalid,
|
|
1097
|
+
isLast = _ref2.isLast;
|
|
1098
|
+
var _useTranslation2 = useTranslation(),
|
|
1099
|
+
t = _useTranslation2.t;
|
|
1100
|
+
var _useClearingHover = useClearingHover(),
|
|
1101
|
+
clearing = _useClearingHover.clearing,
|
|
1102
|
+
clearingHoverProps = _useClearingHover.clearingHoverProps;
|
|
1103
|
+
var lead = (schema === null || schema === void 0 || (_schema$scope2 = schema.scope) === null || _schema$scope2 === void 0 ? void 0 : _schema$scope2.lead) || t("neetoRules.builder.scope.lead");
|
|
1104
|
+
return /*#__PURE__*/jsxs("div", {
|
|
1105
|
+
className: classNames("mb-row", {
|
|
1106
|
+
clearing: clearing
|
|
1107
|
+
}),
|
|
1108
|
+
children: [/*#__PURE__*/jsxs("div", {
|
|
1109
|
+
className: "mb-sentence",
|
|
1110
|
+
children: [/*#__PURE__*/jsx("span", {
|
|
1111
|
+
className: "mb-fixed",
|
|
1112
|
+
children: lead
|
|
1113
|
+
}), /*#__PURE__*/jsx(Token, {
|
|
1114
|
+
active: isActive({
|
|
1115
|
+
type: BUILDER_ANCHORS.SCOPE,
|
|
1116
|
+
index: undefined
|
|
1117
|
+
}),
|
|
1118
|
+
dataTestid: "scope-".concat(index),
|
|
1119
|
+
invalid: isInvalid({
|
|
1120
|
+
type: BUILDER_ANCHORS.SCOPE,
|
|
1121
|
+
index: index
|
|
1122
|
+
}),
|
|
1123
|
+
onClick: handleToken && function () {
|
|
1124
|
+
return handleToken({
|
|
1125
|
+
type: BUILDER_ANCHORS.SCOPE
|
|
1126
|
+
});
|
|
1127
|
+
},
|
|
1128
|
+
children: itemLabel(item)
|
|
1129
|
+
})]
|
|
1130
|
+
}), /*#__PURE__*/jsxs("div", {
|
|
1131
|
+
className: "mb-row-actions",
|
|
1132
|
+
children: [handleToken && isLast && /*#__PURE__*/jsx(Button, {
|
|
1133
|
+
"data-testid": "scope-add-".concat(index),
|
|
1134
|
+
icon: Plus,
|
|
1135
|
+
size: "small",
|
|
1136
|
+
style: "text",
|
|
1137
|
+
tooltipProps: {
|
|
1138
|
+
content: t("neetoRules.builder.aria.addAnotherBookingPage"),
|
|
1139
|
+
position: "top"
|
|
1140
|
+
},
|
|
1141
|
+
onClick: function onClick() {
|
|
1142
|
+
return handleToken({
|
|
1143
|
+
type: BUILDER_ANCHORS.SCOPE
|
|
1144
|
+
});
|
|
1145
|
+
}
|
|
1146
|
+
}), handleRemoveScope && /*#__PURE__*/jsx(Button, _objectSpread$8({
|
|
1147
|
+
"data-testid": "scope-remove-".concat(index),
|
|
1148
|
+
icon: Delete,
|
|
1149
|
+
size: "small",
|
|
1150
|
+
style: "text",
|
|
1151
|
+
tooltipProps: {
|
|
1152
|
+
content: t("neetoRules.builder.aria.removeBookingPage"),
|
|
1153
|
+
position: "top"
|
|
1154
|
+
},
|
|
1155
|
+
onClick: function onClick() {
|
|
1156
|
+
return handleRemoveScope(index);
|
|
1157
|
+
}
|
|
1158
|
+
}, clearingHoverProps))]
|
|
1159
|
+
})]
|
|
1160
|
+
});
|
|
1161
|
+
};
|
|
1162
|
+
|
|
1163
|
+
function ownKeys$7(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; }
|
|
1164
|
+
function _objectSpread$7(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$7(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$7(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
1165
|
+
var ActionRow = function ActionRow(_ref) {
|
|
1166
|
+
var schema = _ref.schema,
|
|
1167
|
+
action = _ref.action,
|
|
1168
|
+
index = _ref.index,
|
|
1169
|
+
position = _ref.position,
|
|
1170
|
+
handleToken = _ref.onToken,
|
|
1171
|
+
handleAddAction = _ref.onAddAction,
|
|
1172
|
+
handleRemove = _ref.onRemove,
|
|
1173
|
+
_ref$isActive = _ref.isActive,
|
|
1174
|
+
isActive = _ref$isActive === void 0 ? function () {
|
|
1175
|
+
return false;
|
|
1176
|
+
} : _ref$isActive,
|
|
1177
|
+
_ref$isInvalid = _ref.isInvalid,
|
|
1178
|
+
isInvalid = _ref$isInvalid === void 0 ? function () {
|
|
1179
|
+
return false;
|
|
1180
|
+
} : _ref$isInvalid;
|
|
1181
|
+
var _useTranslation = useTranslation(),
|
|
1182
|
+
t = _useTranslation.t;
|
|
1183
|
+
var _actionParts = actionParts({
|
|
1184
|
+
schema: schema,
|
|
1185
|
+
action: action
|
|
1186
|
+
}),
|
|
1187
|
+
option = _actionParts.option,
|
|
1188
|
+
label = _actionParts.label,
|
|
1189
|
+
verb = _actionParts.verb,
|
|
1190
|
+
mediumLabel = _actionParts.mediumLabel,
|
|
1191
|
+
MediumIcon = _actionParts.icon,
|
|
1192
|
+
needsRecipient = _actionParts.needsRecipient,
|
|
1193
|
+
recipient = _actionParts.recipient,
|
|
1194
|
+
recipientLabel = _actionParts.recipientLabel,
|
|
1195
|
+
separator = _actionParts.separator,
|
|
1196
|
+
configValue = _actionParts.configValue,
|
|
1197
|
+
configValuePlaceholder = _actionParts.configValuePlaceholder,
|
|
1198
|
+
paramKind = _actionParts.paramKind,
|
|
1199
|
+
valueNoun = _actionParts.valueNoun,
|
|
1200
|
+
valueNounPlural = _actionParts.valueNounPlural;
|
|
1201
|
+
var hasParamTail = paramKind === PARAM_KIND.ENUM_SINGLE || paramKind === PARAM_KIND.ENUM_MULTI;
|
|
1202
|
+
var multiPlaceholder = valueNounPlural ? t("neetoRules.builder.selectNoun", {
|
|
1203
|
+
noun: valueNounPlural
|
|
1204
|
+
}) : t("neetoRules.form.selectValues");
|
|
1205
|
+
var singlePlaceholder = valueNoun ? t("neetoRules.builder.selectNoun", {
|
|
1206
|
+
noun: valueNoun
|
|
1207
|
+
}) : t("neetoRules.form.selectValue");
|
|
1208
|
+
var paramPlaceholder = paramKind === PARAM_KIND.ENUM_MULTI ? multiPlaceholder : singlePlaceholder;
|
|
1209
|
+
var connector = (position !== null && position !== void 0 ? position : index) === 0 ? t("neetoRules.common.then") : t("neetoRules.operators.and");
|
|
1210
|
+
var verbLabel = sentencify(verb || label);
|
|
1211
|
+
var isVerbActive = isActive({
|
|
1212
|
+
type: BUILDER_ANCHORS.ACTION_CHANNEL,
|
|
1213
|
+
index: index
|
|
1214
|
+
}) || isActive({
|
|
1215
|
+
type: BUILDER_ANCHORS.ACTION_ADD,
|
|
1216
|
+
index: index
|
|
1217
|
+
});
|
|
1218
|
+
var configLabel = mediumLabel || sentencify(option === null || option === void 0 ? void 0 : option.placeholder);
|
|
1219
|
+
var isConfigured = isNotEmpty(action === null || action === void 0 ? void 0 : action.metadata);
|
|
1220
|
+
var _useClearingHover = useClearingHover(),
|
|
1221
|
+
clearing = _useClearingHover.clearing,
|
|
1222
|
+
clearingHoverProps = _useClearingHover.clearingHoverProps;
|
|
1223
|
+
return /*#__PURE__*/jsxs("div", {
|
|
1224
|
+
className: classNames("mb-row mb-row-draggable", {
|
|
1225
|
+
clearing: clearing
|
|
1226
|
+
}),
|
|
1227
|
+
children: [/*#__PURE__*/jsxs("div", {
|
|
1228
|
+
className: "mb-sentence",
|
|
1229
|
+
children: [/*#__PURE__*/jsx("span", {
|
|
1230
|
+
className: "mb-fixed",
|
|
1231
|
+
children: connector
|
|
1232
|
+
}), separator ? /*#__PURE__*/jsxs(Token, {
|
|
1233
|
+
active: isVerbActive,
|
|
1234
|
+
className: "mb-tok-medium",
|
|
1235
|
+
dataTestid: "action-verb-".concat(index),
|
|
1236
|
+
onClick: handleToken && function () {
|
|
1237
|
+
return handleToken({
|
|
1238
|
+
type: BUILDER_ANCHORS.ACTION_CHANNEL,
|
|
1239
|
+
index: index
|
|
1240
|
+
});
|
|
1241
|
+
},
|
|
1242
|
+
children: [verbLabel, MediumIcon && /*#__PURE__*/jsx(MediumIcon, {
|
|
1243
|
+
size: 14
|
|
1244
|
+
}), configLabel]
|
|
1245
|
+
}) : /*#__PURE__*/jsxs(Fragment, {
|
|
1246
|
+
children: [/*#__PURE__*/jsx(Token, {
|
|
1247
|
+
active: isVerbActive,
|
|
1248
|
+
dataTestid: "action-verb-".concat(index),
|
|
1249
|
+
onClick: handleToken && function () {
|
|
1250
|
+
return handleToken({
|
|
1251
|
+
type: BUILDER_ANCHORS.ACTION_CHANNEL,
|
|
1252
|
+
index: index
|
|
1253
|
+
});
|
|
1254
|
+
},
|
|
1255
|
+
children: verbLabel
|
|
1256
|
+
}), hasParamTail ? /*#__PURE__*/jsx(Token, {
|
|
1257
|
+
dataTestid: "action-config-value-".concat(index),
|
|
1258
|
+
state: configValue ? TOKEN_STATE.FILLED : TOKEN_STATE.MUTED,
|
|
1259
|
+
active: isActive({
|
|
1260
|
+
type: BUILDER_ANCHORS.ACTION_CONFIG,
|
|
1261
|
+
index: index
|
|
1262
|
+
}),
|
|
1263
|
+
invalid: isInvalid({
|
|
1264
|
+
type: BUILDER_ANCHORS.ACTION_CONFIG,
|
|
1265
|
+
index: index
|
|
1266
|
+
}),
|
|
1267
|
+
onClick: handleToken && function () {
|
|
1268
|
+
return handleToken({
|
|
1269
|
+
type: BUILDER_ANCHORS.ACTION_CONFIG,
|
|
1270
|
+
index: index
|
|
1271
|
+
});
|
|
1272
|
+
},
|
|
1273
|
+
children: configValue || paramPlaceholder
|
|
1274
|
+
}) : configLabel && /*#__PURE__*/jsxs(Token, {
|
|
1275
|
+
className: "mb-tok-medium",
|
|
1276
|
+
dataTestid: "action-config-".concat(index),
|
|
1277
|
+
state: isConfigured ? TOKEN_STATE.FILLED : TOKEN_STATE.MUTED,
|
|
1278
|
+
active: isActive({
|
|
1279
|
+
type: BUILDER_ANCHORS.ACTION_CONFIG,
|
|
1280
|
+
index: index
|
|
1281
|
+
}),
|
|
1282
|
+
invalid: isInvalid({
|
|
1283
|
+
type: BUILDER_ANCHORS.ACTION_CONFIG,
|
|
1284
|
+
index: index
|
|
1285
|
+
}),
|
|
1286
|
+
onClick: handleToken && function () {
|
|
1287
|
+
return handleToken({
|
|
1288
|
+
type: BUILDER_ANCHORS.ACTION_CONFIG,
|
|
1289
|
+
index: index
|
|
1290
|
+
});
|
|
1291
|
+
},
|
|
1292
|
+
children: [MediumIcon && /*#__PURE__*/jsx(MediumIcon, {
|
|
1293
|
+
size: 14
|
|
1294
|
+
}), configLabel]
|
|
1295
|
+
})]
|
|
1296
|
+
}), separator && /*#__PURE__*/jsxs(Fragment, {
|
|
1297
|
+
children: [/*#__PURE__*/jsx("span", {
|
|
1298
|
+
className: "mb-fixed",
|
|
1299
|
+
children: separator
|
|
1300
|
+
}), /*#__PURE__*/jsx(Token, {
|
|
1301
|
+
active: isActive({
|
|
1302
|
+
type: BUILDER_ANCHORS.ACTION_CONFIG,
|
|
1303
|
+
index: index
|
|
1304
|
+
}),
|
|
1305
|
+
dataTestid: "action-config-value-".concat(index),
|
|
1306
|
+
state: configValue ? TOKEN_STATE.FILLED : TOKEN_STATE.MUTED,
|
|
1307
|
+
invalid: isInvalid({
|
|
1308
|
+
type: BUILDER_ANCHORS.ACTION_CONFIG,
|
|
1309
|
+
index: index
|
|
1310
|
+
}),
|
|
1311
|
+
onClick: handleToken && function () {
|
|
1312
|
+
return handleToken({
|
|
1313
|
+
type: BUILDER_ANCHORS.ACTION_CONFIG,
|
|
1314
|
+
index: index
|
|
1315
|
+
});
|
|
1316
|
+
},
|
|
1317
|
+
children: configValue || sentencify(configValuePlaceholder) || t("neetoRules.builder.selectFallback")
|
|
1318
|
+
})]
|
|
1319
|
+
}), needsRecipient && /*#__PURE__*/jsxs(Fragment, {
|
|
1320
|
+
children: [/*#__PURE__*/jsx("span", {
|
|
1321
|
+
className: "mb-fixed",
|
|
1322
|
+
children: t("neetoRules.common.to")
|
|
1323
|
+
}), /*#__PURE__*/jsx(Token, {
|
|
1324
|
+
dataTestid: "action-recipient-".concat(index),
|
|
1325
|
+
state: recipient ? TOKEN_STATE.FILLED : TOKEN_STATE.MUTED,
|
|
1326
|
+
active: isActive({
|
|
1327
|
+
type: BUILDER_ANCHORS.ACTION_RECIPIENT,
|
|
1328
|
+
index: index
|
|
1329
|
+
}),
|
|
1330
|
+
invalid: isInvalid({
|
|
1331
|
+
type: BUILDER_ANCHORS.ACTION_RECIPIENT,
|
|
1332
|
+
index: index
|
|
1333
|
+
}),
|
|
1334
|
+
onClick: handleToken && function () {
|
|
1335
|
+
return handleToken({
|
|
1336
|
+
type: BUILDER_ANCHORS.ACTION_RECIPIENT,
|
|
1337
|
+
index: index
|
|
1338
|
+
});
|
|
1339
|
+
},
|
|
1340
|
+
children: recipient ? String(recipientLabel).toLowerCase() : t("neetoRules.builder.selectRecipient")
|
|
1341
|
+
})]
|
|
1342
|
+
})]
|
|
1343
|
+
}), /*#__PURE__*/jsxs("div", {
|
|
1344
|
+
className: "mb-row-actions",
|
|
1345
|
+
children: [handleAddAction && /*#__PURE__*/jsx(Button, {
|
|
1346
|
+
"data-testid": "action-add-".concat(index),
|
|
1347
|
+
icon: Plus,
|
|
1348
|
+
size: "small",
|
|
1349
|
+
style: "text",
|
|
1350
|
+
tooltipProps: {
|
|
1351
|
+
content: t("neetoRules.builder.aria.addAnotherAction"),
|
|
1352
|
+
position: "top"
|
|
1353
|
+
},
|
|
1354
|
+
onClick: handleAddAction
|
|
1355
|
+
}), handleRemove && /*#__PURE__*/jsx(Button, _objectSpread$7({
|
|
1356
|
+
"data-testid": "action-remove-".concat(index),
|
|
1357
|
+
icon: Delete,
|
|
1358
|
+
size: "small",
|
|
1359
|
+
style: "text",
|
|
1360
|
+
tooltipProps: {
|
|
1361
|
+
content: t("neetoRules.builder.aria.deleteAction"),
|
|
1362
|
+
position: "top"
|
|
1363
|
+
},
|
|
1364
|
+
onClick: handleRemove
|
|
1365
|
+
}, clearingHoverProps))]
|
|
1366
|
+
})]
|
|
1367
|
+
});
|
|
1368
|
+
};
|
|
1369
|
+
|
|
1370
|
+
var ThenBlock = function ThenBlock(_ref) {
|
|
1371
|
+
var rule = _ref.rule,
|
|
1372
|
+
schema = _ref.schema,
|
|
1373
|
+
handleToken = _ref.onToken,
|
|
1374
|
+
handleAddAction = _ref.onAddAction,
|
|
1375
|
+
handleRemoveAction = _ref.onRemoveAction,
|
|
1376
|
+
_ref$isActive = _ref.isActive,
|
|
1377
|
+
isActive = _ref$isActive === void 0 ? function () {
|
|
1378
|
+
return false;
|
|
1379
|
+
} : _ref$isActive,
|
|
1380
|
+
_ref$isInvalid = _ref.isInvalid,
|
|
1381
|
+
isInvalid = _ref$isInvalid === void 0 ? function () {
|
|
1382
|
+
return false;
|
|
1383
|
+
} : _ref$isInvalid,
|
|
1384
|
+
_ref$adding = _ref.adding,
|
|
1385
|
+
adding = _ref$adding === void 0 ? false : _ref$adding;
|
|
1386
|
+
var _useTranslation = useTranslation(),
|
|
1387
|
+
t = _useTranslation.t;
|
|
1388
|
+
var named = rule.actions.map(function (action, index) {
|
|
1389
|
+
return {
|
|
1390
|
+
action: action,
|
|
1391
|
+
index: index
|
|
1392
|
+
};
|
|
1393
|
+
}).filter(function (_ref2) {
|
|
1394
|
+
var action = _ref2.action;
|
|
1395
|
+
return (action === null || action === void 0 ? void 0 : action.channel) || (action === null || action === void 0 ? void 0 : action.name);
|
|
1396
|
+
});
|
|
1397
|
+
if (isEmpty(named)) {
|
|
1398
|
+
var isTriggerSet = hasTrigger(rule);
|
|
1399
|
+
return /*#__PURE__*/jsx("div", {
|
|
1400
|
+
className: "mb-row",
|
|
1401
|
+
children: /*#__PURE__*/jsx("div", {
|
|
1402
|
+
className: "mb-sentence",
|
|
1403
|
+
children: /*#__PURE__*/jsx(Token, {
|
|
1404
|
+
active: isActive({
|
|
1405
|
+
type: BUILDER_ANCHORS.ACTION_ADD,
|
|
1406
|
+
index: 0
|
|
1407
|
+
}),
|
|
1408
|
+
dataTestid: "action-add",
|
|
1409
|
+
invalid: isInvalid({
|
|
1410
|
+
type: BUILDER_ANCHORS.ACTION_ADD,
|
|
1411
|
+
index: 0
|
|
1412
|
+
}),
|
|
1413
|
+
state: isTriggerSet ? TOKEN_STATE.PLACEHOLDER_NEXT : TOKEN_STATE.DISABLED,
|
|
1414
|
+
title: isTriggerSet ? undefined : t("neetoRules.builder.pickTriggerFirst"),
|
|
1415
|
+
onClick: isTriggerSet ? handleAddAction : undefined,
|
|
1416
|
+
children: t("neetoRules.builder.thenDoThis")
|
|
1417
|
+
})
|
|
1418
|
+
})
|
|
1419
|
+
});
|
|
1420
|
+
}
|
|
1421
|
+
return /*#__PURE__*/jsxs(Fragment, {
|
|
1422
|
+
children: [named.map(function (_ref3, position) {
|
|
1423
|
+
var _action$id;
|
|
1424
|
+
var action = _ref3.action,
|
|
1425
|
+
index = _ref3.index;
|
|
1426
|
+
return /*#__PURE__*/createElement(ActionRow, {
|
|
1427
|
+
action: action,
|
|
1428
|
+
index: index,
|
|
1429
|
+
isActive: isActive,
|
|
1430
|
+
isInvalid: isInvalid,
|
|
1431
|
+
position: position,
|
|
1432
|
+
schema: schema,
|
|
1433
|
+
key: (_action$id = action.id) !== null && _action$id !== void 0 ? _action$id : index,
|
|
1434
|
+
onAddAction: position === named.length - 1 && handleAddAction,
|
|
1435
|
+
onRemove: handleRemoveAction && function () {
|
|
1436
|
+
return handleRemoveAction(index);
|
|
1437
|
+
},
|
|
1438
|
+
onToken: handleToken
|
|
1439
|
+
});
|
|
1440
|
+
}), adding && /*#__PURE__*/jsx("div", {
|
|
1441
|
+
className: "mb-row",
|
|
1442
|
+
children: /*#__PURE__*/jsxs("div", {
|
|
1443
|
+
className: "mb-sentence",
|
|
1444
|
+
children: [/*#__PURE__*/jsx("span", {
|
|
1445
|
+
className: "mb-fixed",
|
|
1446
|
+
children: t("neetoRules.operators.and")
|
|
1447
|
+
}), /*#__PURE__*/jsx(Token, {
|
|
1448
|
+
active: true,
|
|
1449
|
+
dataTestid: "action-add-next",
|
|
1450
|
+
state: TOKEN_STATE.PLACEHOLDER_NEXT,
|
|
1451
|
+
onClick: handleAddAction,
|
|
1452
|
+
children: t("neetoRules.form.doThis")
|
|
1453
|
+
})]
|
|
1454
|
+
})
|
|
1455
|
+
})]
|
|
1456
|
+
});
|
|
1457
|
+
};
|
|
1458
|
+
|
|
1459
|
+
function ownKeys$6(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; }
|
|
1460
|
+
function _objectSpread$6(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$6(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$6(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
1461
|
+
var WhenBlock = function WhenBlock(_ref) {
|
|
1462
|
+
var _schema$actor;
|
|
1463
|
+
var rule = _ref.rule,
|
|
1464
|
+
schema = _ref.schema,
|
|
1465
|
+
handleToken = _ref.onToken,
|
|
1466
|
+
handleAddCondition = _ref.onAddCondition,
|
|
1467
|
+
handleClearTrigger = _ref.onClearTrigger,
|
|
1468
|
+
_ref$isActive = _ref.isActive,
|
|
1469
|
+
isActive = _ref$isActive === void 0 ? function () {
|
|
1470
|
+
return false;
|
|
1471
|
+
} : _ref$isActive,
|
|
1472
|
+
_ref$isInvalid = _ref.isInvalid,
|
|
1473
|
+
isInvalid = _ref$isInvalid === void 0 ? function () {
|
|
1474
|
+
return false;
|
|
1475
|
+
} : _ref$isInvalid;
|
|
1476
|
+
var _useTranslation = useTranslation(),
|
|
1477
|
+
t = _useTranslation.t;
|
|
1478
|
+
var triggers = rule.triggers,
|
|
1479
|
+
performer = rule.performer;
|
|
1480
|
+
var isActorEnabled = schema === null || schema === void 0 || (_schema$actor = schema.actor) === null || _schema$actor === void 0 ? void 0 : _schema$actor.enabled;
|
|
1481
|
+
var _useClearingHover = useClearingHover(),
|
|
1482
|
+
clearing = _useClearingHover.clearing,
|
|
1483
|
+
clearingHoverProps = _useClearingHover.clearingHoverProps,
|
|
1484
|
+
resetClearing = _useClearingHover.resetClearing;
|
|
1485
|
+
// eslint-disable-next-line @bigbinary/neeto/prefer-function-reference
|
|
1486
|
+
var hasLeadTimeFor = function hasLeadTimeFor(name) {
|
|
1487
|
+
var _schema$triggers;
|
|
1488
|
+
return ((schema === null || schema === void 0 || (_schema$triggers = schema.triggers) === null || _schema$triggers === void 0 || (_schema$triggers = _schema$triggers.leadTime) === null || _schema$triggers === void 0 ? void 0 : _schema$triggers.appliesTo) || []).includes(name);
|
|
1489
|
+
};
|
|
1490
|
+
if (isEmpty(triggers)) {
|
|
1491
|
+
return /*#__PURE__*/jsx("div", {
|
|
1492
|
+
className: "mb-row",
|
|
1493
|
+
children: /*#__PURE__*/jsx("div", {
|
|
1494
|
+
className: "mb-sentence",
|
|
1495
|
+
children: /*#__PURE__*/jsx(Token, {
|
|
1496
|
+
dataTestid: "trigger-add",
|
|
1497
|
+
state: TOKEN_STATE.PLACEHOLDER_NEXT,
|
|
1498
|
+
onClick: handleToken && function () {
|
|
1499
|
+
return handleToken({
|
|
1500
|
+
type: BUILDER_ANCHORS.TRIGGER_ADD
|
|
1501
|
+
});
|
|
1502
|
+
},
|
|
1503
|
+
children: t("neetoRules.builder.whenThisHappens")
|
|
1504
|
+
})
|
|
1505
|
+
})
|
|
1506
|
+
});
|
|
1507
|
+
}
|
|
1508
|
+
return /*#__PURE__*/jsxs("div", {
|
|
1509
|
+
className: classNames("mb-row", {
|
|
1510
|
+
clearing: clearing
|
|
1511
|
+
}),
|
|
1512
|
+
children: [/*#__PURE__*/jsxs("div", {
|
|
1513
|
+
className: "mb-sentence",
|
|
1514
|
+
children: [/*#__PURE__*/jsx("span", {
|
|
1515
|
+
className: "mb-fixed",
|
|
1516
|
+
children: t("neetoRules.common.when")
|
|
1517
|
+
}), triggers.map(function (trigger, index) {
|
|
1518
|
+
var _trigger$id;
|
|
1519
|
+
return /*#__PURE__*/jsxs(Fragment$1, {
|
|
1520
|
+
children: [index > 0 && /*#__PURE__*/jsx("span", {
|
|
1521
|
+
className: "mb-fixed",
|
|
1522
|
+
children: t("neetoRules.operators.or")
|
|
1523
|
+
}), hasLeadTimeFor(trigger.name) && /*#__PURE__*/jsx(Token, {
|
|
1524
|
+
dataTestid: "trigger-lead-time-".concat(index),
|
|
1525
|
+
active: isActive({
|
|
1526
|
+
type: BUILDER_ANCHORS.TRIGGER_LEAD_TIME,
|
|
1527
|
+
index: index
|
|
1528
|
+
}),
|
|
1529
|
+
onClick: handleToken && function () {
|
|
1530
|
+
return handleToken({
|
|
1531
|
+
type: BUILDER_ANCHORS.TRIGGER_LEAD_TIME,
|
|
1532
|
+
index: index
|
|
1533
|
+
});
|
|
1534
|
+
},
|
|
1535
|
+
children: leadTimeLabel(rule.leadTime)
|
|
1536
|
+
}), /*#__PURE__*/jsx(Token, {
|
|
1537
|
+
dataTestid: "trigger-".concat(index),
|
|
1538
|
+
active: isActive({
|
|
1539
|
+
type: BUILDER_ANCHORS.TRIGGER_REPLACE,
|
|
1540
|
+
index: index
|
|
1541
|
+
}) || index === 0 && isActive({
|
|
1542
|
+
type: BUILDER_ANCHORS.TRIGGER_ADD,
|
|
1543
|
+
index: undefined
|
|
1544
|
+
}),
|
|
1545
|
+
onClick: handleToken && function () {
|
|
1546
|
+
return handleToken({
|
|
1547
|
+
type: BUILDER_ANCHORS.TRIGGER_REPLACE,
|
|
1548
|
+
index: index,
|
|
1549
|
+
trigger: trigger
|
|
1550
|
+
});
|
|
1551
|
+
},
|
|
1552
|
+
children: triggerLabel({
|
|
1553
|
+
schema: schema,
|
|
1554
|
+
trigger: trigger
|
|
1555
|
+
})
|
|
1556
|
+
})]
|
|
1557
|
+
}, (_trigger$id = trigger.id) !== null && _trigger$id !== void 0 ? _trigger$id : index);
|
|
1558
|
+
}), isActorEnabled && /*#__PURE__*/jsxs(Fragment, {
|
|
1559
|
+
children: [/*#__PURE__*/jsx("span", {
|
|
1560
|
+
className: "mb-fixed",
|
|
1561
|
+
children: t("neetoRules.common.by")
|
|
1562
|
+
}), /*#__PURE__*/jsx(Token, {
|
|
1563
|
+
dataTestid: "trigger-actor",
|
|
1564
|
+
state: performer ? TOKEN_STATE.FILLED : TOKEN_STATE.MUTED,
|
|
1565
|
+
active: isActive({
|
|
1566
|
+
type: BUILDER_ANCHORS.TRIGGER_ACTOR,
|
|
1567
|
+
index: undefined
|
|
1568
|
+
}),
|
|
1569
|
+
invalid: isInvalid({
|
|
1570
|
+
type: BUILDER_ANCHORS.TRIGGER_ACTOR,
|
|
1571
|
+
index: undefined
|
|
1572
|
+
}),
|
|
1573
|
+
onClick: handleToken && function () {
|
|
1574
|
+
return handleToken({
|
|
1575
|
+
type: BUILDER_ANCHORS.TRIGGER_ACTOR
|
|
1576
|
+
});
|
|
1577
|
+
},
|
|
1578
|
+
children: performer ? performerLabel({
|
|
1579
|
+
schema: schema,
|
|
1580
|
+
performer: performer
|
|
1581
|
+
}) : t("neetoRules.builder.selectActor")
|
|
1582
|
+
})]
|
|
1583
|
+
})]
|
|
1584
|
+
}), /*#__PURE__*/jsxs("div", {
|
|
1585
|
+
className: "mb-row-actions",
|
|
1586
|
+
children: [handleAddCondition && /*#__PURE__*/jsx(Button, {
|
|
1587
|
+
"data-testid": "trigger-add-condition",
|
|
1588
|
+
icon: Plus,
|
|
1589
|
+
size: "small",
|
|
1590
|
+
style: "text",
|
|
1591
|
+
tooltipProps: {
|
|
1592
|
+
content: t("neetoRules.builder.aria.addCondition"),
|
|
1593
|
+
position: "top"
|
|
1594
|
+
},
|
|
1595
|
+
onClick: handleAddCondition
|
|
1596
|
+
}), handleClearTrigger && /*#__PURE__*/jsx(Button, _objectSpread$6({
|
|
1597
|
+
"data-testid": "trigger-clear",
|
|
1598
|
+
icon: Delete,
|
|
1599
|
+
size: "small",
|
|
1600
|
+
style: "text",
|
|
1601
|
+
tooltipProps: {
|
|
1602
|
+
content: t("neetoRules.builder.aria.clearTrigger"),
|
|
1603
|
+
position: "top"
|
|
1604
|
+
},
|
|
1605
|
+
onClick: function onClick() {
|
|
1606
|
+
resetClearing();
|
|
1607
|
+
handleClearTrigger();
|
|
1608
|
+
}
|
|
1609
|
+
}, clearingHoverProps))]
|
|
1610
|
+
})]
|
|
1611
|
+
});
|
|
1612
|
+
};
|
|
1613
|
+
|
|
1614
|
+
function ownKeys$5(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; }
|
|
1615
|
+
function _objectSpread$5(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$5(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$5(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
1616
|
+
var usePaneCascade = function usePaneCascade(schema) {
|
|
1617
|
+
var _useUtilityStore = useUtilityStore(useShallow(function (store) {
|
|
1618
|
+
return {
|
|
1619
|
+
setPanelState: store["setPanelState"],
|
|
1620
|
+
resetPanelState: store["resetPanelState"]
|
|
1621
|
+
};
|
|
1622
|
+
})),
|
|
1623
|
+
setPanelState = _useUtilityStore.setPanelState,
|
|
1624
|
+
resetPanelState = _useUtilityStore.resetPanelState;
|
|
1625
|
+
var openType = useCallback(function (_ref) {
|
|
1626
|
+
var type = _ref.type,
|
|
1627
|
+
_ref$data = _ref.data,
|
|
1628
|
+
data = _ref$data === void 0 ? {} : _ref$data;
|
|
1629
|
+
return setPanelState({
|
|
1630
|
+
type: type,
|
|
1631
|
+
variant: "builder",
|
|
1632
|
+
size: LARGE_PANEL_TYPES.includes(type) ? "large" : "small",
|
|
1633
|
+
data: _objectSpread$5({
|
|
1634
|
+
schema: schema
|
|
1635
|
+
}, data)
|
|
1636
|
+
});
|
|
1637
|
+
}, [schema, setPanelState]);
|
|
1638
|
+
var openPane = useCallback(function (token) {
|
|
1639
|
+
var type = TOKEN_TO_PANEL_TYPE[token === null || token === void 0 ? void 0 : token.type];
|
|
1640
|
+
if (!type) return;
|
|
1641
|
+
openType({
|
|
1642
|
+
type: type,
|
|
1643
|
+
data: {
|
|
1644
|
+
anchor: token.type,
|
|
1645
|
+
index: token.index
|
|
1646
|
+
}
|
|
1647
|
+
});
|
|
1648
|
+
}, [openType]);
|
|
1649
|
+
return {
|
|
1650
|
+
openPane: openPane,
|
|
1651
|
+
openType: openType,
|
|
1652
|
+
closePane: resetPanelState
|
|
1653
|
+
};
|
|
1654
|
+
};
|
|
1655
|
+
|
|
1656
|
+
var useRuleModel = function useRuleModel(schema) {
|
|
1657
|
+
var _useFormikContext = useFormikContext(),
|
|
1658
|
+
values = _useFormikContext.values,
|
|
1659
|
+
setFieldValue = _useFormikContext.setFieldValue;
|
|
1660
|
+
var apply = function apply(_ref) {
|
|
1661
|
+
var path = _ref.path,
|
|
1662
|
+
value = _ref.value;
|
|
1663
|
+
return setFieldValue(path, value);
|
|
1664
|
+
};
|
|
1665
|
+
var applyAll = function applyAll(edits) {
|
|
1666
|
+
return edits.forEach(apply);
|
|
1667
|
+
};
|
|
1668
|
+
var rule = useMemo(function () {
|
|
1669
|
+
return valuesToRuleModel({
|
|
1670
|
+
values: values,
|
|
1671
|
+
schema: schema
|
|
1672
|
+
});
|
|
1673
|
+
}, [values, schema]);
|
|
1674
|
+
return {
|
|
1675
|
+
rule: rule,
|
|
1676
|
+
fieldKeys: fieldKeysFromSchema(schema),
|
|
1677
|
+
setTriggers: function setTriggers$1(triggers) {
|
|
1678
|
+
return apply(setTriggers({
|
|
1679
|
+
schema: schema,
|
|
1680
|
+
triggers: triggers
|
|
1681
|
+
}));
|
|
1682
|
+
},
|
|
1683
|
+
setPerformer: function setPerformer$1(performer) {
|
|
1684
|
+
return apply(setPerformer({
|
|
1685
|
+
schema: schema,
|
|
1686
|
+
performer: performer
|
|
1687
|
+
}));
|
|
1688
|
+
},
|
|
1689
|
+
setActions: function setActions$1(actions) {
|
|
1690
|
+
return apply(setActions({
|
|
1691
|
+
schema: schema,
|
|
1692
|
+
actions: actions
|
|
1693
|
+
}));
|
|
1694
|
+
},
|
|
1695
|
+
setConditions: function setConditions$1(conditions) {
|
|
1696
|
+
return apply(setConditions({
|
|
1697
|
+
schema: schema,
|
|
1698
|
+
conditions: conditions
|
|
1699
|
+
}));
|
|
1700
|
+
},
|
|
1701
|
+
setConditionMode: function setConditionMode$1(joinType) {
|
|
1702
|
+
return apply(setConditionMode({
|
|
1703
|
+
schema: schema,
|
|
1704
|
+
conditions: rule.conditions,
|
|
1705
|
+
joinType: joinType
|
|
1706
|
+
}));
|
|
1707
|
+
},
|
|
1708
|
+
setDelay: function setDelay$1(delay) {
|
|
1709
|
+
return apply(setDelay({
|
|
1710
|
+
schema: schema,
|
|
1711
|
+
delay: delay
|
|
1712
|
+
}));
|
|
1713
|
+
},
|
|
1714
|
+
setActive: function setActive$1(active) {
|
|
1715
|
+
return apply(setActive({
|
|
1716
|
+
schema: schema,
|
|
1717
|
+
active: active
|
|
1718
|
+
}));
|
|
1719
|
+
},
|
|
1720
|
+
setScope: function setScope$1(scope) {
|
|
1721
|
+
return apply(setScope({
|
|
1722
|
+
schema: schema,
|
|
1723
|
+
scope: scope
|
|
1724
|
+
}));
|
|
1725
|
+
},
|
|
1726
|
+
removeCondition: function removeCondition(index) {
|
|
1727
|
+
return applyAll(removeArrayItem({
|
|
1728
|
+
values: values,
|
|
1729
|
+
fieldKey: fieldKeysFromSchema(schema).conditions,
|
|
1730
|
+
index: index
|
|
1731
|
+
}));
|
|
1732
|
+
},
|
|
1733
|
+
removeAction: function removeAction(index) {
|
|
1734
|
+
return applyAll(removeArrayItem({
|
|
1735
|
+
values: values,
|
|
1736
|
+
fieldKey: fieldKeysFromSchema(schema).actions,
|
|
1737
|
+
index: index
|
|
1738
|
+
}));
|
|
1739
|
+
}
|
|
1740
|
+
};
|
|
1741
|
+
};
|
|
1742
|
+
|
|
1743
|
+
function ownKeys$4(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; }
|
|
1744
|
+
function _objectSpread$4(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$4(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$4(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
1745
|
+
var triggerValue = function triggerValue(option) {
|
|
1746
|
+
var _ref, _option$eventValue;
|
|
1747
|
+
return (_ref = (_option$eventValue = option.eventValue) !== null && _option$eventValue !== void 0 ? _option$eventValue : option.value) !== null && _ref !== void 0 ? _ref : option.id;
|
|
1748
|
+
};
|
|
1749
|
+
var optionValue = function optionValue(option) {
|
|
1750
|
+
var _option$value;
|
|
1751
|
+
return (_option$value = option.value) !== null && _option$value !== void 0 ? _option$value : option.id;
|
|
1752
|
+
};
|
|
1753
|
+
var normalizeOptions = function normalizeOptions(options) {
|
|
1754
|
+
return (options || []).map(function (option) {
|
|
1755
|
+
return typeof option === "string" ? toLabelAndValue(option) : option;
|
|
1756
|
+
});
|
|
1757
|
+
};
|
|
1758
|
+
var groupByCategory = function groupByCategory(options) {
|
|
1759
|
+
var groups = [];
|
|
1760
|
+
var indexByCategory = {};
|
|
1761
|
+
options.forEach(function (option) {
|
|
1762
|
+
var category = option.category || "";
|
|
1763
|
+
// eslint-disable-next-line security/detect-object-injection
|
|
1764
|
+
if (indexByCategory[category] === undefined) {
|
|
1765
|
+
// eslint-disable-next-line security/detect-object-injection
|
|
1766
|
+
indexByCategory[category] = groups.length;
|
|
1767
|
+
groups.push([category, []]);
|
|
1768
|
+
}
|
|
1769
|
+
// eslint-disable-next-line security/detect-object-injection
|
|
1770
|
+
groups[indexByCategory[category]][1].push(option);
|
|
1771
|
+
});
|
|
1772
|
+
return groups;
|
|
1773
|
+
};
|
|
1774
|
+
var conditionAt = function conditionAt(_ref2) {
|
|
1775
|
+
var rule = _ref2.rule,
|
|
1776
|
+
index = _ref2.index;
|
|
1777
|
+
return (
|
|
1778
|
+
// eslint-disable-next-line security/detect-object-injection
|
|
1779
|
+
rule.conditions[index] || {}
|
|
1780
|
+
);
|
|
1781
|
+
};
|
|
1782
|
+
|
|
1783
|
+
// eslint-disable-next-line security/detect-object-injection
|
|
1784
|
+
var actionAt = function actionAt(_ref3) {
|
|
1785
|
+
var rule = _ref3.rule,
|
|
1786
|
+
index = _ref3.index;
|
|
1787
|
+
return rule.actions[index] || {};
|
|
1788
|
+
};
|
|
1789
|
+
var findField = function findField(_ref4) {
|
|
1790
|
+
var _schema$conditions;
|
|
1791
|
+
var schema = _ref4.schema,
|
|
1792
|
+
value = _ref4.value;
|
|
1793
|
+
return (((_schema$conditions = schema.conditions) === null || _schema$conditions === void 0 ? void 0 : _schema$conditions.fields) || []).find(function (field) {
|
|
1794
|
+
return optionValue(field) === value;
|
|
1795
|
+
});
|
|
1796
|
+
};
|
|
1797
|
+
var findActionOption = function findActionOption(_ref5) {
|
|
1798
|
+
var _schema$actions;
|
|
1799
|
+
var schema = _ref5.schema,
|
|
1800
|
+
name = _ref5.name;
|
|
1801
|
+
return (((_schema$actions = schema.actions) === null || _schema$actions === void 0 ? void 0 : _schema$actions.options) || []).find(function (option) {
|
|
1802
|
+
return optionValue(option) === name;
|
|
1803
|
+
});
|
|
1804
|
+
};
|
|
1805
|
+
var channelOf = function channelOf(_ref6) {
|
|
1806
|
+
var _schema$actions2, _schema$actions2$acti;
|
|
1807
|
+
var schema = _ref6.schema,
|
|
1808
|
+
action = _ref6.action;
|
|
1809
|
+
return (action === null || action === void 0 ? void 0 : action.channel) || ((_schema$actions2 = schema.actions) === null || _schema$actions2 === void 0 || (_schema$actions2$acti = _schema$actions2.actionForName) === null || _schema$actions2$acti === void 0 || (_schema$actions2$acti = _schema$actions2$acti.call(_schema$actions2, action === null || action === void 0 ? void 0 : action.name)) === null || _schema$actions2$acti === void 0 ? void 0 : _schema$actions2$acti.channel);
|
|
1810
|
+
};
|
|
1811
|
+
var channelMetaOf = function channelMetaOf(_ref7) {
|
|
1812
|
+
var _schema$actions3;
|
|
1813
|
+
var schema = _ref7.schema,
|
|
1814
|
+
action = _ref7.action;
|
|
1815
|
+
return ((_schema$actions3 = schema.actions) === null || _schema$actions3 === void 0 || (_schema$actions3 = _schema$actions3.channelMeta) === null || _schema$actions3 === void 0 ? void 0 : _schema$actions3[channelOf({
|
|
1816
|
+
schema: schema,
|
|
1817
|
+
action: action
|
|
1818
|
+
})]) || {};
|
|
1819
|
+
};
|
|
1820
|
+
var actionHasConfig = function actionHasConfig(_ref8) {
|
|
1821
|
+
var _schema$actions4, _schema$actions5;
|
|
1822
|
+
var schema = _ref8.schema,
|
|
1823
|
+
action = _ref8.action;
|
|
1824
|
+
var meta = channelMetaOf({
|
|
1825
|
+
schema: schema,
|
|
1826
|
+
action: action
|
|
1827
|
+
});
|
|
1828
|
+
if (meta.mediumLabel) return true;
|
|
1829
|
+
var option = findActionOption({
|
|
1830
|
+
schema: schema,
|
|
1831
|
+
name: action === null || action === void 0 ? void 0 : action.name
|
|
1832
|
+
});
|
|
1833
|
+
if (option !== null && option !== void 0 && option.component || option !== null && option !== void 0 && option.renderConfig) return true;
|
|
1834
|
+
if ((_schema$actions4 = schema.actions) !== null && _schema$actions4 !== void 0 && _schema$actions4.hasConfig) return schema.actions.hasConfig(action);
|
|
1835
|
+
return !!((_schema$actions5 = schema.actions) !== null && _schema$actions5 !== void 0 && _schema$actions5.renderConfig);
|
|
1836
|
+
};
|
|
1837
|
+
var recipientsFor = function recipientsFor(_ref9) {
|
|
1838
|
+
var _schema$actions6, _schema$actions7;
|
|
1839
|
+
var schema = _ref9.schema,
|
|
1840
|
+
action = _ref9.action;
|
|
1841
|
+
var channel = channelOf({
|
|
1842
|
+
schema: schema,
|
|
1843
|
+
action: action
|
|
1844
|
+
});
|
|
1845
|
+
if (channel && (_schema$actions6 = schema.actions) !== null && _schema$actions6 !== void 0 && _schema$actions6.recipientsFor) {
|
|
1846
|
+
return schema.actions.recipientsFor(channel);
|
|
1847
|
+
}
|
|
1848
|
+
var option = findActionOption({
|
|
1849
|
+
schema: schema,
|
|
1850
|
+
name: channel
|
|
1851
|
+
});
|
|
1852
|
+
if (option !== null && option !== void 0 && option.recipients) return option.recipients;
|
|
1853
|
+
return ((_schema$actions7 = schema.actions) === null || _schema$actions7 === void 0 ? void 0 : _schema$actions7.recipients) || [];
|
|
1854
|
+
};
|
|
1855
|
+
var nextTriggers = function nextTriggers(_ref0) {
|
|
1856
|
+
var _schema$triggers;
|
|
1857
|
+
var schema = _ref0.schema,
|
|
1858
|
+
rule = _ref0.rule,
|
|
1859
|
+
value = _ref0.value;
|
|
1860
|
+
if ((_schema$triggers = schema.triggers) !== null && _schema$triggers !== void 0 && _schema$triggers.multi) {
|
|
1861
|
+
var names = pluck("name", rule.triggers);
|
|
1862
|
+
return names.includes(value) ? removeBy({
|
|
1863
|
+
name: value
|
|
1864
|
+
}, rule.triggers) : [].concat(_toConsumableArray(rule.triggers), [{
|
|
1865
|
+
name: value
|
|
1866
|
+
}]);
|
|
1867
|
+
}
|
|
1868
|
+
return [{
|
|
1869
|
+
name: value
|
|
1870
|
+
}];
|
|
1871
|
+
};
|
|
1872
|
+
var nextConditionAt = function nextConditionAt(_ref1) {
|
|
1873
|
+
var _field$allowMatching;
|
|
1874
|
+
var schema = _ref1.schema,
|
|
1875
|
+
rule = _ref1.rule,
|
|
1876
|
+
index = _ref1.index,
|
|
1877
|
+
value = _ref1.value;
|
|
1878
|
+
var field = findField({
|
|
1879
|
+
schema: schema,
|
|
1880
|
+
value: value
|
|
1881
|
+
});
|
|
1882
|
+
var previous = conditionAt({
|
|
1883
|
+
rule: rule,
|
|
1884
|
+
index: index
|
|
1885
|
+
});
|
|
1886
|
+
var first = field === null || field === void 0 || (_field$allowMatching = field.allowMatching) === null || _field$allowMatching === void 0 ? void 0 : _field$allowMatching[0];
|
|
1887
|
+
var defaultVerb = first && !((field === null || field === void 0 ? void 0 : field.noValueForVerbs) || []).includes(first) ? first : undefined;
|
|
1888
|
+
var verb = ((field === null || field === void 0 ? void 0 : field.allowMatching) || []).includes(previous.verb) ? previous.verb : defaultVerb;
|
|
1889
|
+
return _objectSpread$4(_objectSpread$4({}, previous), {}, {
|
|
1890
|
+
field: value,
|
|
1891
|
+
kind: field === null || field === void 0 ? void 0 : field.kind,
|
|
1892
|
+
verb: verb,
|
|
1893
|
+
metadata: {}
|
|
1894
|
+
});
|
|
1895
|
+
};
|
|
1896
|
+
var nextActionAt = function nextActionAt(_ref10) {
|
|
1897
|
+
var _schema$actions8;
|
|
1898
|
+
var schema = _ref10.schema,
|
|
1899
|
+
rule = _ref10.rule,
|
|
1900
|
+
index = _ref10.index,
|
|
1901
|
+
value = _ref10.value;
|
|
1902
|
+
if (!((_schema$actions8 = schema.actions) !== null && _schema$actions8 !== void 0 && _schema$actions8.resolveName)) {
|
|
1903
|
+
var option = findActionOption({
|
|
1904
|
+
schema: schema,
|
|
1905
|
+
name: value
|
|
1906
|
+
});
|
|
1907
|
+
var _prev = actionAt({
|
|
1908
|
+
rule: rule,
|
|
1909
|
+
index: index
|
|
1910
|
+
});
|
|
1911
|
+
if (option !== null && option !== void 0 && option.recipients) {
|
|
1912
|
+
var _channelChanged = _prev.channel !== value;
|
|
1913
|
+
return _objectSpread$4(_objectSpread$4({}, _prev), {}, {
|
|
1914
|
+
channel: value,
|
|
1915
|
+
recipient: _channelChanged ? undefined : _prev.recipient,
|
|
1916
|
+
name: "",
|
|
1917
|
+
type: option === null || option === void 0 ? void 0 : option.type,
|
|
1918
|
+
metadata: _channelChanged ? {} : _prev.metadata
|
|
1919
|
+
});
|
|
1920
|
+
}
|
|
1921
|
+
return _objectSpread$4(_objectSpread$4({}, _prev), {}, {
|
|
1922
|
+
channel: undefined,
|
|
1923
|
+
recipient: undefined,
|
|
1924
|
+
name: value,
|
|
1925
|
+
type: option === null || option === void 0 ? void 0 : option.type,
|
|
1926
|
+
metadata: {}
|
|
1927
|
+
});
|
|
1928
|
+
}
|
|
1929
|
+
var prev = actionAt({
|
|
1930
|
+
rule: rule,
|
|
1931
|
+
index: index
|
|
1932
|
+
});
|
|
1933
|
+
var prevChannel = channelOf({
|
|
1934
|
+
schema: schema,
|
|
1935
|
+
action: prev
|
|
1936
|
+
});
|
|
1937
|
+
var channelChanged = prevChannel !== value;
|
|
1938
|
+
var recipient = channelChanged ? undefined : prev.recipient;
|
|
1939
|
+
if (channelChanged) {
|
|
1940
|
+
var _schema$actions9;
|
|
1941
|
+
var channelRecipients =
|
|
1942
|
+
// eslint-disable-next-line security/detect-object-injection
|
|
1943
|
+
((_schema$actions9 = schema.actions) === null || _schema$actions9 === void 0 || (_schema$actions9 = _schema$actions9.recipientsByChannel) === null || _schema$actions9 === void 0 ? void 0 : _schema$actions9[value]) || [];
|
|
1944
|
+
if (channelRecipients.length === 1) {
|
|
1945
|
+
var _channelRecipients = _slicedToArray(channelRecipients, 1);
|
|
1946
|
+
recipient = _channelRecipients[0];
|
|
1947
|
+
}
|
|
1948
|
+
}
|
|
1949
|
+
return _objectSpread$4(_objectSpread$4({}, prev), {}, {
|
|
1950
|
+
channel: value,
|
|
1951
|
+
recipient: recipient,
|
|
1952
|
+
name: schema.actions.resolveName({
|
|
1953
|
+
channel: value,
|
|
1954
|
+
recipient: recipient
|
|
1955
|
+
}),
|
|
1956
|
+
metadata: channelChanged ? {} : prev.metadata
|
|
1957
|
+
});
|
|
1958
|
+
};
|
|
1959
|
+
var nextActionRecipientAt = function nextActionRecipientAt(_ref11) {
|
|
1960
|
+
var _schema$actions0;
|
|
1961
|
+
var schema = _ref11.schema,
|
|
1962
|
+
rule = _ref11.rule,
|
|
1963
|
+
index = _ref11.index,
|
|
1964
|
+
value = _ref11.value;
|
|
1965
|
+
var prev = actionAt({
|
|
1966
|
+
rule: rule,
|
|
1967
|
+
index: index
|
|
1968
|
+
});
|
|
1969
|
+
var channel = channelOf({
|
|
1970
|
+
schema: schema,
|
|
1971
|
+
action: prev
|
|
1972
|
+
});
|
|
1973
|
+
return _objectSpread$4(_objectSpread$4({}, prev), {}, {
|
|
1974
|
+
recipient: value,
|
|
1975
|
+
name: (_schema$actions0 = schema.actions) !== null && _schema$actions0 !== void 0 && _schema$actions0.resolveName ? schema.actions.resolveName({
|
|
1976
|
+
channel: channel,
|
|
1977
|
+
recipient: value
|
|
1978
|
+
}) : value
|
|
1979
|
+
});
|
|
1980
|
+
};
|
|
1981
|
+
var descriptorFor = function descriptorFor(_ref12) {
|
|
1982
|
+
var _schema$actor2, _schema$conditions2;
|
|
1983
|
+
var anchor = _ref12.anchor,
|
|
1984
|
+
schema = _ref12.schema,
|
|
1985
|
+
rule = _ref12.rule,
|
|
1986
|
+
index = _ref12.index;
|
|
1987
|
+
switch (anchor) {
|
|
1988
|
+
case BUILDER_ANCHORS.TRIGGER_ADD:
|
|
1989
|
+
case BUILDER_ANCHORS.TRIGGER_REPLACE:
|
|
1990
|
+
{
|
|
1991
|
+
var _schema$triggers2, _schema$actor, _schema$triggers3;
|
|
1992
|
+
var multi = !!((_schema$triggers2 = schema.triggers) !== null && _schema$triggers2 !== void 0 && _schema$triggers2.multi);
|
|
1993
|
+
var isReplace = anchor === BUILDER_ANCHORS.TRIGGER_REPLACE;
|
|
1994
|
+
var triggerTitle = isReplace ? multi && t("neetoRules.builder.panes.changeTriggers") || t("neetoRules.builder.panes.changeTrigger") : multi && t("neetoRules.builder.panes.whenEllipsis") || t("neetoRules.builder.panes.addTrigger");
|
|
1995
|
+
var triggerSubtitle = multi && t("neetoRules.builder.panes.triggerSubtitleMulti") || (isReplace ? t("neetoRules.builder.panes.triggerSubtitleReplace") : t("neetoRules.builder.panes.triggerSubtitleAdd"));
|
|
1996
|
+
return {
|
|
1997
|
+
title: triggerTitle,
|
|
1998
|
+
subtitle: triggerSubtitle,
|
|
1999
|
+
multi: multi,
|
|
2000
|
+
cascade: !!((_schema$actor = schema.actor) !== null && _schema$actor !== void 0 && _schema$actor.enabled),
|
|
2001
|
+
options: (((_schema$triggers3 = schema.triggers) === null || _schema$triggers3 === void 0 ? void 0 : _schema$triggers3.options) || []).map(function (option) {
|
|
2002
|
+
return {
|
|
2003
|
+
label: option.paneLabel || option.label,
|
|
2004
|
+
value: triggerValue(option),
|
|
2005
|
+
category: option.category
|
|
2006
|
+
};
|
|
2007
|
+
}),
|
|
2008
|
+
selectedValues: pluck("name", rule.triggers)
|
|
2009
|
+
};
|
|
2010
|
+
}
|
|
2011
|
+
case BUILDER_ANCHORS.TRIGGER_ACTOR:
|
|
2012
|
+
return {
|
|
2013
|
+
title: t("neetoRules.builder.panes.actorTitle"),
|
|
2014
|
+
subtitle: t("neetoRules.builder.panes.actorSubtitle"),
|
|
2015
|
+
options: (((_schema$actor2 = schema.actor) === null || _schema$actor2 === void 0 ? void 0 : _schema$actor2.options) || []).map(function (option) {
|
|
2016
|
+
return {
|
|
2017
|
+
label: option.label,
|
|
2018
|
+
value: optionValue(option)
|
|
2019
|
+
};
|
|
2020
|
+
}),
|
|
2021
|
+
selectedValues: [rule.performer]
|
|
2022
|
+
};
|
|
2023
|
+
case BUILDER_ANCHORS.COND_FIELD:
|
|
2024
|
+
return {
|
|
2025
|
+
title: t("neetoRules.builder.panes.addCondition"),
|
|
2026
|
+
subtitle: t("neetoRules.builder.panes.condFieldSubtitle"),
|
|
2027
|
+
cascade: true,
|
|
2028
|
+
options: (((_schema$conditions2 = schema.conditions) === null || _schema$conditions2 === void 0 ? void 0 : _schema$conditions2.fields) || []).map(function (field) {
|
|
2029
|
+
return {
|
|
2030
|
+
label: field.paneLabel || field.label,
|
|
2031
|
+
value: optionValue(field),
|
|
2032
|
+
category: field.category
|
|
2033
|
+
};
|
|
2034
|
+
}),
|
|
2035
|
+
selectedValues: [conditionAt({
|
|
2036
|
+
rule: rule,
|
|
2037
|
+
index: index
|
|
2038
|
+
}).field]
|
|
2039
|
+
};
|
|
2040
|
+
case BUILDER_ANCHORS.COND_OP_TOGGLE:
|
|
2041
|
+
{
|
|
2042
|
+
var _schema$conditions3;
|
|
2043
|
+
var field = findField({
|
|
2044
|
+
schema: schema,
|
|
2045
|
+
value: conditionAt({
|
|
2046
|
+
rule: rule,
|
|
2047
|
+
index: index
|
|
2048
|
+
}).field
|
|
2049
|
+
});
|
|
2050
|
+
var labels = ((_schema$conditions3 = schema.conditions) === null || _schema$conditions3 === void 0 ? void 0 : _schema$conditions3.operatorLabels) || {};
|
|
2051
|
+
var verbs = (field === null || field === void 0 ? void 0 : field.allowMatching) || [];
|
|
2052
|
+
var fieldLabel = (field === null || field === void 0 ? void 0 : field.paneLabel) || (field === null || field === void 0 ? void 0 : field.label) || "";
|
|
2053
|
+
var isContains = isNotEmpty(verbs) && verbs.every(isContainsVerb);
|
|
2054
|
+
var isNumeric = !isContains && verbs.some(isNumericVerb);
|
|
2055
|
+
var isExclude = !isContains && !isNumeric && verbs.some(isExcludeVerb);
|
|
2056
|
+
var hasOptions = isNotEmpty(normalizeOptions((field === null || field === void 0 ? void 0 : field.values) || (field === null || field === void 0 ? void 0 : field.dropdownOptions) || (field === null || field === void 0 ? void 0 : field.options)));
|
|
2057
|
+
var containsVariant = hasOptions ? "Values" : "Keywords";
|
|
2058
|
+
var numericOrExcludeVariant = isExclude ? "Exclude" : "";
|
|
2059
|
+
var nonContainsVariant = isNumeric ? "Number" : numericOrExcludeVariant;
|
|
2060
|
+
var variant = isContains ? containsVariant : nonContainsVariant;
|
|
2061
|
+
return {
|
|
2062
|
+
title: t("neetoRules.builder.panes.operatorTitle".concat(variant)),
|
|
2063
|
+
subtitle: variant ? t("neetoRules.builder.panes.operatorSubtitle".concat(variant), {
|
|
2064
|
+
field: fieldLabel
|
|
2065
|
+
}) : t("neetoRules.builder.panes.operatorSubtitle"),
|
|
2066
|
+
cascade: true,
|
|
2067
|
+
options: verbs.map(function (verb) {
|
|
2068
|
+
return {
|
|
2069
|
+
// eslint-disable-next-line security/detect-object-injection
|
|
2070
|
+
label: labels[verb] || humanize(verb),
|
|
2071
|
+
value: verb
|
|
2072
|
+
};
|
|
2073
|
+
}),
|
|
2074
|
+
selectedValues: [conditionAt({
|
|
2075
|
+
rule: rule,
|
|
2076
|
+
index: index
|
|
2077
|
+
}).verb]
|
|
2078
|
+
};
|
|
2079
|
+
}
|
|
2080
|
+
case BUILDER_ANCHORS.COND_CONNECTOR:
|
|
2081
|
+
return {
|
|
2082
|
+
title: t("neetoRules.builder.panes.connectorTitle"),
|
|
2083
|
+
subtitle: t("neetoRules.builder.panes.connectorSubtitle"),
|
|
2084
|
+
options: [{
|
|
2085
|
+
label: t("neetoRules.builder.panes.connectorAndOption"),
|
|
2086
|
+
value: CONDITION_MODE.AND
|
|
2087
|
+
}, {
|
|
2088
|
+
label: t("neetoRules.builder.panes.connectorOrOption"),
|
|
2089
|
+
value: CONDITION_MODE.OR
|
|
2090
|
+
}],
|
|
2091
|
+
selectedValues: [rule.conditionMode]
|
|
2092
|
+
};
|
|
2093
|
+
case BUILDER_ANCHORS.ACTION_ADD:
|
|
2094
|
+
case BUILDER_ANCHORS.ACTION_CHANNEL:
|
|
2095
|
+
{
|
|
2096
|
+
var _schema$actions10, _schema$actions11, _channelOf;
|
|
2097
|
+
var isSwap = anchor === BUILDER_ANCHORS.ACTION_CHANNEL;
|
|
2098
|
+
var channelMetaFor = function channelMetaFor(value) {
|
|
2099
|
+
var _schema$actions1;
|
|
2100
|
+
return (
|
|
2101
|
+
// eslint-disable-next-line security/detect-object-injection
|
|
2102
|
+
((_schema$actions1 = schema.actions) === null || _schema$actions1 === void 0 || (_schema$actions1 = _schema$actions1.channelMeta) === null || _schema$actions1 === void 0 ? void 0 : _schema$actions1[value]) || {}
|
|
2103
|
+
);
|
|
2104
|
+
};
|
|
2105
|
+
var rank = function rank(value) {
|
|
2106
|
+
var idx = SWAP_CHANNEL_ORDER.indexOf(value);
|
|
2107
|
+
return idx === -1 ? SWAP_CHANNEL_ORDER.length : idx;
|
|
2108
|
+
};
|
|
2109
|
+
var sourceOptions = isSwap ? _toConsumableArray(((_schema$actions10 = schema.actions) === null || _schema$actions10 === void 0 ? void 0 : _schema$actions10.options) || []).sort(function (optionA, optionB) {
|
|
2110
|
+
return rank(optionValue(optionA)) - rank(optionValue(optionB));
|
|
2111
|
+
}) : ((_schema$actions11 = schema.actions) === null || _schema$actions11 === void 0 ? void 0 : _schema$actions11.options) || [];
|
|
2112
|
+
return {
|
|
2113
|
+
title: isSwap ? t("neetoRules.builder.panes.actionSwapTitle") : t("neetoRules.builder.panes.actionAddTitle"),
|
|
2114
|
+
subtitle: isSwap ? t("neetoRules.builder.panes.actionSwapSubtitle") : t("neetoRules.builder.panes.actionAddSubtitle"),
|
|
2115
|
+
cascade: true,
|
|
2116
|
+
options: sourceOptions.map(function (option) {
|
|
2117
|
+
var value = optionValue(option);
|
|
2118
|
+
var meta = channelMetaFor(value);
|
|
2119
|
+
return {
|
|
2120
|
+
label: isSwap ? meta.channelLabel || option.label : option.label,
|
|
2121
|
+
value: value,
|
|
2122
|
+
category: option.category,
|
|
2123
|
+
disabled: !!option.disabled,
|
|
2124
|
+
icon: (isSwap ? meta.icon : option.icon) || option.icon
|
|
2125
|
+
};
|
|
2126
|
+
}),
|
|
2127
|
+
selectedValues: [(_channelOf = channelOf({
|
|
2128
|
+
schema: schema,
|
|
2129
|
+
action: actionAt({
|
|
2130
|
+
rule: rule,
|
|
2131
|
+
index: index
|
|
2132
|
+
})
|
|
2133
|
+
})) !== null && _channelOf !== void 0 ? _channelOf : actionAt({
|
|
2134
|
+
rule: rule,
|
|
2135
|
+
index: index
|
|
2136
|
+
}).name]
|
|
2137
|
+
};
|
|
2138
|
+
}
|
|
2139
|
+
case BUILDER_ANCHORS.ACTION_RECIPIENT:
|
|
2140
|
+
{
|
|
2141
|
+
var _schema$actions12;
|
|
2142
|
+
var action = actionAt({
|
|
2143
|
+
rule: rule,
|
|
2144
|
+
index: index
|
|
2145
|
+
});
|
|
2146
|
+
var channel = channelOf({
|
|
2147
|
+
schema: schema,
|
|
2148
|
+
action: action
|
|
2149
|
+
});
|
|
2150
|
+
// eslint-disable-next-line security/detect-object-injection
|
|
2151
|
+
var meta = ((_schema$actions12 = schema.actions) === null || _schema$actions12 === void 0 || (_schema$actions12 = _schema$actions12.channelMeta) === null || _schema$actions12 === void 0 ? void 0 : _schema$actions12[channel]) || {};
|
|
2152
|
+
var option = findActionOption({
|
|
2153
|
+
schema: schema,
|
|
2154
|
+
name: channel
|
|
2155
|
+
});
|
|
2156
|
+
return {
|
|
2157
|
+
title: meta.recipientTitle || (option === null || option === void 0 ? void 0 : option.recipientTitle) || t("neetoRules.builder.panes.recipientTitle"),
|
|
2158
|
+
subtitle: meta.recipientSubtitle || (option === null || option === void 0 ? void 0 : option.recipientSubtitle) || t("neetoRules.builder.panes.recipientSubtitle"),
|
|
2159
|
+
options: recipientsFor({
|
|
2160
|
+
schema: schema,
|
|
2161
|
+
action: action
|
|
2162
|
+
}).map(function (recipient) {
|
|
2163
|
+
return {
|
|
2164
|
+
label: recipient.label,
|
|
2165
|
+
value: optionValue(recipient)
|
|
2166
|
+
};
|
|
2167
|
+
}),
|
|
2168
|
+
selectedValues: [action.recipient]
|
|
2169
|
+
};
|
|
2170
|
+
}
|
|
2171
|
+
case BUILDER_ANCHORS.SCOPE:
|
|
2172
|
+
{
|
|
2173
|
+
var _sc$requiresPhone;
|
|
2174
|
+
var sc = schema.scope || {};
|
|
2175
|
+
var selected = (rule.scope || []).map(function (item) {
|
|
2176
|
+
var _item$value;
|
|
2177
|
+
return (_item$value = item === null || item === void 0 ? void 0 : item.value) !== null && _item$value !== void 0 ? _item$value : item;
|
|
2178
|
+
});
|
|
2179
|
+
var requiresPhone = ((_sc$requiresPhone = sc.requiresPhone) === null || _sc$requiresPhone === void 0 ? void 0 : _sc$requiresPhone.call(sc, rule.actions)) || false;
|
|
2180
|
+
return {
|
|
2181
|
+
title: selected.length ? sc.paneChangeTitle || t("neetoRules.builder.panes.scopeChangeTitle") : sc.paneTitle || t("neetoRules.builder.panes.scopeTitle"),
|
|
2182
|
+
subtitle: sc.paneSubtitle || t("neetoRules.builder.panes.scopeSubtitle"),
|
|
2183
|
+
multi: true,
|
|
2184
|
+
options: (sc.options || []).map(function (option) {
|
|
2185
|
+
var value = optionValue(option);
|
|
2186
|
+
var blockedNoPhone = requiresPhone && option.hasPhoneField === false;
|
|
2187
|
+
var isSelected = selected.includes(value);
|
|
2188
|
+
return {
|
|
2189
|
+
label: option.label,
|
|
2190
|
+
value: value,
|
|
2191
|
+
disabled: (!!option.disabled || blockedNoPhone) && !isSelected,
|
|
2192
|
+
disabledReason: blockedNoPhone && sc.disabledReason,
|
|
2193
|
+
disabledTooltip: blockedNoPhone && sc.disabledTooltip
|
|
2194
|
+
};
|
|
2195
|
+
}),
|
|
2196
|
+
selectedValues: selected
|
|
2197
|
+
};
|
|
2198
|
+
}
|
|
2199
|
+
default:
|
|
2200
|
+
return {
|
|
2201
|
+
title: "",
|
|
2202
|
+
subtitle: "",
|
|
2203
|
+
options: [],
|
|
2204
|
+
selectedValues: []
|
|
2205
|
+
};
|
|
2206
|
+
}
|
|
2207
|
+
};
|
|
2208
|
+
var commitFor = function commitFor(_ref13) {
|
|
2209
|
+
var anchor = _ref13.anchor,
|
|
2210
|
+
schema = _ref13.schema,
|
|
2211
|
+
rule = _ref13.rule,
|
|
2212
|
+
index = _ref13.index,
|
|
2213
|
+
value = _ref13.value,
|
|
2214
|
+
helpers = _ref13.helpers;
|
|
2215
|
+
var setTriggers = helpers.setTriggers,
|
|
2216
|
+
setPerformer = helpers.setPerformer,
|
|
2217
|
+
setConditionMode = helpers.setConditionMode,
|
|
2218
|
+
setFieldValue = helpers.setFieldValue,
|
|
2219
|
+
fieldKeys = helpers.fieldKeys;
|
|
2220
|
+
switch (anchor) {
|
|
2221
|
+
case BUILDER_ANCHORS.TRIGGER_ADD:
|
|
2222
|
+
case BUILDER_ANCHORS.TRIGGER_REPLACE:
|
|
2223
|
+
{
|
|
2224
|
+
var _schema$triggers4, _schema$triggers5;
|
|
2225
|
+
if ((_schema$triggers4 = schema.triggers) !== null && _schema$triggers4 !== void 0 && _schema$triggers4.multi) {
|
|
2226
|
+
var names = pluck("name", rule.triggers);
|
|
2227
|
+
setTriggers(names.includes(value) ? removeBy({
|
|
2228
|
+
name: value
|
|
2229
|
+
}, rule.triggers) : [].concat(_toConsumableArray(rule.triggers), [{
|
|
2230
|
+
name: value
|
|
2231
|
+
}]));
|
|
2232
|
+
return "stay";
|
|
2233
|
+
}
|
|
2234
|
+
setTriggers([{
|
|
2235
|
+
name: value
|
|
2236
|
+
}]);
|
|
2237
|
+
var leadTime = (_schema$triggers5 = schema.triggers) === null || _schema$triggers5 === void 0 ? void 0 : _schema$triggers5.leadTime;
|
|
2238
|
+
if (leadTime !== null && leadTime !== void 0 && leadTime.fieldKey && (leadTime.appliesTo || []).includes(value) && !rule.leadTime) {
|
|
2239
|
+
var _leadTime$default;
|
|
2240
|
+
// eslint-disable-next-line @bigbinary/neeto/use-common-constants
|
|
2241
|
+
setFieldValue("".concat(leadTime.fieldKey, ".value"), (_leadTime$default = leadTime["default"]) !== null && _leadTime$default !== void 0 ? _leadTime$default : 10);
|
|
2242
|
+
}
|
|
2243
|
+
return "stay";
|
|
2244
|
+
}
|
|
2245
|
+
case BUILDER_ANCHORS.TRIGGER_ACTOR:
|
|
2246
|
+
setPerformer(value);
|
|
2247
|
+
return "stay";
|
|
2248
|
+
case BUILDER_ANCHORS.COND_FIELD:
|
|
2249
|
+
{
|
|
2250
|
+
setFieldValue("".concat(fieldKeys.conditions, ".value.").concat(index), nextConditionAt({
|
|
2251
|
+
schema: schema,
|
|
2252
|
+
rule: rule,
|
|
2253
|
+
index: index,
|
|
2254
|
+
value: value
|
|
2255
|
+
}));
|
|
2256
|
+
return "stay";
|
|
2257
|
+
}
|
|
2258
|
+
case BUILDER_ANCHORS.COND_OP_TOGGLE:
|
|
2259
|
+
setFieldValue("".concat(fieldKeys.conditions, ".value.").concat(index, ".verb"), value);
|
|
2260
|
+
return "stay";
|
|
2261
|
+
case BUILDER_ANCHORS.COND_CONNECTOR:
|
|
2262
|
+
setConditionMode(value);
|
|
2263
|
+
return "stay";
|
|
2264
|
+
case BUILDER_ANCHORS.ACTION_ADD:
|
|
2265
|
+
case BUILDER_ANCHORS.ACTION_CHANNEL:
|
|
2266
|
+
{
|
|
2267
|
+
setFieldValue("".concat(fieldKeys.actions, ".value.").concat(index), nextActionAt({
|
|
2268
|
+
schema: schema,
|
|
2269
|
+
rule: rule,
|
|
2270
|
+
index: index,
|
|
2271
|
+
value: value
|
|
2272
|
+
}));
|
|
2273
|
+
return "stay";
|
|
2274
|
+
}
|
|
2275
|
+
case BUILDER_ANCHORS.ACTION_RECIPIENT:
|
|
2276
|
+
{
|
|
2277
|
+
setFieldValue("".concat(fieldKeys.actions, ".value.").concat(index), nextActionRecipientAt({
|
|
2278
|
+
schema: schema,
|
|
2279
|
+
rule: rule,
|
|
2280
|
+
index: index,
|
|
2281
|
+
value: value
|
|
2282
|
+
}));
|
|
2283
|
+
return "stay";
|
|
2284
|
+
}
|
|
2285
|
+
case BUILDER_ANCHORS.SCOPE:
|
|
2286
|
+
{
|
|
2287
|
+
var sc = schema.scope || {};
|
|
2288
|
+
var key = sc.fieldKey || "scope";
|
|
2289
|
+
var current = rule.scope || [];
|
|
2290
|
+
var has = current.some(function (item) {
|
|
2291
|
+
var _item$value2;
|
|
2292
|
+
return ((_item$value2 = item === null || item === void 0 ? void 0 : item.value) !== null && _item$value2 !== void 0 ? _item$value2 : item) === value;
|
|
2293
|
+
});
|
|
2294
|
+
var next = has ? current.filter(function (item) {
|
|
2295
|
+
var _item$value3;
|
|
2296
|
+
return ((_item$value3 = item === null || item === void 0 ? void 0 : item.value) !== null && _item$value3 !== void 0 ? _item$value3 : item) !== value;
|
|
2297
|
+
}) : [].concat(_toConsumableArray(current), [(sc.options || []).find(function (option) {
|
|
2298
|
+
return optionValue(option) === value;
|
|
2299
|
+
}) || {
|
|
2300
|
+
value: value
|
|
2301
|
+
}]);
|
|
2302
|
+
setFieldValue("".concat(key, ".value"), next);
|
|
2303
|
+
return "stay";
|
|
2304
|
+
}
|
|
2305
|
+
default:
|
|
2306
|
+
return "close";
|
|
2307
|
+
}
|
|
2308
|
+
};
|
|
2309
|
+
var continueTargetFor = function continueTargetFor(_ref14) {
|
|
2310
|
+
var _schema$actor3;
|
|
2311
|
+
var anchor = _ref14.anchor,
|
|
2312
|
+
schema = _ref14.schema,
|
|
2313
|
+
rule = _ref14.rule,
|
|
2314
|
+
index = _ref14.index;
|
|
2315
|
+
switch (anchor) {
|
|
2316
|
+
case BUILDER_ANCHORS.TRIGGER_ADD:
|
|
2317
|
+
case BUILDER_ANCHORS.TRIGGER_REPLACE:
|
|
2318
|
+
return (_schema$actor3 = schema.actor) !== null && _schema$actor3 !== void 0 && _schema$actor3.enabled ? {
|
|
2319
|
+
type: BUILDER_PANEL_TYPES.ACTOR,
|
|
2320
|
+
data: {
|
|
2321
|
+
anchor: BUILDER_ANCHORS.TRIGGER_ACTOR
|
|
2322
|
+
}
|
|
2323
|
+
} : null;
|
|
2324
|
+
case BUILDER_ANCHORS.COND_FIELD:
|
|
2325
|
+
return {
|
|
2326
|
+
type: BUILDER_PANEL_TYPES.OPERATOR,
|
|
2327
|
+
data: {
|
|
2328
|
+
index: index,
|
|
2329
|
+
anchor: BUILDER_ANCHORS.COND_OP_TOGGLE
|
|
2330
|
+
}
|
|
2331
|
+
};
|
|
2332
|
+
case BUILDER_ANCHORS.COND_OP_TOGGLE:
|
|
2333
|
+
{
|
|
2334
|
+
var condition = conditionAt({
|
|
2335
|
+
rule: rule,
|
|
2336
|
+
index: index
|
|
2337
|
+
});
|
|
2338
|
+
var field = findField({
|
|
2339
|
+
schema: schema,
|
|
2340
|
+
value: condition.field
|
|
2341
|
+
});
|
|
2342
|
+
if (((field === null || field === void 0 ? void 0 : field.noValueForVerbs) || []).includes(condition.verb)) return null;
|
|
2343
|
+
return {
|
|
2344
|
+
type: BUILDER_PANEL_TYPES.CONDITION_VALUE,
|
|
2345
|
+
data: {
|
|
2346
|
+
index: index,
|
|
2347
|
+
anchor: BUILDER_ANCHORS.COND_VALUES
|
|
2348
|
+
}
|
|
2349
|
+
};
|
|
2350
|
+
}
|
|
2351
|
+
case BUILDER_ANCHORS.ACTION_ADD:
|
|
2352
|
+
case BUILDER_ANCHORS.ACTION_CHANNEL:
|
|
2353
|
+
{
|
|
2354
|
+
var action = actionAt({
|
|
2355
|
+
rule: rule,
|
|
2356
|
+
index: index
|
|
2357
|
+
});
|
|
2358
|
+
if (actionHasConfig({
|
|
2359
|
+
schema: schema,
|
|
2360
|
+
action: action
|
|
2361
|
+
})) {
|
|
2362
|
+
return {
|
|
2363
|
+
type: BUILDER_PANEL_TYPES.ACTION_CONFIG,
|
|
2364
|
+
data: {
|
|
2365
|
+
index: index,
|
|
2366
|
+
anchor: BUILDER_ANCHORS.ACTION_CONFIG
|
|
2367
|
+
}
|
|
2368
|
+
};
|
|
2369
|
+
}
|
|
2370
|
+
return channelMetaOf({
|
|
2371
|
+
schema: schema,
|
|
2372
|
+
action: action
|
|
2373
|
+
}).needsRecipient ? {
|
|
2374
|
+
type: BUILDER_PANEL_TYPES.RECIPIENT,
|
|
2375
|
+
data: {
|
|
2376
|
+
index: index,
|
|
2377
|
+
anchor: BUILDER_ANCHORS.ACTION_RECIPIENT
|
|
2378
|
+
}
|
|
2379
|
+
} : null;
|
|
2380
|
+
}
|
|
2381
|
+
case BUILDER_ANCHORS.ACTION_RECIPIENT:
|
|
2382
|
+
return null;
|
|
2383
|
+
default:
|
|
2384
|
+
return null;
|
|
2385
|
+
}
|
|
2386
|
+
};
|
|
2387
|
+
var replaceAt = function replaceAt(_ref15) {
|
|
2388
|
+
var list = _ref15.list,
|
|
2389
|
+
index = _ref15.index,
|
|
2390
|
+
item = _ref15.item;
|
|
2391
|
+
var next = _toConsumableArray(list);
|
|
2392
|
+
// eslint-disable-next-line security/detect-object-injection
|
|
2393
|
+
next[index] = item;
|
|
2394
|
+
return next;
|
|
2395
|
+
};
|
|
2396
|
+
var applyPreview = function applyPreview(_ref16) {
|
|
2397
|
+
var rule = _ref16.rule,
|
|
2398
|
+
schema = _ref16.schema,
|
|
2399
|
+
anchor = _ref16.anchor,
|
|
2400
|
+
index = _ref16.index,
|
|
2401
|
+
value = _ref16.value;
|
|
2402
|
+
switch (anchor) {
|
|
2403
|
+
case BUILDER_ANCHORS.TRIGGER_ADD:
|
|
2404
|
+
case BUILDER_ANCHORS.TRIGGER_REPLACE:
|
|
2405
|
+
return _objectSpread$4(_objectSpread$4({}, rule), {}, {
|
|
2406
|
+
triggers: Array.isArray(value) ? value.map(function (name) {
|
|
2407
|
+
return {
|
|
2408
|
+
name: name
|
|
2409
|
+
};
|
|
2410
|
+
}) : nextTriggers({
|
|
2411
|
+
schema: schema,
|
|
2412
|
+
rule: rule,
|
|
2413
|
+
value: value
|
|
2414
|
+
})
|
|
2415
|
+
});
|
|
2416
|
+
case BUILDER_ANCHORS.TRIGGER_ACTOR:
|
|
2417
|
+
return _objectSpread$4(_objectSpread$4({}, rule), {}, {
|
|
2418
|
+
performer: value
|
|
2419
|
+
});
|
|
2420
|
+
case BUILDER_ANCHORS.COND_FIELD:
|
|
2421
|
+
return _objectSpread$4(_objectSpread$4({}, rule), {}, {
|
|
2422
|
+
conditions: replaceAt({
|
|
2423
|
+
list: rule.conditions,
|
|
2424
|
+
index: index,
|
|
2425
|
+
item: nextConditionAt({
|
|
2426
|
+
schema: schema,
|
|
2427
|
+
rule: rule,
|
|
2428
|
+
index: index,
|
|
2429
|
+
value: value
|
|
2430
|
+
})
|
|
2431
|
+
})
|
|
2432
|
+
});
|
|
2433
|
+
case BUILDER_ANCHORS.COND_OP_TOGGLE:
|
|
2434
|
+
return _objectSpread$4(_objectSpread$4({}, rule), {}, {
|
|
2435
|
+
conditions: replaceAt({
|
|
2436
|
+
list: rule.conditions,
|
|
2437
|
+
index: index,
|
|
2438
|
+
item: _objectSpread$4(_objectSpread$4({}, conditionAt({
|
|
2439
|
+
rule: rule,
|
|
2440
|
+
index: index
|
|
2441
|
+
})), {}, {
|
|
2442
|
+
verb: value
|
|
2443
|
+
})
|
|
2444
|
+
})
|
|
2445
|
+
});
|
|
2446
|
+
case BUILDER_ANCHORS.COND_CONNECTOR:
|
|
2447
|
+
return _objectSpread$4(_objectSpread$4({}, rule), {}, {
|
|
2448
|
+
conditionMode: value
|
|
2449
|
+
});
|
|
2450
|
+
case BUILDER_ANCHORS.ACTION_ADD:
|
|
2451
|
+
case BUILDER_ANCHORS.ACTION_CHANNEL:
|
|
2452
|
+
return _objectSpread$4(_objectSpread$4({}, rule), {}, {
|
|
2453
|
+
actions: replaceAt({
|
|
2454
|
+
list: rule.actions,
|
|
2455
|
+
index: index,
|
|
2456
|
+
item: nextActionAt({
|
|
2457
|
+
schema: schema,
|
|
2458
|
+
rule: rule,
|
|
2459
|
+
index: index,
|
|
2460
|
+
value: value
|
|
2461
|
+
})
|
|
2462
|
+
})
|
|
2463
|
+
});
|
|
2464
|
+
case BUILDER_ANCHORS.ACTION_RECIPIENT:
|
|
2465
|
+
return _objectSpread$4(_objectSpread$4({}, rule), {}, {
|
|
2466
|
+
actions: replaceAt({
|
|
2467
|
+
list: rule.actions,
|
|
2468
|
+
index: index,
|
|
2469
|
+
item: nextActionRecipientAt({
|
|
2470
|
+
schema: schema,
|
|
2471
|
+
rule: rule,
|
|
2472
|
+
index: index,
|
|
2473
|
+
value: value
|
|
2474
|
+
})
|
|
2475
|
+
})
|
|
2476
|
+
});
|
|
2477
|
+
default:
|
|
2478
|
+
return rule;
|
|
2479
|
+
}
|
|
2480
|
+
};
|
|
2481
|
+
|
|
2482
|
+
function ownKeys$3(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; }
|
|
2483
|
+
function _objectSpread$3(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$3(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$3(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
2484
|
+
var Canvas = function Canvas(_ref) {
|
|
2485
|
+
var _schema$scope, _schema$scope2, _schema$conditions, _schema$triggers, _schema$delay, _schema$meta$showName, _schema$meta;
|
|
2486
|
+
var schema = _ref.schema;
|
|
2487
|
+
var _useTranslation = useTranslation(),
|
|
2488
|
+
t = _useTranslation.t;
|
|
2489
|
+
var _usePaneCascade = usePaneCascade(schema),
|
|
2490
|
+
openPane = _usePaneCascade.openPane,
|
|
2491
|
+
closePane = _usePaneCascade.closePane;
|
|
2492
|
+
var _useFormikContext = useFormikContext(),
|
|
2493
|
+
errors = _useFormikContext.errors,
|
|
2494
|
+
submitCount = _useFormikContext.submitCount;
|
|
2495
|
+
var _useRuleModel = useRuleModel(schema),
|
|
2496
|
+
rule = _useRuleModel.rule,
|
|
2497
|
+
fieldKeys = _useRuleModel.fieldKeys,
|
|
2498
|
+
setTriggers = _useRuleModel.setTriggers,
|
|
2499
|
+
setPerformer = _useRuleModel.setPerformer,
|
|
2500
|
+
setConditions = _useRuleModel.setConditions,
|
|
2501
|
+
setActions = _useRuleModel.setActions,
|
|
2502
|
+
setDelay = _useRuleModel.setDelay,
|
|
2503
|
+
removeCondition = _useRuleModel.removeCondition,
|
|
2504
|
+
removeAction = _useRuleModel.removeAction,
|
|
2505
|
+
setActive = _useRuleModel.setActive,
|
|
2506
|
+
setScope = _useRuleModel.setScope;
|
|
2507
|
+
var _useUtilityStore = useUtilityStore(useShallow(function (store) {
|
|
2508
|
+
return {
|
|
2509
|
+
builderPreview: store["builderPreview"],
|
|
2510
|
+
panelState: store["panelState"]
|
|
2511
|
+
};
|
|
2512
|
+
})),
|
|
2513
|
+
builderPreview = _useUtilityStore.builderPreview,
|
|
2514
|
+
panelState = _useUtilityStore.panelState;
|
|
2515
|
+
var displayRule = useMemo(function () {
|
|
2516
|
+
return builderPreview ? applyPreview(_objectSpread$3({
|
|
2517
|
+
rule: rule,
|
|
2518
|
+
schema: schema
|
|
2519
|
+
}, builderPreview)) : rule;
|
|
2520
|
+
}, [rule, schema, builderPreview]);
|
|
2521
|
+
var activeToken = (panelState === null || panelState === void 0 ? void 0 : panelState.data) || {};
|
|
2522
|
+
var isActive = function isActive(_ref2) {
|
|
2523
|
+
var type = _ref2.type,
|
|
2524
|
+
index = _ref2.index;
|
|
2525
|
+
return !!(panelState !== null && panelState !== void 0 && panelState.type) && activeToken.anchor === type && activeToken.index === index;
|
|
2526
|
+
};
|
|
2527
|
+
var addingAction = !!(panelState !== null && panelState !== void 0 && panelState.type) && activeToken.anchor === BUILDER_ANCHORS.ACTION_ADD && activeToken.index === rule.actions.length && !builderPreview;
|
|
2528
|
+
var flatErrors = useMemo(function () {
|
|
2529
|
+
return flatten(errors || {});
|
|
2530
|
+
}, [errors]);
|
|
2531
|
+
var _useState = useState(false),
|
|
2532
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
2533
|
+
flashing = _useState2[0],
|
|
2534
|
+
setFlashing = _useState2[1];
|
|
2535
|
+
var lastSubmitCount = useRef(submitCount);
|
|
2536
|
+
useEffect(function () {
|
|
2537
|
+
if (submitCount <= lastSubmitCount.current) return undefined;
|
|
2538
|
+
lastSubmitCount.current = submitCount;
|
|
2539
|
+
if (isEmpty(flatErrors) && isRuleComplete(rule) && isEmpty(invalidScopeIndexes({
|
|
2540
|
+
rule: rule,
|
|
2541
|
+
schema: schema
|
|
2542
|
+
}))) {
|
|
2543
|
+
return undefined;
|
|
2544
|
+
}
|
|
2545
|
+
setFlashing(true);
|
|
2546
|
+
var timer = setTimeout(function () {
|
|
2547
|
+
return setFlashing(false);
|
|
2548
|
+
}, 2200);
|
|
2549
|
+
return function () {
|
|
2550
|
+
return clearTimeout(timer);
|
|
2551
|
+
};
|
|
2552
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2553
|
+
}, [submitCount]);
|
|
2554
|
+
var hasErrorAt = function hasErrorAt(_ref3) {
|
|
2555
|
+
var prefix = _ref3.prefix,
|
|
2556
|
+
_ref3$exclude = _ref3.exclude,
|
|
2557
|
+
exclude = _ref3$exclude === void 0 ? [] : _ref3$exclude;
|
|
2558
|
+
return Object.keys(flatErrors).some(function (key) {
|
|
2559
|
+
return (key === prefix || key.startsWith("".concat(prefix, "."))) && !exclude.some(function (sub) {
|
|
2560
|
+
return key === "".concat(prefix, ".").concat(sub) || key.startsWith("".concat(prefix, ".").concat(sub, "."));
|
|
2561
|
+
});
|
|
2562
|
+
});
|
|
2563
|
+
};
|
|
2564
|
+
var isInvalid = function isInvalid(_ref4) {
|
|
2565
|
+
var _schema$actions, _schema$actions$actio, _schema$actions2, _schema$actions2$rend, _schema$actions3, _schema$actions3$rend, _schema$actions4, _schema$actions4$opti, _schema$actions5, _schema$actions5$opti;
|
|
2566
|
+
var type = _ref4.type,
|
|
2567
|
+
index = _ref4.index;
|
|
2568
|
+
if (!flashing) return false;
|
|
2569
|
+
var conditionMeta = "".concat(fieldKeys.conditions, ".value.").concat(index, ".metadata");
|
|
2570
|
+
var actionMeta = "".concat(fieldKeys.actions, ".value.").concat(index, ".metadata");
|
|
2571
|
+
// eslint-disable-next-line security/detect-object-injection
|
|
2572
|
+
var actionItem = rule.actions[index] || {};
|
|
2573
|
+
var channel = actionItem.channel || ((_schema$actions = schema.actions) === null || _schema$actions === void 0 || (_schema$actions$actio = _schema$actions.actionForName) === null || _schema$actions$actio === void 0 || (_schema$actions$actio = _schema$actions$actio.call(_schema$actions, actionItem.name)) === null || _schema$actions$actio === void 0 ? void 0 : _schema$actions$actio.channel);
|
|
2574
|
+
var hasRecipientEditor = !!((_schema$actions2 = schema.actions) !== null && _schema$actions2 !== void 0 && (_schema$actions2$rend = _schema$actions2.renderRecipientEditor) !== null && _schema$actions2$rend !== void 0 && _schema$actions2$rend.call(_schema$actions2, {
|
|
2575
|
+
channel: channel,
|
|
2576
|
+
name: actionMeta,
|
|
2577
|
+
action: actionItem
|
|
2578
|
+
}));
|
|
2579
|
+
var hasRecipientField = !!((_schema$actions3 = schema.actions) !== null && _schema$actions3 !== void 0 && (_schema$actions3$rend = _schema$actions3.renderRecipientField) !== null && _schema$actions3$rend !== void 0 && _schema$actions3$rend.call(_schema$actions3, {
|
|
2580
|
+
channel: channel,
|
|
2581
|
+
recipient: actionItem.recipient,
|
|
2582
|
+
name: actionMeta,
|
|
2583
|
+
action: actionItem
|
|
2584
|
+
}));
|
|
2585
|
+
var flatOption = ((_schema$actions4 = schema.actions) === null || _schema$actions4 === void 0 || (_schema$actions4$opti = _schema$actions4.optionForName) === null || _schema$actions4$opti === void 0 ? void 0 : _schema$actions4$opti.call(_schema$actions4, actionItem.name)) || ((_schema$actions5 = schema.actions) === null || _schema$actions5 === void 0 || (_schema$actions5$opti = _schema$actions5.optionForChannel) === null || _schema$actions5$opti === void 0 ? void 0 : _schema$actions5$opti.call(_schema$actions5, channel));
|
|
2586
|
+
var recipientFields = [].concat(_toConsumableArray(hasRecipientEditor || hasRecipientField ? ["emails"] : []), _toConsumableArray((flatOption === null || flatOption === void 0 ? void 0 : flatOption.type) === "smsToNumbers" ? ["phoneNumbers"] : []));
|
|
2587
|
+
switch (type) {
|
|
2588
|
+
case BUILDER_ANCHORS.TRIGGER_ACTOR:
|
|
2589
|
+
{
|
|
2590
|
+
var _schema$actor;
|
|
2591
|
+
var actorKey = (_schema$actor = schema.actor) === null || _schema$actor === void 0 ? void 0 : _schema$actor.fieldKey;
|
|
2592
|
+
return !!actorKey && hasErrorAt({
|
|
2593
|
+
prefix: "".concat(actorKey, ".value")
|
|
2594
|
+
});
|
|
2595
|
+
}
|
|
2596
|
+
case BUILDER_ANCHORS.COND_FIELD:
|
|
2597
|
+
return hasErrorAt({
|
|
2598
|
+
prefix: "".concat(fieldKeys.conditions, ".value.").concat(index, ".field")
|
|
2599
|
+
});
|
|
2600
|
+
case BUILDER_ANCHORS.COND_OP_TOGGLE:
|
|
2601
|
+
{
|
|
2602
|
+
// eslint-disable-next-line security/detect-object-injection
|
|
2603
|
+
var condition = rule.conditions[index] || {};
|
|
2604
|
+
return !!condition.field && !condition.verb;
|
|
2605
|
+
}
|
|
2606
|
+
case BUILDER_ANCHORS.COND_VALUES:
|
|
2607
|
+
return hasErrorAt({
|
|
2608
|
+
prefix: conditionMeta
|
|
2609
|
+
});
|
|
2610
|
+
case BUILDER_ANCHORS.ACTION_CONFIG:
|
|
2611
|
+
return hasErrorAt({
|
|
2612
|
+
prefix: actionMeta,
|
|
2613
|
+
exclude: recipientFields
|
|
2614
|
+
});
|
|
2615
|
+
case BUILDER_ANCHORS.ACTION_RECIPIENT:
|
|
2616
|
+
return recipientFields.some(function (field) {
|
|
2617
|
+
return hasErrorAt({
|
|
2618
|
+
prefix: "".concat(actionMeta, ".").concat(field)
|
|
2619
|
+
});
|
|
2620
|
+
});
|
|
2621
|
+
case BUILDER_ANCHORS.ACTION_ADD:
|
|
2622
|
+
return !rule.actions.some(function (item) {
|
|
2623
|
+
return (item === null || item === void 0 ? void 0 : item.channel) || (item === null || item === void 0 ? void 0 : item.name);
|
|
2624
|
+
});
|
|
2625
|
+
case BUILDER_ANCHORS.RULE_DELAY:
|
|
2626
|
+
return hasErrorAt({
|
|
2627
|
+
prefix: "".concat(fieldKeys.delay, ".value")
|
|
2628
|
+
});
|
|
2629
|
+
case BUILDER_ANCHORS.SCOPE:
|
|
2630
|
+
return invalidScopeIndexes({
|
|
2631
|
+
rule: rule,
|
|
2632
|
+
schema: schema
|
|
2633
|
+
}).includes(index);
|
|
2634
|
+
case BUILDER_ANCHORS.META_NAME:
|
|
2635
|
+
return hasErrorAt({
|
|
2636
|
+
prefix: "".concat(fieldKeys.name, ".value")
|
|
2637
|
+
});
|
|
2638
|
+
default:
|
|
2639
|
+
return false;
|
|
2640
|
+
}
|
|
2641
|
+
};
|
|
2642
|
+
var closePaneIfTargeting = function closePaneIfTargeting(_ref5) {
|
|
2643
|
+
var anchors = _ref5.anchors,
|
|
2644
|
+
index = _ref5.index;
|
|
2645
|
+
if (panelState !== null && panelState !== void 0 && panelState.type && anchors.includes(activeToken.anchor) && activeToken.index === index) {
|
|
2646
|
+
closePane();
|
|
2647
|
+
}
|
|
2648
|
+
};
|
|
2649
|
+
var handleRemoveCondition = function handleRemoveCondition(index) {
|
|
2650
|
+
closePaneIfTargeting({
|
|
2651
|
+
anchors: CONDITION_ANCHORS,
|
|
2652
|
+
index: index
|
|
2653
|
+
});
|
|
2654
|
+
removeCondition(index);
|
|
2655
|
+
};
|
|
2656
|
+
var handleRemoveAction = function handleRemoveAction(index) {
|
|
2657
|
+
closePaneIfTargeting({
|
|
2658
|
+
anchors: ACTION_ANCHORS,
|
|
2659
|
+
index: index
|
|
2660
|
+
});
|
|
2661
|
+
removeAction(index);
|
|
2662
|
+
var remaining = rule.actions.filter(function (_, i) {
|
|
2663
|
+
return i !== index;
|
|
2664
|
+
});
|
|
2665
|
+
if (!remaining.some(function (action) {
|
|
2666
|
+
return (action === null || action === void 0 ? void 0 : action.channel) || (action === null || action === void 0 ? void 0 : action.name);
|
|
2667
|
+
})) {
|
|
2668
|
+
setScope([]);
|
|
2669
|
+
}
|
|
2670
|
+
};
|
|
2671
|
+
var handleRemoveDelay = function handleRemoveDelay() {
|
|
2672
|
+
closePaneIfTargeting({
|
|
2673
|
+
anchors: [BUILDER_ANCHORS.RULE_DELAY],
|
|
2674
|
+
index: undefined
|
|
2675
|
+
});
|
|
2676
|
+
setDelay(null);
|
|
2677
|
+
};
|
|
2678
|
+
var isTriggerSet = hasTrigger(rule);
|
|
2679
|
+
var hasAction = rule.actions.some(function (action) {
|
|
2680
|
+
return (action === null || action === void 0 ? void 0 : action.channel) || (action === null || action === void 0 ? void 0 : action.name);
|
|
2681
|
+
});
|
|
2682
|
+
var isScopeEnabled = (schema === null || schema === void 0 || (_schema$scope = schema.scope) === null || _schema$scope === void 0 ? void 0 : _schema$scope.enabled) && isTriggerSet && hasAction;
|
|
2683
|
+
var isScopeComplete = !(schema !== null && schema !== void 0 && (_schema$scope2 = schema.scope) !== null && _schema$scope2 !== void 0 && _schema$scope2.enabled) || isNotEmpty(rule.scope || []);
|
|
2684
|
+
var isComplete = isRuleComplete(rule) && isScopeComplete;
|
|
2685
|
+
var handleRemoveScope = function handleRemoveScope(index) {
|
|
2686
|
+
return setScope((rule.scope || []).filter(function (_, i) {
|
|
2687
|
+
return i !== index;
|
|
2688
|
+
}));
|
|
2689
|
+
};
|
|
2690
|
+
var conditionFields = (schema === null || schema === void 0 || (_schema$conditions = schema.conditions) === null || _schema$conditions === void 0 ? void 0 : _schema$conditions.fields) || [];
|
|
2691
|
+
var canAddCondition = isNotEmpty(conditionFields);
|
|
2692
|
+
var leadTimeAppliesTo = (schema === null || schema === void 0 || (_schema$triggers = schema.triggers) === null || _schema$triggers === void 0 || (_schema$triggers = _schema$triggers.leadTime) === null || _schema$triggers === void 0 ? void 0 : _schema$triggers.appliesTo) || [];
|
|
2693
|
+
var hasLeadTimeTrigger = rule.triggers.some(function (trigger) {
|
|
2694
|
+
return leadTimeAppliesTo.includes(trigger.name);
|
|
2695
|
+
});
|
|
2696
|
+
var isDelayEnabled = (schema === null || schema === void 0 || (_schema$delay = schema.delay) === null || _schema$delay === void 0 ? void 0 : _schema$delay.enabled) && !hasLeadTimeTrigger;
|
|
2697
|
+
useEffect(function () {
|
|
2698
|
+
if (hasLeadTimeTrigger && rule.delay) setDelay(null);
|
|
2699
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2700
|
+
}, [hasLeadTimeTrigger, rule.delay]);
|
|
2701
|
+
var handleAddCondition = function handleAddCondition() {
|
|
2702
|
+
if (isEmpty(conditionFields)) return;
|
|
2703
|
+
setConditions([].concat(_toConsumableArray(rule.conditions), [{
|
|
2704
|
+
joinType: joinTypeFor(rule.conditionMode),
|
|
2705
|
+
metadata: {}
|
|
2706
|
+
}]));
|
|
2707
|
+
openPane({
|
|
2708
|
+
type: BUILDER_ANCHORS.COND_FIELD,
|
|
2709
|
+
index: rule.conditions.length
|
|
2710
|
+
});
|
|
2711
|
+
};
|
|
2712
|
+
var handleClearTrigger = function handleClearTrigger() {
|
|
2713
|
+
setTriggers([]);
|
|
2714
|
+
setPerformer(null);
|
|
2715
|
+
setConditions([]);
|
|
2716
|
+
setDelay(null);
|
|
2717
|
+
setActions([]);
|
|
2718
|
+
setScope([]);
|
|
2719
|
+
closePane();
|
|
2720
|
+
};
|
|
2721
|
+
var handleAddAction = function handleAddAction() {
|
|
2722
|
+
openPane({
|
|
2723
|
+
type: BUILDER_ANCHORS.ACTION_ADD,
|
|
2724
|
+
index: rule.actions.length
|
|
2725
|
+
});
|
|
2726
|
+
};
|
|
2727
|
+
var slotCtx = {
|
|
2728
|
+
rule: rule,
|
|
2729
|
+
schema: schema,
|
|
2730
|
+
openPane: openPane
|
|
2731
|
+
};
|
|
2732
|
+
var renderSlot = function renderSlot(name) {
|
|
2733
|
+
var _schema$slots$name, _schema$slots, _schema$slots$name2;
|
|
2734
|
+
return (// eslint-disable-next-line security/detect-object-injection
|
|
2735
|
+
(_schema$slots$name = schema === null || schema === void 0 || (_schema$slots = schema.slots) === null || _schema$slots === void 0 || (_schema$slots$name2 = _schema$slots[name]) === null || _schema$slots$name2 === void 0 ? void 0 : _schema$slots$name2.call(_schema$slots, slotCtx)) !== null && _schema$slots$name !== void 0 ? _schema$slots$name : null
|
|
2736
|
+
);
|
|
2737
|
+
};
|
|
2738
|
+
return /*#__PURE__*/jsx("div", {
|
|
2739
|
+
className: "neeto-rules-builder",
|
|
2740
|
+
children: /*#__PURE__*/jsxs("div", {
|
|
2741
|
+
className: "mb-canvas neeto-rules-main-card",
|
|
2742
|
+
children: [/*#__PURE__*/jsx(WhenBlock, {
|
|
2743
|
+
isActive: isActive,
|
|
2744
|
+
isInvalid: isInvalid,
|
|
2745
|
+
schema: schema,
|
|
2746
|
+
rule: displayRule,
|
|
2747
|
+
onClearTrigger: isTriggerSet && handleClearTrigger,
|
|
2748
|
+
onToken: openPane,
|
|
2749
|
+
onAddCondition: canAddCondition && isEmpty(displayRule.conditions) && handleAddCondition
|
|
2750
|
+
}), renderSlot("afterWhen"), displayRule.conditions.map(function (condition, index) {
|
|
2751
|
+
var _condition$id;
|
|
2752
|
+
return /*#__PURE__*/createElement(ConditionRow, {
|
|
2753
|
+
condition: condition,
|
|
2754
|
+
index: index,
|
|
2755
|
+
isActive: isActive,
|
|
2756
|
+
isInvalid: isInvalid,
|
|
2757
|
+
schema: schema,
|
|
2758
|
+
key: (_condition$id = condition.id) !== null && _condition$id !== void 0 ? _condition$id : index,
|
|
2759
|
+
rule: displayRule,
|
|
2760
|
+
onRemove: function onRemove() {
|
|
2761
|
+
return handleRemoveCondition(index);
|
|
2762
|
+
},
|
|
2763
|
+
onToken: openPane,
|
|
2764
|
+
onAddCondition: canAddCondition && index === displayRule.conditions.length - 1 && handleAddCondition
|
|
2765
|
+
});
|
|
2766
|
+
}), renderSlot("afterConditions"), /*#__PURE__*/jsx(Connector, {
|
|
2767
|
+
active: isTriggerSet
|
|
2768
|
+
}), isDelayEnabled && isTriggerSet && (rule.delay ? /*#__PURE__*/jsxs(Fragment$1, {
|
|
2769
|
+
children: [/*#__PURE__*/jsx(DelayRow, {
|
|
2770
|
+
isActive: isActive,
|
|
2771
|
+
isInvalid: isInvalid,
|
|
2772
|
+
rule: rule,
|
|
2773
|
+
onRemove: handleRemoveDelay,
|
|
2774
|
+
onToken: openPane
|
|
2775
|
+
}), /*#__PURE__*/jsx(Connector, {
|
|
2776
|
+
active: true
|
|
2777
|
+
})]
|
|
2778
|
+
}) : /*#__PURE__*/jsx("div", {
|
|
2779
|
+
className: "mb-add-row",
|
|
2780
|
+
children: /*#__PURE__*/jsx(Button, {
|
|
2781
|
+
icon: Plus,
|
|
2782
|
+
iconPosition: "left",
|
|
2783
|
+
label: t("neetoRules.common.addDelay"),
|
|
2784
|
+
size: "small",
|
|
2785
|
+
style: "tertiary",
|
|
2786
|
+
onClick: function onClick() {
|
|
2787
|
+
return openPane({
|
|
2788
|
+
type: BUILDER_ANCHORS.RULE_DELAY
|
|
2789
|
+
});
|
|
2790
|
+
}
|
|
2791
|
+
})
|
|
2792
|
+
})), /*#__PURE__*/jsx(ThenBlock, {
|
|
2793
|
+
isActive: isActive,
|
|
2794
|
+
isInvalid: isInvalid,
|
|
2795
|
+
schema: schema,
|
|
2796
|
+
adding: addingAction,
|
|
2797
|
+
rule: displayRule,
|
|
2798
|
+
onAddAction: handleAddAction,
|
|
2799
|
+
onRemoveAction: handleRemoveAction,
|
|
2800
|
+
onToken: openPane
|
|
2801
|
+
}), renderSlot("afterActions"), isScopeEnabled && /*#__PURE__*/jsxs(Fragment$1, {
|
|
2802
|
+
children: [/*#__PURE__*/jsx(Connector, {
|
|
2803
|
+
active: true
|
|
2804
|
+
}), /*#__PURE__*/jsx(ScopeBlock, {
|
|
2805
|
+
isActive: isActive,
|
|
2806
|
+
isInvalid: isInvalid,
|
|
2807
|
+
schema: schema,
|
|
2808
|
+
rule: displayRule,
|
|
2809
|
+
onRemoveScope: handleRemoveScope,
|
|
2810
|
+
onToken: openPane
|
|
2811
|
+
})]
|
|
2812
|
+
}), isComplete && /*#__PURE__*/jsxs(Fragment$1, {
|
|
2813
|
+
children: [/*#__PURE__*/jsx(Connector, {
|
|
2814
|
+
active: true
|
|
2815
|
+
}), /*#__PURE__*/jsx(MetaBlock, {
|
|
2816
|
+
rule: rule,
|
|
2817
|
+
isInvalid: isInvalid({
|
|
2818
|
+
type: BUILDER_ANCHORS.META_NAME
|
|
2819
|
+
}),
|
|
2820
|
+
showName: (_schema$meta$showName = schema === null || schema === void 0 || (_schema$meta = schema.meta) === null || _schema$meta === void 0 ? void 0 : _schema$meta.showName) !== null && _schema$meta$showName !== void 0 ? _schema$meta$showName : true,
|
|
2821
|
+
onEditName: function onEditName() {
|
|
2822
|
+
return openPane({
|
|
2823
|
+
type: BUILDER_ANCHORS.META_NAME
|
|
2824
|
+
});
|
|
2825
|
+
},
|
|
2826
|
+
onToggleActive: function onToggleActive(event) {
|
|
2827
|
+
return setActive(event.target.checked);
|
|
2828
|
+
}
|
|
2829
|
+
})]
|
|
2830
|
+
})]
|
|
2831
|
+
})
|
|
2832
|
+
});
|
|
2833
|
+
};
|
|
2834
|
+
|
|
2835
|
+
var restoreTokens = function restoreTokens(text) {
|
|
2836
|
+
return text ? text.replace(/\[\[/g, "{{").replace(/\]\]/g, "}}") : text;
|
|
2837
|
+
};
|
|
2838
|
+
var ActionConfigFields = function ActionConfigFields(_ref) {
|
|
2839
|
+
var name = _ref.name,
|
|
2840
|
+
option = _ref.option,
|
|
2841
|
+
action = _ref.action,
|
|
2842
|
+
_ref$searchTerm = _ref.searchTerm,
|
|
2843
|
+
searchTerm = _ref$searchTerm === void 0 ? "" : _ref$searchTerm;
|
|
2844
|
+
var _useTranslation = useTranslation(),
|
|
2845
|
+
t = _useTranslation.t;
|
|
2846
|
+
var _useFormikContext = useFormikContext(),
|
|
2847
|
+
values = _useFormikContext.values,
|
|
2848
|
+
setFieldValue = _useFormikContext.setFieldValue,
|
|
2849
|
+
setFieldTouched = _useFormikContext.setFieldTouched,
|
|
2850
|
+
errors = _useFormikContext.errors,
|
|
2851
|
+
touched = _useFormikContext.touched;
|
|
2852
|
+
var type = option === null || option === void 0 ? void 0 : option.type;
|
|
2853
|
+
var options = normalizeOptions(option === null || option === void 0 ? void 0 : option.dropdownOptions);
|
|
2854
|
+
var valuePath = "".concat(name, ".value");
|
|
2855
|
+
var fieldError = function fieldError(path) {
|
|
2856
|
+
return getIn(touched, path) && getIn(errors, path);
|
|
2857
|
+
};
|
|
2858
|
+
var term = searchTerm.trim().toLowerCase();
|
|
2859
|
+
var filterOptions = function filterOptions(list) {
|
|
2860
|
+
return term ? list.filter(function (item) {
|
|
2861
|
+
return String(item.label).toLowerCase().includes(term);
|
|
2862
|
+
}) : list;
|
|
2863
|
+
};
|
|
2864
|
+
var hint = restoreTokens(option === null || option === void 0 ? void 0 : option.dynamicValuesHint);
|
|
2865
|
+
var hintBlock = hint ? /*#__PURE__*/jsx(Typography, {
|
|
2866
|
+
className: "neeto-ui-text-gray-500",
|
|
2867
|
+
style: "body3",
|
|
2868
|
+
children: hint
|
|
2869
|
+
}) : null;
|
|
2870
|
+
var noOptionsMessage = function noOptionsMessage() {
|
|
2871
|
+
var noun = (option === null || option === void 0 ? void 0 : option.valueNounPlural) || (option === null || option === void 0 ? void 0 : option.valueNoun);
|
|
2872
|
+
return /*#__PURE__*/jsx(Typography, {
|
|
2873
|
+
className: "neeto-ui-text-gray-500",
|
|
2874
|
+
style: "body2",
|
|
2875
|
+
children: noun ? t("neetoRules.builder.config.noOptionsFor", {
|
|
2876
|
+
field: noun
|
|
2877
|
+
}) : t("neetoRules.builder.config.noOptions")
|
|
2878
|
+
});
|
|
2879
|
+
};
|
|
2880
|
+
var noMatches = /*#__PURE__*/jsx("div", {
|
|
2881
|
+
className: "mb-pane-empty",
|
|
2882
|
+
children: t("neetoRules.builder.noMatches")
|
|
2883
|
+
});
|
|
2884
|
+
if (type === "emailChannel") {
|
|
2885
|
+
var _getIn, _action$metadata;
|
|
2886
|
+
var subjectPath = "".concat(name, ".subject");
|
|
2887
|
+
var bodyPath = "".concat(name, ".body");
|
|
2888
|
+
return /*#__PURE__*/jsxs("div", {
|
|
2889
|
+
className: "flex flex-col gap-4",
|
|
2890
|
+
children: [/*#__PURE__*/jsx(Input, {
|
|
2891
|
+
required: true,
|
|
2892
|
+
error: fieldError(subjectPath),
|
|
2893
|
+
label: t("neetoRules.builder.config.subject"),
|
|
2894
|
+
placeholder: t("neetoRules.builder.config.subjectPlaceholder"),
|
|
2895
|
+
size: "large",
|
|
2896
|
+
value: (_getIn = getIn(values, subjectPath)) !== null && _getIn !== void 0 ? _getIn : "",
|
|
2897
|
+
onBlur: function onBlur() {
|
|
2898
|
+
return setFieldTouched(subjectPath, true);
|
|
2899
|
+
},
|
|
2900
|
+
onChange: function onChange(event) {
|
|
2901
|
+
return setFieldValue(subjectPath, event.target.value);
|
|
2902
|
+
}
|
|
2903
|
+
}), /*#__PURE__*/jsx(EditorAction, {
|
|
2904
|
+
required: true,
|
|
2905
|
+
label: t("neetoRules.builder.config.body"),
|
|
2906
|
+
name: bodyPath,
|
|
2907
|
+
placeholder: t("neetoRules.builder.config.bodyPlaceholder"),
|
|
2908
|
+
value: action === null || action === void 0 || (_action$metadata = action.metadata) === null || _action$metadata === void 0 ? void 0 : _action$metadata.body,
|
|
2909
|
+
variables: option === null || option === void 0 ? void 0 : option.variables
|
|
2910
|
+
}), hintBlock]
|
|
2911
|
+
});
|
|
2912
|
+
}
|
|
2913
|
+
if (type === "multiSelect") {
|
|
2914
|
+
if (isEmpty(options)) return noOptionsMessage();
|
|
2915
|
+
var current = getIn(values, valuePath) || [];
|
|
2916
|
+
var filtered = filterOptions(options);
|
|
2917
|
+
if (term && isEmpty(filtered)) return noMatches;
|
|
2918
|
+
var toggle = function toggle(value) {
|
|
2919
|
+
setFieldTouched(valuePath, true);
|
|
2920
|
+
setFieldValue(valuePath, current.includes(value) ? current.filter(isNot(value)) : [].concat(_toConsumableArray(current), [value]));
|
|
2921
|
+
};
|
|
2922
|
+
return /*#__PURE__*/jsxs("div", {
|
|
2923
|
+
className: "flex flex-col gap-y-1",
|
|
2924
|
+
children: [filtered.map(function (item) {
|
|
2925
|
+
return /*#__PURE__*/jsx(Checkbox, {
|
|
2926
|
+
checked: current.includes(item.value),
|
|
2927
|
+
label: item.label,
|
|
2928
|
+
onChange: function onChange() {
|
|
2929
|
+
return toggle(item.value);
|
|
2930
|
+
}
|
|
2931
|
+
}, item.value);
|
|
2932
|
+
}), fieldError(valuePath) && /*#__PURE__*/jsx("p", {
|
|
2933
|
+
className: "neeto-ui-input__error",
|
|
2934
|
+
children: fieldError(valuePath)
|
|
2935
|
+
})]
|
|
2936
|
+
});
|
|
2937
|
+
}
|
|
2938
|
+
if (type === "dropdown") {
|
|
2939
|
+
if (isEmpty(options)) return noOptionsMessage();
|
|
2940
|
+
var _current = getIn(values, valuePath);
|
|
2941
|
+
var _filtered = filterOptions(options);
|
|
2942
|
+
if (term && isEmpty(_filtered)) return noMatches;
|
|
2943
|
+
return /*#__PURE__*/jsx(Radio, {
|
|
2944
|
+
stacked: true,
|
|
2945
|
+
error: fieldError(valuePath),
|
|
2946
|
+
value: _current !== null && _current !== void 0 ? _current : "",
|
|
2947
|
+
onBlur: function onBlur() {
|
|
2948
|
+
return setFieldTouched(valuePath, true);
|
|
2949
|
+
},
|
|
2950
|
+
onChange: function onChange(event) {
|
|
2951
|
+
var picked = options.find(function (item) {
|
|
2952
|
+
return String(item.value) === event.target.value;
|
|
2953
|
+
});
|
|
2954
|
+
setFieldValue(valuePath, picked ? picked.value : event.target.value);
|
|
2955
|
+
},
|
|
2956
|
+
children: _filtered.map(function (item) {
|
|
2957
|
+
return /*#__PURE__*/jsx(Radio.Item, {
|
|
2958
|
+
label: item.label,
|
|
2959
|
+
value: item.value
|
|
2960
|
+
}, item.value);
|
|
2961
|
+
})
|
|
2962
|
+
});
|
|
2963
|
+
}
|
|
2964
|
+
if (type === "note") {
|
|
2965
|
+
var _action$metadata2;
|
|
2966
|
+
return /*#__PURE__*/jsxs("div", {
|
|
2967
|
+
className: "flex flex-col gap-2",
|
|
2968
|
+
children: [/*#__PURE__*/jsx(EditorAction, {
|
|
2969
|
+
required: true,
|
|
2970
|
+
label: t("neetoRules.builder.config.note"),
|
|
2971
|
+
name: valuePath,
|
|
2972
|
+
placeholder: t("neetoRules.builder.config.bodyPlaceholder"),
|
|
2973
|
+
value: action === null || action === void 0 || (_action$metadata2 = action.metadata) === null || _action$metadata2 === void 0 ? void 0 : _action$metadata2.value,
|
|
2974
|
+
variables: option === null || option === void 0 ? void 0 : option.variables
|
|
2975
|
+
}), hintBlock]
|
|
2976
|
+
});
|
|
2977
|
+
}
|
|
2978
|
+
if (type === "textarea" || type === "number") {
|
|
2979
|
+
var _getIn2, _getIn3;
|
|
2980
|
+
return type === "number" ? /*#__PURE__*/jsx(Input, {
|
|
2981
|
+
required: true,
|
|
2982
|
+
error: fieldError(valuePath),
|
|
2983
|
+
label: t("neetoRules.builder.config.value"),
|
|
2984
|
+
size: "large",
|
|
2985
|
+
type: "number",
|
|
2986
|
+
value: (_getIn2 = getIn(values, valuePath)) !== null && _getIn2 !== void 0 ? _getIn2 : "",
|
|
2987
|
+
onBlur: function onBlur() {
|
|
2988
|
+
return setFieldTouched(valuePath, true);
|
|
2989
|
+
},
|
|
2990
|
+
onChange: function onChange(event) {
|
|
2991
|
+
return setFieldValue(valuePath, event.target.value);
|
|
2992
|
+
}
|
|
2993
|
+
}) : /*#__PURE__*/jsx(Textarea, {
|
|
2994
|
+
required: true,
|
|
2995
|
+
error: fieldError(valuePath),
|
|
2996
|
+
label: t("neetoRules.builder.config.message"),
|
|
2997
|
+
rows: 5,
|
|
2998
|
+
size: "large",
|
|
2999
|
+
value: (_getIn3 = getIn(values, valuePath)) !== null && _getIn3 !== void 0 ? _getIn3 : "",
|
|
3000
|
+
onBlur: function onBlur() {
|
|
3001
|
+
return setFieldTouched(valuePath, true);
|
|
3002
|
+
},
|
|
3003
|
+
onChange: function onChange(event) {
|
|
3004
|
+
return setFieldValue(valuePath, event.target.value);
|
|
3005
|
+
}
|
|
3006
|
+
});
|
|
3007
|
+
}
|
|
3008
|
+
return /*#__PURE__*/jsx(Typography, {
|
|
3009
|
+
style: "body2",
|
|
3010
|
+
children: t("neetoRules.builder.noConfig")
|
|
3011
|
+
});
|
|
3012
|
+
};
|
|
3013
|
+
|
|
3014
|
+
function _regenerator$1() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2$1(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = false, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = true, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), true), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2$1(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2$1(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2$1(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2$1(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2$1(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2$1(u), _regeneratorDefine2$1(u, o, "Generator"), _regeneratorDefine2$1(u, n, function () { return this; }), _regeneratorDefine2$1(u, "toString", function () { return "[object Generator]"; }), (_regenerator$1 = function _regenerator() { return { w: i, m: f }; })(); }
|
|
3015
|
+
function _regeneratorDefine2$1(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2$1 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2$1(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2$1(e, r, n, t); }
|
|
3016
|
+
var keysUnder = function keysUnder(_ref) {
|
|
3017
|
+
var obj = _ref.obj,
|
|
3018
|
+
prefix = _ref.prefix,
|
|
3019
|
+
_ref$exclude = _ref.exclude,
|
|
3020
|
+
exclude = _ref$exclude === void 0 ? [] : _ref$exclude;
|
|
3021
|
+
return Object.keys(flatten(obj || {})).filter(function (key) {
|
|
3022
|
+
return (key === prefix || key.startsWith("".concat(prefix, "."))) && !exclude.some(function (sub) {
|
|
3023
|
+
return key === "".concat(prefix, ".").concat(sub) || key.startsWith("".concat(prefix, ".").concat(sub, "."));
|
|
3024
|
+
});
|
|
3025
|
+
});
|
|
3026
|
+
};
|
|
3027
|
+
var usePaneValidation = function usePaneValidation(prefix) {
|
|
3028
|
+
var _useFormikContext = useFormikContext(),
|
|
3029
|
+
validateForm = _useFormikContext.validateForm,
|
|
3030
|
+
setFieldTouched = _useFormikContext.setFieldTouched,
|
|
3031
|
+
errors = _useFormikContext.errors;
|
|
3032
|
+
var errorsRef = useRef(errors);
|
|
3033
|
+
errorsRef.current = errors;
|
|
3034
|
+
useEffect(function () {
|
|
3035
|
+
keysUnder({
|
|
3036
|
+
obj: errorsRef.current,
|
|
3037
|
+
prefix: prefix
|
|
3038
|
+
}).forEach(function (key) {
|
|
3039
|
+
return setFieldTouched(key, false, false);
|
|
3040
|
+
});
|
|
3041
|
+
return function () {
|
|
3042
|
+
keysUnder({
|
|
3043
|
+
obj: errorsRef.current,
|
|
3044
|
+
prefix: prefix
|
|
3045
|
+
}).forEach(function (key) {
|
|
3046
|
+
return setFieldTouched(key, true, false);
|
|
3047
|
+
});
|
|
3048
|
+
};
|
|
3049
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3050
|
+
}, [prefix]);
|
|
3051
|
+
var validate = /*#__PURE__*/function () {
|
|
3052
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator$1().m(function _callee() {
|
|
3053
|
+
var exclude,
|
|
3054
|
+
nextErrors,
|
|
3055
|
+
offending,
|
|
3056
|
+
_args = arguments;
|
|
3057
|
+
return _regenerator$1().w(function (_context) {
|
|
3058
|
+
while (1) switch (_context.n) {
|
|
3059
|
+
case 0:
|
|
3060
|
+
exclude = _args.length > 0 && _args[0] !== undefined ? _args[0] : [];
|
|
3061
|
+
_context.n = 1;
|
|
3062
|
+
return validateForm();
|
|
3063
|
+
case 1:
|
|
3064
|
+
nextErrors = _context.v;
|
|
3065
|
+
offending = keysUnder({
|
|
3066
|
+
obj: nextErrors,
|
|
3067
|
+
prefix: prefix,
|
|
3068
|
+
exclude: exclude
|
|
3069
|
+
});
|
|
3070
|
+
offending.forEach(function (key) {
|
|
3071
|
+
return setFieldTouched(key, true, false);
|
|
3072
|
+
});
|
|
3073
|
+
return _context.a(2, isEmpty(offending));
|
|
3074
|
+
}
|
|
3075
|
+
}, _callee);
|
|
3076
|
+
}));
|
|
3077
|
+
return function validate() {
|
|
3078
|
+
return _ref2.apply(this, arguments);
|
|
3079
|
+
};
|
|
3080
|
+
}();
|
|
3081
|
+
return {
|
|
3082
|
+
validate: validate
|
|
3083
|
+
};
|
|
3084
|
+
};
|
|
3085
|
+
|
|
3086
|
+
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = false, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = true, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), true), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
|
3087
|
+
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
|
|
3088
|
+
var ConfigPane = function ConfigPane(_ref) {
|
|
3089
|
+
var _schema$actions, _schema$actions$optio, _schema$actions2, _schema$actions2$opti, _schema$actions3, _schema$actions4, _schema$actions4$opti, _hostRenderConfig;
|
|
3090
|
+
var schema = _ref.schema,
|
|
3091
|
+
index = _ref.index;
|
|
3092
|
+
var _useTranslation = useTranslation(),
|
|
3093
|
+
t = _useTranslation.t;
|
|
3094
|
+
var _useRuleModel = useRuleModel(schema),
|
|
3095
|
+
rule = _useRuleModel.rule,
|
|
3096
|
+
fieldKeys = _useRuleModel.fieldKeys;
|
|
3097
|
+
var _useFormikContext = useFormikContext(),
|
|
3098
|
+
setFieldValue = _useFormikContext.setFieldValue;
|
|
3099
|
+
var _usePaneCascade = usePaneCascade(schema),
|
|
3100
|
+
openType = _usePaneCascade.openType,
|
|
3101
|
+
closePane = _usePaneCascade.closePane;
|
|
3102
|
+
var bodyRef = useRef(null);
|
|
3103
|
+
var _useState = useState(""),
|
|
3104
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
3105
|
+
searchTerm = _useState2[0],
|
|
3106
|
+
setSearchTerm = _useState2[1];
|
|
3107
|
+
|
|
3108
|
+
// eslint-disable-next-line security/detect-object-injection
|
|
3109
|
+
var action = rule.actions[index] || {};
|
|
3110
|
+
var base = "".concat(fieldKeys.actions, ".value.").concat(index);
|
|
3111
|
+
var _actionParts = actionParts({
|
|
3112
|
+
schema: schema,
|
|
3113
|
+
action: action
|
|
3114
|
+
}),
|
|
3115
|
+
option = _actionParts.option,
|
|
3116
|
+
channel = _actionParts.channel,
|
|
3117
|
+
verb = _actionParts.verb,
|
|
3118
|
+
mediumLabel = _actionParts.mediumLabel,
|
|
3119
|
+
needsRecipient = _actionParts.needsRecipient,
|
|
3120
|
+
configTitle = _actionParts.configTitle,
|
|
3121
|
+
configSubtitle = _actionParts.configSubtitle;
|
|
3122
|
+
var name = "".concat(base, ".metadata");
|
|
3123
|
+
var flatOption = ((_schema$actions = schema.actions) === null || _schema$actions === void 0 || (_schema$actions$optio = _schema$actions.optionForName) === null || _schema$actions$optio === void 0 ? void 0 : _schema$actions$optio.call(_schema$actions, action.name)) || ((_schema$actions2 = schema.actions) === null || _schema$actions2 === void 0 || (_schema$actions2$opti = _schema$actions2.optionForChannel) === null || _schema$actions2$opti === void 0 ? void 0 : _schema$actions2$opti.call(_schema$actions2, channel)) || option;
|
|
3124
|
+
var isSms = SMS_TYPES.includes(flatOption === null || flatOption === void 0 ? void 0 : flatOption.type);
|
|
3125
|
+
var disabledReason = (flatOption === null || flatOption === void 0 ? void 0 : flatOption.isDisabled) && flatOption.disabledReason;
|
|
3126
|
+
var hostRenderConfig = (flatOption === null || flatOption === void 0 ? void 0 : flatOption.renderConfig) || (flatOption === null || flatOption === void 0 ? void 0 : flatOption.component) || ((_schema$actions3 = schema.actions) === null || _schema$actions3 === void 0 ? void 0 : _schema$actions3.renderConfig);
|
|
3127
|
+
var showSearch = normalizeOptions(flatOption === null || flatOption === void 0 ? void 0 : flatOption.dropdownOptions).length >= PANE_SEARCH_THRESHOLD;
|
|
3128
|
+
var shouldAdvanceToRecipient = !!needsRecipient;
|
|
3129
|
+
var _usePaneValidation = usePaneValidation(name),
|
|
3130
|
+
validate = _usePaneValidation.validate;
|
|
3131
|
+
var channelRepName = (_schema$actions4 = schema.actions) === null || _schema$actions4 === void 0 || (_schema$actions4$opti = _schema$actions4.optionForChannel) === null || _schema$actions4$opti === void 0 || (_schema$actions4$opti = _schema$actions4$opti.call(_schema$actions4, channel)) === null || _schema$actions4$opti === void 0 ? void 0 : _schema$actions4$opti.value;
|
|
3132
|
+
var unnamedOnOpen = useRef(!action.name);
|
|
3133
|
+
useEffect(function () {
|
|
3134
|
+
if (!unnamedOnOpen.current || !channelRepName) return undefined;
|
|
3135
|
+
setFieldValue("".concat(base, ".name"), channelRepName);
|
|
3136
|
+
return function () {
|
|
3137
|
+
return setFieldValue("".concat(base, ".name"), "");
|
|
3138
|
+
};
|
|
3139
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3140
|
+
}, [base, channelRepName]);
|
|
3141
|
+
useEffect(function () {
|
|
3142
|
+
if (isSms) return undefined;
|
|
3143
|
+
var frame;
|
|
3144
|
+
var attempts = 0;
|
|
3145
|
+
var _focusFirst = function focusFirst() {
|
|
3146
|
+
var _bodyRef$current;
|
|
3147
|
+
var first = (_bodyRef$current = bodyRef.current) === null || _bodyRef$current === void 0 ? void 0 : _bodyRef$current.querySelector(CONFIG_FOCUSABLE_SELECTOR);
|
|
3148
|
+
if (first) {
|
|
3149
|
+
first.focus();
|
|
3150
|
+
} else if (attempts++ < 20) {
|
|
3151
|
+
frame = requestAnimationFrame(_focusFirst);
|
|
3152
|
+
}
|
|
3153
|
+
};
|
|
3154
|
+
frame = requestAnimationFrame(_focusFirst);
|
|
3155
|
+
return function () {
|
|
3156
|
+
return cancelAnimationFrame(frame);
|
|
3157
|
+
};
|
|
3158
|
+
}, [isSms, action.name]);
|
|
3159
|
+
var title = configTitle || mediumLabel && t("neetoRules.builder.setUpMediumLabel", {
|
|
3160
|
+
verb: verb || t("neetoRules.builder.setUp"),
|
|
3161
|
+
mediumLabel: mediumLabel
|
|
3162
|
+
}) || (option === null || option === void 0 ? void 0 : option.label) || t("neetoRules.builder.setUpAction");
|
|
3163
|
+
var handleContinue = /*#__PURE__*/function () {
|
|
3164
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
3165
|
+
return _regenerator().w(function (_context) {
|
|
3166
|
+
while (1) switch (_context.n) {
|
|
3167
|
+
case 0:
|
|
3168
|
+
_context.n = 1;
|
|
3169
|
+
return validate(["emails"]);
|
|
3170
|
+
case 1:
|
|
3171
|
+
if (_context.v) {
|
|
3172
|
+
_context.n = 2;
|
|
3173
|
+
break;
|
|
3174
|
+
}
|
|
3175
|
+
return _context.a(2);
|
|
3176
|
+
case 2:
|
|
3177
|
+
if (shouldAdvanceToRecipient) {
|
|
3178
|
+
openType({
|
|
3179
|
+
type: BUILDER_PANEL_TYPES.RECIPIENT,
|
|
3180
|
+
data: {
|
|
3181
|
+
index: index,
|
|
3182
|
+
anchor: BUILDER_ANCHORS.ACTION_RECIPIENT
|
|
3183
|
+
}
|
|
3184
|
+
});
|
|
3185
|
+
} else {
|
|
3186
|
+
closePane();
|
|
3187
|
+
}
|
|
3188
|
+
case 3:
|
|
3189
|
+
return _context.a(2);
|
|
3190
|
+
}
|
|
3191
|
+
}, _callee);
|
|
3192
|
+
}));
|
|
3193
|
+
return function handleContinue() {
|
|
3194
|
+
return _ref2.apply(this, arguments);
|
|
3195
|
+
};
|
|
3196
|
+
}();
|
|
3197
|
+
return /*#__PURE__*/jsxs(Fragment, {
|
|
3198
|
+
children: [/*#__PURE__*/jsx(Panel.Header, {
|
|
3199
|
+
children: /*#__PURE__*/jsxs("div", {
|
|
3200
|
+
className: "flex w-full flex-col gap-y-2",
|
|
3201
|
+
children: [/*#__PURE__*/jsx(Typography, {
|
|
3202
|
+
style: "h3",
|
|
3203
|
+
children: title
|
|
3204
|
+
}), configSubtitle && /*#__PURE__*/jsx(Typography, {
|
|
3205
|
+
className: "neeto-ui-text-gray-500",
|
|
3206
|
+
style: "body2",
|
|
3207
|
+
children: configSubtitle
|
|
3208
|
+
}), showSearch && /*#__PURE__*/jsx("div", {
|
|
3209
|
+
className: "mb-pane-search",
|
|
3210
|
+
children: /*#__PURE__*/jsx(Input, {
|
|
3211
|
+
placeholder: t("neetoRules.builder.searchPlaceholder"),
|
|
3212
|
+
prefix: /*#__PURE__*/jsx(Search, {}),
|
|
3213
|
+
size: "large",
|
|
3214
|
+
value: searchTerm,
|
|
3215
|
+
onChange: function onChange(event) {
|
|
3216
|
+
return setSearchTerm(event.target.value);
|
|
3217
|
+
}
|
|
3218
|
+
})
|
|
3219
|
+
})]
|
|
3220
|
+
})
|
|
3221
|
+
}), /*#__PURE__*/jsx(Panel.Body, {
|
|
3222
|
+
children: /*#__PURE__*/jsxs("div", {
|
|
3223
|
+
ref: bodyRef,
|
|
3224
|
+
children: [disabledReason && /*#__PURE__*/jsx("div", {
|
|
3225
|
+
className: "mb-4",
|
|
3226
|
+
children: /*#__PURE__*/jsx(ErrorCallout, {
|
|
3227
|
+
message: disabledReason,
|
|
3228
|
+
selectedField: flatOption
|
|
3229
|
+
})
|
|
3230
|
+
}), isSms ? /*#__PURE__*/jsxs(Fragment, {
|
|
3231
|
+
children: [/*#__PURE__*/jsx(SmsFields, {
|
|
3232
|
+
action: action,
|
|
3233
|
+
index: index,
|
|
3234
|
+
name: name,
|
|
3235
|
+
shouldAutoFocus: true,
|
|
3236
|
+
selectedField: flatOption,
|
|
3237
|
+
showPhoneNumberInput: false
|
|
3238
|
+
}), /*#__PURE__*/jsx(Typography, {
|
|
3239
|
+
className: "neeto-ui-text-gray-500 mt-2",
|
|
3240
|
+
style: "body3",
|
|
3241
|
+
children: t("neetoRules.builder.config.smsSegmentHint")
|
|
3242
|
+
})]
|
|
3243
|
+
}) : (_hostRenderConfig = hostRenderConfig === null || hostRenderConfig === void 0 ? void 0 : hostRenderConfig({
|
|
3244
|
+
name: name,
|
|
3245
|
+
action: action,
|
|
3246
|
+
option: flatOption,
|
|
3247
|
+
searchTerm: searchTerm
|
|
3248
|
+
})) !== null && _hostRenderConfig !== void 0 ? _hostRenderConfig : /*#__PURE__*/jsx(ActionConfigFields, {
|
|
3249
|
+
action: action,
|
|
3250
|
+
name: name,
|
|
3251
|
+
searchTerm: searchTerm,
|
|
3252
|
+
option: flatOption
|
|
3253
|
+
})]
|
|
3254
|
+
})
|
|
3255
|
+
}), shouldAdvanceToRecipient && /*#__PURE__*/jsx(Panel.Footer, {
|
|
3256
|
+
children: /*#__PURE__*/jsx(Button, {
|
|
3257
|
+
label: t("neetoRules.buttons.continue"),
|
|
3258
|
+
size: "large",
|
|
3259
|
+
onClick: handleContinue
|
|
3260
|
+
})
|
|
3261
|
+
})]
|
|
3262
|
+
});
|
|
3263
|
+
};
|
|
3264
|
+
|
|
3265
|
+
var DelayPane = function DelayPane(_ref) {
|
|
3266
|
+
var _schema$delay;
|
|
3267
|
+
var schema = _ref.schema;
|
|
3268
|
+
var _useTranslation = useTranslation(),
|
|
3269
|
+
t = _useTranslation.t;
|
|
3270
|
+
var _useRuleModel = useRuleModel(schema),
|
|
3271
|
+
fieldKeys = _useRuleModel.fieldKeys;
|
|
3272
|
+
var _useFormikContext = useFormikContext(),
|
|
3273
|
+
setFieldValue = _useFormikContext.setFieldValue;
|
|
3274
|
+
var bodyRef = useRef(null);
|
|
3275
|
+
var name = fieldKeys.delay;
|
|
3276
|
+
var _useField = useField("".concat(name, ".value")),
|
|
3277
|
+
_useField2 = _slicedToArray(_useField, 1),
|
|
3278
|
+
value = _useField2[0].value;
|
|
3279
|
+
var units = normalizeOptions((_schema$delay = schema.delay) === null || _schema$delay === void 0 ? void 0 : _schema$delay.units);
|
|
3280
|
+
var unitOptions = isNotEmpty(units) ? units : DEFAULT_DELAY_UNITS;
|
|
3281
|
+
usePaneValidation("".concat(name, ".value"));
|
|
3282
|
+
useEffect(function () {
|
|
3283
|
+
if (isEmpty(value || {})) {
|
|
3284
|
+
var _unitOptions$0$value, _unitOptions$;
|
|
3285
|
+
setFieldValue("".concat(name, ".value"), {
|
|
3286
|
+
value: 10,
|
|
3287
|
+
unit: (_unitOptions$0$value = (_unitOptions$ = unitOptions[0]) === null || _unitOptions$ === void 0 ? void 0 : _unitOptions$.value) !== null && _unitOptions$0$value !== void 0 ? _unitOptions$0$value : "minutes"
|
|
3288
|
+
});
|
|
3289
|
+
}
|
|
3290
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3291
|
+
}, []);
|
|
3292
|
+
useEffect(function () {
|
|
3293
|
+
var _bodyRef$current;
|
|
3294
|
+
var first = (_bodyRef$current = bodyRef.current) === null || _bodyRef$current === void 0 ? void 0 : _bodyRef$current.querySelector("input");
|
|
3295
|
+
// eslint-disable-next-line @bigbinary/neeto/prefer-function-reference
|
|
3296
|
+
if (first) setTimeout(function () {
|
|
3297
|
+
return first.focus();
|
|
3298
|
+
}, 0);
|
|
3299
|
+
}, []);
|
|
3300
|
+
return /*#__PURE__*/jsxs(Fragment, {
|
|
3301
|
+
children: [/*#__PURE__*/jsx(Panel.Header, {
|
|
3302
|
+
children: /*#__PURE__*/jsxs("div", {
|
|
3303
|
+
className: "flex flex-col gap-y-1",
|
|
3304
|
+
children: [/*#__PURE__*/jsx(Typography, {
|
|
3305
|
+
style: "h3",
|
|
3306
|
+
children: t("neetoRules.common.addDelay")
|
|
3307
|
+
}), /*#__PURE__*/jsx(Typography, {
|
|
3308
|
+
className: "neeto-ui-text-gray-500",
|
|
3309
|
+
style: "body2",
|
|
3310
|
+
children: t("neetoRules.helpText.addDelay")
|
|
3311
|
+
})]
|
|
3312
|
+
})
|
|
3313
|
+
}), /*#__PURE__*/jsx(Panel.Body, {
|
|
3314
|
+
children: /*#__PURE__*/jsxs("div", {
|
|
3315
|
+
className: "flex flex-col gap-y-1.5",
|
|
3316
|
+
ref: bodyRef,
|
|
3317
|
+
children: [/*#__PURE__*/jsx(Typography, {
|
|
3318
|
+
className: "neeto-ui-text-gray-800",
|
|
3319
|
+
style: "body2",
|
|
3320
|
+
weight: "medium",
|
|
3321
|
+
children: t("neetoRules.builder.waitFor")
|
|
3322
|
+
}), /*#__PURE__*/jsxs("div", {
|
|
3323
|
+
className: "flex items-start gap-x-2",
|
|
3324
|
+
children: [/*#__PURE__*/jsx(Input$1, {
|
|
3325
|
+
className: "w-44",
|
|
3326
|
+
max: 999,
|
|
3327
|
+
min: 1,
|
|
3328
|
+
name: "".concat(name, ".value.value"),
|
|
3329
|
+
placeholder: t("neetoRules.placeholders.enterDelay"),
|
|
3330
|
+
size: "large",
|
|
3331
|
+
type: "number"
|
|
3332
|
+
}), /*#__PURE__*/jsx(Select, {
|
|
3333
|
+
defaultValue: findBy({
|
|
3334
|
+
value: value === null || value === void 0 ? void 0 : value.unit
|
|
3335
|
+
}, unitOptions),
|
|
3336
|
+
menuPosition: "fixed",
|
|
3337
|
+
name: "".concat(name, ".value.unit"),
|
|
3338
|
+
options: unitOptions,
|
|
3339
|
+
size: "large",
|
|
3340
|
+
onChange: function onChange(option) {
|
|
3341
|
+
return setFieldValue("".concat(name, ".value.unit"), option === null || option === void 0 ? void 0 : option.value);
|
|
3342
|
+
}
|
|
3343
|
+
})]
|
|
3344
|
+
})]
|
|
3345
|
+
})
|
|
3346
|
+
})]
|
|
3347
|
+
});
|
|
3348
|
+
};
|
|
3349
|
+
|
|
3350
|
+
var toNumber = function toNumber(value) {
|
|
3351
|
+
return value === "" || isNil(value) ? null : Number(value);
|
|
3352
|
+
};
|
|
3353
|
+
var clamp = function clamp(_ref) {
|
|
3354
|
+
var value = _ref.value,
|
|
3355
|
+
min = _ref.min,
|
|
3356
|
+
max = _ref.max;
|
|
3357
|
+
var next = value;
|
|
3358
|
+
if (!isNil(min)) next = Math.max(min, next);
|
|
3359
|
+
if (!isNil(max)) next = Math.min(max, next);
|
|
3360
|
+
return next;
|
|
3361
|
+
};
|
|
3362
|
+
var asText = function asText(value) {
|
|
3363
|
+
return value === "" || isNil(value) ? "" : String(value);
|
|
3364
|
+
};
|
|
3365
|
+
|
|
3366
|
+
var NumberStepper = function NumberStepper(_ref) {
|
|
3367
|
+
var value = _ref.value,
|
|
3368
|
+
onChange = _ref.onChange,
|
|
3369
|
+
label = _ref.label,
|
|
3370
|
+
_ref$min = _ref.min,
|
|
3371
|
+
min = _ref$min === void 0 ? 1 : _ref$min,
|
|
3372
|
+
max = _ref.max,
|
|
3373
|
+
required = _ref.required;
|
|
3374
|
+
var _useTranslation = useTranslation(),
|
|
3375
|
+
t = _useTranslation.t;
|
|
3376
|
+
var _useState = useState(null),
|
|
3377
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
3378
|
+
draft = _useState2[0],
|
|
3379
|
+
setDraft = _useState2[1];
|
|
3380
|
+
var display = draft !== null && draft !== void 0 ? draft : asText(value);
|
|
3381
|
+
var commit = function commit(raw) {
|
|
3382
|
+
setDraft(raw);
|
|
3383
|
+
onChange(raw === "" ? min !== null && min !== void 0 ? min : 0 : clamp({
|
|
3384
|
+
value: Number(raw),
|
|
3385
|
+
min: min,
|
|
3386
|
+
max: max
|
|
3387
|
+
}));
|
|
3388
|
+
};
|
|
3389
|
+
var step = function step(delta) {
|
|
3390
|
+
setDraft(null);
|
|
3391
|
+
var base = Number.isFinite(toNumber(value)) ? toNumber(value) : min !== null && min !== void 0 ? min : 0;
|
|
3392
|
+
onChange(clamp({
|
|
3393
|
+
value: base + delta,
|
|
3394
|
+
min: min,
|
|
3395
|
+
max: max
|
|
3396
|
+
}));
|
|
3397
|
+
};
|
|
3398
|
+
return /*#__PURE__*/jsxs("div", {
|
|
3399
|
+
className: "mb-stepper",
|
|
3400
|
+
children: [/*#__PURE__*/jsx(Input, {
|
|
3401
|
+
label: label,
|
|
3402
|
+
min: min,
|
|
3403
|
+
required: required,
|
|
3404
|
+
autoFocus: true,
|
|
3405
|
+
type: "number",
|
|
3406
|
+
value: display,
|
|
3407
|
+
onBlur: function onBlur() {
|
|
3408
|
+
return setDraft(null);
|
|
3409
|
+
},
|
|
3410
|
+
onChange: function onChange(event) {
|
|
3411
|
+
return commit(event.target.value);
|
|
3412
|
+
},
|
|
3413
|
+
onFocus: function onFocus(event) {
|
|
3414
|
+
return event.target.select();
|
|
3415
|
+
}
|
|
3416
|
+
}), /*#__PURE__*/jsxs("div", {
|
|
3417
|
+
className: "mb-stepper-controls",
|
|
3418
|
+
children: [/*#__PURE__*/jsx("button", {
|
|
3419
|
+
"aria-label": t("neetoRules.builder.aria.increase"),
|
|
3420
|
+
className: "mb-stepper-btn",
|
|
3421
|
+
tabIndex: -1,
|
|
3422
|
+
type: "button",
|
|
3423
|
+
onClick: function onClick() {
|
|
3424
|
+
return step(1);
|
|
3425
|
+
},
|
|
3426
|
+
children: /*#__PURE__*/jsx(Up, {})
|
|
3427
|
+
}), /*#__PURE__*/jsx("button", {
|
|
3428
|
+
"aria-label": t("neetoRules.builder.aria.decrease"),
|
|
3429
|
+
className: "mb-stepper-btn",
|
|
3430
|
+
tabIndex: -1,
|
|
3431
|
+
type: "button",
|
|
3432
|
+
onClick: function onClick() {
|
|
3433
|
+
return step(-1);
|
|
3434
|
+
},
|
|
3435
|
+
children: /*#__PURE__*/jsx(Down, {})
|
|
3436
|
+
})]
|
|
3437
|
+
})]
|
|
3438
|
+
});
|
|
3439
|
+
};
|
|
3440
|
+
|
|
3441
|
+
var LeadTimePane = function LeadTimePane(_ref) {
|
|
3442
|
+
var schema = _ref.schema;
|
|
3443
|
+
var _useTranslation = useTranslation(),
|
|
3444
|
+
t = _useTranslation.t;
|
|
3445
|
+
var _useFormikContext = useFormikContext(),
|
|
3446
|
+
setFieldValue = _useFormikContext.setFieldValue;
|
|
3447
|
+
var _useRuleModel = useRuleModel(schema),
|
|
3448
|
+
rule = _useRuleModel.rule,
|
|
3449
|
+
fieldKeys = _useRuleModel.fieldKeys;
|
|
3450
|
+
var _minutesToParts = minutesToParts(rule.leadTime),
|
|
3451
|
+
amount = _minutesToParts.value,
|
|
3452
|
+
unit = _minutesToParts.unit;
|
|
3453
|
+
var path = "".concat(fieldKeys.leadTime, ".value");
|
|
3454
|
+
var update = function update(_ref2) {
|
|
3455
|
+
var value = _ref2.value,
|
|
3456
|
+
nextUnit = _ref2.unit;
|
|
3457
|
+
return setFieldValue(path, partsToMinutes({
|
|
3458
|
+
value: value,
|
|
3459
|
+
unit: nextUnit
|
|
3460
|
+
}));
|
|
3461
|
+
};
|
|
3462
|
+
return /*#__PURE__*/jsxs(Fragment, {
|
|
3463
|
+
children: [/*#__PURE__*/jsx(Panel.Header, {
|
|
3464
|
+
children: /*#__PURE__*/jsxs("div", {
|
|
3465
|
+
className: "flex flex-col gap-y-1",
|
|
3466
|
+
children: [/*#__PURE__*/jsx(Typography, {
|
|
3467
|
+
style: "h3",
|
|
3468
|
+
children: t("neetoRules.builder.leadTimeTitle")
|
|
3469
|
+
}), /*#__PURE__*/jsx(Typography, {
|
|
3470
|
+
className: "neeto-ui-text-gray-500",
|
|
3471
|
+
style: "body2",
|
|
3472
|
+
children: t("neetoRules.builder.leadTimeSubtitle")
|
|
3473
|
+
})]
|
|
3474
|
+
})
|
|
3475
|
+
}), /*#__PURE__*/jsx(Panel.Body, {
|
|
3476
|
+
children: /*#__PURE__*/jsxs("div", {
|
|
3477
|
+
className: "flex items-end gap-x-3",
|
|
3478
|
+
children: [/*#__PURE__*/jsx("div", {
|
|
3479
|
+
className: "flex-1",
|
|
3480
|
+
children: /*#__PURE__*/jsx(NumberStepper, {
|
|
3481
|
+
label: t("neetoRules.builder.before"),
|
|
3482
|
+
value: amount,
|
|
3483
|
+
onChange: function onChange(value) {
|
|
3484
|
+
return update({
|
|
3485
|
+
value: value === "" ? 0 : value,
|
|
3486
|
+
unit: unit
|
|
3487
|
+
});
|
|
3488
|
+
}
|
|
3489
|
+
})
|
|
3490
|
+
}), /*#__PURE__*/jsx("div", {
|
|
3491
|
+
className: "w-32 shrink-0",
|
|
3492
|
+
children: /*#__PURE__*/jsx(Select$1, {
|
|
3493
|
+
isSearchable: false,
|
|
3494
|
+
options: LEAD_TIME_UNITS,
|
|
3495
|
+
value: findBy({
|
|
3496
|
+
value: unit
|
|
3497
|
+
}, LEAD_TIME_UNITS) || null,
|
|
3498
|
+
onChange: function onChange(option) {
|
|
3499
|
+
return update({
|
|
3500
|
+
value: amount,
|
|
3501
|
+
unit: option === null || option === void 0 ? void 0 : option.value
|
|
3502
|
+
});
|
|
3503
|
+
}
|
|
3504
|
+
})
|
|
3505
|
+
})]
|
|
3506
|
+
})
|
|
3507
|
+
})]
|
|
3508
|
+
});
|
|
3509
|
+
};
|
|
3510
|
+
|
|
3511
|
+
var NamePane = function NamePane(_ref) {
|
|
3512
|
+
var schema = _ref.schema;
|
|
3513
|
+
var _useTranslation = useTranslation(),
|
|
3514
|
+
t = _useTranslation.t;
|
|
3515
|
+
var _useRuleModel = useRuleModel(schema),
|
|
3516
|
+
fieldKeys = _useRuleModel.fieldKeys;
|
|
3517
|
+
return /*#__PURE__*/jsxs(Fragment, {
|
|
3518
|
+
children: [/*#__PURE__*/jsx(Panel.Header, {
|
|
3519
|
+
children: /*#__PURE__*/jsxs("div", {
|
|
3520
|
+
className: "flex flex-col gap-y-1",
|
|
3521
|
+
children: [/*#__PURE__*/jsx(Typography, {
|
|
3522
|
+
style: "h3",
|
|
3523
|
+
children: t("neetoRules.builder.automationName")
|
|
3524
|
+
}), /*#__PURE__*/jsx(Typography, {
|
|
3525
|
+
className: "neeto-ui-text-gray-500",
|
|
3526
|
+
style: "body2",
|
|
3527
|
+
children: t("neetoRules.builder.nameSubtitle")
|
|
3528
|
+
})]
|
|
3529
|
+
})
|
|
3530
|
+
}), /*#__PURE__*/jsx(Panel.Body, {
|
|
3531
|
+
children: /*#__PURE__*/jsx(Input$1, {
|
|
3532
|
+
autoFocus: true,
|
|
3533
|
+
required: true,
|
|
3534
|
+
label: t("neetoRules.common.name"),
|
|
3535
|
+
name: "".concat(fieldKeys.name, ".value"),
|
|
3536
|
+
placeholder: t("neetoRules.builder.nameYourAutomation"),
|
|
3537
|
+
size: "large"
|
|
3538
|
+
})
|
|
3539
|
+
})]
|
|
3540
|
+
});
|
|
3541
|
+
};
|
|
3542
|
+
|
|
3543
|
+
function ownKeys$2(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; }
|
|
3544
|
+
function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$2(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$2(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
3545
|
+
var OptionsPane = function OptionsPane(_ref) {
|
|
3546
|
+
var schema = _ref.schema,
|
|
3547
|
+
anchor = _ref.anchor,
|
|
3548
|
+
index = _ref.index,
|
|
3549
|
+
_ref$belowContent = _ref.belowContent,
|
|
3550
|
+
belowContent = _ref$belowContent === void 0 ? null : _ref$belowContent;
|
|
3551
|
+
var _useTranslation = useTranslation(),
|
|
3552
|
+
t = _useTranslation.t;
|
|
3553
|
+
var _useFormikContext = useFormikContext(),
|
|
3554
|
+
setFieldValue = _useFormikContext.setFieldValue;
|
|
3555
|
+
var _useRuleModel = useRuleModel(schema),
|
|
3556
|
+
rule = _useRuleModel.rule,
|
|
3557
|
+
fieldKeys = _useRuleModel.fieldKeys,
|
|
3558
|
+
setTriggers = _useRuleModel.setTriggers,
|
|
3559
|
+
setPerformer = _useRuleModel.setPerformer,
|
|
3560
|
+
setConditionMode = _useRuleModel.setConditionMode;
|
|
3561
|
+
var _usePaneCascade = usePaneCascade(schema),
|
|
3562
|
+
openType = _usePaneCascade.openType,
|
|
3563
|
+
closePane = _usePaneCascade.closePane;
|
|
3564
|
+
var _useUtilityStore = useUtilityStore(useShallow(function (store) {
|
|
3565
|
+
return {
|
|
3566
|
+
setBuilderPreview: store["setBuilderPreview"]
|
|
3567
|
+
};
|
|
3568
|
+
})),
|
|
3569
|
+
setBuilderPreview = _useUtilityStore.setBuilderPreview;
|
|
3570
|
+
var _useState = useState(""),
|
|
3571
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
3572
|
+
searchTerm = _useState2[0],
|
|
3573
|
+
setSearchTerm = _useState2[1];
|
|
3574
|
+
var searchRef = useRef(null);
|
|
3575
|
+
|
|
3576
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3577
|
+
useEffect(function () {
|
|
3578
|
+
return function () {
|
|
3579
|
+
return setBuilderPreview(null);
|
|
3580
|
+
};
|
|
3581
|
+
}, []);
|
|
3582
|
+
useEffect(function () {
|
|
3583
|
+
var _searchRef$current;
|
|
3584
|
+
(_searchRef$current = searchRef.current) === null || _searchRef$current === void 0 || (_searchRef$current = _searchRef$current.querySelector("input")) === null || _searchRef$current === void 0 || _searchRef$current.focus();
|
|
3585
|
+
}, []);
|
|
3586
|
+
var _useMemo = useMemo(function () {
|
|
3587
|
+
return descriptorFor({
|
|
3588
|
+
anchor: anchor,
|
|
3589
|
+
schema: schema,
|
|
3590
|
+
rule: rule,
|
|
3591
|
+
index: index
|
|
3592
|
+
});
|
|
3593
|
+
}, [anchor, schema, rule, index]),
|
|
3594
|
+
title = _useMemo.title,
|
|
3595
|
+
subtitle = _useMemo.subtitle,
|
|
3596
|
+
multi = _useMemo.multi,
|
|
3597
|
+
options = _useMemo.options,
|
|
3598
|
+
selectedValues = _useMemo.selectedValues,
|
|
3599
|
+
cascade = _useMemo.cascade;
|
|
3600
|
+
var helpers = {
|
|
3601
|
+
setTriggers: setTriggers,
|
|
3602
|
+
setPerformer: setPerformer,
|
|
3603
|
+
setConditionMode: setConditionMode,
|
|
3604
|
+
setFieldValue: setFieldValue,
|
|
3605
|
+
fieldKeys: fieldKeys
|
|
3606
|
+
};
|
|
3607
|
+
var showSearch = (schema === null || schema === void 0 ? void 0 : schema.searchable) !== false && options.length >= PANE_SEARCH_THRESHOLD;
|
|
3608
|
+
var term = searchTerm.trim().toLowerCase();
|
|
3609
|
+
var filtered = useMemo(function () {
|
|
3610
|
+
return term ? options.filter(function (option) {
|
|
3611
|
+
return option.label.toLowerCase().includes(term);
|
|
3612
|
+
}) : options;
|
|
3613
|
+
}, [options, term]);
|
|
3614
|
+
var groups = useMemo(function () {
|
|
3615
|
+
return groupByCategory(filtered);
|
|
3616
|
+
}, [filtered]);
|
|
3617
|
+
// eslint-disable-next-line @bigbinary/neeto/prefer-function-reference
|
|
3618
|
+
var isSelected = function isSelected(value) {
|
|
3619
|
+
return selectedValues.includes(value);
|
|
3620
|
+
};
|
|
3621
|
+
var handleSelect = function handleSelect(value) {
|
|
3622
|
+
setBuilderPreview(null);
|
|
3623
|
+
var result = commitFor({
|
|
3624
|
+
anchor: anchor,
|
|
3625
|
+
schema: schema,
|
|
3626
|
+
rule: rule,
|
|
3627
|
+
index: index,
|
|
3628
|
+
value: value,
|
|
3629
|
+
helpers: helpers
|
|
3630
|
+
});
|
|
3631
|
+
if (result === "close") closePane();
|
|
3632
|
+
};
|
|
3633
|
+
var multiCandidate = function multiCandidate(optionValue) {
|
|
3634
|
+
return selectedValues.includes(optionValue) ? selectedValues.filter(isNot(optionValue)) : [].concat(_toConsumableArray(selectedValues.filter(Boolean)), [optionValue]);
|
|
3635
|
+
};
|
|
3636
|
+
var previewHandlers = function previewHandlers(optionValue) {
|
|
3637
|
+
var value = multi ? multiCandidate(optionValue) : optionValue;
|
|
3638
|
+
return {
|
|
3639
|
+
onMouseEnter: function onMouseEnter() {
|
|
3640
|
+
return setBuilderPreview({
|
|
3641
|
+
anchor: anchor,
|
|
3642
|
+
index: index,
|
|
3643
|
+
value: value
|
|
3644
|
+
});
|
|
3645
|
+
},
|
|
3646
|
+
onMouseLeave: function onMouseLeave() {
|
|
3647
|
+
return setBuilderPreview(null);
|
|
3648
|
+
}
|
|
3649
|
+
};
|
|
3650
|
+
};
|
|
3651
|
+
var handleContinue = function handleContinue() {
|
|
3652
|
+
var target = continueTargetFor({
|
|
3653
|
+
anchor: anchor,
|
|
3654
|
+
schema: schema,
|
|
3655
|
+
rule: rule,
|
|
3656
|
+
index: index
|
|
3657
|
+
});
|
|
3658
|
+
if (target) openType({
|
|
3659
|
+
type: target.type,
|
|
3660
|
+
data: target.data
|
|
3661
|
+
});else closePane();
|
|
3662
|
+
};
|
|
3663
|
+
var optionLabel = function optionLabel(option) {
|
|
3664
|
+
var Icon = option.icon;
|
|
3665
|
+
if (!Icon && !option.disabledReason) return option.label;
|
|
3666
|
+
return /*#__PURE__*/jsxs("span", {
|
|
3667
|
+
className: "mb-pane-option",
|
|
3668
|
+
children: [Icon && /*#__PURE__*/jsx(Icon, {
|
|
3669
|
+
size: 20
|
|
3670
|
+
}), option.label, option.disabledReason && (option.disabledTooltip ? /*#__PURE__*/jsx(Tooltip, {
|
|
3671
|
+
content: option.disabledTooltip,
|
|
3672
|
+
position: "top",
|
|
3673
|
+
children: /*#__PURE__*/jsx("span", {
|
|
3674
|
+
className: "mb-pane-warn",
|
|
3675
|
+
children: option.disabledReason
|
|
3676
|
+
})
|
|
3677
|
+
}) : /*#__PURE__*/jsx("span", {
|
|
3678
|
+
className: "mb-pane-warn",
|
|
3679
|
+
children: option.disabledReason
|
|
3680
|
+
}))]
|
|
3681
|
+
});
|
|
3682
|
+
};
|
|
3683
|
+
var renderGroupHeader = function renderGroupHeader(category) {
|
|
3684
|
+
return category && /*#__PURE__*/jsx("div", {
|
|
3685
|
+
className: "mb-pane-group",
|
|
3686
|
+
children: category
|
|
3687
|
+
});
|
|
3688
|
+
};
|
|
3689
|
+
var renderBody = function renderBody() {
|
|
3690
|
+
var _selectedValues$;
|
|
3691
|
+
if (isEmpty(filtered)) {
|
|
3692
|
+
return /*#__PURE__*/jsx("div", {
|
|
3693
|
+
className: "mb-pane-empty",
|
|
3694
|
+
children: t("neetoRules.builder.noMatches")
|
|
3695
|
+
});
|
|
3696
|
+
}
|
|
3697
|
+
if (multi) {
|
|
3698
|
+
return /*#__PURE__*/jsx("div", {
|
|
3699
|
+
className: "flex flex-col",
|
|
3700
|
+
children: groups.map(function (_ref2) {
|
|
3701
|
+
var _ref3 = _slicedToArray(_ref2, 2),
|
|
3702
|
+
category = _ref3[0],
|
|
3703
|
+
items = _ref3[1];
|
|
3704
|
+
return /*#__PURE__*/jsxs(Fragment$1, {
|
|
3705
|
+
children: [renderGroupHeader(category), items.map(function (option) {
|
|
3706
|
+
return /*#__PURE__*/jsx(Checkbox, _objectSpread$2(_objectSpread$2({
|
|
3707
|
+
checked: isSelected(option.value),
|
|
3708
|
+
disabled: option.disabled,
|
|
3709
|
+
label: optionLabel(option),
|
|
3710
|
+
labelProps: previewHandlers(option.value),
|
|
3711
|
+
onChange: function onChange() {
|
|
3712
|
+
return handleSelect(option.value);
|
|
3713
|
+
}
|
|
3714
|
+
}, option.icon || option.disabledReason ? {
|
|
3715
|
+
dataTestid: option.value
|
|
3716
|
+
} : {}), previewHandlers(option.value)), option.value);
|
|
3717
|
+
})]
|
|
3718
|
+
}, category || "_uncategorized");
|
|
3719
|
+
})
|
|
3720
|
+
});
|
|
3721
|
+
}
|
|
3722
|
+
return /*#__PURE__*/jsx(Radio, {
|
|
3723
|
+
stacked: true,
|
|
3724
|
+
value: (_selectedValues$ = selectedValues === null || selectedValues === void 0 ? void 0 : selectedValues[0]) !== null && _selectedValues$ !== void 0 ? _selectedValues$ : "",
|
|
3725
|
+
onChange: function onChange(event) {
|
|
3726
|
+
return handleSelect(event.target.value);
|
|
3727
|
+
},
|
|
3728
|
+
children: groups.flatMap(function (_ref4) {
|
|
3729
|
+
var _ref5 = _slicedToArray(_ref4, 2),
|
|
3730
|
+
category = _ref5[0],
|
|
3731
|
+
items = _ref5[1];
|
|
3732
|
+
return [category ? /*#__PURE__*/jsx("div", {
|
|
3733
|
+
className: "mb-pane-group",
|
|
3734
|
+
children: category
|
|
3735
|
+
}, "group-".concat(category)) : null].concat(_toConsumableArray(items.map(function (option) {
|
|
3736
|
+
return /*#__PURE__*/jsx(Radio.Item, _objectSpread$2(_objectSpread$2({
|
|
3737
|
+
disabled: option.disabled,
|
|
3738
|
+
label: optionLabel(option),
|
|
3739
|
+
labelProps: previewHandlers(option.value),
|
|
3740
|
+
value: option.value
|
|
3741
|
+
}, option.icon || option.disabledReason ? {
|
|
3742
|
+
dataTestid: option.value
|
|
3743
|
+
} : {}), previewHandlers(option.value)), option.value);
|
|
3744
|
+
})));
|
|
3745
|
+
}).filter(Boolean)
|
|
3746
|
+
});
|
|
3747
|
+
};
|
|
3748
|
+
return /*#__PURE__*/jsxs(Fragment, {
|
|
3749
|
+
children: [/*#__PURE__*/jsx(Panel.Header, {
|
|
3750
|
+
children: /*#__PURE__*/jsxs("div", {
|
|
3751
|
+
className: "flex w-full flex-col gap-y-2",
|
|
3752
|
+
children: [/*#__PURE__*/jsx(Typography, {
|
|
3753
|
+
style: "h3",
|
|
3754
|
+
children: title
|
|
3755
|
+
}), /*#__PURE__*/jsx(Typography, {
|
|
3756
|
+
className: "neeto-ui-text-gray-500",
|
|
3757
|
+
style: "body2",
|
|
3758
|
+
children: subtitle
|
|
3759
|
+
}), showSearch && /*#__PURE__*/jsx("div", {
|
|
3760
|
+
className: "mb-pane-search",
|
|
3761
|
+
ref: searchRef,
|
|
3762
|
+
children: /*#__PURE__*/jsx(Input, {
|
|
3763
|
+
placeholder: t("neetoRules.builder.searchPlaceholder"),
|
|
3764
|
+
prefix: /*#__PURE__*/jsx(Search, {}),
|
|
3765
|
+
size: "large",
|
|
3766
|
+
value: searchTerm,
|
|
3767
|
+
onChange: function onChange(event) {
|
|
3768
|
+
return setSearchTerm(event.target.value);
|
|
3769
|
+
}
|
|
3770
|
+
})
|
|
3771
|
+
})]
|
|
3772
|
+
})
|
|
3773
|
+
}), /*#__PURE__*/jsxs(Panel.Body, {
|
|
3774
|
+
children: [renderBody(), belowContent]
|
|
3775
|
+
}), cascade && /*#__PURE__*/jsx(Panel.Footer, {
|
|
3776
|
+
children: /*#__PURE__*/jsx(Button, {
|
|
3777
|
+
disabled: !selectedValues.some(Boolean),
|
|
3778
|
+
label: t("neetoRules.buttons.continue"),
|
|
3779
|
+
size: "large",
|
|
3780
|
+
onClick: handleContinue
|
|
3781
|
+
})
|
|
3782
|
+
})]
|
|
3783
|
+
});
|
|
3784
|
+
};
|
|
3785
|
+
|
|
3786
|
+
var RecipientField = function RecipientField(_ref) {
|
|
3787
|
+
var field = _ref.field,
|
|
3788
|
+
name = _ref.name,
|
|
3789
|
+
dropdownOptions = _ref.dropdownOptions,
|
|
3790
|
+
placeholder = _ref.placeholder;
|
|
3791
|
+
var _useTranslation = useTranslation(),
|
|
3792
|
+
t = _useTranslation.t;
|
|
3793
|
+
var _useFormikContext = useFormikContext(),
|
|
3794
|
+
values = _useFormikContext.values,
|
|
3795
|
+
setFieldValue = _useFormikContext.setFieldValue,
|
|
3796
|
+
setFieldTouched = _useFormikContext.setFieldTouched,
|
|
3797
|
+
errors = _useFormikContext.errors,
|
|
3798
|
+
touched = _useFormikContext.touched;
|
|
3799
|
+
var fieldError = function fieldError(path) {
|
|
3800
|
+
return getIn(touched, path) && getIn(errors, path);
|
|
3801
|
+
};
|
|
3802
|
+
if (field === "emails") {
|
|
3803
|
+
var _path = "".concat(name, ".emails");
|
|
3804
|
+
var _current = getIn(values, _path) || [];
|
|
3805
|
+
return /*#__PURE__*/jsx(MultiEmailInput, {
|
|
3806
|
+
required: true,
|
|
3807
|
+
error: fieldError(_path),
|
|
3808
|
+
label: t("neetoRules.builder.config.emailAddresses"),
|
|
3809
|
+
placeholder: t("neetoRules.builder.config.emailPlaceholder"),
|
|
3810
|
+
size: "large",
|
|
3811
|
+
value: _current.map(function (email) {
|
|
3812
|
+
return {
|
|
3813
|
+
label: email,
|
|
3814
|
+
value: email,
|
|
3815
|
+
valid: true
|
|
3816
|
+
};
|
|
3817
|
+
}),
|
|
3818
|
+
onBlur: function onBlur() {
|
|
3819
|
+
return setFieldTouched(_path, true);
|
|
3820
|
+
},
|
|
3821
|
+
onChange: function onChange(items) {
|
|
3822
|
+
return setFieldValue(_path, pluck("value", items || []));
|
|
3823
|
+
}
|
|
3824
|
+
});
|
|
3825
|
+
}
|
|
3826
|
+
var path = "".concat(name, ".value");
|
|
3827
|
+
var current = getIn(values, path);
|
|
3828
|
+
var options = normalizeOptions(dropdownOptions);
|
|
3829
|
+
return /*#__PURE__*/jsx(Select$1, {
|
|
3830
|
+
options: options,
|
|
3831
|
+
placeholder: placeholder,
|
|
3832
|
+
required: true,
|
|
3833
|
+
error: fieldError(path),
|
|
3834
|
+
label: t("neetoRules.builder.config.recipient"),
|
|
3835
|
+
size: "large",
|
|
3836
|
+
value: findBy({
|
|
3837
|
+
value: current
|
|
3838
|
+
}, options) || null,
|
|
3839
|
+
onBlur: function onBlur() {
|
|
3840
|
+
return setFieldTouched(path, true);
|
|
3841
|
+
},
|
|
3842
|
+
onChange: function onChange(option) {
|
|
3843
|
+
return setFieldValue(path, option === null || option === void 0 ? void 0 : option.value);
|
|
3844
|
+
}
|
|
3845
|
+
});
|
|
3846
|
+
};
|
|
3847
|
+
|
|
3848
|
+
var RecipientPane = function RecipientPane(_ref) {
|
|
3849
|
+
var _schema$actions, _schema$actions$actio, _schema$actions2, _schema$actions2$rend, _schema$actions3, _schema$actions3$opti, _schema$actions4, _schema$actions4$opti, _schema$actions5, _schema$actions6, _schema$actions$rende, _schema$actions7, _schema$actions7$rend, _action$metadata, _schema$actions8;
|
|
3850
|
+
var schema = _ref.schema,
|
|
3851
|
+
index = _ref.index;
|
|
3852
|
+
var _useTranslation = useTranslation(),
|
|
3853
|
+
t = _useTranslation.t;
|
|
3854
|
+
var _useRuleModel = useRuleModel(schema),
|
|
3855
|
+
rule = _useRuleModel.rule,
|
|
3856
|
+
fieldKeys = _useRuleModel.fieldKeys;
|
|
3857
|
+
var bodyRef = useRef(null);
|
|
3858
|
+
var belowRef = useRef(null);
|
|
3859
|
+
|
|
3860
|
+
// eslint-disable-next-line security/detect-object-injection
|
|
3861
|
+
var action = rule.actions[index] || {};
|
|
3862
|
+
var channel = action.channel || ((_schema$actions = schema.actions) === null || _schema$actions === void 0 || (_schema$actions$actio = _schema$actions.actionForName) === null || _schema$actions$actio === void 0 || (_schema$actions$actio = _schema$actions$actio.call(_schema$actions, action.name)) === null || _schema$actions$actio === void 0 ? void 0 : _schema$actions$actio.channel);
|
|
3863
|
+
var name = "".concat(fieldKeys.actions, ".value.").concat(index, ".metadata");
|
|
3864
|
+
var editor = (_schema$actions2 = schema.actions) === null || _schema$actions2 === void 0 || (_schema$actions2$rend = _schema$actions2.renderRecipientEditor) === null || _schema$actions2$rend === void 0 ? void 0 : _schema$actions2$rend.call(_schema$actions2, {
|
|
3865
|
+
channel: channel,
|
|
3866
|
+
name: name,
|
|
3867
|
+
action: action
|
|
3868
|
+
});
|
|
3869
|
+
var flatOption = ((_schema$actions3 = schema.actions) === null || _schema$actions3 === void 0 || (_schema$actions3$opti = _schema$actions3.optionForName) === null || _schema$actions3$opti === void 0 ? void 0 : _schema$actions3$opti.call(_schema$actions3, action.name)) || ((_schema$actions4 = schema.actions) === null || _schema$actions4 === void 0 || (_schema$actions4$opti = _schema$actions4.optionForChannel) === null || _schema$actions4$opti === void 0 ? void 0 : _schema$actions4$opti.call(_schema$actions4, channel));
|
|
3870
|
+
var isSmsToNumbers = (flatOption === null || flatOption === void 0 ? void 0 : flatOption.type) === SMS_TO_NUMBERS;
|
|
3871
|
+
var recipientFieldPath = isSmsToNumbers ? "".concat(name, ".phoneNumbers") : "".concat(name, ".emails");
|
|
3872
|
+
usePaneValidation(recipientFieldPath);
|
|
3873
|
+
useEffect(function () {
|
|
3874
|
+
var _bodyRef$current;
|
|
3875
|
+
if (!editor) return;
|
|
3876
|
+
var first = (_bodyRef$current = bodyRef.current) === null || _bodyRef$current === void 0 ? void 0 : _bodyRef$current.querySelector(RECIPIENT_FOCUSABLE_SELECTOR);
|
|
3877
|
+
// eslint-disable-next-line @bigbinary/neeto/prefer-function-reference
|
|
3878
|
+
if (first) setTimeout(function () {
|
|
3879
|
+
return first.focus();
|
|
3880
|
+
}, 0);
|
|
3881
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3882
|
+
}, [!editor]);
|
|
3883
|
+
var recipientConfig = (((_schema$actions5 = schema.actions) === null || _schema$actions5 === void 0 ? void 0 : _schema$actions5.options) || []).flatMap(function (option) {
|
|
3884
|
+
return option.recipients || [];
|
|
3885
|
+
}).concat(((_schema$actions6 = schema.actions) === null || _schema$actions6 === void 0 ? void 0 : _schema$actions6.recipients) || []).find(function (item) {
|
|
3886
|
+
var _item$value;
|
|
3887
|
+
return ((_item$value = item.value) !== null && _item$value !== void 0 ? _item$value : item.id) === action.recipient;
|
|
3888
|
+
});
|
|
3889
|
+
var builtInRecipientField = recipientConfig !== null && recipientConfig !== void 0 && recipientConfig.field ? /*#__PURE__*/jsx(RecipientField, {
|
|
3890
|
+
name: name,
|
|
3891
|
+
dropdownOptions: recipientConfig.dropdownOptions,
|
|
3892
|
+
field: recipientConfig.field,
|
|
3893
|
+
placeholder: recipientConfig.placeholder
|
|
3894
|
+
}) : null;
|
|
3895
|
+
var recipientField = (_schema$actions$rende = (_schema$actions7 = schema.actions) === null || _schema$actions7 === void 0 || (_schema$actions7$rend = _schema$actions7.renderRecipientField) === null || _schema$actions7$rend === void 0 ? void 0 : _schema$actions7$rend.call(_schema$actions7, {
|
|
3896
|
+
channel: channel,
|
|
3897
|
+
recipient: action.recipient,
|
|
3898
|
+
name: name,
|
|
3899
|
+
action: action
|
|
3900
|
+
})) !== null && _schema$actions$rende !== void 0 ? _schema$actions$rende : builtInRecipientField;
|
|
3901
|
+
var phoneField = isSmsToNumbers ? /*#__PURE__*/jsx(PhoneNumberField, {
|
|
3902
|
+
name: "".concat(name, ".phoneNumbers"),
|
|
3903
|
+
phoneNumbers: (_action$metadata = action.metadata) === null || _action$metadata === void 0 ? void 0 : _action$metadata.phoneNumbers
|
|
3904
|
+
}) : null;
|
|
3905
|
+
var belowField = phoneField || recipientField;
|
|
3906
|
+
var belowContent = belowField ? /*#__PURE__*/jsx("div", {
|
|
3907
|
+
className: "mt-5",
|
|
3908
|
+
ref: belowRef,
|
|
3909
|
+
children: belowField
|
|
3910
|
+
}) : null;
|
|
3911
|
+
useEffect(function () {
|
|
3912
|
+
if (!belowField) return undefined;
|
|
3913
|
+
var timer = setTimeout(function () {
|
|
3914
|
+
var _belowRef$current;
|
|
3915
|
+
return (_belowRef$current = belowRef.current) === null || _belowRef$current === void 0 || (_belowRef$current = _belowRef$current.querySelector(RECIPIENT_FOCUSABLE_SELECTOR)) === null || _belowRef$current === void 0 ? void 0 : _belowRef$current.focus();
|
|
3916
|
+
}, 0);
|
|
3917
|
+
return function () {
|
|
3918
|
+
return clearTimeout(timer);
|
|
3919
|
+
};
|
|
3920
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3921
|
+
}, [!!belowField]);
|
|
3922
|
+
if (!editor) {
|
|
3923
|
+
return /*#__PURE__*/jsx(OptionsPane, {
|
|
3924
|
+
belowContent: belowContent,
|
|
3925
|
+
index: index,
|
|
3926
|
+
schema: schema,
|
|
3927
|
+
anchor: BUILDER_ANCHORS.ACTION_RECIPIENT
|
|
3928
|
+
});
|
|
3929
|
+
}
|
|
3930
|
+
|
|
3931
|
+
// eslint-disable-next-line security/detect-object-injection
|
|
3932
|
+
var meta = ((_schema$actions8 = schema.actions) === null || _schema$actions8 === void 0 || (_schema$actions8 = _schema$actions8.channelMeta) === null || _schema$actions8 === void 0 ? void 0 : _schema$actions8[channel]) || {};
|
|
3933
|
+
return /*#__PURE__*/jsxs(Fragment, {
|
|
3934
|
+
children: [/*#__PURE__*/jsx(Panel.Header, {
|
|
3935
|
+
children: /*#__PURE__*/jsxs("div", {
|
|
3936
|
+
className: "flex w-full flex-col gap-y-2",
|
|
3937
|
+
children: [/*#__PURE__*/jsx(Typography, {
|
|
3938
|
+
style: "h3",
|
|
3939
|
+
children: meta.recipientTitle || t("neetoRules.builder.panes.recipientTitle")
|
|
3940
|
+
}), /*#__PURE__*/jsx(Typography, {
|
|
3941
|
+
className: "neeto-ui-text-gray-500",
|
|
3942
|
+
style: "body2",
|
|
3943
|
+
children: meta.recipientSubtitle || t("neetoRules.builder.panes.recipientSubtitle")
|
|
3944
|
+
})]
|
|
3945
|
+
})
|
|
3946
|
+
}), /*#__PURE__*/jsx(Panel.Body, {
|
|
3947
|
+
children: /*#__PURE__*/jsx("div", {
|
|
3948
|
+
ref: bodyRef,
|
|
3949
|
+
children: editor
|
|
3950
|
+
})
|
|
3951
|
+
})]
|
|
3952
|
+
});
|
|
3953
|
+
};
|
|
3954
|
+
|
|
3955
|
+
var ConditionValueFields = function ConditionValueFields(_ref) {
|
|
3956
|
+
var name = _ref.name,
|
|
3957
|
+
field = _ref.field,
|
|
3958
|
+
_ref$searchTerm = _ref.searchTerm,
|
|
3959
|
+
searchTerm = _ref$searchTerm === void 0 ? "" : _ref$searchTerm;
|
|
3960
|
+
var _useTranslation = useTranslation(),
|
|
3961
|
+
t = _useTranslation.t;
|
|
3962
|
+
var _useFormikContext = useFormikContext(),
|
|
3963
|
+
values = _useFormikContext.values,
|
|
3964
|
+
setFieldValue = _useFormikContext.setFieldValue,
|
|
3965
|
+
setFieldTouched = _useFormikContext.setFieldTouched,
|
|
3966
|
+
errors = _useFormikContext.errors,
|
|
3967
|
+
touched = _useFormikContext.touched;
|
|
3968
|
+
var type = field === null || field === void 0 ? void 0 : field.type;
|
|
3969
|
+
var valueType = (field === null || field === void 0 ? void 0 : field.valueType) || type;
|
|
3970
|
+
var valuePath = "".concat(name, ".metadata.value");
|
|
3971
|
+
var valuesPath = "".concat(name, ".metadata.values");
|
|
3972
|
+
var enumOptions = normalizeOptions((field === null || field === void 0 ? void 0 : field.values) || (field === null || field === void 0 ? void 0 : field.dropdownOptions) || (field === null || field === void 0 ? void 0 : field.options));
|
|
3973
|
+
var fieldError = function fieldError(path) {
|
|
3974
|
+
return getIn(touched, path) && getIn(errors, path);
|
|
3975
|
+
};
|
|
3976
|
+
var term = searchTerm.trim().toLowerCase();
|
|
3977
|
+
var filterOptions = function filterOptions(list) {
|
|
3978
|
+
return term ? list.filter(function (option) {
|
|
3979
|
+
return String(option.label).toLowerCase().includes(term);
|
|
3980
|
+
}) : list;
|
|
3981
|
+
};
|
|
3982
|
+
var noMatches = /*#__PURE__*/jsx("div", {
|
|
3983
|
+
className: "mb-pane-empty",
|
|
3984
|
+
children: t("neetoRules.builder.noMatches")
|
|
3985
|
+
});
|
|
3986
|
+
if (type === "multi-select" && isNotEmpty(enumOptions)) {
|
|
3987
|
+
var current = getIn(values, valuesPath) || [];
|
|
3988
|
+
var filtered = filterOptions(enumOptions);
|
|
3989
|
+
if (term && isEmpty(filtered)) return noMatches;
|
|
3990
|
+
var toggle = function toggle(value) {
|
|
3991
|
+
setFieldTouched(valuesPath, true);
|
|
3992
|
+
setFieldValue(valuesPath, current.includes(value) ? current.filter(isNot(value)) : [].concat(_toConsumableArray(current), [value]));
|
|
3993
|
+
};
|
|
3994
|
+
return /*#__PURE__*/jsxs("div", {
|
|
3995
|
+
className: "flex flex-col gap-y-1",
|
|
3996
|
+
children: [filtered.map(function (option) {
|
|
3997
|
+
return /*#__PURE__*/jsx(Checkbox, {
|
|
3998
|
+
checked: current.includes(option.value),
|
|
3999
|
+
label: option.label,
|
|
4000
|
+
onChange: function onChange() {
|
|
4001
|
+
return toggle(option.value);
|
|
4002
|
+
}
|
|
4003
|
+
}, option.value);
|
|
4004
|
+
}), fieldError(valuesPath) && /*#__PURE__*/jsx("p", {
|
|
4005
|
+
className: "neeto-ui-input__error",
|
|
4006
|
+
children: fieldError(valuesPath)
|
|
4007
|
+
})]
|
|
4008
|
+
});
|
|
4009
|
+
}
|
|
4010
|
+
if (type === "multi-select") {
|
|
4011
|
+
return /*#__PURE__*/jsx(Typography, {
|
|
4012
|
+
className: "neeto-ui-text-gray-500",
|
|
4013
|
+
style: "body2",
|
|
4014
|
+
children: field !== null && field !== void 0 && field.label ? t("neetoRules.builder.config.noOptionsFor", {
|
|
4015
|
+
field: field.label
|
|
4016
|
+
}) : t("neetoRules.builder.config.noOptions")
|
|
4017
|
+
});
|
|
4018
|
+
}
|
|
4019
|
+
if (type === "multi-select-create") {
|
|
4020
|
+
var _current = getIn(values, valuesPath) || [];
|
|
4021
|
+
return /*#__PURE__*/jsx(Select$1, {
|
|
4022
|
+
autoFocus: true,
|
|
4023
|
+
isCreateable: true,
|
|
4024
|
+
isMulti: true,
|
|
4025
|
+
required: true,
|
|
4026
|
+
error: fieldError(valuesPath),
|
|
4027
|
+
label: t("neetoRules.builder.config.keywords"),
|
|
4028
|
+
placeholder: t("neetoRules.builder.config.keywordsPlaceholder"),
|
|
4029
|
+
size: "large",
|
|
4030
|
+
value: _current.map(toLabelAndValue),
|
|
4031
|
+
onBlur: function onBlur() {
|
|
4032
|
+
return setFieldTouched(valuesPath, true);
|
|
4033
|
+
},
|
|
4034
|
+
onChange: function onChange(selected) {
|
|
4035
|
+
return setFieldValue(valuesPath, pluck("value", selected || []));
|
|
4036
|
+
}
|
|
4037
|
+
});
|
|
4038
|
+
}
|
|
4039
|
+
if (isNotEmpty(enumOptions)) {
|
|
4040
|
+
var _current2 = getIn(values, valuePath);
|
|
4041
|
+
var _filtered = filterOptions(enumOptions);
|
|
4042
|
+
if (term && isEmpty(_filtered)) return noMatches;
|
|
4043
|
+
return /*#__PURE__*/jsx(Radio, {
|
|
4044
|
+
stacked: true,
|
|
4045
|
+
error: fieldError(valuePath),
|
|
4046
|
+
value: _current2 !== null && _current2 !== void 0 ? _current2 : "",
|
|
4047
|
+
onBlur: function onBlur() {
|
|
4048
|
+
return setFieldTouched(valuePath, true);
|
|
4049
|
+
},
|
|
4050
|
+
onChange: function onChange(event) {
|
|
4051
|
+
return setFieldValue(valuePath, event.target.value);
|
|
4052
|
+
},
|
|
4053
|
+
children: _filtered.map(function (option) {
|
|
4054
|
+
return /*#__PURE__*/jsx(Radio.Item, {
|
|
4055
|
+
label: String(option.label).toLowerCase(),
|
|
4056
|
+
value: option.value
|
|
4057
|
+
}, option.value);
|
|
4058
|
+
})
|
|
4059
|
+
});
|
|
4060
|
+
}
|
|
4061
|
+
if (valueType === "number") {
|
|
4062
|
+
var _getIn;
|
|
4063
|
+
return /*#__PURE__*/jsx(Input, {
|
|
4064
|
+
autoFocus: true,
|
|
4065
|
+
required: true,
|
|
4066
|
+
error: fieldError(valuePath),
|
|
4067
|
+
label: t("neetoRules.common.value"),
|
|
4068
|
+
size: "large",
|
|
4069
|
+
type: "number",
|
|
4070
|
+
value: (_getIn = getIn(values, valuePath)) !== null && _getIn !== void 0 ? _getIn : "",
|
|
4071
|
+
onBlur: function onBlur() {
|
|
4072
|
+
return setFieldTouched(valuePath, true);
|
|
4073
|
+
},
|
|
4074
|
+
onChange: function onChange(event) {
|
|
4075
|
+
return setFieldValue(valuePath, event.target.value === "" ? "" : Number(event.target.value));
|
|
4076
|
+
}
|
|
4077
|
+
});
|
|
4078
|
+
}
|
|
4079
|
+
return /*#__PURE__*/jsx(Input$1, {
|
|
4080
|
+
autoFocus: true,
|
|
4081
|
+
required: true,
|
|
4082
|
+
label: t("neetoRules.common.value"),
|
|
4083
|
+
name: valuePath,
|
|
4084
|
+
size: "large",
|
|
4085
|
+
type: valueType === "email" ? "email" : "text",
|
|
4086
|
+
placeholder: (field === null || field === void 0 ? void 0 : field.placeholder) || (valueType === "email" ? t("neetoRules.builder.config.exampleEmail") : undefined)
|
|
4087
|
+
});
|
|
4088
|
+
};
|
|
4089
|
+
|
|
4090
|
+
var ValuePane = function ValuePane(_ref) {
|
|
4091
|
+
var _schema$conditions;
|
|
4092
|
+
var schema = _ref.schema,
|
|
4093
|
+
index = _ref.index;
|
|
4094
|
+
var _useTranslation = useTranslation(),
|
|
4095
|
+
t = _useTranslation.t;
|
|
4096
|
+
var _useFormikContext = useFormikContext(),
|
|
4097
|
+
setFieldValue = _useFormikContext.setFieldValue;
|
|
4098
|
+
var _useRuleModel = useRuleModel(schema),
|
|
4099
|
+
rule = _useRuleModel.rule,
|
|
4100
|
+
fieldKeys = _useRuleModel.fieldKeys;
|
|
4101
|
+
var _useState = useState(""),
|
|
4102
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
4103
|
+
searchTerm = _useState2[0],
|
|
4104
|
+
setSearchTerm = _useState2[1];
|
|
4105
|
+
var searchRef = useRef(null);
|
|
4106
|
+
|
|
4107
|
+
// eslint-disable-next-line security/detect-object-injection
|
|
4108
|
+
var condition = rule.conditions[index] || {};
|
|
4109
|
+
var field = (((_schema$conditions = schema.conditions) === null || _schema$conditions === void 0 ? void 0 : _schema$conditions.fields) || []).find(function (candidate) {
|
|
4110
|
+
return optionValue(candidate) === condition.field;
|
|
4111
|
+
});
|
|
4112
|
+
var base = "".concat(fieldKeys.conditions, ".value.").concat(index);
|
|
4113
|
+
usePaneValidation("".concat(base, ".metadata"));
|
|
4114
|
+
var enumOptions = normalizeOptions((field === null || field === void 0 ? void 0 : field.values) || (field === null || field === void 0 ? void 0 : field.dropdownOptions) || (field === null || field === void 0 ? void 0 : field.options));
|
|
4115
|
+
var showSearch = enumOptions.length >= PANE_SEARCH_THRESHOLD;
|
|
4116
|
+
var renderBody = function renderBody() {
|
|
4117
|
+
var _schema$conditions2;
|
|
4118
|
+
if ((_schema$conditions2 = schema.conditions) !== null && _schema$conditions2 !== void 0 && _schema$conditions2.renderValue) {
|
|
4119
|
+
return schema.conditions.renderValue({
|
|
4120
|
+
name: base,
|
|
4121
|
+
condition: condition,
|
|
4122
|
+
field: field,
|
|
4123
|
+
setFieldValue: setFieldValue,
|
|
4124
|
+
searchTerm: searchTerm
|
|
4125
|
+
});
|
|
4126
|
+
}
|
|
4127
|
+
return /*#__PURE__*/jsx(ConditionValueFields, {
|
|
4128
|
+
field: field,
|
|
4129
|
+
searchTerm: searchTerm,
|
|
4130
|
+
name: base
|
|
4131
|
+
});
|
|
4132
|
+
};
|
|
4133
|
+
return /*#__PURE__*/jsxs(Fragment, {
|
|
4134
|
+
children: [/*#__PURE__*/jsx(Panel.Header, {
|
|
4135
|
+
children: /*#__PURE__*/jsxs("div", {
|
|
4136
|
+
className: "flex w-full flex-col gap-y-2",
|
|
4137
|
+
children: [/*#__PURE__*/jsx(Typography, {
|
|
4138
|
+
style: "h3",
|
|
4139
|
+
children: t("neetoRules.builder.pickValue", {
|
|
4140
|
+
field: (field === null || field === void 0 ? void 0 : field.label) || t("neetoRules.builder.valueWord")
|
|
4141
|
+
})
|
|
4142
|
+
}), /*#__PURE__*/jsx(Typography, {
|
|
4143
|
+
className: "neeto-ui-text-gray-500",
|
|
4144
|
+
style: "body2",
|
|
4145
|
+
children: (field === null || field === void 0 ? void 0 : field.valueSubtitle) || (isMultiValueVerb(condition === null || condition === void 0 ? void 0 : condition.verb) ? t("neetoRules.builder.valuesSubtitle", {
|
|
4146
|
+
field: (field === null || field === void 0 ? void 0 : field.label) || t("neetoRules.builder.valueWord")
|
|
4147
|
+
}) : t("neetoRules.builder.valueSubtitle"))
|
|
4148
|
+
}), showSearch && /*#__PURE__*/jsx("div", {
|
|
4149
|
+
className: "mb-pane-search",
|
|
4150
|
+
ref: searchRef,
|
|
4151
|
+
children: /*#__PURE__*/jsx(Input, {
|
|
4152
|
+
placeholder: t("neetoRules.builder.searchPlaceholder"),
|
|
4153
|
+
prefix: /*#__PURE__*/jsx(Search, {}),
|
|
4154
|
+
size: "large",
|
|
4155
|
+
value: searchTerm,
|
|
4156
|
+
onChange: function onChange(event) {
|
|
4157
|
+
return setSearchTerm(event.target.value);
|
|
4158
|
+
}
|
|
4159
|
+
})
|
|
4160
|
+
})]
|
|
4161
|
+
})
|
|
4162
|
+
}), /*#__PURE__*/jsx(Panel.Body, {
|
|
4163
|
+
children: renderBody()
|
|
4164
|
+
})]
|
|
4165
|
+
});
|
|
4166
|
+
};
|
|
4167
|
+
|
|
4168
|
+
var _BUILDER_PANEL_TYPE_C;
|
|
4169
|
+
var BUILDER_PANEL_TYPE_CONFIG_MAP = (_BUILDER_PANEL_TYPE_C = {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_BUILDER_PANEL_TYPE_C, BUILDER_PANEL_TYPES.TRIGGER, {
|
|
4170
|
+
component: OptionsPane
|
|
4171
|
+
}), BUILDER_PANEL_TYPES.ACTOR, {
|
|
4172
|
+
component: OptionsPane
|
|
4173
|
+
}), BUILDER_PANEL_TYPES.CONDITION_FIELD, {
|
|
4174
|
+
component: OptionsPane
|
|
4175
|
+
}), BUILDER_PANEL_TYPES.OPERATOR, {
|
|
4176
|
+
component: OptionsPane
|
|
4177
|
+
}), BUILDER_PANEL_TYPES.CONNECTOR, {
|
|
4178
|
+
component: OptionsPane
|
|
4179
|
+
}), BUILDER_PANEL_TYPES.ACTION_CHANNEL, {
|
|
4180
|
+
component: OptionsPane
|
|
4181
|
+
}), BUILDER_PANEL_TYPES.RECIPIENT, {
|
|
4182
|
+
component: RecipientPane
|
|
4183
|
+
}), BUILDER_PANEL_TYPES.CONDITION_VALUE, {
|
|
4184
|
+
component: ValuePane
|
|
4185
|
+
}), BUILDER_PANEL_TYPES.ACTION_CONFIG, {
|
|
4186
|
+
component: ConfigPane
|
|
4187
|
+
}), BUILDER_PANEL_TYPES.DELAY, {
|
|
4188
|
+
component: DelayPane
|
|
4189
|
+
}), _defineProperty(_defineProperty(_defineProperty(_BUILDER_PANEL_TYPE_C, BUILDER_PANEL_TYPES.LEAD_TIME, {
|
|
4190
|
+
component: LeadTimePane
|
|
4191
|
+
}), BUILDER_PANEL_TYPES.NAME, {
|
|
4192
|
+
component: NamePane
|
|
4193
|
+
}), BUILDER_PANEL_TYPES.SCOPE, {
|
|
4194
|
+
component: OptionsPane
|
|
4195
|
+
}));
|
|
4196
|
+
|
|
4197
|
+
function ownKeys$1(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; }
|
|
4198
|
+
function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4199
|
+
var Form = function Form(_ref) {
|
|
4200
|
+
var _schema$meta$showName, _schema$meta;
|
|
4201
|
+
var _ref$data = _ref.data,
|
|
4202
|
+
data = _ref$data === void 0 ? {} : _ref$data,
|
|
4203
|
+
_ref$schema = _ref.schema,
|
|
4204
|
+
rawSchema = _ref$schema === void 0 ? {} : _ref$schema,
|
|
4205
|
+
url = _ref.automationRulesEndpoint,
|
|
4206
|
+
title = _ref.title,
|
|
4207
|
+
_ref$breadcrumbs = _ref.breadcrumbs,
|
|
4208
|
+
breadcrumbs = _ref$breadcrumbs === void 0 ? {} : _ref$breadcrumbs,
|
|
4209
|
+
_ref$isLoading = _ref.isLoading,
|
|
4210
|
+
isLoading = _ref$isLoading === void 0 ? false : _ref$isLoading,
|
|
4211
|
+
className = _ref.className,
|
|
4212
|
+
_ref$handleSubmit = _ref.handleSubmit,
|
|
4213
|
+
handleSubmit = _ref$handleSubmit === void 0 ? noop : _ref$handleSubmit,
|
|
4214
|
+
_ref$handleCancel = _ref.handleCancel,
|
|
4215
|
+
handleCancel = _ref$handleCancel === void 0 ? noop : _ref$handleCancel,
|
|
4216
|
+
_ref$payloadKey = _ref.payloadKey,
|
|
4217
|
+
payloadKey = _ref$payloadKey === void 0 ? "rule" : _ref$payloadKey,
|
|
4218
|
+
_ref$isNameGeneration = _ref.isNameGenerationDisabled,
|
|
4219
|
+
isNameGenerationDisabled = _ref$isNameGeneration === void 0 ? false : _ref$isNameGeneration;
|
|
4220
|
+
var _useTranslation = useTranslation(),
|
|
4221
|
+
t = _useTranslation.t;
|
|
4222
|
+
var formikRef = useRef(null);
|
|
4223
|
+
var formRef = useRef(null);
|
|
4224
|
+
var _useCustomDataStore = useCustomDataStore(useShallow(function (store) {
|
|
4225
|
+
return {
|
|
4226
|
+
customData: store["customData"]
|
|
4227
|
+
};
|
|
4228
|
+
})),
|
|
4229
|
+
customData = _useCustomDataStore.customData;
|
|
4230
|
+
var _useUtilityStore = useUtilityStore(useShallow(function (store) {
|
|
4231
|
+
return {
|
|
4232
|
+
resetPanelState: store["resetPanelState"],
|
|
4233
|
+
errorFields: store["errorFields"]
|
|
4234
|
+
};
|
|
4235
|
+
})),
|
|
4236
|
+
resetPanelState = _useUtilityStore.resetPanelState,
|
|
4237
|
+
errorFields = _useUtilityStore.errorFields;
|
|
4238
|
+
var initialValues = useMemo(function () {
|
|
4239
|
+
return formatData(data);
|
|
4240
|
+
}, [data]);
|
|
4241
|
+
var schema = useMemo(function () {
|
|
4242
|
+
return normalizeSchema(rawSchema);
|
|
4243
|
+
}, [rawSchema]);
|
|
4244
|
+
var isNameRequired = isNameGenerationDisabled || ((_schema$meta$showName = (_schema$meta = schema.meta) === null || _schema$meta === void 0 ? void 0 : _schema$meta.showName) !== null && _schema$meta$showName !== void 0 ? _schema$meta$showName : true);
|
|
4245
|
+
var _usePollRuleName = usePollRuleName({
|
|
4246
|
+
url: url,
|
|
4247
|
+
formikRef: formikRef,
|
|
4248
|
+
payloadKey: payloadKey,
|
|
4249
|
+
isNameGenerationDisabled: isNameGenerationDisabled
|
|
4250
|
+
}),
|
|
4251
|
+
waitForGeneratedRuleName = _usePollRuleName.waitForGeneratedRuleName,
|
|
4252
|
+
saveRuleName = _usePollRuleName.saveRuleName,
|
|
4253
|
+
isCancelledNameGeneration = _usePollRuleName.isCancelledNameGeneration;
|
|
4254
|
+
|
|
4255
|
+
// eslint-disable-next-line @bigbinary/neeto/prefer-function-reference, react-hooks/exhaustive-deps
|
|
4256
|
+
useEffect(function () {
|
|
4257
|
+
return function () {
|
|
4258
|
+
return resetPanelState();
|
|
4259
|
+
};
|
|
4260
|
+
}, []);
|
|
4261
|
+
var submitForm = function submitForm(values, formikBag) {
|
|
4262
|
+
if (isNotEmpty(errorFields)) {
|
|
4263
|
+
formikBag.setSubmitting(false);
|
|
4264
|
+
return;
|
|
4265
|
+
}
|
|
4266
|
+
var rule = valuesToRuleModel({
|
|
4267
|
+
values: values,
|
|
4268
|
+
schema: schema
|
|
4269
|
+
});
|
|
4270
|
+
if (!isRuleComplete(rule) || invalidScopeIndexes({
|
|
4271
|
+
rule: rule,
|
|
4272
|
+
schema: schema
|
|
4273
|
+
}).length) {
|
|
4274
|
+
formikBag.setSubmitting(false);
|
|
4275
|
+
return;
|
|
4276
|
+
}
|
|
4277
|
+
if (isCancelledNameGeneration) {
|
|
4278
|
+
saveRuleName(values);
|
|
4279
|
+
return;
|
|
4280
|
+
}
|
|
4281
|
+
var payload = buildPayload(data, values);
|
|
4282
|
+
resetPanelState();
|
|
4283
|
+
handleSubmit(payload, formikBag, waitForGeneratedRuleName);
|
|
4284
|
+
};
|
|
4285
|
+
return /*#__PURE__*/jsx(Formik, {
|
|
4286
|
+
enableReinitialize: true,
|
|
4287
|
+
initialValues: _objectSpread$1(_objectSpread$1({}, DEFAULT_INITIAL_VALUE), initialValues),
|
|
4288
|
+
innerRef: formikRef,
|
|
4289
|
+
validationSchema: getValidationSchema({
|
|
4290
|
+
data: data,
|
|
4291
|
+
customData: customData,
|
|
4292
|
+
isNameGenerationDisabled: isNameRequired
|
|
4293
|
+
}),
|
|
4294
|
+
onSubmit: submitForm,
|
|
4295
|
+
children: function children() {
|
|
4296
|
+
return /*#__PURE__*/jsxs("div", {
|
|
4297
|
+
className: "flex neeto-rules-main-content h-full w-full",
|
|
4298
|
+
children: [/*#__PURE__*/jsx(TouchErrors, {}), /*#__PURE__*/jsxs(Container, {
|
|
4299
|
+
className: "neeto-rules-main-content__container max-h-full",
|
|
4300
|
+
children: [/*#__PURE__*/jsx(Header, {
|
|
4301
|
+
breadcrumbs: breadcrumbs,
|
|
4302
|
+
title: title || t("neetoRules.common.title")
|
|
4303
|
+
}), isLoading ? /*#__PURE__*/jsx("div", {
|
|
4304
|
+
className: "flex h-full w-full items-center justify-center",
|
|
4305
|
+
children: /*#__PURE__*/jsx(Spinner, {})
|
|
4306
|
+
}) : /*#__PURE__*/jsxs(Form$1, {
|
|
4307
|
+
ref: formRef,
|
|
4308
|
+
className: classNames(["w-full neeto-rules-main-content__form max-w-5xl", className]),
|
|
4309
|
+
children: [/*#__PURE__*/jsx(Canvas, {
|
|
4310
|
+
schema: schema
|
|
4311
|
+
}), /*#__PURE__*/jsx(ScrollToErrorField, {
|
|
4312
|
+
formRef: formRef
|
|
4313
|
+
}), /*#__PURE__*/jsx("div", {
|
|
4314
|
+
className: "neeto-ui-bg-white sticky bottom-0 py-6",
|
|
4315
|
+
children: /*#__PURE__*/jsx(ActionBlock, {
|
|
4316
|
+
cancelButtonProps: {
|
|
4317
|
+
onClick: handleCancel
|
|
4318
|
+
},
|
|
4319
|
+
submitButtonProps: {
|
|
4320
|
+
"data-testid": "form-submit-button"
|
|
4321
|
+
}
|
|
4322
|
+
})
|
|
4323
|
+
})]
|
|
4324
|
+
})]
|
|
4325
|
+
}), /*#__PURE__*/jsx(Panel, {
|
|
4326
|
+
configMap: BUILDER_PANEL_TYPE_CONFIG_MAP
|
|
4327
|
+
})]
|
|
4328
|
+
});
|
|
4329
|
+
}
|
|
4330
|
+
});
|
|
4331
|
+
};
|
|
4332
|
+
|
|
4333
|
+
function ownKeys(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; }
|
|
4334
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4335
|
+
var NeetoRulesBuilder = function NeetoRulesBuilder(_ref) {
|
|
4336
|
+
var rest = Object.assign({}, (_objectDestructuringEmpty(_ref), _ref));
|
|
4337
|
+
return /*#__PURE__*/jsx(Form, _objectSpread({}, rest));
|
|
4338
|
+
};
|
|
4339
|
+
|
|
4340
|
+
export { NeetoRulesBuilder as default };
|
|
4341
|
+
//# sourceMappingURL=NeetoRulesBuilder.js.map
|