@reltio/components 1.4.2024 → 1.4.2025
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/EditModeAttributesPager/components/AttributeRenderer/IntegrationAttributeRenderer.test.js +10 -0
- package/SimpleAttributeEditor/SimpleAttributeEditor.js +12 -5
- package/cjs/EditModeAttributesPager/components/AttributeRenderer/IntegrationAttributeRenderer.test.js +10 -0
- package/cjs/SimpleAttributeEditor/SimpleAttributeEditor.js +12 -5
- package/package.json +1 -1
package/EditModeAttributesPager/components/AttributeRenderer/IntegrationAttributeRenderer.test.js
CHANGED
|
@@ -212,4 +212,14 @@ describe('Attribute renderer tests', function () {
|
|
|
212
212
|
expect(within(attributeValues[1]).getByText('Yes')).toBeInTheDocument();
|
|
213
213
|
expect(within(attributeValues[1]).queryByText('No')).not.toBeInTheDocument();
|
|
214
214
|
});
|
|
215
|
+
it('should not allow to add more values in edit mode if cardinality max value is one', function () {
|
|
216
|
+
var props = __assign(__assign({}, defaultProps), { attributeType: __assign(__assign({}, attributeType), { cardinality: { maxValue: 1, minValue: 0 } }) });
|
|
217
|
+
setUp({ props: props });
|
|
218
|
+
expect(screen.queryByTestId('reltio-add-one-more-simple-attribute-button')).not.toBeInTheDocument();
|
|
219
|
+
});
|
|
220
|
+
it('should allow to add more values in edit mode if cardinality max value is more than one', function () {
|
|
221
|
+
var props = __assign(__assign({}, defaultProps), { attributeType: __assign(__assign({}, attributeType), { cardinality: { maxValue: 2, minValue: 1 } }) });
|
|
222
|
+
setUp({ props: props });
|
|
223
|
+
expect(screen.getByTestId('reltio-add-one-more-simple-attribute-button')).toBeInTheDocument();
|
|
224
|
+
});
|
|
215
225
|
});
|
|
@@ -50,21 +50,22 @@ var AsyncMountPlaceholder = function () {
|
|
|
50
50
|
};
|
|
51
51
|
var SimpleAttributeEditor = function (_a) {
|
|
52
52
|
var _b, _c;
|
|
53
|
-
var
|
|
53
|
+
var _d;
|
|
54
|
+
var className = _a.className, attributeValue = _a.attributeValue, attributeType = _a.attributeType, isReltioCrosswalk = _a.isReltioCrosswalk, ownError = _a.ownError, mode = _a.mode, onAddOneMore = _a.onAddOneMore, onDeleteAttribute = _a.onDeleteAttribute, onChangeAttribute = _a.onChangeAttribute, onDeactivateError = _a.onDeactivateError, additionalControlsRenderer = _a.additionalControlsRenderer, state = _a.state, highlightedError = _a.highlightedError, _e = _a.isEmptyEditor, isEmptyEditor = _e === void 0 ? false : _e, otherProps = __rest(_a, ["className", "attributeValue", "attributeType", "isReltioCrosswalk", "ownError", "mode", "onAddOneMore", "onDeleteAttribute", "onChangeAttribute", "onDeactivateError", "additionalControlsRenderer", "state", "highlightedError", "isEmptyEditor"]);
|
|
54
55
|
var styles = useStyles();
|
|
55
56
|
var deleted = state === 'deleted';
|
|
56
57
|
var edited = state === 'edited';
|
|
57
58
|
var isEditableMode = checkIsEditableMode(mode);
|
|
58
|
-
var
|
|
59
|
+
var _f = useAttributeValuePermissions({
|
|
59
60
|
attributeValue: attributeValue,
|
|
60
61
|
attributeType: attributeType,
|
|
61
62
|
mode: mode,
|
|
62
63
|
isReltioCrosswalk: isReltioCrosswalk
|
|
63
|
-
}), canCreate =
|
|
64
|
+
}), canCreate = _f.canCreate, canEdit = _f.canEdit, canDelete = _f.canDelete;
|
|
64
65
|
var showToEdit = canEdit && isEditableMode && !attributeValue.masked;
|
|
65
66
|
var errorMessage = getErrorMessage(ownError);
|
|
66
67
|
var dependentLookupEditorContext = useMdmDependentLookupEditorContext(attributeValue, attributeType);
|
|
67
|
-
var
|
|
68
|
+
var _g = useScrollToAttributeError({ highlightedError: highlightedError, isSimple: true }), ref = _g.ref, errorClassName = _g.errorClassName;
|
|
68
69
|
useEffect(function () {
|
|
69
70
|
// when editor is empty but has default lookup code, onChangeAttribute will be called by useLookupsResolver
|
|
70
71
|
if (isEmptyEditor && isDependentLookupAttrType(attributeType) && !has('lookupCode', attributeValue)) {
|
|
@@ -90,7 +91,13 @@ var SimpleAttributeEditor = function (_a) {
|
|
|
90
91
|
deactivateError();
|
|
91
92
|
}
|
|
92
93
|
};
|
|
93
|
-
var
|
|
94
|
+
var maxCardinalityIsOne = ((_d = attributeType === null || attributeType === void 0 ? void 0 : attributeType.cardinality) === null || _d === void 0 ? void 0 : _d.maxValue) === 1;
|
|
95
|
+
var showAddButton = !!onAddOneMore &&
|
|
96
|
+
canCreate &&
|
|
97
|
+
!attributeType.singleValue &&
|
|
98
|
+
!attributeValue.masked &&
|
|
99
|
+
mode !== Mode.Viewing &&
|
|
100
|
+
!maxCardinalityIsOne;
|
|
94
101
|
var showDeleteButton = !deleted && !!onDeleteAttribute && canDelete && !attributeValue.masked && mode !== Mode.Viewing;
|
|
95
102
|
var hasError = !!errorMessage;
|
|
96
103
|
var deletedProps = deleted ? { disabled: true, isCrossedOut: true } : {};
|
|
@@ -217,4 +217,14 @@ describe('Attribute renderer tests', function () {
|
|
|
217
217
|
expect((0, react_2.within)(attributeValues[1]).getByText('Yes')).toBeInTheDocument();
|
|
218
218
|
expect((0, react_2.within)(attributeValues[1]).queryByText('No')).not.toBeInTheDocument();
|
|
219
219
|
});
|
|
220
|
+
it('should not allow to add more values in edit mode if cardinality max value is one', function () {
|
|
221
|
+
var props = __assign(__assign({}, defaultProps), { attributeType: __assign(__assign({}, attributeType), { cardinality: { maxValue: 1, minValue: 0 } }) });
|
|
222
|
+
setUp({ props: props });
|
|
223
|
+
expect(react_2.screen.queryByTestId('reltio-add-one-more-simple-attribute-button')).not.toBeInTheDocument();
|
|
224
|
+
});
|
|
225
|
+
it('should allow to add more values in edit mode if cardinality max value is more than one', function () {
|
|
226
|
+
var props = __assign(__assign({}, defaultProps), { attributeType: __assign(__assign({}, attributeType), { cardinality: { maxValue: 2, minValue: 1 } }) });
|
|
227
|
+
setUp({ props: props });
|
|
228
|
+
expect(react_2.screen.getByTestId('reltio-add-one-more-simple-attribute-button')).toBeInTheDocument();
|
|
229
|
+
});
|
|
220
230
|
});
|
|
@@ -78,21 +78,22 @@ var AsyncMountPlaceholder = function () {
|
|
|
78
78
|
};
|
|
79
79
|
var SimpleAttributeEditor = function (_a) {
|
|
80
80
|
var _b, _c;
|
|
81
|
-
var
|
|
81
|
+
var _d;
|
|
82
|
+
var className = _a.className, attributeValue = _a.attributeValue, attributeType = _a.attributeType, isReltioCrosswalk = _a.isReltioCrosswalk, ownError = _a.ownError, mode = _a.mode, onAddOneMore = _a.onAddOneMore, onDeleteAttribute = _a.onDeleteAttribute, onChangeAttribute = _a.onChangeAttribute, onDeactivateError = _a.onDeactivateError, additionalControlsRenderer = _a.additionalControlsRenderer, state = _a.state, highlightedError = _a.highlightedError, _e = _a.isEmptyEditor, isEmptyEditor = _e === void 0 ? false : _e, otherProps = __rest(_a, ["className", "attributeValue", "attributeType", "isReltioCrosswalk", "ownError", "mode", "onAddOneMore", "onDeleteAttribute", "onChangeAttribute", "onDeactivateError", "additionalControlsRenderer", "state", "highlightedError", "isEmptyEditor"]);
|
|
82
83
|
var styles = (0, styles_1.useStyles)();
|
|
83
84
|
var deleted = state === 'deleted';
|
|
84
85
|
var edited = state === 'edited';
|
|
85
86
|
var isEditableMode = (0, mdm_sdk_1.isEditableMode)(mode);
|
|
86
|
-
var
|
|
87
|
+
var _f = (0, useAttributeValuePermissions_1.useAttributeValuePermissions)({
|
|
87
88
|
attributeValue: attributeValue,
|
|
88
89
|
attributeType: attributeType,
|
|
89
90
|
mode: mode,
|
|
90
91
|
isReltioCrosswalk: isReltioCrosswalk
|
|
91
|
-
}), canCreate =
|
|
92
|
+
}), canCreate = _f.canCreate, canEdit = _f.canEdit, canDelete = _f.canDelete;
|
|
92
93
|
var showToEdit = canEdit && isEditableMode && !attributeValue.masked;
|
|
93
94
|
var errorMessage = (0, mdm_sdk_1.getErrorMessage)(ownError);
|
|
94
95
|
var dependentLookupEditorContext = (0, MdmModuleContext_1.useMdmDependentLookupEditorContext)(attributeValue, attributeType);
|
|
95
|
-
var
|
|
96
|
+
var _g = (0, useScrollToAttributeError_1.useScrollToAttributeError)({ highlightedError: highlightedError, isSimple: true }), ref = _g.ref, errorClassName = _g.errorClassName;
|
|
96
97
|
(0, react_1.useEffect)(function () {
|
|
97
98
|
// when editor is empty but has default lookup code, onChangeAttribute will be called by useLookupsResolver
|
|
98
99
|
if (isEmptyEditor && (0, mdm_sdk_1.isDependentLookupAttrType)(attributeType) && !(0, ramda_1.has)('lookupCode', attributeValue)) {
|
|
@@ -118,7 +119,13 @@ var SimpleAttributeEditor = function (_a) {
|
|
|
118
119
|
deactivateError();
|
|
119
120
|
}
|
|
120
121
|
};
|
|
121
|
-
var
|
|
122
|
+
var maxCardinalityIsOne = ((_d = attributeType === null || attributeType === void 0 ? void 0 : attributeType.cardinality) === null || _d === void 0 ? void 0 : _d.maxValue) === 1;
|
|
123
|
+
var showAddButton = !!onAddOneMore &&
|
|
124
|
+
canCreate &&
|
|
125
|
+
!attributeType.singleValue &&
|
|
126
|
+
!attributeValue.masked &&
|
|
127
|
+
mode !== mdm_sdk_1.Mode.Viewing &&
|
|
128
|
+
!maxCardinalityIsOne;
|
|
122
129
|
var showDeleteButton = !deleted && !!onDeleteAttribute && canDelete && !attributeValue.masked && mode !== mdm_sdk_1.Mode.Viewing;
|
|
123
130
|
var hasError = !!errorMessage;
|
|
124
131
|
var deletedProps = deleted ? { disabled: true, isCrossedOut: true } : {};
|