@synerise/ds-condition 0.14.0 → 0.14.3
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 +30 -0
- package/dist/Condition.d.ts +1 -0
- package/dist/Condition.js +33 -10
- package/dist/Condition.style.d.ts +3 -1
- package/dist/Condition.types.d.ts +2 -2
- package/dist/ConditionStep/AddCondition/AddCondition.types.d.ts +3 -3
- package/dist/ConditionStep/ConditionRow/ConditionRow.js +6 -4
- package/dist/ConditionStep/ConditionRow/ConditionRow.types.d.ts +1 -1
- package/dist/ConditionStep/ConditionStep.js +13 -12
- package/dist/ConditionStep/ConditionStep.types.d.ts +2 -0
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,36 @@
|
|
|
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.14.3](https://github.com/Synerise/synerise-design/compare/@synerise/ds-condition@0.14.2...@synerise/ds-condition@0.14.3) (2022-04-12)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **condition:** rules-of-hooks dependencies ([10e573e](https://github.com/Synerise/synerise-design/commit/10e573e018ca7e2f69f3f317f35d51eace89ded8))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## [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)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* fix filter dropdowns ([eaab107](https://github.com/Synerise/synerise-design/commit/eaab107b6dca7401a17c2e36806febd11edc677b))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
## [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)
|
|
29
|
+
|
|
30
|
+
**Note:** Version bump only for package @synerise/ds-condition
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
6
36
|
# [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
37
|
|
|
8
38
|
|
package/dist/Condition.d.ts
CHANGED
|
@@ -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',
|
|
@@ -76,10 +77,6 @@ var Condition = function Condition(props) {
|
|
|
76
77
|
currentField = _React$useState3[0],
|
|
77
78
|
setCurrentField = _React$useState3[1];
|
|
78
79
|
|
|
79
|
-
var _React$useState4 = React.useState(null),
|
|
80
|
-
priorityStepId = _React$useState4[0],
|
|
81
|
-
setPriorityStepId = _React$useState4[1];
|
|
82
|
-
|
|
83
80
|
var prevSteps = usePrevious(steps);
|
|
84
81
|
React.useEffect(function () {
|
|
85
82
|
var newConditionId = prevSteps && steps && steps.reduce(function (id, step) {
|
|
@@ -148,11 +145,13 @@ var Condition = function Condition(props) {
|
|
|
148
145
|
var selectSubject = React.useCallback(function (value, stepId) {
|
|
149
146
|
clearConditionRow(stepId);
|
|
150
147
|
setCurrentStepId(stepId);
|
|
148
|
+
setCurrentField(PARAMETER);
|
|
151
149
|
onChangeSubject && onChangeSubject(stepId, value);
|
|
152
150
|
}, [clearConditionRow, onChangeSubject]);
|
|
153
151
|
var selectContext = React.useCallback(function (value, stepId) {
|
|
154
152
|
clearConditionRow(stepId);
|
|
155
153
|
setCurrentStepId(stepId);
|
|
154
|
+
setCurrentField(PARAMETER);
|
|
156
155
|
onChangeContext && onChangeContext(stepId, value);
|
|
157
156
|
}, [clearConditionRow, onChangeContext]);
|
|
158
157
|
var selectParameter = React.useCallback(function (stepId, conditionId, value) {
|
|
@@ -188,6 +187,29 @@ var Condition = function Condition(props) {
|
|
|
188
187
|
var draggableEnabled = React.useMemo(function () {
|
|
189
188
|
return onChangeOrder && steps.length > 1;
|
|
190
189
|
}, [steps, onChangeOrder]);
|
|
190
|
+
var handleAddStep = React.useCallback(function () {
|
|
191
|
+
var newStepId = addStep ? addStep() : undefined;
|
|
192
|
+
|
|
193
|
+
if (newStepId) {
|
|
194
|
+
setCurrentStepId(newStepId);
|
|
195
|
+
setCurrentField(SUBJECT);
|
|
196
|
+
}
|
|
197
|
+
}, [addStep]);
|
|
198
|
+
var handleAddCondtion = React.useMemo(function () {
|
|
199
|
+
if (!addCondition) {
|
|
200
|
+
return undefined;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return function (stepId) {
|
|
204
|
+
var newConditionId = addCondition ? addCondition(stepId) : undefined;
|
|
205
|
+
|
|
206
|
+
if (newConditionId) {
|
|
207
|
+
setCurrentConditionId(newConditionId);
|
|
208
|
+
setCurrentStepId(stepId);
|
|
209
|
+
setCurrentField(PARAMETER);
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
}, [addCondition]);
|
|
191
213
|
return React.useMemo(function () {
|
|
192
214
|
return /*#__PURE__*/React.createElement(S.Condition, {
|
|
193
215
|
className: "ds-conditions",
|
|
@@ -201,8 +223,7 @@ var Condition = function Condition(props) {
|
|
|
201
223
|
step: step,
|
|
202
224
|
texts: text,
|
|
203
225
|
index: index,
|
|
204
|
-
hasPriority: step.id ===
|
|
205
|
-
onStepActivate: setPriorityStepId,
|
|
226
|
+
hasPriority: step.id === currentStepId,
|
|
206
227
|
getPopupContainerOverride: getPopupContainerOverride,
|
|
207
228
|
draggableEnabled: draggableEnabled,
|
|
208
229
|
selectOperator: selectOperator,
|
|
@@ -220,17 +241,19 @@ var Condition = function Condition(props) {
|
|
|
220
241
|
currentStepId: currentStepId,
|
|
221
242
|
currentField: currentField,
|
|
222
243
|
removeCondition: removeCondition,
|
|
223
|
-
addCondition:
|
|
224
|
-
setCurrentField: setCurrentField
|
|
244
|
+
addCondition: handleAddCondtion,
|
|
245
|
+
setCurrentField: setCurrentField,
|
|
246
|
+
setCurrentCondition: setCurrentConditionId,
|
|
247
|
+
setCurrentStep: setCurrentStepId
|
|
225
248
|
});
|
|
226
249
|
})), addStep && /*#__PURE__*/React.createElement(S.AddStepButton, null, /*#__PURE__*/React.createElement(Button, {
|
|
227
250
|
type: "ghost",
|
|
228
251
|
mode: "icon-label",
|
|
229
|
-
onClick:
|
|
252
|
+
onClick: handleAddStep
|
|
230
253
|
}, /*#__PURE__*/React.createElement(Icon, {
|
|
231
254
|
component: /*#__PURE__*/React.createElement(Add3M, null)
|
|
232
255
|
}), text.addStep)));
|
|
233
|
-
}, [steps,
|
|
256
|
+
}, [steps, onChangeOrder, addStep, handleAddStep, text, currentConditionId, currentStepId, currentField, getPopupContainerOverride, draggableEnabled, handleAddCondtion, selectOperator, selectParameter, selectContext, selectSubject, onUpdateStepName, duplicateStep, removeStep, minConditionsLength, maxConditionsLength, setStepConditionFactorType, setStepConditionFactorValue, removeCondition]);
|
|
234
257
|
};
|
|
235
258
|
|
|
236
259
|
export default Condition;
|
|
@@ -13,7 +13,9 @@ export declare const StepHeader: import("styled-components").StyledComponent<"di
|
|
|
13
13
|
draggable: boolean;
|
|
14
14
|
}, never>;
|
|
15
15
|
export declare const Step: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
16
|
-
export declare const ConditionWrapper: import("styled-components").StyledComponent<"div", any, {
|
|
16
|
+
export declare const ConditionWrapper: import("styled-components").StyledComponent<"div", any, {
|
|
17
|
+
fullWidth?: boolean | undefined;
|
|
18
|
+
}, never>;
|
|
17
19
|
export declare const Subject: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
18
20
|
export declare const RemoveIconWrapper: import("styled-components").StyledComponent<"span", any, {}, never>;
|
|
19
21
|
export declare const ConditionRows: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
@@ -30,11 +30,11 @@ export declare type ConditionTexts = {
|
|
|
30
30
|
export declare type ConditionProps = {
|
|
31
31
|
steps: ConditionStep[];
|
|
32
32
|
getPopupContainerOverride?: (trigger: HTMLElement | null) => HTMLElement;
|
|
33
|
-
addCondition?: (stepId: React.ReactText) =>
|
|
33
|
+
addCondition?: (stepId: React.ReactText) => string | undefined;
|
|
34
34
|
removeCondition?: (stepId: React.ReactText, conditionRowId: React.ReactText) => void;
|
|
35
35
|
removeStep?: (stepId: React.ReactText) => void;
|
|
36
36
|
duplicateStep?: (stepId: React.ReactText) => void;
|
|
37
|
-
addStep?: () =>
|
|
37
|
+
addStep?: () => string | undefined;
|
|
38
38
|
onChangeOrder?: (newOrder: ConditionStep[]) => void;
|
|
39
39
|
texts?: Partial<ConditionTexts>;
|
|
40
40
|
minConditionsLength: number;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ConditionTexts } from '../../Condition.types';
|
|
3
3
|
export declare type AddConditionProps = {
|
|
4
|
-
addCondition:
|
|
4
|
+
addCondition: (stepId: React.ReactText) => void;
|
|
5
5
|
stepId: React.ReactText;
|
|
6
6
|
conditionsNumber: number;
|
|
7
7
|
texts: Partial<ConditionTexts>;
|
|
@@ -49,7 +49,7 @@ export var ConditionRow = function ConditionRow(_ref) {
|
|
|
49
49
|
onChangeValue: function onChangeValue(value) {
|
|
50
50
|
return selectParameter(stepId, conditionId, value);
|
|
51
51
|
},
|
|
52
|
-
opened: stepId === currentStepId && conditionId === currentConditionId && currentField === PARAMETER
|
|
52
|
+
opened: hasPriority && stepId === currentStepId && conditionId === currentConditionId && currentField === PARAMETER
|
|
53
53
|
}))), (!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
54
|
getPopupContainerOverride: getPopupContainerOverride,
|
|
55
55
|
onActivate: function onActivate() {
|
|
@@ -58,8 +58,10 @@ export var ConditionRow = function ConditionRow(_ref) {
|
|
|
58
58
|
onChange: function onChange(value) {
|
|
59
59
|
return selectOperator(stepId, conditionId, value);
|
|
60
60
|
},
|
|
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,
|
|
61
|
+
opened: hasPriority && 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, {
|
|
63
|
+
fullWidth: true
|
|
64
|
+
}, /*#__PURE__*/React.createElement(React.Fragment, null, (conditionFactor == null ? void 0 : conditionFactor.withCustomFactor) || /*#__PURE__*/React.createElement(Factors, _extends({}, conditionFactor, {
|
|
63
65
|
getPopupContainerOverride: getPopupContainerOverride,
|
|
64
66
|
onActivate: function onActivate() {
|
|
65
67
|
return _onActivate && _onActivate(FACTOR);
|
|
@@ -71,7 +73,7 @@ export var ConditionRow = function ConditionRow(_ref) {
|
|
|
71
73
|
return setStepConditionFactorValue(stepId, conditionId, value);
|
|
72
74
|
},
|
|
73
75
|
factorKey: conditionId,
|
|
74
|
-
opened: stepId === currentStepId && conditionId === currentConditionId && currentField === FACTOR
|
|
76
|
+
opened: hasPriority && stepId === currentStepId && conditionId === currentConditionId && currentField === FACTOR
|
|
75
77
|
})))), removeCondition && conditionsNumber > minConditionLength && /*#__PURE__*/React.createElement(S.RemoveIconWrapper, {
|
|
76
78
|
onClick: function onClick() {
|
|
77
79
|
return removeCondition(stepId, conditionId);
|
|
@@ -7,7 +7,7 @@ export declare type ConditionRowProps = {
|
|
|
7
7
|
hasPriority?: boolean;
|
|
8
8
|
onActivate?: (fieldType: string) => void;
|
|
9
9
|
conditionId: React.ReactText;
|
|
10
|
-
addCondition:
|
|
10
|
+
addCondition?: (stepId: React.ReactText) => void;
|
|
11
11
|
conditionParameter: FactorsProps;
|
|
12
12
|
conditionOperator: OperatorsProps;
|
|
13
13
|
conditionFactor: FactorsProps;
|
|
@@ -13,7 +13,8 @@ import { useIntl } from 'react-intl';
|
|
|
13
13
|
import * as S from '../Condition.style';
|
|
14
14
|
import { StepHeader } from './StepHeader';
|
|
15
15
|
import { AddCondition } from './AddCondition';
|
|
16
|
-
import { ConditionRow } from './ConditionRow';
|
|
16
|
+
import { ConditionRow } from './ConditionRow';
|
|
17
|
+
import { SUBJECT } from '../Condition'; // eslint-disable-next-line import/prefer-default-export
|
|
17
18
|
|
|
18
19
|
export var ConditionStep = function ConditionStep(_ref) {
|
|
19
20
|
var step = _ref.step,
|
|
@@ -35,16 +36,13 @@ export var ConditionStep = function ConditionStep(_ref) {
|
|
|
35
36
|
setStepConditionFactorType = _ref.setStepConditionFactorType,
|
|
36
37
|
setStepConditionFactorValue = _ref.setStepConditionFactorValue,
|
|
37
38
|
getPopupContainerOverride = _ref.getPopupContainerOverride,
|
|
38
|
-
onStepActivate = _ref.onStepActivate,
|
|
39
39
|
hasPriority = _ref.hasPriority,
|
|
40
40
|
currentStepId = _ref.currentStepId,
|
|
41
41
|
currentConditionId = _ref.currentConditionId,
|
|
42
42
|
currentField = _ref.currentField,
|
|
43
|
-
setCurrentField = _ref.setCurrentField
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
activeConditionId = _React$useState[0],
|
|
47
|
-
setActiveConditionId = _React$useState[1];
|
|
43
|
+
setCurrentField = _ref.setCurrentField,
|
|
44
|
+
setCurrentCondition = _ref.setCurrentCondition,
|
|
45
|
+
setCurrentStep = _ref.setCurrentStep;
|
|
48
46
|
|
|
49
47
|
var _useIntl = useIntl(),
|
|
50
48
|
formatMessage = _useIntl.formatMessage;
|
|
@@ -89,8 +87,8 @@ export var ConditionStep = function ConditionStep(_ref) {
|
|
|
89
87
|
})
|
|
90
88
|
}, texts);
|
|
91
89
|
}, [texts, formatMessage]);
|
|
92
|
-
var onActivate =
|
|
93
|
-
return
|
|
90
|
+
var onActivate = setCurrentStep ? function () {
|
|
91
|
+
return setCurrentStep(step.id);
|
|
94
92
|
} : undefined;
|
|
95
93
|
var onAddCondition = React.useCallback(function (stepId) {
|
|
96
94
|
addCondition && addCondition(stepId);
|
|
@@ -125,15 +123,16 @@ export var ConditionStep = function ConditionStep(_ref) {
|
|
|
125
123
|
|
|
126
124
|
var handleActivation = function handleActivation(conditionId) {
|
|
127
125
|
return function (fieldType) {
|
|
128
|
-
setActiveConditionId(conditionId);
|
|
129
126
|
onActivate && onActivate();
|
|
130
127
|
setCurrentField && setCurrentField(fieldType);
|
|
128
|
+
setCurrentCondition && setCurrentCondition(conditionId);
|
|
129
|
+
setCurrentStep && setCurrentStep(step.id);
|
|
131
130
|
};
|
|
132
131
|
};
|
|
133
132
|
|
|
134
133
|
return /*#__PURE__*/React.createElement(ConditionRow, {
|
|
135
134
|
key: "step-" + step.id + "-condition-" + condition.id,
|
|
136
|
-
hasPriority: hasPriority &&
|
|
135
|
+
hasPriority: hasPriority && currentConditionId === condition.id,
|
|
137
136
|
index: conditionIndex,
|
|
138
137
|
conditionId: condition.id,
|
|
139
138
|
addCondition: addCondition,
|
|
@@ -159,7 +158,7 @@ export var ConditionStep = function ConditionStep(_ref) {
|
|
|
159
158
|
texts: text,
|
|
160
159
|
stepType: (_step$context2 = step.context) == null ? void 0 : _step$context2.type
|
|
161
160
|
});
|
|
162
|
-
}, [step.id, step.conditions.length, step.context, hasPriority,
|
|
161
|
+
}, [step.id, step.conditions.length, step.context, hasPriority, currentConditionId, addCondition, removeCondition, minConditionsLength, maxConditionsLength, currentStepId, currentField, selectParameter, selectOperator, getPopupContainerOverride, setStepConditionFactorType, setStepConditionFactorValue, text, onActivate, setCurrentField, setCurrentCondition, setCurrentStep]);
|
|
163
162
|
return /*#__PURE__*/React.createElement(S.Step, {
|
|
164
163
|
key: step.id,
|
|
165
164
|
id: "condition-step-" + step.id,
|
|
@@ -172,12 +171,14 @@ export var ConditionStep = function ConditionStep(_ref) {
|
|
|
172
171
|
}, /*#__PURE__*/React.createElement(S.Subject, null, step.subject && /*#__PURE__*/React.createElement(Subject, _extends({}, step.subject, {
|
|
173
172
|
getPopupContainerOverride: getPopupContainerOverride,
|
|
174
173
|
onActivate: onActivate,
|
|
174
|
+
opened: step.id === currentStepId && currentField === SUBJECT,
|
|
175
175
|
onSelectItem: function onSelectItem(value) {
|
|
176
176
|
return selectSubject(value, step.id);
|
|
177
177
|
}
|
|
178
178
|
})), step.context && /*#__PURE__*/React.createElement(ContextSelector, _extends({}, step.context, {
|
|
179
179
|
getPopupContainerOverride: getPopupContainerOverride,
|
|
180
180
|
onActivate: onActivate,
|
|
181
|
+
opened: step.id === currentStepId && currentField === SUBJECT,
|
|
181
182
|
onSelectItem: function onSelectItem(value) {
|
|
182
183
|
return selectContext(value, step.id);
|
|
183
184
|
}
|
|
@@ -29,4 +29,6 @@ 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;
|
|
32
34
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@synerise/ds-condition",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.3",
|
|
4
4
|
"description": "Condition UI Component for the Synerise Design System",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"repository": "Synerise/synerise-design",
|
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
"@synerise/ds-context-selector": "^0.11.0",
|
|
37
37
|
"@synerise/ds-core": "^0.33.0",
|
|
38
38
|
"@synerise/ds-cruds": "^0.3.9",
|
|
39
|
-
"@synerise/ds-factors": "^0.12.
|
|
39
|
+
"@synerise/ds-factors": "^0.12.2",
|
|
40
40
|
"@synerise/ds-icon": "^0.49.0",
|
|
41
|
-
"@synerise/ds-inline-edit": "^0.6.
|
|
42
|
-
"@synerise/ds-operators": "^0.8.
|
|
43
|
-
"@synerise/ds-subject": "^0.8.
|
|
41
|
+
"@synerise/ds-inline-edit": "^0.6.11",
|
|
42
|
+
"@synerise/ds-operators": "^0.8.1",
|
|
43
|
+
"@synerise/ds-subject": "^0.8.1",
|
|
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": "
|
|
52
|
+
"gitHead": "78a3de75d8ec9c917d96c1b54c70d24f50dc8c7a"
|
|
53
53
|
}
|