@reltio/components 1.4.2015 → 1.4.2017
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/ProfileBandNavigation/useSearchNavigation.js +8 -2
- package/cjs/ProfileBandNavigation/useSearchNavigation.js +8 -2
- package/cjs/features/workflow/AssigneeSelector/AssigneeSelector.spec.js +80 -0
- package/cjs/features/workflow/hooks/useWorkflowAssignee.js +24 -36
- package/cjs/hooks/useCommentsEntitiesMap/useCommentsEntitiesMap.js +3 -1
- package/cjs/hooks/useMatchesLoader/useMatchesLoader.js +1 -1
- package/cjs/hooks/usePivotingDataLoader/usePivotingDataLoader.js +2 -1
- package/cjs/hooks/useSavedState/useSavedState.js +7 -3
- package/cjs/hooks/useSavedStateForEntityType/useSavedStateForEntityType.js +7 -3
- package/features/workflow/AssigneeSelector/AssigneeSelector.spec.js +81 -1
- package/features/workflow/hooks/useWorkflowAssignee.js +25 -37
- package/hooks/useCommentsEntitiesMap/useCommentsEntitiesMap.js +3 -1
- package/hooks/useMatchesLoader/useMatchesLoader.js +1 -1
- package/hooks/usePivotingDataLoader/usePivotingDataLoader.js +2 -1
- package/hooks/useSavedState/useSavedState.js +7 -3
- package/hooks/useSavedStateForEntityType/useSavedStateForEntityType.js +7 -3
- package/package.json +1 -1
|
@@ -160,6 +160,7 @@ export var useSearchNavigation = function () {
|
|
|
160
160
|
total: total,
|
|
161
161
|
index: total - 1
|
|
162
162
|
});
|
|
163
|
+
return Promise.resolve();
|
|
163
164
|
}
|
|
164
165
|
else {
|
|
165
166
|
return requestNextPage(cache, total, index);
|
|
@@ -196,6 +197,7 @@ export var useSearchNavigation = function () {
|
|
|
196
197
|
cache: cache,
|
|
197
198
|
total: total
|
|
198
199
|
});
|
|
200
|
+
return Promise.resolve();
|
|
199
201
|
}
|
|
200
202
|
else {
|
|
201
203
|
return requestPrevPage(cache, index);
|
|
@@ -204,13 +206,17 @@ export var useSearchNavigation = function () {
|
|
|
204
206
|
var onPrev = useCallback(function () {
|
|
205
207
|
if (cache && uri) {
|
|
206
208
|
var cacheIndex = cache.indexOf(uri) - 1;
|
|
207
|
-
stepBackWithCheck(cache, cacheIndex, total, index)
|
|
209
|
+
stepBackWithCheck(cache, cacheIndex, total, index).catch(function (error) {
|
|
210
|
+
console.warn("Can't load prev page of search", error);
|
|
211
|
+
});
|
|
208
212
|
}
|
|
209
213
|
}, [stepBackWithCheck, cache, uri, total, index]);
|
|
210
214
|
var onNext = useCallback(function () {
|
|
211
215
|
if (cache && uri) {
|
|
212
216
|
var cacheIndex = cache.indexOf(uri) + 1;
|
|
213
|
-
stepForwardWithCheck(cache, cacheIndex, total, index)
|
|
217
|
+
stepForwardWithCheck(cache, cacheIndex, total, index).catch(function (error) {
|
|
218
|
+
console.warn("Can't load next page of search", error);
|
|
219
|
+
});
|
|
214
220
|
}
|
|
215
221
|
}, [stepForwardWithCheck, cache, uri, total, index]);
|
|
216
222
|
useEffect(function () {
|
|
@@ -163,6 +163,7 @@ var useSearchNavigation = function () {
|
|
|
163
163
|
total: total,
|
|
164
164
|
index: total - 1
|
|
165
165
|
});
|
|
166
|
+
return Promise.resolve();
|
|
166
167
|
}
|
|
167
168
|
else {
|
|
168
169
|
return requestNextPage(cache, total, index);
|
|
@@ -199,6 +200,7 @@ var useSearchNavigation = function () {
|
|
|
199
200
|
cache: cache,
|
|
200
201
|
total: total
|
|
201
202
|
});
|
|
203
|
+
return Promise.resolve();
|
|
202
204
|
}
|
|
203
205
|
else {
|
|
204
206
|
return requestPrevPage(cache, index);
|
|
@@ -207,13 +209,17 @@ var useSearchNavigation = function () {
|
|
|
207
209
|
var onPrev = (0, react_1.useCallback)(function () {
|
|
208
210
|
if (cache && uri) {
|
|
209
211
|
var cacheIndex = cache.indexOf(uri) - 1;
|
|
210
|
-
stepBackWithCheck(cache, cacheIndex, total, index)
|
|
212
|
+
stepBackWithCheck(cache, cacheIndex, total, index).catch(function (error) {
|
|
213
|
+
console.warn("Can't load prev page of search", error);
|
|
214
|
+
});
|
|
211
215
|
}
|
|
212
216
|
}, [stepBackWithCheck, cache, uri, total, index]);
|
|
213
217
|
var onNext = (0, react_1.useCallback)(function () {
|
|
214
218
|
if (cache && uri) {
|
|
215
219
|
var cacheIndex = cache.indexOf(uri) + 1;
|
|
216
|
-
stepForwardWithCheck(cache, cacheIndex, total, index)
|
|
220
|
+
stepForwardWithCheck(cache, cacheIndex, total, index).catch(function (error) {
|
|
221
|
+
console.warn("Can't load next page of search", error);
|
|
222
|
+
});
|
|
217
223
|
}
|
|
218
224
|
}, [stepForwardWithCheck, cache, uri, total, index]);
|
|
219
225
|
(0, react_1.useEffect)(function () {
|
|
@@ -272,4 +272,84 @@ describe('AssigneeSelector tests', function () {
|
|
|
272
272
|
}
|
|
273
273
|
});
|
|
274
274
|
}); });
|
|
275
|
+
it('should make a single request on load, show loading state, and not re-fetch if assignees are already loaded', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
276
|
+
var user, input;
|
|
277
|
+
return __generator(this, function (_a) {
|
|
278
|
+
switch (_a.label) {
|
|
279
|
+
case 0:
|
|
280
|
+
user = setUp().user;
|
|
281
|
+
return [4 /*yield*/, react_2.screen.findByText('Assigned to')];
|
|
282
|
+
case 1:
|
|
283
|
+
_a.sent();
|
|
284
|
+
expect(mdm_sdk_1.getAssigneeForTask).toHaveBeenCalledTimes(1);
|
|
285
|
+
input = react_2.screen.getByRole('combobox');
|
|
286
|
+
return [4 /*yield*/, user.click(input)];
|
|
287
|
+
case 2:
|
|
288
|
+
_a.sent();
|
|
289
|
+
expect(react_2.screen.getByText('Loading...')).toBeInTheDocument();
|
|
290
|
+
(0, react_2.act)(function () {
|
|
291
|
+
resolveAssigneeForTask(response);
|
|
292
|
+
});
|
|
293
|
+
return [4 /*yield*/, (0, react_2.waitForElementToBeRemoved)(react_2.screen.queryByText('Loading...'))];
|
|
294
|
+
case 3:
|
|
295
|
+
_a.sent();
|
|
296
|
+
return [4 /*yield*/, react_2.screen.findByText('user1')];
|
|
297
|
+
case 4:
|
|
298
|
+
_a.sent();
|
|
299
|
+
return [4 /*yield*/, react_2.screen.findByText('user2')];
|
|
300
|
+
case 5:
|
|
301
|
+
_a.sent();
|
|
302
|
+
return [4 /*yield*/, react_2.screen.findByText('firstUser')];
|
|
303
|
+
case 6:
|
|
304
|
+
_a.sent();
|
|
305
|
+
return [4 /*yield*/, user.type(input, 'user')];
|
|
306
|
+
case 7:
|
|
307
|
+
_a.sent();
|
|
308
|
+
expect(mdm_sdk_1.getAssigneeForTask).toHaveBeenCalledTimes(1);
|
|
309
|
+
return [4 /*yield*/, user.clear(input)];
|
|
310
|
+
case 8:
|
|
311
|
+
_a.sent();
|
|
312
|
+
return [4 /*yield*/, user.type(input, 'first')];
|
|
313
|
+
case 9:
|
|
314
|
+
_a.sent();
|
|
315
|
+
expect(mdm_sdk_1.getAssigneeForTask).toHaveBeenCalledTimes(1);
|
|
316
|
+
return [2 /*return*/];
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
}); });
|
|
320
|
+
it('should correctly filter options based on user input', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
321
|
+
var user, input;
|
|
322
|
+
return __generator(this, function (_a) {
|
|
323
|
+
switch (_a.label) {
|
|
324
|
+
case 0:
|
|
325
|
+
user = setUp().user;
|
|
326
|
+
return [4 /*yield*/, react_2.screen.findByText('Assigned to')];
|
|
327
|
+
case 1:
|
|
328
|
+
_a.sent();
|
|
329
|
+
input = react_2.screen.getByRole('combobox');
|
|
330
|
+
return [4 /*yield*/, user.click(input)];
|
|
331
|
+
case 2:
|
|
332
|
+
_a.sent();
|
|
333
|
+
(0, react_2.act)(function () {
|
|
334
|
+
resolveAssigneeForTask(response);
|
|
335
|
+
});
|
|
336
|
+
return [4 /*yield*/, react_2.screen.findByText('user2')];
|
|
337
|
+
case 3:
|
|
338
|
+
_a.sent();
|
|
339
|
+
return [4 /*yield*/, user.type(input, 'user2')];
|
|
340
|
+
case 4:
|
|
341
|
+
_a.sent();
|
|
342
|
+
expect(react_2.screen.getByText('user2')).toBeInTheDocument();
|
|
343
|
+
expect(react_2.screen.queryByText('user1')).not.toBeInTheDocument();
|
|
344
|
+
expect(react_2.screen.queryByText('firstUser')).not.toBeInTheDocument();
|
|
345
|
+
return [4 /*yield*/, user.clear(input)];
|
|
346
|
+
case 5:
|
|
347
|
+
_a.sent();
|
|
348
|
+
expect(react_2.screen.getByText('user1')).toBeInTheDocument();
|
|
349
|
+
expect(react_2.screen.getByText('user2')).toBeInTheDocument();
|
|
350
|
+
expect(react_2.screen.getByText('firstUser')).toBeInTheDocument();
|
|
351
|
+
return [2 /*return*/];
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
}); });
|
|
275
355
|
});
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useWorkflowAssignee = void 0;
|
|
4
4
|
var react_1 = require("react");
|
|
5
|
-
var ramda_1 = require("ramda");
|
|
6
5
|
var mdm_sdk_1 = require("@reltio/mdm-sdk");
|
|
7
6
|
var useSafePromise_1 = require("../../../hooks/useSafePromise");
|
|
8
7
|
var WorkflowTasksContext_1 = require("../../../contexts/WorkflowTasksContext");
|
|
@@ -14,6 +13,9 @@ var assigneeToValue = function (assignee) { return ({
|
|
|
14
13
|
label: assignee,
|
|
15
14
|
value: assignee
|
|
16
15
|
}); };
|
|
16
|
+
var filterAssignees = function (assignees, text) {
|
|
17
|
+
return assignees.filter(function (item) { return item.value.toLowerCase().includes(text === null || text === void 0 ? void 0 : text.toLowerCase()); });
|
|
18
|
+
};
|
|
17
19
|
var useWorkflowAssignee = function (_a) {
|
|
18
20
|
var assignee = _a.assignee, _b = _a.showCurrentAssignee, showCurrentAssignee = _b === void 0 ? true : _b, taskId = _a.taskId, isOpen = _a.isOpen, onChange = _a.onChange;
|
|
19
21
|
var updateTaskState = ((0, react_1.useContext)(WorkflowTasksContext_1.WorkflowTasksContext) || {}).updateTaskState;
|
|
@@ -21,56 +23,42 @@ var useWorkflowAssignee = function (_a) {
|
|
|
21
23
|
var environment = (0, MdmModuleContext_1.useMdmWorkflowEnvironmentUrl)();
|
|
22
24
|
var tenant = (0, MdmModuleContext_1.useMdmTenant)();
|
|
23
25
|
var updateSafePromise = (0, useSafePromise_1.useSafePromise)();
|
|
24
|
-
var getSafePromise = (0, useSafePromise_1.useSafePromise)();
|
|
25
26
|
var _c = (0, react_1.useState)(null), currentAssignee = _c[0], setCurrentAssignee = _c[1];
|
|
26
|
-
var _d = (0, react_1.useState)(),
|
|
27
|
-
var _e = (0, react_1.useState)(false), updateRequestIsInProgress = _e[0], setUpdateRequestIsInProgress = _e[1];
|
|
27
|
+
var _d = (0, react_1.useState)(false), updateRequestIsInProgress = _d[0], setUpdateRequestIsInProgress = _d[1];
|
|
28
28
|
var checkWorkflowPermission = (0, useWorkflowCheckPermission_1.useWorkflowCheckPermission)();
|
|
29
29
|
var canUpdateTask = checkWorkflowPermission('UPDATE_TASK') && (0, common_1.isOpenTask)(isOpen);
|
|
30
|
+
var assigneesRequestRef = (0, react_1.useRef)(null);
|
|
30
31
|
(0, react_1.useEffect)(function () {
|
|
31
32
|
if (showCurrentAssignee)
|
|
32
33
|
setCurrentAssignee(assigneeToValue(assignee));
|
|
33
|
-
},
|
|
34
|
+
},
|
|
35
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
36
|
+
[assignee]);
|
|
34
37
|
var getAssignees = (0, react_1.useCallback)(function (text) {
|
|
35
38
|
if (workflowPath && canUpdateTask && taskId) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
if (!assigneesRequestRef.current) {
|
|
40
|
+
assigneesRequestRef.current = (0, mdm_sdk_1.getAssigneeForTask)({
|
|
41
|
+
taskId: taskId,
|
|
42
|
+
workflowPath: workflowPath,
|
|
43
|
+
environment: environment,
|
|
44
|
+
tenant: tenant
|
|
45
|
+
});
|
|
41
46
|
}
|
|
42
|
-
return
|
|
43
|
-
taskId: taskId,
|
|
44
|
-
workflowPath: workflowPath,
|
|
45
|
-
environment: environment,
|
|
46
|
-
tenant: tenant
|
|
47
|
-
}))
|
|
47
|
+
return assigneesRequestRef.current
|
|
48
48
|
.then(function (result) {
|
|
49
49
|
var data = result.data;
|
|
50
|
-
var
|
|
50
|
+
var fetchedAssignees = data
|
|
51
51
|
.filter(function (a) { return (showCurrentAssignee ? true : a !== assignee); })
|
|
52
|
-
.sort(function (a, b) {
|
|
53
|
-
return mdm_sdk_1.utils.strings.sort('asc', a, b);
|
|
54
|
-
})
|
|
52
|
+
.sort(function (a, b) { return mdm_sdk_1.utils.strings.sort('asc', a, b); })
|
|
55
53
|
.map(assigneeToValue);
|
|
56
|
-
|
|
57
|
-
return filterOutRest_1(assignees);
|
|
54
|
+
return filterAssignees(fetchedAssignees, text);
|
|
58
55
|
})
|
|
59
|
-
.catch(
|
|
56
|
+
.catch(function (e) {
|
|
57
|
+
(0, errors_1.showWorkflowError)(e);
|
|
58
|
+
assigneesRequestRef.current = null;
|
|
59
|
+
});
|
|
60
60
|
}
|
|
61
|
-
},
|
|
62
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
63
|
-
[
|
|
64
|
-
workflowPath,
|
|
65
|
-
taskId,
|
|
66
|
-
environment,
|
|
67
|
-
tenant,
|
|
68
|
-
assignees,
|
|
69
|
-
setAssignees,
|
|
70
|
-
canUpdateTask,
|
|
71
|
-
assignee,
|
|
72
|
-
showCurrentAssignee
|
|
73
|
-
]);
|
|
61
|
+
}, [workflowPath, taskId, environment, tenant, canUpdateTask, assignee, showCurrentAssignee]);
|
|
74
62
|
var updateAssignee = (0, react_1.useCallback)(function (newValue) {
|
|
75
63
|
var assignee = newValue.value;
|
|
76
64
|
if (onChange) {
|
|
@@ -72,7 +72,9 @@ var useCommentsEntitiesMap = function (comments) {
|
|
|
72
72
|
}, __assign({}, prevEntitiesMap));
|
|
73
73
|
});
|
|
74
74
|
})
|
|
75
|
-
.catch(function () {
|
|
75
|
+
.catch(function (error) {
|
|
76
|
+
console.warn("Can't load entities for comments map", error);
|
|
77
|
+
});
|
|
76
78
|
}
|
|
77
79
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
78
80
|
}, [getEntities, addNotFoundEntities, comments, currentEntityUri]);
|
|
@@ -34,7 +34,8 @@ var usePivotingDataLoader = function (_a) {
|
|
|
34
34
|
setEntities(Array.isArray(entities) ? entities : []);
|
|
35
35
|
setTotal(total);
|
|
36
36
|
})
|
|
37
|
-
.catch(function () {
|
|
37
|
+
.catch(function (error) {
|
|
38
|
+
console.warn("Can't load entities or total for pivoting data", error);
|
|
38
39
|
setEntities([]);
|
|
39
40
|
setTotal(0);
|
|
40
41
|
});
|
|
@@ -10,9 +10,13 @@ var useSavedState = function (getSavedState) {
|
|
|
10
10
|
.then(function (savedState) {
|
|
11
11
|
setSavedState(savedState || {});
|
|
12
12
|
})
|
|
13
|
-
.
|
|
14
|
-
.
|
|
15
|
-
|
|
13
|
+
.catch(function (error) {
|
|
14
|
+
console.warn("Can't load saved state", error);
|
|
15
|
+
})
|
|
16
|
+
.finally(function () {
|
|
17
|
+
setIsLoaded(true);
|
|
18
|
+
});
|
|
19
|
+
}, []); // eslint-disable-line react-hooks/exhaustive-deps
|
|
16
20
|
return { isLoaded: isLoaded, savedState: savedState };
|
|
17
21
|
};
|
|
18
22
|
exports.useSavedState = useSavedState;
|
|
@@ -41,9 +41,13 @@ var useSavedStateForEntityType = function (_a) {
|
|
|
41
41
|
.then(function (savedState) {
|
|
42
42
|
setSavedState(savedState || {});
|
|
43
43
|
})
|
|
44
|
-
.
|
|
45
|
-
.
|
|
46
|
-
|
|
44
|
+
.catch(function (error) {
|
|
45
|
+
console.warn("Can't load saved state for entity type", error);
|
|
46
|
+
})
|
|
47
|
+
.finally(function () {
|
|
48
|
+
setIsLoaded(true);
|
|
49
|
+
});
|
|
50
|
+
}, []); // eslint-disable-line react-hooks/exhaustive-deps
|
|
47
51
|
return { isLoaded: isLoaded && !!entityTypeUri, savedState: savedState[entityTypeUri], updateSavedState: updateSavedState };
|
|
48
52
|
};
|
|
49
53
|
exports.useSavedStateForEntityType = useSavedStateForEntityType;
|
|
@@ -46,7 +46,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
46
46
|
}
|
|
47
47
|
};
|
|
48
48
|
import React from 'react';
|
|
49
|
-
import { render, screen, act } from '@testing-library/react';
|
|
49
|
+
import { render, screen, act, waitForElementToBeRemoved } from '@testing-library/react';
|
|
50
50
|
import userEvent from '@testing-library/user-event';
|
|
51
51
|
import { getAssigneeForTask, updateAssigneeForTask } from '@reltio/mdm-sdk';
|
|
52
52
|
import { MdmModuleProvider } from '../../../contexts/MdmModuleContext';
|
|
@@ -267,4 +267,84 @@ describe('AssigneeSelector tests', function () {
|
|
|
267
267
|
}
|
|
268
268
|
});
|
|
269
269
|
}); });
|
|
270
|
+
it('should make a single request on load, show loading state, and not re-fetch if assignees are already loaded', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
271
|
+
var user, input;
|
|
272
|
+
return __generator(this, function (_a) {
|
|
273
|
+
switch (_a.label) {
|
|
274
|
+
case 0:
|
|
275
|
+
user = setUp().user;
|
|
276
|
+
return [4 /*yield*/, screen.findByText('Assigned to')];
|
|
277
|
+
case 1:
|
|
278
|
+
_a.sent();
|
|
279
|
+
expect(getAssigneeForTask).toHaveBeenCalledTimes(1);
|
|
280
|
+
input = screen.getByRole('combobox');
|
|
281
|
+
return [4 /*yield*/, user.click(input)];
|
|
282
|
+
case 2:
|
|
283
|
+
_a.sent();
|
|
284
|
+
expect(screen.getByText('Loading...')).toBeInTheDocument();
|
|
285
|
+
act(function () {
|
|
286
|
+
resolveAssigneeForTask(response);
|
|
287
|
+
});
|
|
288
|
+
return [4 /*yield*/, waitForElementToBeRemoved(screen.queryByText('Loading...'))];
|
|
289
|
+
case 3:
|
|
290
|
+
_a.sent();
|
|
291
|
+
return [4 /*yield*/, screen.findByText('user1')];
|
|
292
|
+
case 4:
|
|
293
|
+
_a.sent();
|
|
294
|
+
return [4 /*yield*/, screen.findByText('user2')];
|
|
295
|
+
case 5:
|
|
296
|
+
_a.sent();
|
|
297
|
+
return [4 /*yield*/, screen.findByText('firstUser')];
|
|
298
|
+
case 6:
|
|
299
|
+
_a.sent();
|
|
300
|
+
return [4 /*yield*/, user.type(input, 'user')];
|
|
301
|
+
case 7:
|
|
302
|
+
_a.sent();
|
|
303
|
+
expect(getAssigneeForTask).toHaveBeenCalledTimes(1);
|
|
304
|
+
return [4 /*yield*/, user.clear(input)];
|
|
305
|
+
case 8:
|
|
306
|
+
_a.sent();
|
|
307
|
+
return [4 /*yield*/, user.type(input, 'first')];
|
|
308
|
+
case 9:
|
|
309
|
+
_a.sent();
|
|
310
|
+
expect(getAssigneeForTask).toHaveBeenCalledTimes(1);
|
|
311
|
+
return [2 /*return*/];
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
}); });
|
|
315
|
+
it('should correctly filter options based on user input', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
316
|
+
var user, input;
|
|
317
|
+
return __generator(this, function (_a) {
|
|
318
|
+
switch (_a.label) {
|
|
319
|
+
case 0:
|
|
320
|
+
user = setUp().user;
|
|
321
|
+
return [4 /*yield*/, screen.findByText('Assigned to')];
|
|
322
|
+
case 1:
|
|
323
|
+
_a.sent();
|
|
324
|
+
input = screen.getByRole('combobox');
|
|
325
|
+
return [4 /*yield*/, user.click(input)];
|
|
326
|
+
case 2:
|
|
327
|
+
_a.sent();
|
|
328
|
+
act(function () {
|
|
329
|
+
resolveAssigneeForTask(response);
|
|
330
|
+
});
|
|
331
|
+
return [4 /*yield*/, screen.findByText('user2')];
|
|
332
|
+
case 3:
|
|
333
|
+
_a.sent();
|
|
334
|
+
return [4 /*yield*/, user.type(input, 'user2')];
|
|
335
|
+
case 4:
|
|
336
|
+
_a.sent();
|
|
337
|
+
expect(screen.getByText('user2')).toBeInTheDocument();
|
|
338
|
+
expect(screen.queryByText('user1')).not.toBeInTheDocument();
|
|
339
|
+
expect(screen.queryByText('firstUser')).not.toBeInTheDocument();
|
|
340
|
+
return [4 /*yield*/, user.clear(input)];
|
|
341
|
+
case 5:
|
|
342
|
+
_a.sent();
|
|
343
|
+
expect(screen.getByText('user1')).toBeInTheDocument();
|
|
344
|
+
expect(screen.getByText('user2')).toBeInTheDocument();
|
|
345
|
+
expect(screen.getByText('firstUser')).toBeInTheDocument();
|
|
346
|
+
return [2 /*return*/];
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
}); });
|
|
270
350
|
});
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { useState, useEffect, useCallback, useContext } from 'react';
|
|
2
|
-
import { filter } from 'ramda';
|
|
1
|
+
import { useState, useEffect, useCallback, useContext, useRef } from 'react';
|
|
3
2
|
import { getAssigneeForTask, updateAssigneeForTask, utils } from '@reltio/mdm-sdk';
|
|
4
3
|
import { useSafePromise } from '../../../hooks/useSafePromise';
|
|
5
4
|
import { WorkflowTasksContext } from '../../../contexts/WorkflowTasksContext';
|
|
@@ -11,6 +10,9 @@ var assigneeToValue = function (assignee) { return ({
|
|
|
11
10
|
label: assignee,
|
|
12
11
|
value: assignee
|
|
13
12
|
}); };
|
|
13
|
+
var filterAssignees = function (assignees, text) {
|
|
14
|
+
return assignees.filter(function (item) { return item.value.toLowerCase().includes(text === null || text === void 0 ? void 0 : text.toLowerCase()); });
|
|
15
|
+
};
|
|
14
16
|
export var useWorkflowAssignee = function (_a) {
|
|
15
17
|
var assignee = _a.assignee, _b = _a.showCurrentAssignee, showCurrentAssignee = _b === void 0 ? true : _b, taskId = _a.taskId, isOpen = _a.isOpen, onChange = _a.onChange;
|
|
16
18
|
var updateTaskState = (useContext(WorkflowTasksContext) || {}).updateTaskState;
|
|
@@ -18,56 +20,42 @@ export var useWorkflowAssignee = function (_a) {
|
|
|
18
20
|
var environment = useMdmWorkflowEnvironmentUrl();
|
|
19
21
|
var tenant = useMdmTenant();
|
|
20
22
|
var updateSafePromise = useSafePromise();
|
|
21
|
-
var getSafePromise = useSafePromise();
|
|
22
23
|
var _c = useState(null), currentAssignee = _c[0], setCurrentAssignee = _c[1];
|
|
23
|
-
var _d = useState(),
|
|
24
|
-
var _e = useState(false), updateRequestIsInProgress = _e[0], setUpdateRequestIsInProgress = _e[1];
|
|
24
|
+
var _d = useState(false), updateRequestIsInProgress = _d[0], setUpdateRequestIsInProgress = _d[1];
|
|
25
25
|
var checkWorkflowPermission = useWorkflowCheckPermission();
|
|
26
26
|
var canUpdateTask = checkWorkflowPermission('UPDATE_TASK') && isOpenTask(isOpen);
|
|
27
|
+
var assigneesRequestRef = useRef(null);
|
|
27
28
|
useEffect(function () {
|
|
28
29
|
if (showCurrentAssignee)
|
|
29
30
|
setCurrentAssignee(assigneeToValue(assignee));
|
|
30
|
-
},
|
|
31
|
+
},
|
|
32
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
33
|
+
[assignee]);
|
|
31
34
|
var getAssignees = useCallback(function (text) {
|
|
32
35
|
if (workflowPath && canUpdateTask && taskId) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
if (!assigneesRequestRef.current) {
|
|
37
|
+
assigneesRequestRef.current = getAssigneeForTask({
|
|
38
|
+
taskId: taskId,
|
|
39
|
+
workflowPath: workflowPath,
|
|
40
|
+
environment: environment,
|
|
41
|
+
tenant: tenant
|
|
42
|
+
});
|
|
38
43
|
}
|
|
39
|
-
return
|
|
40
|
-
taskId: taskId,
|
|
41
|
-
workflowPath: workflowPath,
|
|
42
|
-
environment: environment,
|
|
43
|
-
tenant: tenant
|
|
44
|
-
}))
|
|
44
|
+
return assigneesRequestRef.current
|
|
45
45
|
.then(function (result) {
|
|
46
46
|
var data = result.data;
|
|
47
|
-
var
|
|
47
|
+
var fetchedAssignees = data
|
|
48
48
|
.filter(function (a) { return (showCurrentAssignee ? true : a !== assignee); })
|
|
49
|
-
.sort(function (a, b) {
|
|
50
|
-
return utils.strings.sort('asc', a, b);
|
|
51
|
-
})
|
|
49
|
+
.sort(function (a, b) { return utils.strings.sort('asc', a, b); })
|
|
52
50
|
.map(assigneeToValue);
|
|
53
|
-
|
|
54
|
-
return filterOutRest_1(assignees);
|
|
51
|
+
return filterAssignees(fetchedAssignees, text);
|
|
55
52
|
})
|
|
56
|
-
.catch(
|
|
53
|
+
.catch(function (e) {
|
|
54
|
+
showWorkflowError(e);
|
|
55
|
+
assigneesRequestRef.current = null;
|
|
56
|
+
});
|
|
57
57
|
}
|
|
58
|
-
},
|
|
59
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
60
|
-
[
|
|
61
|
-
workflowPath,
|
|
62
|
-
taskId,
|
|
63
|
-
environment,
|
|
64
|
-
tenant,
|
|
65
|
-
assignees,
|
|
66
|
-
setAssignees,
|
|
67
|
-
canUpdateTask,
|
|
68
|
-
assignee,
|
|
69
|
-
showCurrentAssignee
|
|
70
|
-
]);
|
|
58
|
+
}, [workflowPath, taskId, environment, tenant, canUpdateTask, assignee, showCurrentAssignee]);
|
|
71
59
|
var updateAssignee = useCallback(function (newValue) {
|
|
72
60
|
var assignee = newValue.value;
|
|
73
61
|
if (onChange) {
|
|
@@ -69,7 +69,9 @@ export var useCommentsEntitiesMap = function (comments) {
|
|
|
69
69
|
}, __assign({}, prevEntitiesMap));
|
|
70
70
|
});
|
|
71
71
|
})
|
|
72
|
-
.catch(function () {
|
|
72
|
+
.catch(function (error) {
|
|
73
|
+
console.warn("Can't load entities for comments map", error);
|
|
74
|
+
});
|
|
73
75
|
}
|
|
74
76
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
75
77
|
}, [getEntities, addNotFoundEntities, comments, currentEntityUri]);
|
|
@@ -86,7 +86,7 @@ export var useMatchesLoader = function (_a) {
|
|
|
86
86
|
setMatches(response);
|
|
87
87
|
})
|
|
88
88
|
.catch(function (error) {
|
|
89
|
-
console.warn("Can't load matches:", error);
|
|
89
|
+
console.warn("Can't load entities or total for matches:", error);
|
|
90
90
|
setMatches([]);
|
|
91
91
|
setTotal(0);
|
|
92
92
|
})
|
|
@@ -31,7 +31,8 @@ export var usePivotingDataLoader = function (_a) {
|
|
|
31
31
|
setEntities(Array.isArray(entities) ? entities : []);
|
|
32
32
|
setTotal(total);
|
|
33
33
|
})
|
|
34
|
-
.catch(function () {
|
|
34
|
+
.catch(function (error) {
|
|
35
|
+
console.warn("Can't load entities or total for pivoting data", error);
|
|
35
36
|
setEntities([]);
|
|
36
37
|
setTotal(0);
|
|
37
38
|
});
|
|
@@ -7,8 +7,12 @@ export var useSavedState = function (getSavedState) {
|
|
|
7
7
|
.then(function (savedState) {
|
|
8
8
|
setSavedState(savedState || {});
|
|
9
9
|
})
|
|
10
|
-
.
|
|
11
|
-
.
|
|
12
|
-
|
|
10
|
+
.catch(function (error) {
|
|
11
|
+
console.warn("Can't load saved state", error);
|
|
12
|
+
})
|
|
13
|
+
.finally(function () {
|
|
14
|
+
setIsLoaded(true);
|
|
15
|
+
});
|
|
16
|
+
}, []); // eslint-disable-line react-hooks/exhaustive-deps
|
|
13
17
|
return { isLoaded: isLoaded, savedState: savedState };
|
|
14
18
|
};
|
|
@@ -38,8 +38,12 @@ export var useSavedStateForEntityType = function (_a) {
|
|
|
38
38
|
.then(function (savedState) {
|
|
39
39
|
setSavedState(savedState || {});
|
|
40
40
|
})
|
|
41
|
-
.
|
|
42
|
-
.
|
|
43
|
-
|
|
41
|
+
.catch(function (error) {
|
|
42
|
+
console.warn("Can't load saved state for entity type", error);
|
|
43
|
+
})
|
|
44
|
+
.finally(function () {
|
|
45
|
+
setIsLoaded(true);
|
|
46
|
+
});
|
|
47
|
+
}, []); // eslint-disable-line react-hooks/exhaustive-deps
|
|
44
48
|
return { isLoaded: isLoaded && !!entityTypeUri, savedState: savedState[entityTypeUri], updateSavedState: updateSavedState };
|
|
45
49
|
};
|