@reltio/components 1.4.1829 → 1.4.1831

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.
@@ -29,3 +29,4 @@ export { useLayoutResetter } from './useLayoutResetter';
29
29
  export { useExpandInvalidRelations } from './useExpandInvalidRelations';
30
30
  export { useAutoFocus } from './useAutoFocus';
31
31
  export { useRequestDCRReview } from './useRequestDCRReview';
32
+ export { useSavedSearchesRequest } from './useSavedSearchesRequest';
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useRequestDCRReview = exports.useAutoFocus = exports.useExpandInvalidRelations = exports.useLayoutResetter = exports.useIsMountedRef = exports.useSnackbar = exports.useSavedStateForEntityType = exports.useReadableSearchState = exports.useEditableConnection = exports.useCustomScripts = exports.useMarkAsNotMatchRequest = exports.useMergeAllRequest = exports.usePagingSimulator = exports.useMatchesLoader = exports.useConfigPermissions = exports.useWhyDidYouUpdate = exports.useUsers = exports.useSavedState = exports.useSafePromise = exports.useRunOnceAfterValueInitialization = exports.useRelationsLoader = exports.useRelationTypeSelector = exports.usePrevious = exports.useDidUpdateEffect = exports.useCommentsEntitiesMap = exports.useCollaboration = exports.useAsyncMount = exports.useAPI = exports.useActions = exports.useMatchesColumnsData = exports.useScrollToAttributeError = void 0;
3
+ exports.useSavedSearchesRequest = exports.useRequestDCRReview = exports.useAutoFocus = exports.useExpandInvalidRelations = exports.useLayoutResetter = exports.useIsMountedRef = exports.useSnackbar = exports.useSavedStateForEntityType = exports.useReadableSearchState = exports.useEditableConnection = exports.useCustomScripts = exports.useMarkAsNotMatchRequest = exports.useMergeAllRequest = exports.usePagingSimulator = exports.useMatchesLoader = exports.useConfigPermissions = exports.useWhyDidYouUpdate = exports.useUsers = exports.useSavedState = exports.useSafePromise = exports.useRunOnceAfterValueInitialization = exports.useRelationsLoader = exports.useRelationTypeSelector = exports.usePrevious = exports.useDidUpdateEffect = exports.useCommentsEntitiesMap = exports.useCollaboration = exports.useAsyncMount = exports.useAPI = exports.useActions = exports.useMatchesColumnsData = exports.useScrollToAttributeError = void 0;
4
4
  var useScrollToAttributeError_1 = require("./useScrollToAttributeError/useScrollToAttributeError");
5
5
  Object.defineProperty(exports, "useScrollToAttributeError", { enumerable: true, get: function () { return useScrollToAttributeError_1.useScrollToAttributeError; } });
6
6
  var useMatchesColumnsData_1 = require("./useMatchesColumnsData/useMatchesColumnsData");
@@ -63,3 +63,5 @@ var useAutoFocus_1 = require("./useAutoFocus");
63
63
  Object.defineProperty(exports, "useAutoFocus", { enumerable: true, get: function () { return useAutoFocus_1.useAutoFocus; } });
64
64
  var useRequestDCRReview_1 = require("./useRequestDCRReview");
65
65
  Object.defineProperty(exports, "useRequestDCRReview", { enumerable: true, get: function () { return useRequestDCRReview_1.useRequestDCRReview; } });
66
+ var useSavedSearchesRequest_1 = require("./useSavedSearchesRequest");
67
+ Object.defineProperty(exports, "useSavedSearchesRequest", { enumerable: true, get: function () { return useSavedSearchesRequest_1.useSavedSearchesRequest; } });
@@ -21,16 +21,18 @@ var contexts_1 = require("../../contexts");
21
21
  var API_1 = require("./API");
22
22
  var helpers_1 = require("./helpers");
23
23
  var useAPI = function (config) {
24
+ var _a;
24
25
  if (config === void 0) { config = {}; }
25
- var _a = config.action || {}, processApiRequest = _a.processApiRequest, processApiResponse = _a.processApiResponse, platform = _a.platform;
26
- var _b = (0, react_1.useState)(), html = _b[0], setHtml = _b[1];
27
- var _c = (0, react_1.useState)([]), listenersToReset = _c[0], setListenersToReset = _c[1];
28
- var _d = (0, react_1.useState)([]), popupListenersToReset = _d[0], setPopupListenersToReset = _d[1];
29
- var _e = (0, react_1.useState)(true), visible = _e[0], setVisible = _e[1];
30
- var _f = (0, react_1.useState)(), popup = _f[0], setPopup = _f[1];
31
- var _g = (0, react_1.useState)(null), tooltip = _g[0], setTooltip = _g[1];
32
- var _h = (0, react_1.useState)({}), customStyles = _h[0], setCustomStyles = _h[1];
26
+ var _b = config.action || {}, processApiRequest = _b.processApiRequest, processApiResponse = _b.processApiResponse, platform = _b.platform;
27
+ var _c = (0, react_1.useState)(), html = _c[0], setHtml = _c[1];
28
+ var _d = (0, react_1.useState)([]), listenersToReset = _d[0], setListenersToReset = _d[1];
29
+ var _e = (0, react_1.useState)([]), popupListenersToReset = _e[0], setPopupListenersToReset = _e[1];
30
+ var _f = (0, react_1.useState)(true), visible = _f[0], setVisible = _f[1];
31
+ var _g = (0, react_1.useState)(), popup = _g[0], setPopup = _g[1];
32
+ var _h = (0, react_1.useState)(null), tooltip = _h[0], setTooltip = _h[1];
33
+ var _j = (0, react_1.useState)({}), customStyles = _j[0], setCustomStyles = _j[1];
33
34
  var workerRef = (0, react_1.useRef)();
35
+ var entityRef = (0, react_1.useRef)();
34
36
  var requestListeners = (0, react_1.useRef)({});
35
37
  var responseListeners = (0, react_1.useRef)({});
36
38
  var sanitizeHtml = (0, useHtmlSanitizer_1.useHtmlSanitizer)();
@@ -42,8 +44,8 @@ var useAPI = function (config) {
42
44
  var qxApi = (0, react_1.useContext)(contexts_1.SandboxAPIContext);
43
45
  var interceptHandlers = (0, react_1.useContext)(contexts_1.InterceptHandlersContext);
44
46
  var workflowCheckPermission = (0, workflow_1.useWorkflowCheckPermission)();
45
- var metadata = (0, contexts_1.useMdmMetadata)() || {};
46
- var entity = (0, contexts_1.useMdmEntity)() || {};
47
+ var metadata = (0, contexts_1.useMdmMetadata)();
48
+ var entity = (0, contexts_1.useMdmEntity)();
47
49
  var apiPath = (0, contexts_1.useMdmApiPath)();
48
50
  var servicesPath = (0, contexts_1.useMdmServicesPath)();
49
51
  var reltioPath = (0, contexts_1.useMdmReltioPath)();
@@ -52,8 +54,8 @@ var useAPI = function (config) {
52
54
  var entityUri = (0, contexts_1.useMdmEntityUri)();
53
55
  var isEditableMode = (0, contexts_1.useMdmIsEditableMode)();
54
56
  var environment = (0, contexts_1.useMdmWorkflowEnvironmentUrl)();
55
- var _j = (0, contexts_1.useMdmSearchProviderData)() || {}, typeSearch = _j.type, search = _j.data;
56
- var searchQuery = typeSearch === 'search' ? search === null || search === void 0 ? void 0 : search.query : null;
57
+ var searchProviderData = (0, contexts_1.useMdmSearchProviderData)();
58
+ var searchQuery = (searchProviderData === null || searchProviderData === void 0 ? void 0 : searchProviderData.type) === 'search' ? (_a = searchProviderData === null || searchProviderData === void 0 ? void 0 : searchProviderData.data) === null || _a === void 0 ? void 0 : _a.query : null;
57
59
  var innerText = '';
58
60
  var popupText = '';
59
61
  var process = function (_a) {
@@ -142,7 +144,7 @@ var useAPI = function (config) {
142
144
  }
143
145
  case mdm_sdk_1.CustomAction.REQUEST: {
144
146
  var processedTask = (0, helpers_1.getProcessedTask)(task, apiPath, reltioPath, tenant);
145
- (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: entity, entityUri: entityUri, environment: environment, query: searchQuery, openSearch: openSearch, workflowCheckPermission: workflowCheckPermission }, qxApi));
147
+ (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: entityUri, environment: environment, query: searchQuery, openSearch: openSearch, workflowCheckPermission: workflowCheckPermission }, qxApi));
146
148
  break;
147
149
  }
148
150
  case mdm_sdk_1.CustomAction.RETURN_PROCESSED_API_RESPONSE: {
@@ -209,9 +211,12 @@ var useAPI = function (config) {
209
211
  interceptHandlers.finishInterceptorInit();
210
212
  pendingInterceptors.current = false;
211
213
  }
212
- postEventMessage('updateEntity', entity);
213
214
  }
214
- }, [entity, config]);
215
+ }, [config]);
216
+ (0, react_1.useEffect)(function () {
217
+ postEventMessage('updateEntity', entity);
218
+ entityRef.current = entity;
219
+ }, [entity]);
215
220
  (0, react_1.useEffect)(function () {
216
221
  postEventMessage('editMode', isEditableMode);
217
222
  }, [isEditableMode]);
@@ -56,8 +56,8 @@ var useCustomScripts = function (config) {
56
56
  var _b = (0, react_1.useContext)(contexts_1.InterceptHandlersContext), addInternalRequestInterceptor = _b.addInternalRequestInterceptor, addInternalResponseInterceptor = _b.addInternalResponseInterceptor, removeInternalRequestInterceptor = _b.removeInternalRequestInterceptor, removeInternalResponseInterceptor = _b.removeInternalResponseInterceptor;
57
57
  var qxApi = (0, react_1.useContext)(contexts_1.SandboxAPIContext);
58
58
  var openSearch = (0, contexts_1.useMdmAction)('openSearch');
59
- var metadata = (_a = (0, contexts_1.useMdmMetadata)()) !== null && _a !== void 0 ? _a : null;
60
- var entity = (0, contexts_1.useMdmEntity)() || {};
59
+ var metadata = (0, contexts_1.useMdmMetadata)();
60
+ var entity = (0, contexts_1.useMdmEntity)();
61
61
  var uiPath = (0, contexts_1.useMdmUiPath)();
62
62
  var servicesPath = (0, contexts_1.useMdmServicesPath)();
63
63
  var reltioPath = (0, contexts_1.useMdmReltioPath)();
@@ -69,7 +69,8 @@ var useCustomScripts = function (config) {
69
69
  var entityUri = (0, contexts_1.useMdmEntityUri)();
70
70
  var environment = (0, contexts_1.useMdmWorkflowEnvironmentUrl)();
71
71
  var workflowCheckPermission = (0, workflow_1.useWorkflowCheckPermission)();
72
- var _c = (0, contexts_1.useMdmSearchProviderData)() || {}, typeSearch = _c.type, search = _c.data;
72
+ var searchProviderData = (0, contexts_1.useMdmSearchProviderData)();
73
+ var searchQuery = (searchProviderData === null || searchProviderData === void 0 ? void 0 : searchProviderData.type) === 'search' ? (_a = searchProviderData === null || searchProviderData === void 0 ? void 0 : searchProviderData.data) === null || _a === void 0 ? void 0 : _a.query : null;
73
74
  var requestListeners = (0, react_1.useRef)({});
74
75
  var responseListeners = (0, react_1.useRef)({});
75
76
  var workers = (0, react_1.useRef)({});
@@ -87,7 +88,7 @@ var useCustomScripts = function (config) {
87
88
  }
88
89
  case mdm_sdk_1.CustomAction.REQUEST: {
89
90
  var processedTask = (0, helpers_1.getProcessedTask)(task, apiPath, reltioPath, tenant);
90
- (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: entity, entityUri: entityUri, environment: environment, query: typeSearch === 'search' ? search === null || search === void 0 ? void 0 : search.query : null, openSearch: openSearch, workflowCheckPermission: workflowCheckPermission }, qxApi));
91
+ (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: entity, entityUri: entityUri, environment: environment, query: searchQuery, openSearch: openSearch, workflowCheckPermission: workflowCheckPermission }, qxApi));
91
92
  break;
92
93
  }
93
94
  case mdm_sdk_1.CustomAction.RETURN_PROCESSED_API_RESPONSE: {
@@ -110,19 +111,18 @@ var useCustomScripts = function (config) {
110
111
  }
111
112
  };
112
113
  (0, react_1.useEffect)(function () {
113
- if (metadata === null) {
114
- return;
114
+ if (metadata) {
115
+ workers.current = customScripts.reduce(function (acc, customScript) {
116
+ var _a;
117
+ var customViewConfig = getCustomViewConfig(customScript);
118
+ return __assign(__assign({}, acc), (_a = {}, _a[customScript.actionId] = (0, mdm_sdk_1.initializeWebWorker)(workerUrl, processMessageFromWorker, customViewConfig), _a));
119
+ }, workers.current);
120
+ return function () {
121
+ Object.keys(workers.current).forEach(function (actionId) {
122
+ workers.current[actionId].terminate();
123
+ });
124
+ };
115
125
  }
116
- workers.current = customScripts.reduce(function (acc, customScript) {
117
- var _a;
118
- var customViewConfig = getCustomViewConfig(customScript);
119
- return __assign(__assign({}, acc), (_a = {}, _a[customScript.actionId] = (0, mdm_sdk_1.initializeWebWorker)(workerUrl, processMessageFromWorker, customViewConfig), _a));
120
- }, workers.current);
121
- return function () {
122
- Object.keys(workers.current).forEach(function (actionId) {
123
- workers.current[actionId].terminate();
124
- });
125
- };
126
126
  }, [config, metadata]);
127
127
  var customScriptRequestInterceptor = function (_a) {
128
128
  var _b;
@@ -0,0 +1,28 @@
1
+ import { SavedSearchData, SavedSearchesOptions, deleteSavedSearch, updateSavedSearch } from '@reltio/mdm-sdk';
2
+ import { RequestStates } from '../types';
3
+ type Props = {
4
+ options?: SavedSearchesOptions;
5
+ offset: number;
6
+ max: number;
7
+ queryEstimatorEnabled?: boolean;
8
+ };
9
+ export declare const useSavedSearchesRequest: ({ options, offset, max, queryEstimatorEnabled }: Props) => {
10
+ state: RequestStates;
11
+ data: SavedSearchData[];
12
+ reload: () => void;
13
+ total: number;
14
+ loadTotalForSearchByUri: (uri: string) => Promise<void>;
15
+ saveSearch: (savedSearch: Partial<SavedSearchData> & {
16
+ name: string;
17
+ query: string;
18
+ uiState: Record<string, any>;
19
+ }) => Promise<SavedSearchData>;
20
+ updateSearch: (savedSearch: Parameters<typeof updateSavedSearch>[0]) => Promise<SavedSearchData>;
21
+ deleteSearch: (savedSearch: Parameters<typeof deleteSavedSearch>[0]) => Promise<{
22
+ success: true;
23
+ } | {
24
+ success: false;
25
+ error: unknown;
26
+ }>;
27
+ };
28
+ export {};
@@ -0,0 +1,182 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __rest = (this && this.__rest) || function (s, e) {
50
+ var t = {};
51
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
52
+ t[p] = s[p];
53
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
54
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
55
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
56
+ t[p[i]] = s[p[i]];
57
+ }
58
+ return t;
59
+ };
60
+ Object.defineProperty(exports, "__esModule", { value: true });
61
+ exports.useSavedSearchesRequest = void 0;
62
+ var mdm_sdk_1 = require("@reltio/mdm-sdk");
63
+ var ramda_1 = require("ramda");
64
+ var react_1 = require("react");
65
+ var contexts_1 = require("../contexts");
66
+ var types_1 = require("../types");
67
+ var useSavedSearchesRequest = function (_a) {
68
+ var options = _a.options, offset = _a.offset, max = _a.max, queryEstimatorEnabled = _a.queryEstimatorEnabled;
69
+ var _b = (0, react_1.useState)([]), data = _b[0], setData = _b[1];
70
+ var _c = (0, react_1.useState)(0), total = _c[0], setTotal = _c[1];
71
+ var _d = (0, react_1.useState)(types_1.RequestStates.INIT), requestState = _d[0], setRequestState = _d[1];
72
+ var onError = function (error) {
73
+ console.warn(error); // eslint-disable-line
74
+ if (!(0, mdm_sdk_1.isAbortError)(error)) {
75
+ setRequestState(types_1.RequestStates.ERROR);
76
+ setData([]);
77
+ }
78
+ };
79
+ var signal = (0, react_1.useContext)(contexts_1.PageRequestsAbortingContext);
80
+ var loadData = (0, react_1.useCallback)(function () {
81
+ setRequestState(types_1.RequestStates.LOADING);
82
+ var onRequestFinished = function (data) {
83
+ setData(data.result || []);
84
+ setTotal(data.total);
85
+ setRequestState(types_1.RequestStates.LOADED);
86
+ };
87
+ var _a = (options || {}), countResults = _a.countResults, restOptions = __rest(_a, ["countResults"]);
88
+ var getData = function () { return __awaiter(void 0, void 0, void 0, function () {
89
+ var _a, _b, savedSearches, total, totalRequests, totalResults, searchesWithCount;
90
+ return __generator(this, function (_c) {
91
+ switch (_c.label) {
92
+ case 0: return [4 /*yield*/, (0, mdm_sdk_1.getSavedSearches)(__assign({ offset: offset, max: max }, restOptions), signal)];
93
+ case 1:
94
+ _a = _c.sent(), _b = _a.result, savedSearches = _b === void 0 ? [] : _b, total = _a.total;
95
+ if (!countResults) return [3 /*break*/, 3];
96
+ totalRequests = savedSearches.map(function (search) {
97
+ return (0, mdm_sdk_1.getTotalsForQuery)((0, mdm_sdk_1.replacePlaceholdersInQuery)(search.query), queryEstimatorEnabled, signal);
98
+ });
99
+ return [4 /*yield*/, (0, mdm_sdk_1.promiseAllSettled)(totalRequests)];
100
+ case 2:
101
+ totalResults = _c.sent();
102
+ searchesWithCount = totalResults.reduce(function (searchesWithTotal, _a, searchIndex) {
103
+ var status = _a.status, value = _a.value, reason = _a.reason;
104
+ switch (status) {
105
+ case 'fulfilled':
106
+ return (0, ramda_1.assocPath)([searchIndex, 'count'], value.total, searchesWithTotal);
107
+ case 'rejected':
108
+ console.warn(reason);
109
+ break;
110
+ }
111
+ return searchesWithTotal;
112
+ }, savedSearches);
113
+ onRequestFinished({ result: searchesWithCount, total: total });
114
+ return [3 /*break*/, 4];
115
+ case 3:
116
+ onRequestFinished({ result: savedSearches, total: total });
117
+ _c.label = 4;
118
+ case 4: return [2 /*return*/];
119
+ }
120
+ });
121
+ }); };
122
+ getData().catch(onError);
123
+ }, [options, offset, max, signal, queryEstimatorEnabled]);
124
+ var refreshAction = function () {
125
+ try {
126
+ loadData();
127
+ }
128
+ catch (e) {
129
+ onError(e);
130
+ }
131
+ };
132
+ var loadTotalForUri = (0, react_1.useCallback)(function (uri) { return __awaiter(void 0, void 0, void 0, function () {
133
+ var searchIndex, search, total_1, e_1;
134
+ return __generator(this, function (_a) {
135
+ switch (_a.label) {
136
+ case 0:
137
+ searchIndex = data.findIndex((0, ramda_1.propEq)('uri', uri));
138
+ search = data[searchIndex];
139
+ setData((0, ramda_1.assocPath)([searchIndex, 'isLoadingTotal'], true));
140
+ _a.label = 1;
141
+ case 1:
142
+ _a.trys.push([1, 3, , 4]);
143
+ return [4 /*yield*/, (0, mdm_sdk_1.getTotalsForQuery)((0, mdm_sdk_1.replacePlaceholdersInQuery)(search.query), false, signal)];
144
+ case 2:
145
+ total_1 = (_a.sent()).total;
146
+ setData((0, ramda_1.assocPath)([searchIndex, 'count'], total_1));
147
+ return [3 /*break*/, 4];
148
+ case 3:
149
+ e_1 = _a.sent();
150
+ console.warn(e_1);
151
+ return [3 /*break*/, 4];
152
+ case 4:
153
+ setData((0, ramda_1.assocPath)([searchIndex, 'isLoadingTotal'], false));
154
+ return [2 /*return*/];
155
+ }
156
+ });
157
+ }); }, [data, signal]);
158
+ var saveSearch = (0, react_1.useCallback)(function (savedSearch) {
159
+ var type = (options || {}).type;
160
+ return (0, mdm_sdk_1.createSavedSearch)([__assign(__assign({}, savedSearch), { type: type })]);
161
+ }, [options]);
162
+ var updateSearch = (0, react_1.useCallback)(function (savedSearch) {
163
+ return (0, mdm_sdk_1.updateSavedSearch)(savedSearch);
164
+ }, []);
165
+ var deleteSearch = (0, react_1.useCallback)(function (savedSearch) {
166
+ return (0, mdm_sdk_1.deleteSavedSearch)(savedSearch);
167
+ }, []);
168
+ (0, react_1.useEffect)(function () {
169
+ refreshAction();
170
+ }, [loadData]);
171
+ return {
172
+ state: requestState,
173
+ data: data,
174
+ reload: refreshAction,
175
+ total: total,
176
+ loadTotalForSearchByUri: loadTotalForUri,
177
+ saveSearch: saveSearch,
178
+ updateSearch: updateSearch,
179
+ deleteSearch: deleteSearch
180
+ };
181
+ };
182
+ exports.useSavedSearchesRequest = useSavedSearchesRequest;
@@ -29,3 +29,4 @@ export { useLayoutResetter } from './useLayoutResetter';
29
29
  export { useExpandInvalidRelations } from './useExpandInvalidRelations';
30
30
  export { useAutoFocus } from './useAutoFocus';
31
31
  export { useRequestDCRReview } from './useRequestDCRReview';
32
+ export { useSavedSearchesRequest } from './useSavedSearchesRequest';
@@ -29,3 +29,4 @@ export { useLayoutResetter } from './useLayoutResetter';
29
29
  export { useExpandInvalidRelations } from './useExpandInvalidRelations';
30
30
  export { useAutoFocus } from './useAutoFocus';
31
31
  export { useRequestDCRReview } from './useRequestDCRReview';
32
+ export { useSavedSearchesRequest } from './useSavedSearchesRequest';
@@ -18,16 +18,18 @@ import { InterceptHandlersContext, SandboxAPIContext, SnackbarContext, useMdmAct
18
18
  import { processRequest } from './API';
19
19
  import { getWorkerURL, isValidCustomScript, resetHtml, getProcessedTask, setUpRequestInterceptor, setUpResponseInterceptor } from './helpers';
20
20
  export var useAPI = function (config) {
21
+ var _a;
21
22
  if (config === void 0) { config = {}; }
22
- var _a = config.action || {}, processApiRequest = _a.processApiRequest, processApiResponse = _a.processApiResponse, platform = _a.platform;
23
- var _b = useState(), html = _b[0], setHtml = _b[1];
24
- var _c = useState([]), listenersToReset = _c[0], setListenersToReset = _c[1];
25
- var _d = useState([]), popupListenersToReset = _d[0], setPopupListenersToReset = _d[1];
26
- var _e = useState(true), visible = _e[0], setVisible = _e[1];
27
- var _f = useState(), popup = _f[0], setPopup = _f[1];
28
- var _g = useState(null), tooltip = _g[0], setTooltip = _g[1];
29
- var _h = useState({}), customStyles = _h[0], setCustomStyles = _h[1];
23
+ var _b = config.action || {}, processApiRequest = _b.processApiRequest, processApiResponse = _b.processApiResponse, platform = _b.platform;
24
+ var _c = useState(), html = _c[0], setHtml = _c[1];
25
+ var _d = useState([]), listenersToReset = _d[0], setListenersToReset = _d[1];
26
+ var _e = useState([]), popupListenersToReset = _e[0], setPopupListenersToReset = _e[1];
27
+ var _f = useState(true), visible = _f[0], setVisible = _f[1];
28
+ var _g = useState(), popup = _g[0], setPopup = _g[1];
29
+ var _h = useState(null), tooltip = _h[0], setTooltip = _h[1];
30
+ var _j = useState({}), customStyles = _j[0], setCustomStyles = _j[1];
30
31
  var workerRef = useRef();
32
+ var entityRef = useRef();
31
33
  var requestListeners = useRef({});
32
34
  var responseListeners = useRef({});
33
35
  var sanitizeHtml = useHtmlSanitizer();
@@ -39,8 +41,8 @@ export var useAPI = function (config) {
39
41
  var qxApi = useContext(SandboxAPIContext);
40
42
  var interceptHandlers = useContext(InterceptHandlersContext);
41
43
  var workflowCheckPermission = useWorkflowCheckPermission();
42
- var metadata = useMdmMetadata() || {};
43
- var entity = useMdmEntity() || {};
44
+ var metadata = useMdmMetadata();
45
+ var entity = useMdmEntity();
44
46
  var apiPath = useMdmApiPath();
45
47
  var servicesPath = useMdmServicesPath();
46
48
  var reltioPath = useMdmReltioPath();
@@ -49,8 +51,8 @@ export var useAPI = function (config) {
49
51
  var entityUri = useMdmEntityUri();
50
52
  var isEditableMode = useMdmIsEditableMode();
51
53
  var environment = useMdmWorkflowEnvironmentUrl();
52
- var _j = useMdmSearchProviderData() || {}, typeSearch = _j.type, search = _j.data;
53
- var searchQuery = typeSearch === 'search' ? search === null || search === void 0 ? void 0 : search.query : null;
54
+ var searchProviderData = useMdmSearchProviderData();
55
+ var searchQuery = (searchProviderData === null || searchProviderData === void 0 ? void 0 : searchProviderData.type) === 'search' ? (_a = searchProviderData === null || searchProviderData === void 0 ? void 0 : searchProviderData.data) === null || _a === void 0 ? void 0 : _a.query : null;
54
56
  var innerText = '';
55
57
  var popupText = '';
56
58
  var process = function (_a) {
@@ -139,7 +141,7 @@ export var useAPI = function (config) {
139
141
  }
140
142
  case CustomAction.REQUEST: {
141
143
  var processedTask = getProcessedTask(task, apiPath, reltioPath, tenant);
142
- 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));
144
+ 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: entityUri, environment: environment, query: searchQuery, openSearch: openSearch, workflowCheckPermission: workflowCheckPermission }, qxApi));
143
145
  break;
144
146
  }
145
147
  case CustomAction.RETURN_PROCESSED_API_RESPONSE: {
@@ -206,9 +208,12 @@ export var useAPI = function (config) {
206
208
  interceptHandlers.finishInterceptorInit();
207
209
  pendingInterceptors.current = false;
208
210
  }
209
- postEventMessage('updateEntity', entity);
210
211
  }
211
- }, [entity, config]);
212
+ }, [config]);
213
+ useEffect(function () {
214
+ postEventMessage('updateEntity', entity);
215
+ entityRef.current = entity;
216
+ }, [entity]);
212
217
  useEffect(function () {
213
218
  postEventMessage('editMode', isEditableMode);
214
219
  }, [isEditableMode]);
@@ -53,8 +53,8 @@ export var useCustomScripts = function (config) {
53
53
  var _b = useContext(InterceptHandlersContext), addInternalRequestInterceptor = _b.addInternalRequestInterceptor, addInternalResponseInterceptor = _b.addInternalResponseInterceptor, removeInternalRequestInterceptor = _b.removeInternalRequestInterceptor, removeInternalResponseInterceptor = _b.removeInternalResponseInterceptor;
54
54
  var qxApi = useContext(SandboxAPIContext);
55
55
  var openSearch = useMdmAction('openSearch');
56
- var metadata = (_a = useMdmMetadata()) !== null && _a !== void 0 ? _a : null;
57
- var entity = useMdmEntity() || {};
56
+ var metadata = useMdmMetadata();
57
+ var entity = useMdmEntity();
58
58
  var uiPath = useMdmUiPath();
59
59
  var servicesPath = useMdmServicesPath();
60
60
  var reltioPath = useMdmReltioPath();
@@ -66,7 +66,8 @@ export var useCustomScripts = function (config) {
66
66
  var entityUri = useMdmEntityUri();
67
67
  var environment = useMdmWorkflowEnvironmentUrl();
68
68
  var workflowCheckPermission = useWorkflowCheckPermission();
69
- var _c = useMdmSearchProviderData() || {}, typeSearch = _c.type, search = _c.data;
69
+ var searchProviderData = useMdmSearchProviderData();
70
+ var searchQuery = (searchProviderData === null || searchProviderData === void 0 ? void 0 : searchProviderData.type) === 'search' ? (_a = searchProviderData === null || searchProviderData === void 0 ? void 0 : searchProviderData.data) === null || _a === void 0 ? void 0 : _a.query : null;
70
71
  var requestListeners = useRef({});
71
72
  var responseListeners = useRef({});
72
73
  var workers = useRef({});
@@ -84,7 +85,7 @@ export var useCustomScripts = function (config) {
84
85
  }
85
86
  case CustomAction.REQUEST: {
86
87
  var processedTask = getProcessedTask(task, apiPath, reltioPath, tenant);
87
- 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));
88
+ 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: searchQuery, openSearch: openSearch, workflowCheckPermission: workflowCheckPermission }, qxApi));
88
89
  break;
89
90
  }
90
91
  case CustomAction.RETURN_PROCESSED_API_RESPONSE: {
@@ -107,19 +108,18 @@ export var useCustomScripts = function (config) {
107
108
  }
108
109
  };
109
110
  useEffect(function () {
110
- if (metadata === null) {
111
- return;
111
+ if (metadata) {
112
+ workers.current = customScripts.reduce(function (acc, customScript) {
113
+ var _a;
114
+ var customViewConfig = getCustomViewConfig(customScript);
115
+ return __assign(__assign({}, acc), (_a = {}, _a[customScript.actionId] = initializeWebWorker(workerUrl, processMessageFromWorker, customViewConfig), _a));
116
+ }, workers.current);
117
+ return function () {
118
+ Object.keys(workers.current).forEach(function (actionId) {
119
+ workers.current[actionId].terminate();
120
+ });
121
+ };
112
122
  }
113
- workers.current = customScripts.reduce(function (acc, customScript) {
114
- var _a;
115
- var customViewConfig = getCustomViewConfig(customScript);
116
- return __assign(__assign({}, acc), (_a = {}, _a[customScript.actionId] = initializeWebWorker(workerUrl, processMessageFromWorker, customViewConfig), _a));
117
- }, workers.current);
118
- return function () {
119
- Object.keys(workers.current).forEach(function (actionId) {
120
- workers.current[actionId].terminate();
121
- });
122
- };
123
123
  }, [config, metadata]);
124
124
  var customScriptRequestInterceptor = function (_a) {
125
125
  var _b;
@@ -0,0 +1,28 @@
1
+ import { SavedSearchData, SavedSearchesOptions, deleteSavedSearch, updateSavedSearch } from '@reltio/mdm-sdk';
2
+ import { RequestStates } from '../types';
3
+ type Props = {
4
+ options?: SavedSearchesOptions;
5
+ offset: number;
6
+ max: number;
7
+ queryEstimatorEnabled?: boolean;
8
+ };
9
+ export declare const useSavedSearchesRequest: ({ options, offset, max, queryEstimatorEnabled }: Props) => {
10
+ state: RequestStates;
11
+ data: SavedSearchData[];
12
+ reload: () => void;
13
+ total: number;
14
+ loadTotalForSearchByUri: (uri: string) => Promise<void>;
15
+ saveSearch: (savedSearch: Partial<SavedSearchData> & {
16
+ name: string;
17
+ query: string;
18
+ uiState: Record<string, any>;
19
+ }) => Promise<SavedSearchData>;
20
+ updateSearch: (savedSearch: Parameters<typeof updateSavedSearch>[0]) => Promise<SavedSearchData>;
21
+ deleteSearch: (savedSearch: Parameters<typeof deleteSavedSearch>[0]) => Promise<{
22
+ success: true;
23
+ } | {
24
+ success: false;
25
+ error: unknown;
26
+ }>;
27
+ };
28
+ export {};
@@ -0,0 +1,178 @@
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
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
+ }
47
+ };
48
+ var __rest = (this && this.__rest) || function (s, e) {
49
+ var t = {};
50
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
51
+ t[p] = s[p];
52
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
53
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
54
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
55
+ t[p[i]] = s[p[i]];
56
+ }
57
+ return t;
58
+ };
59
+ import { createSavedSearch, deleteSavedSearch, getSavedSearches, getTotalsForQuery, isAbortError, promiseAllSettled, replacePlaceholdersInQuery, updateSavedSearch } from '@reltio/mdm-sdk';
60
+ import { assocPath, propEq } from 'ramda';
61
+ import { useCallback, useContext, useEffect, useState } from 'react';
62
+ import { PageRequestsAbortingContext } from '../contexts';
63
+ import { RequestStates } from '../types';
64
+ export var useSavedSearchesRequest = function (_a) {
65
+ var options = _a.options, offset = _a.offset, max = _a.max, queryEstimatorEnabled = _a.queryEstimatorEnabled;
66
+ var _b = useState([]), data = _b[0], setData = _b[1];
67
+ var _c = useState(0), total = _c[0], setTotal = _c[1];
68
+ var _d = useState(RequestStates.INIT), requestState = _d[0], setRequestState = _d[1];
69
+ var onError = function (error) {
70
+ console.warn(error); // eslint-disable-line
71
+ if (!isAbortError(error)) {
72
+ setRequestState(RequestStates.ERROR);
73
+ setData([]);
74
+ }
75
+ };
76
+ var signal = useContext(PageRequestsAbortingContext);
77
+ var loadData = useCallback(function () {
78
+ setRequestState(RequestStates.LOADING);
79
+ var onRequestFinished = function (data) {
80
+ setData(data.result || []);
81
+ setTotal(data.total);
82
+ setRequestState(RequestStates.LOADED);
83
+ };
84
+ var _a = (options || {}), countResults = _a.countResults, restOptions = __rest(_a, ["countResults"]);
85
+ var getData = function () { return __awaiter(void 0, void 0, void 0, function () {
86
+ var _a, _b, savedSearches, total, totalRequests, totalResults, searchesWithCount;
87
+ return __generator(this, function (_c) {
88
+ switch (_c.label) {
89
+ case 0: return [4 /*yield*/, getSavedSearches(__assign({ offset: offset, max: max }, restOptions), signal)];
90
+ case 1:
91
+ _a = _c.sent(), _b = _a.result, savedSearches = _b === void 0 ? [] : _b, total = _a.total;
92
+ if (!countResults) return [3 /*break*/, 3];
93
+ totalRequests = savedSearches.map(function (search) {
94
+ return getTotalsForQuery(replacePlaceholdersInQuery(search.query), queryEstimatorEnabled, signal);
95
+ });
96
+ return [4 /*yield*/, promiseAllSettled(totalRequests)];
97
+ case 2:
98
+ totalResults = _c.sent();
99
+ searchesWithCount = totalResults.reduce(function (searchesWithTotal, _a, searchIndex) {
100
+ var status = _a.status, value = _a.value, reason = _a.reason;
101
+ switch (status) {
102
+ case 'fulfilled':
103
+ return assocPath([searchIndex, 'count'], value.total, searchesWithTotal);
104
+ case 'rejected':
105
+ console.warn(reason);
106
+ break;
107
+ }
108
+ return searchesWithTotal;
109
+ }, savedSearches);
110
+ onRequestFinished({ result: searchesWithCount, total: total });
111
+ return [3 /*break*/, 4];
112
+ case 3:
113
+ onRequestFinished({ result: savedSearches, total: total });
114
+ _c.label = 4;
115
+ case 4: return [2 /*return*/];
116
+ }
117
+ });
118
+ }); };
119
+ getData().catch(onError);
120
+ }, [options, offset, max, signal, queryEstimatorEnabled]);
121
+ var refreshAction = function () {
122
+ try {
123
+ loadData();
124
+ }
125
+ catch (e) {
126
+ onError(e);
127
+ }
128
+ };
129
+ var loadTotalForUri = useCallback(function (uri) { return __awaiter(void 0, void 0, void 0, function () {
130
+ var searchIndex, search, total_1, e_1;
131
+ return __generator(this, function (_a) {
132
+ switch (_a.label) {
133
+ case 0:
134
+ searchIndex = data.findIndex(propEq('uri', uri));
135
+ search = data[searchIndex];
136
+ setData(assocPath([searchIndex, 'isLoadingTotal'], true));
137
+ _a.label = 1;
138
+ case 1:
139
+ _a.trys.push([1, 3, , 4]);
140
+ return [4 /*yield*/, getTotalsForQuery(replacePlaceholdersInQuery(search.query), false, signal)];
141
+ case 2:
142
+ total_1 = (_a.sent()).total;
143
+ setData(assocPath([searchIndex, 'count'], total_1));
144
+ return [3 /*break*/, 4];
145
+ case 3:
146
+ e_1 = _a.sent();
147
+ console.warn(e_1);
148
+ return [3 /*break*/, 4];
149
+ case 4:
150
+ setData(assocPath([searchIndex, 'isLoadingTotal'], false));
151
+ return [2 /*return*/];
152
+ }
153
+ });
154
+ }); }, [data, signal]);
155
+ var saveSearch = useCallback(function (savedSearch) {
156
+ var type = (options || {}).type;
157
+ return createSavedSearch([__assign(__assign({}, savedSearch), { type: type })]);
158
+ }, [options]);
159
+ var updateSearch = useCallback(function (savedSearch) {
160
+ return updateSavedSearch(savedSearch);
161
+ }, []);
162
+ var deleteSearch = useCallback(function (savedSearch) {
163
+ return deleteSavedSearch(savedSearch);
164
+ }, []);
165
+ useEffect(function () {
166
+ refreshAction();
167
+ }, [loadData]);
168
+ return {
169
+ state: requestState,
170
+ data: data,
171
+ reload: refreshAction,
172
+ total: total,
173
+ loadTotalForSearchByUri: loadTotalForUri,
174
+ saveSearch: saveSearch,
175
+ updateSearch: updateSearch,
176
+ deleteSearch: deleteSearch
177
+ };
178
+ };
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@reltio/components",
3
- "version": "1.4.1829",
3
+ "version": "1.4.1831",
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
  "@fluentui/react-context-selector": "^9.1.26",
9
9
  "@react-google-maps/api": "2.7.0",
10
- "@reltio/mdm-sdk": "^1.4.1788",
10
+ "@reltio/mdm-sdk": "^1.4.1790",
11
11
  "classnames": "^2.2.5",
12
12
  "d3-cloud": "^1.2.5",
13
13
  "d3-geo": "^2.0.1",