@reltio/components 1.4.1219 → 1.4.1228
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/contexts/InterceptHandlersContext/index.d.ts +3 -0
- package/cjs/contexts/InterceptHandlersContext/index.js +9 -0
- package/cjs/contexts/SandboxAPIContext/index.d.ts +6 -2
- package/cjs/contexts/index.d.ts +1 -0
- package/cjs/contexts/index.js +3 -1
- package/cjs/hooks/useAPI/API.js +5 -4
- package/cjs/hooks/useAPI/helpers.d.ts +49 -0
- package/cjs/hooks/useAPI/helpers.js +203 -1
- package/cjs/hooks/useAPI/useAPI.js +124 -86
- package/cjs/hooks/useCustomScripts.d.ts +2 -9
- package/cjs/hooks/useCustomScripts.js +9 -6
- package/esm/contexts/InterceptHandlersContext/index.d.ts +3 -0
- package/esm/contexts/InterceptHandlersContext/index.js +3 -0
- package/esm/contexts/SandboxAPIContext/index.d.ts +6 -2
- package/esm/contexts/index.d.ts +1 -0
- package/esm/contexts/index.js +1 -0
- package/esm/hooks/useAPI/API.js +5 -4
- package/esm/hooks/useAPI/helpers.d.ts +49 -0
- package/esm/hooks/useAPI/helpers.js +193 -0
- package/esm/hooks/useAPI/useAPI.js +126 -88
- package/esm/hooks/useCustomScripts.d.ts +2 -9
- package/esm/hooks/useCustomScripts.js +10 -7
- package/package.json +3 -3
|
@@ -69,8 +69,7 @@ var getCustomViewConfig = function (config) {
|
|
|
69
69
|
var processApiResponse = config.processApiResponse, processApiRequest = config.processApiRequest, permissions = config.permissions, files = config.files, otherProps = __rest(config, ["processApiResponse", "processApiRequest", "permissions", "files"]);
|
|
70
70
|
return __assign({ action: { processApiResponse: processApiResponse, processApiRequest: processApiRequest, permissions: permissions, files: files } }, otherProps);
|
|
71
71
|
};
|
|
72
|
-
var useCustomScripts = function (config
|
|
73
|
-
var addInternalRequestInterceptor = _a.addInternalRequestInterceptor, addInternalResponseInterceptor = _a.addInternalResponseInterceptor, removeInternalRequestInterceptor = _a.removeInternalRequestInterceptor, removeInternalResponseInterceptor = _a.removeInternalResponseInterceptor;
|
|
72
|
+
var useCustomScripts = function (config) {
|
|
74
73
|
var customScripts = config.reduce(function (acc, customScript) {
|
|
75
74
|
if (customScript.platform !== mdm_sdk_1.CustomScriptPlatform.CLASSIC) {
|
|
76
75
|
return __spreadArray(__spreadArray([], acc), [__assign(__assign({}, customScript), { actionId: nanoid_1.default() })]);
|
|
@@ -78,6 +77,8 @@ var useCustomScripts = function (config, _a) {
|
|
|
78
77
|
return acc;
|
|
79
78
|
}, []);
|
|
80
79
|
var showSnackbarMessage = react_1.useContext(contexts_1.SnackbarContext);
|
|
80
|
+
var _a = react_1.useContext(contexts_1.InterceptHandlersContext), addInternalRequestInterceptor = _a.addInternalRequestInterceptor, addInternalResponseInterceptor = _a.addInternalResponseInterceptor, removeInternalRequestInterceptor = _a.removeInternalRequestInterceptor, removeInternalResponseInterceptor = _a.removeInternalResponseInterceptor;
|
|
81
|
+
var qxApi = react_1.useContext(contexts_1.SandboxAPIContext);
|
|
81
82
|
var dispatch = react_redux_1.useDispatch();
|
|
82
83
|
var metadata = react_redux_1.useSelector(mdm_module_1.default.selectors.getMetadata) || {};
|
|
83
84
|
var entity = react_redux_1.useSelector(mdm_module_1.default.selectors.getEntity) || {};
|
|
@@ -91,7 +92,6 @@ var useCustomScripts = function (config, _a) {
|
|
|
91
92
|
var user = react_redux_1.useSelector(mdm_module_1.default.selectors.getUser);
|
|
92
93
|
var entityUri = react_redux_1.useSelector(mdm_module_1.default.selectors.getEntityUri);
|
|
93
94
|
var environment = react_redux_1.useSelector(mdm_module_1.default.selectors.getWorkflowEnvironmentUrl);
|
|
94
|
-
var qxApi = react_1.useContext(contexts_1.SandboxAPIContext);
|
|
95
95
|
var workflowCheckPermission = workflow_1.useWorkflowCheckPermission();
|
|
96
96
|
var _b = react_redux_1.useSelector(mdm_module_1.default.selectors.getSearchProviderData) || {}, typeSearch = _b.type, search = _b.data;
|
|
97
97
|
var openSearch = function (search) { return dispatch(mdm_module_1.ui.actions.openSearch(search)); };
|
|
@@ -130,10 +130,13 @@ var useCustomScripts = function (config, _a) {
|
|
|
130
130
|
var _d = task.params, headers = _d.headers, id = _d.id, fakeURL = _d.url, method = _d.method, data = _d.data;
|
|
131
131
|
var url = fakeURL.replace(reltioPath, apiPath);
|
|
132
132
|
if (requestListeners.current[headers.requestId]) {
|
|
133
|
-
requestListeners.current[headers.requestId].next(url,
|
|
133
|
+
requestListeners.current[headers.requestId].next(url, {
|
|
134
|
+
body: data,
|
|
135
|
+
id: id,
|
|
134
136
|
task: task,
|
|
135
137
|
headers: headers,
|
|
136
|
-
method: method
|
|
138
|
+
method: method
|
|
139
|
+
});
|
|
137
140
|
requestListeners.current = ramda_1.omit([headers.requestId], requestListeners.current);
|
|
138
141
|
}
|
|
139
142
|
}
|
|
@@ -155,7 +158,7 @@ var useCustomScripts = function (config, _a) {
|
|
|
155
158
|
workers.current = customScripts.reduce(function (acc, customScript) {
|
|
156
159
|
var _a;
|
|
157
160
|
var customViewConfig = getCustomViewConfig(customScript);
|
|
158
|
-
return __assign(__assign({}, acc), (_a = {}, _a[customScript.actionId] = mdm_sdk_1.initializeWebWorker(workerUrl,
|
|
161
|
+
return __assign(__assign({}, acc), (_a = {}, _a[customScript.actionId] = mdm_sdk_1.initializeWebWorker(workerUrl, process, customViewConfig), _a));
|
|
159
162
|
}, workers.current);
|
|
160
163
|
return function () {
|
|
161
164
|
Object.keys(workers.current).forEach(function (actionId) {
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
|
|
2
|
+
import { InterceptHandlers } from '@reltio/mdm-sdk';
|
|
3
|
+
declare type SandboxAPI = {
|
|
4
|
+
interceptors?: InterceptHandlers;
|
|
3
5
|
getCurrentPerspectiveId: () => string;
|
|
4
6
|
showPerspective: (perspective: any) => void;
|
|
5
7
|
setEntityUri: (entityUri: string, listener: () => void) => void;
|
|
6
|
-
}
|
|
8
|
+
};
|
|
9
|
+
export declare const SandboxAPIContext: React.Context<SandboxAPI>;
|
|
10
|
+
export {};
|
package/esm/contexts/index.d.ts
CHANGED
|
@@ -20,3 +20,4 @@ export { useReloadAllFacets, ReloadFacetProvider, useReloadFacet } from './Reloa
|
|
|
20
20
|
export { SearchFiltersContext } from './SearchFiltersContext';
|
|
21
21
|
export { SnackbarContext } from './SnackbarContext';
|
|
22
22
|
export { HighlightedValuesContext } from './HighlightedValuesContext';
|
|
23
|
+
export { InterceptHandlersContext } from './InterceptHandlersContext';
|
package/esm/contexts/index.js
CHANGED
|
@@ -20,3 +20,4 @@ export { useReloadAllFacets, ReloadFacetProvider, useReloadFacet } from './Reloa
|
|
|
20
20
|
export { SearchFiltersContext } from './SearchFiltersContext';
|
|
21
21
|
export { SnackbarContext } from './SnackbarContext';
|
|
22
22
|
export { HighlightedValuesContext } from './HighlightedValuesContext';
|
|
23
|
+
export { InterceptHandlersContext } from './InterceptHandlersContext';
|
package/esm/hooks/useAPI/API.js
CHANGED
|
@@ -126,7 +126,8 @@ var sendApiRequest = function (params, permissions, signHandler) { return __awai
|
|
|
126
126
|
url: params.url,
|
|
127
127
|
method: params.method,
|
|
128
128
|
data: params.data,
|
|
129
|
-
headers: headers
|
|
129
|
+
headers: headers,
|
|
130
|
+
noRequestProcessor: true
|
|
130
131
|
})];
|
|
131
132
|
case 2: return [2 /*return*/, _a.sent()];
|
|
132
133
|
}
|
|
@@ -159,10 +160,10 @@ export var processRequest = function (_a) {
|
|
|
159
160
|
var handleRequest = function (request) {
|
|
160
161
|
request
|
|
161
162
|
.then(function (data) {
|
|
162
|
-
worker.postMessage(__assign({ action: 'response', result: { data: data } }, paramObject.params));
|
|
163
|
+
worker.postMessage(__assign({ action: 'response', result: { data: data, headers: paramObject.params.headers, status: 200 } }, paramObject.params));
|
|
163
164
|
})
|
|
164
165
|
.catch(function (error) {
|
|
165
|
-
worker.postMessage(__assign({ action: 'response', result: { data: error, headers:
|
|
166
|
+
worker.postMessage(__assign({ action: 'response', result: { data: error, headers: paramObject.params.headers, status: 0 } }, paramObject.params));
|
|
166
167
|
});
|
|
167
168
|
};
|
|
168
169
|
var shouldSignRequest = isNewUI(servicesPath);
|
|
@@ -222,7 +223,7 @@ export var processRequest = function (_a) {
|
|
|
222
223
|
break;
|
|
223
224
|
}
|
|
224
225
|
case RequestAction.OPEN_SEARCH: {
|
|
225
|
-
openSearch({ viewId: config.id, searchState: paramObject.params.searchState });
|
|
226
|
+
openSearch({ viewId: config.id, searchState: paramObject.params.searchState || {} });
|
|
226
227
|
break;
|
|
227
228
|
}
|
|
228
229
|
case RequestAction.GET_ENTITY_URI: {
|
|
@@ -1,2 +1,51 @@
|
|
|
1
1
|
export declare const isNewUI: (path?: string) => boolean;
|
|
2
2
|
export declare const getWorkerURL: (uiPath: string, tenant: string) => string;
|
|
3
|
+
export declare const getFilesWithArrayBuffer: (files: FileList) => Promise<unknown[]>;
|
|
4
|
+
declare type ResetHTMLParams = {
|
|
5
|
+
worker: Worker;
|
|
6
|
+
setTooltip: any;
|
|
7
|
+
html?: string;
|
|
8
|
+
innerText?: string;
|
|
9
|
+
setListenersToReset: any;
|
|
10
|
+
setHtml: any;
|
|
11
|
+
};
|
|
12
|
+
export declare const resetHtml: ({ worker, setTooltip, innerText, html, setListenersToReset, setHtml }: ResetHTMLParams) => void;
|
|
13
|
+
export declare const setUpQooxdooRequestInterceptor: ({ workerRef, setRequestListeners }: {
|
|
14
|
+
workerRef: any;
|
|
15
|
+
setRequestListeners: any;
|
|
16
|
+
}) => {
|
|
17
|
+
processApiRequest: (url: any, method: any, headers: any, data: any, next: any) => void;
|
|
18
|
+
};
|
|
19
|
+
export declare const setUpQooxdooResponseInterceptor: ({ workerRef, setResponseListeners }: {
|
|
20
|
+
workerRef: any;
|
|
21
|
+
setResponseListeners: any;
|
|
22
|
+
}) => {
|
|
23
|
+
processApiResponse: (url: any, method: any, data: any, next: any) => void;
|
|
24
|
+
};
|
|
25
|
+
export declare const setUpRequestInterceptor: ({ apiPath, reltioPath, tenant, processApiRequest, workerRef, setRequestListeners }: {
|
|
26
|
+
apiPath: any;
|
|
27
|
+
reltioPath: any;
|
|
28
|
+
tenant: any;
|
|
29
|
+
processApiRequest: any;
|
|
30
|
+
workerRef: any;
|
|
31
|
+
setRequestListeners: any;
|
|
32
|
+
}) => ({ options, url, next }: {
|
|
33
|
+
next: (url: string, options: RequestInit) => void;
|
|
34
|
+
abort?: (error: Error) => void;
|
|
35
|
+
url: string;
|
|
36
|
+
options: RequestInit;
|
|
37
|
+
}) => void;
|
|
38
|
+
export declare const setUpResponseInterceptor: ({ reltioPath, apiPath, processApiResponse, workerRef, setResponseListeners }: {
|
|
39
|
+
reltioPath: any;
|
|
40
|
+
apiPath: any;
|
|
41
|
+
processApiResponse: any;
|
|
42
|
+
workerRef: any;
|
|
43
|
+
setResponseListeners: any;
|
|
44
|
+
}) => ({ url, response, next, options, abort }: {
|
|
45
|
+
url: any;
|
|
46
|
+
response: any;
|
|
47
|
+
next: any;
|
|
48
|
+
options: any;
|
|
49
|
+
abort: any;
|
|
50
|
+
}) => void;
|
|
51
|
+
export {};
|
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import nanoid from 'nanoid';
|
|
1
13
|
export var isNewUI = function (path) {
|
|
2
14
|
return path === null || path === void 0 ? void 0 : path.includes('/nui');
|
|
3
15
|
};
|
|
@@ -9,3 +21,184 @@ export var getWorkerURL = function (uiPath, tenant) {
|
|
|
9
21
|
return uiPath + "worker_api.js";
|
|
10
22
|
}
|
|
11
23
|
};
|
|
24
|
+
export var getFilesWithArrayBuffer = function (files) {
|
|
25
|
+
var readFilePromises = Array.from(files).map(function (file) {
|
|
26
|
+
return new Promise(function (resolve, reject) {
|
|
27
|
+
var reader = new FileReader();
|
|
28
|
+
reader.onload = function (event) {
|
|
29
|
+
var content = event.target.result;
|
|
30
|
+
var lastModified = file.lastModified, name = file.name, size = file.size, type = file.type;
|
|
31
|
+
resolve({ lastModified: lastModified, name: name, size: size, type: type, content: content });
|
|
32
|
+
};
|
|
33
|
+
reader.onerror = function (error) {
|
|
34
|
+
reject(error);
|
|
35
|
+
};
|
|
36
|
+
reader.readAsArrayBuffer(file);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
return Promise.all(readFilePromises);
|
|
40
|
+
};
|
|
41
|
+
var processInnerHtml = function (parent, worker, setTooltip) {
|
|
42
|
+
var handlersToReset = [];
|
|
43
|
+
var uiActions = parent.getAttribute('ui-actions');
|
|
44
|
+
var uiTooltip = parent.getAttribute('ui-tooltip');
|
|
45
|
+
var id = parent.getAttribute('id') || parent.getAttribute('name');
|
|
46
|
+
if (uiActions) {
|
|
47
|
+
uiActions.split(',').forEach(function (uiAction) {
|
|
48
|
+
var handler = function (event) {
|
|
49
|
+
var _a;
|
|
50
|
+
var target = event.target;
|
|
51
|
+
var postEventMessage = function (files) {
|
|
52
|
+
worker.postMessage({
|
|
53
|
+
action: 'event',
|
|
54
|
+
type: 'uiAction',
|
|
55
|
+
data: { type: uiAction, id: id, event: __assign(__assign({}, event), { files: files }) }
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
if ((_a = target.files) === null || _a === void 0 ? void 0 : _a.length) {
|
|
59
|
+
getFilesWithArrayBuffer(target.files).then(postEventMessage);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
postEventMessage();
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
parent.addEventListener(uiAction, handler);
|
|
66
|
+
handlersToReset.push(function () {
|
|
67
|
+
parent.removeEventListener(uiAction, handler);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
parent.removeAttribute('ui-actions');
|
|
71
|
+
}
|
|
72
|
+
if (uiTooltip) {
|
|
73
|
+
setTooltip(uiTooltip);
|
|
74
|
+
}
|
|
75
|
+
parent.childNodes.forEach(function (child) {
|
|
76
|
+
if (child.nodeType === 1) {
|
|
77
|
+
//Node.ELEMENT_NODE
|
|
78
|
+
handlersToReset = handlersToReset.concat(processInnerHtml(child, worker, setTooltip));
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
return handlersToReset;
|
|
82
|
+
};
|
|
83
|
+
export var resetHtml = function (_a) {
|
|
84
|
+
var worker = _a.worker, setTooltip = _a.setTooltip, innerText = _a.innerText, html = _a.html, setListenersToReset = _a.setListenersToReset, setHtml = _a.setHtml;
|
|
85
|
+
var docBlock = document.createElement('div');
|
|
86
|
+
docBlock.innerHTML = html || innerText;
|
|
87
|
+
var handlersToReset = processInnerHtml(docBlock, worker, setTooltip);
|
|
88
|
+
setListenersToReset(handlersToReset);
|
|
89
|
+
setHtml(docBlock);
|
|
90
|
+
};
|
|
91
|
+
var isURLtoProcess = function (processApi, url) {
|
|
92
|
+
return (processApi || []).some(function (request) {
|
|
93
|
+
var regExp = new RegExp("^" + request + "$");
|
|
94
|
+
return request.replace(/\/*$/, '') === url || (request && regExp.test(url));
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
export var setUpQooxdooRequestInterceptor = function (_a) {
|
|
98
|
+
var workerRef = _a.workerRef, setRequestListeners = _a.setRequestListeners;
|
|
99
|
+
return ({
|
|
100
|
+
processApiRequest: function (url, method, headers, data, next) {
|
|
101
|
+
var requestId = nanoid();
|
|
102
|
+
var options = { url: url, method: method, headers: headers, noRequestProcessor: true };
|
|
103
|
+
setRequestListeners(options, next, requestId);
|
|
104
|
+
workerRef.current.postMessage({
|
|
105
|
+
action: 'apiRequest',
|
|
106
|
+
id: requestId,
|
|
107
|
+
url: url,
|
|
108
|
+
method: method,
|
|
109
|
+
headers: headers,
|
|
110
|
+
data: data
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
export var setUpQooxdooResponseInterceptor = function (_a) {
|
|
116
|
+
var workerRef = _a.workerRef, setResponseListeners = _a.setResponseListeners;
|
|
117
|
+
return ({
|
|
118
|
+
processApiResponse: function (url, method, data, next) {
|
|
119
|
+
var responseId = nanoid();
|
|
120
|
+
setResponseListeners(next, responseId);
|
|
121
|
+
workerRef.current.postMessage({
|
|
122
|
+
action: 'apiResponse',
|
|
123
|
+
id: responseId,
|
|
124
|
+
url: url,
|
|
125
|
+
method: method,
|
|
126
|
+
data: data
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
export var setUpRequestInterceptor = function (_a) {
|
|
132
|
+
var apiPath = _a.apiPath, reltioPath = _a.reltioPath, tenant = _a.tenant, processApiRequest = _a.processApiRequest, workerRef = _a.workerRef, setRequestListeners = _a.setRequestListeners;
|
|
133
|
+
return function (_a) {
|
|
134
|
+
var _b = _a.options, options = _b === void 0 ? {} : _b, url = _a.url, next = _a.next;
|
|
135
|
+
var fakeURL = url.startsWith('/') && !url.startsWith(apiPath)
|
|
136
|
+
? reltioPath + "/api/" + tenant + url
|
|
137
|
+
: "" + reltioPath + url.replace(apiPath, '');
|
|
138
|
+
var isProcessableUrl = isURLtoProcess(processApiRequest, fakeURL);
|
|
139
|
+
if (isProcessableUrl) {
|
|
140
|
+
var requestId = nanoid();
|
|
141
|
+
setRequestListeners(options, next, requestId);
|
|
142
|
+
workerRef.current.postMessage({
|
|
143
|
+
action: 'apiRequest',
|
|
144
|
+
id: requestId,
|
|
145
|
+
url: fakeURL,
|
|
146
|
+
method: options.method,
|
|
147
|
+
headers: __assign(__assign({}, options.headers), { origin: 'ui', requestId: requestId }),
|
|
148
|
+
data: options.body
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
next(url, options);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
export var setUpResponseInterceptor = function (_a) {
|
|
157
|
+
var reltioPath = _a.reltioPath, apiPath = _a.apiPath, processApiResponse = _a.processApiResponse, workerRef = _a.workerRef, setResponseListeners = _a.setResponseListeners;
|
|
158
|
+
return function (_a) {
|
|
159
|
+
var _b;
|
|
160
|
+
var url = _a.url, response = _a.response, next = _a.next, options = _a.options, abort = _a.abort;
|
|
161
|
+
if (((_b = options === null || options === void 0 ? void 0 : options.headers) === null || _b === void 0 ? void 0 : _b.origin) === 'ui') {
|
|
162
|
+
response
|
|
163
|
+
.json()
|
|
164
|
+
.then(function (data) {
|
|
165
|
+
var _a, _b;
|
|
166
|
+
setResponseListeners(next, options.headers.requestId);
|
|
167
|
+
workerRef.current.postMessage({
|
|
168
|
+
action: 'response',
|
|
169
|
+
result: { data: data, status: response.status },
|
|
170
|
+
id: options === null || options === void 0 ? void 0 : options.id,
|
|
171
|
+
name: (_b = (_a = options === null || options === void 0 ? void 0 : options.task) === null || _a === void 0 ? void 0 : _a.params) === null || _b === void 0 ? void 0 : _b.name
|
|
172
|
+
});
|
|
173
|
+
})
|
|
174
|
+
.catch(function (error) {
|
|
175
|
+
abort(error);
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
var fakeURL_1 = "" + reltioPath + url.replace(apiPath, '');
|
|
180
|
+
var isProcessableUrl = isURLtoProcess(processApiResponse, fakeURL_1);
|
|
181
|
+
if (isProcessableUrl) {
|
|
182
|
+
var responseId_1 = nanoid();
|
|
183
|
+
response
|
|
184
|
+
.json()
|
|
185
|
+
.then(function (data) {
|
|
186
|
+
setResponseListeners(next, responseId_1);
|
|
187
|
+
workerRef.current.postMessage({
|
|
188
|
+
action: 'apiResponse',
|
|
189
|
+
id: responseId_1,
|
|
190
|
+
url: fakeURL_1,
|
|
191
|
+
method: options.method,
|
|
192
|
+
data: data
|
|
193
|
+
});
|
|
194
|
+
})
|
|
195
|
+
.catch(function (error) {
|
|
196
|
+
abort(error);
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
next(response);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
};
|
|
@@ -13,80 +13,48 @@ import { useCallback, useContext, useEffect, useRef, useState } from 'react';
|
|
|
13
13
|
import { useDispatch, useSelector } from 'react-redux';
|
|
14
14
|
import mdmModule, { ui } from '@reltio/mdm-module';
|
|
15
15
|
import { CustomAction, CustomScriptPlatform, initializeWebWorker, isEmptyValue } from '@reltio/mdm-sdk';
|
|
16
|
+
import { omit } from 'ramda';
|
|
16
17
|
import { useWorkflowCheckPermission } from '../../components/workflow';
|
|
17
|
-
import { SandboxAPIContext, SnackbarContext } from '../../contexts';
|
|
18
|
+
import { InterceptHandlersContext, SandboxAPIContext, SnackbarContext } from '../../contexts';
|
|
18
19
|
import { processRequest } from './API';
|
|
19
|
-
import { getWorkerURL } from './helpers';
|
|
20
|
+
import { getWorkerURL, resetHtml, isNewUI, setUpResponseInterceptor, setUpRequestInterceptor, setUpQooxdooRequestInterceptor, setUpQooxdooResponseInterceptor } from './helpers';
|
|
20
21
|
export var useAPI = function (config) {
|
|
22
|
+
var _a, _b;
|
|
21
23
|
if (config === void 0) { config = {}; }
|
|
22
|
-
var
|
|
23
|
-
var
|
|
24
|
-
var
|
|
25
|
-
var
|
|
26
|
-
var
|
|
27
|
-
var
|
|
24
|
+
var _c = useState(), html = _c[0], setHtml = _c[1];
|
|
25
|
+
var _d = useState([]), listenersToReset = _d[0], setListenersToReset = _d[1];
|
|
26
|
+
var _e = useState(true), visible = _e[0], setVisible = _e[1];
|
|
27
|
+
var _f = useState(null), tooltip = _f[0], setTooltip = _f[1];
|
|
28
|
+
var _g = useState({}), customStyles = _g[0], setCustomStyles = _g[1];
|
|
29
|
+
var workerRef = useRef();
|
|
30
|
+
var requestListeners = useRef({});
|
|
31
|
+
var responseListeners = useRef({});
|
|
28
32
|
var dispatch = useDispatch();
|
|
29
|
-
var metadata = useSelector(mdmModule.selectors.getMetadata) || {};
|
|
30
|
-
var entity = useSelector(mdmModule.selectors.getEntity) || {};
|
|
31
33
|
var uiPath = useSelector(mdmModule.selectors.getUIPath);
|
|
32
34
|
var tenant = useSelector(mdmModule.selectors.getTenant);
|
|
33
35
|
var workerUrl = getWorkerURL(uiPath, tenant);
|
|
36
|
+
var showSnackbarMessage = useContext(SnackbarContext);
|
|
37
|
+
var qxApi = useContext(SandboxAPIContext);
|
|
38
|
+
var interceptHandlers = useContext(InterceptHandlersContext);
|
|
39
|
+
var workflowCheckPermission = useWorkflowCheckPermission();
|
|
40
|
+
var metadata = useSelector(mdmModule.selectors.getMetadata) || {};
|
|
41
|
+
var entity = useSelector(mdmModule.selectors.getEntity) || {};
|
|
42
|
+
var apiPath = useSelector(mdmModule.selectors.getApiPath);
|
|
43
|
+
var servicesPath = useSelector(mdmModule.selectors.getServicesPath);
|
|
34
44
|
var reltioPath = useSelector(mdmModule.selectors.getReltioPath);
|
|
35
45
|
var workflowPath = useSelector(mdmModule.selectors.getWorkflowPath);
|
|
36
46
|
var user = useSelector(mdmModule.selectors.getUser);
|
|
37
|
-
var servicesPath = useSelector(mdmModule.selectors.getServicesPath);
|
|
38
47
|
var entityUri = useSelector(mdmModule.selectors.getEntityUri);
|
|
39
48
|
var environment = useSelector(mdmModule.selectors.getWorkflowEnvironmentUrl);
|
|
40
|
-
var
|
|
41
|
-
var
|
|
42
|
-
var
|
|
49
|
+
var _h = useSelector(mdmModule.selectors.getSearchProviderData) || {}, typeSearch = _h.type, search = _h.data;
|
|
50
|
+
var isOldUI = !isNewUI(servicesPath);
|
|
51
|
+
var supportedInterceptHandlers = isOldUI ? qxApi.interceptors : interceptHandlers;
|
|
43
52
|
var openSearch = function (search) { return dispatch(ui.actions.openSearch(search)); };
|
|
44
|
-
var
|
|
53
|
+
var innerText = '';
|
|
45
54
|
var process = function (_a) {
|
|
46
|
-
var
|
|
55
|
+
var _b, _c;
|
|
56
|
+
var task = _a.task, worker = _a.worker;
|
|
47
57
|
if (task) {
|
|
48
|
-
var handlersToReset_1 = [];
|
|
49
|
-
var processInnerHtml_1 = function (parent) {
|
|
50
|
-
var uiActions = parent.getAttribute('ui-actions');
|
|
51
|
-
var uiTooltip = parent.getAttribute('ui-tooltip');
|
|
52
|
-
var id = parent.getAttribute('id') || parent.getAttribute('name');
|
|
53
|
-
if (uiActions) {
|
|
54
|
-
uiActions.split(',').forEach(function (uiAction) {
|
|
55
|
-
var handler = function () {
|
|
56
|
-
var data = {
|
|
57
|
-
action: 'event',
|
|
58
|
-
type: 'uiAction',
|
|
59
|
-
data: {
|
|
60
|
-
type: uiAction,
|
|
61
|
-
id: id
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
worker.postMessage(data);
|
|
65
|
-
};
|
|
66
|
-
parent.addEventListener(uiAction, handler);
|
|
67
|
-
handlersToReset_1.push(function () {
|
|
68
|
-
parent.removeEventListener(uiAction, handler);
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
parent.removeAttribute('ui-actions');
|
|
72
|
-
}
|
|
73
|
-
if (uiTooltip) {
|
|
74
|
-
setTooltip(uiTooltip);
|
|
75
|
-
}
|
|
76
|
-
parent.childNodes.forEach(function (child) {
|
|
77
|
-
if (child.nodeType === 1) {
|
|
78
|
-
//Node.ELEMENT_NODE
|
|
79
|
-
processInnerHtml_1(child);
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
};
|
|
83
|
-
var resetHtml = function (html) {
|
|
84
|
-
var docBlock = document.createElement('div');
|
|
85
|
-
docBlock.innerHTML = html || innerText;
|
|
86
|
-
processInnerHtml_1(docBlock);
|
|
87
|
-
setListenersToReset(handlersToReset_1);
|
|
88
|
-
setHtml(docBlock);
|
|
89
|
-
};
|
|
90
58
|
switch (task.action) {
|
|
91
59
|
case CustomAction.SET_HTML: {
|
|
92
60
|
if (task.params.id) {
|
|
@@ -94,18 +62,22 @@ export var useAPI = function (config) {
|
|
|
94
62
|
elem.innerHTML = task.params.html;
|
|
95
63
|
}
|
|
96
64
|
else if (innerText !== task.params.html) {
|
|
97
|
-
|
|
65
|
+
innerText = task.params.html;
|
|
66
|
+
resetHtml({
|
|
67
|
+
worker: worker,
|
|
68
|
+
setTooltip: setTooltip,
|
|
69
|
+
html: task.params.html,
|
|
70
|
+
innerText: innerText,
|
|
71
|
+
setListenersToReset: setListenersToReset,
|
|
72
|
+
setHtml: setHtml
|
|
73
|
+
});
|
|
98
74
|
}
|
|
99
75
|
break;
|
|
100
76
|
}
|
|
101
|
-
case CustomAction.LOG: {
|
|
102
|
-
console.log(task.params); //eslint-disable-line no-console
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
77
|
case CustomAction.SET_VISIBILITY: {
|
|
106
78
|
if (task.params === 'visible') {
|
|
107
79
|
setVisible(true);
|
|
108
|
-
resetHtml();
|
|
80
|
+
resetHtml({ worker: worker, setTooltip: setTooltip, innerText: innerText, setListenersToReset: setListenersToReset, setHtml: setHtml });
|
|
109
81
|
}
|
|
110
82
|
else {
|
|
111
83
|
setVisible(false);
|
|
@@ -114,56 +86,99 @@ export var useAPI = function (config) {
|
|
|
114
86
|
}
|
|
115
87
|
case CustomAction.SET_TOOLTIP: {
|
|
116
88
|
setTooltip(task.params);
|
|
117
|
-
resetHtml();
|
|
118
89
|
break;
|
|
119
90
|
}
|
|
120
91
|
case CustomAction.SET_HEIGHT: {
|
|
121
|
-
setCustomStyles(function (prev) { return (__assign(__assign({},
|
|
92
|
+
setCustomStyles(function (prev) { return (__assign(__assign({}, prev), { height: task.params })); });
|
|
122
93
|
break;
|
|
123
94
|
}
|
|
124
95
|
case CustomAction.SET_WIDTH: {
|
|
125
|
-
setCustomStyles(function (prev) { return (__assign(__assign({},
|
|
96
|
+
setCustomStyles(function (prev) { return (__assign(__assign({}, prev), { width: task.params })); });
|
|
126
97
|
break;
|
|
127
98
|
}
|
|
128
99
|
case CustomAction.SET_ENABLED: {
|
|
129
100
|
setCustomStyles(function (prev) {
|
|
130
|
-
|
|
131
|
-
if (!task.params) {
|
|
132
|
-
newStyles['pointerEvents'] = 'none';
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
delete newStyles['pointerEvents'];
|
|
136
|
-
}
|
|
137
|
-
return newStyles;
|
|
101
|
+
return task.params ? omit(['pointer-events'], prev) : __assign(__assign({}, prev), { 'pointer-events': 'none' });
|
|
138
102
|
});
|
|
139
103
|
break;
|
|
140
104
|
}
|
|
105
|
+
case CustomAction.LOG: {
|
|
106
|
+
console.log(task.params); //eslint-disable-line no-console
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
141
109
|
case CustomAction.MESSAGE: {
|
|
142
110
|
showSnackbarMessage(task.params);
|
|
143
111
|
break;
|
|
144
112
|
}
|
|
145
113
|
case CustomAction.REQUEST: {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
114
|
+
if (((_c = (_b = task.params) === null || _b === void 0 ? void 0 : _b.headers) === null || _c === void 0 ? void 0 : _c.origin) !== 'ui') {
|
|
115
|
+
processRequest(__assign({ name: task.params.name, paramObject: task, permissions: config.action.permissions, worker: worker,
|
|
116
|
+
metadata: metadata, config: config, user: user,
|
|
117
|
+
servicesPath: servicesPath, apiPath: isOldUI ? apiPath : reltioPath, tenant: tenant,
|
|
118
|
+
workflowPath: workflowPath,
|
|
119
|
+
entity: entity,
|
|
120
|
+
entityUri: entityUri,
|
|
121
|
+
environment: environment, query: typeSearch === 'search' ? search === null || search === void 0 ? void 0 : search.query : null, openSearch: openSearch,
|
|
122
|
+
workflowCheckPermission: workflowCheckPermission }, qxApi));
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
var _d = task.params, headers = _d.headers, id = _d.id, fakeURL = _d.url, method = _d.method, data = _d.data;
|
|
126
|
+
var url = fakeURL.replace(reltioPath, apiPath);
|
|
127
|
+
if (requestListeners.current[headers.requestId]) {
|
|
128
|
+
requestListeners.current[headers.requestId].next(url, {
|
|
129
|
+
body: data,
|
|
130
|
+
id: id,
|
|
131
|
+
task: task,
|
|
132
|
+
headers: headers,
|
|
133
|
+
method: method
|
|
134
|
+
});
|
|
135
|
+
requestListeners.current = omit([headers.requestId], requestListeners.current);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
case CustomAction.RETURN_PROCESSED_API_RESPONSE:
|
|
141
|
+
case CustomAction.RETURN_PROCESSED_API_REQUEST: {
|
|
142
|
+
var _e = task.params, id = _e.id, data = _e.data;
|
|
143
|
+
if (responseListeners.current[id]) {
|
|
144
|
+
responseListeners.current[id].next(data);
|
|
145
|
+
responseListeners.current = omit([id], responseListeners.current);
|
|
146
|
+
}
|
|
154
147
|
break;
|
|
155
148
|
}
|
|
156
149
|
}
|
|
157
150
|
}
|
|
158
151
|
};
|
|
152
|
+
var setRequestListeners = function (options, next, requestId) {
|
|
153
|
+
var _a;
|
|
154
|
+
requestListeners.current = __assign(__assign({}, requestListeners.current), (_a = {}, _a[requestId] = { options: options, next: next, id: requestId }, _a));
|
|
155
|
+
};
|
|
156
|
+
var setResponseListeners = function (next, responseId) {
|
|
157
|
+
var _a;
|
|
158
|
+
responseListeners.current = __assign(__assign({}, responseListeners.current), (_a = {}, _a[responseId] = { next: next }, _a));
|
|
159
|
+
};
|
|
160
|
+
var qooxdooRequestInterceptor = setUpQooxdooRequestInterceptor({ workerRef: workerRef, setRequestListeners: setRequestListeners });
|
|
161
|
+
var qooxdooResponseInterceptor = setUpQooxdooResponseInterceptor({ workerRef: workerRef, setResponseListeners: setResponseListeners });
|
|
162
|
+
var requestInterceptor = setUpRequestInterceptor({
|
|
163
|
+
apiPath: apiPath,
|
|
164
|
+
reltioPath: reltioPath,
|
|
165
|
+
tenant: tenant,
|
|
166
|
+
processApiRequest: (_a = config === null || config === void 0 ? void 0 : config.action) === null || _a === void 0 ? void 0 : _a.processApiRequest,
|
|
167
|
+
workerRef: workerRef,
|
|
168
|
+
setRequestListeners: setRequestListeners
|
|
169
|
+
});
|
|
170
|
+
var responseInterceptor = setUpResponseInterceptor({
|
|
171
|
+
reltioPath: reltioPath,
|
|
172
|
+
apiPath: apiPath,
|
|
173
|
+
processApiResponse: (_b = config === null || config === void 0 ? void 0 : config.action) === null || _b === void 0 ? void 0 : _b.processApiResponse,
|
|
174
|
+
workerRef: workerRef,
|
|
175
|
+
setResponseListeners: setResponseListeners
|
|
176
|
+
});
|
|
159
177
|
useEffect(function () {
|
|
160
178
|
if (!isEmptyValue(config.action) && config.action.platform !== CustomScriptPlatform.CLASSIC) {
|
|
161
|
-
workerRef.current = initializeWebWorker(workerUrl,
|
|
162
|
-
return function () {
|
|
163
|
-
workerRef.current.terminate();
|
|
164
|
-
};
|
|
179
|
+
workerRef.current = initializeWebWorker(workerUrl, process, config);
|
|
165
180
|
}
|
|
166
|
-
}, [
|
|
181
|
+
}, [entity]);
|
|
167
182
|
useEffect(function () { return function () {
|
|
168
183
|
listenersToReset.forEach(function (listener) { return listener(); });
|
|
169
184
|
}; }, [listenersToReset]);
|
|
@@ -175,5 +190,28 @@ export var useAPI = function (config) {
|
|
|
175
190
|
data: null
|
|
176
191
|
});
|
|
177
192
|
}, [config]);
|
|
193
|
+
useEffect(function () {
|
|
194
|
+
var _a, _b, _c, _d;
|
|
195
|
+
if (!isEmptyValue(supportedInterceptHandlers) &&
|
|
196
|
+
(((_a = config === null || config === void 0 ? void 0 : config.action) === null || _a === void 0 ? void 0 : _a.processApiRequest) || ((_b = config === null || config === void 0 ? void 0 : config.action) === null || _b === void 0 ? void 0 : _b.processApiResponse))) {
|
|
197
|
+
var addInternalRequestInterceptor = supportedInterceptHandlers.addInternalRequestInterceptor, addInternalResponseInterceptor = supportedInterceptHandlers.addInternalResponseInterceptor, removeInternalRequestInterceptor_1 = supportedInterceptHandlers.removeInternalRequestInterceptor, removeInternalResponseInterceptor_1 = supportedInterceptHandlers.removeInternalResponseInterceptor;
|
|
198
|
+
if (isOldUI) {
|
|
199
|
+
addInternalRequestInterceptor((_c = config === null || config === void 0 ? void 0 : config.action) === null || _c === void 0 ? void 0 : _c.processApiRequest, qooxdooRequestInterceptor);
|
|
200
|
+
addInternalResponseInterceptor((_d = config === null || config === void 0 ? void 0 : config.action) === null || _d === void 0 ? void 0 : _d.processApiResponse, qooxdooResponseInterceptor);
|
|
201
|
+
return function () {
|
|
202
|
+
removeInternalRequestInterceptor_1(qooxdooRequestInterceptor);
|
|
203
|
+
removeInternalResponseInterceptor_1(qooxdooResponseInterceptor);
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
addInternalRequestInterceptor(requestInterceptor);
|
|
208
|
+
addInternalResponseInterceptor(responseInterceptor);
|
|
209
|
+
return function () {
|
|
210
|
+
removeInternalRequestInterceptor_1(requestInterceptor);
|
|
211
|
+
removeInternalResponseInterceptor_1(responseInterceptor);
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}, [config]);
|
|
178
216
|
return { html: html, visible: visible, tooltip: tooltip, customStyles: customStyles, onClick: onClick };
|
|
179
217
|
};
|