@reltio/interactions 1.4.1584 → 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,300 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ACTORS_COLUMN_ID,
|
|
3
|
+
ATTRIBUTES_COLUMN_ID,
|
|
4
|
+
getColumnsData,
|
|
5
|
+
getRowsPerPageOptions,
|
|
6
|
+
INTERACTION_TYPE_COLUMN_ID,
|
|
7
|
+
MAX_ATTRIBUTES_TO_SHOW
|
|
8
|
+
} from '../tableHelpers';
|
|
9
|
+
import {DataTypes, makeCompositeFilterOption} from '@reltio/mdm-sdk';
|
|
10
|
+
|
|
11
|
+
describe('get rows per page options scenarios', () => {
|
|
12
|
+
it('should return rows per page options include default', () => {
|
|
13
|
+
expect(getRowsPerPageOptions(15)).toEqual([10, 15, 25, 50, 100]);
|
|
14
|
+
});
|
|
15
|
+
it('should not contain duplicates', () => {
|
|
16
|
+
expect(getRowsPerPageOptions(25)).toEqual([10, 25, 50, 100]);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe('get column data scenarios', () => {
|
|
21
|
+
const interactionTypes = [
|
|
22
|
+
{
|
|
23
|
+
uri: 'configuration/interactionTypes/Type1',
|
|
24
|
+
attributes: [
|
|
25
|
+
{
|
|
26
|
+
type: 'String',
|
|
27
|
+
uri: 'configuration/interactionTypes/Type/attributes/String',
|
|
28
|
+
name: 'String',
|
|
29
|
+
label: 'String'
|
|
30
|
+
}
|
|
31
|
+
],
|
|
32
|
+
label: 'Type 1',
|
|
33
|
+
memberTypes: [
|
|
34
|
+
{
|
|
35
|
+
name: 'HCP',
|
|
36
|
+
label: 'HCP'
|
|
37
|
+
}
|
|
38
|
+
]
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
uri: 'configuration/interactionTypes/Type2',
|
|
42
|
+
attributes: [],
|
|
43
|
+
label: 'Type 2',
|
|
44
|
+
memberTypes: [
|
|
45
|
+
{
|
|
46
|
+
name: 'HCO',
|
|
47
|
+
label: 'HCO'
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
];
|
|
52
|
+
const metadata = {
|
|
53
|
+
interactionTypes
|
|
54
|
+
};
|
|
55
|
+
const config = {
|
|
56
|
+
attributes: {
|
|
57
|
+
'configuration/interactionTypes/1': [
|
|
58
|
+
'configuration/interactionTypes/1/attributes/ATTR_NAME1',
|
|
59
|
+
'configuration/interactionTypes/1/attributes/ATTR_NAME2'
|
|
60
|
+
]
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
it('should return date, actors and attributes columns if current interaction type is defined', () => {
|
|
65
|
+
const columnsData = getColumnsData(metadata, config, interactionTypes, 'configuration/interactionTypes/Type1');
|
|
66
|
+
expect(columnsData).toEqual([
|
|
67
|
+
{
|
|
68
|
+
id: 'timestamp',
|
|
69
|
+
label: 'Date',
|
|
70
|
+
dataTypeDefinition: {
|
|
71
|
+
type: DataTypes.TYPE_TIMESTAMP
|
|
72
|
+
},
|
|
73
|
+
hideable: false
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
id: ACTORS_COLUMN_ID,
|
|
77
|
+
label: 'Actors',
|
|
78
|
+
sortable: false,
|
|
79
|
+
dataTypeDefinition: {
|
|
80
|
+
type: DataTypes.TYPE_STRING
|
|
81
|
+
},
|
|
82
|
+
filterOptions: [
|
|
83
|
+
{value: 'equals'},
|
|
84
|
+
{value: 'not equals'},
|
|
85
|
+
{value: 'hasAll'},
|
|
86
|
+
{value: 'in.file'},
|
|
87
|
+
{value: 'not.in.file'},
|
|
88
|
+
{
|
|
89
|
+
value: makeCompositeFilterOption('types', 'equals'),
|
|
90
|
+
label: 'type equals',
|
|
91
|
+
dataTypeDefinition: {
|
|
92
|
+
type: 'Select',
|
|
93
|
+
options: [{value: 'HCP', label: 'HCP'}]
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
value: makeCompositeFilterOption('types', 'not equals'),
|
|
98
|
+
label: 'type not',
|
|
99
|
+
dataTypeDefinition: {
|
|
100
|
+
type: 'Select',
|
|
101
|
+
options: [{value: 'HCP', label: 'HCP'}]
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
value: makeCompositeFilterOption('types', 'hasAll'),
|
|
106
|
+
label: 'type has all',
|
|
107
|
+
dataTypeDefinition: {
|
|
108
|
+
type: 'Select',
|
|
109
|
+
options: [{value: 'HCP', label: 'HCP'}]
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
value: makeCompositeFilterOption('types', 'in.file'),
|
|
114
|
+
label: 'type in file'
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
value: makeCompositeFilterOption('types', 'not.in.file'),
|
|
118
|
+
label: 'type not in file'
|
|
119
|
+
}
|
|
120
|
+
]
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
id: 'attributes.String',
|
|
124
|
+
label: 'String',
|
|
125
|
+
dataTypeDefinition: {
|
|
126
|
+
type: 'String',
|
|
127
|
+
uri: 'configuration/interactionTypes/Type/attributes/String',
|
|
128
|
+
name: 'String'
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
]);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('should return date, actors, type and attributes columns if current interaction type is undefined', () => {
|
|
135
|
+
const columnsData = getColumnsData(metadata, config, interactionTypes);
|
|
136
|
+
expect(columnsData).toEqual([
|
|
137
|
+
{
|
|
138
|
+
id: 'timestamp',
|
|
139
|
+
label: 'Date',
|
|
140
|
+
dataTypeDefinition: {
|
|
141
|
+
type: DataTypes.TYPE_TIMESTAMP
|
|
142
|
+
},
|
|
143
|
+
hideable: false
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
id: INTERACTION_TYPE_COLUMN_ID,
|
|
147
|
+
label: 'Interaction type',
|
|
148
|
+
sortable: false,
|
|
149
|
+
filterOptions: [{value: 'equals'}, {value: 'not equals'}],
|
|
150
|
+
dataTypeDefinition: {
|
|
151
|
+
type: DataTypes.TYPE_SELECT,
|
|
152
|
+
options: interactionTypes.map(({uri, label}) => ({value: uri, label}))
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
id: ACTORS_COLUMN_ID,
|
|
157
|
+
label: 'Actors',
|
|
158
|
+
sortable: false,
|
|
159
|
+
dataTypeDefinition: {
|
|
160
|
+
type: DataTypes.TYPE_STRING
|
|
161
|
+
},
|
|
162
|
+
filterOptions: [
|
|
163
|
+
{value: 'equals'},
|
|
164
|
+
{value: 'not equals'},
|
|
165
|
+
{value: 'hasAll'},
|
|
166
|
+
{value: 'in.file'},
|
|
167
|
+
{value: 'not.in.file'},
|
|
168
|
+
{
|
|
169
|
+
value: makeCompositeFilterOption('types', 'equals'),
|
|
170
|
+
label: 'type equals',
|
|
171
|
+
dataTypeDefinition: {
|
|
172
|
+
type: 'Select',
|
|
173
|
+
options: [
|
|
174
|
+
{value: 'HCP', label: 'HCP'},
|
|
175
|
+
{value: 'HCO', label: 'HCO'}
|
|
176
|
+
]
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
value: makeCompositeFilterOption('types', 'not equals'),
|
|
181
|
+
label: 'type not',
|
|
182
|
+
dataTypeDefinition: {
|
|
183
|
+
type: 'Select',
|
|
184
|
+
options: [
|
|
185
|
+
{value: 'HCP', label: 'HCP'},
|
|
186
|
+
{value: 'HCO', label: 'HCO'}
|
|
187
|
+
]
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
value: makeCompositeFilterOption('types', 'hasAll'),
|
|
192
|
+
label: 'type has all',
|
|
193
|
+
dataTypeDefinition: {
|
|
194
|
+
type: 'Select',
|
|
195
|
+
options: [
|
|
196
|
+
{value: 'HCP', label: 'HCP'},
|
|
197
|
+
{value: 'HCO', label: 'HCO'}
|
|
198
|
+
]
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
value: makeCompositeFilterOption('types', 'in.file'),
|
|
203
|
+
label: 'type in file'
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
value: makeCompositeFilterOption('types', 'not.in.file'),
|
|
207
|
+
label: 'type not in file'
|
|
208
|
+
}
|
|
209
|
+
]
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
id: ATTRIBUTES_COLUMN_ID,
|
|
213
|
+
label: 'Attributes',
|
|
214
|
+
sortable: false,
|
|
215
|
+
filterable: false,
|
|
216
|
+
maxAttrsToShow: MAX_ATTRIBUTES_TO_SHOW,
|
|
217
|
+
attrsToShow: config.attributes
|
|
218
|
+
}
|
|
219
|
+
]);
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it('should return date, actors, type and attributes columns if interationTypes is missing in metadata', () => {
|
|
223
|
+
const columnsData = getColumnsData({}, config, []);
|
|
224
|
+
expect(columnsData).toEqual([
|
|
225
|
+
{
|
|
226
|
+
id: 'timestamp',
|
|
227
|
+
label: 'Date',
|
|
228
|
+
dataTypeDefinition: {
|
|
229
|
+
type: DataTypes.TYPE_TIMESTAMP
|
|
230
|
+
},
|
|
231
|
+
hideable: false
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
id: INTERACTION_TYPE_COLUMN_ID,
|
|
235
|
+
label: 'Interaction type',
|
|
236
|
+
sortable: false,
|
|
237
|
+
filterOptions: [{value: 'equals'}, {value: 'not equals'}],
|
|
238
|
+
dataTypeDefinition: {
|
|
239
|
+
type: DataTypes.TYPE_SELECT,
|
|
240
|
+
options: []
|
|
241
|
+
}
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
id: ACTORS_COLUMN_ID,
|
|
245
|
+
label: 'Actors',
|
|
246
|
+
sortable: false,
|
|
247
|
+
dataTypeDefinition: {
|
|
248
|
+
type: DataTypes.TYPE_STRING
|
|
249
|
+
},
|
|
250
|
+
filterOptions: [
|
|
251
|
+
{value: 'equals'},
|
|
252
|
+
{value: 'not equals'},
|
|
253
|
+
{value: 'hasAll'},
|
|
254
|
+
{value: 'in.file'},
|
|
255
|
+
{value: 'not.in.file'},
|
|
256
|
+
{
|
|
257
|
+
value: makeCompositeFilterOption('types', 'equals'),
|
|
258
|
+
label: 'type equals',
|
|
259
|
+
dataTypeDefinition: {
|
|
260
|
+
type: 'Select',
|
|
261
|
+
options: []
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
value: makeCompositeFilterOption('types', 'not equals'),
|
|
266
|
+
label: 'type not',
|
|
267
|
+
dataTypeDefinition: {
|
|
268
|
+
type: 'Select',
|
|
269
|
+
options: []
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
value: makeCompositeFilterOption('types', 'hasAll'),
|
|
274
|
+
label: 'type has all',
|
|
275
|
+
dataTypeDefinition: {
|
|
276
|
+
type: 'Select',
|
|
277
|
+
options: []
|
|
278
|
+
}
|
|
279
|
+
},
|
|
280
|
+
{
|
|
281
|
+
value: makeCompositeFilterOption('types', 'in.file'),
|
|
282
|
+
label: 'type in file'
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
value: makeCompositeFilterOption('types', 'not.in.file'),
|
|
286
|
+
label: 'type not in file'
|
|
287
|
+
}
|
|
288
|
+
]
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
id: ATTRIBUTES_COLUMN_ID,
|
|
292
|
+
label: 'Attributes',
|
|
293
|
+
sortable: false,
|
|
294
|
+
filterable: false,
|
|
295
|
+
maxAttrsToShow: MAX_ATTRIBUTES_TO_SHOW,
|
|
296
|
+
attrsToShow: config.attributes
|
|
297
|
+
}
|
|
298
|
+
]);
|
|
299
|
+
});
|
|
300
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {FilterBuilder, Maybe} from '@reltio/mdm-sdk';
|
|
2
|
+
import {buildColumnsFilter, ColumnData, ColumnFilter} from '@reltio/components';
|
|
3
|
+
|
|
4
|
+
const createInteractionTypeFilter = (value) => `equals(type,'${value}')`;
|
|
5
|
+
|
|
6
|
+
const buildInteractionsFilter = (
|
|
7
|
+
currentInteractionType: string,
|
|
8
|
+
filters: Record<string, ColumnFilter>,
|
|
9
|
+
columnsData: ColumnData[]
|
|
10
|
+
) => {
|
|
11
|
+
const currentTypeClause = Maybe.fromNull(currentInteractionType).map(createInteractionTypeFilter).orSome('');
|
|
12
|
+
|
|
13
|
+
const filtersClause = buildColumnsFilter(columnsData, filters);
|
|
14
|
+
|
|
15
|
+
return new FilterBuilder().addClause(currentTypeClause).addClause(filtersClause).build();
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export {buildInteractionsFilter};
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import {
|
|
2
|
+
attributeUriToSearchUri,
|
|
3
|
+
DataTypes,
|
|
4
|
+
FilterOptions,
|
|
5
|
+
getAttrDataTypeDefinition,
|
|
6
|
+
getInteractionAttributesFromMetadata,
|
|
7
|
+
getInteractionType,
|
|
8
|
+
InteractionType,
|
|
9
|
+
makeCompositeFilterOption
|
|
10
|
+
} from '@reltio/mdm-sdk';
|
|
11
|
+
import {adjust, assoc, chain, concat, map, pipe, pluck, prop, propEq, reject, subtract, uniqBy} from 'ramda';
|
|
12
|
+
import i18n from 'ui-i18n';
|
|
13
|
+
|
|
14
|
+
const ROWS_PER_PAGE_OPTIONS = [10, 25, 50, 100];
|
|
15
|
+
const getRowsPerPageOptions = (defaultRowsPerPage: number) =>
|
|
16
|
+
ROWS_PER_PAGE_OPTIONS.filter((option) => option !== defaultRowsPerPage)
|
|
17
|
+
.concat(defaultRowsPerPage)
|
|
18
|
+
.sort(subtract);
|
|
19
|
+
|
|
20
|
+
const INTERACTION_TYPE_COLUMN_ID = 'type';
|
|
21
|
+
const ACTORS_COLUMN_ID = 'members';
|
|
22
|
+
const ATTRIBUTES_COLUMN_ID = 'attributes';
|
|
23
|
+
|
|
24
|
+
const MAX_ATTRIBUTES_TO_SHOW = 7;
|
|
25
|
+
|
|
26
|
+
const DEFAULT_COLUMNS_DATA = [
|
|
27
|
+
{
|
|
28
|
+
id: 'timestamp',
|
|
29
|
+
label: 'Date',
|
|
30
|
+
dataTypeDefinition: {
|
|
31
|
+
type: DataTypes.TYPE_TIMESTAMP
|
|
32
|
+
},
|
|
33
|
+
hideable: false
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
id: INTERACTION_TYPE_COLUMN_ID,
|
|
37
|
+
label: 'Interaction type',
|
|
38
|
+
sortable: false,
|
|
39
|
+
filterOptions: [{value: FilterOptions.EQUALS}, {value: FilterOptions.NOT_EQUALS}]
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
id: ACTORS_COLUMN_ID,
|
|
43
|
+
label: 'Actors',
|
|
44
|
+
sortable: false,
|
|
45
|
+
dataTypeDefinition: {
|
|
46
|
+
type: DataTypes.TYPE_STRING
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
id: ATTRIBUTES_COLUMN_ID,
|
|
51
|
+
label: 'Attributes',
|
|
52
|
+
sortable: false,
|
|
53
|
+
filterable: false,
|
|
54
|
+
maxAttrsToShow: MAX_ATTRIBUTES_TO_SHOW
|
|
55
|
+
}
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
const DEFAULT_COLUMNS = pluck('id', DEFAULT_COLUMNS_DATA);
|
|
59
|
+
const ALL_TYPES_COLUMNS = [INTERACTION_TYPE_COLUMN_ID, ATTRIBUTES_COLUMN_ID];
|
|
60
|
+
|
|
61
|
+
const getColumnsDataFromInteractionAttributes = pipe(
|
|
62
|
+
map((attr) => ({
|
|
63
|
+
id: attributeUriToSearchUri(attr.uri),
|
|
64
|
+
label: attr.label,
|
|
65
|
+
dataTypeDefinition: getAttrDataTypeDefinition(attr)
|
|
66
|
+
})),
|
|
67
|
+
uniqBy(prop('id'))
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
const getInteractionColumnDataType = (interactionTypes) => ({
|
|
71
|
+
type: DataTypes.TYPE_SELECT,
|
|
72
|
+
options: interactionTypes.map(({uri, label}) => ({value: uri, label}))
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const getActorTypesOptions = pipe(
|
|
76
|
+
chain(({memberTypes}) => memberTypes.map(({name, label}) => ({label, value: name}))),
|
|
77
|
+
uniqBy(prop('value'))
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
const getActorsColumnFilterOptions = (interactionTypes: Array<InteractionType>) => {
|
|
81
|
+
const typeFilterDataType = {
|
|
82
|
+
type: DataTypes.TYPE_SELECT,
|
|
83
|
+
options: getActorTypesOptions(interactionTypes)
|
|
84
|
+
};
|
|
85
|
+
const makeTypeOption = makeCompositeFilterOption('types');
|
|
86
|
+
return [
|
|
87
|
+
{value: FilterOptions.EQUALS},
|
|
88
|
+
{value: FilterOptions.NOT_EQUALS},
|
|
89
|
+
{value: FilterOptions.HAS_ALL},
|
|
90
|
+
{value: FilterOptions.IN_FILE},
|
|
91
|
+
{value: FilterOptions.NOT_IN_FILE},
|
|
92
|
+
{
|
|
93
|
+
value: makeTypeOption(FilterOptions.EQUALS),
|
|
94
|
+
label: i18n.text('type equals'),
|
|
95
|
+
dataTypeDefinition: typeFilterDataType
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
value: makeTypeOption(FilterOptions.NOT_EQUALS),
|
|
99
|
+
label: i18n.text('type not'),
|
|
100
|
+
dataTypeDefinition: typeFilterDataType
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
value: makeTypeOption(FilterOptions.HAS_ALL),
|
|
104
|
+
label: i18n.text('type has all'),
|
|
105
|
+
dataTypeDefinition: typeFilterDataType
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
value: makeTypeOption(FilterOptions.IN_FILE),
|
|
109
|
+
label: i18n.text('type in file')
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
value: makeTypeOption(FilterOptions.NOT_IN_FILE),
|
|
113
|
+
label: i18n.text('type not in file')
|
|
114
|
+
}
|
|
115
|
+
];
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const updateColumnData = (columnId, updateFn) => (columnsData) =>
|
|
119
|
+
adjust(columnsData.findIndex(propEq('id', columnId)), updateFn, columnsData);
|
|
120
|
+
|
|
121
|
+
const updateInteractionTypeColumn = (interactionTypes) =>
|
|
122
|
+
updateColumnData(
|
|
123
|
+
INTERACTION_TYPE_COLUMN_ID,
|
|
124
|
+
assoc('dataTypeDefinition', getInteractionColumnDataType(interactionTypes))
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
const updateActorsColumn = (interactionTypes) =>
|
|
128
|
+
updateColumnData(ACTORS_COLUMN_ID, assoc('filterOptions', getActorsColumnFilterOptions(interactionTypes)));
|
|
129
|
+
|
|
130
|
+
const updateAttributesColumn = (attributes) => updateColumnData(ATTRIBUTES_COLUMN_ID, assoc('attrsToShow', attributes));
|
|
131
|
+
|
|
132
|
+
const getColumnsData = (metadata, config, interactionTypes, currentInteractionType) => {
|
|
133
|
+
return currentInteractionType
|
|
134
|
+
? pipe(
|
|
135
|
+
getInteractionAttributesFromMetadata,
|
|
136
|
+
getColumnsDataFromInteractionAttributes,
|
|
137
|
+
concat(DEFAULT_COLUMNS_DATA),
|
|
138
|
+
reject(({id}) => ALL_TYPES_COLUMNS.includes(id)),
|
|
139
|
+
updateActorsColumn([getInteractionType(metadata, currentInteractionType)])
|
|
140
|
+
)(metadata, currentInteractionType)
|
|
141
|
+
: pipe(
|
|
142
|
+
updateAttributesColumn(config.attributes),
|
|
143
|
+
updateInteractionTypeColumn(interactionTypes),
|
|
144
|
+
updateActorsColumn(metadata.interactionTypes || [])
|
|
145
|
+
)(DEFAULT_COLUMNS_DATA);
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
export {
|
|
149
|
+
getRowsPerPageOptions,
|
|
150
|
+
DEFAULT_COLUMNS,
|
|
151
|
+
getColumnsData,
|
|
152
|
+
INTERACTION_TYPE_COLUMN_ID,
|
|
153
|
+
ACTORS_COLUMN_ID,
|
|
154
|
+
ATTRIBUTES_COLUMN_ID,
|
|
155
|
+
ALL_TYPES_COLUMNS,
|
|
156
|
+
MAX_ATTRIBUTES_TO_SHOW
|
|
157
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {useState, useEffect} from 'react';
|
|
2
|
+
import {getInteractions} from '@reltio/mdm-sdk';
|
|
3
|
+
import {Sorting, useSafePromise} from '@reltio/components';
|
|
4
|
+
|
|
5
|
+
type Props = {
|
|
6
|
+
entityUri: string;
|
|
7
|
+
sorting: Sorting;
|
|
8
|
+
page: number;
|
|
9
|
+
rowsPerPage: number;
|
|
10
|
+
filter: string;
|
|
11
|
+
enabled: boolean;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const useInteractions = ({entityUri, filter, sorting, page, rowsPerPage, enabled}: Props) => {
|
|
15
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
16
|
+
const [total, setTotal] = useState(0);
|
|
17
|
+
const [interactions, setInteractions] = useState([]);
|
|
18
|
+
const safePromise = useSafePromise();
|
|
19
|
+
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (enabled) {
|
|
22
|
+
setIsLoading(true);
|
|
23
|
+
safePromise(
|
|
24
|
+
getInteractions({
|
|
25
|
+
entityUri: entityUri,
|
|
26
|
+
offset: page * rowsPerPage,
|
|
27
|
+
max: rowsPerPage,
|
|
28
|
+
filter,
|
|
29
|
+
sort: sorting.field,
|
|
30
|
+
order: sorting.order
|
|
31
|
+
})
|
|
32
|
+
)
|
|
33
|
+
.then(({totalFetched, interactions = []}) => {
|
|
34
|
+
setTotal(totalFetched);
|
|
35
|
+
setInteractions(interactions);
|
|
36
|
+
})
|
|
37
|
+
.then((_) => setIsLoading(false))
|
|
38
|
+
.catch((_) => setIsLoading(false));
|
|
39
|
+
}
|
|
40
|
+
}, [entityUri, filter, sorting.field, sorting.order, page, rowsPerPage, enabled]); // eslint-disable-line
|
|
41
|
+
|
|
42
|
+
return {isLoading, interactions, total};
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export default useInteractions;
|