@reltio/components 1.4.1849 → 1.4.1850

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.
Files changed (41) hide show
  1. package/cjs/SaveSegmentDialog/SaveSegmentDialog.d.ts +8 -0
  2. package/cjs/SaveSegmentDialog/SaveSegmentDialog.js +129 -0
  3. package/cjs/SaveSegmentDialog/SaveSegmentDialog.test.d.ts +1 -0
  4. package/cjs/SaveSegmentDialog/SaveSegmentDialog.test.js +214 -0
  5. package/cjs/SaveSegmentDialog/index.d.ts +1 -0
  6. package/cjs/SaveSegmentDialog/index.js +5 -0
  7. package/cjs/SaveSegmentDialog/styles.d.ts +1 -0
  8. package/cjs/SaveSegmentDialog/styles.js +15 -0
  9. package/cjs/hooks/useSavedSearchesRequest/index.d.ts +1 -0
  10. package/cjs/hooks/useSavedSearchesRequest/index.js +5 -0
  11. package/cjs/hooks/useSavedSearchesRequest/requests.d.ts +6 -0
  12. package/cjs/hooks/useSavedSearchesRequest/requests.js +72 -0
  13. package/cjs/hooks/useSavedSearchesRequest/useSavedSearchesRequest.d.ts +76 -0
  14. package/cjs/hooks/useSavedSearchesRequest/useSavedSearchesRequest.js +255 -0
  15. package/cjs/hooks/useSavedSearchesRequest/useSavedSearchesRequest.test.d.ts +1 -0
  16. package/cjs/hooks/useSavedSearchesRequest/useSavedSearchesRequest.test.js +743 -0
  17. package/cjs/index.d.ts +1 -0
  18. package/cjs/index.js +3 -1
  19. package/esm/SaveSegmentDialog/SaveSegmentDialog.d.ts +8 -0
  20. package/esm/SaveSegmentDialog/SaveSegmentDialog.js +99 -0
  21. package/esm/SaveSegmentDialog/SaveSegmentDialog.test.d.ts +1 -0
  22. package/esm/SaveSegmentDialog/SaveSegmentDialog.test.js +209 -0
  23. package/esm/SaveSegmentDialog/index.d.ts +1 -0
  24. package/esm/SaveSegmentDialog/index.js +1 -0
  25. package/esm/SaveSegmentDialog/styles.d.ts +1 -0
  26. package/esm/SaveSegmentDialog/styles.js +12 -0
  27. package/esm/hooks/useSavedSearchesRequest/index.d.ts +1 -0
  28. package/esm/hooks/useSavedSearchesRequest/index.js +1 -0
  29. package/esm/hooks/useSavedSearchesRequest/requests.d.ts +6 -0
  30. package/esm/hooks/useSavedSearchesRequest/requests.js +68 -0
  31. package/esm/hooks/useSavedSearchesRequest/useSavedSearchesRequest.d.ts +76 -0
  32. package/esm/hooks/useSavedSearchesRequest/useSavedSearchesRequest.js +251 -0
  33. package/esm/hooks/useSavedSearchesRequest/useSavedSearchesRequest.test.d.ts +1 -0
  34. package/esm/hooks/useSavedSearchesRequest/useSavedSearchesRequest.test.js +738 -0
  35. package/esm/index.d.ts +1 -0
  36. package/esm/index.js +1 -0
  37. package/package.json +1 -1
  38. package/cjs/hooks/useSavedSearchesRequest.d.ts +0 -23
  39. package/cjs/hooks/useSavedSearchesRequest.js +0 -224
  40. package/esm/hooks/useSavedSearchesRequest.d.ts +0 -23
  41. package/esm/hooks/useSavedSearchesRequest.js +0 -220
@@ -0,0 +1,255 @@
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 core_1 = require("../../core");
68
+ var requests_1 = require("./requests");
69
+ var useSavedSearchesRequest = function (_a) {
70
+ var options = _a.options, defaultRowsPerPage = _a.defaultRowsPerPage, queryEstimatorEnabled = _a.queryEstimatorEnabled;
71
+ var _b = (0, react_1.useState)(0), page = _b[0], setPage = _b[1];
72
+ var _c = (0, react_1.useState)(defaultRowsPerPage), rowsPerPage = _c[0], setRowsPerPage = _c[1];
73
+ var _d = (0, react_1.useState)([]), data = _d[0], setData = _d[1];
74
+ var _e = (0, react_1.useState)(0), total = _e[0], setTotal = _e[1];
75
+ var _f = (0, react_1.useState)({}), profilesCountMap = _f[0], setProfilesCountMap = _f[1];
76
+ var _g = (0, react_1.useState)({
77
+ loading: types_1.RequestStates.INIT,
78
+ creating: types_1.RequestStates.INIT,
79
+ updating: types_1.RequestStates.INIT,
80
+ deleting: types_1.RequestStates.INIT
81
+ }), requestsStates = _g[0], setRequestsStates = _g[1];
82
+ var signal = (0, react_1.useContext)(contexts_1.PageRequestsAbortingContext);
83
+ var allOptions = (0, react_1.useMemo)(function () { return (__assign(__assign({}, options), { max: rowsPerPage, offset: rowsPerPage * page })); }, [options, page, rowsPerPage]);
84
+ var savedSearchesWithCount = (0, react_1.useMemo)(function () {
85
+ return data.map(function (savedSearch) {
86
+ var _a;
87
+ var _b = (_a = profilesCountMap[savedSearch.uri]) !== null && _a !== void 0 ? _a : {}, count = _b.count, isLoading = _b.isLoading;
88
+ var savedSearchWithCount = __assign({}, savedSearch);
89
+ if (!(0, ramda_1.isNil)(count))
90
+ savedSearchWithCount.count = count;
91
+ if (!(0, ramda_1.isNil)(isLoading))
92
+ savedSearchWithCount.isLoadingTotal = isLoading;
93
+ return savedSearchWithCount;
94
+ });
95
+ }, [data, profilesCountMap]);
96
+ var updateRequestState = (0, react_1.useCallback)(function (type, state) {
97
+ setRequestsStates(function (prevRequestsStates) {
98
+ var _a;
99
+ return (__assign(__assign({}, prevRequestsStates), (_a = {}, _a[type] = state, _a)));
100
+ });
101
+ }, []);
102
+ var loadSavedSearches = (0, react_1.useCallback)(function () { return __awaiter(void 0, void 0, void 0, function () {
103
+ var countResults, restOptions, _a, _b, savedSearches, total_1, totals, error_1;
104
+ return __generator(this, function (_c) {
105
+ switch (_c.label) {
106
+ case 0:
107
+ updateRequestState('loading', types_1.RequestStates.LOADING);
108
+ _c.label = 1;
109
+ case 1:
110
+ _c.trys.push([1, 5, , 6]);
111
+ countResults = allOptions.countResults, restOptions = __rest(allOptions, ["countResults"]);
112
+ return [4 /*yield*/, (0, mdm_sdk_1.getSavedSearches)(restOptions, signal)];
113
+ case 2:
114
+ _a = _c.sent(), _b = _a.result, savedSearches = _b === void 0 ? [] : _b, total_1 = _a.total;
115
+ if (!countResults) return [3 /*break*/, 4];
116
+ return [4 /*yield*/, (0, requests_1.getTotalsForSavedSearches)(savedSearches, queryEstimatorEnabled, signal)];
117
+ case 3:
118
+ totals = _c.sent();
119
+ setProfilesCountMap(totals);
120
+ _c.label = 4;
121
+ case 4:
122
+ setData(savedSearches || []);
123
+ setTotal(total_1);
124
+ updateRequestState('loading', types_1.RequestStates.LOADED);
125
+ return [3 /*break*/, 6];
126
+ case 5:
127
+ error_1 = _c.sent();
128
+ console.warn(error_1); // eslint-disable-line
129
+ if (!(0, mdm_sdk_1.isAbortError)(error_1)) {
130
+ updateRequestState('loading', types_1.RequestStates.ERROR);
131
+ setData([]);
132
+ }
133
+ return [3 /*break*/, 6];
134
+ case 6: return [2 /*return*/];
135
+ }
136
+ });
137
+ }); }, [allOptions, signal, queryEstimatorEnabled, updateRequestState]);
138
+ var loadTotalForUri = (0, react_1.useCallback)(function (uri) { return __awaiter(void 0, void 0, void 0, function () {
139
+ var savedSearch, total_2, e_1;
140
+ return __generator(this, function (_a) {
141
+ switch (_a.label) {
142
+ case 0:
143
+ savedSearch = data.find((0, ramda_1.propEq)('uri', uri));
144
+ setProfilesCountMap((0, ramda_1.assocPath)([uri, 'isLoading'], true));
145
+ _a.label = 1;
146
+ case 1:
147
+ _a.trys.push([1, 3, 4, 5]);
148
+ return [4 /*yield*/, (0, mdm_sdk_1.getTotalsForQuery)((0, mdm_sdk_1.replacePlaceholdersInQuery)(savedSearch.query), false, signal)];
149
+ case 2:
150
+ total_2 = (_a.sent()).total;
151
+ setProfilesCountMap((0, ramda_1.assocPath)([uri, 'count'], total_2));
152
+ return [3 /*break*/, 5];
153
+ case 3:
154
+ e_1 = _a.sent();
155
+ console.warn(e_1);
156
+ return [3 /*break*/, 5];
157
+ case 4:
158
+ setProfilesCountMap((0, ramda_1.assocPath)([uri, 'isLoading'], false));
159
+ return [7 /*endfinally*/];
160
+ case 5: return [2 /*return*/];
161
+ }
162
+ });
163
+ }); }, [data, signal]);
164
+ var createSearch = (0, react_1.useCallback)(function (savedSearch) { return __awaiter(void 0, void 0, void 0, function () {
165
+ var type, result, error_2;
166
+ return __generator(this, function (_a) {
167
+ switch (_a.label) {
168
+ case 0:
169
+ updateRequestState('creating', types_1.RequestStates.LOADING);
170
+ _a.label = 1;
171
+ case 1:
172
+ _a.trys.push([1, 3, , 4]);
173
+ type = allOptions.type;
174
+ return [4 /*yield*/, (0, mdm_sdk_1.createSavedSearch)([__assign(__assign({}, savedSearch), { type: type })])];
175
+ case 2:
176
+ result = _a.sent();
177
+ page === 0 ? loadSavedSearches() : setPage(0);
178
+ updateRequestState('creating', types_1.RequestStates.LOADED);
179
+ return [2 /*return*/, { success: true, result: result }];
180
+ case 3:
181
+ error_2 = _a.sent();
182
+ (0, core_1.showDefaultErrorMessage)(error_2);
183
+ updateRequestState('creating', types_1.RequestStates.ERROR);
184
+ return [2 /*return*/, { success: false, error: error_2 }];
185
+ case 4: return [2 /*return*/];
186
+ }
187
+ });
188
+ }); }, [allOptions, page, updateRequestState, loadSavedSearches]);
189
+ var updateSearch = (0, react_1.useCallback)(function (savedSearch) { return __awaiter(void 0, void 0, void 0, function () {
190
+ var result, error_3;
191
+ return __generator(this, function (_a) {
192
+ switch (_a.label) {
193
+ case 0:
194
+ updateRequestState('updating', types_1.RequestStates.LOADING);
195
+ _a.label = 1;
196
+ case 1:
197
+ _a.trys.push([1, 3, , 4]);
198
+ return [4 /*yield*/, (0, mdm_sdk_1.updateSavedSearch)(savedSearch)];
199
+ case 2:
200
+ result = _a.sent();
201
+ setData(function (prevData) { return prevData.map(function (item) { return (item.uri === savedSearch.uri ? savedSearch : item); }); });
202
+ updateRequestState('updating', types_1.RequestStates.LOADED);
203
+ return [2 /*return*/, { success: true, result: result }];
204
+ case 3:
205
+ error_3 = _a.sent();
206
+ (0, core_1.showDefaultErrorMessage)(error_3);
207
+ updateRequestState('updating', types_1.RequestStates.ERROR);
208
+ return [2 /*return*/, { success: false, error: error_3 }];
209
+ case 4: return [2 /*return*/];
210
+ }
211
+ });
212
+ }); }, [updateRequestState]);
213
+ var deleteSearch = (0, react_1.useCallback)(function (uri) { return __awaiter(void 0, void 0, void 0, function () {
214
+ var result, error_4;
215
+ return __generator(this, function (_a) {
216
+ switch (_a.label) {
217
+ case 0:
218
+ updateRequestState('deleting', types_1.RequestStates.LOADING);
219
+ _a.label = 1;
220
+ case 1:
221
+ _a.trys.push([1, 3, , 4]);
222
+ return [4 /*yield*/, (0, mdm_sdk_1.deleteSavedSearch)({ uri: uri })];
223
+ case 2:
224
+ result = _a.sent();
225
+ loadSavedSearches();
226
+ updateRequestState('deleting', types_1.RequestStates.LOADED);
227
+ return [2 /*return*/, { success: true, result: result }];
228
+ case 3:
229
+ error_4 = _a.sent();
230
+ (0, core_1.showDefaultErrorMessage)(error_4);
231
+ updateRequestState('deleting', types_1.RequestStates.ERROR);
232
+ return [2 /*return*/, { success: false, error: error_4 }];
233
+ case 4: return [2 /*return*/];
234
+ }
235
+ });
236
+ }); }, [updateRequestState, loadSavedSearches]);
237
+ (0, react_1.useEffect)(function () {
238
+ loadSavedSearches();
239
+ }, [loadSavedSearches]);
240
+ return {
241
+ states: requestsStates,
242
+ data: savedSearchesWithCount,
243
+ total: total,
244
+ page: page,
245
+ rowsPerPage: rowsPerPage,
246
+ updatePage: setPage,
247
+ updateRowsPerPage: setRowsPerPage,
248
+ reload: loadSavedSearches,
249
+ loadTotalForSearchByUri: loadTotalForUri,
250
+ createSearch: createSearch,
251
+ updateSearch: updateSearch,
252
+ deleteSearch: deleteSearch
253
+ };
254
+ };
255
+ exports.useSavedSearchesRequest = useSavedSearchesRequest;