@reltio/interactions 1.4.1585 → 1.4.1586-mui5
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/index.ts +1 -0
- package/package.json +38 -21
- package/public/bundle.js +205 -0
- package/public/bundle.js.LICENSE.txt +79 -0
- package/public/package.json +22 -0
- package/scripts/build/index.js +20 -0
- package/src/InteractionsTableView/InteractionsTable/InteractionsTable.tsx +87 -0
- package/src/InteractionsTableView/InteractionsTable/__tests__/InteractionsTable.test.js +146 -0
- package/src/InteractionsTableView/InteractionsTable/cell-renderers/ActorsRenderer.js +57 -0
- package/src/InteractionsTableView/InteractionsTable/cell-renderers/AttributesRenderer.js +50 -0
- package/src/InteractionsTableView/InteractionsTable/cell-renderers/BlobRenderer.js +14 -0
- package/src/InteractionsTableView/InteractionsTable/cell-renderers/DefaultCellValueRenderer.js +22 -0
- package/src/InteractionsTableView/InteractionsTable/cell-renderers/HeadCellRenderer.js +16 -0
- package/src/InteractionsTableView/InteractionsTable/cell-renderers/LinkRenderer.js +22 -0
- package/src/InteractionsTableView/InteractionsTable/cell-renderers/RowCellRenderer.js +31 -0
- package/src/InteractionsTableView/InteractionsTable/cell-renderers/__tests__/ActorsRenderer.test.js +87 -0
- package/src/InteractionsTableView/InteractionsTable/cell-renderers/__tests__/AttributesRenderer.test.js +118 -0
- package/src/InteractionsTableView/InteractionsTable/cell-renderers/__tests__/DefaultCellValueRenderer.test.js +23 -0
- package/src/InteractionsTableView/InteractionsTable/cell-renderers/__tests__/LinkRenderer.test.js +20 -0
- package/src/InteractionsTableView/InteractionsTable/cell-renderers/__tests__/RowCellRenderer.test.js +53 -0
- package/src/InteractionsTableView/InteractionsTable/cell-renderers/styles.js +67 -0
- package/src/InteractionsTableView/InteractionsTable/helpers/__tests__/dataHelpers.spec.js +286 -0
- package/src/InteractionsTableView/InteractionsTable/helpers/dataHelpers.ts +120 -0
- package/src/InteractionsTableView/InteractionsTable/styles.ts +29 -0
- package/src/InteractionsTableView/InteractionsTableHeader/InteractionTypeSelector/InteractionTypeSelector.tsx +26 -0
- package/src/InteractionsTableView/InteractionsTableHeader/InteractionTypeSelector/__tests__/InteractionTypeSelector.test.js +34 -0
- package/src/InteractionsTableView/InteractionsTableHeader/InteractionsTableHeader.js +76 -0
- package/src/InteractionsTableView/InteractionsTableHeader/__tests__/InteractionsTableHeader.test.js +106 -0
- package/src/InteractionsTableView/InteractionsTableHeader/styles.js +21 -0
- package/src/InteractionsTableView/__tests__/InteractionsTableView.test.js +570 -0
- package/src/InteractionsTableView/__tests__/stateReducer.test.js +260 -0
- package/src/InteractionsTableView/helpers/__tests__/filtersHelper.test.js +221 -0
- package/src/InteractionsTableView/helpers/__tests__/tableHelper.test.js +300 -0
- package/src/InteractionsTableView/helpers/filtersHelpers.ts +18 -0
- package/src/InteractionsTableView/helpers/tableHelpers.ts +157 -0
- package/src/InteractionsTableView/hooks/useInteractions.ts +45 -0
- package/src/InteractionsTableView/index.tsx +200 -0
- package/src/InteractionsTableView/stateReducer.ts +132 -0
- package/src/InteractionsTableView/styles.ts +18 -0
- package/src/InteractionsTableView/types/index.ts +8 -0
- package/src/index.tsx +59 -0
- package/stories/Interactions.stories.js +31 -0
- package/stories/utils/entity.js +11 -0
- package/stories/utils/interactions.js +837 -0
- package/stories/utils/interactionsViewConfig.js +6 -0
- package/stories/utils/mdmStore.js +28 -0
- package/stories/utils/metadata.js +7221 -0
- package/tsconfig.json +4 -0
- package/webpack.config.js +10 -0
- package/bundle.js +0 -2
- package/bundle.js.LICENSE.txt +0 -36
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {shallow} from 'enzyme';
|
|
3
|
+
import {act} from 'react-dom/test-utils';
|
|
4
|
+
|
|
5
|
+
import * as reactRedux from 'react-redux';
|
|
6
|
+
import mdmModule from '@reltio/mdm-module';
|
|
7
|
+
import AttributesRenderer from '../AttributesRenderer';
|
|
8
|
+
import {ReadOnlyAttributesList, ViewMoreToggle} from '@reltio/components';
|
|
9
|
+
|
|
10
|
+
describe('AttributesRenderer tests', () => {
|
|
11
|
+
beforeAll(() => {
|
|
12
|
+
jest.spyOn(reactRedux, 'useSelector').mockImplementation((selector) => selector());
|
|
13
|
+
jest.spyOn(mdmModule.selectors, 'getMetadata').mockReturnValue({
|
|
14
|
+
interactionTypes: [
|
|
15
|
+
{
|
|
16
|
+
uri: 'configuration/interactionsTypes/1',
|
|
17
|
+
attributes: [
|
|
18
|
+
{
|
|
19
|
+
uri: 'configuration/interactionsTypes/1/attributes/String',
|
|
20
|
+
name: 'String'
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
uri: 'configuration/interactionsTypes/1/attributes/Number',
|
|
24
|
+
name: 'Number'
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
]
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const props = {
|
|
33
|
+
value: {
|
|
34
|
+
Number: {
|
|
35
|
+
uri: 'configuration/interactionsTypes/1/attributes/Number/1',
|
|
36
|
+
value: '1'
|
|
37
|
+
},
|
|
38
|
+
String: {
|
|
39
|
+
uri: 'configuration/interactionsTypes/1/attributes/String/1',
|
|
40
|
+
value: '1'
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
rowValue: {
|
|
44
|
+
rawValue: {
|
|
45
|
+
uri: 'interactions/1',
|
|
46
|
+
type: 'configuration/interactionsTypes/1',
|
|
47
|
+
attributes: {
|
|
48
|
+
String: {
|
|
49
|
+
uri: 'configuration/interactionsTypes/1/attributes/String/1',
|
|
50
|
+
value: '1'
|
|
51
|
+
},
|
|
52
|
+
Number: {
|
|
53
|
+
uri: 'configuration/interactionsTypes/1/attributes/Number/1',
|
|
54
|
+
value: '1'
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
columnData: {
|
|
60
|
+
maxAttrsToShow: 2
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
it('should render ReadOnlyAttributesList with correct props', () => {
|
|
65
|
+
const wrapper = shallow(<AttributesRenderer {...props} />);
|
|
66
|
+
expect(wrapper.find(ReadOnlyAttributesList).props()).toMatchObject({
|
|
67
|
+
entity: {attributes: props.value},
|
|
68
|
+
attrTypes: [
|
|
69
|
+
{
|
|
70
|
+
uri: 'configuration/interactionsTypes/1/attributes/Number',
|
|
71
|
+
name: 'Number'
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
uri: 'configuration/interactionsTypes/1/attributes/String',
|
|
75
|
+
name: 'String'
|
|
76
|
+
}
|
|
77
|
+
],
|
|
78
|
+
drawLines: false
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('should render ViewMoreToggle if attributes count exceeds maxAttrsToShow', () => {
|
|
83
|
+
const wrapper = shallow(<AttributesRenderer {...props} />);
|
|
84
|
+
expect(wrapper.find(ViewMoreToggle)).toHaveLength(0);
|
|
85
|
+
wrapper.setProps({columnData: {maxAttrsToShow: 1}});
|
|
86
|
+
expect(wrapper.find(ViewMoreToggle)).toHaveLength(1);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('should collapse/expand attributes on view more/view less click', () => {
|
|
90
|
+
const wrapper = shallow(<AttributesRenderer {...props} columnData={{maxAttrsToShow: 1}} />);
|
|
91
|
+
expect(wrapper.find(ViewMoreToggle).prop('active')).toBe(false);
|
|
92
|
+
expect(wrapper.find(ReadOnlyAttributesList).prop('entity')).toEqual({
|
|
93
|
+
attributes: {
|
|
94
|
+
Number: {
|
|
95
|
+
uri: 'configuration/interactionsTypes/1/attributes/Number/1',
|
|
96
|
+
value: '1'
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
act(() => {
|
|
101
|
+
wrapper.find(ViewMoreToggle).simulate('click');
|
|
102
|
+
});
|
|
103
|
+
expect(wrapper.find(ViewMoreToggle).prop('active')).toBe(true);
|
|
104
|
+
expect(wrapper.find(ReadOnlyAttributesList).prop('entity')).toEqual({attributes: props.value});
|
|
105
|
+
act(() => {
|
|
106
|
+
wrapper.find(ViewMoreToggle).simulate('click');
|
|
107
|
+
});
|
|
108
|
+
expect(wrapper.find(ViewMoreToggle).prop('active')).toBe(false);
|
|
109
|
+
expect(wrapper.find(ReadOnlyAttributesList).prop('entity')).toEqual({
|
|
110
|
+
attributes: {
|
|
111
|
+
Number: {
|
|
112
|
+
uri: 'configuration/interactionsTypes/1/attributes/Number/1',
|
|
113
|
+
value: '1'
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {shallow} from 'enzyme';
|
|
3
|
+
|
|
4
|
+
import {DataTypeValue} from '@reltio/components';
|
|
5
|
+
import DefaultCellValueRenderer from '../DefaultCellValueRenderer';
|
|
6
|
+
|
|
7
|
+
describe('Default cell value renderer tests', () => {
|
|
8
|
+
it('should render DataTypeValue with correct props', () => {
|
|
9
|
+
const props = {
|
|
10
|
+
value: 'value',
|
|
11
|
+
columnData: {
|
|
12
|
+
dataTypeDefinition: {
|
|
13
|
+
type: 'String'
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const wrapper = shallow(<DefaultCellValueRenderer {...props} />);
|
|
18
|
+
expect(wrapper.find(DataTypeValue).props()).toEqual({
|
|
19
|
+
value: props.value,
|
|
20
|
+
dataTypeDefinition: props.columnData.dataTypeDefinition
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
});
|
package/src/InteractionsTableView/InteractionsTable/cell-renderers/__tests__/LinkRenderer.test.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {shallow} from 'enzyme';
|
|
3
|
+
|
|
4
|
+
import LinkRenderer from '../LinkRenderer';
|
|
5
|
+
import Link from '@mui/material/Link';
|
|
6
|
+
|
|
7
|
+
describe('LinkRenderer tests', () => {
|
|
8
|
+
it('should render MUI Link with correct props', () => {
|
|
9
|
+
const props = {
|
|
10
|
+
value: 'http://some.url'
|
|
11
|
+
};
|
|
12
|
+
const wrapper = shallow(<LinkRenderer {...props} />);
|
|
13
|
+
expect(wrapper.find(Link).props()).toMatchObject({
|
|
14
|
+
href: props.value,
|
|
15
|
+
target: '_blank',
|
|
16
|
+
underline: 'none',
|
|
17
|
+
children: props.value
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
});
|
package/src/InteractionsTableView/InteractionsTable/cell-renderers/__tests__/RowCellRenderer.test.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {mount} from 'enzyme';
|
|
3
|
+
import RowCellRenderer from '../RowCellRenderer';
|
|
4
|
+
import {pluck, prop} from 'ramda';
|
|
5
|
+
import {isActiveObject} from '@reltio/mdm-sdk';
|
|
6
|
+
|
|
7
|
+
jest.mock('@reltio/mdm-sdk', () => ({
|
|
8
|
+
...jest.requireActual('@reltio/mdm-sdk'),
|
|
9
|
+
isActiveObject: jest.fn()
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
describe('Row cell renderer scenario', () => {
|
|
13
|
+
let wrapper, props, interaction;
|
|
14
|
+
beforeAll(() => {
|
|
15
|
+
isActiveObject.mockReturnValue(true);
|
|
16
|
+
|
|
17
|
+
interaction = {
|
|
18
|
+
uri: '123'
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
props = {
|
|
22
|
+
cell: {values: [1, 2, 3]},
|
|
23
|
+
CellValueRenderer: jest.fn(({value}) => value),
|
|
24
|
+
rowValue: {interaction},
|
|
25
|
+
isSorted: false
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
wrapper = mount(<RowCellRenderer {...props} />);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
afterAll(() => {
|
|
33
|
+
jest.restoreAllMocks();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
afterEach(() => {
|
|
37
|
+
jest.clearAllMocks();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('should call CellValueRenderer for all cell values', () => {
|
|
41
|
+
expect(pluck(0, props.CellValueRenderer.mock.calls).map(prop('value'))).toEqual([1, 2, 3]);
|
|
42
|
+
expect(wrapper.text()).toBe('123');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('should apply sorted styles if cell is sorted', () => {
|
|
46
|
+
const sortedClass = '--sorted';
|
|
47
|
+
expect(wrapper.find('div').prop('className').includes(sortedClass)).toBe(false);
|
|
48
|
+
wrapper.setProps({
|
|
49
|
+
isSorted: true
|
|
50
|
+
});
|
|
51
|
+
expect(wrapper.find('div').prop('className').includes(sortedClass)).toBe(true);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import {makeStyles} from '@mui/styles';
|
|
2
|
+
|
|
3
|
+
const defaultWrapperStyles = {
|
|
4
|
+
padding: '15px 25px 0 25px',
|
|
5
|
+
'&:last-child': {
|
|
6
|
+
paddingBottom: '15px'
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const useStyles = makeStyles((theme) => ({
|
|
11
|
+
headCell: {
|
|
12
|
+
display: 'flex',
|
|
13
|
+
alignItems: 'center',
|
|
14
|
+
height: '100%',
|
|
15
|
+
fontSize: '12px'
|
|
16
|
+
},
|
|
17
|
+
rowCell: {
|
|
18
|
+
fontSize: '13px',
|
|
19
|
+
overflow: 'hidden',
|
|
20
|
+
overflowWrap: 'break-word',
|
|
21
|
+
wordWrap: 'break-word' // for IE
|
|
22
|
+
},
|
|
23
|
+
'row-cell--sorted': {
|
|
24
|
+
color: 'rgba(0,0,0,0.87)'
|
|
25
|
+
},
|
|
26
|
+
actorsWrapper: {
|
|
27
|
+
paddingRight: '25px',
|
|
28
|
+
paddingLeft: '15px',
|
|
29
|
+
'&:last-child': {
|
|
30
|
+
paddingBottom: '15px'
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
memberWrapper: {
|
|
34
|
+
display: 'flex',
|
|
35
|
+
paddingTop: '15px',
|
|
36
|
+
boxSizing: 'border-box',
|
|
37
|
+
position: 'relative'
|
|
38
|
+
},
|
|
39
|
+
entityLabel: {
|
|
40
|
+
fontSize: '15px',
|
|
41
|
+
display: 'inline-block',
|
|
42
|
+
overflowX: 'hidden',
|
|
43
|
+
margin: '-2px 0 -1px 45px'
|
|
44
|
+
},
|
|
45
|
+
entityAvatar: {
|
|
46
|
+
transform: 'scale(0.5)',
|
|
47
|
+
position: 'absolute',
|
|
48
|
+
left: 0,
|
|
49
|
+
top: '2px'
|
|
50
|
+
},
|
|
51
|
+
defaultWrapper: defaultWrapperStyles,
|
|
52
|
+
blobWrapper: {
|
|
53
|
+
...defaultWrapperStyles,
|
|
54
|
+
whiteSpace: 'pre-wrap'
|
|
55
|
+
},
|
|
56
|
+
link: {
|
|
57
|
+
cursor: 'pointer',
|
|
58
|
+
color: theme.palette.primary.main
|
|
59
|
+
},
|
|
60
|
+
attributesWrapper: {
|
|
61
|
+
padding: '15px 25px 10px 25px',
|
|
62
|
+
color: 'rgba(0,0,0,0.87)'
|
|
63
|
+
},
|
|
64
|
+
viewMore: {
|
|
65
|
+
marginLeft: '-5px'
|
|
66
|
+
}
|
|
67
|
+
}));
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import {getBasicTableColumnsData, getBasicTableRowsData, getStaticRowCellHeight} from '../dataHelpers';
|
|
2
|
+
import {DataTypes} from '@reltio/mdm-sdk';
|
|
3
|
+
import {defaultGetRowCellHeight} from '@reltio/components';
|
|
4
|
+
import HeadCellRenderer from '../../cell-renderers/HeadCellRenderer';
|
|
5
|
+
import ActorsRenderer from '../../cell-renderers/ActorsRenderer';
|
|
6
|
+
import {ACTORS_COLUMN_ID, ATTRIBUTES_COLUMN_ID, INTERACTION_TYPE_COLUMN_ID} from '../../../helpers/tableHelpers';
|
|
7
|
+
import {pick, pluck} from 'ramda';
|
|
8
|
+
import LinkRenderer from '../../cell-renderers/LinkRenderer';
|
|
9
|
+
import BlobRender from '../../cell-renderers/BlobRenderer';
|
|
10
|
+
import DefaultCellValueRenderer from '../../cell-renderers/DefaultCellValueRenderer';
|
|
11
|
+
import AttributesRenderer from '../../cell-renderers/AttributesRenderer';
|
|
12
|
+
|
|
13
|
+
jest.mock('@reltio/components', () => ({
|
|
14
|
+
...jest.requireActual('@reltio/components'),
|
|
15
|
+
defaultGetRowCellHeight: jest.fn()
|
|
16
|
+
}));
|
|
17
|
+
|
|
18
|
+
describe('getBasicTableColumnsData scenario', () => {
|
|
19
|
+
it('should mark columns as resizable and sortable', () => {
|
|
20
|
+
const columnsData = [
|
|
21
|
+
{
|
|
22
|
+
id: 'members',
|
|
23
|
+
label: 'Entity label',
|
|
24
|
+
dataTypeDefinition: {
|
|
25
|
+
type: DataTypes.TYPE_STRING
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
];
|
|
29
|
+
expect(getBasicTableColumnsData(columnsData)[0]).toMatchObject({
|
|
30
|
+
...columnsData[0],
|
|
31
|
+
resizable: true,
|
|
32
|
+
sortable: true
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('should calculate nested path for columns', () => {
|
|
37
|
+
const columnsData = [
|
|
38
|
+
{
|
|
39
|
+
id: 'attributes.Nested.String',
|
|
40
|
+
label: 'Nested String',
|
|
41
|
+
dataTypeDefinition: {
|
|
42
|
+
type: DataTypes.TYPE_STRING
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
];
|
|
46
|
+
expect(getBasicTableColumnsData(columnsData)[0]).toMatchObject({
|
|
47
|
+
...columnsData[0],
|
|
48
|
+
nestedPath: ['Nested']
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('should assign head cell renderer for columns', () => {
|
|
53
|
+
const columnsData = [
|
|
54
|
+
{
|
|
55
|
+
id: 'attributes.Nested.String',
|
|
56
|
+
label: 'Nested String',
|
|
57
|
+
dataTypeDefinition: {
|
|
58
|
+
type: DataTypes.TYPE_STRING
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
];
|
|
62
|
+
expect(getBasicTableColumnsData(columnsData)[0]).toMatchObject({
|
|
63
|
+
...columnsData[0],
|
|
64
|
+
headCellRenderer: HeadCellRenderer
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('should assign row cell value renderer for columns', () => {
|
|
69
|
+
const columnsData = [
|
|
70
|
+
{
|
|
71
|
+
id: ACTORS_COLUMN_ID,
|
|
72
|
+
dataTypeDefinition: {
|
|
73
|
+
type: DataTypes.TYPE_STRING
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
id: 'attributes.URL',
|
|
78
|
+
dataTypeDefinition: {
|
|
79
|
+
type: DataTypes.TYPE_URL
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
id: 'attributes.BLOG_URL',
|
|
84
|
+
dataTypeDefinition: {
|
|
85
|
+
type: DataTypes.TYPE_BLOG_URL
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
id: 'attributes.IMAGE_URL',
|
|
90
|
+
dataTypeDefinition: {
|
|
91
|
+
type: DataTypes.TYPE_IMAGE_URL
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
id: 'attributes.EMAIL',
|
|
96
|
+
dataTypeDefinition: {
|
|
97
|
+
type: DataTypes.TYPE_EMAIL
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
id: 'attributes.BLOB',
|
|
102
|
+
dataTypeDefinition: {
|
|
103
|
+
type: DataTypes.TYPE_BLOB
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
id: 'attributes.Nested.String',
|
|
108
|
+
dataTypeDefinition: {
|
|
109
|
+
type: DataTypes.TYPE_STRING
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
{id: ATTRIBUTES_COLUMN_ID}
|
|
113
|
+
];
|
|
114
|
+
const result = getBasicTableColumnsData(columnsData);
|
|
115
|
+
expect(pluck('rowCellValueRenderer', result)).toEqual([
|
|
116
|
+
ActorsRenderer,
|
|
117
|
+
LinkRenderer,
|
|
118
|
+
LinkRenderer,
|
|
119
|
+
LinkRenderer,
|
|
120
|
+
LinkRenderer,
|
|
121
|
+
BlobRender,
|
|
122
|
+
DefaultCellValueRenderer,
|
|
123
|
+
AttributesRenderer
|
|
124
|
+
]);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
describe('row cell height scenario', () => {
|
|
129
|
+
it('should return height based on values count for actors', () => {
|
|
130
|
+
const member1 = {};
|
|
131
|
+
const member2 = {};
|
|
132
|
+
const value = {
|
|
133
|
+
columnData: {
|
|
134
|
+
id: ACTORS_COLUMN_ID
|
|
135
|
+
},
|
|
136
|
+
cell: {
|
|
137
|
+
values: [
|
|
138
|
+
[
|
|
139
|
+
{
|
|
140
|
+
members: [member1, member2]
|
|
141
|
+
}
|
|
142
|
+
]
|
|
143
|
+
]
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
expect(getStaticRowCellHeight(value)).toBe(2 * 33 + 15);
|
|
147
|
+
});
|
|
148
|
+
it('should return height based on attributes count for attributes', () => {
|
|
149
|
+
const value = {
|
|
150
|
+
columnData: {
|
|
151
|
+
id: ATTRIBUTES_COLUMN_ID,
|
|
152
|
+
maxAttrsToShow: 2
|
|
153
|
+
},
|
|
154
|
+
cell: {
|
|
155
|
+
values: [
|
|
156
|
+
{
|
|
157
|
+
name1: {},
|
|
158
|
+
name2: {}
|
|
159
|
+
}
|
|
160
|
+
]
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
expect(getStaticRowCellHeight(value)).toBe(2 * 26 + 25);
|
|
164
|
+
});
|
|
165
|
+
it('should return height based on max attributes to show count for attributes', () => {
|
|
166
|
+
const value = {
|
|
167
|
+
columnData: {
|
|
168
|
+
id: ATTRIBUTES_COLUMN_ID,
|
|
169
|
+
maxAttrsToShow: 2
|
|
170
|
+
},
|
|
171
|
+
cell: {
|
|
172
|
+
values: [
|
|
173
|
+
{
|
|
174
|
+
name1: {},
|
|
175
|
+
name2: {},
|
|
176
|
+
name3: {}
|
|
177
|
+
}
|
|
178
|
+
]
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
expect(getStaticRowCellHeight(value)).toBe(2 * 26 + 49);
|
|
182
|
+
});
|
|
183
|
+
it('should return default height for other cells', () => {
|
|
184
|
+
const DEFAULT_HEIGHT = 48;
|
|
185
|
+
defaultGetRowCellHeight.mockReturnValueOnce(DEFAULT_HEIGHT);
|
|
186
|
+
const value = {
|
|
187
|
+
columnData: {
|
|
188
|
+
id: 'attributes.Nested.String'
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
expect(getStaticRowCellHeight(value)).toBe(DEFAULT_HEIGHT);
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
describe('get table data scenario', () => {
|
|
196
|
+
it('should return correct table data', () => {
|
|
197
|
+
const columnsData = [
|
|
198
|
+
{
|
|
199
|
+
id: 'timestamp'
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
id: INTERACTION_TYPE_COLUMN_ID
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
id: ACTORS_COLUMN_ID
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
id: 'attributes.String',
|
|
209
|
+
label: 'String',
|
|
210
|
+
dataTypeDefinition: {
|
|
211
|
+
type: DataTypes.TYPE_STRING
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
id: ATTRIBUTES_COLUMN_ID,
|
|
216
|
+
attrsToShow: {
|
|
217
|
+
'configuration/interactionTypes/Interaciton': [
|
|
218
|
+
'configuration/interactionTypes/Interaciton/attributes/Number'
|
|
219
|
+
]
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
];
|
|
223
|
+
const interactions = [
|
|
224
|
+
{
|
|
225
|
+
type: 'configuration/interactionTypes/Interaciton',
|
|
226
|
+
timestamp: 12345,
|
|
227
|
+
members: {
|
|
228
|
+
EntityType: {
|
|
229
|
+
members: [{type: 'configuration/entityTypes/EntityType', label: 'Entity'}],
|
|
230
|
+
type: 'configuration/interactionTypes/Interaciton/memberTypes/EntityType',
|
|
231
|
+
uri: 'interactions/Reltio+8778306289485/members/EntityType'
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
attributes: {
|
|
235
|
+
String: [
|
|
236
|
+
{
|
|
237
|
+
ov: true,
|
|
238
|
+
value: 'String',
|
|
239
|
+
uri: 'interactions/Reltio+8778306289485/attributes/String/6',
|
|
240
|
+
type: 'configuration/interactionTypes/Interaciton/attributes/String'
|
|
241
|
+
}
|
|
242
|
+
],
|
|
243
|
+
Number: [
|
|
244
|
+
{
|
|
245
|
+
ov: true,
|
|
246
|
+
value: 'Number',
|
|
247
|
+
uri: 'interactions/Reltio+8778306289485/attributes/Number/6',
|
|
248
|
+
type: 'configuration/interactionTypes/Interaciton/attributes/Number'
|
|
249
|
+
}
|
|
250
|
+
]
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
];
|
|
254
|
+
const metadata = {
|
|
255
|
+
entityTypes: [{uri: 'configuration/entityTypes/EntityType'}],
|
|
256
|
+
interactionTypes: [
|
|
257
|
+
{
|
|
258
|
+
uri: 'configuration/interactionTypes/Interaciton',
|
|
259
|
+
memberTypes: [
|
|
260
|
+
{
|
|
261
|
+
name: 'EntityType'
|
|
262
|
+
}
|
|
263
|
+
],
|
|
264
|
+
attributes: [
|
|
265
|
+
{
|
|
266
|
+
type: 'String',
|
|
267
|
+
name: 'String',
|
|
268
|
+
uri: 'configuration/interactionTypes/Interaciton/attributes/String'
|
|
269
|
+
}
|
|
270
|
+
]
|
|
271
|
+
}
|
|
272
|
+
]
|
|
273
|
+
};
|
|
274
|
+
const rowsData = getBasicTableRowsData(interactions, columnsData, metadata);
|
|
275
|
+
expect(rowsData).toEqual([
|
|
276
|
+
expect.objectContaining({
|
|
277
|
+
timestamp: interactions[0].timestamp,
|
|
278
|
+
[INTERACTION_TYPE_COLUMN_ID]: interactions[0].type,
|
|
279
|
+
[ACTORS_COLUMN_ID]: interactions[0].members,
|
|
280
|
+
'attributes.String': [interactions[0].attributes.String[0].value],
|
|
281
|
+
[ATTRIBUTES_COLUMN_ID]: pick(['Number'], interactions[0].attributes),
|
|
282
|
+
rawValue: interactions[0]
|
|
283
|
+
})
|
|
284
|
+
]);
|
|
285
|
+
});
|
|
286
|
+
});
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import HeadCellRenderer from '../cell-renderers/HeadCellRenderer';
|
|
2
|
+
import ActorsRenderer from '../cell-renderers/ActorsRenderer';
|
|
3
|
+
import DefaultCellValueRenderer from '../cell-renderers/DefaultCellValueRenderer';
|
|
4
|
+
import {ColumnData, defaultGetRowCellHeight} from '@reltio/components';
|
|
5
|
+
import {assoc, cond, length, map, path, pathEq, pickBy, pipe, prop, reduce, slice, split, T, values} from 'ramda';
|
|
6
|
+
import {
|
|
7
|
+
DataTypes,
|
|
8
|
+
getActorsForInteraction,
|
|
9
|
+
getAttributeValuesByPath,
|
|
10
|
+
Interaction,
|
|
11
|
+
makeAttrTypeUri,
|
|
12
|
+
Metadata
|
|
13
|
+
} from '@reltio/mdm-sdk';
|
|
14
|
+
import {ACTORS_COLUMN_ID, ATTRIBUTES_COLUMN_ID, INTERACTION_TYPE_COLUMN_ID} from '../../helpers/tableHelpers';
|
|
15
|
+
import BlobRender from '../cell-renderers/BlobRenderer';
|
|
16
|
+
import LinkRenderer from '../cell-renderers/LinkRenderer';
|
|
17
|
+
import AttributesRenderer from '../cell-renderers/AttributesRenderer';
|
|
18
|
+
|
|
19
|
+
const getInteractionAttributeValues = (attrPath, interaction) =>
|
|
20
|
+
pipe(path(['attributes']), getAttributeValuesByPath(attrPath))(interaction);
|
|
21
|
+
|
|
22
|
+
const getAttrPathFromColumnId = pipe(split('.'), slice(1, Infinity));
|
|
23
|
+
|
|
24
|
+
const getRowValueByColumn = (columnData: ColumnData, interaction: Interaction, metadata: Metadata) => {
|
|
25
|
+
switch (columnData.id) {
|
|
26
|
+
case ACTORS_COLUMN_ID:
|
|
27
|
+
return getActorsForInteraction(metadata, interaction);
|
|
28
|
+
case 'timestamp':
|
|
29
|
+
return interaction.timestamp;
|
|
30
|
+
case INTERACTION_TYPE_COLUMN_ID:
|
|
31
|
+
return interaction.type;
|
|
32
|
+
case ATTRIBUTES_COLUMN_ID: {
|
|
33
|
+
const urisToShow = path(['attrsToShow', interaction.type], columnData);
|
|
34
|
+
const isAttrToShow = (values, name) => urisToShow.includes(makeAttrTypeUri(interaction.type, name));
|
|
35
|
+
return urisToShow ? pickBy(isAttrToShow, interaction.attributes) : interaction.attributes;
|
|
36
|
+
}
|
|
37
|
+
default: {
|
|
38
|
+
const attrPath = getAttrPathFromColumnId(columnData.id);
|
|
39
|
+
return getInteractionAttributeValues(attrPath, interaction);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const getBasicTableRowsData = (interactions: Interaction[], columnsData: ColumnData, metadata: Metadata) =>
|
|
45
|
+
interactions.map((interaction) =>
|
|
46
|
+
pipe(
|
|
47
|
+
reduce(
|
|
48
|
+
(acc, columnData) => assoc(columnData.id, getRowValueByColumn(columnData, interaction, metadata), acc),
|
|
49
|
+
{}
|
|
50
|
+
),
|
|
51
|
+
assoc('rawValue', interaction)
|
|
52
|
+
)(columnsData)
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const getNestedPathByColumnId = (columnId) => {
|
|
56
|
+
if (columnId.startsWith('attributes.')) {
|
|
57
|
+
const attrPath = getAttrPathFromColumnId(columnId);
|
|
58
|
+
return attrPath.length > 1 ? attrPath.slice(0, -1) : null;
|
|
59
|
+
} else {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const getCellValueRenderer = (columnData) => {
|
|
65
|
+
if (columnData.id === ACTORS_COLUMN_ID) {
|
|
66
|
+
return ActorsRenderer;
|
|
67
|
+
}
|
|
68
|
+
if (columnData.id === ATTRIBUTES_COLUMN_ID) {
|
|
69
|
+
return AttributesRenderer;
|
|
70
|
+
}
|
|
71
|
+
switch (columnData.dataTypeDefinition.type) {
|
|
72
|
+
case DataTypes.TYPE_URL:
|
|
73
|
+
case DataTypes.TYPE_BLOG_URL:
|
|
74
|
+
case DataTypes.TYPE_IMAGE_URL:
|
|
75
|
+
case DataTypes.TYPE_EMAIL:
|
|
76
|
+
return LinkRenderer;
|
|
77
|
+
case DataTypes.TYPE_BLOB:
|
|
78
|
+
return BlobRender;
|
|
79
|
+
default:
|
|
80
|
+
return DefaultCellValueRenderer;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const getColumnDataByColumnId = (columnData) => ({
|
|
85
|
+
sortable: true,
|
|
86
|
+
...columnData,
|
|
87
|
+
resizable: true,
|
|
88
|
+
nestedPath: getNestedPathByColumnId(columnData.id),
|
|
89
|
+
headCellRenderer: HeadCellRenderer,
|
|
90
|
+
rowCellValueRenderer: getCellValueRenderer(columnData)
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const getBasicTableColumnsData = map(getColumnDataByColumnId);
|
|
94
|
+
|
|
95
|
+
const getMembersCount = pipe(prop('members'), length);
|
|
96
|
+
const getMemberCellHeight = pipe(
|
|
97
|
+
map(getMembersCount),
|
|
98
|
+
values,
|
|
99
|
+
reduce((acc, count) => acc + count * 33, 15)
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
const calculateMembersCellHeight = pipe(
|
|
103
|
+
path(['cell', 'values']),
|
|
104
|
+
reduce((acc, actors) => acc + getMemberCellHeight(actors), 0)
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
const calculateAttributesCellHeight = ({columnData, cell}) => {
|
|
108
|
+
const attributesCount = pipe(path(['values', 0]), values, length)(cell);
|
|
109
|
+
return attributesCount > columnData.maxAttrsToShow
|
|
110
|
+
? columnData.maxAttrsToShow * 26 + 49
|
|
111
|
+
: attributesCount * 26 + 25;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const getStaticRowCellHeight = cond([
|
|
115
|
+
[pathEq(['columnData', 'id'], ACTORS_COLUMN_ID), calculateMembersCellHeight],
|
|
116
|
+
[pathEq(['columnData', 'id'], ATTRIBUTES_COLUMN_ID), calculateAttributesCellHeight],
|
|
117
|
+
[T, defaultGetRowCellHeight]
|
|
118
|
+
]);
|
|
119
|
+
|
|
120
|
+
export {getBasicTableRowsData, getBasicTableColumnsData, getStaticRowCellHeight};
|