@reltio/components 1.4.1964 → 1.4.1965
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/cjs/SimpleAttributeEditor/SimpleAttributeEditorWithoutPermissions.test.js +52 -23
- package/cjs/SimpleAttributeEditor/useAttributeValuePermissions.js +8 -2
- package/esm/SimpleAttributeEditor/SimpleAttributeEditorWithoutPermissions.test.js +52 -23
- package/esm/SimpleAttributeEditor/useAttributeValuePermissions.js +8 -2
- package/package.json +2 -2
|
@@ -15,23 +15,34 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
var react_1 = __importDefault(require("react"));
|
|
18
|
+
var react_2 = require("@testing-library/react");
|
|
18
19
|
var SimpleAttributeEditor_1 = __importDefault(require("./SimpleAttributeEditor"));
|
|
19
|
-
var enzyme_1 = require("enzyme");
|
|
20
20
|
var mdm_sdk_1 = require("@reltio/mdm-sdk");
|
|
21
21
|
var MdmModuleContext_1 = require("../contexts/MdmModuleContext");
|
|
22
|
+
var AllwaysVisibleAttributesContext_1 = require("../contexts/AllwaysVisibleAttributesContext");
|
|
22
23
|
jest.mock('@reltio/mdm-sdk', function () { return (__assign(__assign({}, jest.requireActual('@reltio/mdm-sdk')), { checkMetadataPermission: function () { return false; } })); });
|
|
23
24
|
var mdmValues = {
|
|
24
25
|
dependentLookups: {
|
|
25
26
|
editors: {}
|
|
26
27
|
}
|
|
27
28
|
};
|
|
28
|
-
var findActionButtons = function (component) {
|
|
29
|
-
return component.findWhere(function (n) { return n.prop('className') && n.prop('className').includes('editor-actions'); }).children();
|
|
30
|
-
};
|
|
31
29
|
describe('SimpleAttributeEditor without permissions', function () {
|
|
32
30
|
var onAddFn = jest.fn();
|
|
33
31
|
var onDeleteFn = jest.fn();
|
|
34
32
|
var onChangeFn = jest.fn();
|
|
33
|
+
var defaultProps = {
|
|
34
|
+
mode: mdm_sdk_1.Mode.Editing,
|
|
35
|
+
isReltioCrosswalk: true,
|
|
36
|
+
onAddAttributes: onAddFn,
|
|
37
|
+
onDeleteAttribute: onDeleteFn,
|
|
38
|
+
onChangeAttribute: onChangeFn
|
|
39
|
+
};
|
|
40
|
+
var setUp = function (_a) {
|
|
41
|
+
var props = _a.props, _b = _a.alwaysVisibleAttributes, alwaysVisibleAttributes = _b === void 0 ? [] : _b;
|
|
42
|
+
return (0, react_2.render)(react_1.default.createElement(AllwaysVisibleAttributesContext_1.AlwaysVisibleAttributesContext.Provider, { value: alwaysVisibleAttributes },
|
|
43
|
+
react_1.default.createElement(MdmModuleContext_1.MdmModuleProvider, { values: mdmValues },
|
|
44
|
+
react_1.default.createElement(SimpleAttributeEditor_1.default, __assign({}, defaultProps, props)))));
|
|
45
|
+
};
|
|
35
46
|
it('should render just text, if there is only READ permission', function () {
|
|
36
47
|
var props = {
|
|
37
48
|
attributeValue: {
|
|
@@ -42,17 +53,11 @@ describe('SimpleAttributeEditor without permissions', function () {
|
|
|
42
53
|
access: ['READ'],
|
|
43
54
|
type: 'String',
|
|
44
55
|
uri: 'configuration/entityTypes/HCA/attributes/InternalCustomer'
|
|
45
|
-
}
|
|
46
|
-
mode: mdm_sdk_1.Mode.Editing,
|
|
47
|
-
isReltioCrosswalk: true,
|
|
48
|
-
onAddAttributes: onAddFn,
|
|
49
|
-
onDeleteAttribute: onDeleteFn,
|
|
50
|
-
onChangeAttribute: onChangeFn
|
|
56
|
+
}
|
|
51
57
|
};
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
expect(
|
|
55
|
-
expect(findActionButtons(simpleAttributeEditor).length).toBe(0);
|
|
58
|
+
setUp({ props: props });
|
|
59
|
+
expect(react_2.screen.getByText('some string')).toBeInTheDocument();
|
|
60
|
+
expect(react_2.screen.queryByTestId('reltio-delete-simple-attribute-button')).not.toBeInTheDocument();
|
|
56
61
|
});
|
|
57
62
|
it('should render text and DELETE button, if there are only READ and DELETE permission', function () {
|
|
58
63
|
var props = {
|
|
@@ -64,16 +69,40 @@ describe('SimpleAttributeEditor without permissions', function () {
|
|
|
64
69
|
access: ['READ', 'DELETE'],
|
|
65
70
|
type: 'String',
|
|
66
71
|
uri: 'configuration/entityTypes/HCA/attributes/InternalCustomer'
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
setUp({ props: props });
|
|
75
|
+
expect(react_2.screen.getByText('some string')).toBeInTheDocument();
|
|
76
|
+
expect(react_2.screen.getByTestId('reltio-delete-simple-attribute-button')).toBeInTheDocument();
|
|
77
|
+
});
|
|
78
|
+
it('should render always visible attribute without value correct, if there are only READ permission', function () {
|
|
79
|
+
var props = {
|
|
80
|
+
attributeValue: {
|
|
81
|
+
uri: 'uri$$'
|
|
67
82
|
},
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
83
|
+
attributeType: {
|
|
84
|
+
access: ['READ'],
|
|
85
|
+
type: 'String',
|
|
86
|
+
uri: 'configuration/entityTypes/HCA/attributes/InternalCustomer'
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
setUp({ props: props, alwaysVisibleAttributes: ['configuration/entityTypes/HCA/attributes/InternalCustomer'] });
|
|
90
|
+
expect(react_2.screen.queryByRole('textbox')).not.toBeInTheDocument();
|
|
91
|
+
expect(react_2.screen.queryByTestId('reltio-delete-simple-attribute-button')).not.toBeInTheDocument();
|
|
92
|
+
});
|
|
93
|
+
it('should render always visible attribute without value correct, if there are only READ and DELETE permission', function () {
|
|
94
|
+
var props = {
|
|
95
|
+
attributeValue: {
|
|
96
|
+
uri: 'uri$$'
|
|
97
|
+
},
|
|
98
|
+
attributeType: {
|
|
99
|
+
access: ['READ', 'DELETE'],
|
|
100
|
+
type: 'String',
|
|
101
|
+
uri: 'configuration/entityTypes/HCA/attributes/InternalCustomer'
|
|
102
|
+
}
|
|
73
103
|
};
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
expect(
|
|
77
|
-
expect(findActionButtons(simpleAttributeEditor).length).toBe(1);
|
|
104
|
+
setUp({ props: props, alwaysVisibleAttributes: ['configuration/entityTypes/HCA/attributes/InternalCustomer'] });
|
|
105
|
+
expect(react_2.screen.queryByRole('textbox')).not.toBeInTheDocument();
|
|
106
|
+
expect(react_2.screen.getByTestId('reltio-delete-simple-attribute-button')).toBeInTheDocument();
|
|
78
107
|
});
|
|
79
108
|
});
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useAttributeValuePermissions = void 0;
|
|
4
|
+
var react_1 = require("react");
|
|
4
5
|
var mdm_sdk_1 = require("@reltio/mdm-sdk");
|
|
5
6
|
var ConfigPermissionsContext_1 = require("../contexts/ConfigPermissionsContext");
|
|
7
|
+
var AllwaysVisibleAttributesContext_1 = require("../contexts/AllwaysVisibleAttributesContext");
|
|
6
8
|
var useAttributeValuePermissions = function (_a) {
|
|
7
9
|
var attributeType = _a.attributeType, attributeValue = _a.attributeValue, isReltioCrosswalk = _a.isReltioCrosswalk, mode = _a.mode;
|
|
8
10
|
var _b = (0, ConfigPermissionsContext_1.useAttributeValueConfigPermissions)(attributeValue.uri), configCanCreate = _b.canCreate, configCanUpdate = _b.canUpdate, configCanDelete = _b.canDelete;
|
|
11
|
+
var alwaysVisibleAttributes = (0, react_1.useContext)(AllwaysVisibleAttributesContext_1.AlwaysVisibleAttributesContext);
|
|
12
|
+
var isAlwaysVisible = (0, react_1.useMemo)(function () { return alwaysVisibleAttributes === null || alwaysVisibleAttributes === void 0 ? void 0 : alwaysVisibleAttributes.includes(attributeType.uri); }, [attributeType.uri, alwaysVisibleAttributes]);
|
|
9
13
|
var canCreate = configCanCreate && (0, mdm_sdk_1.checkCanCreateAttribute)({ attributeType: attributeType, mode: mode });
|
|
10
|
-
var canEdit = configCanUpdate &&
|
|
11
|
-
|
|
14
|
+
var canEdit = configCanUpdate &&
|
|
15
|
+
(0, mdm_sdk_1.checkCanEditAttribute)({ attributeType: attributeType, attributeValue: attributeValue, mode: mode, isReltioCrosswalk: isReltioCrosswalk, isAlwaysVisible: isAlwaysVisible });
|
|
16
|
+
var canDelete = configCanDelete &&
|
|
17
|
+
(0, mdm_sdk_1.checkCanDeleteAttribute)({ attributeType: attributeType, attributeValue: attributeValue, mode: mode, isReltioCrosswalk: isReltioCrosswalk, isAlwaysVisible: isAlwaysVisible });
|
|
12
18
|
return { canCreate: canCreate, canEdit: canEdit, canDelete: canDelete };
|
|
13
19
|
};
|
|
14
20
|
exports.useAttributeValuePermissions = useAttributeValuePermissions;
|
|
@@ -10,23 +10,34 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
12
|
import React from 'react';
|
|
13
|
+
import { render, screen } from '@testing-library/react';
|
|
13
14
|
import SimpleAttributeEditor from './SimpleAttributeEditor';
|
|
14
|
-
import { mount } from 'enzyme';
|
|
15
15
|
import { Mode } from '@reltio/mdm-sdk';
|
|
16
16
|
import { MdmModuleProvider } from '../contexts/MdmModuleContext';
|
|
17
|
+
import { AlwaysVisibleAttributesContext } from '../contexts/AllwaysVisibleAttributesContext';
|
|
17
18
|
jest.mock('@reltio/mdm-sdk', function () { return (__assign(__assign({}, jest.requireActual('@reltio/mdm-sdk')), { checkMetadataPermission: function () { return false; } })); });
|
|
18
19
|
var mdmValues = {
|
|
19
20
|
dependentLookups: {
|
|
20
21
|
editors: {}
|
|
21
22
|
}
|
|
22
23
|
};
|
|
23
|
-
var findActionButtons = function (component) {
|
|
24
|
-
return component.findWhere(function (n) { return n.prop('className') && n.prop('className').includes('editor-actions'); }).children();
|
|
25
|
-
};
|
|
26
24
|
describe('SimpleAttributeEditor without permissions', function () {
|
|
27
25
|
var onAddFn = jest.fn();
|
|
28
26
|
var onDeleteFn = jest.fn();
|
|
29
27
|
var onChangeFn = jest.fn();
|
|
28
|
+
var defaultProps = {
|
|
29
|
+
mode: Mode.Editing,
|
|
30
|
+
isReltioCrosswalk: true,
|
|
31
|
+
onAddAttributes: onAddFn,
|
|
32
|
+
onDeleteAttribute: onDeleteFn,
|
|
33
|
+
onChangeAttribute: onChangeFn
|
|
34
|
+
};
|
|
35
|
+
var setUp = function (_a) {
|
|
36
|
+
var props = _a.props, _b = _a.alwaysVisibleAttributes, alwaysVisibleAttributes = _b === void 0 ? [] : _b;
|
|
37
|
+
return render(React.createElement(AlwaysVisibleAttributesContext.Provider, { value: alwaysVisibleAttributes },
|
|
38
|
+
React.createElement(MdmModuleProvider, { values: mdmValues },
|
|
39
|
+
React.createElement(SimpleAttributeEditor, __assign({}, defaultProps, props)))));
|
|
40
|
+
};
|
|
30
41
|
it('should render just text, if there is only READ permission', function () {
|
|
31
42
|
var props = {
|
|
32
43
|
attributeValue: {
|
|
@@ -37,17 +48,11 @@ describe('SimpleAttributeEditor without permissions', function () {
|
|
|
37
48
|
access: ['READ'],
|
|
38
49
|
type: 'String',
|
|
39
50
|
uri: 'configuration/entityTypes/HCA/attributes/InternalCustomer'
|
|
40
|
-
}
|
|
41
|
-
mode: Mode.Editing,
|
|
42
|
-
isReltioCrosswalk: true,
|
|
43
|
-
onAddAttributes: onAddFn,
|
|
44
|
-
onDeleteAttribute: onDeleteFn,
|
|
45
|
-
onChangeAttribute: onChangeFn
|
|
51
|
+
}
|
|
46
52
|
};
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
expect(
|
|
50
|
-
expect(findActionButtons(simpleAttributeEditor).length).toBe(0);
|
|
53
|
+
setUp({ props: props });
|
|
54
|
+
expect(screen.getByText('some string')).toBeInTheDocument();
|
|
55
|
+
expect(screen.queryByTestId('reltio-delete-simple-attribute-button')).not.toBeInTheDocument();
|
|
51
56
|
});
|
|
52
57
|
it('should render text and DELETE button, if there are only READ and DELETE permission', function () {
|
|
53
58
|
var props = {
|
|
@@ -59,16 +64,40 @@ describe('SimpleAttributeEditor without permissions', function () {
|
|
|
59
64
|
access: ['READ', 'DELETE'],
|
|
60
65
|
type: 'String',
|
|
61
66
|
uri: 'configuration/entityTypes/HCA/attributes/InternalCustomer'
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
setUp({ props: props });
|
|
70
|
+
expect(screen.getByText('some string')).toBeInTheDocument();
|
|
71
|
+
expect(screen.getByTestId('reltio-delete-simple-attribute-button')).toBeInTheDocument();
|
|
72
|
+
});
|
|
73
|
+
it('should render always visible attribute without value correct, if there are only READ permission', function () {
|
|
74
|
+
var props = {
|
|
75
|
+
attributeValue: {
|
|
76
|
+
uri: 'uri$$'
|
|
62
77
|
},
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
78
|
+
attributeType: {
|
|
79
|
+
access: ['READ'],
|
|
80
|
+
type: 'String',
|
|
81
|
+
uri: 'configuration/entityTypes/HCA/attributes/InternalCustomer'
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
setUp({ props: props, alwaysVisibleAttributes: ['configuration/entityTypes/HCA/attributes/InternalCustomer'] });
|
|
85
|
+
expect(screen.queryByRole('textbox')).not.toBeInTheDocument();
|
|
86
|
+
expect(screen.queryByTestId('reltio-delete-simple-attribute-button')).not.toBeInTheDocument();
|
|
87
|
+
});
|
|
88
|
+
it('should render always visible attribute without value correct, if there are only READ and DELETE permission', function () {
|
|
89
|
+
var props = {
|
|
90
|
+
attributeValue: {
|
|
91
|
+
uri: 'uri$$'
|
|
92
|
+
},
|
|
93
|
+
attributeType: {
|
|
94
|
+
access: ['READ', 'DELETE'],
|
|
95
|
+
type: 'String',
|
|
96
|
+
uri: 'configuration/entityTypes/HCA/attributes/InternalCustomer'
|
|
97
|
+
}
|
|
68
98
|
};
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
expect(
|
|
72
|
-
expect(findActionButtons(simpleAttributeEditor).length).toBe(1);
|
|
99
|
+
setUp({ props: props, alwaysVisibleAttributes: ['configuration/entityTypes/HCA/attributes/InternalCustomer'] });
|
|
100
|
+
expect(screen.queryByRole('textbox')).not.toBeInTheDocument();
|
|
101
|
+
expect(screen.getByTestId('reltio-delete-simple-attribute-button')).toBeInTheDocument();
|
|
73
102
|
});
|
|
74
103
|
});
|
|
@@ -1,10 +1,16 @@
|
|
|
1
|
+
import { useContext, useMemo } from 'react';
|
|
1
2
|
import { checkCanCreateAttribute, checkCanDeleteAttribute, checkCanEditAttribute } from '@reltio/mdm-sdk';
|
|
2
3
|
import { useAttributeValueConfigPermissions } from '../contexts/ConfigPermissionsContext';
|
|
4
|
+
import { AlwaysVisibleAttributesContext } from '../contexts/AllwaysVisibleAttributesContext';
|
|
3
5
|
export var useAttributeValuePermissions = function (_a) {
|
|
4
6
|
var attributeType = _a.attributeType, attributeValue = _a.attributeValue, isReltioCrosswalk = _a.isReltioCrosswalk, mode = _a.mode;
|
|
5
7
|
var _b = useAttributeValueConfigPermissions(attributeValue.uri), configCanCreate = _b.canCreate, configCanUpdate = _b.canUpdate, configCanDelete = _b.canDelete;
|
|
8
|
+
var alwaysVisibleAttributes = useContext(AlwaysVisibleAttributesContext);
|
|
9
|
+
var isAlwaysVisible = useMemo(function () { return alwaysVisibleAttributes === null || alwaysVisibleAttributes === void 0 ? void 0 : alwaysVisibleAttributes.includes(attributeType.uri); }, [attributeType.uri, alwaysVisibleAttributes]);
|
|
6
10
|
var canCreate = configCanCreate && checkCanCreateAttribute({ attributeType: attributeType, mode: mode });
|
|
7
|
-
var canEdit = configCanUpdate &&
|
|
8
|
-
|
|
11
|
+
var canEdit = configCanUpdate &&
|
|
12
|
+
checkCanEditAttribute({ attributeType: attributeType, attributeValue: attributeValue, mode: mode, isReltioCrosswalk: isReltioCrosswalk, isAlwaysVisible: isAlwaysVisible });
|
|
13
|
+
var canDelete = configCanDelete &&
|
|
14
|
+
checkCanDeleteAttribute({ attributeType: attributeType, attributeValue: attributeValue, mode: mode, isReltioCrosswalk: isReltioCrosswalk, isAlwaysVisible: isAlwaysVisible });
|
|
9
15
|
return { canCreate: canCreate, canEdit: canEdit, canDelete: canDelete };
|
|
10
16
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reltio/components",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.1965",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE FILE",
|
|
5
5
|
"main": "./cjs/index.js",
|
|
6
6
|
"module": "./esm/index.js",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"@fluentui/react-context-selector": "^9.1.26",
|
|
9
9
|
"@react-google-maps/api": "2.7.0",
|
|
10
10
|
"@react-sigma/core": "3.4.0",
|
|
11
|
-
"@reltio/mdm-sdk": "^1.4.
|
|
11
|
+
"@reltio/mdm-sdk": "^1.4.1869",
|
|
12
12
|
"d3-cloud": "^1.2.5",
|
|
13
13
|
"d3-geo": "^2.0.1",
|
|
14
14
|
"d3-hierarchy": "^2.0.0",
|