@reltio/components 1.4.2277 → 1.4.2278
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/hooks/useAPI/useAPI.js +6 -4
- package/cjs/hooks/useAPI/useAPI.test.js +31 -0
- package/cjs/hooks/useCustomScripts/useCustomScripts.js +12 -4
- package/cjs/hooks/useCustomScripts/useCustomScripts.test.js +78 -2
- package/hooks/useAPI/useAPI.js +7 -5
- package/hooks/useAPI/useAPI.test.js +31 -0
- package/hooks/useCustomScripts/useCustomScripts.js +13 -5
- package/hooks/useCustomScripts/useCustomScripts.test.js +78 -2
- package/package.json +1 -1
|
@@ -36,6 +36,7 @@ var useAPI = function (config) {
|
|
|
36
36
|
var _j = (0, react_1.useState)({}), customStyles = _j[0], setCustomStyles = _j[1];
|
|
37
37
|
var workerRef = (0, react_1.useRef)(null);
|
|
38
38
|
var entityRef = (0, react_1.useRef)(null);
|
|
39
|
+
var searchQueryRef = (0, react_1.useRef)(null);
|
|
39
40
|
var requestListeners = (0, react_1.useRef)({});
|
|
40
41
|
var responseListeners = (0, react_1.useRef)({});
|
|
41
42
|
var sanitizeHtml = (0, useHtmlSanitizer_1.useHtmlSanitizer)();
|
|
@@ -54,7 +55,6 @@ var useAPI = function (config) {
|
|
|
54
55
|
var reltioPath = (0, MdmModuleContext_1.useMdmReltioPath)();
|
|
55
56
|
var workflowPath = (0, MdmModuleContext_1.useMdmWorkflowPath)();
|
|
56
57
|
var user = (0, MdmModuleContext_1.useMdmUser)();
|
|
57
|
-
var entityUri = (0, MdmModuleContext_1.useMdmEntityUri)();
|
|
58
58
|
var isEditableMode = (0, MdmModuleContext_1.useMdmIsEditableMode)();
|
|
59
59
|
var environment = (0, MdmModuleContext_1.useMdmWorkflowEnvironmentUrl)();
|
|
60
60
|
var searchProviderData = (0, MdmModuleContext_1.useMdmSearchProviderData)();
|
|
@@ -62,6 +62,7 @@ var useAPI = function (config) {
|
|
|
62
62
|
var innerText = '';
|
|
63
63
|
var popupText = '';
|
|
64
64
|
var process = function (_a) {
|
|
65
|
+
var _b;
|
|
65
66
|
var task = _a.task, worker = _a.worker;
|
|
66
67
|
if (task) {
|
|
67
68
|
switch (task.action) {
|
|
@@ -147,11 +148,11 @@ var useAPI = function (config) {
|
|
|
147
148
|
}
|
|
148
149
|
case mdm_sdk_1.CustomAction.REQUEST: {
|
|
149
150
|
var processedTask = (0, customScript_1.getProcessedTask)(task, apiPath, reltioPath, tenant);
|
|
150
|
-
(0, API_1.processRequest)(__assign({ params: processedTask.params, permissions: config.action.permissions, worker: worker, metadata: metadata, config: config, user: user, servicesPath: servicesPath, apiPath: reltioPath, tenant: tenant, workflowPath: workflowPath, entity: entityRef.current, entityUri:
|
|
151
|
+
(0, API_1.processRequest)(__assign({ params: processedTask.params, permissions: config.action.permissions, worker: worker, metadata: metadata, config: config, user: user, servicesPath: servicesPath, apiPath: reltioPath, tenant: tenant, workflowPath: workflowPath, entity: entityRef.current, entityUri: (_b = entityRef.current) === null || _b === void 0 ? void 0 : _b.uri, environment: environment, query: searchQueryRef.current, openSearch: openSearch, workflowCheckPermission: workflowCheckPermission }, qxApi));
|
|
151
152
|
break;
|
|
152
153
|
}
|
|
153
154
|
case mdm_sdk_1.CustomAction.RETURN_PROCESSED_API_RESPONSE: {
|
|
154
|
-
var
|
|
155
|
+
var _c = task.params, id = _c.id, data = _c.data;
|
|
155
156
|
if (responseListeners.current[id]) {
|
|
156
157
|
responseListeners.current[id].next(data);
|
|
157
158
|
responseListeners.current = (0, ramda_1.omit)([id], responseListeners.current);
|
|
@@ -159,7 +160,7 @@ var useAPI = function (config) {
|
|
|
159
160
|
break;
|
|
160
161
|
}
|
|
161
162
|
case mdm_sdk_1.CustomAction.RETURN_PROCESSED_API_REQUEST: {
|
|
162
|
-
var
|
|
163
|
+
var _d = task.params, id = _d.id, data = _d.data;
|
|
163
164
|
if (requestListeners.current[id]) {
|
|
164
165
|
requestListeners.current[id].resolve(data);
|
|
165
166
|
requestListeners.current = (0, ramda_1.omit)([id], requestListeners.current);
|
|
@@ -224,6 +225,7 @@ var useAPI = function (config) {
|
|
|
224
225
|
postEventMessage('editMode', isEditableMode);
|
|
225
226
|
}, [isEditableMode]);
|
|
226
227
|
(0, react_1.useEffect)(function () {
|
|
228
|
+
searchQueryRef.current = searchQuery;
|
|
227
229
|
postEventMessage('changeSearchQuery', searchQuery);
|
|
228
230
|
}, [searchQuery]);
|
|
229
231
|
(0, react_1.useEffect)(function () {
|
|
@@ -1040,6 +1040,37 @@ describe('useAPI custom sandbox behavior', function () {
|
|
|
1040
1040
|
});
|
|
1041
1041
|
expect(postMessage).toHaveBeenCalledWith(__assign({ action: 'response', result: 'entities/mnGg0XB' }, params));
|
|
1042
1042
|
});
|
|
1043
|
+
it('should return the current entityUri on getEntityUri after navigating to another entity', function () {
|
|
1044
|
+
var updateMdmValues = setUp().updateMdmValues;
|
|
1045
|
+
(0, react_2.act)(function () {
|
|
1046
|
+
onmessageFromWorker({
|
|
1047
|
+
action: mdm_sdk_1.CustomAction.REQUEST,
|
|
1048
|
+
params: { name: mdm_sdk_1.RequestAction.GET_ENTITY_URI, id: 1 }
|
|
1049
|
+
});
|
|
1050
|
+
});
|
|
1051
|
+
expect(postMessage).toHaveBeenLastCalledWith({
|
|
1052
|
+
action: 'response',
|
|
1053
|
+
result: 'entities/mnGg0XB',
|
|
1054
|
+
name: mdm_sdk_1.RequestAction.GET_ENTITY_URI,
|
|
1055
|
+
id: 1
|
|
1056
|
+
});
|
|
1057
|
+
var newEntity = { uri: 'entities/NEW999', type: 'configuration/entityTypes/HCA', attributes: {} };
|
|
1058
|
+
(0, react_2.act)(function () {
|
|
1059
|
+
updateMdmValues(function (prev) { return (__assign(__assign({}, prev), { entity: newEntity })); });
|
|
1060
|
+
});
|
|
1061
|
+
(0, react_2.act)(function () {
|
|
1062
|
+
onmessageFromWorker({
|
|
1063
|
+
action: mdm_sdk_1.CustomAction.REQUEST,
|
|
1064
|
+
params: { name: mdm_sdk_1.RequestAction.GET_ENTITY_URI, id: 2 }
|
|
1065
|
+
});
|
|
1066
|
+
});
|
|
1067
|
+
expect(postMessage).toHaveBeenLastCalledWith({
|
|
1068
|
+
action: 'response',
|
|
1069
|
+
result: 'entities/NEW999',
|
|
1070
|
+
name: mdm_sdk_1.RequestAction.GET_ENTITY_URI,
|
|
1071
|
+
id: 2
|
|
1072
|
+
});
|
|
1073
|
+
});
|
|
1043
1074
|
it('should return entity on getEntity request', function () {
|
|
1044
1075
|
setUp();
|
|
1045
1076
|
var params = {
|
|
@@ -69,7 +69,6 @@ var useCustomScripts = function (config) {
|
|
|
69
69
|
var apiPath = (0, MdmModuleContext_1.useMdmApiPath)();
|
|
70
70
|
var workflowPath = (0, MdmModuleContext_1.useMdmWorkflowPath)();
|
|
71
71
|
var user = (0, MdmModuleContext_1.useMdmUser)();
|
|
72
|
-
var entityUri = (0, MdmModuleContext_1.useMdmEntityUri)();
|
|
73
72
|
var environment = (0, MdmModuleContext_1.useMdmWorkflowEnvironmentUrl)();
|
|
74
73
|
var workflowCheckPermission = (0, workflow_1.useWorkflowCheckPermission)();
|
|
75
74
|
var searchProviderData = (0, MdmModuleContext_1.useMdmSearchProviderData)();
|
|
@@ -77,7 +76,10 @@ var useCustomScripts = function (config) {
|
|
|
77
76
|
var requestListeners = (0, react_1.useRef)({});
|
|
78
77
|
var responseListeners = (0, react_1.useRef)({});
|
|
79
78
|
var workers = (0, react_1.useRef)({});
|
|
79
|
+
var entityRef = (0, react_1.useRef)(null);
|
|
80
|
+
var searchQueryRef = (0, react_1.useRef)(null);
|
|
80
81
|
var processMessageFromWorker = function (_a) {
|
|
82
|
+
var _b;
|
|
81
83
|
var task = _a.task, worker = _a.worker, config = _a.config;
|
|
82
84
|
if (task) {
|
|
83
85
|
switch (task.action) {
|
|
@@ -91,11 +93,11 @@ var useCustomScripts = function (config) {
|
|
|
91
93
|
}
|
|
92
94
|
case mdm_sdk_1.CustomAction.REQUEST: {
|
|
93
95
|
var processedTask = (0, customScript_1.getProcessedTask)(task, apiPath, reltioPath, tenant);
|
|
94
|
-
(0, useAPI_1.processRequest)(__assign({ params: processedTask.params, permissions: config.action.permissions, worker: worker, metadata: metadata, config: config, user: user, apiPath: reltioPath, servicesPath: servicesPath, tenant: tenant, workflowPath: workflowPath, entity:
|
|
96
|
+
(0, useAPI_1.processRequest)(__assign({ params: processedTask.params, permissions: config.action.permissions, worker: worker, metadata: metadata, config: config, user: user, apiPath: reltioPath, servicesPath: servicesPath, tenant: tenant, workflowPath: workflowPath, entity: entityRef.current, entityUri: (_b = entityRef.current) === null || _b === void 0 ? void 0 : _b.uri, environment: environment, query: searchQueryRef.current, openSearch: openSearch, workflowCheckPermission: workflowCheckPermission }, qxApi));
|
|
95
97
|
break;
|
|
96
98
|
}
|
|
97
99
|
case mdm_sdk_1.CustomAction.RETURN_PROCESSED_API_RESPONSE: {
|
|
98
|
-
var
|
|
100
|
+
var _c = task.params, id = _c.id, data = _c.data;
|
|
99
101
|
if (responseListeners.current[id]) {
|
|
100
102
|
responseListeners.current[id].next(data);
|
|
101
103
|
responseListeners.current = (0, ramda_1.omit)([id], responseListeners.current);
|
|
@@ -103,7 +105,7 @@ var useCustomScripts = function (config) {
|
|
|
103
105
|
break;
|
|
104
106
|
}
|
|
105
107
|
case mdm_sdk_1.CustomAction.RETURN_PROCESSED_API_REQUEST: {
|
|
106
|
-
var
|
|
108
|
+
var _d = task.params, id = _d.id, data = _d.data;
|
|
107
109
|
if (requestListeners.current[id]) {
|
|
108
110
|
requestListeners.current[id].resolve(data);
|
|
109
111
|
requestListeners.current = (0, ramda_1.omit)([id], requestListeners.current);
|
|
@@ -127,6 +129,12 @@ var useCustomScripts = function (config) {
|
|
|
127
129
|
};
|
|
128
130
|
}
|
|
129
131
|
}, [config, metadata]);
|
|
132
|
+
(0, react_1.useEffect)(function () {
|
|
133
|
+
entityRef.current = entity;
|
|
134
|
+
}, [entity]);
|
|
135
|
+
(0, react_1.useEffect)(function () {
|
|
136
|
+
searchQueryRef.current = searchQuery;
|
|
137
|
+
}, [searchQuery]);
|
|
130
138
|
var customScriptRequestInterceptor = function (_a) {
|
|
131
139
|
var _b;
|
|
132
140
|
var url = _a.url, next = _a.next, resolve = _a.resolve, _c = _a.options, options = _c === void 0 ? {} : _c;
|
|
@@ -122,13 +122,16 @@ describe('useCustomScripts', function () {
|
|
|
122
122
|
};
|
|
123
123
|
var setUp = function (_a) {
|
|
124
124
|
var _b = _a === void 0 ? {} : _a, _c = _b.mdmValues, mdmValues = _c === void 0 ? defaultMdmValues : _c, _d = _b.config, config = _d === void 0 ? createConfig() : _d;
|
|
125
|
+
var updateMdmValues;
|
|
125
126
|
var Providers = function (_a) {
|
|
126
127
|
var children = _a.children;
|
|
127
|
-
|
|
128
|
+
var _b = react_1.default.useState(mdmValues), mdmValuesState = _b[0], setMdmValuesState = _b[1];
|
|
129
|
+
updateMdmValues = setMdmValuesState;
|
|
130
|
+
return (react_1.default.createElement(MdmModuleContext_1.MdmModuleProvider, { values: mdmValuesState },
|
|
128
131
|
react_1.default.createElement(SnackbarContext_1.SnackbarContext.Provider, { value: showSnackbarMessage },
|
|
129
132
|
react_1.default.createElement(InterceptHandlersContext_1.InterceptHandlersContext.Provider, { value: interceptors }, children))));
|
|
130
133
|
};
|
|
131
|
-
return (0, react_2.renderHook)(useCustomScripts_1.useCustomScripts, { initialProps: config, wrapper: Providers });
|
|
134
|
+
return __assign(__assign({}, (0, react_2.renderHook)(useCustomScripts_1.useCustomScripts, { initialProps: config, wrapper: Providers })), { updateMdmValues: updateMdmValues });
|
|
132
135
|
};
|
|
133
136
|
var postMessage = jest.fn();
|
|
134
137
|
var onmessageFromWorker;
|
|
@@ -488,4 +491,77 @@ describe('useCustomScripts', function () {
|
|
|
488
491
|
}
|
|
489
492
|
});
|
|
490
493
|
}); });
|
|
494
|
+
it('should resolve getEntityUri/getEntity with the current entity after navigation', function () {
|
|
495
|
+
var entityA = { uri: 'entities/AAA', type: 'configuration/entityTypes/HCA', attributes: {} };
|
|
496
|
+
var entityB = { uri: 'entities/BBB', type: 'configuration/entityTypes/HCA', attributes: {} };
|
|
497
|
+
var updateMdmValues = setUp({ mdmValues: __assign(__assign({}, defaultMdmValues), { entity: entityA }) }).updateMdmValues;
|
|
498
|
+
(0, react_2.act)(function () {
|
|
499
|
+
onmessageFromWorker({
|
|
500
|
+
action: mdm_sdk_1.CustomAction.REQUEST,
|
|
501
|
+
params: { name: mdm_sdk_1.RequestAction.GET_ENTITY_URI, id: 'id1' }
|
|
502
|
+
});
|
|
503
|
+
});
|
|
504
|
+
expect(postMessage).toHaveBeenLastCalledWith({
|
|
505
|
+
action: 'response',
|
|
506
|
+
result: 'entities/AAA',
|
|
507
|
+
name: mdm_sdk_1.RequestAction.GET_ENTITY_URI,
|
|
508
|
+
id: 'id1'
|
|
509
|
+
});
|
|
510
|
+
(0, react_2.act)(function () {
|
|
511
|
+
updateMdmValues(function (prev) { return (__assign(__assign({}, prev), { entity: entityB })); });
|
|
512
|
+
});
|
|
513
|
+
(0, react_2.act)(function () {
|
|
514
|
+
onmessageFromWorker({
|
|
515
|
+
action: mdm_sdk_1.CustomAction.REQUEST,
|
|
516
|
+
params: { name: mdm_sdk_1.RequestAction.GET_ENTITY_URI, id: 'id2' }
|
|
517
|
+
});
|
|
518
|
+
});
|
|
519
|
+
expect(postMessage).toHaveBeenLastCalledWith({
|
|
520
|
+
action: 'response',
|
|
521
|
+
result: 'entities/BBB',
|
|
522
|
+
name: mdm_sdk_1.RequestAction.GET_ENTITY_URI,
|
|
523
|
+
id: 'id2'
|
|
524
|
+
});
|
|
525
|
+
(0, react_2.act)(function () {
|
|
526
|
+
onmessageFromWorker({ action: mdm_sdk_1.CustomAction.REQUEST, params: { name: mdm_sdk_1.RequestAction.GET_ENTITY, id: 'id3' } });
|
|
527
|
+
});
|
|
528
|
+
expect(postMessage).toHaveBeenLastCalledWith({
|
|
529
|
+
action: 'response',
|
|
530
|
+
result: entityB,
|
|
531
|
+
name: mdm_sdk_1.RequestAction.GET_ENTITY,
|
|
532
|
+
id: 'id3'
|
|
533
|
+
});
|
|
534
|
+
});
|
|
535
|
+
it('should resolve getSearchQuery with the current query after it changes', function () {
|
|
536
|
+
var updateMdmValues = setUp({
|
|
537
|
+
mdmValues: __assign(__assign({}, defaultMdmValues), { searchProviderData: { type: 'search', data: { query: 'q1' } } })
|
|
538
|
+
}).updateMdmValues;
|
|
539
|
+
(0, react_2.act)(function () {
|
|
540
|
+
onmessageFromWorker({
|
|
541
|
+
action: mdm_sdk_1.CustomAction.REQUEST,
|
|
542
|
+
params: { name: mdm_sdk_1.RequestAction.GET_SEARCH_QUERY, id: 'id1' }
|
|
543
|
+
});
|
|
544
|
+
});
|
|
545
|
+
expect(postMessage).toHaveBeenLastCalledWith({
|
|
546
|
+
action: 'response',
|
|
547
|
+
result: 'q1',
|
|
548
|
+
name: mdm_sdk_1.RequestAction.GET_SEARCH_QUERY,
|
|
549
|
+
id: 'id1'
|
|
550
|
+
});
|
|
551
|
+
(0, react_2.act)(function () {
|
|
552
|
+
updateMdmValues(function (prev) { return (__assign(__assign({}, prev), { searchProviderData: { type: 'search', data: { query: 'q2' } } })); });
|
|
553
|
+
});
|
|
554
|
+
(0, react_2.act)(function () {
|
|
555
|
+
onmessageFromWorker({
|
|
556
|
+
action: mdm_sdk_1.CustomAction.REQUEST,
|
|
557
|
+
params: { name: mdm_sdk_1.RequestAction.GET_SEARCH_QUERY, id: 'id2' }
|
|
558
|
+
});
|
|
559
|
+
});
|
|
560
|
+
expect(postMessage).toHaveBeenLastCalledWith({
|
|
561
|
+
action: 'response',
|
|
562
|
+
result: 'q2',
|
|
563
|
+
name: mdm_sdk_1.RequestAction.GET_SEARCH_QUERY,
|
|
564
|
+
id: 'id2'
|
|
565
|
+
});
|
|
566
|
+
});
|
|
491
567
|
});
|
package/hooks/useAPI/useAPI.js
CHANGED
|
@@ -17,7 +17,7 @@ import { useHtmlSanitizer } from '../useHtmlSanitizer';
|
|
|
17
17
|
import { InterceptHandlersContext } from '../../contexts/InterceptHandlersContext';
|
|
18
18
|
import { SandboxAPIContext } from '../../contexts/SandboxAPIContext';
|
|
19
19
|
import { SnackbarContext } from '../../contexts/SnackbarContext';
|
|
20
|
-
import { useMdmAction, useMdmApiPath, useMdmEntity,
|
|
20
|
+
import { useMdmAction, useMdmApiPath, useMdmEntity, useMdmIsEditableMode, useMdmMetadata, useMdmReltioPath, useMdmSearchProviderData, useMdmServicesPath, useMdmTenant, useMdmUiPath, useMdmUser, useMdmWorkflowEnvironmentUrl, useMdmWorkflowPath } from '../../contexts/MdmModuleContext';
|
|
21
21
|
import { processRequest } from './API';
|
|
22
22
|
import { getWorkerURL, isValidCustomScript, resetHtml, getProcessedTask, setUpRequestInterceptor, setUpResponseInterceptor } from '../../helpers/customScript';
|
|
23
23
|
export var useAPI = function (config) {
|
|
@@ -33,6 +33,7 @@ export var useAPI = function (config) {
|
|
|
33
33
|
var _j = useState({}), customStyles = _j[0], setCustomStyles = _j[1];
|
|
34
34
|
var workerRef = useRef(null);
|
|
35
35
|
var entityRef = useRef(null);
|
|
36
|
+
var searchQueryRef = useRef(null);
|
|
36
37
|
var requestListeners = useRef({});
|
|
37
38
|
var responseListeners = useRef({});
|
|
38
39
|
var sanitizeHtml = useHtmlSanitizer();
|
|
@@ -51,7 +52,6 @@ export var useAPI = function (config) {
|
|
|
51
52
|
var reltioPath = useMdmReltioPath();
|
|
52
53
|
var workflowPath = useMdmWorkflowPath();
|
|
53
54
|
var user = useMdmUser();
|
|
54
|
-
var entityUri = useMdmEntityUri();
|
|
55
55
|
var isEditableMode = useMdmIsEditableMode();
|
|
56
56
|
var environment = useMdmWorkflowEnvironmentUrl();
|
|
57
57
|
var searchProviderData = useMdmSearchProviderData();
|
|
@@ -59,6 +59,7 @@ export var useAPI = function (config) {
|
|
|
59
59
|
var innerText = '';
|
|
60
60
|
var popupText = '';
|
|
61
61
|
var process = function (_a) {
|
|
62
|
+
var _b;
|
|
62
63
|
var task = _a.task, worker = _a.worker;
|
|
63
64
|
if (task) {
|
|
64
65
|
switch (task.action) {
|
|
@@ -144,11 +145,11 @@ export var useAPI = function (config) {
|
|
|
144
145
|
}
|
|
145
146
|
case CustomAction.REQUEST: {
|
|
146
147
|
var processedTask = getProcessedTask(task, apiPath, reltioPath, tenant);
|
|
147
|
-
processRequest(__assign({ params: processedTask.params, permissions: config.action.permissions, worker: worker, metadata: metadata, config: config, user: user, servicesPath: servicesPath, apiPath: reltioPath, tenant: tenant, workflowPath: workflowPath, entity: entityRef.current, entityUri:
|
|
148
|
+
processRequest(__assign({ params: processedTask.params, permissions: config.action.permissions, worker: worker, metadata: metadata, config: config, user: user, servicesPath: servicesPath, apiPath: reltioPath, tenant: tenant, workflowPath: workflowPath, entity: entityRef.current, entityUri: (_b = entityRef.current) === null || _b === void 0 ? void 0 : _b.uri, environment: environment, query: searchQueryRef.current, openSearch: openSearch, workflowCheckPermission: workflowCheckPermission }, qxApi));
|
|
148
149
|
break;
|
|
149
150
|
}
|
|
150
151
|
case CustomAction.RETURN_PROCESSED_API_RESPONSE: {
|
|
151
|
-
var
|
|
152
|
+
var _c = task.params, id = _c.id, data = _c.data;
|
|
152
153
|
if (responseListeners.current[id]) {
|
|
153
154
|
responseListeners.current[id].next(data);
|
|
154
155
|
responseListeners.current = omit([id], responseListeners.current);
|
|
@@ -156,7 +157,7 @@ export var useAPI = function (config) {
|
|
|
156
157
|
break;
|
|
157
158
|
}
|
|
158
159
|
case CustomAction.RETURN_PROCESSED_API_REQUEST: {
|
|
159
|
-
var
|
|
160
|
+
var _d = task.params, id = _d.id, data = _d.data;
|
|
160
161
|
if (requestListeners.current[id]) {
|
|
161
162
|
requestListeners.current[id].resolve(data);
|
|
162
163
|
requestListeners.current = omit([id], requestListeners.current);
|
|
@@ -221,6 +222,7 @@ export var useAPI = function (config) {
|
|
|
221
222
|
postEventMessage('editMode', isEditableMode);
|
|
222
223
|
}, [isEditableMode]);
|
|
223
224
|
useEffect(function () {
|
|
225
|
+
searchQueryRef.current = searchQuery;
|
|
224
226
|
postEventMessage('changeSearchQuery', searchQuery);
|
|
225
227
|
}, [searchQuery]);
|
|
226
228
|
useEffect(function () {
|
|
@@ -1015,6 +1015,37 @@ describe('useAPI custom sandbox behavior', function () {
|
|
|
1015
1015
|
});
|
|
1016
1016
|
expect(postMessage).toHaveBeenCalledWith(__assign({ action: 'response', result: 'entities/mnGg0XB' }, params));
|
|
1017
1017
|
});
|
|
1018
|
+
it('should return the current entityUri on getEntityUri after navigating to another entity', function () {
|
|
1019
|
+
var updateMdmValues = setUp().updateMdmValues;
|
|
1020
|
+
act(function () {
|
|
1021
|
+
onmessageFromWorker({
|
|
1022
|
+
action: CustomAction.REQUEST,
|
|
1023
|
+
params: { name: RequestAction.GET_ENTITY_URI, id: 1 }
|
|
1024
|
+
});
|
|
1025
|
+
});
|
|
1026
|
+
expect(postMessage).toHaveBeenLastCalledWith({
|
|
1027
|
+
action: 'response',
|
|
1028
|
+
result: 'entities/mnGg0XB',
|
|
1029
|
+
name: RequestAction.GET_ENTITY_URI,
|
|
1030
|
+
id: 1
|
|
1031
|
+
});
|
|
1032
|
+
var newEntity = { uri: 'entities/NEW999', type: 'configuration/entityTypes/HCA', attributes: {} };
|
|
1033
|
+
act(function () {
|
|
1034
|
+
updateMdmValues(function (prev) { return (__assign(__assign({}, prev), { entity: newEntity })); });
|
|
1035
|
+
});
|
|
1036
|
+
act(function () {
|
|
1037
|
+
onmessageFromWorker({
|
|
1038
|
+
action: CustomAction.REQUEST,
|
|
1039
|
+
params: { name: RequestAction.GET_ENTITY_URI, id: 2 }
|
|
1040
|
+
});
|
|
1041
|
+
});
|
|
1042
|
+
expect(postMessage).toHaveBeenLastCalledWith({
|
|
1043
|
+
action: 'response',
|
|
1044
|
+
result: 'entities/NEW999',
|
|
1045
|
+
name: RequestAction.GET_ENTITY_URI,
|
|
1046
|
+
id: 2
|
|
1047
|
+
});
|
|
1048
|
+
});
|
|
1018
1049
|
it('should return entity on getEntity request', function () {
|
|
1019
1050
|
setUp();
|
|
1020
1051
|
var params = {
|
|
@@ -37,7 +37,7 @@ import { useWorkflowCheckPermission } from '../../features/workflow';
|
|
|
37
37
|
import { SnackbarContext } from '../../contexts/SnackbarContext';
|
|
38
38
|
import { SandboxAPIContext } from '../../contexts/SandboxAPIContext';
|
|
39
39
|
import { InterceptHandlersContext } from '../../contexts/InterceptHandlersContext';
|
|
40
|
-
import { useMdmAction, useMdmApiPath, useMdmEntity,
|
|
40
|
+
import { useMdmAction, useMdmApiPath, useMdmEntity, useMdmMetadata, useMdmReltioPath, useMdmSearchProviderData, useMdmServicesPath, useMdmTenant, useMdmUiPath, useMdmUser, useMdmWorkflowEnvironmentUrl, useMdmWorkflowPath } from '../../contexts/MdmModuleContext';
|
|
41
41
|
import { processRequest } from '../useAPI';
|
|
42
42
|
import { isValidCustomScript, isURLtoProcess, getProcessedTask, getRequestFakeUrl, getResponseFakeUrl, getWorkerURL } from '../../helpers/customScript';
|
|
43
43
|
var getCustomViewConfig = function (config) {
|
|
@@ -66,7 +66,6 @@ export var useCustomScripts = function (config) {
|
|
|
66
66
|
var apiPath = useMdmApiPath();
|
|
67
67
|
var workflowPath = useMdmWorkflowPath();
|
|
68
68
|
var user = useMdmUser();
|
|
69
|
-
var entityUri = useMdmEntityUri();
|
|
70
69
|
var environment = useMdmWorkflowEnvironmentUrl();
|
|
71
70
|
var workflowCheckPermission = useWorkflowCheckPermission();
|
|
72
71
|
var searchProviderData = useMdmSearchProviderData();
|
|
@@ -74,7 +73,10 @@ export var useCustomScripts = function (config) {
|
|
|
74
73
|
var requestListeners = useRef({});
|
|
75
74
|
var responseListeners = useRef({});
|
|
76
75
|
var workers = useRef({});
|
|
76
|
+
var entityRef = useRef(null);
|
|
77
|
+
var searchQueryRef = useRef(null);
|
|
77
78
|
var processMessageFromWorker = function (_a) {
|
|
79
|
+
var _b;
|
|
78
80
|
var task = _a.task, worker = _a.worker, config = _a.config;
|
|
79
81
|
if (task) {
|
|
80
82
|
switch (task.action) {
|
|
@@ -88,11 +90,11 @@ export var useCustomScripts = function (config) {
|
|
|
88
90
|
}
|
|
89
91
|
case CustomAction.REQUEST: {
|
|
90
92
|
var processedTask = getProcessedTask(task, apiPath, reltioPath, tenant);
|
|
91
|
-
processRequest(__assign({ params: processedTask.params, permissions: config.action.permissions, worker: worker, metadata: metadata, config: config, user: user, apiPath: reltioPath, servicesPath: servicesPath, tenant: tenant, workflowPath: workflowPath, entity:
|
|
93
|
+
processRequest(__assign({ params: processedTask.params, permissions: config.action.permissions, worker: worker, metadata: metadata, config: config, user: user, apiPath: reltioPath, servicesPath: servicesPath, tenant: tenant, workflowPath: workflowPath, entity: entityRef.current, entityUri: (_b = entityRef.current) === null || _b === void 0 ? void 0 : _b.uri, environment: environment, query: searchQueryRef.current, openSearch: openSearch, workflowCheckPermission: workflowCheckPermission }, qxApi));
|
|
92
94
|
break;
|
|
93
95
|
}
|
|
94
96
|
case CustomAction.RETURN_PROCESSED_API_RESPONSE: {
|
|
95
|
-
var
|
|
97
|
+
var _c = task.params, id = _c.id, data = _c.data;
|
|
96
98
|
if (responseListeners.current[id]) {
|
|
97
99
|
responseListeners.current[id].next(data);
|
|
98
100
|
responseListeners.current = omit([id], responseListeners.current);
|
|
@@ -100,7 +102,7 @@ export var useCustomScripts = function (config) {
|
|
|
100
102
|
break;
|
|
101
103
|
}
|
|
102
104
|
case CustomAction.RETURN_PROCESSED_API_REQUEST: {
|
|
103
|
-
var
|
|
105
|
+
var _d = task.params, id = _d.id, data = _d.data;
|
|
104
106
|
if (requestListeners.current[id]) {
|
|
105
107
|
requestListeners.current[id].resolve(data);
|
|
106
108
|
requestListeners.current = omit([id], requestListeners.current);
|
|
@@ -124,6 +126,12 @@ export var useCustomScripts = function (config) {
|
|
|
124
126
|
};
|
|
125
127
|
}
|
|
126
128
|
}, [config, metadata]);
|
|
129
|
+
useEffect(function () {
|
|
130
|
+
entityRef.current = entity;
|
|
131
|
+
}, [entity]);
|
|
132
|
+
useEffect(function () {
|
|
133
|
+
searchQueryRef.current = searchQuery;
|
|
134
|
+
}, [searchQuery]);
|
|
127
135
|
var customScriptRequestInterceptor = function (_a) {
|
|
128
136
|
var _b;
|
|
129
137
|
var url = _a.url, next = _a.next, resolve = _a.resolve, _c = _a.options, options = _c === void 0 ? {} : _c;
|
|
@@ -94,13 +94,16 @@ describe('useCustomScripts', function () {
|
|
|
94
94
|
};
|
|
95
95
|
var setUp = function (_a) {
|
|
96
96
|
var _b = _a === void 0 ? {} : _a, _c = _b.mdmValues, mdmValues = _c === void 0 ? defaultMdmValues : _c, _d = _b.config, config = _d === void 0 ? createConfig() : _d;
|
|
97
|
+
var updateMdmValues;
|
|
97
98
|
var Providers = function (_a) {
|
|
98
99
|
var children = _a.children;
|
|
99
|
-
|
|
100
|
+
var _b = React.useState(mdmValues), mdmValuesState = _b[0], setMdmValuesState = _b[1];
|
|
101
|
+
updateMdmValues = setMdmValuesState;
|
|
102
|
+
return (React.createElement(MdmModuleProvider, { values: mdmValuesState },
|
|
100
103
|
React.createElement(SnackbarContext.Provider, { value: showSnackbarMessage },
|
|
101
104
|
React.createElement(InterceptHandlersContext.Provider, { value: interceptors }, children))));
|
|
102
105
|
};
|
|
103
|
-
return renderHook(useCustomScripts, { initialProps: config, wrapper: Providers });
|
|
106
|
+
return __assign(__assign({}, renderHook(useCustomScripts, { initialProps: config, wrapper: Providers })), { updateMdmValues: updateMdmValues });
|
|
104
107
|
};
|
|
105
108
|
var postMessage = jest.fn();
|
|
106
109
|
var onmessageFromWorker;
|
|
@@ -460,4 +463,77 @@ describe('useCustomScripts', function () {
|
|
|
460
463
|
}
|
|
461
464
|
});
|
|
462
465
|
}); });
|
|
466
|
+
it('should resolve getEntityUri/getEntity with the current entity after navigation', function () {
|
|
467
|
+
var entityA = { uri: 'entities/AAA', type: 'configuration/entityTypes/HCA', attributes: {} };
|
|
468
|
+
var entityB = { uri: 'entities/BBB', type: 'configuration/entityTypes/HCA', attributes: {} };
|
|
469
|
+
var updateMdmValues = setUp({ mdmValues: __assign(__assign({}, defaultMdmValues), { entity: entityA }) }).updateMdmValues;
|
|
470
|
+
act(function () {
|
|
471
|
+
onmessageFromWorker({
|
|
472
|
+
action: CustomAction.REQUEST,
|
|
473
|
+
params: { name: RequestAction.GET_ENTITY_URI, id: 'id1' }
|
|
474
|
+
});
|
|
475
|
+
});
|
|
476
|
+
expect(postMessage).toHaveBeenLastCalledWith({
|
|
477
|
+
action: 'response',
|
|
478
|
+
result: 'entities/AAA',
|
|
479
|
+
name: RequestAction.GET_ENTITY_URI,
|
|
480
|
+
id: 'id1'
|
|
481
|
+
});
|
|
482
|
+
act(function () {
|
|
483
|
+
updateMdmValues(function (prev) { return (__assign(__assign({}, prev), { entity: entityB })); });
|
|
484
|
+
});
|
|
485
|
+
act(function () {
|
|
486
|
+
onmessageFromWorker({
|
|
487
|
+
action: CustomAction.REQUEST,
|
|
488
|
+
params: { name: RequestAction.GET_ENTITY_URI, id: 'id2' }
|
|
489
|
+
});
|
|
490
|
+
});
|
|
491
|
+
expect(postMessage).toHaveBeenLastCalledWith({
|
|
492
|
+
action: 'response',
|
|
493
|
+
result: 'entities/BBB',
|
|
494
|
+
name: RequestAction.GET_ENTITY_URI,
|
|
495
|
+
id: 'id2'
|
|
496
|
+
});
|
|
497
|
+
act(function () {
|
|
498
|
+
onmessageFromWorker({ action: CustomAction.REQUEST, params: { name: RequestAction.GET_ENTITY, id: 'id3' } });
|
|
499
|
+
});
|
|
500
|
+
expect(postMessage).toHaveBeenLastCalledWith({
|
|
501
|
+
action: 'response',
|
|
502
|
+
result: entityB,
|
|
503
|
+
name: RequestAction.GET_ENTITY,
|
|
504
|
+
id: 'id3'
|
|
505
|
+
});
|
|
506
|
+
});
|
|
507
|
+
it('should resolve getSearchQuery with the current query after it changes', function () {
|
|
508
|
+
var updateMdmValues = setUp({
|
|
509
|
+
mdmValues: __assign(__assign({}, defaultMdmValues), { searchProviderData: { type: 'search', data: { query: 'q1' } } })
|
|
510
|
+
}).updateMdmValues;
|
|
511
|
+
act(function () {
|
|
512
|
+
onmessageFromWorker({
|
|
513
|
+
action: CustomAction.REQUEST,
|
|
514
|
+
params: { name: RequestAction.GET_SEARCH_QUERY, id: 'id1' }
|
|
515
|
+
});
|
|
516
|
+
});
|
|
517
|
+
expect(postMessage).toHaveBeenLastCalledWith({
|
|
518
|
+
action: 'response',
|
|
519
|
+
result: 'q1',
|
|
520
|
+
name: RequestAction.GET_SEARCH_QUERY,
|
|
521
|
+
id: 'id1'
|
|
522
|
+
});
|
|
523
|
+
act(function () {
|
|
524
|
+
updateMdmValues(function (prev) { return (__assign(__assign({}, prev), { searchProviderData: { type: 'search', data: { query: 'q2' } } })); });
|
|
525
|
+
});
|
|
526
|
+
act(function () {
|
|
527
|
+
onmessageFromWorker({
|
|
528
|
+
action: CustomAction.REQUEST,
|
|
529
|
+
params: { name: RequestAction.GET_SEARCH_QUERY, id: 'id2' }
|
|
530
|
+
});
|
|
531
|
+
});
|
|
532
|
+
expect(postMessage).toHaveBeenLastCalledWith({
|
|
533
|
+
action: 'response',
|
|
534
|
+
result: 'q2',
|
|
535
|
+
name: RequestAction.GET_SEARCH_QUERY,
|
|
536
|
+
id: 'id2'
|
|
537
|
+
});
|
|
538
|
+
});
|
|
463
539
|
});
|