@synerise/ds-condition 0.9.1 → 0.11.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.
Files changed (32) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/README.md +29 -18
  3. package/dist/Condition.d.ts +5 -2
  4. package/dist/Condition.js +114 -196
  5. package/dist/Condition.style.d.ts +7 -5
  6. package/dist/Condition.style.js +7 -5
  7. package/dist/Condition.types.d.ts +18 -11
  8. package/dist/ConditionStep/AddCondition/AddCondition.d.ts +3 -0
  9. package/dist/ConditionStep/AddCondition/AddCondition.js +27 -0
  10. package/dist/ConditionStep/AddCondition/AddCondition.types.d.ts +10 -0
  11. package/dist/ConditionStep/AddCondition/AddCondition.types.js +0 -0
  12. package/dist/ConditionStep/AddCondition/index.d.ts +1 -0
  13. package/dist/ConditionStep/AddCondition/index.js +1 -0
  14. package/dist/ConditionStep/ConditionRow/ConditionRow.d.ts +3 -0
  15. package/dist/ConditionStep/ConditionRow/ConditionRow.js +70 -0
  16. package/dist/ConditionStep/ConditionRow/ConditionRow.types.d.ts +26 -0
  17. package/dist/ConditionStep/ConditionRow/ConditionRow.types.js +0 -0
  18. package/dist/ConditionStep/ConditionRow/index.d.ts +2 -0
  19. package/dist/ConditionStep/ConditionRow/index.js +2 -0
  20. package/dist/ConditionStep/ConditionStep.d.ts +3 -0
  21. package/dist/ConditionStep/ConditionStep.js +149 -0
  22. package/dist/ConditionStep/ConditionStep.types.d.ts +28 -0
  23. package/dist/ConditionStep/ConditionStep.types.js +0 -0
  24. package/dist/ConditionStep/StepHeader/StepHeader.d.ts +3 -0
  25. package/dist/ConditionStep/StepHeader/StepHeader.js +68 -0
  26. package/dist/ConditionStep/StepHeader/StepHeader.types.d.ts +12 -0
  27. package/dist/ConditionStep/StepHeader/StepHeader.types.js +0 -0
  28. package/dist/ConditionStep/StepHeader/index.d.ts +2 -0
  29. package/dist/ConditionStep/StepHeader/index.js +2 -0
  30. package/dist/ConditionStep/index.d.ts +2 -0
  31. package/dist/ConditionStep/index.js +2 -0
  32. package/package.json +11 -11
package/CHANGELOG.md CHANGED
@@ -3,6 +3,57 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [0.11.0](https://github.com/Synerise/synerise-design/compare/@synerise/ds-condition@0.10.2...@synerise/ds-condition@0.11.0) (2021-11-04)
7
+
8
+
9
+ ### Features
10
+
11
+ * **condition:** add custom factor component ([d1205bc](https://github.com/Synerise/synerise-design/commit/d1205bce20f4154e7596bcd33ad127557bc0ad99))
12
+
13
+
14
+
15
+
16
+
17
+ ## [0.10.2](https://github.com/Synerise/synerise-design/compare/@synerise/ds-condition@0.10.0...@synerise/ds-condition@0.10.2) (2021-10-26)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * **condition:** fixes add condition button ([2a06856](https://github.com/Synerise/synerise-design/commit/2a06856cf8759db1459467f95fcd4dd12af53e1c))
23
+
24
+
25
+
26
+
27
+
28
+ ## [0.10.1](https://github.com/Synerise/synerise-design/compare/@synerise/ds-condition@0.10.0...@synerise/ds-condition@0.10.1) (2021-10-19)
29
+
30
+
31
+ ### Bug Fixes
32
+
33
+ * **condition:** fixes add condition button ([2a06856](https://github.com/Synerise/synerise-design/commit/2a06856cf8759db1459467f95fcd4dd12af53e1c))
34
+
35
+
36
+
37
+
38
+
39
+ # [0.10.0](https://github.com/Synerise/synerise-design/compare/@synerise/ds-condition@0.9.1...@synerise/ds-condition@0.10.0) (2021-10-19)
40
+
41
+
42
+ ### Bug Fixes
43
+
44
+ * **condition:** performance improvements ([c3f54cf](https://github.com/Synerise/synerise-design/commit/c3f54cffcf2cfcb58da8686b88800fffed5e26ce))
45
+
46
+
47
+ ### Features
48
+
49
+ * **condition:** performance improvements ([128f4e3](https://github.com/Synerise/synerise-design/commit/128f4e3f608fe8b7d3429ca73da3a338285f9e7f))
50
+ * **condition:** uses current stepId for autofocus ([739d271](https://github.com/Synerise/synerise-design/commit/739d271b616c779c8877574ad239416a0739c621))
51
+ * **context-selector:** optimization improvements ([28feae6](https://github.com/Synerise/synerise-design/commit/28feae6ebc0e07c37c6c83f5197e80ea7c59347f))
52
+
53
+
54
+
55
+
56
+
6
57
  ## [0.9.1](https://github.com/Synerise/synerise-design/compare/@synerise/ds-condition@0.9.0...@synerise/ds-condition@0.9.1) (2021-10-05)
7
58
 
8
59
  **Note:** Version bump only for package @synerise/ds-condition
package/README.md CHANGED
@@ -25,12 +25,19 @@ import Condition from '@synerise/ds-condition'
25
25
  addCondition={() => {}}
26
26
  removeCondition={(stepId, conditionId) => {}}
27
27
  updateStepName={(stepId, name) => {}}
28
+ minConditionsLength={1}
29
+ maxConditionsLength={1}
30
+ onChangeContext={(stepId, contextItem) => {}}
31
+ onChangeSubject={(stepId, subjectItem) => {}}
32
+ onChangeParameter={(stepId, conditionId, value) => {}}
33
+ onChangeOperator={(stepId, conditionId, operator) => {}}
34
+ onChangeFactorValue={(stepId, conditionId, factorValue) => {}
35
+ onChangeFactorType={(stepId, conditionId, factorType) => {}
28
36
  steps={
29
37
  [{
30
38
  id: 1,
31
39
  stepName: 'Step #1',
32
40
  subject: {
33
- onSelectItem: (item) => setStepSubject(step.id, item),
34
41
  type: 'event',
35
42
  placeholder: 'Choose event',
36
43
  showPreview: false,
@@ -41,7 +48,6 @@ import Condition from '@synerise/ds-condition'
41
48
  },
42
49
  context: {
43
50
  texts: CONTEXT_TEXTS,
44
- onSelectItem: item => setStepSubject(step.id, item),
45
51
  selectedItem: step.subject.selectedItem,
46
52
  items: CONTEXT_ITEMS,
47
53
  groups: CONTEXT_GROUPS,
@@ -53,7 +59,6 @@ import Condition from '@synerise/ds-condition'
53
59
  selectedFactorType: 'parameter',
54
60
  defaultFactorType: 'parameter',
55
61
  setSelectedFactorType: () => {},
56
- onChangeValue: (value) => {},
57
62
  value: undefined,
58
63
  parameters: {
59
64
  buttonLabel: 'Parameter',
@@ -65,7 +70,6 @@ import Condition from '@synerise/ds-condition'
65
70
  texts: FACTORS_TEXTS,
66
71
  },
67
72
  operator: {
68
- onChange: (value) => {},
69
73
  value: value,
70
74
  items: OPERATORS_ITEMS,
71
75
  groups: OPERATORS_GROUPS,
@@ -74,8 +78,6 @@ import Condition from '@synerise/ds-condition'
74
78
  factor: {
75
79
  selectedFactorType: 'text',
76
80
  defaultFactorType: 'text',
77
- setSelectedFactorType: (factorType) => {},
78
- onChangeValue: (value) => {},
79
81
  textType: 'default',
80
82
  value: condition.factor.value,
81
83
  formulaEditor: <div>Formula editor</div>,
@@ -99,18 +101,27 @@ import Condition from '@synerise/ds-condition'
99
101
 
100
102
  ## API
101
103
 
102
- | Property | Description | Type | Default |
103
- | --- | --- | --- | --- |
104
- | addCondition | Callback called when user adds new row of conditions | (stepId: React.ReactText) => void | - |
105
- | removeCondition | Callback called when user clicks on remove row of condtions | (stepId: React.ReactText, conditionRowId: React.ReactText) => void | - |
106
- | steps | Array contains all steps of condition | ConditionStep[] | - |
107
- | texts | Translations object | Texts | - |
108
- | updateStepName | Callback called when user change the name of step | (stepId: React.ReactText, value: string) => void | - |
109
- | addStep | Callback called when user clicks on add step button | () => void | - |
110
- | duplicateStep | Callback called when user clicks on duplicate step button | (stepId: React.ReactText) => void | - |
111
- | removeStep | Callback called when user clicks on remove step button | (stepId: React.ReactText) => void | - |
112
- | onChangeOrder | Callback called when user change order of steps | (order: ConditionStep[]) => void | - |
113
- | autoClearCondition | Automatically fires clearing values of dependent elements | Boolean | false |
104
+ | Property | Description | Type | Default |
105
+ | --- | --- | --- | --- |
106
+ | addCondition | Callback called when user adds new row of conditions | (stepId: React.ReactText) => void | - |
107
+ | removeCondition | Callback called when user clicks on remove row of condtions | (stepId: React.ReactText, conditionRowId: React.ReactText) => void | - |
108
+ | steps | Array contains all steps of condition | ConditionStep[] | - |
109
+ | texts | Translations object | Texts | - |
110
+ | updateStepName | Callback called when user change the name of step | (stepId: React.ReactText, value: string) => void | - |
111
+ | addStep | Callback called when user clicks on add step button | () => void | - |
112
+ | duplicateStep | Callback called when user clicks on duplicate step button | (stepId: React.ReactText) => void | - |
113
+ | removeStep | Callback called when user clicks on remove step button | (stepId: React.ReactText) => void | - |
114
+ | onChangeOrder | Callback called when user change order of steps | (order: ConditionStep[]) => void | - |
115
+ | autoClearCondition | Automatically fires clearing values of dependent elements | Boolean | false |
116
+ | minConditionsLength | Minimal length of conditions in step | number | - |
117
+ | maxConditionsLength | Maximal length of conditions in step | number \ undefined | - |
118
+ | onChangeContext | Callback called when user change value of step context | (stepId: React.ReactText, value: ContextItem \ ContextGroup \ undefined) => void | - |
119
+ | onChangeSubject | Callback called when user change value of step subject | (stepId: React.ReactText, value: SubjectItem \ undefined) => void | - |
120
+ | onChangeParameter | Callback called when user change value of condition parameter | (stepId: React.ReactText, conditionId: React.ReactText, value: ParameterValue) | - |
121
+ | onChangeOperator | Callback called when user change value of condition operator | (stepId: React.ReactText, conditionId: React.ReactText, value: OperatorsItem \ undefined) => void | - |
122
+ | onChangeFactorValue | Callback called when user change value of condition factor | (stepId: React.ReactText, conditionId: React.ReactText, value: OperatorsType \ undefined) => void | - |
123
+ | onChangeFactorType | Callback called when user change type of condition factor | (stepId: React.ReactText, conditionId: React.ReactText, value: FactorType \ undefined) => void | - |
124
+ | onUpdateStepName | Callback called when user change the name of step condition | (stepId: React.ReactText, value: string) => void | - |
114
125
 
115
126
  ### ConditionStep
116
127
 
@@ -1,4 +1,7 @@
1
1
  import * as React from 'react';
2
- import { ConditionProps } from './Condition.types';
3
- declare const Condition: React.FC<ConditionProps>;
2
+ import * as T from './Condition.types';
3
+ export declare const OPERATOR = "operator";
4
+ export declare const PARAMETER = "parameter";
5
+ export declare const FACTOR = "factor";
6
+ declare const Condition: React.FC<T.ConditionProps>;
4
7
  export default Condition;
package/dist/Condition.js CHANGED
@@ -21,25 +21,19 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
21
21
  import * as React from 'react';
22
22
  import { useIntl } from 'react-intl';
23
23
  import { ReactSortable } from 'react-sortablejs';
24
- import InlineEdit from '@synerise/ds-inline-edit';
25
- import { Add2M, Add3M, CloseS, DragHandleM } from '@synerise/ds-icon/dist/icons';
24
+ import { Add3M } from '@synerise/ds-icon/dist/icons';
26
25
  import Icon from '@synerise/ds-icon';
27
26
  import Button from '@synerise/ds-button';
28
- import theme from '@synerise/ds-core/dist/js/DSProvider/ThemeProvider/theme';
29
- import Tooltip from '@synerise/ds-tooltip';
30
27
  import { NOOP } from '@synerise/ds-utils';
31
- import Subject from '@synerise/ds-subject';
32
- import Factors from '@synerise/ds-factors';
33
- import Operators from '@synerise/ds-operators';
34
- import ContextSelector from '@synerise/ds-context-selector';
35
- import Cruds from '@synerise/ds-cruds';
36
28
  import usePrevious from '@synerise/ds-utils/dist/usePrevious/usePrevious';
29
+ import { ConditionStep } from './ConditionStep';
37
30
  import * as S from './Condition.style';
38
31
  var DEFAULT_FIELD = '';
39
32
  var DEFAULT_CONDITION = '';
40
- var OPERATOR = 'operator';
41
- var PARAMETER = 'parameter';
42
- var FACTOR = 'factor';
33
+ var DEFAULT_STEP = '';
34
+ export var OPERATOR = 'operator';
35
+ export var PARAMETER = 'parameter';
36
+ export var FACTOR = 'factor';
43
37
  var SORTABLE_CONFIG = {
44
38
  ghostClass: 'steps-list-ghost-element',
45
39
  className: 'steps-list',
@@ -48,60 +42,35 @@ var SORTABLE_CONFIG = {
48
42
  forceFallback: true
49
43
  };
50
44
 
51
- var Condition = function Condition(_ref) {
52
- var steps = _ref.steps,
53
- addCondition = _ref.addCondition,
54
- removeCondition = _ref.removeCondition,
55
- updateStepName = _ref.updateStepName,
56
- texts = _ref.texts,
57
- duplicateStep = _ref.duplicateStep,
58
- removeStep = _ref.removeStep,
59
- addStep = _ref.addStep,
60
- onChangeOrder = _ref.onChangeOrder,
61
- _ref$minConditionsLen = _ref.minConditionsLength,
62
- minConditionsLength = _ref$minConditionsLen === void 0 ? 1 : _ref$minConditionsLen,
63
- autoClearCondition = _ref.autoClearCondition;
45
+ var Condition = function Condition(props) {
46
+ var steps = props.steps,
47
+ addCondition = props.addCondition,
48
+ removeCondition = props.removeCondition,
49
+ texts = props.texts,
50
+ duplicateStep = props.duplicateStep,
51
+ removeStep = props.removeStep,
52
+ addStep = props.addStep,
53
+ onChangeOrder = props.onChangeOrder,
54
+ _props$minConditionsL = props.minConditionsLength,
55
+ minConditionsLength = _props$minConditionsL === void 0 ? 1 : _props$minConditionsL,
56
+ maxConditionsLength = props.maxConditionsLength,
57
+ autoClearCondition = props.autoClearCondition,
58
+ onChangeContext = props.onChangeContext,
59
+ onChangeSubject = props.onChangeSubject,
60
+ onChangeParameter = props.onChangeParameter,
61
+ onChangeOperator = props.onChangeOperator,
62
+ onChangeFactorType = props.onChangeFactorType,
63
+ onChangeFactorValue = props.onChangeFactorValue,
64
+ onUpdateStepName = props.onUpdateStepName;
64
65
 
65
66
  var _useIntl = useIntl(),
66
67
  formatMessage = _useIntl.formatMessage;
67
68
 
68
69
  var text = React.useMemo(function () {
69
70
  return _objectSpread({
70
- stepNamePlaceholder: formatMessage({
71
- id: 'DS.CONDITION.STEP_NAME-PLACEHOLDER',
72
- defaultMessage: 'Step name'
73
- }),
74
- removeConditionRowTooltip: formatMessage({
75
- id: 'DS.CONDITION.REMOVE-CONDITION-ROW-TOOLTIP',
76
- defaultMessage: 'Delete'
77
- }),
78
- addConditionRowButton: formatMessage({
79
- id: 'DS.CONDITION.ADD-CONDITION-ROW-BUTTON',
80
- defaultMessage: 'Add condition'
81
- }),
82
- addFirstConditionRowButton: formatMessage({
83
- id: 'DS.CONDITION.ADD-FIRST-CONDITION-ROW-BUTTON',
84
- defaultMessage: 'Add condition'
85
- }),
86
71
  addStep: formatMessage({
87
72
  id: 'DS.CONDITION.ADD-STEP',
88
73
  defaultMessage: 'Add step'
89
- }),
90
- dropLabel: formatMessage({
91
- id: 'DS.CONDITION.DROP-LABEL',
92
- defaultMessage: 'Drop me here'
93
- }),
94
- moveTooltip: formatMessage({
95
- id: 'DS.CONDITION.MOVE-TOOLTIP',
96
- defaultMessage: 'Move'
97
- }),
98
- duplicateTooltip: formatMessage({
99
- id: 'DS.CONDITION.DUPLICATE-TOOLTIP',
100
- defaultMessage: 'Duplicate'
101
- }),
102
- removeTooltip: formatMessage({
103
- id: 'DS.CONDITION.REMOVE-TOOLTIP',
104
- defaultMessage: 'Delete'
105
74
  })
106
75
  }, texts);
107
76
  }, [texts, formatMessage]);
@@ -111,10 +80,15 @@ var Condition = function Condition(_ref) {
111
80
  currentConditionId = _React$useState2[0],
112
81
  setCurrentConditionId = _React$useState2[1];
113
82
 
114
- var _React$useState3 = React.useState(DEFAULT_FIELD),
83
+ var _React$useState3 = React.useState(DEFAULT_STEP),
115
84
  _React$useState4 = _slicedToArray(_React$useState3, 2),
116
- currentField = _React$useState4[0],
117
- setCurrentField = _React$useState4[1];
85
+ currentStepId = _React$useState4[0],
86
+ setCurrentStepId = _React$useState4[1];
87
+
88
+ var _React$useState5 = React.useState(DEFAULT_FIELD),
89
+ _React$useState6 = _slicedToArray(_React$useState5, 2),
90
+ currentField = _React$useState6[0],
91
+ setCurrentField = _React$useState6[1];
118
92
 
119
93
  var prevSteps = usePrevious(steps);
120
94
  React.useEffect(function () {
@@ -151,11 +125,13 @@ var Condition = function Condition(_ref) {
151
125
 
152
126
  if (newConditionId && newConditionId !== currentConditionId) {
153
127
  setCurrentConditionId(newConditionId);
154
- setCurrentField(PARAMETER);
155
128
  }
156
129
  }, [currentConditionId, currentField, prevSteps, steps]);
157
- var clearConditionRow = React.useCallback(function (step) {
158
- if (step.conditions.length === 0) return;
130
+ var clearConditionRow = React.useCallback(function (stepId) {
131
+ var step = steps.find(function (s) {
132
+ return s.id === stepId;
133
+ });
134
+ if (step === undefined || step.conditions.length === 0) return;
159
135
 
160
136
  if (removeCondition && addCondition) {
161
137
  step.conditions.forEach(function (condition, index) {
@@ -166,158 +142,100 @@ var Condition = function Condition(_ref) {
166
142
  }
167
143
 
168
144
  autoClearCondition && step.conditions.forEach(function (condition) {
169
- condition.factor && condition.factor.onChangeValue(undefined);
170
- condition.operator && condition.operator.onChange(undefined);
171
- condition.parameter && condition.parameter.onChangeValue(undefined);
145
+ onChangeFactorValue && onChangeFactorValue(step.id, condition.id, undefined);
146
+ onChangeOperator && onChangeOperator(step.id, condition.id, undefined);
147
+ onChangeParameter && onChangeParameter(step.id, condition.id, undefined);
172
148
  });
173
149
  setCurrentConditionId(step.conditions[0].id);
150
+ setCurrentStepId(step.id);
174
151
 
175
152
  if (step.conditions[0].parameter) {
176
153
  setCurrentField(PARAMETER);
177
154
  } else if (step.conditions[0].operator) {
178
155
  setCurrentField(OPERATOR);
179
156
  }
180
- }, [removeCondition, addCondition, autoClearCondition]);
181
- var selectSubject = React.useCallback(function (value, step) {
182
- clearConditionRow(step);
183
- step.subject && step.subject.onSelectItem(value);
184
- }, [clearConditionRow]);
185
- var selectContext = React.useCallback(function (value, step) {
186
- clearConditionRow(step);
187
- step.context && step.context.onSelectItem(value);
188
- }, [clearConditionRow]);
189
- var selectParameter = React.useCallback(function (condition, value) {
190
- if (condition.id && condition.parameter) {
191
- autoClearCondition && condition.operator && condition.operator.onChange(undefined);
192
- autoClearCondition && condition.factor && condition.factor.onChangeValue(undefined);
193
- condition.parameter.onChangeValue(value);
194
- setCurrentConditionId(condition.id);
157
+ }, [steps, removeCondition, addCondition, autoClearCondition, onChangeFactorValue, onChangeOperator, onChangeParameter]);
158
+ var selectSubject = React.useCallback(function (value, stepId) {
159
+ clearConditionRow(stepId);
160
+ setCurrentStepId(stepId);
161
+ onChangeSubject && onChangeSubject(stepId, value);
162
+ }, [clearConditionRow, onChangeSubject]);
163
+ var selectContext = React.useCallback(function (value, stepId) {
164
+ clearConditionRow(stepId);
165
+ setCurrentStepId(stepId);
166
+ onChangeContext && onChangeContext(stepId, value);
167
+ }, [clearConditionRow, onChangeContext]);
168
+ var selectParameter = React.useCallback(function (stepId, conditionId, value) {
169
+ if (conditionId && onChangeParameter) {
170
+ autoClearCondition && onChangeOperator && onChangeOperator(stepId, conditionId, undefined);
171
+ autoClearCondition && onChangeFactorValue && onChangeFactorValue(stepId, conditionId, undefined);
172
+ onChangeParameter(stepId, conditionId, value);
173
+ setCurrentConditionId(conditionId);
174
+ setCurrentStepId(stepId);
195
175
  setCurrentField(OPERATOR);
196
176
  }
197
- }, [autoClearCondition]);
198
- var selectOperator = React.useCallback(function (condition, value) {
199
- if (condition.id && condition.operator) {
200
- autoClearCondition && condition.factor && condition.factor.onChangeValue(undefined);
201
- condition.operator.onChange(value);
202
- setCurrentConditionId(condition.id);
177
+ }, [autoClearCondition, onChangeFactorValue, onChangeOperator, onChangeParameter]);
178
+ var selectOperator = React.useCallback(function (stepId, conditionId, value) {
179
+ if (conditionId && onChangeOperator) {
180
+ autoClearCondition && onChangeFactorValue && onChangeFactorValue(stepId, conditionId, undefined);
181
+ onChangeOperator(stepId, conditionId, value);
182
+ setCurrentConditionId(conditionId);
183
+ setCurrentStepId(stepId);
203
184
  setCurrentField(FACTOR);
204
185
  }
205
- }, [autoClearCondition]);
206
- var setStepConditionFactorType = React.useCallback(function (step, condition, factorType) {
207
- setCurrentConditionId(condition.id);
186
+ }, [autoClearCondition, onChangeFactorValue, onChangeOperator]);
187
+ var setStepConditionFactorType = React.useCallback(function (stepId, conditionId, factorType) {
188
+ setCurrentConditionId(conditionId);
189
+ setCurrentStepId(stepId);
208
190
  setCurrentField(FACTOR);
209
- condition.factor && condition.factor.setSelectedFactorType(factorType);
210
- }, []);
211
- var setStepConditionFactorValue = React.useCallback(function (step, condition, value) {
191
+ onChangeFactorType && onChangeFactorType(stepId, conditionId, factorType);
192
+ }, [onChangeFactorType]);
193
+ var setStepConditionFactorValue = React.useCallback(function (stepId, conditionId, value) {
212
194
  setCurrentField(DEFAULT_FIELD);
213
- condition.factor && condition.factor.onChangeValue(value);
214
- }, []);
195
+ setCurrentStepId(stepId);
196
+ onChangeFactorValue && onChangeFactorValue(stepId, conditionId, value);
197
+ }, [onChangeFactorValue]);
215
198
  var draggableEnabled = React.useMemo(function () {
216
199
  return onChangeOrder && steps.length > 1;
217
200
  }, [steps, onChangeOrder]);
218
- return React.createElement(S.Condition, {
219
- className: "ds-conditions"
220
- }, React.createElement(ReactSortable, _extends({}, SORTABLE_CONFIG, {
221
- list: steps,
222
- setList: onChangeOrder || NOOP
223
- }), steps.map(function (step, index) {
224
- var _step$subject, _step$context;
225
-
226
- return React.createElement(S.Step, {
227
- key: step.id,
228
- withStepName: step.stepName !== undefined,
229
- "data-dropLabel": text.dropLabel
230
- }, React.createElement(S.StepHeader, null, step.stepName !== undefined && React.createElement(S.StepName, null, "".concat(index + 1, "."), ' ', React.createElement(InlineEdit, {
231
- size: "small",
232
- input: {
233
- value: step.stepName,
234
- name: "condition-step-name-".concat(step.id),
235
- placeholder: text.stepNamePlaceholder,
236
- onChange: function onChange(event) {
237
- return updateStepName && updateStepName(step.id, event.target.value);
238
- }
239
- }
240
- })), React.createElement(S.StepCruds, null, draggableEnabled && React.createElement(Cruds.CustomAction, {
241
- icon: React.createElement(DragHandleM, null),
242
- title: text.moveTooltip,
243
- onClick: NOOP,
244
- className: "step-drag-handler"
245
- }), React.createElement(Cruds, {
246
- onDuplicate: duplicateStep ? function () {
247
- return duplicateStep(step.id);
248
- } : undefined,
249
- onDelete: removeStep ? function () {
250
- return removeStep(step.id);
251
- } : undefined,
252
- duplicateTooltip: text.duplicateTooltip,
253
- deleteTooltip: text.removeTooltip
254
- }))), React.createElement(S.StepConditions, null, React.createElement(S.Subject, null, step.subject && React.createElement(Subject, _extends({}, step.subject, {
255
- onSelectItem: function onSelectItem(value) {
256
- return selectSubject(value, step);
257
- }
258
- })), step.context && React.createElement(ContextSelector, _extends({}, step.context, {
259
- onSelectItem: function onSelectItem(value) {
260
- return selectContext(value, step);
261
- }
262
- }))), React.createElement(S.ConditionRows, null, step.conditions.length > 0 && step.conditions.map(function (condition, conditionIndex) {
263
- var _condition$parameter2, _condition$operator;
264
-
265
- return React.createElement(S.ConditionRow, {
266
- key: "condition-row-".concat(condition.id)
267
- }, React.createElement(S.ConditionConnections, {
268
- first: conditionIndex === 0,
269
- last: conditionIndex + 1 === step.conditions.length && !addCondition
270
- }), React.createElement(S.ConditionWrapper, null, condition.parameter && React.createElement(Factors, _extends({}, condition.parameter, {
271
- onChangeValue: function onChangeValue(value) {
272
- return selectParameter(condition, value);
273
- },
274
- opened: condition.id === currentConditionId && currentField === PARAMETER
275
- }))), (!(condition === null || condition === void 0 ? void 0 : condition.parameter) || (condition === null || condition === void 0 ? void 0 : (_condition$parameter2 = condition.parameter) === null || _condition$parameter2 === void 0 ? void 0 : _condition$parameter2.value)) && condition.operator && React.createElement(S.ConditionWrapper, null, React.createElement(Operators, _extends({}, condition.operator, {
276
- onChange: function onChange(value) {
277
- return selectOperator(condition, value);
278
- },
279
- opened: condition.id === currentConditionId && currentField === OPERATOR
280
- }))), (condition === null || condition === void 0 ? void 0 : (_condition$operator = condition.operator) === null || _condition$operator === void 0 ? void 0 : _condition$operator.value) && React.createElement(S.ConditionWrapper, null, condition.factor && React.createElement(Factors, _extends({}, condition.factor, {
281
- setSelectedFactorType: function setSelectedFactorType(factorType) {
282
- return setStepConditionFactorType(step, condition, factorType);
283
- },
284
- onChangeValue: function onChangeValue(value) {
285
- return setStepConditionFactorValue(step, condition, value);
286
- },
287
- factorKey: condition.id,
288
- opened: condition.id === currentConditionId && currentField === FACTOR
289
- }))), removeCondition && step.conditions.length > minConditionsLength && React.createElement(S.RemoveIconWrapper, {
290
- onClick: function onClick() {
291
- return removeCondition(step.id, condition.id);
292
- },
293
- className: "ds-conditions-remove-row"
294
- }, React.createElement(Tooltip, {
295
- title: text.removeConditionRowTooltip,
296
- trigger: ['hover']
297
- }, React.createElement(Icon, {
298
- component: React.createElement(CloseS, null),
299
- color: theme.palette['red-600']
300
- }))));
301
- }), addCondition && React.createElement(S.AddConditionRow, null, React.createElement(S.ConditionConnections, {
302
- last: true,
303
- first: step.conditions.length === 0
304
- }), React.createElement(Button, {
305
- type: "ghost",
201
+ return React.useMemo(function () {
202
+ return React.createElement(S.Condition, {
203
+ className: "ds-conditions"
204
+ }, React.createElement(ReactSortable, _extends({}, SORTABLE_CONFIG, {
205
+ list: steps,
206
+ setList: onChangeOrder || NOOP
207
+ }), steps.map(function (step, index) {
208
+ return React.createElement(ConditionStep, {
209
+ key: "step-id-".concat(step.id),
210
+ step: step,
211
+ texts: texts,
212
+ index: index,
213
+ draggableEnabled: draggableEnabled,
214
+ selectOperator: selectOperator,
215
+ selectParameter: selectParameter,
216
+ selectContext: selectContext,
217
+ selectSubject: selectSubject,
218
+ updateStepName: onUpdateStepName,
219
+ duplicateStep: duplicateStep,
220
+ removeStep: removeStep,
221
+ minConditionsLength: minConditionsLength,
222
+ maxConditionsLength: maxConditionsLength,
223
+ setStepConditionFactorType: setStepConditionFactorType,
224
+ setStepConditionFactorValue: setStepConditionFactorValue,
225
+ currentConditionId: currentConditionId,
226
+ currentStepId: currentStepId,
227
+ currentField: currentField,
228
+ removeCondition: removeCondition,
229
+ addCondition: addCondition
230
+ });
231
+ })), addStep && React.createElement(Button, {
232
+ type: "ghost-primary",
306
233
  mode: "icon-label",
307
- onClick: function onClick() {
308
- addCondition(step.id);
309
- },
310
- disabled: !(Boolean((_step$subject = step.subject) === null || _step$subject === void 0 ? void 0 : _step$subject.selectedItem) || Boolean((_step$context = step.context) === null || _step$context === void 0 ? void 0 : _step$context.selectedItem))
234
+ onClick: addStep
311
235
  }, React.createElement(Icon, {
312
- component: React.createElement(Add2M, null)
313
- }), step.conditions.length > 0 ? text.addConditionRowButton : text.addFirstConditionRowButton)))));
314
- })), addStep && React.createElement(Button, {
315
- type: "ghost-primary",
316
- mode: "icon-label",
317
- onClick: addStep
318
- }, React.createElement(Icon, {
319
- component: React.createElement(Add3M, null)
320
- }), text.addStep));
236
+ component: React.createElement(Add3M, null)
237
+ }), text.addStep));
238
+ }, [steps, onChangeOrder, addStep, text.addStep, texts, draggableEnabled, selectOperator, selectParameter, selectContext, selectSubject, onUpdateStepName, duplicateStep, removeStep, minConditionsLength, maxConditionsLength, setStepConditionFactorType, setStepConditionFactorValue, currentConditionId, currentStepId, currentField, removeCondition, addCondition]);
321
239
  };
322
240
 
323
241
  export default Condition;
@@ -1,16 +1,18 @@
1
- export declare const StepConditions: import("styled-components").StyledComponent<"div", any, {}, never>;
1
+ export declare const StepConditions: import("styled-components").StyledComponent<"div", any, {
2
+ withoutStepName: boolean;
3
+ }, never>;
2
4
  export declare const StepName: import("styled-components").StyledComponent<"div", any, {}, never>;
3
5
  export declare const Condition: import("styled-components").StyledComponent<"div", any, {}, never>;
4
6
  export declare const StepCruds: import("styled-components").StyledComponent<"div", any, {}, never>;
5
7
  export declare const StepHeader: import("styled-components").StyledComponent<"div", any, {}, never>;
6
- export declare const Step: import("styled-components").StyledComponent<"div", any, {
7
- withStepName: boolean;
8
- }, never>;
8
+ export declare const Step: import("styled-components").StyledComponent<"div", any, {}, never>;
9
9
  export declare const ConditionWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
10
10
  export declare const Subject: import("styled-components").StyledComponent<"div", any, {}, never>;
11
11
  export declare const RemoveIconWrapper: import("styled-components").StyledComponent<"span", any, {}, never>;
12
12
  export declare const ConditionRows: import("styled-components").StyledComponent<"div", any, {}, never>;
13
- export declare const ConditionRow: import("styled-components").StyledComponent<"div", any, {}, never>;
13
+ export declare const ConditionRow: import("styled-components").StyledComponent<"div", any, {
14
+ index: number;
15
+ }, never>;
14
16
  export declare const AddConditionRow: import("styled-components").StyledComponent<"div", any, {}, never>;
15
17
  export declare const ConditionConnections: import("styled-components").StyledComponent<"span", any, {
16
18
  first?: boolean | undefined;
@@ -3,7 +3,9 @@ import { IconWrapper } from '@synerise/ds-inline-edit/dist/InlineEdit.styles';
3
3
  export var StepConditions = styled.div.withConfig({
4
4
  displayName: "Conditionstyle__StepConditions",
5
5
  componentId: "sc-1lk06p3-0"
6
- })(["display:flex;flex-direction:row;align-items:flex-start;justify-content:flex-start;"]);
6
+ })(["display:flex;flex-direction:row;align-items:flex-start;justify-content:flex-start;margin-top:", ";"], function (props) {
7
+ return props.withoutStepName ? '22px' : '0';
8
+ });
7
9
  export var StepName = styled.div.withConfig({
8
10
  displayName: "Conditionstyle__StepName",
9
11
  componentId: "sc-1lk06p3-1"
@@ -25,9 +27,7 @@ export var StepHeader = styled.div.withConfig({
25
27
  export var Step = styled.div.withConfig({
26
28
  displayName: "Conditionstyle__Step",
27
29
  componentId: "sc-1lk06p3-5"
28
- })(["display:flex;flex-direction:column;align-items:flex-start;justify-content:flex-start;padding:", ";border-top:1px dotted ", ";&:first-of-type{border-top:0;&.steps-list-ghost-element{&:after{display:none;}}}&:hover{", "{opacity:1;visibility:visible;}}&.sortable-chosen{cursor:grabbing;width:100%;opacity:1 !important;height:50px;background-color:", ";display:flex;align-items:center;justify-content:center;padding:0 20px;box-shadow:0 16px 32px 0 #23293619;", "{align-items:center;}", "{margin:0;", "{display:none;}}", "{display:none;}}&.steps-list-ghost-element{cursor:grabbing;width:100%;background-color:", ";border:1px dashed ", ";border-radius:3px;display:flex;align-items:center;justify-content:center;padding:0;height:50px;box-shadow:none;position:relative;margin:24px 0;&:after{content:'';position:absolute;top:-24px;left:0;width:100%;height:1px;border-bottom:1px dotted ", ";}&:before{content:attr(data-dropLabel);text-align:center;position:relative;color:", ";}*{display:none;}}}"], function (props) {
29
- return props.withStepName ? '0 0 36px' : '0 0 24px 0';
30
- }, function (props) {
30
+ })(["display:flex;flex-direction:column;align-items:flex-start;justify-content:flex-start;padding:0 0 24px 0;border-top:1px dotted ", ";position:relative;&:first-of-type{border-top:0;&.steps-list-ghost-element{&:after{display:none;}}}&:hover{", "{opacity:1;visibility:visible;}}&.sortable-chosen{cursor:grabbing;width:100%;opacity:1 !important;height:50px;background-color:", ";display:flex;align-items:center;justify-content:center;padding:0 20px;box-shadow:0 16px 32px 0 #23293619;", "{align-items:center;}", "{margin:0;", "{display:none;}}", "{display:none;}}&.steps-list-ghost-element{cursor:grabbing;width:100%;background-color:", ";border:1px dashed ", ";border-radius:3px;display:flex;align-items:center;justify-content:center;padding:0;height:50px;box-shadow:none;position:relative;margin:24px 0;&:after{content:'';position:absolute;top:-24px;left:0;width:100%;height:1px;border-bottom:1px dotted ", ";}&:before{content:attr(data-dropLabel);text-align:center;position:relative;color:", ";}*{display:none;}}}"], function (props) {
31
31
  return props.theme.palette['grey-300'];
32
32
  }, StepCruds, function (props) {
33
33
  return props.theme.palette.white;
@@ -59,7 +59,9 @@ export var ConditionRows = styled.div.withConfig({
59
59
  export var ConditionRow = styled.div.withConfig({
60
60
  displayName: "Conditionstyle__ConditionRow",
61
61
  componentId: "sc-1lk06p3-10"
62
- })(["display:flex;flex-direction:row;align-items:flex-start;justify-content:flex-start;padding-bottom:16px;min-width:780px;", "{margin-right:8px;&:last-of-type{margin-right:0;}}&:hover{", "{opacity:1;visibility:visible;pointer-events:all;cursor:pointer;}}"], ConditionWrapper, RemoveIconWrapper);
62
+ })(["display:flex;flex-direction:row;align-items:flex-start;justify-content:flex-start;padding-bottom:16px;min-width:780px;z-index:", ";", "{margin-right:8px;&:last-of-type{margin-right:0;}}&:hover{", "{opacity:1;visibility:visible;pointer-events:all;cursor:pointer;}}"], function (props) {
63
+ return 10000 - props.index;
64
+ }, ConditionWrapper, RemoveIconWrapper);
63
65
  export var AddConditionRow = styled.div.withConfig({
64
66
  displayName: "Conditionstyle__AddConditionRow",
65
67
  componentId: "sc-1lk06p3-11"
@@ -1,18 +1,18 @@
1
1
  import * as React from 'react';
2
- import { SubjectProps } from '@synerise/ds-subject/dist/Subject.types';
3
- import { FactorsProps } from '@synerise/ds-factors/dist/Factors.types';
4
- import { OperatorsProps } from '@synerise/ds-operators/dist/Operator.types';
5
- import { ContextProps } from '@synerise/ds-context-selector/dist/ContextSelector.types';
2
+ import { SubjectItem, SubjectProps } from '@synerise/ds-subject/dist/Subject.types';
3
+ import { FactorsProps, FactorType, FactorValueType } from '@synerise/ds-factors/dist/Factors.types';
4
+ import { OperatorsItem, OperatorsProps } from '@synerise/ds-operators/dist/Operator.types';
5
+ import { ContextGroup, ContextItem, ContextProps } from '@synerise/ds-context-selector/dist/ContextSelector.types';
6
6
  export declare type StepConditions = {
7
7
  id: React.ReactText;
8
- parameter?: FactorsProps;
9
- operator?: OperatorsProps;
10
- factor?: FactorsProps;
8
+ parameter?: Omit<FactorsProps, 'onChangeValue'>;
9
+ operator?: Omit<OperatorsProps, 'onChange'>;
10
+ factor?: Omit<FactorsProps, 'onChangeValue' | 'setSelectedFactorType'>;
11
11
  };
12
12
  export declare type ConditionStep = {
13
13
  id: React.ReactText;
14
- subject?: SubjectProps;
15
- context?: ContextProps;
14
+ subject?: Omit<SubjectProps, 'onSelectItem'>;
15
+ context?: Omit<ContextProps, 'onSelectItem'>;
16
16
  stepName?: string;
17
17
  conditions: StepConditions[];
18
18
  };
@@ -31,12 +31,19 @@ export declare type ConditionProps = {
31
31
  steps: ConditionStep[];
32
32
  addCondition?: (stepId: React.ReactText) => void;
33
33
  removeCondition?: (stepId: React.ReactText, conditionRowId: React.ReactText) => void;
34
- updateStepName?: (stepId: React.ReactText, value: string) => void;
35
34
  removeStep?: (stepId: React.ReactText) => void;
36
35
  duplicateStep?: (stepId: React.ReactText) => void;
37
36
  addStep?: () => void;
38
37
  onChangeOrder?: (newOrder: ConditionStep[]) => void;
39
38
  texts?: Partial<ConditionTexts>;
40
- minConditionsLength?: number;
39
+ minConditionsLength: number;
40
+ maxConditionsLength?: number | undefined;
41
41
  autoClearCondition?: boolean;
42
+ onChangeContext: (stepId: React.ReactText, value: ContextItem | ContextGroup | undefined) => void;
43
+ onChangeSubject: (stepId: React.ReactText, value: SubjectItem | undefined) => void;
44
+ onChangeParameter: (stepId: React.ReactText, conditionId: React.ReactText, value: FactorValueType | undefined) => void;
45
+ onChangeOperator: (stepId: React.ReactText, conditionId: React.ReactText, value: OperatorsItem | undefined) => void;
46
+ onChangeFactorValue: (stepId: React.ReactText, conditionId: React.ReactText, value: FactorValueType | undefined) => void;
47
+ onChangeFactorType: (stepId: React.ReactText, conditionId: React.ReactText, value: FactorType | undefined) => void;
48
+ onUpdateStepName?: (stepId: React.ReactText, value: string) => void;
42
49
  };
@@ -0,0 +1,3 @@
1
+ import * as React from 'react';
2
+ import * as T from './AddCondition.types';
3
+ export declare const AddCondition: React.FC<T.AddConditionProps>;
@@ -0,0 +1,27 @@
1
+ import * as React from 'react';
2
+ import Button from '@synerise/ds-button';
3
+ import Icon from '@synerise/ds-icon';
4
+ import { Add2M } from '@synerise/ds-icon/dist/icons';
5
+ import * as S from '../../Condition.style';
6
+ // eslint-disable-next-line import/prefer-default-export
7
+ export var AddCondition = function AddCondition(_ref) {
8
+ var addCondition = _ref.addCondition,
9
+ stepId = _ref.stepId,
10
+ conditionsNumber = _ref.conditionsNumber,
11
+ texts = _ref.texts,
12
+ selectedSubject = _ref.selectedSubject,
13
+ selectedContext = _ref.selectedContext;
14
+ return React.createElement(S.AddConditionRow, null, React.createElement(S.ConditionConnections, {
15
+ last: true,
16
+ first: conditionsNumber === 0
17
+ }), React.createElement(Button, {
18
+ type: "ghost",
19
+ mode: "icon-label",
20
+ onClick: function onClick() {
21
+ addCondition && addCondition(stepId);
22
+ },
23
+ disabled: !(selectedSubject || selectedContext)
24
+ }, React.createElement(Icon, {
25
+ component: React.createElement(Add2M, null)
26
+ }), conditionsNumber > 0 ? texts.addConditionRowButton : texts.addFirstConditionRowButton));
27
+ };
@@ -0,0 +1,10 @@
1
+ /// <reference types="react" />
2
+ import { ConditionProps, ConditionTexts } from '../../Condition.types';
3
+ export declare type AddConditionProps = {
4
+ addCondition: ConditionProps['addCondition'];
5
+ stepId: React.ReactText;
6
+ conditionsNumber: number;
7
+ texts: Partial<ConditionTexts>;
8
+ selectedSubject: boolean;
9
+ selectedContext: boolean;
10
+ };
@@ -0,0 +1 @@
1
+ export * from './AddCondition';
@@ -0,0 +1 @@
1
+ export * from './AddCondition';
@@ -0,0 +1,3 @@
1
+ import * as React from 'react';
2
+ import * as T from './ConditionRow.types';
3
+ export declare const ConditionRow: React.FC<T.ConditionRowProps>;
@@ -0,0 +1,70 @@
1
+ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
+
3
+ import Factors from '@synerise/ds-factors';
4
+ import Operators from '@synerise/ds-operators';
5
+ import Tooltip from '@synerise/ds-tooltip';
6
+ import Icon from '@synerise/ds-icon';
7
+ import { CloseS } from '@synerise/ds-icon/dist/icons';
8
+ import theme from '@synerise/ds-core/dist/js/DSProvider/ThemeProvider/theme';
9
+ import * as React from 'react';
10
+ import { FACTOR, OPERATOR, PARAMETER } from '../../Condition';
11
+ import * as S from '../../Condition.style';
12
+ // eslint-disable-next-line import/prefer-default-export
13
+ export var ConditionRow = function ConditionRow(_ref) {
14
+ var index = _ref.index,
15
+ conditionId = _ref.conditionId,
16
+ conditionParameter = _ref.conditionParameter,
17
+ conditionOperator = _ref.conditionOperator,
18
+ conditionFactor = _ref.conditionFactor,
19
+ removeCondition = _ref.removeCondition,
20
+ addCondition = _ref.addCondition,
21
+ minConditionLength = _ref.minConditionLength,
22
+ maxConditionLength = _ref.maxConditionLength,
23
+ conditionsNumber = _ref.conditionsNumber,
24
+ stepId = _ref.stepId,
25
+ currentStepId = _ref.currentStepId,
26
+ currentConditionId = _ref.currentConditionId,
27
+ currentField = _ref.currentField,
28
+ selectParameter = _ref.selectParameter,
29
+ selectOperator = _ref.selectOperator,
30
+ setStepConditionFactorType = _ref.setStepConditionFactorType,
31
+ setStepConditionFactorValue = _ref.setStepConditionFactorValue,
32
+ texts = _ref.texts;
33
+ return React.createElement(S.ConditionRow, {
34
+ key: "condition-row-".concat(conditionId),
35
+ index: index
36
+ }, React.createElement(S.ConditionConnections, {
37
+ first: index === 0,
38
+ last: Boolean(addCondition && index + 1 === conditionsNumber && maxConditionLength !== undefined && conditionsNumber === maxConditionLength)
39
+ }), React.createElement(S.ConditionWrapper, null, conditionParameter && React.createElement(Factors, _extends({}, conditionParameter, {
40
+ onChangeValue: function onChangeValue(value) {
41
+ return selectParameter(stepId, conditionId, value);
42
+ },
43
+ opened: stepId === currentStepId && conditionId === currentConditionId && currentField === PARAMETER
44
+ }))), (!conditionParameter || (conditionParameter === null || conditionParameter === void 0 ? void 0 : conditionParameter.value)) && conditionOperator && React.createElement(S.ConditionWrapper, null, React.createElement(Operators, _extends({}, conditionOperator, {
45
+ onChange: function onChange(value) {
46
+ return selectOperator(stepId, conditionId, value);
47
+ },
48
+ opened: stepId === currentStepId && conditionId === currentConditionId && currentField === OPERATOR
49
+ }))), (conditionOperator === null || conditionOperator === void 0 ? void 0 : conditionOperator.value) && React.createElement(S.ConditionWrapper, null, React.createElement(React.Fragment, null, (conditionFactor === null || conditionFactor === void 0 ? void 0 : conditionFactor.withCustomFactor) || React.createElement(Factors, _extends({}, conditionFactor, {
50
+ setSelectedFactorType: function setSelectedFactorType(factorType) {
51
+ return setStepConditionFactorType(stepId, conditionId, factorType);
52
+ },
53
+ onChangeValue: function onChangeValue(value) {
54
+ return setStepConditionFactorValue(stepId, conditionId, value);
55
+ },
56
+ factorKey: conditionId,
57
+ opened: stepId === currentStepId && conditionId === currentConditionId && currentField === FACTOR
58
+ })))), removeCondition && conditionsNumber > minConditionLength && React.createElement(S.RemoveIconWrapper, {
59
+ onClick: function onClick() {
60
+ return removeCondition(stepId, conditionId);
61
+ },
62
+ className: "ds-conditions-remove-row"
63
+ }, React.createElement(Tooltip, {
64
+ title: texts.removeConditionRowTooltip,
65
+ trigger: ['hover']
66
+ }, React.createElement(Icon, {
67
+ component: React.createElement(CloseS, null),
68
+ color: theme.palette['red-600']
69
+ }))));
70
+ };
@@ -0,0 +1,26 @@
1
+ import * as React from 'react';
2
+ import { FactorsProps } from '@synerise/ds-factors/dist/Factors.types';
3
+ import { OperatorsProps } from '@synerise/ds-operators/dist/Operator.types';
4
+ import { ConditionProps, ConditionTexts } from '../../Condition.types';
5
+ export declare type ConditionRowProps = {
6
+ index: number;
7
+ conditionId: React.ReactText;
8
+ addCondition: ConditionProps['addCondition'];
9
+ conditionParameter: FactorsProps;
10
+ conditionOperator: OperatorsProps;
11
+ conditionFactor: FactorsProps;
12
+ removeCondition: ConditionProps['removeCondition'];
13
+ minConditionLength: ConditionProps['minConditionsLength'];
14
+ maxConditionLength: ConditionProps['maxConditionsLength'];
15
+ conditionsNumber: number;
16
+ stepId: React.ReactText;
17
+ currentStepId: React.ReactText;
18
+ currentConditionId: React.ReactText;
19
+ currentField: React.ReactText;
20
+ selectParameter: ConditionProps['onChangeParameter'];
21
+ selectOperator: ConditionProps['onChangeOperator'];
22
+ setStepConditionFactorType: ConditionProps['onChangeFactorType'];
23
+ setStepConditionFactorValue: ConditionProps['onChangeFactorValue'];
24
+ texts: Partial<ConditionTexts>;
25
+ stepType: 'event' | 'attribute' | 'default' | undefined;
26
+ };
@@ -0,0 +1,2 @@
1
+ export * from './ConditionRow.types';
2
+ export * from './ConditionRow';
@@ -0,0 +1,2 @@
1
+ export * from './ConditionRow.types';
2
+ export * from './ConditionRow';
@@ -0,0 +1,3 @@
1
+ import * as React from 'react';
2
+ import * as T from './ConditionStep.types';
3
+ export declare const ConditionStep: React.FC<T.ConditionStepProps>;
@@ -0,0 +1,149 @@
1
+ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
+
3
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
4
+
5
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
6
+
7
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
8
+
9
+ import * as React from 'react';
10
+ import Subject from '@synerise/ds-subject';
11
+ import ContextSelector from '@synerise/ds-context-selector';
12
+ import { useIntl } from 'react-intl';
13
+ import * as S from '../Condition.style';
14
+ import { StepHeader } from './StepHeader';
15
+ import { AddCondition } from './AddCondition';
16
+ import { ConditionRow } from './ConditionRow'; // eslint-disable-next-line import/prefer-default-export
17
+
18
+ export var ConditionStep = function ConditionStep(_ref) {
19
+ var step = _ref.step,
20
+ texts = _ref.texts,
21
+ index = _ref.index,
22
+ addCondition = _ref.addCondition,
23
+ removeCondition = _ref.removeCondition,
24
+ updateStepName = _ref.updateStepName,
25
+ removeStep = _ref.removeStep,
26
+ duplicateStep = _ref.duplicateStep,
27
+ _ref$minConditionsLen = _ref.minConditionsLength,
28
+ minConditionsLength = _ref$minConditionsLen === void 0 ? 1 : _ref$minConditionsLen,
29
+ maxConditionsLength = _ref.maxConditionsLength,
30
+ draggableEnabled = _ref.draggableEnabled,
31
+ selectSubject = _ref.selectSubject,
32
+ selectContext = _ref.selectContext,
33
+ selectOperator = _ref.selectOperator,
34
+ selectParameter = _ref.selectParameter,
35
+ setStepConditionFactorType = _ref.setStepConditionFactorType,
36
+ setStepConditionFactorValue = _ref.setStepConditionFactorValue,
37
+ currentStepId = _ref.currentStepId,
38
+ currentConditionId = _ref.currentConditionId,
39
+ currentField = _ref.currentField;
40
+
41
+ var _useIntl = useIntl(),
42
+ formatMessage = _useIntl.formatMessage;
43
+
44
+ var text = React.useMemo(function () {
45
+ return _objectSpread({
46
+ stepNamePlaceholder: formatMessage({
47
+ id: 'DS.CONDITION.STEP_NAME-PLACEHOLDER',
48
+ defaultMessage: 'Step name'
49
+ }),
50
+ removeConditionRowTooltip: formatMessage({
51
+ id: 'DS.CONDITION.REMOVE-CONDITION-ROW-TOOLTIP',
52
+ defaultMessage: 'Delete'
53
+ }),
54
+ addConditionRowButton: formatMessage({
55
+ id: 'DS.CONDITION.ADD-CONDITION-ROW-BUTTON',
56
+ defaultMessage: 'Add condition'
57
+ }),
58
+ addFirstConditionRowButton: formatMessage({
59
+ id: 'DS.CONDITION.ADD-FIRST-CONDITION-ROW-BUTTON',
60
+ defaultMessage: 'Add condition'
61
+ }),
62
+ dropLabel: formatMessage({
63
+ id: 'DS.CONDITION.DROP-LABEL',
64
+ defaultMessage: 'Drop me here'
65
+ }),
66
+ moveTooltip: formatMessage({
67
+ id: 'DS.CONDITION.MOVE-TOOLTIP',
68
+ defaultMessage: 'Move'
69
+ }),
70
+ duplicateTooltip: formatMessage({
71
+ id: 'DS.CONDITION.DUPLICATE-TOOLTIP',
72
+ defaultMessage: 'Duplicate'
73
+ }),
74
+ removeTooltip: formatMessage({
75
+ id: 'DS.CONDITION.REMOVE-TOOLTIP',
76
+ defaultMessage: 'Delete'
77
+ }),
78
+ addStep: formatMessage({
79
+ id: 'DS.CONDITION.ADD-STEP',
80
+ defaultMessage: 'Add step'
81
+ })
82
+ }, texts);
83
+ }, [texts, formatMessage]);
84
+ var stepHeader = React.useMemo(function () {
85
+ return React.createElement(StepHeader, {
86
+ index: index,
87
+ stepId: step.id,
88
+ stepName: step.stepName || '',
89
+ texts: text,
90
+ updateStepName: updateStepName,
91
+ removeStep: removeStep,
92
+ duplicateStep: duplicateStep,
93
+ draggableEnabled: Boolean(draggableEnabled)
94
+ });
95
+ }, [draggableEnabled, duplicateStep, index, removeStep, step.id, step.stepName, text, updateStepName]);
96
+ var addConditionButton = React.useMemo(function () {
97
+ var _step$subject, _step$context;
98
+
99
+ return addCondition && (maxConditionsLength === undefined || step.conditions.length < maxConditionsLength) && React.createElement(AddCondition, {
100
+ texts: text,
101
+ stepId: step.id,
102
+ addCondition: addCondition,
103
+ conditionsNumber: step.conditions.length,
104
+ selectedSubject: Boolean((_step$subject = step.subject) === null || _step$subject === void 0 ? void 0 : _step$subject.selectedItem),
105
+ selectedContext: Boolean((_step$context = step.context) === null || _step$context === void 0 ? void 0 : _step$context.selectedItem)
106
+ });
107
+ }, [addCondition, maxConditionsLength, step.conditions.length, step.context, step.id, step.subject, text]);
108
+ var renderConditionRow = React.useCallback(function (condition, conditionIndex) {
109
+ var _step$context2;
110
+
111
+ return React.createElement(ConditionRow, {
112
+ key: "step-".concat(step.id, "-condition-").concat(condition.id),
113
+ index: conditionIndex,
114
+ conditionId: condition.id,
115
+ addCondition: addCondition,
116
+ conditionParameter: condition.parameter,
117
+ conditionOperator: condition.operator,
118
+ conditionFactor: condition.factor,
119
+ removeCondition: removeCondition,
120
+ minConditionLength: minConditionsLength,
121
+ maxConditionLength: maxConditionsLength,
122
+ conditionsNumber: step.conditions.length,
123
+ stepId: step.id,
124
+ currentStepId: currentStepId,
125
+ currentConditionId: currentConditionId,
126
+ currentField: currentField,
127
+ selectParameter: selectParameter,
128
+ selectOperator: selectOperator,
129
+ setStepConditionFactorType: setStepConditionFactorType,
130
+ setStepConditionFactorValue: setStepConditionFactorValue,
131
+ texts: text,
132
+ stepType: (_step$context2 = step.context) === null || _step$context2 === void 0 ? void 0 : _step$context2.type
133
+ });
134
+ }, [addCondition, currentConditionId, currentField, currentStepId, maxConditionsLength, minConditionsLength, removeCondition, selectOperator, selectParameter, setStepConditionFactorType, setStepConditionFactorValue, step.conditions.length, step.context, step.id, text]);
135
+ return React.createElement(S.Step, {
136
+ key: step.id,
137
+ "data-dropLabel": text.dropLabel
138
+ }, updateStepName && stepHeader, React.createElement(S.StepConditions, {
139
+ withoutStepName: updateStepName === undefined
140
+ }, React.createElement(S.Subject, null, step.subject && React.createElement(Subject, _extends({}, step.subject, {
141
+ onSelectItem: function onSelectItem(value) {
142
+ return selectSubject(value, step.id);
143
+ }
144
+ })), step.context && React.createElement(ContextSelector, _extends({}, step.context, {
145
+ onSelectItem: function onSelectItem(value) {
146
+ return selectContext(value, step.id);
147
+ }
148
+ }))), React.createElement(S.ConditionRows, null, step.conditions.length > 0 && step.conditions.map(renderConditionRow), addConditionButton)));
149
+ };
@@ -0,0 +1,28 @@
1
+ import * as React from 'react';
2
+ import { FactorType, FactorValueType } from '@synerise/ds-factors/dist/Factors.types';
3
+ import { ContextGroup, ContextItem } from '@synerise/ds-context-selector/dist/ContextSelector.types';
4
+ import { SubjectItem } from '@synerise/ds-subject/dist/Subject.types';
5
+ import { OperatorsGroup, OperatorsItem } from '@synerise/ds-operators/dist/Operator.types';
6
+ import { ConditionStep, ConditionTexts } from '../Condition.types';
7
+ export declare type ConditionStepProps = {
8
+ index: number;
9
+ step: ConditionStep;
10
+ addCondition?: (stepId: React.ReactText) => void;
11
+ removeCondition?: (stepId: React.ReactText, conditionRowId: React.ReactText) => void;
12
+ updateStepName?: (stepId: React.ReactText, value: string) => void;
13
+ removeStep?: (stepId: React.ReactText) => void;
14
+ duplicateStep?: (stepId: React.ReactText) => void;
15
+ texts?: Partial<ConditionTexts>;
16
+ minConditionsLength: number;
17
+ maxConditionsLength: number | undefined;
18
+ draggableEnabled?: boolean;
19
+ selectSubject: (value: SubjectItem, stepId: React.ReactText) => void;
20
+ selectContext: (value: ContextItem | ContextGroup | undefined, stepId: React.ReactText) => void;
21
+ selectParameter: (stepId: React.ReactText, condition: React.ReactText, value: FactorValueType | undefined) => void;
22
+ selectOperator: (stepId: React.ReactText, condition: React.ReactText, value: OperatorsItem | OperatorsGroup | undefined) => void;
23
+ setStepConditionFactorType: (stepId: React.ReactText, condition: React.ReactText, factorType: FactorType | undefined) => void;
24
+ setStepConditionFactorValue: (stepId: React.ReactText, condition: React.ReactText, value: FactorValueType) => void;
25
+ currentStepId: React.ReactText;
26
+ currentConditionId: React.ReactText;
27
+ currentField: React.ReactText;
28
+ };
File without changes
@@ -0,0 +1,3 @@
1
+ import * as React from 'react';
2
+ import * as T from './StepHeader.types';
3
+ export declare const StepHeader: React.FC<T.StepHeaderProps>;
@@ -0,0 +1,68 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+
3
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
+
5
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
6
+
7
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
8
+
9
+ function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
10
+
11
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
12
+
13
+ import InlineEdit from '@synerise/ds-inline-edit';
14
+ import * as React from 'react';
15
+ import Cruds from '@synerise/ds-cruds';
16
+ import { DragHandleM } from '@synerise/ds-icon/dist/icons';
17
+ import { NOOP } from '@synerise/ds-utils';
18
+ import { debounce } from 'lodash';
19
+ import * as S from '../../Condition.style';
20
+ // eslint-disable-next-line import/prefer-default-export
21
+ export var StepHeader = function StepHeader(_ref) {
22
+ var stepName = _ref.stepName,
23
+ stepId = _ref.stepId,
24
+ texts = _ref.texts,
25
+ _ref$updateStepName = _ref.updateStepName,
26
+ updateStepName = _ref$updateStepName === void 0 ? NOOP : _ref$updateStepName,
27
+ duplicateStep = _ref.duplicateStep,
28
+ removeStep = _ref.removeStep,
29
+ index = _ref.index,
30
+ draggableEnabled = _ref.draggableEnabled;
31
+ var onChangeNameDebounce = React.useCallback(debounce(updateStepName, 300), [updateStepName]);
32
+
33
+ var _React$useState = React.useState(stepName),
34
+ _React$useState2 = _slicedToArray(_React$useState, 2),
35
+ localName = _React$useState2[0],
36
+ setLocalName = _React$useState2[1];
37
+
38
+ React.useEffect(function () {
39
+ setLocalName(stepName);
40
+ }, [stepName]);
41
+ var handleChangeName = React.useCallback(function (event) {
42
+ setLocalName(event.target.value);
43
+ onChangeNameDebounce(stepId, event.target.value);
44
+ }, [onChangeNameDebounce, stepId]);
45
+ return React.createElement(S.StepHeader, null, updateStepName && React.createElement(S.StepName, null, "".concat(index + 1, "."), ' ', React.createElement(InlineEdit, {
46
+ size: "small",
47
+ input: {
48
+ value: localName,
49
+ name: "condition-step-name-".concat(stepId),
50
+ placeholder: texts.stepNamePlaceholder,
51
+ onChange: handleChangeName
52
+ }
53
+ })), React.createElement(S.StepCruds, null, draggableEnabled && React.createElement(Cruds.CustomAction, {
54
+ icon: React.createElement(DragHandleM, null),
55
+ title: texts.moveTooltip,
56
+ onClick: NOOP,
57
+ className: "step-drag-handler"
58
+ }), React.createElement(Cruds, {
59
+ onDuplicate: duplicateStep ? function () {
60
+ return duplicateStep(stepId);
61
+ } : undefined,
62
+ onDelete: removeStep ? function () {
63
+ return removeStep(stepId);
64
+ } : undefined,
65
+ duplicateTooltip: texts.duplicateTooltip,
66
+ deleteTooltip: texts.removeTooltip
67
+ })));
68
+ };
@@ -0,0 +1,12 @@
1
+ import * as React from 'react';
2
+ import { ConditionProps, ConditionTexts } from '../../Condition.types';
3
+ export declare type StepHeaderProps = {
4
+ index: number;
5
+ texts: Partial<ConditionTexts>;
6
+ stepName: string;
7
+ stepId: React.ReactText;
8
+ removeStep: ConditionProps['removeStep'];
9
+ duplicateStep: ConditionProps['duplicateStep'];
10
+ updateStepName: ConditionProps['onUpdateStepName'];
11
+ draggableEnabled: boolean;
12
+ };
@@ -0,0 +1,2 @@
1
+ export * from './StepHeader.types';
2
+ export * from './StepHeader';
@@ -0,0 +1,2 @@
1
+ export * from './StepHeader.types';
2
+ export * from './StepHeader';
@@ -0,0 +1,2 @@
1
+ export * from './ConditionStep.types';
2
+ export * from './ConditionStep';
@@ -0,0 +1,2 @@
1
+ export * from './ConditionStep.types';
2
+ export * from './ConditionStep';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synerise/ds-condition",
3
- "version": "0.9.1",
3
+ "version": "0.11.0",
4
4
  "description": "Condition UI Component for the Synerise Design System",
5
5
  "license": "ISC",
6
6
  "repository": "Synerise/synerise-design",
@@ -32,22 +32,22 @@
32
32
  ],
33
33
  "types": "dist/index.d.ts",
34
34
  "dependencies": {
35
- "@synerise/ds-button": "^0.13.66",
36
- "@synerise/ds-context-selector": "^0.6.4",
35
+ "@synerise/ds-button": "^0.15.0",
36
+ "@synerise/ds-context-selector": "^0.7.2",
37
37
  "@synerise/ds-core": "^0.30.14",
38
- "@synerise/ds-cruds": "^0.2.46",
39
- "@synerise/ds-factors": "^0.7.36",
38
+ "@synerise/ds-cruds": "^0.2.49",
39
+ "@synerise/ds-factors": "^0.9.0",
40
40
  "@synerise/ds-icon": "^0.36.0",
41
- "@synerise/ds-inline-edit": "^0.4.35",
42
- "@synerise/ds-operators": "^0.4.29",
43
- "@synerise/ds-subject": "^0.5.48",
44
- "@synerise/ds-tooltip": "^0.10.52",
45
- "@synerise/ds-utils": "^0.18.1",
41
+ "@synerise/ds-inline-edit": "^0.4.38",
42
+ "@synerise/ds-operators": "^0.5.2",
43
+ "@synerise/ds-subject": "^0.5.51",
44
+ "@synerise/ds-tooltip": "^0.10.55",
45
+ "@synerise/ds-utils": "^0.19.0",
46
46
  "react-sortablejs": "^6.0.0"
47
47
  },
48
48
  "peerDependencies": {
49
49
  "@synerise/ds-core": "*",
50
50
  "react": ">=16.9.0 < 17.0.0"
51
51
  },
52
- "gitHead": "78685caf9c9b72daabe890e18cb666eb17c8b724"
52
+ "gitHead": "1c362e630aa782b5a781724f0cb4f32a4a2b55bf"
53
53
  }