@reltio/components 1.4.1578 → 1.4.1580
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/components/AttributeListItem/AttributeListItem.d.ts +3 -1
- package/cjs/components/AttributeListItem/AttributeListItem.js +3 -3
- package/cjs/hooks/useAPI/API.d.ts +1 -1
- package/cjs/hooks/useAPI/API.js +101 -121
- package/cjs/hooks/useAPI/helpers.d.ts +8 -27
- package/cjs/hooks/useAPI/helpers.js +49 -89
- package/cjs/hooks/useAPI/types.d.ts +3 -6
- package/cjs/hooks/useAPI/useAPI.js +29 -53
- package/cjs/hooks/useCustomScripts.js +26 -61
- package/esm/components/AttributeListItem/AttributeListItem.d.ts +3 -1
- package/esm/components/AttributeListItem/AttributeListItem.js +3 -3
- package/esm/hooks/useAPI/API.d.ts +1 -1
- package/esm/hooks/useAPI/API.js +101 -121
- package/esm/hooks/useAPI/helpers.d.ts +8 -27
- package/esm/hooks/useAPI/helpers.js +42 -84
- package/esm/hooks/useAPI/types.d.ts +3 -6
- package/esm/hooks/useAPI/useAPI.js +32 -56
- package/esm/hooks/useCustomScripts.js +29 -64
- package/package.json +3 -3
|
@@ -12,23 +12,23 @@ var __assign = (this && this.__assign) || function () {
|
|
|
12
12
|
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
|
-
import { CustomAction, CustomScriptPlatform, initializeWebWorker, isEmptyValue
|
|
16
|
-
import {
|
|
15
|
+
import { CustomAction, CustomScriptPlatform, initializeWebWorker, isEmptyValue } from '@reltio/mdm-sdk';
|
|
16
|
+
import { omit } from 'ramda';
|
|
17
17
|
import { useWorkflowCheckPermission } from '../../components/workflow';
|
|
18
18
|
import { useHtmlSanitizer } from '../useHtmlSanitizer';
|
|
19
19
|
import { InterceptHandlersContext, SandboxAPIContext, SnackbarContext } from '../../contexts';
|
|
20
20
|
import { processRequest } from './API';
|
|
21
|
-
import { getWorkerURL,
|
|
21
|
+
import { getWorkerURL, isValidCustomScript, resetHtml, getProcessedTask, setUpRequestInterceptor, setUpResponseInterceptor } from './helpers';
|
|
22
22
|
export var useAPI = function (config) {
|
|
23
|
-
var _a, _b, _c, _d;
|
|
24
23
|
if (config === void 0) { config = {}; }
|
|
25
|
-
var
|
|
26
|
-
var
|
|
27
|
-
var
|
|
28
|
-
var
|
|
29
|
-
var
|
|
30
|
-
var
|
|
31
|
-
var
|
|
24
|
+
var _a = config.action || {}, processApiRequest = _a.processApiRequest, processApiResponse = _a.processApiResponse, platform = _a.platform;
|
|
25
|
+
var _b = useState(), html = _b[0], setHtml = _b[1];
|
|
26
|
+
var _c = useState([]), listenersToReset = _c[0], setListenersToReset = _c[1];
|
|
27
|
+
var _d = useState([]), popupListenersToReset = _d[0], setPopupListenersToReset = _d[1];
|
|
28
|
+
var _e = useState(true), visible = _e[0], setVisible = _e[1];
|
|
29
|
+
var _f = useState(), popup = _f[0], setPopup = _f[1];
|
|
30
|
+
var _g = useState(null), tooltip = _g[0], setTooltip = _g[1];
|
|
31
|
+
var _h = useState({}), customStyles = _h[0], setCustomStyles = _h[1];
|
|
32
32
|
var workerRef = useRef();
|
|
33
33
|
var requestListeners = useRef({});
|
|
34
34
|
var responseListeners = useRef({});
|
|
@@ -51,10 +51,8 @@ export var useAPI = function (config) {
|
|
|
51
51
|
var entityUri = useSelector(mdmModule.selectors.getEntityUri);
|
|
52
52
|
var isEditableMode = useSelector(mdmModule.selectors.getIsEditableMode);
|
|
53
53
|
var environment = useSelector(mdmModule.selectors.getWorkflowEnvironmentUrl);
|
|
54
|
-
var
|
|
54
|
+
var _j = useSelector(mdmModule.selectors.getSearchProviderData) || {}, typeSearch = _j.type, search = _j.data;
|
|
55
55
|
var searchQuery = typeSearch === 'search' ? search === null || search === void 0 ? void 0 : search.query : null;
|
|
56
|
-
var isOldUI = !isNewUI(servicesPath);
|
|
57
|
-
var supportedInterceptHandlers = isOldUI ? qxApi.interceptors : interceptHandlers;
|
|
58
56
|
var openSearch = function (search) { return dispatch(ui.actions.openSearch(search)); };
|
|
59
57
|
var innerText = '';
|
|
60
58
|
var popupText = '';
|
|
@@ -143,15 +141,8 @@ export var useAPI = function (config) {
|
|
|
143
141
|
break;
|
|
144
142
|
}
|
|
145
143
|
case CustomAction.REQUEST: {
|
|
146
|
-
var
|
|
147
|
-
|
|
148
|
-
!startsWith(apiPath, pathOr('', ['params', 'url'], task));
|
|
149
|
-
var isApiAction = pathEq(['params', 'name'], RequestAction.API, task);
|
|
150
|
-
var processedParams = pipe(evolve({
|
|
151
|
-
url: ifElse(both(always(isGlobalUrl), always(isApiAction)), concat("".concat(processedApiPath, "/api/").concat(tenant)), replace(reltioPath, apiPath))
|
|
152
|
-
}), when(has('url'), assocPath(['validationUrl'], task.params.url)))(task.params);
|
|
153
|
-
var processedTask = __assign(__assign({}, task), { params: processedParams });
|
|
154
|
-
processRequest(__assign({ name: processedTask.params.name, paramObject: processedTask, permissions: config.action.permissions, worker: worker, metadata: metadata, config: config, user: user, servicesPath: servicesPath, apiPath: reltioPath, tenant: tenant, workflowPath: workflowPath, entity: entity, entityUri: entityUri, environment: environment, query: searchQuery, openSearch: openSearch, workflowCheckPermission: workflowCheckPermission }, qxApi));
|
|
144
|
+
var processedTask = getProcessedTask(task, apiPath, reltioPath, tenant);
|
|
145
|
+
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: entity, entityUri: entityUri, environment: environment, query: searchQuery, openSearch: openSearch, workflowCheckPermission: workflowCheckPermission }, qxApi));
|
|
155
146
|
break;
|
|
156
147
|
}
|
|
157
148
|
case CustomAction.RETURN_PROCESSED_API_RESPONSE: {
|
|
@@ -181,20 +172,18 @@ export var useAPI = function (config) {
|
|
|
181
172
|
var _a;
|
|
182
173
|
responseListeners.current = __assign(__assign({}, responseListeners.current), (_a = {}, _a[responseId] = { next: next }, _a));
|
|
183
174
|
};
|
|
184
|
-
var qooxdooRequestInterceptor = setUpQooxdooRequestInterceptor({ workerRef: workerRef, setRequestListeners: setRequestListeners });
|
|
185
|
-
var qooxdooResponseInterceptor = setUpQooxdooResponseInterceptor({ workerRef: workerRef, setResponseListeners: setResponseListeners });
|
|
186
175
|
var requestInterceptor = setUpRequestInterceptor({
|
|
187
176
|
apiPath: apiPath,
|
|
188
177
|
reltioPath: reltioPath,
|
|
189
178
|
tenant: tenant,
|
|
190
|
-
processApiRequest:
|
|
179
|
+
processApiRequest: processApiRequest,
|
|
191
180
|
workerRef: workerRef,
|
|
192
181
|
setRequestListeners: setRequestListeners
|
|
193
182
|
});
|
|
194
183
|
var responseInterceptor = setUpResponseInterceptor({
|
|
195
184
|
reltioPath: reltioPath,
|
|
196
185
|
apiPath: apiPath,
|
|
197
|
-
processApiResponse:
|
|
186
|
+
processApiResponse: processApiResponse,
|
|
198
187
|
workerRef: workerRef,
|
|
199
188
|
setResponseListeners: setResponseListeners
|
|
200
189
|
});
|
|
@@ -203,11 +192,10 @@ export var useAPI = function (config) {
|
|
|
203
192
|
(_a = workerRef.current) === null || _a === void 0 ? void 0 : _a.postMessage({ action: 'event', type: type, data: data });
|
|
204
193
|
};
|
|
205
194
|
var pendingInterceptors = useRef(false);
|
|
206
|
-
var needDelayedRequestForInterceptors =
|
|
207
|
-
interceptHandlers &&
|
|
195
|
+
var needDelayedRequestForInterceptors = interceptHandlers &&
|
|
208
196
|
!isEmptyValue(config.action) &&
|
|
209
|
-
|
|
210
|
-
(
|
|
197
|
+
platform !== CustomScriptPlatform.CLASSIC &&
|
|
198
|
+
(processApiRequest || processApiResponse);
|
|
211
199
|
if (needDelayedRequestForInterceptors) {
|
|
212
200
|
if (!pendingInterceptors.current && !workerRef.current) {
|
|
213
201
|
interceptHandlers.startInterceptorInit();
|
|
@@ -215,7 +203,7 @@ export var useAPI = function (config) {
|
|
|
215
203
|
}
|
|
216
204
|
}
|
|
217
205
|
useEffect(function () {
|
|
218
|
-
if (
|
|
206
|
+
if (isValidCustomScript(config.action)) {
|
|
219
207
|
workerRef.current = initializeWebWorker(workerUrl, process, config);
|
|
220
208
|
if (pendingInterceptors.current) {
|
|
221
209
|
interceptHandlers.finishInterceptorInit();
|
|
@@ -244,30 +232,18 @@ export var useAPI = function (config) {
|
|
|
244
232
|
postEventMessage('execute', null);
|
|
245
233
|
}, [config]);
|
|
246
234
|
useEffect(function () {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
(
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
}
|
|
259
|
-
else {
|
|
260
|
-
addInternalRequestInterceptor(requestInterceptor);
|
|
261
|
-
addInternalResponseInterceptor(responseInterceptor);
|
|
262
|
-
workerRef.current.onerror = function () {
|
|
263
|
-
removeInternalRequestInterceptor_1(requestInterceptor);
|
|
264
|
-
removeInternalResponseInterceptor_1(responseInterceptor);
|
|
265
|
-
};
|
|
266
|
-
return function () {
|
|
267
|
-
removeInternalRequestInterceptor_1(requestInterceptor);
|
|
268
|
-
removeInternalResponseInterceptor_1(responseInterceptor);
|
|
269
|
-
};
|
|
270
|
-
}
|
|
235
|
+
if (!isEmptyValue(interceptHandlers) && (processApiRequest || processApiResponse)) {
|
|
236
|
+
var addInternalRequestInterceptor = interceptHandlers.addInternalRequestInterceptor, addInternalResponseInterceptor = interceptHandlers.addInternalResponseInterceptor, removeInternalRequestInterceptor_1 = interceptHandlers.removeInternalRequestInterceptor, removeInternalResponseInterceptor_1 = interceptHandlers.removeInternalResponseInterceptor;
|
|
237
|
+
addInternalRequestInterceptor(requestInterceptor);
|
|
238
|
+
addInternalResponseInterceptor(responseInterceptor);
|
|
239
|
+
workerRef.current.onerror = function () {
|
|
240
|
+
removeInternalRequestInterceptor_1(requestInterceptor);
|
|
241
|
+
removeInternalResponseInterceptor_1(responseInterceptor);
|
|
242
|
+
};
|
|
243
|
+
return function () {
|
|
244
|
+
removeInternalRequestInterceptor_1(requestInterceptor);
|
|
245
|
+
removeInternalResponseInterceptor_1(responseInterceptor);
|
|
246
|
+
};
|
|
271
247
|
}
|
|
272
248
|
}, [config]);
|
|
273
249
|
return { html: html, visible: visible, tooltip: tooltip, customStyles: customStyles, onClick: onClick, popup: popup };
|
|
@@ -32,19 +32,13 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
32
32
|
import { useContext, useEffect, useRef } from 'react';
|
|
33
33
|
import { useDispatch, useSelector } from 'react-redux';
|
|
34
34
|
import mdmModule, { ui } from '@reltio/mdm-module';
|
|
35
|
-
import { CustomAction,
|
|
35
|
+
import { CustomAction, initializeWebWorker, isEmptyValue } from '@reltio/mdm-sdk';
|
|
36
36
|
import { nanoid } from 'nanoid';
|
|
37
|
-
import {
|
|
37
|
+
import { omit } from 'ramda';
|
|
38
38
|
import { useWorkflowCheckPermission } from '../components/workflow';
|
|
39
39
|
import { InterceptHandlersContext, SandboxAPIContext, SnackbarContext } from '../contexts';
|
|
40
40
|
import { getWorkerURL, processRequest } from './useAPI';
|
|
41
|
-
import {
|
|
42
|
-
var isURLtoProcess = function (processApi, url) {
|
|
43
|
-
return (processApi || []).some(function (request) {
|
|
44
|
-
var regExp = new RegExp("^".concat(request, "$"));
|
|
45
|
-
return request.replace(/\/*$/, '') === url || (request && regExp.test(url));
|
|
46
|
-
});
|
|
47
|
-
};
|
|
41
|
+
import { isValidCustomScript, isURLtoProcess, getProcessedTask, getRequestFakeUrl, getResponseFakeUrl } from './useAPI/helpers';
|
|
48
42
|
var getCustomViewConfig = function (config) {
|
|
49
43
|
var processApiResponse = config.processApiResponse, processApiRequest = config.processApiRequest, permissions = config.permissions, files = config.files, otherProps = __rest(config, ["processApiResponse", "processApiRequest", "permissions", "files"]);
|
|
50
44
|
return __assign({ action: { processApiResponse: processApiResponse, processApiRequest: processApiRequest, permissions: permissions, files: files } }, otherProps);
|
|
@@ -52,7 +46,7 @@ var getCustomViewConfig = function (config) {
|
|
|
52
46
|
export var useCustomScripts = function (config) {
|
|
53
47
|
var _a;
|
|
54
48
|
var customScripts = config.reduce(function (acc, customScript) {
|
|
55
|
-
if (customScript
|
|
49
|
+
if (isValidCustomScript(customScript)) {
|
|
56
50
|
return __spreadArray(__spreadArray([], acc, true), [__assign(__assign({}, customScript), { actionId: nanoid() })], false);
|
|
57
51
|
}
|
|
58
52
|
return acc;
|
|
@@ -92,16 +86,8 @@ export var useCustomScripts = function (config) {
|
|
|
92
86
|
break;
|
|
93
87
|
}
|
|
94
88
|
case CustomAction.REQUEST: {
|
|
95
|
-
var
|
|
96
|
-
|
|
97
|
-
var isGlobalUrl = startsWith('/', pathOr('', ['params', 'url'], task)) &&
|
|
98
|
-
!startsWith(apiPath, pathOr('', ['params', 'url'], task));
|
|
99
|
-
var isApiAction = pathEq(['params', 'name'], RequestAction.API, task);
|
|
100
|
-
var processedParams = pipe(evolve({
|
|
101
|
-
url: ifElse(both(always(isGlobalUrl), always(isApiAction)), concat("".concat(processedApiPath, "/api/").concat(tenant)), replace(reltioPath, apiPath))
|
|
102
|
-
}), when(has('url'), assocPath(['validationUrl'], task.params.url)))(task.params);
|
|
103
|
-
var processedTask = __assign(__assign({}, task), { params: processedParams });
|
|
104
|
-
processRequest(__assign({ name: processedTask.params.name, paramObject: processedTask, permissions: config.action.permissions, worker: worker, metadata: metadata, config: config, user: user, apiPath: reltioPath, servicesPath: servicesPath, tenant: tenant, workflowPath: workflowPath, entity: entity, entityUri: entityUri, environment: environment, query: typeSearch === 'search' ? search === null || search === void 0 ? void 0 : search.query : null, openSearch: openSearch, workflowCheckPermission: workflowCheckPermission }, qxApi));
|
|
89
|
+
var processedTask = getProcessedTask(task, apiPath, reltioPath, tenant);
|
|
90
|
+
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: entity, entityUri: entityUri, environment: environment, query: typeSearch === 'search' ? search === null || search === void 0 ? void 0 : search.query : null, openSearch: openSearch, workflowCheckPermission: workflowCheckPermission }, qxApi));
|
|
105
91
|
break;
|
|
106
92
|
}
|
|
107
93
|
case CustomAction.RETURN_PROCESSED_API_RESPONSE: {
|
|
@@ -140,14 +126,13 @@ export var useCustomScripts = function (config) {
|
|
|
140
126
|
}, [config, metadata]);
|
|
141
127
|
var customScriptRequestInterceptor = function (_a) {
|
|
142
128
|
var _b;
|
|
143
|
-
var
|
|
144
|
-
var fakeURL = url
|
|
145
|
-
|
|
146
|
-
: "".concat(reltioPath).concat(url.replace(apiPath, ''));
|
|
147
|
-
var actionId = pipe(map(pick(['actionId', 'processApiRequest'])), find(function (_a) {
|
|
129
|
+
var url = _a.url, next = _a.next, resolve = _a.resolve, options = _a.options;
|
|
130
|
+
var fakeURL = getRequestFakeUrl(url, apiPath, reltioPath, tenant);
|
|
131
|
+
var customScript = customScripts.find(function (_a) {
|
|
148
132
|
var processApiRequest = _a.processApiRequest;
|
|
149
|
-
return isURLtoProcess(
|
|
150
|
-
})
|
|
133
|
+
return isURLtoProcess(fakeURL, processApiRequest);
|
|
134
|
+
});
|
|
135
|
+
var actionId = customScript === null || customScript === void 0 ? void 0 : customScript.actionId;
|
|
151
136
|
if (actionId) {
|
|
152
137
|
var requestId = nanoid();
|
|
153
138
|
requestListeners.current = __assign(__assign({}, requestListeners.current), (_b = {}, _b[requestId] = { options: options, next: next, id: requestId, resolve: resolve }, _b));
|
|
@@ -156,7 +141,7 @@ export var useCustomScripts = function (config) {
|
|
|
156
141
|
id: requestId,
|
|
157
142
|
url: fakeURL,
|
|
158
143
|
method: options.method,
|
|
159
|
-
headers: __assign(__assign({}, options.headers), {
|
|
144
|
+
headers: __assign(__assign({}, options.headers), { actionId: actionId }),
|
|
160
145
|
data: options.body || options.data
|
|
161
146
|
});
|
|
162
147
|
}
|
|
@@ -165,20 +150,26 @@ export var useCustomScripts = function (config) {
|
|
|
165
150
|
}
|
|
166
151
|
};
|
|
167
152
|
var customScriptResponseInterceptor = function (_a) {
|
|
168
|
-
var _b;
|
|
169
153
|
var url = _a.url, response = _a.response, next = _a.next, options = _a.options, abort = _a.abort;
|
|
170
|
-
|
|
154
|
+
var fakeURL = getResponseFakeUrl(url, apiPath, reltioPath);
|
|
155
|
+
var customScript = customScripts.find(function (_a) {
|
|
156
|
+
var processApiResponse = _a.processApiResponse;
|
|
157
|
+
return isURLtoProcess(fakeURL, processApiResponse);
|
|
158
|
+
});
|
|
159
|
+
var actionId = customScript === null || customScript === void 0 ? void 0 : customScript.actionId;
|
|
160
|
+
if (actionId) {
|
|
161
|
+
var responseId_1 = nanoid();
|
|
171
162
|
response
|
|
172
163
|
.json()
|
|
173
164
|
.then(function (data) {
|
|
174
165
|
var _a;
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
166
|
+
responseListeners.current = __assign(__assign({}, responseListeners.current), (_a = {}, _a[responseId_1] = { next: next }, _a));
|
|
167
|
+
workers.current[actionId].postMessage({
|
|
168
|
+
action: 'apiResponse',
|
|
169
|
+
id: responseId_1,
|
|
170
|
+
url: fakeURL,
|
|
171
|
+
method: options.method,
|
|
172
|
+
data: data
|
|
182
173
|
});
|
|
183
174
|
})
|
|
184
175
|
.catch(function (error) {
|
|
@@ -186,33 +177,7 @@ export var useCustomScripts = function (config) {
|
|
|
186
177
|
});
|
|
187
178
|
}
|
|
188
179
|
else {
|
|
189
|
-
|
|
190
|
-
var actionId_1 = pipe(map(pick(['actionId', 'processApiResponse'])), find(function (_a) {
|
|
191
|
-
var processApiResponse = _a.processApiResponse;
|
|
192
|
-
return isURLtoProcess(processApiResponse, fakeURL_1);
|
|
193
|
-
}), prop('actionId'))(customScripts);
|
|
194
|
-
if (actionId_1) {
|
|
195
|
-
var responseId_1 = nanoid();
|
|
196
|
-
response
|
|
197
|
-
.json()
|
|
198
|
-
.then(function (data) {
|
|
199
|
-
var _a;
|
|
200
|
-
responseListeners.current = __assign(__assign({}, responseListeners.current), (_a = {}, _a[responseId_1] = { next: next }, _a));
|
|
201
|
-
workers.current[actionId_1].postMessage({
|
|
202
|
-
action: 'apiResponse',
|
|
203
|
-
id: responseId_1,
|
|
204
|
-
url: fakeURL_1,
|
|
205
|
-
method: options.method,
|
|
206
|
-
data: data
|
|
207
|
-
});
|
|
208
|
-
})
|
|
209
|
-
.catch(function (error) {
|
|
210
|
-
abort(error);
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
else {
|
|
214
|
-
next(response);
|
|
215
|
-
}
|
|
180
|
+
next(response);
|
|
216
181
|
}
|
|
217
182
|
};
|
|
218
183
|
useEffect(function () {
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reltio/components",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.1580",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE FILE",
|
|
5
5
|
"main": "./cjs/index.js",
|
|
6
6
|
"module": "./esm/index.js",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@date-io/moment": "^1.3.5",
|
|
9
9
|
"@react-google-maps/api": "2.7.0",
|
|
10
|
-
"@reltio/mdm-module": "^1.4.
|
|
11
|
-
"@reltio/mdm-sdk": "^1.4.
|
|
10
|
+
"@reltio/mdm-module": "^1.4.1580",
|
|
11
|
+
"@reltio/mdm-sdk": "^1.4.1580",
|
|
12
12
|
"classnames": "^2.2.5",
|
|
13
13
|
"d3-cloud": "^1.2.5",
|
|
14
14
|
"d3-geo": "^2.0.1",
|