@reltio/components 1.4.1848 → 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.
- package/cjs/SaveSegmentDialog/SaveSegmentDialog.d.ts +8 -0
- package/cjs/SaveSegmentDialog/SaveSegmentDialog.js +129 -0
- package/cjs/SaveSegmentDialog/SaveSegmentDialog.test.d.ts +1 -0
- package/cjs/SaveSegmentDialog/SaveSegmentDialog.test.js +214 -0
- package/cjs/SaveSegmentDialog/index.d.ts +1 -0
- package/cjs/SaveSegmentDialog/index.js +5 -0
- package/cjs/SaveSegmentDialog/styles.d.ts +1 -0
- package/cjs/SaveSegmentDialog/styles.js +15 -0
- package/cjs/features/graph/DataModelGraph/DataModelGraph.d.ts +2 -1
- package/cjs/features/graph/DataModelGraph/DataModelGraph.js +2 -2
- package/cjs/features/graph/DataModelGraph/DataModelGraph.test.js +1 -1
- package/cjs/features/graph/DataModelGraph/components/DataModelCircleLayout/DataModelCircleLayuot.d.ts +2 -1
- package/cjs/features/graph/DataModelGraph/components/DataModelCircleLayout/DataModelCircleLayuot.js +3 -2
- package/cjs/features/graph/DataModelGraph/hooks/useDataModelGraphAppearance.d.ts +2 -1
- package/cjs/features/graph/DataModelGraph/hooks/useDataModelGraphAppearance.js +5 -2
- package/cjs/features/graph/DataModelGraph/hooks/useDataModelGraphAppearance.test.js +7 -1
- package/cjs/hooks/useSavedSearchesRequest/index.d.ts +1 -0
- package/cjs/hooks/useSavedSearchesRequest/index.js +5 -0
- package/cjs/hooks/useSavedSearchesRequest/requests.d.ts +6 -0
- package/cjs/hooks/useSavedSearchesRequest/requests.js +72 -0
- package/cjs/hooks/useSavedSearchesRequest/useSavedSearchesRequest.d.ts +76 -0
- package/cjs/hooks/useSavedSearchesRequest/useSavedSearchesRequest.js +255 -0
- package/cjs/hooks/useSavedSearchesRequest/useSavedSearchesRequest.test.d.ts +1 -0
- package/cjs/hooks/useSavedSearchesRequest/useSavedSearchesRequest.test.js +743 -0
- package/cjs/index.d.ts +1 -0
- package/cjs/index.js +3 -1
- package/esm/SaveSegmentDialog/SaveSegmentDialog.d.ts +8 -0
- package/esm/SaveSegmentDialog/SaveSegmentDialog.js +99 -0
- package/esm/SaveSegmentDialog/SaveSegmentDialog.test.d.ts +1 -0
- package/esm/SaveSegmentDialog/SaveSegmentDialog.test.js +209 -0
- package/esm/SaveSegmentDialog/index.d.ts +1 -0
- package/esm/SaveSegmentDialog/index.js +1 -0
- package/esm/SaveSegmentDialog/styles.d.ts +1 -0
- package/esm/SaveSegmentDialog/styles.js +12 -0
- package/esm/features/graph/DataModelGraph/DataModelGraph.d.ts +2 -1
- package/esm/features/graph/DataModelGraph/DataModelGraph.js +2 -2
- package/esm/features/graph/DataModelGraph/DataModelGraph.test.js +1 -1
- package/esm/features/graph/DataModelGraph/components/DataModelCircleLayout/DataModelCircleLayuot.d.ts +2 -1
- package/esm/features/graph/DataModelGraph/components/DataModelCircleLayout/DataModelCircleLayuot.js +3 -2
- package/esm/features/graph/DataModelGraph/hooks/useDataModelGraphAppearance.d.ts +2 -1
- package/esm/features/graph/DataModelGraph/hooks/useDataModelGraphAppearance.js +5 -2
- package/esm/features/graph/DataModelGraph/hooks/useDataModelGraphAppearance.test.js +7 -1
- package/esm/hooks/useSavedSearchesRequest/index.d.ts +1 -0
- package/esm/hooks/useSavedSearchesRequest/index.js +1 -0
- package/esm/hooks/useSavedSearchesRequest/requests.d.ts +6 -0
- package/esm/hooks/useSavedSearchesRequest/requests.js +68 -0
- package/esm/hooks/useSavedSearchesRequest/useSavedSearchesRequest.d.ts +76 -0
- package/esm/hooks/useSavedSearchesRequest/useSavedSearchesRequest.js +251 -0
- package/esm/hooks/useSavedSearchesRequest/useSavedSearchesRequest.test.d.ts +1 -0
- package/esm/hooks/useSavedSearchesRequest/useSavedSearchesRequest.test.js +738 -0
- package/esm/index.d.ts +1 -0
- package/esm/index.js +1 -0
- package/package.json +1 -1
- package/cjs/hooks/useSavedSearchesRequest.d.ts +0 -23
- package/cjs/hooks/useSavedSearchesRequest.js +0 -224
- package/esm/hooks/useSavedSearchesRequest.d.ts +0 -23
- package/esm/hooks/useSavedSearchesRequest.js +0 -220
package/esm/index.d.ts
CHANGED
|
@@ -110,6 +110,7 @@ export { FilterValueEditor } from './FilterValueEditor';
|
|
|
110
110
|
export { DropDownEditor } from './DropDownEditor';
|
|
111
111
|
export { EmptySearchResult } from './EmptySearchResult';
|
|
112
112
|
export { FileTypeEditor } from './FileTypeEditor';
|
|
113
|
+
export { SaveSegmentDialog } from './SaveSegmentDialog';
|
|
113
114
|
export { withChartDataPercents as withPercents } from './HOCs/withChartDataPercents';
|
|
114
115
|
export { withFilterAtBottom } from './HOCs/withFilterAtBottom';
|
|
115
116
|
export { withTableContext } from './HOCs/withTableContext';
|
package/esm/index.js
CHANGED
|
@@ -111,6 +111,7 @@ export { FilterValueEditor } from './FilterValueEditor';
|
|
|
111
111
|
export { DropDownEditor } from './DropDownEditor';
|
|
112
112
|
export { EmptySearchResult } from './EmptySearchResult';
|
|
113
113
|
export { FileTypeEditor } from './FileTypeEditor';
|
|
114
|
+
export { SaveSegmentDialog } from './SaveSegmentDialog';
|
|
114
115
|
// HOCs
|
|
115
116
|
export { withChartDataPercents as withPercents } from './HOCs/withChartDataPercents';
|
|
116
117
|
export { withFilterAtBottom } from './HOCs/withFilterAtBottom';
|
package/package.json
CHANGED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { SavedSearchData, SavedSearchesOptions } 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: SavedSearchData) => Promise<void>;
|
|
21
|
-
deleteSearch: (uri: string) => Promise<void>;
|
|
22
|
-
};
|
|
23
|
-
export {};
|
|
@@ -1,224 +0,0 @@
|
|
|
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) { return __awaiter(void 0, void 0, void 0, function () {
|
|
163
|
-
var e_2;
|
|
164
|
-
return __generator(this, function (_a) {
|
|
165
|
-
switch (_a.label) {
|
|
166
|
-
case 0:
|
|
167
|
-
setRequestState(types_1.RequestStates.LOADING);
|
|
168
|
-
_a.label = 1;
|
|
169
|
-
case 1:
|
|
170
|
-
_a.trys.push([1, 3, , 4]);
|
|
171
|
-
return [4 /*yield*/, (0, mdm_sdk_1.updateSavedSearch)(savedSearch)];
|
|
172
|
-
case 2:
|
|
173
|
-
_a.sent();
|
|
174
|
-
setData(function (prevData) { return prevData.map(function (item) { return (item.uri === savedSearch.uri ? savedSearch : item); }); });
|
|
175
|
-
setRequestState(types_1.RequestStates.LOADED);
|
|
176
|
-
return [3 /*break*/, 4];
|
|
177
|
-
case 3:
|
|
178
|
-
e_2 = _a.sent();
|
|
179
|
-
console.warn(e_2);
|
|
180
|
-
setRequestState(types_1.RequestStates.ERROR);
|
|
181
|
-
return [3 /*break*/, 4];
|
|
182
|
-
case 4: return [2 /*return*/];
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
}); }, []);
|
|
186
|
-
var deleteSearch = (0, react_1.useCallback)(function (uri) { return __awaiter(void 0, void 0, void 0, function () {
|
|
187
|
-
var e_3;
|
|
188
|
-
return __generator(this, function (_a) {
|
|
189
|
-
switch (_a.label) {
|
|
190
|
-
case 0:
|
|
191
|
-
setRequestState(types_1.RequestStates.LOADING);
|
|
192
|
-
_a.label = 1;
|
|
193
|
-
case 1:
|
|
194
|
-
_a.trys.push([1, 3, , 4]);
|
|
195
|
-
return [4 /*yield*/, (0, mdm_sdk_1.deleteSavedSearch)({ uri: uri })];
|
|
196
|
-
case 2:
|
|
197
|
-
_a.sent();
|
|
198
|
-
setData(function (prevData) { return prevData.filter(function (item) { return item.uri !== uri; }); });
|
|
199
|
-
setRequestState(types_1.RequestStates.LOADED);
|
|
200
|
-
return [3 /*break*/, 4];
|
|
201
|
-
case 3:
|
|
202
|
-
e_3 = _a.sent();
|
|
203
|
-
console.warn(e_3);
|
|
204
|
-
setRequestState(types_1.RequestStates.ERROR);
|
|
205
|
-
return [3 /*break*/, 4];
|
|
206
|
-
case 4: return [2 /*return*/];
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
|
-
}); }, []);
|
|
210
|
-
(0, react_1.useEffect)(function () {
|
|
211
|
-
refreshAction();
|
|
212
|
-
}, [loadData]);
|
|
213
|
-
return {
|
|
214
|
-
state: requestState,
|
|
215
|
-
data: data,
|
|
216
|
-
reload: refreshAction,
|
|
217
|
-
total: total,
|
|
218
|
-
loadTotalForSearchByUri: loadTotalForUri,
|
|
219
|
-
saveSearch: saveSearch,
|
|
220
|
-
updateSearch: updateSearch,
|
|
221
|
-
deleteSearch: deleteSearch
|
|
222
|
-
};
|
|
223
|
-
};
|
|
224
|
-
exports.useSavedSearchesRequest = useSavedSearchesRequest;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { SavedSearchData, SavedSearchesOptions } 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: SavedSearchData) => Promise<void>;
|
|
21
|
-
deleteSearch: (uri: string) => Promise<void>;
|
|
22
|
-
};
|
|
23
|
-
export {};
|
|
@@ -1,220 +0,0 @@
|
|
|
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) { return __awaiter(void 0, void 0, void 0, function () {
|
|
160
|
-
var e_2;
|
|
161
|
-
return __generator(this, function (_a) {
|
|
162
|
-
switch (_a.label) {
|
|
163
|
-
case 0:
|
|
164
|
-
setRequestState(RequestStates.LOADING);
|
|
165
|
-
_a.label = 1;
|
|
166
|
-
case 1:
|
|
167
|
-
_a.trys.push([1, 3, , 4]);
|
|
168
|
-
return [4 /*yield*/, updateSavedSearch(savedSearch)];
|
|
169
|
-
case 2:
|
|
170
|
-
_a.sent();
|
|
171
|
-
setData(function (prevData) { return prevData.map(function (item) { return (item.uri === savedSearch.uri ? savedSearch : item); }); });
|
|
172
|
-
setRequestState(RequestStates.LOADED);
|
|
173
|
-
return [3 /*break*/, 4];
|
|
174
|
-
case 3:
|
|
175
|
-
e_2 = _a.sent();
|
|
176
|
-
console.warn(e_2);
|
|
177
|
-
setRequestState(RequestStates.ERROR);
|
|
178
|
-
return [3 /*break*/, 4];
|
|
179
|
-
case 4: return [2 /*return*/];
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
}); }, []);
|
|
183
|
-
var deleteSearch = useCallback(function (uri) { return __awaiter(void 0, void 0, void 0, function () {
|
|
184
|
-
var e_3;
|
|
185
|
-
return __generator(this, function (_a) {
|
|
186
|
-
switch (_a.label) {
|
|
187
|
-
case 0:
|
|
188
|
-
setRequestState(RequestStates.LOADING);
|
|
189
|
-
_a.label = 1;
|
|
190
|
-
case 1:
|
|
191
|
-
_a.trys.push([1, 3, , 4]);
|
|
192
|
-
return [4 /*yield*/, deleteSavedSearch({ uri: uri })];
|
|
193
|
-
case 2:
|
|
194
|
-
_a.sent();
|
|
195
|
-
setData(function (prevData) { return prevData.filter(function (item) { return item.uri !== uri; }); });
|
|
196
|
-
setRequestState(RequestStates.LOADED);
|
|
197
|
-
return [3 /*break*/, 4];
|
|
198
|
-
case 3:
|
|
199
|
-
e_3 = _a.sent();
|
|
200
|
-
console.warn(e_3);
|
|
201
|
-
setRequestState(RequestStates.ERROR);
|
|
202
|
-
return [3 /*break*/, 4];
|
|
203
|
-
case 4: return [2 /*return*/];
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
|
-
}); }, []);
|
|
207
|
-
useEffect(function () {
|
|
208
|
-
refreshAction();
|
|
209
|
-
}, [loadData]);
|
|
210
|
-
return {
|
|
211
|
-
state: requestState,
|
|
212
|
-
data: data,
|
|
213
|
-
reload: refreshAction,
|
|
214
|
-
total: total,
|
|
215
|
-
loadTotalForSearchByUri: loadTotalForUri,
|
|
216
|
-
saveSearch: saveSearch,
|
|
217
|
-
updateSearch: updateSearch,
|
|
218
|
-
deleteSearch: deleteSearch
|
|
219
|
-
};
|
|
220
|
-
};
|