@synerise/ds-condition 0.16.0 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
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.17.0](https://github.com/Synerise/synerise-design/compare/@synerise/ds-condition@0.16.0...@synerise/ds-condition@0.17.0) (2022-05-28)
7
+
8
+
9
+ ### Features
10
+
11
+ * **condition:** validation condition ([b8d9e62](https://github.com/Synerise/synerise-design/commit/b8d9e627f2d62113abc4716d4049c2e27ad49718))
12
+
13
+
14
+
15
+
16
+
6
17
  # [0.16.0](https://github.com/Synerise/synerise-design/compare/@synerise/ds-condition@0.15.1...@synerise/ds-condition@0.16.0) (2022-05-13)
7
18
 
8
19
 
package/dist/Condition.js CHANGED
@@ -86,6 +86,10 @@ var Condition = function Condition(props) {
86
86
  currentField = _React$useState3[0],
87
87
  setCurrentField = _React$useState3[1];
88
88
 
89
+ var _React$useState4 = React.useState(''),
90
+ errorId = _React$useState4[0],
91
+ setErrorId = _React$useState4[1];
92
+
89
93
  var prevSteps = usePrevious(steps);
90
94
  React.useEffect(function () {
91
95
  if (autoOpenedComponent && steps.length && steps[0].conditions[0].operator && steps[0].conditions[0].operator.value === undefined) {
@@ -212,13 +216,32 @@ var Condition = function Condition(props) {
212
216
  setCurrentField(SUBJECT);
213
217
  }
214
218
  }, [addStep]);
219
+ var returnLast = React.useCallback(function (arr) {
220
+ return arr[arr.length - 1];
221
+ }, []);
222
+ var testPrevValueElement = React.useCallback(function () {
223
+ return steps == null ? void 0 : steps.map(function (step) {
224
+ var _returnLast;
225
+
226
+ return !((_returnLast = returnLast(step.conditions)) != null && _returnLast.factor.value) && setErrorId(returnLast(step.conditions).id);
227
+ });
228
+ }, [steps, returnLast]);
215
229
  var handleAddCondition = React.useMemo(function () {
230
+ var lastStep = returnLast(steps);
231
+ var lastCondition = returnLast(lastStep.conditions);
232
+
216
233
  if (!addCondition) {
217
234
  return undefined;
218
235
  }
219
236
 
220
237
  return function (stepId) {
221
- var newConditionId = addCondition ? addCondition(stepId) : undefined;
238
+ var newConditionId;
239
+
240
+ if (addCondition && lastCondition != null && lastCondition.factor.value || (lastStep == null ? void 0 : lastStep.conditions.length) === 0) {
241
+ newConditionId = addCondition(stepId);
242
+ }
243
+
244
+ testPrevValueElement();
222
245
 
223
246
  if (newConditionId) {
224
247
  setCurrentConditionId(newConditionId);
@@ -226,7 +249,7 @@ var Condition = function Condition(props) {
226
249
  setCurrentField(PARAMETER);
227
250
  }
228
251
  };
229
- }, [addCondition]);
252
+ }, [addCondition, steps, testPrevValueElement, returnLast]);
230
253
  var handleClearActiveCondition = React.useCallback(function () {
231
254
  setCurrentConditionId(DEFAULT_CONDITION);
232
255
  setCurrentStepId(DEFAULT_STEP);
@@ -269,7 +292,8 @@ var Condition = function Condition(props) {
269
292
  setCurrentStep: setCurrentStepId,
270
293
  onDeactivate: handleClearActiveCondition,
271
294
  showSuffix: showSuffix,
272
- hoverDisabled: hoverDisabled || currentStepId !== step.id && currentStepId !== undefined
295
+ hoverDisabled: hoverDisabled || currentStepId !== step.id && currentStepId !== undefined,
296
+ errorId: errorId
273
297
  });
274
298
  })), addStep && /*#__PURE__*/React.createElement(S.AddStepButton, null, /*#__PURE__*/React.createElement(Button, {
275
299
  type: "ghost",
@@ -278,7 +302,7 @@ var Condition = function Condition(props) {
278
302
  }, /*#__PURE__*/React.createElement(Icon, {
279
303
  component: /*#__PURE__*/React.createElement(Add3M, null)
280
304
  }), text.addStep)), renderAddStep && /*#__PURE__*/React.createElement(S.AddStepButton, null, renderAddStep()));
281
- }, [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, hoverDisabled]);
305
+ }, [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, hoverDisabled, errorId]);
282
306
  };
283
307
 
284
308
  export default Condition;
@@ -33,7 +33,8 @@ export var ConditionRow = function ConditionRow(_ref) {
33
33
  hasPriority = _ref.hasPriority,
34
34
  texts = _ref.texts,
35
35
  stepType = _ref.stepType,
36
- onDeactivate = _ref.onDeactivate;
36
+ onDeactivate = _ref.onDeactivate,
37
+ error = _ref.error;
37
38
  return /*#__PURE__*/React.createElement(S.ConditionRow, {
38
39
  stepType: stepType,
39
40
  style: hasPriority ? {
@@ -79,6 +80,7 @@ export var ConditionRow = function ConditionRow(_ref) {
79
80
  return setStepConditionFactorValue(stepId, conditionId, value);
80
81
  },
81
82
  factorKey: conditionId,
83
+ error: error,
82
84
  opened: hasPriority && stepId === currentStepId && conditionId === currentConditionId && currentField === FACTOR
83
85
  })))), removeCondition && conditionsNumber > minConditionLength && /*#__PURE__*/React.createElement(S.RemoveIconWrapper, {
84
86
  onClick: function onClick() {
@@ -4,6 +4,7 @@ import { OperatorsProps } from '@synerise/ds-operators/dist/Operator.types';
4
4
  import { ConditionProps, ConditionTexts } from '../../Condition.types';
5
5
  export declare type ConditionRowProps = {
6
6
  index: number;
7
+ error?: boolean;
7
8
  hasPriority?: boolean;
8
9
  onActivate?: (fieldType: string) => void;
9
10
  onDeactivate?: () => void;
@@ -48,7 +48,8 @@ export var ConditionStep = function ConditionStep(_ref) {
48
48
  setCurrentStep = _ref.setCurrentStep,
49
49
  onDeactivate = _ref.onDeactivate,
50
50
  showSuffix = _ref.showSuffix,
51
- hoverDisabled = _ref.hoverDisabled;
51
+ hoverDisabled = _ref.hoverDisabled,
52
+ errorId = _ref.errorId;
52
53
 
53
54
  var _useIntl = useIntl(),
54
55
  formatMessage = _useIntl.formatMessage;
@@ -167,9 +168,10 @@ export var ConditionStep = function ConditionStep(_ref) {
167
168
  setStepConditionFactorValue: setStepConditionFactorValue,
168
169
  texts: text,
169
170
  stepType: (_step$context2 = step.context) == null ? void 0 : _step$context2.type,
170
- onDeactivate: onDeactivate
171
+ onDeactivate: onDeactivate,
172
+ error: errorId === condition.id && !condition.factor.value && true
171
173
  });
172
- }, [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]);
174
+ }, [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, errorId]);
173
175
  return /*#__PURE__*/React.createElement(S.Step, {
174
176
  key: step.id,
175
177
  id: "condition-step-" + step.id,
@@ -7,6 +7,7 @@ import { ConditionStep, ConditionTexts, ConditionProps } from '../Condition.type
7
7
  export declare type ConditionStepProps = {
8
8
  index: number;
9
9
  step: ConditionStep;
10
+ errorId?: string;
10
11
  hasPriority?: boolean;
11
12
  onStepActivate?: (stepid: React.ReactText) => void;
12
13
  getPopupContainerOverride?: ConditionProps['getPopupContainerOverride'];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synerise/ds-condition",
3
- "version": "0.16.0",
3
+ "version": "0.17.0",
4
4
  "description": "Condition UI Component for the Synerise Design System",
5
5
  "license": "ISC",
6
6
  "repository": "Synerise/synerise-design",
@@ -36,7 +36,7 @@
36
36
  "@synerise/ds-context-selector": "^0.12.1",
37
37
  "@synerise/ds-core": "^0.34.0",
38
38
  "@synerise/ds-cruds": "^0.3.9",
39
- "@synerise/ds-factors": "^0.13.2",
39
+ "@synerise/ds-factors": "^0.14.0",
40
40
  "@synerise/ds-icon": "^0.49.0",
41
41
  "@synerise/ds-inline-edit": "^0.6.12",
42
42
  "@synerise/ds-operators": "^0.9.0",
@@ -49,5 +49,5 @@
49
49
  "@synerise/ds-core": "*",
50
50
  "react": ">=16.9.0 < 17.0.0"
51
51
  },
52
- "gitHead": "25e5737ebe9d4319de963b369bc281651872887c"
52
+ "gitHead": "db2ce8aa0a0fd56511ded2f0e21c597fffd3d158"
53
53
  }