@synerise/ds-condition 0.14.0 → 0.15.1

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/CHANGELOG.md CHANGED
@@ -3,6 +3,66 @@
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.15.1](https://github.com/Synerise/synerise-design/compare/@synerise/ds-condition@0.15.0...@synerise/ds-condition@0.15.1) (2022-04-29)
7
+
8
+ **Note:** Version bump only for package @synerise/ds-condition
9
+
10
+
11
+
12
+
13
+
14
+ # [0.15.0](https://github.com/Synerise/synerise-design/compare/@synerise/ds-condition@0.14.4...@synerise/ds-condition@0.15.0) (2022-04-29)
15
+
16
+
17
+ ### Features
18
+
19
+ * **condition:** clearing active step on deactivating inner components ([ad45310](https://github.com/Synerise/synerise-design/commit/ad45310cde108e40b2b88c0a88bf801d679056db))
20
+
21
+
22
+
23
+
24
+
25
+ ## [0.14.4](https://github.com/Synerise/synerise-design/compare/@synerise/ds-condition@0.14.3...@synerise/ds-condition@0.14.4) (2022-04-13)
26
+
27
+
28
+ ### Bug Fixes
29
+
30
+ * **condition:** conditionally render addCondition renderProp ([78a3de7](https://github.com/Synerise/synerise-design/commit/78a3de75d8ec9c917d96c1b54c70d24f50dc8c7a))
31
+
32
+
33
+
34
+
35
+
36
+ ## [0.14.3](https://github.com/Synerise/synerise-design/compare/@synerise/ds-condition@0.14.2...@synerise/ds-condition@0.14.3) (2022-04-12)
37
+
38
+
39
+ ### Bug Fixes
40
+
41
+ * **condition:** rules-of-hooks dependencies ([10e573e](https://github.com/Synerise/synerise-design/commit/10e573e018ca7e2f69f3f317f35d51eace89ded8))
42
+
43
+
44
+
45
+
46
+
47
+ ## [0.14.2](https://github.com/Synerise/synerise-design/compare/@synerise/ds-condition@0.14.1...@synerise/ds-condition@0.14.2) (2022-04-12)
48
+
49
+
50
+ ### Bug Fixes
51
+
52
+ * fix filter dropdowns ([eaab107](https://github.com/Synerise/synerise-design/commit/eaab107b6dca7401a17c2e36806febd11edc677b))
53
+
54
+
55
+
56
+
57
+
58
+ ## [0.14.1](https://github.com/Synerise/synerise-design/compare/@synerise/ds-condition@0.14.0...@synerise/ds-condition@0.14.1) (2022-04-08)
59
+
60
+ **Note:** Version bump only for package @synerise/ds-condition
61
+
62
+
63
+
64
+
65
+
6
66
  # [0.14.0](https://github.com/Synerise/synerise-design/compare/@synerise/ds-condition@0.13.10...@synerise/ds-condition@0.14.0) (2022-04-05)
7
67
 
8
68
 
@@ -3,5 +3,6 @@ import * as T from './Condition.types';
3
3
  export declare const OPERATOR = "operator";
4
4
  export declare const PARAMETER = "parameter";
5
5
  export declare const FACTOR = "factor";
6
+ export declare const SUBJECT = "subject";
6
7
  declare const Condition: React.FC<T.ConditionProps>;
7
8
  export default Condition;
package/dist/Condition.js CHANGED
@@ -21,6 +21,7 @@ var DEFAULT_STEP = '';
21
21
  export var OPERATOR = 'operator';
22
22
  export var PARAMETER = 'parameter';
23
23
  export var FACTOR = 'factor';
24
+ export var SUBJECT = 'subject';
24
25
  var SORTABLE_CONFIG = {
25
26
  ghostClass: 'steps-list-ghost-element',
26
27
  className: 'steps-list',
@@ -38,6 +39,7 @@ var Condition = function Condition(props) {
38
39
  duplicateStep = props.duplicateStep,
39
40
  removeStep = props.removeStep,
40
41
  addStep = props.addStep,
42
+ renderAddStep = props.renderAddStep,
41
43
  onChangeOrder = props.onChangeOrder,
42
44
  _props$minConditionsL = props.minConditionsLength,
43
45
  minConditionsLength = _props$minConditionsL === void 0 ? 1 : _props$minConditionsL,
@@ -50,7 +52,8 @@ var Condition = function Condition(props) {
50
52
  onChangeFactorType = props.onChangeFactorType,
51
53
  onChangeFactorValue = props.onChangeFactorValue,
52
54
  onUpdateStepName = props.onUpdateStepName,
53
- getPopupContainerOverride = props.getPopupContainerOverride;
55
+ getPopupContainerOverride = props.getPopupContainerOverride,
56
+ showSuffix = props.showSuffix;
54
57
 
55
58
  var _useIntl = useIntl(),
56
59
  formatMessage = _useIntl.formatMessage;
@@ -60,6 +63,10 @@ var Condition = function Condition(props) {
60
63
  addStep: formatMessage({
61
64
  id: 'DS.CONDITION.ADD-STEP',
62
65
  defaultMessage: 'and then...'
66
+ }),
67
+ conditionSuffix: formatMessage({
68
+ id: 'DS.CONDITION.SUFFIX',
69
+ defaultMessage: 'and'
63
70
  })
64
71
  }, texts);
65
72
  }, [texts, formatMessage]);
@@ -76,10 +83,6 @@ var Condition = function Condition(props) {
76
83
  currentField = _React$useState3[0],
77
84
  setCurrentField = _React$useState3[1];
78
85
 
79
- var _React$useState4 = React.useState(null),
80
- priorityStepId = _React$useState4[0],
81
- setPriorityStepId = _React$useState4[1];
82
-
83
86
  var prevSteps = usePrevious(steps);
84
87
  React.useEffect(function () {
85
88
  var newConditionId = prevSteps && steps && steps.reduce(function (id, step) {
@@ -148,11 +151,13 @@ var Condition = function Condition(props) {
148
151
  var selectSubject = React.useCallback(function (value, stepId) {
149
152
  clearConditionRow(stepId);
150
153
  setCurrentStepId(stepId);
154
+ setCurrentField(PARAMETER);
151
155
  onChangeSubject && onChangeSubject(stepId, value);
152
156
  }, [clearConditionRow, onChangeSubject]);
153
157
  var selectContext = React.useCallback(function (value, stepId) {
154
158
  clearConditionRow(stepId);
155
159
  setCurrentStepId(stepId);
160
+ setCurrentField(PARAMETER);
156
161
  onChangeContext && onChangeContext(stepId, value);
157
162
  }, [clearConditionRow, onChangeContext]);
158
163
  var selectParameter = React.useCallback(function (stepId, conditionId, value) {
@@ -188,6 +193,34 @@ var Condition = function Condition(props) {
188
193
  var draggableEnabled = React.useMemo(function () {
189
194
  return onChangeOrder && steps.length > 1;
190
195
  }, [steps, onChangeOrder]);
196
+ var handleAddStep = React.useCallback(function () {
197
+ var newStepId = addStep ? addStep() : undefined;
198
+
199
+ if (newStepId) {
200
+ setCurrentStepId(newStepId);
201
+ setCurrentField(SUBJECT);
202
+ }
203
+ }, [addStep]);
204
+ var handleAddCondition = React.useMemo(function () {
205
+ if (!addCondition) {
206
+ return undefined;
207
+ }
208
+
209
+ return function (stepId) {
210
+ var newConditionId = addCondition ? addCondition(stepId) : undefined;
211
+
212
+ if (newConditionId) {
213
+ setCurrentConditionId(newConditionId);
214
+ setCurrentStepId(stepId);
215
+ setCurrentField(PARAMETER);
216
+ }
217
+ };
218
+ }, [addCondition]);
219
+ var handleClearActiveCondition = React.useCallback(function () {
220
+ setCurrentConditionId(DEFAULT_CONDITION);
221
+ setCurrentStepId(DEFAULT_STEP);
222
+ setCurrentField(DEFAULT_FIELD);
223
+ }, []);
191
224
  return React.useMemo(function () {
192
225
  return /*#__PURE__*/React.createElement(S.Condition, {
193
226
  className: "ds-conditions",
@@ -201,8 +234,7 @@ var Condition = function Condition(props) {
201
234
  step: step,
202
235
  texts: text,
203
236
  index: index,
204
- hasPriority: step.id === priorityStepId,
205
- onStepActivate: setPriorityStepId,
237
+ hasPriority: step.id === currentStepId,
206
238
  getPopupContainerOverride: getPopupContainerOverride,
207
239
  draggableEnabled: draggableEnabled,
208
240
  selectOperator: selectOperator,
@@ -220,17 +252,21 @@ var Condition = function Condition(props) {
220
252
  currentStepId: currentStepId,
221
253
  currentField: currentField,
222
254
  removeCondition: removeCondition,
223
- addCondition: addCondition,
224
- setCurrentField: setCurrentField
255
+ addCondition: handleAddCondition,
256
+ setCurrentField: setCurrentField,
257
+ setCurrentCondition: setCurrentConditionId,
258
+ setCurrentStep: setCurrentStepId,
259
+ onDeactivate: handleClearActiveCondition,
260
+ showSuffix: showSuffix
225
261
  });
226
262
  })), addStep && /*#__PURE__*/React.createElement(S.AddStepButton, null, /*#__PURE__*/React.createElement(Button, {
227
263
  type: "ghost",
228
264
  mode: "icon-label",
229
- onClick: addStep
265
+ onClick: handleAddStep
230
266
  }, /*#__PURE__*/React.createElement(Icon, {
231
267
  component: /*#__PURE__*/React.createElement(Add3M, null)
232
- }), text.addStep)));
233
- }, [steps, priorityStepId, setPriorityStepId, onChangeOrder, addStep, text, draggableEnabled, selectOperator, selectParameter, selectContext, selectSubject, onUpdateStepName, duplicateStep, removeStep, minConditionsLength, maxConditionsLength, setStepConditionFactorType, setStepConditionFactorValue, currentConditionId, currentStepId, currentField, removeCondition, addCondition, getPopupContainerOverride]);
268
+ }), text.addStep)), renderAddStep && /*#__PURE__*/React.createElement(S.AddStepButton, null, renderAddStep()));
269
+ }, [steps, onChangeOrder, addStep, handleAddStep, text, renderAddStep, currentStepId, getPopupContainerOverride, draggableEnabled, selectOperator, selectParameter, selectContext, selectSubject, onUpdateStepName, duplicateStep, removeStep, minConditionsLength, maxConditionsLength, setStepConditionFactorType, setStepConditionFactorValue, currentConditionId, currentField, removeCondition, handleAddCondition, handleClearActiveCondition, showSuffix]);
234
270
  };
235
271
 
236
272
  export default Condition;
@@ -1,4 +1,7 @@
1
1
  /// <reference types="react" />
2
+ import { ConditionRowProps } from './ConditionStep/ConditionRow';
3
+ export declare const DragIcon: import("styled-components").StyledComponent<import("react").FC<import("@synerise/ds-icon").IconProps>, any, {}, never>;
4
+ export declare const StepConditionCruds: import("styled-components").StyledComponent<import("react").FC<import("@synerise/ds-cruds/dist/Cruds.types").CrudsProps> & import("@synerise/ds-cruds/dist/Cruds.types").CrudsSubComponents, any, {}, never>;
2
5
  export declare const StepConditions: import("styled-components").StyledComponent<"div", any, {
3
6
  withoutStepName: boolean;
4
7
  }, never>;
@@ -6,19 +9,23 @@ export declare const StepName: import("styled-components").StyledComponent<"div"
6
9
  export declare const Condition: import("styled-components").StyledComponent<"div", any, {}, never>;
7
10
  export declare const ConditionStepWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
8
11
  export declare const And: import("styled-components").StyledComponent<"div", any, {}, never>;
9
- export declare const DragIcon: import("styled-components").StyledComponent<import("react").FC<import("@synerise/ds-icon").IconProps>, any, {}, never>;
10
12
  export declare const StepCruds: import("styled-components").StyledComponent<"div", any, {}, never>;
11
13
  export declare const LeftSide: import("styled-components").StyledComponent<"div", any, {}, never>;
12
- export declare const StepHeader: import("styled-components").StyledComponent<"div", any, {
13
- draggable: boolean;
14
+ export declare const StepHeader: import("styled-components").StyledComponent<"div", any, {}, never>;
15
+ export declare const DraggedLabel: import("styled-components").StyledComponent<"span", any, {}, never>;
16
+ export declare const Step: import("styled-components").StyledComponent<"div", any, {
17
+ active: boolean;
18
+ showSuffix: boolean | undefined;
19
+ }, never>;
20
+ export declare const ConditionWrapper: import("styled-components").StyledComponent<"div", any, {
21
+ fullWidth?: boolean | undefined;
14
22
  }, never>;
15
- export declare const Step: import("styled-components").StyledComponent<"div", any, {}, never>;
16
- export declare const ConditionWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
17
23
  export declare const Subject: import("styled-components").StyledComponent<"div", any, {}, never>;
18
24
  export declare const RemoveIconWrapper: import("styled-components").StyledComponent<"span", any, {}, never>;
19
25
  export declare const ConditionRows: import("styled-components").StyledComponent<"div", any, {}, never>;
20
26
  export declare const ConditionRow: import("styled-components").StyledComponent<"div", any, {
21
27
  index: number;
28
+ stepType: ConditionRowProps['stepType'];
22
29
  }, never>;
23
30
  export declare const AddConditionRow: import("styled-components").StyledComponent<"div", any, {}, never>;
24
31
  export declare const ConditionConnections: import("styled-components").StyledComponent<"span", any, {
@@ -1,92 +1,107 @@
1
- import styled from 'styled-components';
1
+ import styled, { css } from 'styled-components';
2
2
  import { IconWrapper } from '@synerise/ds-inline-edit/dist/InlineEdit.styles';
3
3
  import Icon from '@synerise/ds-icon';
4
+ import Cruds from '@synerise/ds-cruds';
5
+ export var DragIcon = styled(Icon).withConfig({
6
+ displayName: "Conditionstyle__DragIcon",
7
+ componentId: "sc-1lk06p3-0"
8
+ })(["opacity:0;visibility:hidden;position:absolute;top:0;left:-24px;cursor:grab;"]);
9
+ export var StepConditionCruds = styled(Cruds).withConfig({
10
+ displayName: "Conditionstyle__StepConditionCruds",
11
+ componentId: "sc-1lk06p3-1"
12
+ })(["position:absolute;top:16px;right:24px;visibility:hidden;opacity:0;"]);
4
13
  export var StepConditions = styled.div.withConfig({
5
14
  displayName: "Conditionstyle__StepConditions",
6
- componentId: "sc-1lk06p3-0"
7
- })(["display:flex;flex-direction:row;align-items:flex-start;justify-content:flex-start;margin-top:0;padding:0 24px;width:100%;"]);
15
+ componentId: "sc-1lk06p3-2"
16
+ })(["display:flex;flex-direction:row;align-items:flex-start;justify-content:flex-start;margin-top:0;padding:0 24px;width:", ";", "{left:0;top:16px;}"], function (props) {
17
+ return props.withoutStepName ? 'calc(100% - 48px)' : '100%';
18
+ }, DragIcon);
8
19
  export var StepName = styled.div.withConfig({
9
20
  displayName: "Conditionstyle__StepName",
10
- componentId: "sc-1lk06p3-1"
21
+ componentId: "sc-1lk06p3-3"
11
22
  })(["font-size:13px;line-height:1.84;color:", ";display:flex;flex-direction:row;align-items:center;justify-content:flex-start;white-space:pre-wrap;&&& input{margin-top:2px;cursor:default;}"], function (props) {
12
23
  return props.theme.palette['grey-800'];
13
24
  });
14
25
  export var Condition = styled.div.withConfig({
15
26
  displayName: "Conditionstyle__Condition",
16
- componentId: "sc-1lk06p3-2"
27
+ componentId: "sc-1lk06p3-4"
17
28
  })(["padding:12px 0;display:flex;flex-direction:column;align-items:flex-start;justify-content:flex-start;min-width:575px;width:100%;.steps-list{width:100%;}"]);
18
29
  export var ConditionStepWrapper = styled.div.withConfig({
19
30
  displayName: "Conditionstyle__ConditionStepWrapper",
20
- componentId: "sc-1lk06p3-3"
31
+ componentId: "sc-1lk06p3-5"
21
32
  })(["display:flex;align-items:flex-start;justify-content:flex-start;flex-direction:column;width:100%;"]);
22
33
  export var And = styled.div.withConfig({
23
34
  displayName: "Conditionstyle__And",
24
- componentId: "sc-1lk06p3-4"
25
- })([""]);
26
- export var DragIcon = styled(Icon).withConfig({
27
- displayName: "Conditionstyle__DragIcon",
28
- componentId: "sc-1lk06p3-5"
29
- })(["opacity:0;visibility:hidden;position:absolute;top:0;left:-24px;"]);
35
+ componentId: "sc-1lk06p3-6"
36
+ })(["display:contents;"]);
30
37
  export var StepCruds = styled.div.withConfig({
31
38
  displayName: "Conditionstyle__StepCruds",
32
- componentId: "sc-1lk06p3-6"
39
+ componentId: "sc-1lk06p3-7"
33
40
  })(["display:flex;align-items:center;justify-content:flex-end;opacity:0;visibility:hidden;"]);
34
41
  export var LeftSide = styled.div.withConfig({
35
42
  displayName: "Conditionstyle__LeftSide",
36
- componentId: "sc-1lk06p3-7"
43
+ componentId: "sc-1lk06p3-8"
37
44
  })(["display:flex;flex-direction:row;align-items:center;justify-content:flex-start;position:relative;"]);
38
45
  export var StepHeader = styled.div.withConfig({
39
46
  displayName: "Conditionstyle__StepHeader",
40
- componentId: "sc-1lk06p3-8"
41
- })(["display:flex;width:100%;flex-direction:row;align-items:flex-end;justify-content:space-between;margin-bottom:8px;padding:12px 24px 0;cursor:", ";"], function (props) {
42
- return props.draggable ? 'grab' : 'default';
47
+ componentId: "sc-1lk06p3-9"
48
+ })(["display:flex;width:100%;flex-direction:row;align-items:flex-end;justify-content:space-between;margin-bottom:8px;padding:0 24px;"]);
49
+ export var DraggedLabel = styled.span.withConfig({
50
+ displayName: "Conditionstyle__DraggedLabel",
51
+ componentId: "sc-1lk06p3-10"
52
+ })(["width:100%;height:100%;display:none;position:absolute;top:0;left:0;align-items:center;justify-content:flex-start;padding-left:18px;color:", ";font-size:13px;"], function (props) {
53
+ return props.theme.palette['grey-600'];
43
54
  });
44
55
  export var Step = styled.div.withConfig({
45
56
  displayName: "Conditionstyle__Step",
46
- componentId: "sc-1lk06p3-9"
47
- })(["display:flex;flex-direction:column;align-items:flex-start;justify-content:flex-start;padding:0 0 12px;position:relative;&:first-of-type{&.steps-list-ghost-element{&:after{display:none;}}}&:hover{background-color:", ";", "{opacity:1;visibility:visible;}", "{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-left:2px solid ", ";border-radius:0;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) {
57
+ componentId: "sc-1lk06p3-11"
58
+ })(["display:flex;flex-direction:column;align-items:flex-start;justify-content:flex-start;padding:12px 0 12px;position:relative;", " &:first-of-type{&.steps-list-ghost-element{&:after{display:none;}}}background-color:", ";&:hover{background-color:", ";", "{opacity:1;visibility:visible;}", "{opacity:1;visibility:visible;}", "{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;&:after{display:none;}", "{align-items:center;}", "{margin:0;", "{display:none;}}", "{display:none;}", "{display:flex;}}&.steps-list-ghost-element{cursor:grabbing;width:100%;background-color:", ";border-left:2px solid ", ";border-radius:0;display:flex;align-items:center;justify-content:center;padding:0;height:50px;box-shadow:none;position:relative;&:before{content:attr(data-dropLabel);text-align:center;position:relative;color:", ";}", "{display:none;}*{display:none;}}}"], function (props) {
59
+ return Boolean(props.showSuffix) && css(["&:after{display:none;width:100%;padding:18px 0 18px 24px;bottom:-18px;content:attr(data-conditionSuffix);background-color:", ";position:relative;font-size:16px;font-weight:500;color:#3f4c5b;}&:first-child:not(:last-child){&:after{display:flex;}}&:not(:last-child){&:after{display:flex;}}"], props.theme.palette.white);
60
+ }, function (props) {
61
+ return props.active ? props.theme.palette['grey-050'] : 'transparent';
62
+ }, function (props) {
48
63
  return props.theme.palette['grey-050'];
49
- }, StepCruds, DragIcon, function (props) {
64
+ }, StepCruds, StepConditionCruds, DragIcon, function (props) {
50
65
  return props.theme.palette.white;
51
- }, StepHeader, StepName, IconWrapper, StepConditions, function (props) {
66
+ }, StepHeader, StepName, IconWrapper, StepConditions, DraggedLabel, function (props) {
52
67
  return props.theme.palette['blue-050'];
53
68
  }, function (props) {
54
69
  return props.theme.palette['blue-600'];
55
- }, function (props) {
56
- return props.theme.palette['grey-300'];
57
70
  }, function (props) {
58
71
  return props.theme.palette['blue-600'];
59
- });
72
+ }, DraggedLabel);
60
73
  export var ConditionWrapper = styled.div.withConfig({
61
74
  displayName: "Conditionstyle__ConditionWrapper",
62
- componentId: "sc-1lk06p3-10"
75
+ componentId: "sc-1lk06p3-12"
63
76
  })([""]);
64
77
  export var Subject = styled.div.withConfig({
65
78
  displayName: "Conditionstyle__Subject",
66
- componentId: "sc-1lk06p3-11"
79
+ componentId: "sc-1lk06p3-13"
67
80
  })([""]);
68
81
  export var RemoveIconWrapper = styled.span.withConfig({
69
82
  displayName: "Conditionstyle__RemoveIconWrapper",
70
- componentId: "sc-1lk06p3-12"
83
+ componentId: "sc-1lk06p3-14"
71
84
  })(["visibility:hidden;pointer-events:none;opacity:0;transition:all 0.3s ease;width:32px;height:32px;display:flex;align-items:center;justify-content:center;margin-left:8px;"]);
72
85
  export var ConditionRows = styled.div.withConfig({
73
86
  displayName: "Conditionstyle__ConditionRows",
74
- componentId: "sc-1lk06p3-13"
87
+ componentId: "sc-1lk06p3-15"
75
88
  })(["display:flex;align-items:flex-start;justify-content:flex-start;flex-direction:column;"]);
76
89
  export var ConditionRow = styled.div.withConfig({
77
90
  displayName: "Conditionstyle__ConditionRow",
78
- componentId: "sc-1lk06p3-14"
79
- })(["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) {
91
+ componentId: "sc-1lk06p3-16"
92
+ })(["display:flex;flex-direction:row;align-items:flex-start;justify-content:flex-start;padding-bottom:", ";z-index:", ";", "{margin-right:8px;&:last-of-type{margin-right:0;}}&:hover{", "{opacity:1;visibility:visible;pointer-events:all;cursor:pointer;}}"], function (props) {
93
+ return props.stepType === 'event' ? '16px' : '0';
94
+ }, function (props) {
80
95
  return 10000 - props.index;
81
96
  }, ConditionWrapper, RemoveIconWrapper);
82
97
  export var AddConditionRow = styled.div.withConfig({
83
98
  displayName: "Conditionstyle__AddConditionRow",
84
- componentId: "sc-1lk06p3-15"
99
+ componentId: "sc-1lk06p3-17"
85
100
  })(["display:flex;align-items:flex-start;justify-content:flex-start;flex-direction:row;"]);
86
101
  export var ConditionConnections = styled.span.withConfig({
87
102
  displayName: "Conditionstyle__ConditionConnections",
88
- componentId: "sc-1lk06p3-16"
89
- })(["display:flex;width:32px;margin:0 12px;position:relative;height:32px;&:before{position:absolute;content:'';width:", ";height:1px;top:50%;left:", ";background-color:", ";}&:after{display:", ";position:absolute;content:'';width:1px;left:50%;height:auto;top:", ";bottom:", ";background-color:", ";}"], function (props) {
103
+ componentId: "sc-1lk06p3-18"
104
+ })(["display:flex;width:32px;min-width:32px;margin:0 12px;position:relative;height:32px;&:before{position:absolute;content:'';width:", ";height:1px;top:50%;left:", ";background-color:", ";}&:after{display:", ";position:absolute;content:'';width:1px;left:50%;height:auto;top:", ";bottom:", ";background-color:", ";}"], function (props) {
90
105
  return props.first ? '100%' : '16px';
91
106
  }, function (props) {
92
107
  return props.first ? '0' : '16px';
@@ -103,5 +118,5 @@ export var ConditionConnections = styled.span.withConfig({
103
118
  });
104
119
  export var AddStepButton = styled.div.withConfig({
105
120
  displayName: "Conditionstyle__AddStepButton",
106
- componentId: "sc-1lk06p3-17"
121
+ componentId: "sc-1lk06p3-19"
107
122
  })(["margin:12px 24px 0;"]);
@@ -26,15 +26,17 @@ export declare type ConditionTexts = {
26
26
  moveTooltip: string;
27
27
  duplicateTooltip: string;
28
28
  removeTooltip: string;
29
+ conditionSuffix: string;
29
30
  };
30
31
  export declare type ConditionProps = {
31
32
  steps: ConditionStep[];
32
33
  getPopupContainerOverride?: (trigger: HTMLElement | null) => HTMLElement;
33
- addCondition?: (stepId: React.ReactText) => void;
34
+ addCondition?: (stepId: React.ReactText) => string | undefined;
35
+ renderAddStep?: () => React.ReactNode;
34
36
  removeCondition?: (stepId: React.ReactText, conditionRowId: React.ReactText) => void;
35
37
  removeStep?: (stepId: React.ReactText) => void;
36
38
  duplicateStep?: (stepId: React.ReactText) => void;
37
- addStep?: () => void;
39
+ addStep?: () => string | undefined;
38
40
  onChangeOrder?: (newOrder: ConditionStep[]) => void;
39
41
  texts?: Partial<ConditionTexts>;
40
42
  minConditionsLength: number;
@@ -48,4 +50,5 @@ export declare type ConditionProps = {
48
50
  onChangeFactorType: (stepId: React.ReactText, conditionId: React.ReactText, value: FactorType | undefined) => void;
49
51
  onUpdateStepName?: (stepId: React.ReactText, value: string) => void;
50
52
  type?: 'attribute' | 'event';
53
+ showSuffix?: boolean;
51
54
  };
@@ -1,7 +1,7 @@
1
- /// <reference types="react" />
2
- import { ConditionProps, ConditionTexts } from '../../Condition.types';
1
+ import * as React from 'react';
2
+ import { ConditionTexts } from '../../Condition.types';
3
3
  export declare type AddConditionProps = {
4
- addCondition: ConditionProps['addCondition'];
4
+ addCondition: (stepId: React.ReactText) => void;
5
5
  stepId: React.ReactText;
6
6
  conditionsNumber: number;
7
7
  texts: Partial<ConditionTexts>;
@@ -31,8 +31,11 @@ export var ConditionRow = function ConditionRow(_ref) {
31
31
  getPopupContainerOverride = _ref.getPopupContainerOverride,
32
32
  _onActivate = _ref.onActivate,
33
33
  hasPriority = _ref.hasPriority,
34
- texts = _ref.texts;
34
+ texts = _ref.texts,
35
+ stepType = _ref.stepType,
36
+ onDeactivate = _ref.onDeactivate;
35
37
  return /*#__PURE__*/React.createElement(S.ConditionRow, {
38
+ stepType: stepType,
36
39
  style: hasPriority ? {
37
40
  zIndex: 10001
38
41
  } : undefined,
@@ -46,24 +49,29 @@ export var ConditionRow = function ConditionRow(_ref) {
46
49
  onActivate: function onActivate() {
47
50
  return _onActivate && _onActivate(PARAMETER);
48
51
  },
52
+ onDeactivate: onDeactivate,
49
53
  onChangeValue: function onChangeValue(value) {
50
54
  return selectParameter(stepId, conditionId, value);
51
55
  },
52
- opened: stepId === currentStepId && conditionId === currentConditionId && currentField === PARAMETER
56
+ opened: hasPriority && stepId === currentStepId && conditionId === currentConditionId && currentField === PARAMETER
53
57
  }))), (!conditionParameter || (conditionParameter == null ? void 0 : conditionParameter.value) && (conditionParameter == null ? void 0 : conditionParameter.value).name !== '') && conditionOperator && /*#__PURE__*/React.createElement(S.ConditionWrapper, null, /*#__PURE__*/React.createElement(Operators, _extends({}, conditionOperator, {
54
58
  getPopupContainerOverride: getPopupContainerOverride,
55
59
  onActivate: function onActivate() {
56
60
  return _onActivate && _onActivate(OPERATOR);
57
61
  },
62
+ onDeactivate: onDeactivate,
58
63
  onChange: function onChange(value) {
59
64
  return selectOperator(stepId, conditionId, value);
60
65
  },
61
- opened: stepId === currentStepId && conditionId === currentConditionId && currentField === OPERATOR
62
- }))), conditionFactor !== undefined && (conditionOperator == null ? void 0 : conditionOperator.value) && (conditionFactor == null ? void 0 : conditionFactor.availableFactorTypes) !== null && /*#__PURE__*/React.createElement(S.ConditionWrapper, null, /*#__PURE__*/React.createElement(React.Fragment, null, (conditionFactor == null ? void 0 : conditionFactor.withCustomFactor) || /*#__PURE__*/React.createElement(Factors, _extends({}, conditionFactor, {
66
+ opened: hasPriority && stepId === currentStepId && conditionId === currentConditionId && currentField === OPERATOR
67
+ }))), conditionFactor !== undefined && (conditionOperator == null ? void 0 : conditionOperator.value) && (conditionFactor == null ? void 0 : conditionFactor.availableFactorTypes) !== null && /*#__PURE__*/React.createElement(S.ConditionWrapper, {
68
+ fullWidth: true
69
+ }, /*#__PURE__*/React.createElement(React.Fragment, null, (conditionFactor == null ? void 0 : conditionFactor.withCustomFactor) || /*#__PURE__*/React.createElement(Factors, _extends({}, conditionFactor, {
63
70
  getPopupContainerOverride: getPopupContainerOverride,
64
71
  onActivate: function onActivate() {
65
72
  return _onActivate && _onActivate(FACTOR);
66
73
  },
74
+ onDeactivate: onDeactivate,
67
75
  setSelectedFactorType: function setSelectedFactorType(factorType) {
68
76
  return setStepConditionFactorType(stepId, conditionId, factorType);
69
77
  },
@@ -71,7 +79,7 @@ export var ConditionRow = function ConditionRow(_ref) {
71
79
  return setStepConditionFactorValue(stepId, conditionId, value);
72
80
  },
73
81
  factorKey: conditionId,
74
- opened: stepId === currentStepId && conditionId === currentConditionId && currentField === FACTOR
82
+ opened: hasPriority && stepId === currentStepId && conditionId === currentConditionId && currentField === FACTOR
75
83
  })))), removeCondition && conditionsNumber > minConditionLength && /*#__PURE__*/React.createElement(S.RemoveIconWrapper, {
76
84
  onClick: function onClick() {
77
85
  return removeCondition(stepId, conditionId);
@@ -6,8 +6,9 @@ export declare type ConditionRowProps = {
6
6
  index: number;
7
7
  hasPriority?: boolean;
8
8
  onActivate?: (fieldType: string) => void;
9
+ onDeactivate?: () => void;
9
10
  conditionId: React.ReactText;
10
- addCondition: ConditionProps['addCondition'];
11
+ addCondition?: (stepId: React.ReactText) => void;
11
12
  conditionParameter: FactorsProps;
12
13
  conditionOperator: OperatorsProps;
13
14
  conditionFactor: FactorsProps;
@@ -10,12 +10,16 @@ import * as React from 'react';
10
10
  import Subject from '@synerise/ds-subject';
11
11
  import ContextSelector from '@synerise/ds-context-selector';
12
12
  import { useIntl } from 'react-intl';
13
+ import { DragHandleM } from '@synerise/ds-icon';
13
14
  import * as S from '../Condition.style';
14
15
  import { StepHeader } from './StepHeader';
15
16
  import { AddCondition } from './AddCondition';
16
- import { ConditionRow } from './ConditionRow'; // eslint-disable-next-line import/prefer-default-export
17
+ import { ConditionRow } from './ConditionRow';
18
+ import { SUBJECT } from '../Condition'; // eslint-disable-next-line import/prefer-default-export
17
19
 
18
20
  export var ConditionStep = function ConditionStep(_ref) {
21
+ var _step$subject2, _step$subject2$select, _step$context3, _step$context3$select;
22
+
19
23
  var step = _ref.step,
20
24
  texts = _ref.texts,
21
25
  index = _ref.index,
@@ -35,16 +39,15 @@ export var ConditionStep = function ConditionStep(_ref) {
35
39
  setStepConditionFactorType = _ref.setStepConditionFactorType,
36
40
  setStepConditionFactorValue = _ref.setStepConditionFactorValue,
37
41
  getPopupContainerOverride = _ref.getPopupContainerOverride,
38
- onStepActivate = _ref.onStepActivate,
39
42
  hasPriority = _ref.hasPriority,
40
43
  currentStepId = _ref.currentStepId,
41
44
  currentConditionId = _ref.currentConditionId,
42
45
  currentField = _ref.currentField,
43
- setCurrentField = _ref.setCurrentField;
44
-
45
- var _React$useState = React.useState(null),
46
- activeConditionId = _React$useState[0],
47
- setActiveConditionId = _React$useState[1];
46
+ setCurrentField = _ref.setCurrentField,
47
+ setCurrentCondition = _ref.setCurrentCondition,
48
+ setCurrentStep = _ref.setCurrentStep,
49
+ onDeactivate = _ref.onDeactivate,
50
+ showSuffix = _ref.showSuffix;
48
51
 
49
52
  var _useIntl = useIntl(),
50
53
  formatMessage = _useIntl.formatMessage;
@@ -86,11 +89,15 @@ export var ConditionStep = function ConditionStep(_ref) {
86
89
  addStep: formatMessage({
87
90
  id: 'DS.CONDITION.ADD-STEP',
88
91
  defaultMessage: 'Add step'
92
+ }),
93
+ conditionSuffix: formatMessage({
94
+ id: 'DS.CONDITION.SUFFIX',
95
+ defaultMessage: 'and'
89
96
  })
90
97
  }, texts);
91
98
  }, [texts, formatMessage]);
92
- var onActivate = onStepActivate ? function () {
93
- return onStepActivate(step.id);
99
+ var onActivate = setCurrentStep ? function () {
100
+ return setCurrentStep(step.id);
94
101
  } : undefined;
95
102
  var onAddCondition = React.useCallback(function (stepId) {
96
103
  addCondition && addCondition(stepId);
@@ -125,15 +132,16 @@ export var ConditionStep = function ConditionStep(_ref) {
125
132
 
126
133
  var handleActivation = function handleActivation(conditionId) {
127
134
  return function (fieldType) {
128
- setActiveConditionId(conditionId);
129
135
  onActivate && onActivate();
130
136
  setCurrentField && setCurrentField(fieldType);
137
+ setCurrentCondition && setCurrentCondition(conditionId);
138
+ setCurrentStep && setCurrentStep(step.id);
131
139
  };
132
140
  };
133
141
 
134
142
  return /*#__PURE__*/React.createElement(ConditionRow, {
135
143
  key: "step-" + step.id + "-condition-" + condition.id,
136
- hasPriority: hasPriority && activeConditionId === condition.id,
144
+ hasPriority: hasPriority && currentConditionId === condition.id,
137
145
  index: conditionIndex,
138
146
  conditionId: condition.id,
139
147
  addCondition: addCondition,
@@ -157,29 +165,49 @@ export var ConditionStep = function ConditionStep(_ref) {
157
165
  setStepConditionFactorType: setStepConditionFactorType,
158
166
  setStepConditionFactorValue: setStepConditionFactorValue,
159
167
  texts: text,
160
- stepType: (_step$context2 = step.context) == null ? void 0 : _step$context2.type
168
+ stepType: (_step$context2 = step.context) == null ? void 0 : _step$context2.type,
169
+ onDeactivate: onDeactivate
161
170
  });
162
- }, [step.id, step.conditions.length, step.context, hasPriority, activeConditionId, addCondition, removeCondition, minConditionsLength, maxConditionsLength, currentStepId, currentConditionId, currentField, selectParameter, selectOperator, getPopupContainerOverride, setStepConditionFactorType, setStepConditionFactorValue, text, onActivate, setCurrentField]);
171
+ }, [step.id, step.conditions.length, step.context, hasPriority, currentConditionId, addCondition, removeCondition, minConditionsLength, maxConditionsLength, currentStepId, currentField, selectParameter, selectOperator, getPopupContainerOverride, setStepConditionFactorType, setStepConditionFactorValue, text, onDeactivate, onActivate, setCurrentField, setCurrentCondition, setCurrentStep]);
163
172
  return /*#__PURE__*/React.createElement(S.Step, {
164
173
  key: step.id,
165
174
  id: "condition-step-" + step.id,
166
175
  "data-dropLabel": text.dropLabel,
176
+ "data-conditionSuffix": text.conditionSuffix,
167
177
  style: hasPriority ? {
168
178
  zIndex: 10001
169
- } : undefined
170
- }, updateStepName && stepHeader, /*#__PURE__*/React.createElement(S.StepConditions, {
179
+ } : undefined,
180
+ active: step.id === currentStepId && currentField !== '',
181
+ showSuffix: showSuffix
182
+ }, !updateStepName && /*#__PURE__*/React.createElement(S.DraggedLabel, null, ((_step$subject2 = step.subject) == null ? void 0 : (_step$subject2$select = _step$subject2.selectedItem) == null ? void 0 : _step$subject2$select.name) || ((_step$context3 = step.context) == null ? void 0 : (_step$context3$select = _step$context3.selectedItem) == null ? void 0 : _step$context3$select.name)), updateStepName && stepHeader, /*#__PURE__*/React.createElement(S.StepConditions, {
171
183
  withoutStepName: updateStepName === undefined
172
- }, /*#__PURE__*/React.createElement(S.Subject, null, step.subject && /*#__PURE__*/React.createElement(Subject, _extends({}, step.subject, {
184
+ }, draggableEnabled && !updateStepName && /*#__PURE__*/React.createElement(S.DragIcon, {
185
+ className: "step-drag-handler",
186
+ component: /*#__PURE__*/React.createElement(DragHandleM, null)
187
+ }), /*#__PURE__*/React.createElement(S.Subject, null, step.subject && /*#__PURE__*/React.createElement(Subject, _extends({}, step.subject, {
173
188
  getPopupContainerOverride: getPopupContainerOverride,
174
189
  onActivate: onActivate,
190
+ onDeactivate: onDeactivate,
191
+ opened: step.id === currentStepId && currentField === SUBJECT,
175
192
  onSelectItem: function onSelectItem(value) {
176
193
  return selectSubject(value, step.id);
177
194
  }
178
195
  })), step.context && /*#__PURE__*/React.createElement(ContextSelector, _extends({}, step.context, {
179
196
  getPopupContainerOverride: getPopupContainerOverride,
180
197
  onActivate: onActivate,
198
+ onDeactivate: onDeactivate,
199
+ opened: step.id === currentStepId && currentField === SUBJECT,
181
200
  onSelectItem: function onSelectItem(value) {
182
201
  return selectContext(value, step.id);
183
202
  }
184
- }))), /*#__PURE__*/React.createElement(S.ConditionRows, null, step.conditions.length > 0 && step.conditions.map(renderConditionRow), addConditionButton)));
203
+ }))), /*#__PURE__*/React.createElement(S.ConditionRows, null, step.conditions.length > 0 && step.conditions.map(renderConditionRow), addConditionButton), !updateStepName && /*#__PURE__*/React.createElement(S.StepConditionCruds, {
204
+ onDuplicate: duplicateStep ? function () {
205
+ return duplicateStep(step.id);
206
+ } : undefined,
207
+ onDelete: removeStep ? function () {
208
+ return removeStep(step.id);
209
+ } : undefined,
210
+ duplicateTooltip: text.duplicateTooltip,
211
+ deleteTooltip: text.removeTooltip
212
+ })));
185
213
  };
@@ -29,4 +29,8 @@ export declare type ConditionStepProps = {
29
29
  currentConditionId: React.ReactText;
30
30
  currentField: React.ReactText;
31
31
  setCurrentField: (field: string) => void;
32
+ setCurrentCondition: (conditionId: string) => void;
33
+ setCurrentStep: (stepId: React.ReactText) => void;
34
+ onDeactivate: () => void;
35
+ showSuffix?: boolean;
32
36
  };
@@ -29,11 +29,12 @@ export var StepHeader = function StepHeader(_ref) {
29
29
  onChangeNameDebounce(stepId, event.target.value);
30
30
  }, [onChangeNameDebounce, stepId]);
31
31
  return /*#__PURE__*/React.createElement(S.StepHeader, {
32
- className: "step-drag-handler",
32
+ className: "ds-condition-step-header",
33
33
  draggable: draggableEnabled
34
34
  }, /*#__PURE__*/React.createElement(S.LeftSide, null, draggableEnabled && /*#__PURE__*/React.createElement(S.DragIcon, {
35
+ className: "step-drag-handler",
35
36
  component: /*#__PURE__*/React.createElement(DragHandleM, null)
36
- }), updateStepName && /*#__PURE__*/React.createElement(S.StepName, {
37
+ }), /*#__PURE__*/React.createElement(S.StepName, {
37
38
  className: "ds-condition-step-name"
38
39
  }, "" + (index + 1), ' ', /*#__PURE__*/React.createElement(InlineEdit, {
39
40
  size: "small",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synerise/ds-condition",
3
- "version": "0.14.0",
3
+ "version": "0.15.1",
4
4
  "description": "Condition UI Component for the Synerise Design System",
5
5
  "license": "ISC",
6
6
  "repository": "Synerise/synerise-design",
@@ -33,14 +33,14 @@
33
33
  "types": "dist/index.d.ts",
34
34
  "dependencies": {
35
35
  "@synerise/ds-button": "^0.17.2",
36
- "@synerise/ds-context-selector": "^0.11.0",
37
- "@synerise/ds-core": "^0.33.0",
36
+ "@synerise/ds-context-selector": "^0.12.1",
37
+ "@synerise/ds-core": "^0.34.0",
38
38
  "@synerise/ds-cruds": "^0.3.9",
39
- "@synerise/ds-factors": "^0.12.0",
39
+ "@synerise/ds-factors": "^0.13.1",
40
40
  "@synerise/ds-icon": "^0.49.0",
41
- "@synerise/ds-inline-edit": "^0.6.10",
42
- "@synerise/ds-operators": "^0.8.0",
43
- "@synerise/ds-subject": "^0.8.0",
41
+ "@synerise/ds-inline-edit": "^0.6.12",
42
+ "@synerise/ds-operators": "^0.9.0",
43
+ "@synerise/ds-subject": "^0.9.0",
44
44
  "@synerise/ds-tooltip": "^0.11.9",
45
45
  "@synerise/ds-utils": "^0.19.0",
46
46
  "react-sortablejs": "^6.0.0"
@@ -49,5 +49,5 @@
49
49
  "@synerise/ds-core": "*",
50
50
  "react": ">=16.9.0 < 17.0.0"
51
51
  },
52
- "gitHead": "5793ce09feb88b36cc8ca1923ddfcb272b889cb0"
52
+ "gitHead": "21879cf06623fe6e1c2523ebf7c055ab9dbd50ef"
53
53
  }