blixify-ui-web 1.2.183 → 1.2.185
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/lib/components/chart/pieChart/index.d.ts +1 -0
- package/lib/components/chart/pieChart/index.d.ts.map +1 -1
- package/lib/components/chart/pieChart/index.js +7 -0
- package/lib/components/chart/pieChart/index.js.map +1 -1
- package/lib/components/data/dataGraph/chartErrorBoundary.d.ts +28 -0
- package/lib/components/data/dataGraph/chartErrorBoundary.d.ts.map +1 -0
- package/lib/components/data/dataGraph/chartErrorBoundary.js +50 -0
- package/lib/components/data/dataGraph/chartErrorBoundary.js.map +1 -0
- package/lib/components/data/dataGraph/chartErrors.d.ts +28 -0
- package/lib/components/data/dataGraph/chartErrors.d.ts.map +1 -0
- package/lib/components/data/dataGraph/chartErrors.js +116 -0
- package/lib/components/data/dataGraph/chartErrors.js.map +1 -0
- package/lib/components/data/dataGraph/chartResults.d.ts +81 -0
- package/lib/components/data/dataGraph/chartResults.d.ts.map +1 -0
- package/lib/components/data/dataGraph/chartResults.js +200 -0
- package/lib/components/data/dataGraph/chartResults.js.map +1 -0
- package/lib/components/data/dataGraph/index.d.ts +16 -0
- package/lib/components/data/dataGraph/index.d.ts.map +1 -1
- package/lib/components/data/dataGraph/index.js +788 -324
- package/lib/components/data/dataGraph/index.js.map +1 -1
- package/lib/components/data/dataTemplate/chartBuilder.d.ts +47 -0
- package/lib/components/data/dataTemplate/chartBuilder.d.ts.map +1 -0
- package/lib/components/data/dataTemplate/chartBuilder.js +234 -0
- package/lib/components/data/dataTemplate/chartBuilder.js.map +1 -0
- package/lib/components/data/dataTemplate/chartView.d.ts.map +1 -1
- package/lib/components/data/dataTemplate/chartView.js +243 -64
- package/lib/components/data/dataTemplate/chartView.js.map +1 -1
- package/lib/components/data/dataTemplate/index.d.ts.map +1 -1
- package/lib/components/data/dataTemplate/index.js +148 -133
- package/lib/components/data/dataTemplate/index.js.map +1 -1
- package/lib/components/data/dataTemplate/spaceModel.d.ts +9 -0
- package/lib/components/data/dataTemplate/spaceModel.d.ts.map +1 -1
- package/lib/components/display/drawer/index.d.ts +1 -0
- package/lib/components/display/drawer/index.d.ts.map +1 -1
- package/lib/components/display/drawer/index.js +10 -2
- package/lib/components/display/drawer/index.js.map +1 -1
- package/lib/components/display/newTable/index.d.ts.map +1 -1
- package/lib/components/display/newTable/index.js +80 -23
- package/lib/components/display/newTable/index.js.map +1 -1
- package/lib/tail.css +1 -1
- package/package.json +1 -1
|
@@ -82,6 +82,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
82
82
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
83
83
|
};
|
|
84
84
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
85
|
+
exports.handleIsShapedChart = void 0;
|
|
85
86
|
exports.DataGraph = DataGraph;
|
|
86
87
|
var solid_1 = require("@heroicons/react/24/solid");
|
|
87
88
|
var axios_1 = __importDefault(require("axios"));
|
|
@@ -93,19 +94,50 @@ var card_1 = require("../../chart/card");
|
|
|
93
94
|
var lineChart_1 = require("../../chart/lineChart");
|
|
94
95
|
var pieChart_1 = require("../../chart/pieChart");
|
|
95
96
|
var radarChart_1 = require("../../chart/radarChart");
|
|
97
|
+
var textButton_1 = require("../../action/textButton");
|
|
96
98
|
var loading_1 = require("../../display/loading");
|
|
97
|
-
var tag_1 = require("../../display/tag");
|
|
98
99
|
var select_1 = require("../../input/select");
|
|
99
100
|
var readQuery_1 = require("../readQuery");
|
|
100
101
|
var stories_1 = require("../stories");
|
|
101
102
|
var utils_1 = require("../utils");
|
|
102
103
|
var allIcons = __importStar(require("@heroicons/react/24/solid"));
|
|
104
|
+
var chartErrorBoundary_1 = require("./chartErrorBoundary");
|
|
105
|
+
var chartErrors_1 = require("./chartErrors");
|
|
106
|
+
var chartResults_1 = require("./chartResults");
|
|
107
|
+
var MAX_SEGMENTS = 10;
|
|
108
|
+
var DEFAULT_INTERVAL_SPAN = {
|
|
109
|
+
day: [30, "day"],
|
|
110
|
+
week: [12, "week"],
|
|
111
|
+
month: [12, "month"],
|
|
112
|
+
};
|
|
113
|
+
// INFO: written out so Tailwind keeps every width in a consumer's CSS build
|
|
114
|
+
var GRID_SPAN_CLASS = {
|
|
115
|
+
1: "col-span-1",
|
|
116
|
+
2: "col-span-2",
|
|
117
|
+
3: "col-span-3",
|
|
118
|
+
4: "col-span-4",
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* A chart drawn from new-style options — group by any column, date buckets,
|
|
122
|
+
* segments — rather than one query per list value.
|
|
123
|
+
*/
|
|
124
|
+
var handleIsShapedChart = function (chart) {
|
|
125
|
+
return chart.type !== "radar" &&
|
|
126
|
+
!!(chart.groupBy || chart.queryDateInterval || chart.segmentBy);
|
|
127
|
+
};
|
|
128
|
+
exports.handleIsShapedChart = handleIsShapedChart;
|
|
103
129
|
function DataGraph(props) {
|
|
104
130
|
var _this = this;
|
|
105
131
|
var _a = (0, react_1.useState)({}), graphAnalyticsData = _a[0], setGraphAnalyticsData = _a[1];
|
|
106
132
|
var _b = (0, react_1.useState)({}), graphAnalyticsFilter = _b[0], setGraphAnalyticsFilter = _b[1];
|
|
107
133
|
var _c = (0, react_1.useState)({}), graphAnalyticsError = _c[0], setGraphAnalyticsError = _c[1];
|
|
134
|
+
var _d = (0, react_1.useState)({}), graphSeries = _d[0], setGraphSeries = _d[1];
|
|
135
|
+
var _e = (0, react_1.useState)({}), retryCount = _e[0], setRetryCount = _e[1];
|
|
136
|
+
var _f = (0, react_1.useState)({}), detailsOpen = _f[0], setDetailsOpen = _f[1];
|
|
108
137
|
var oldGraphAnalyticsFilterRef = (0, react_1.useRef)({});
|
|
138
|
+
// INFO: the latest load of each chart; an older answer arriving after a
|
|
139
|
+
// newer one is dropped, so the builder preview never shows past settings
|
|
140
|
+
var loadSequenceRef = (0, react_1.useRef)({});
|
|
109
141
|
var oldChartListRef = (0, react_1.useRef)([]);
|
|
110
142
|
var SpaceRQ = function (server, collection, api, apiToken, userToken) {
|
|
111
143
|
return new readQuery_1.ReadQuery({
|
|
@@ -132,74 +164,21 @@ function DataGraph(props) {
|
|
|
132
164
|
if (graphAnalyticsDataChangedKey) {
|
|
133
165
|
var selectedChart = props.charts.find(function (eachCharts) { return eachCharts.title === graphAnalyticsDataChangedKey; });
|
|
134
166
|
var handleGetUpdatedGraph = function (selectedChart) { return __awaiter(_this, void 0, void 0, function () {
|
|
135
|
-
var
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
switch (_b.label) {
|
|
167
|
+
var clonedGraphAnalyticsFilter;
|
|
168
|
+
return __generator(this, function (_a) {
|
|
169
|
+
switch (_a.label) {
|
|
139
170
|
case 0:
|
|
140
|
-
if (!selectedChart) return [3 /*break*/,
|
|
141
|
-
|
|
142
|
-
clonedGraphAnalyticsError_1 = JSON.parse(JSON.stringify(graphAnalyticsError));
|
|
143
|
-
if (!(selectedChart.type !== "radar")) return [3 /*break*/, 2];
|
|
144
|
-
return [4 /*yield*/, handleReadGraphDetail(selectedChart)];
|
|
171
|
+
if (!selectedChart) return [3 /*break*/, 2];
|
|
172
|
+
return [4 /*yield*/, handleLoadChart(selectedChart, graphAnalyticsFilter)];
|
|
145
173
|
case 1:
|
|
146
|
-
_a
|
|
147
|
-
clonedGraphAnalyticsData[selectedChart.title] = data;
|
|
148
|
-
clonedGraphAnalyticsError_1[selectedChart.title] = error;
|
|
149
|
-
return [3 /*break*/, 4];
|
|
150
|
-
case 2:
|
|
151
|
-
if (!selectedChart.queryAttributeId) return [3 /*break*/, 4];
|
|
152
|
-
radarAttributeIdKeys_1 = {};
|
|
153
|
-
localData_1 = [];
|
|
154
|
-
selectedChart.query.map(function (eachQuery) {
|
|
155
|
-
localData_1.push({
|
|
156
|
-
id: eachQuery.value,
|
|
157
|
-
value: [],
|
|
158
|
-
});
|
|
159
|
-
return null;
|
|
160
|
-
});
|
|
161
|
-
return [4 /*yield*/, Promise.all(selectedChart.queryAttributeId.map(function (eachAttribute) { return __awaiter(_this, void 0, void 0, function () {
|
|
162
|
-
var _a, data, error;
|
|
163
|
-
return __generator(this, function (_b) {
|
|
164
|
-
switch (_b.label) {
|
|
165
|
-
case 0: return [4 /*yield*/, handleReadGraphDetail(selectedChart, eachAttribute)];
|
|
166
|
-
case 1:
|
|
167
|
-
_a = _b.sent(), data = _a.data, error = _a.error;
|
|
168
|
-
data.map(function (eachData) {
|
|
169
|
-
if (!radarAttributeIdKeys_1[eachAttribute])
|
|
170
|
-
radarAttributeIdKeys_1[eachAttribute] = [];
|
|
171
|
-
radarAttributeIdKeys_1[eachAttribute].push(eachData.value);
|
|
172
|
-
return null;
|
|
173
|
-
});
|
|
174
|
-
clonedGraphAnalyticsError_1[selectedChart.title] = error;
|
|
175
|
-
return [2 /*return*/];
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
}); }))];
|
|
179
|
-
case 3:
|
|
180
|
-
_b.sent();
|
|
181
|
-
selectedChart.queryAttributeId.map(function (eachAttribute) {
|
|
182
|
-
if (radarAttributeIdKeys_1[eachAttribute] &&
|
|
183
|
-
radarAttributeIdKeys_1[eachAttribute].length > 0) {
|
|
184
|
-
radarAttributeIdKeys_1[eachAttribute].map(function (value, index) {
|
|
185
|
-
localData_1[index].value.push(value);
|
|
186
|
-
return null;
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
return null;
|
|
190
|
-
});
|
|
191
|
-
clonedGraphAnalyticsData[selectedChart.title] = localData_1;
|
|
192
|
-
_b.label = 4;
|
|
193
|
-
case 4:
|
|
194
|
-
setGraphAnalyticsData(clonedGraphAnalyticsData);
|
|
195
|
-
setGraphAnalyticsError(clonedGraphAnalyticsError_1);
|
|
174
|
+
_a.sent();
|
|
196
175
|
clonedGraphAnalyticsFilter = handleCloneGraphAnalyticsFilter();
|
|
197
176
|
clonedGraphAnalyticsFilter[graphAnalyticsDataChangedKey].loading =
|
|
198
177
|
false;
|
|
199
178
|
oldGraphAnalyticsFilterRef.current = graphAnalyticsFilter;
|
|
200
179
|
setGraphAnalyticsFilter(clonedGraphAnalyticsFilter);
|
|
201
|
-
|
|
202
|
-
case
|
|
180
|
+
_a.label = 2;
|
|
181
|
+
case 2: return [2 /*return*/];
|
|
203
182
|
}
|
|
204
183
|
});
|
|
205
184
|
}); };
|
|
@@ -258,18 +237,26 @@ function DataGraph(props) {
|
|
|
258
237
|
}
|
|
259
238
|
return splitDateTimes;
|
|
260
239
|
};
|
|
261
|
-
var
|
|
240
|
+
var handleResolveRange = function (eachChart, dateRange) {
|
|
262
241
|
var _a, _b, _c, _d, _e;
|
|
263
|
-
var
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
var
|
|
242
|
+
var span = eachChart.queryDateInterval
|
|
243
|
+
? DEFAULT_INTERVAL_SPAN[eachChart.queryDateInterval]
|
|
244
|
+
: undefined;
|
|
245
|
+
var startDate = (_a = dateRange === null || dateRange === void 0 ? void 0 : dateRange.startDate) !== null && _a !== void 0 ? _a : (span
|
|
246
|
+
? (0, dayjs_1.default)().subtract(span[0] - 1, span[1]).startOf(span[1]).toDate()
|
|
247
|
+
: (0, dayjs_1.default)().subtract(7, "days").toDate());
|
|
248
|
+
return {
|
|
267
249
|
startDate: startDate,
|
|
268
|
-
endDate: endDate,
|
|
250
|
+
endDate: (_b = dateRange === null || dateRange === void 0 ? void 0 : dateRange.endDate) !== null && _b !== void 0 ? _b : (0, dayjs_1.default)().toDate(),
|
|
269
251
|
startTime: (_c = dateRange === null || dateRange === void 0 ? void 0 : dateRange.startTime) !== null && _c !== void 0 ? _c : "00:00:00",
|
|
270
252
|
endTime: (_d = dateRange === null || dateRange === void 0 ? void 0 : dateRange.endTime) !== null && _d !== void 0 ? _d : "23:59:59",
|
|
271
253
|
isDuration: ((_e = dateRange === null || dateRange === void 0 ? void 0 : dateRange.isDuration) !== null && _e !== void 0 ? _e : eachChart.queryBaseDateId) ? true : false,
|
|
272
254
|
};
|
|
255
|
+
};
|
|
256
|
+
var handleSetGraphDateRange = function (eachChart, dateRange) {
|
|
257
|
+
var range = [];
|
|
258
|
+
var customRange = handleResolveRange(eachChart, dateRange);
|
|
259
|
+
var startDate = customRange.startDate, endDate = customRange.endDate;
|
|
273
260
|
switch (eachChart.type) {
|
|
274
261
|
case "pie":
|
|
275
262
|
case "bar":
|
|
@@ -297,29 +284,60 @@ function DataGraph(props) {
|
|
|
297
284
|
}
|
|
298
285
|
return range;
|
|
299
286
|
};
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
287
|
+
// INFO: the date condition a drill-down adds so its records match the
|
|
288
|
+
// range the chart counted
|
|
289
|
+
var handleDateRangeQuery = function (eachChart, dateRange) {
|
|
290
|
+
if (!eachChart.queryBaseDateId)
|
|
291
|
+
return [];
|
|
292
|
+
var customRange = handleResolveRange(eachChart, dateRange);
|
|
293
|
+
var end = (0, dayjs_1.default)("".concat((0, dayjs_1.default)(customRange.endDate).format("YYYY-MM-DD"), " ").concat(customRange.endTime)).toDate();
|
|
294
|
+
// INFO: a single date counts everything up to it — the end date on a line,
|
|
295
|
+
// the start date with its time on every other chart, as the request does
|
|
296
|
+
if (!customRange.isDuration) {
|
|
297
|
+
var until = eachChart.type === "line"
|
|
298
|
+
? end
|
|
299
|
+
: (0, dayjs_1.default)("".concat((0, dayjs_1.default)(customRange.startDate).format("YYYY-MM-DD"), " ").concat(customRange.startTime)).toDate();
|
|
300
|
+
return [{ type: "<", queryId: eachChart.queryBaseDateId, value: until }];
|
|
301
|
+
}
|
|
302
|
+
var start = (0, dayjs_1.default)("".concat((0, dayjs_1.default)(customRange.startDate).format("YYYY-MM-DD"), " ").concat(customRange.startTime)).toDate();
|
|
303
|
+
return [
|
|
304
|
+
{ type: "><", queryId: eachChart.queryBaseDateId, value: [start, end] },
|
|
305
|
+
];
|
|
306
|
+
};
|
|
307
|
+
var handleChartFilterQuery = function (eachChart, filters) {
|
|
308
|
+
var filterQuery = [];
|
|
309
|
+
if (filters[eachChart.title] && filters[eachChart.title].reference) {
|
|
310
|
+
filterQuery.push({
|
|
311
|
+
type: "=",
|
|
312
|
+
value: "".concat(filters[eachChart.title].reference),
|
|
313
|
+
queryId: "".concat(eachChart.queryReferenceId),
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
if (eachChart.baseQuery)
|
|
317
|
+
filterQuery = filterQuery.concat(eachChart.baseQuery);
|
|
318
|
+
return filterQuery;
|
|
319
|
+
};
|
|
320
|
+
var handleChartRQ = function (collectionId) {
|
|
321
|
+
var _a;
|
|
322
|
+
var devSettings = (0, utils_1.parseWorkspaceSettings)({
|
|
323
|
+
dbEndpoint: stories_1.defaultDBEndpoint,
|
|
324
|
+
imageEndpoint: stories_1.defaultImageEndpoint,
|
|
325
|
+
uploadEndpoint: stories_1.defaultUploadEndpoint,
|
|
326
|
+
}, props.workspace);
|
|
327
|
+
return SpaceRQ(devSettings.server, collectionId, (_a = props.workspace.apiEndpoint) !== null && _a !== void 0 ? _a : "", props.workspace.apiEndpointToken, props.workspace.apiUserToken);
|
|
328
|
+
};
|
|
329
|
+
var handleReadGraphDetail = function (eachChart, filters, currentAttribute) { return __awaiter(_this, void 0, void 0, function () {
|
|
330
|
+
var dataList, error, range, filterQuery, requestData, spaceRQ, queries, _i, queries_1, eachQuery, clonedRequestData, res, err_1;
|
|
331
|
+
var _a, _b;
|
|
332
|
+
return __generator(this, function (_c) {
|
|
333
|
+
switch (_c.label) {
|
|
305
334
|
case 0:
|
|
306
335
|
dataList = [];
|
|
307
|
-
error =
|
|
308
|
-
range = handleSetGraphDateRange(eachChart,
|
|
309
|
-
|
|
310
|
-
? graphAnalyticsFilter[eachChart.title].range
|
|
336
|
+
error = undefined;
|
|
337
|
+
range = handleSetGraphDateRange(eachChart, filters[eachChart.title] && filters[eachChart.title].range
|
|
338
|
+
? filters[eachChart.title].range
|
|
311
339
|
: undefined);
|
|
312
|
-
filterQuery =
|
|
313
|
-
if (graphAnalyticsFilter[eachChart.title] &&
|
|
314
|
-
graphAnalyticsFilter[eachChart.title].reference) {
|
|
315
|
-
filterQuery.push({
|
|
316
|
-
type: "=",
|
|
317
|
-
value: "".concat(graphAnalyticsFilter[eachChart.title].reference),
|
|
318
|
-
queryId: "".concat(eachChart.queryReferenceId),
|
|
319
|
-
});
|
|
320
|
-
}
|
|
321
|
-
if (eachChart.baseQuery)
|
|
322
|
-
filterQuery = filterQuery.concat(eachChart.baseQuery);
|
|
340
|
+
filterQuery = handleChartFilterQuery(eachChart, filters);
|
|
323
341
|
requestData = {
|
|
324
342
|
type: "list",
|
|
325
343
|
aggregate: {
|
|
@@ -332,13 +350,12 @@ function DataGraph(props) {
|
|
|
332
350
|
timezone: dayjs_1.default.tz.guess(),
|
|
333
351
|
},
|
|
334
352
|
};
|
|
335
|
-
if (
|
|
336
|
-
graphAnalyticsFilter[eachChart.title].filter) {
|
|
353
|
+
if (filters[eachChart.title] && filters[eachChart.title].filter) {
|
|
337
354
|
requestData = {
|
|
338
355
|
type: "list",
|
|
339
356
|
aggregate: {
|
|
340
357
|
type: (_b = eachChart.queryBaseType) !== null && _b !== void 0 ? _b : "count",
|
|
341
|
-
queryId:
|
|
358
|
+
queryId: filters[eachChart.title].filter,
|
|
342
359
|
dateId: eachChart.queryBaseDateId
|
|
343
360
|
? eachChart.queryBaseDateId
|
|
344
361
|
: "baseUpdatedAt",
|
|
@@ -347,138 +364,502 @@ function DataGraph(props) {
|
|
|
347
364
|
},
|
|
348
365
|
};
|
|
349
366
|
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
}, props.workspace);
|
|
355
|
-
spaceRQ = SpaceRQ(devSettings.server, eachChart.spaceId, (_c = props.workspace.apiEndpoint) !== null && _c !== void 0 ? _c : "", props.workspace.apiEndpointToken, props.workspace.apiUserToken);
|
|
356
|
-
if (!((eachChart === null || eachChart === void 0 ? void 0 : eachChart.query) && eachChart.query.length > 0)) return [3 /*break*/, 7];
|
|
357
|
-
j = 0;
|
|
358
|
-
_f.label = 1;
|
|
367
|
+
spaceRQ = handleChartRQ(eachChart.spaceId);
|
|
368
|
+
queries = (eachChart === null || eachChart === void 0 ? void 0 : eachChart.query) && eachChart.query.length > 0 ? eachChart.query : [null];
|
|
369
|
+
_i = 0, queries_1 = queries;
|
|
370
|
+
_c.label = 1;
|
|
359
371
|
case 1:
|
|
360
|
-
if (!(
|
|
361
|
-
|
|
372
|
+
if (!(_i < queries_1.length)) return [3 /*break*/, 6];
|
|
373
|
+
eachQuery = queries_1[_i];
|
|
374
|
+
_c.label = 2;
|
|
362
375
|
case 2:
|
|
363
|
-
|
|
364
|
-
eachQuery = eachChart.query[j];
|
|
376
|
+
_c.trys.push([2, 4, , 5]);
|
|
365
377
|
clonedRequestData = JSON.parse(JSON.stringify(requestData));
|
|
366
|
-
clonedRequestData["query"] =
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
378
|
+
clonedRequestData["query"] = eachQuery
|
|
379
|
+
? __spreadArray([
|
|
380
|
+
{
|
|
381
|
+
type: eachQuery.type,
|
|
382
|
+
value: eachQuery.value,
|
|
383
|
+
queryId: eachQuery.queryId,
|
|
384
|
+
}
|
|
385
|
+
], filterQuery, true) : filterQuery;
|
|
373
386
|
return [4 /*yield*/, spaceRQ.call(clonedRequestData)];
|
|
374
387
|
case 3:
|
|
375
|
-
res =
|
|
388
|
+
res = _c.sent();
|
|
376
389
|
if (res === null || res === void 0 ? void 0 : res.data)
|
|
377
390
|
dataList.push.apply(dataList, res.data);
|
|
378
391
|
else
|
|
379
392
|
throw new Error("Data Not Found");
|
|
380
393
|
return [3 /*break*/, 5];
|
|
381
394
|
case 4:
|
|
382
|
-
err_1 =
|
|
383
|
-
|
|
384
|
-
console.
|
|
395
|
+
err_1 = _c.sent();
|
|
396
|
+
error = (0, chartErrors_1.handleDescribeChartError)(err_1, eachChart);
|
|
397
|
+
console.error("[DataGraph] - ".concat(eachChart.title, " - ").concat(error.details));
|
|
385
398
|
dataList.push({ id: "", value: 0 });
|
|
386
|
-
error = "Error - Check console";
|
|
387
399
|
return [3 /*break*/, 5];
|
|
388
400
|
case 5:
|
|
389
|
-
|
|
401
|
+
_i++;
|
|
390
402
|
return [3 /*break*/, 1];
|
|
391
|
-
case 6: return [
|
|
392
|
-
case 7:
|
|
393
|
-
_f.trys.push([7, 9, , 10]);
|
|
394
|
-
clonedRequestData = JSON.parse(JSON.stringify(requestData));
|
|
395
|
-
if (filterQuery)
|
|
396
|
-
clonedRequestData["query"] = filterQuery;
|
|
397
|
-
return [4 /*yield*/, spaceRQ.call(clonedRequestData)];
|
|
398
|
-
case 8:
|
|
399
|
-
res = _f.sent();
|
|
400
|
-
if (res === null || res === void 0 ? void 0 : res.data)
|
|
401
|
-
dataList.push.apply(dataList, res.data);
|
|
402
|
-
else
|
|
403
|
-
throw new Error("Data Not Found");
|
|
404
|
-
return [3 /*break*/, 10];
|
|
405
|
-
case 9:
|
|
406
|
-
err_2 = _f.sent();
|
|
407
|
-
errorObj = JSON.parse(typeof err_2 === "string" ? err_2 : JSON.stringify(err_2));
|
|
408
|
-
console.log(eachChart.title + " - " + ((_e = errorObj === null || errorObj === void 0 ? void 0 : errorObj.err) === null || _e === void 0 ? void 0 : _e.details));
|
|
409
|
-
dataList.push({ id: "", value: 0 });
|
|
410
|
-
error = "Error - Check console";
|
|
411
|
-
return [3 /*break*/, 10];
|
|
412
|
-
case 10: return [2 /*return*/, { data: dataList, error: error }];
|
|
403
|
+
case 6: return [2 /*return*/, { data: dataList, error: error }];
|
|
413
404
|
}
|
|
414
405
|
});
|
|
415
406
|
}); };
|
|
416
|
-
|
|
417
|
-
|
|
407
|
+
// INFO: names for the ids a person or reference column groups by
|
|
408
|
+
var handleResolveGroupLabels = function (column, keys) { return __awaiter(_this, void 0, void 0, function () {
|
|
409
|
+
var labels, isReference, ids, labelId, res, err_2;
|
|
410
|
+
var _a, _b, _c;
|
|
411
|
+
return __generator(this, function (_d) {
|
|
412
|
+
switch (_d.label) {
|
|
413
|
+
case 0:
|
|
414
|
+
labels = {};
|
|
415
|
+
if (!column)
|
|
416
|
+
return [2 /*return*/, labels];
|
|
417
|
+
if (column.type === "person" || column.type === "listPerson") {
|
|
418
|
+
((_a = props.personOptions) !== null && _a !== void 0 ? _a : []).forEach(function (eachOption) {
|
|
419
|
+
labels[String(eachOption.key)] = String(eachOption.label);
|
|
420
|
+
});
|
|
421
|
+
return [2 /*return*/, labels];
|
|
422
|
+
}
|
|
423
|
+
isReference = column.type === "reference" || column.type === "listReference";
|
|
424
|
+
ids = Array.from(new Set(keys
|
|
425
|
+
.flat()
|
|
426
|
+
.filter(function (each) { return each !== null && each !== undefined && each !== ""; })
|
|
427
|
+
.map(function (each) { return String(each); })));
|
|
428
|
+
if (!isReference || !column.referenceSpaceId || ids.length === 0)
|
|
429
|
+
return [2 /*return*/, labels];
|
|
430
|
+
labelId = (_b = column.referenceLabel) !== null && _b !== void 0 ? _b : "name";
|
|
431
|
+
_d.label = 1;
|
|
432
|
+
case 1:
|
|
433
|
+
_d.trys.push([1, 3, , 4]);
|
|
434
|
+
return [4 /*yield*/, handleChartRQ(column.referenceSpaceId).call({
|
|
435
|
+
type: "list",
|
|
436
|
+
query: [{ type: "in", queryId: "_id", value: ids }],
|
|
437
|
+
attributeIds: [labelId],
|
|
438
|
+
limit: ids.length,
|
|
439
|
+
})];
|
|
440
|
+
case 2:
|
|
441
|
+
res = _d.sent();
|
|
442
|
+
((_c = res === null || res === void 0 ? void 0 : res.data) !== null && _c !== void 0 ? _c : []).forEach(function (eachRecord) {
|
|
443
|
+
if ((eachRecord === null || eachRecord === void 0 ? void 0 : eachRecord._id) && eachRecord[labelId] !== undefined)
|
|
444
|
+
labels[String(eachRecord._id)] = String(eachRecord[labelId]);
|
|
445
|
+
});
|
|
446
|
+
return [3 /*break*/, 4];
|
|
447
|
+
case 3:
|
|
448
|
+
err_2 = _d.sent();
|
|
449
|
+
// INFO: without names the ids still draw; the chart is not failed for it
|
|
450
|
+
console.error("[DataGraph] - group labels failed:", err_2);
|
|
451
|
+
return [3 /*break*/, 4];
|
|
452
|
+
case 4: return [2 /*return*/, labels];
|
|
453
|
+
}
|
|
454
|
+
});
|
|
455
|
+
}); };
|
|
456
|
+
var handleFindColumn = function (columnId) {
|
|
457
|
+
var _a;
|
|
458
|
+
return columnId
|
|
459
|
+
? (_a = props.structure) === null || _a === void 0 ? void 0 : _a.find(function (eachColumn) { return eachColumn.id === columnId; })
|
|
460
|
+
: undefined;
|
|
461
|
+
};
|
|
462
|
+
/**
|
|
463
|
+
* The points of a chart built from new-style options: one aggregate per
|
|
464
|
+
* group set, date buckets as ranges, and each segment as its own pass.
|
|
465
|
+
*/
|
|
466
|
+
var handleReadShapedChart = function (eachChart, filters) { return __awaiter(_this, void 0, void 0, function () {
|
|
467
|
+
var filterRange, filterQuery, spaceRQ, dateId, isDateMode, buckets, range, aggregate, handleRunPoints, columnError, points, groupColumn_1, labels_1, shaped_1, shapedPoints, segments, err_3, error;
|
|
418
468
|
var _this = this;
|
|
419
|
-
|
|
420
|
-
|
|
469
|
+
var _a, _b, _c, _d, _e;
|
|
470
|
+
return __generator(this, function (_f) {
|
|
471
|
+
switch (_f.label) {
|
|
421
472
|
case 0:
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
473
|
+
filterRange = (_a = filters[eachChart.title]) === null || _a === void 0 ? void 0 : _a.range;
|
|
474
|
+
filterQuery = handleChartFilterQuery(eachChart, filters);
|
|
475
|
+
spaceRQ = handleChartRQ(eachChart.spaceId);
|
|
476
|
+
dateId = (_b = eachChart.queryBaseDateId) !== null && _b !== void 0 ? _b : "baseUpdatedAt";
|
|
477
|
+
isDateMode = !!eachChart.queryDateInterval &&
|
|
478
|
+
!!eachChart.queryBaseDateId &&
|
|
479
|
+
!eachChart.groupBy;
|
|
480
|
+
buckets = isDateMode
|
|
481
|
+
? (function () {
|
|
482
|
+
var resolved = handleResolveRange(eachChart, filterRange);
|
|
483
|
+
return (0, chartResults_1.handleSplitDateInterval)(resolved.startDate, resolved.endDate, eachChart.queryDateInterval);
|
|
484
|
+
})()
|
|
485
|
+
: [];
|
|
486
|
+
range = isDateMode
|
|
487
|
+
? buckets.map(function (eachBucket) { return eachBucket.range; })
|
|
488
|
+
: handleSetGraphDateRange(eachChart, filterRange);
|
|
489
|
+
aggregate = {
|
|
490
|
+
type: (_c = eachChart.queryBaseType) !== null && _c !== void 0 ? _c : "count",
|
|
491
|
+
queryId: (_e = (_d = eachChart.queryAttributeId) === null || _d === void 0 ? void 0 : _d[0]) !== null && _e !== void 0 ? _e : "",
|
|
492
|
+
dateId: dateId,
|
|
493
|
+
range: range,
|
|
494
|
+
timezone: dayjs_1.default.tz.guess(),
|
|
495
|
+
};
|
|
496
|
+
handleRunPoints = function (extraQuery) { return __awaiter(_this, void 0, void 0, function () {
|
|
497
|
+
var res, res, data_1, queries, sharedColumn, res, byKey_1;
|
|
498
|
+
var _this = this;
|
|
499
|
+
var _a, _b, _c;
|
|
500
|
+
return __generator(this, function (_d) {
|
|
501
|
+
switch (_d.label) {
|
|
502
|
+
case 0:
|
|
503
|
+
if (!eachChart.groupBy) return [3 /*break*/, 2];
|
|
504
|
+
return [4 /*yield*/, spaceRQ.call({
|
|
505
|
+
type: "list",
|
|
506
|
+
query: __spreadArray(__spreadArray([], extraQuery, true), filterQuery, true),
|
|
507
|
+
aggregate: __assign(__assign({}, aggregate), { groupId: eachChart.groupBy }),
|
|
508
|
+
})];
|
|
509
|
+
case 1:
|
|
510
|
+
res = _d.sent();
|
|
511
|
+
return [2 /*return*/, (0, chartResults_1.handleFlattenGroupedResult)(res === null || res === void 0 ? void 0 : res.data).map(function (eachGroup) {
|
|
512
|
+
var _a;
|
|
513
|
+
return ({
|
|
514
|
+
x: "",
|
|
515
|
+
y: (_a = eachGroup.value) !== null && _a !== void 0 ? _a : 0,
|
|
516
|
+
key: eachGroup.key,
|
|
517
|
+
query: (0, chartResults_1.handleGroupKeyQuery)(eachChart.groupBy, eachGroup.key),
|
|
445
518
|
});
|
|
446
|
-
|
|
519
|
+
})];
|
|
520
|
+
case 2:
|
|
521
|
+
if (!isDateMode) return [3 /*break*/, 4];
|
|
522
|
+
return [4 /*yield*/, spaceRQ.call({
|
|
523
|
+
type: "list",
|
|
524
|
+
query: __spreadArray(__spreadArray([], extraQuery, true), filterQuery, true),
|
|
525
|
+
aggregate: aggregate,
|
|
526
|
+
})];
|
|
527
|
+
case 3:
|
|
528
|
+
res = _d.sent();
|
|
529
|
+
data_1 = (_a = res === null || res === void 0 ? void 0 : res.data) !== null && _a !== void 0 ? _a : [];
|
|
530
|
+
return [2 /*return*/, buckets.map(function (eachBucket, index) {
|
|
531
|
+
var _a, _b;
|
|
532
|
+
return ({
|
|
533
|
+
x: eachBucket.label,
|
|
534
|
+
y: (_b = (0, chartResults_1.handleToChartNumber)((_a = data_1[index]) === null || _a === void 0 ? void 0 : _a.value)) !== null && _b !== void 0 ? _b : 0,
|
|
535
|
+
key: eachBucket.label,
|
|
536
|
+
query: [
|
|
537
|
+
{
|
|
538
|
+
type: "><",
|
|
539
|
+
queryId: dateId,
|
|
540
|
+
value: [eachBucket.start, eachBucket.end],
|
|
541
|
+
},
|
|
542
|
+
],
|
|
543
|
+
});
|
|
544
|
+
})];
|
|
545
|
+
case 4:
|
|
546
|
+
queries = (_b = eachChart.query) !== null && _b !== void 0 ? _b : [];
|
|
547
|
+
sharedColumn = (_c = queries[0]) === null || _c === void 0 ? void 0 : _c.queryId;
|
|
548
|
+
if (!(queries.length > 1 &&
|
|
549
|
+
sharedColumn &&
|
|
550
|
+
queries.every(function (eachQuery) {
|
|
551
|
+
return eachQuery.type === "=" && eachQuery.queryId === sharedColumn;
|
|
552
|
+
}))) return [3 /*break*/, 6];
|
|
553
|
+
return [4 /*yield*/, spaceRQ.call({
|
|
554
|
+
type: "list",
|
|
555
|
+
query: __spreadArray(__spreadArray([], extraQuery, true), filterQuery, true),
|
|
556
|
+
aggregate: __assign(__assign({}, aggregate), { groupId: sharedColumn }),
|
|
557
|
+
})];
|
|
558
|
+
case 5:
|
|
559
|
+
res = _d.sent();
|
|
560
|
+
byKey_1 = new Map((0, chartResults_1.handleFlattenGroupedResult)(res === null || res === void 0 ? void 0 : res.data).map(function (eachGroup) {
|
|
561
|
+
var _a;
|
|
562
|
+
return [
|
|
563
|
+
JSON.stringify((_a = eachGroup.key) !== null && _a !== void 0 ? _a : null),
|
|
564
|
+
eachGroup.value,
|
|
565
|
+
];
|
|
566
|
+
}));
|
|
567
|
+
return [2 /*return*/, queries.map(function (eachQuery, index) {
|
|
568
|
+
var _a, _b, _c, _d;
|
|
569
|
+
return ({
|
|
570
|
+
x: (_b = (_a = eachChart.seriesLabels) === null || _a === void 0 ? void 0 : _a[index]) !== null && _b !== void 0 ? _b : String(eachQuery.value),
|
|
571
|
+
y: (_d = byKey_1.get(JSON.stringify((_c = eachQuery.value) !== null && _c !== void 0 ? _c : null))) !== null && _d !== void 0 ? _d : 0,
|
|
572
|
+
key: eachQuery.value,
|
|
573
|
+
query: [eachQuery],
|
|
574
|
+
});
|
|
575
|
+
})];
|
|
576
|
+
case 6: return [2 /*return*/, Promise.all(queries.map(function (eachQuery, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
577
|
+
var res;
|
|
578
|
+
var _a, _b, _c, _d, _e;
|
|
579
|
+
return __generator(this, function (_f) {
|
|
580
|
+
switch (_f.label) {
|
|
581
|
+
case 0: return [4 /*yield*/, spaceRQ.call({
|
|
582
|
+
type: "list",
|
|
583
|
+
query: __spreadArray(__spreadArray([eachQuery], extraQuery, true), filterQuery, true),
|
|
584
|
+
aggregate: aggregate,
|
|
585
|
+
})];
|
|
586
|
+
case 1:
|
|
587
|
+
res = _f.sent();
|
|
588
|
+
return [2 /*return*/, {
|
|
589
|
+
x: (_b = (_a = eachChart.seriesLabels) === null || _a === void 0 ? void 0 : _a[index]) !== null && _b !== void 0 ? _b : String(eachQuery.value),
|
|
590
|
+
y: (_e = (0, chartResults_1.handleToChartNumber)((_d = (_c = res === null || res === void 0 ? void 0 : res.data) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.value)) !== null && _e !== void 0 ? _e : 0,
|
|
591
|
+
key: eachQuery.value,
|
|
592
|
+
query: [eachQuery],
|
|
593
|
+
}];
|
|
594
|
+
}
|
|
447
595
|
});
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
596
|
+
}); }))];
|
|
597
|
+
}
|
|
598
|
+
});
|
|
599
|
+
}); };
|
|
600
|
+
_f.label = 1;
|
|
601
|
+
case 1:
|
|
602
|
+
_f.trys.push([1, 7, , 8]);
|
|
603
|
+
columnError = (0, chartErrors_1.handleCheckChartColumns)(eachChart, props.structure);
|
|
604
|
+
if (columnError)
|
|
605
|
+
return [2 /*return*/, { error: columnError }];
|
|
606
|
+
return [4 /*yield*/, handleRunPoints([])];
|
|
607
|
+
case 2:
|
|
608
|
+
points = _f.sent();
|
|
609
|
+
groupColumn_1 = handleFindColumn(eachChart.groupBy);
|
|
610
|
+
if (!eachChart.groupBy) return [3 /*break*/, 4];
|
|
611
|
+
return [4 /*yield*/, handleResolveGroupLabels(groupColumn_1, points.map(function (eachPoint) { return eachPoint.key; }))];
|
|
612
|
+
case 3:
|
|
613
|
+
labels_1 = _f.sent();
|
|
614
|
+
points = points.map(function (eachPoint) { return (__assign(__assign({}, eachPoint), { x: (0, chartResults_1.handleGroupKeyLabel)(eachPoint.key, groupColumn_1, labels_1) })); });
|
|
615
|
+
_f.label = 4;
|
|
616
|
+
case 4:
|
|
617
|
+
shaped_1 = (0, chartResults_1.handleShapeChartPoints)(points, {
|
|
618
|
+
sortBy: eachChart.sortBy,
|
|
619
|
+
sortDirection: eachChart.sortDirection,
|
|
620
|
+
// INFO: a time axis keeps every bucket in date order
|
|
621
|
+
topN: isDateMode ? undefined : eachChart.topN,
|
|
622
|
+
showOthers: eachChart.showOthers,
|
|
623
|
+
// INFO: segments stay in counts, so a split chart is never a percentage
|
|
624
|
+
showPercent: eachChart.showPercent && !eachChart.segmentBy,
|
|
625
|
+
cumulative: isDateMode && eachChart.cumulative,
|
|
626
|
+
measure: eachChart.queryBaseType,
|
|
627
|
+
});
|
|
628
|
+
shapedPoints = shaped_1.points.map(function (eachPoint) {
|
|
629
|
+
return eachPoint.x === chartResults_1.OTHERS_LABEL && eachPoint.key === undefined
|
|
630
|
+
? __assign(__assign({}, eachPoint), { query: eachChart.groupBy
|
|
631
|
+
? [
|
|
632
|
+
{
|
|
633
|
+
type: "in",
|
|
634
|
+
queryId: eachChart.groupBy,
|
|
635
|
+
value: shaped_1.hiddenKeys,
|
|
636
|
+
},
|
|
637
|
+
]
|
|
638
|
+
: [] }) : eachPoint;
|
|
639
|
+
});
|
|
640
|
+
segments = undefined;
|
|
641
|
+
if (!(eachChart.segmentBy && eachChart.type !== "pie")) return [3 /*break*/, 6];
|
|
642
|
+
return [4 /*yield*/, handleReadSegments(eachChart, shapedPoints, handleRunPoints, filterQuery, filterRange)];
|
|
643
|
+
case 5:
|
|
644
|
+
segments = _f.sent();
|
|
645
|
+
_f.label = 6;
|
|
646
|
+
case 6: return [2 /*return*/, { series: { points: shapedPoints, segments: segments } }];
|
|
647
|
+
case 7:
|
|
648
|
+
err_3 = _f.sent();
|
|
649
|
+
error = (0, chartErrors_1.handleDescribeChartError)(err_3, eachChart);
|
|
650
|
+
console.error("[DataGraph] - ".concat(eachChart.title, " - ").concat(error.details));
|
|
651
|
+
return [2 /*return*/, { error: error }];
|
|
652
|
+
case 8: return [2 /*return*/];
|
|
653
|
+
}
|
|
654
|
+
});
|
|
655
|
+
}); };
|
|
656
|
+
// INFO: the values to split by — a list column's own options, otherwise the
|
|
657
|
+
// most common values — capped, with the rest drawn as "Others"
|
|
658
|
+
var handleReadSegments = function (eachChart, points, handleRunPoints, filterQuery, filterRange) { return __awaiter(_this, void 0, void 0, function () {
|
|
659
|
+
var segmentColumn, segmentKeys, res, labels, segments, rest;
|
|
660
|
+
var _this = this;
|
|
661
|
+
var _a, _b;
|
|
662
|
+
return __generator(this, function (_c) {
|
|
663
|
+
switch (_c.label) {
|
|
664
|
+
case 0:
|
|
665
|
+
segmentColumn = handleFindColumn(eachChart.segmentBy);
|
|
666
|
+
segmentKeys = [];
|
|
667
|
+
if (!((segmentColumn === null || segmentColumn === void 0 ? void 0 : segmentColumn.type) === "list" && ((_a = segmentColumn.listSelection) === null || _a === void 0 ? void 0 : _a.length))) return [3 /*break*/, 1];
|
|
668
|
+
segmentKeys = segmentColumn.listSelection.slice(0, MAX_SEGMENTS);
|
|
669
|
+
return [3 /*break*/, 3];
|
|
670
|
+
case 1: return [4 /*yield*/, handleChartRQ(eachChart.spaceId).call({
|
|
671
|
+
type: "list",
|
|
672
|
+
query: filterQuery,
|
|
673
|
+
aggregate: {
|
|
674
|
+
type: "count",
|
|
675
|
+
queryId: "_id",
|
|
676
|
+
groupId: eachChart.segmentBy,
|
|
677
|
+
dateId: (_b = eachChart.queryBaseDateId) !== null && _b !== void 0 ? _b : "baseUpdatedAt",
|
|
678
|
+
range: handleSetGraphDateRange(__assign(__assign({}, eachChart), { type: "bar" }), filterRange),
|
|
679
|
+
timezone: dayjs_1.default.tz.guess(),
|
|
680
|
+
},
|
|
681
|
+
})];
|
|
682
|
+
case 2:
|
|
683
|
+
res = _c.sent();
|
|
684
|
+
segmentKeys = (0, chartResults_1.handleFlattenGroupedResult)(res === null || res === void 0 ? void 0 : res.data)
|
|
685
|
+
.sort(function (first, second) { var _a, _b; return ((_a = second.value) !== null && _a !== void 0 ? _a : 0) - ((_b = first.value) !== null && _b !== void 0 ? _b : 0); })
|
|
686
|
+
.slice(0, MAX_SEGMENTS)
|
|
687
|
+
.map(function (eachGroup) { return eachGroup.key; });
|
|
688
|
+
_c.label = 3;
|
|
689
|
+
case 3: return [4 /*yield*/, handleResolveGroupLabels(segmentColumn, segmentKeys)];
|
|
690
|
+
case 4:
|
|
691
|
+
labels = _c.sent();
|
|
692
|
+
return [4 /*yield*/, Promise.all(segmentKeys.map(function (eachKey) { return __awaiter(_this, void 0, void 0, function () {
|
|
693
|
+
var segmentPoints, byKey, running;
|
|
694
|
+
return __generator(this, function (_a) {
|
|
695
|
+
switch (_a.label) {
|
|
696
|
+
case 0: return [4 /*yield*/, handleRunPoints((0, chartResults_1.handleGroupKeyQuery)(eachChart.segmentBy, eachKey))];
|
|
697
|
+
case 1:
|
|
698
|
+
segmentPoints = _a.sent();
|
|
699
|
+
byKey = new Map(segmentPoints.map(function (eachPoint) {
|
|
700
|
+
var _a;
|
|
701
|
+
return [
|
|
702
|
+
JSON.stringify((_a = eachPoint.key) !== null && _a !== void 0 ? _a : null),
|
|
703
|
+
eachPoint.y,
|
|
704
|
+
];
|
|
705
|
+
}));
|
|
706
|
+
running = 0;
|
|
707
|
+
return [2 /*return*/, {
|
|
708
|
+
name: (0, chartResults_1.handleGroupKeyLabel)(eachKey, segmentColumn, labels),
|
|
709
|
+
data: points.map(function (eachPoint) {
|
|
710
|
+
var _a, _b;
|
|
711
|
+
var value = eachPoint.x === chartResults_1.OTHERS_LABEL
|
|
712
|
+
? 0
|
|
713
|
+
: (_b = byKey.get(JSON.stringify((_a = eachPoint.key) !== null && _a !== void 0 ? _a : null))) !== null && _b !== void 0 ? _b : 0;
|
|
714
|
+
running += value;
|
|
715
|
+
return eachChart.cumulative && eachChart.queryDateInterval
|
|
716
|
+
? Math.round(running * 100) / 100
|
|
717
|
+
: value;
|
|
718
|
+
}),
|
|
719
|
+
}];
|
|
469
720
|
}
|
|
470
721
|
});
|
|
471
722
|
}); }))];
|
|
723
|
+
case 5:
|
|
724
|
+
segments = _c.sent();
|
|
725
|
+
// INFO: whatever the capped segments leave of each total
|
|
726
|
+
if (eachChart.queryBaseType !== "avg") {
|
|
727
|
+
rest = points.map(function (eachPoint, index) {
|
|
728
|
+
var covered = segments.reduce(function (sum, eachSegment) { return sum + eachSegment.data[index]; }, 0);
|
|
729
|
+
return Math.max(0, Math.round((eachPoint.y - covered) * 100) / 100);
|
|
730
|
+
});
|
|
731
|
+
if (rest.some(function (each) { return each > 0; }))
|
|
732
|
+
segments.push({ name: chartResults_1.OTHERS_LABEL, data: rest });
|
|
733
|
+
}
|
|
734
|
+
return [2 /*return*/, segments.length ? segments : undefined];
|
|
735
|
+
}
|
|
736
|
+
});
|
|
737
|
+
}); };
|
|
738
|
+
var handleReadRadar = function (eachChart, filters) { return __awaiter(_this, void 0, void 0, function () {
|
|
739
|
+
var localData, error, results;
|
|
740
|
+
var _a;
|
|
741
|
+
return __generator(this, function (_b) {
|
|
742
|
+
switch (_b.label) {
|
|
743
|
+
case 0:
|
|
744
|
+
localData = [];
|
|
745
|
+
error = (_a = (0, chartErrors_1.handleCheckChartColumns)(eachChart, props.structure)) !== null && _a !== void 0 ? _a : undefined;
|
|
746
|
+
if (error || !eachChart.queryAttributeId)
|
|
747
|
+
return [2 /*return*/, { data: localData, error: error }];
|
|
748
|
+
eachChart.query.forEach(function (eachQuery) {
|
|
749
|
+
localData.push({ id: eachQuery.value, value: [] });
|
|
750
|
+
});
|
|
751
|
+
return [4 /*yield*/, Promise.all(eachChart.queryAttributeId.map(function (eachAttribute) {
|
|
752
|
+
return handleReadGraphDetail(eachChart, filters, eachAttribute);
|
|
753
|
+
}))];
|
|
472
754
|
case 1:
|
|
473
|
-
|
|
474
|
-
|
|
755
|
+
results = _b.sent();
|
|
756
|
+
results.forEach(function (eachResult) {
|
|
757
|
+
eachResult.data.forEach(function (eachData, index) {
|
|
758
|
+
var _a, _b;
|
|
759
|
+
// INFO: a failed request answers one placeholder, not one per query
|
|
760
|
+
(_a = localData[index]) === null || _a === void 0 ? void 0 : _a.value.push((_b = (0, chartResults_1.handleToChartNumber)(eachData.value)) !== null && _b !== void 0 ? _b : 0);
|
|
761
|
+
});
|
|
762
|
+
if (eachResult.error)
|
|
763
|
+
error = eachResult.error;
|
|
764
|
+
});
|
|
765
|
+
return [2 /*return*/, { data: localData, error: error }];
|
|
766
|
+
}
|
|
767
|
+
});
|
|
768
|
+
}); };
|
|
769
|
+
/**
|
|
770
|
+
* Loads one chart into state, whichever way it is built. Every path ends in
|
|
771
|
+
* an error card rather than a throw, so one chart never fails the others.
|
|
772
|
+
*/
|
|
773
|
+
var handleLoadChart = function (eachChart, filters) { return __awaiter(_this, void 0, void 0, function () {
|
|
774
|
+
var sequence, data, series, error, columnError, err_4;
|
|
775
|
+
var _a, _b, _c;
|
|
776
|
+
var _d;
|
|
777
|
+
return __generator(this, function (_e) {
|
|
778
|
+
switch (_e.label) {
|
|
779
|
+
case 0:
|
|
780
|
+
sequence = ((_d = loadSequenceRef.current[eachChart.title]) !== null && _d !== void 0 ? _d : 0) + 1;
|
|
781
|
+
loadSequenceRef.current[eachChart.title] = sequence;
|
|
782
|
+
data = undefined;
|
|
783
|
+
series = undefined;
|
|
784
|
+
error = undefined;
|
|
785
|
+
_e.label = 1;
|
|
786
|
+
case 1:
|
|
787
|
+
_e.trys.push([1, 9, , 10]);
|
|
788
|
+
if (!(eachChart.type === "radar")) return [3 /*break*/, 3];
|
|
789
|
+
return [4 /*yield*/, handleReadRadar(eachChart, filters)];
|
|
475
790
|
case 2:
|
|
476
|
-
|
|
477
|
-
|
|
791
|
+
(_a = _e.sent(), data = _a.data, error = _a.error);
|
|
792
|
+
return [3 /*break*/, 8];
|
|
793
|
+
case 3:
|
|
794
|
+
if (!(0, exports.handleIsShapedChart)(eachChart)) return [3 /*break*/, 5];
|
|
795
|
+
return [4 /*yield*/, handleReadShapedChart(eachChart, filters)];
|
|
796
|
+
case 4:
|
|
797
|
+
(_b = _e.sent(), series = _b.series, error = _b.error);
|
|
798
|
+
return [3 /*break*/, 8];
|
|
799
|
+
case 5:
|
|
800
|
+
columnError = (0, chartErrors_1.handleCheckChartColumns)(eachChart, props.structure);
|
|
801
|
+
if (!columnError) return [3 /*break*/, 6];
|
|
802
|
+
error = columnError;
|
|
803
|
+
return [3 /*break*/, 8];
|
|
804
|
+
case 6: return [4 /*yield*/, handleReadGraphDetail(eachChart, filters)];
|
|
805
|
+
case 7:
|
|
806
|
+
(_c = _e.sent(), data = _c.data, error = _c.error);
|
|
807
|
+
_e.label = 8;
|
|
808
|
+
case 8: return [3 /*break*/, 10];
|
|
809
|
+
case 9:
|
|
810
|
+
err_4 = _e.sent();
|
|
811
|
+
error = (0, chartErrors_1.handleDescribeChartError)(err_4, eachChart);
|
|
812
|
+
return [3 /*break*/, 10];
|
|
813
|
+
case 10:
|
|
814
|
+
if (loadSequenceRef.current[eachChart.title] !== sequence)
|
|
815
|
+
return [2 /*return*/];
|
|
816
|
+
setGraphAnalyticsData(function (prev) {
|
|
817
|
+
var _a;
|
|
818
|
+
return (__assign(__assign({}, prev), (_a = {}, _a[eachChart.title] = data, _a)));
|
|
819
|
+
});
|
|
820
|
+
setGraphSeries(function (prev) {
|
|
821
|
+
var next = __assign({}, prev);
|
|
822
|
+
if (series)
|
|
823
|
+
next[eachChart.title] = series;
|
|
824
|
+
else
|
|
825
|
+
delete next[eachChart.title];
|
|
826
|
+
return next;
|
|
827
|
+
});
|
|
828
|
+
setGraphAnalyticsError(function (prev) {
|
|
829
|
+
var _a;
|
|
830
|
+
return (__assign(__assign({}, prev), (_a = {}, _a[eachChart.title] = error, _a)));
|
|
831
|
+
});
|
|
478
832
|
return [2 /*return*/];
|
|
479
833
|
}
|
|
480
834
|
});
|
|
481
835
|
}); };
|
|
836
|
+
var handleGetGraphDetail = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
837
|
+
return __generator(this, function (_a) {
|
|
838
|
+
switch (_a.label) {
|
|
839
|
+
case 0:
|
|
840
|
+
if (!props.charts)
|
|
841
|
+
return [2 /*return*/];
|
|
842
|
+
return [4 /*yield*/, Promise.all(props.charts.map(function (eachChart) {
|
|
843
|
+
return handleLoadChart(eachChart, graphAnalyticsFilter);
|
|
844
|
+
}))];
|
|
845
|
+
case 1:
|
|
846
|
+
_a.sent();
|
|
847
|
+
return [2 /*return*/];
|
|
848
|
+
}
|
|
849
|
+
});
|
|
850
|
+
}); };
|
|
851
|
+
var handleRetryChart = function (eachChart) {
|
|
852
|
+
setRetryCount(function (prev) {
|
|
853
|
+
var _a;
|
|
854
|
+
var _b;
|
|
855
|
+
return (__assign(__assign({}, prev), (_a = {}, _a[eachChart.title] = ((_b = prev[eachChart.title]) !== null && _b !== void 0 ? _b : 0) + 1, _a)));
|
|
856
|
+
});
|
|
857
|
+
setGraphAnalyticsError(function (prev) {
|
|
858
|
+
var _a;
|
|
859
|
+
return (__assign(__assign({}, prev), (_a = {}, _a[eachChart.title] = undefined, _a)));
|
|
860
|
+
});
|
|
861
|
+
handleLoadChart(eachChart, graphAnalyticsFilter);
|
|
862
|
+
};
|
|
482
863
|
var handleCloneGraphAnalyticsFilter = function () {
|
|
483
864
|
var clonedGraphAnalyticsFilter = JSON.parse(JSON.stringify(graphAnalyticsFilter));
|
|
484
865
|
Object.keys(clonedGraphAnalyticsFilter).map(function (eachKeys) {
|
|
@@ -516,6 +897,78 @@ function DataGraph(props) {
|
|
|
516
897
|
return [2 /*return*/];
|
|
517
898
|
});
|
|
518
899
|
}); };
|
|
900
|
+
var handleDrillDown = function (eachChart, point) {
|
|
901
|
+
var _a, _b;
|
|
902
|
+
if (!props.onDrillDown || !point)
|
|
903
|
+
return;
|
|
904
|
+
// INFO: a percentage or running total still opens the records of its own
|
|
905
|
+
// value, not of everything before it
|
|
906
|
+
props.onDrillDown({
|
|
907
|
+
chart: eachChart,
|
|
908
|
+
label: point.x,
|
|
909
|
+
query: __spreadArray(__spreadArray(__spreadArray([], ((_a = point.query) !== null && _a !== void 0 ? _a : []), true), handleChartFilterQuery(eachChart, graphAnalyticsFilter), true), (eachChart.queryDateInterval && !eachChart.groupBy
|
|
910
|
+
? []
|
|
911
|
+
: handleDateRangeQuery(eachChart, (_b = graphAnalyticsFilter[eachChart.title]) === null || _b === void 0 ? void 0 : _b.range)), true),
|
|
912
|
+
});
|
|
913
|
+
};
|
|
914
|
+
var handleBuildLegacyPoints = function (eachChart) {
|
|
915
|
+
var points = [];
|
|
916
|
+
var selectedChart = eachChart === null || eachChart === void 0 ? void 0 : eachChart.query;
|
|
917
|
+
var raw = graphAnalyticsData[eachChart.title];
|
|
918
|
+
if (!Array.isArray(raw))
|
|
919
|
+
return points;
|
|
920
|
+
raw.forEach(function (eachData, index) {
|
|
921
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
922
|
+
var title = eachData._id;
|
|
923
|
+
var dates = typeof eachData._id === "string" ? eachData._id.split("-") : [];
|
|
924
|
+
if (dates.length === 2) {
|
|
925
|
+
var format = "DD/MM/YY";
|
|
926
|
+
var range = (_b = graphAnalyticsFilter[(_a = eachChart.title) !== null && _a !== void 0 ? _a : ""]) === null || _b === void 0 ? void 0 : _b.range;
|
|
927
|
+
if (range &&
|
|
928
|
+
(0, dayjs_1.default)(range.startDate).isSame((0, dayjs_1.default)(range.endDate), "day")) {
|
|
929
|
+
format = "HH:mm";
|
|
930
|
+
}
|
|
931
|
+
var startDate = (0, dayjs_1.default)(dates[0], "DD/MM/YYYY HH:mm:ss").format(format);
|
|
932
|
+
var endDate = (0, dayjs_1.default)(dates[1], "DD/MM/YYYY HH:mm:ss").format(format);
|
|
933
|
+
title = "".concat(startDate, " - ").concat(endDate);
|
|
934
|
+
}
|
|
935
|
+
var seriesLabel = (_c = eachChart.seriesLabels) === null || _c === void 0 ? void 0 : _c[index];
|
|
936
|
+
if (seriesLabel && eachChart.type !== "line") {
|
|
937
|
+
title = seriesLabel;
|
|
938
|
+
}
|
|
939
|
+
else if (selectedChart &&
|
|
940
|
+
Array.isArray(selectedChart) &&
|
|
941
|
+
eachChart.type !== "line") {
|
|
942
|
+
var queryId = (_e = (_d = selectedChart[index]) === null || _d === void 0 ? void 0 : _d.queryId) !== null && _e !== void 0 ? _e : "";
|
|
943
|
+
var type = (_g = (_f = selectedChart[index]) === null || _f === void 0 ? void 0 : _f.type) !== null && _g !== void 0 ? _g : "";
|
|
944
|
+
var value = (_j = (_h = selectedChart[index]) === null || _h === void 0 ? void 0 : _h.value) !== null && _j !== void 0 ? _j : "";
|
|
945
|
+
title =
|
|
946
|
+
queryId && type && value ? "".concat(queryId, " ").concat(type, " ").concat(value) : title;
|
|
947
|
+
}
|
|
948
|
+
var query = eachChart.type !== "line" && (selectedChart === null || selectedChart === void 0 ? void 0 : selectedChart[index])
|
|
949
|
+
? [selectedChart[index]]
|
|
950
|
+
: undefined;
|
|
951
|
+
points.push({
|
|
952
|
+
x: title === null || title === undefined ? chartResults_1.EMPTY_GROUP_LABEL : String(title),
|
|
953
|
+
y: (_k = (0, chartResults_1.handleToChartNumber)(eachData.value)) !== null && _k !== void 0 ? _k : 0,
|
|
954
|
+
key: (_l = selectedChart === null || selectedChart === void 0 ? void 0 : selectedChart[index]) === null || _l === void 0 ? void 0 : _l.value,
|
|
955
|
+
query: query,
|
|
956
|
+
});
|
|
957
|
+
});
|
|
958
|
+
if (eachChart.type === "line")
|
|
959
|
+
return points;
|
|
960
|
+
return (0, chartResults_1.handleShapeChartPoints)(points, {
|
|
961
|
+
sortBy: eachChart.sortBy,
|
|
962
|
+
sortDirection: eachChart.sortDirection,
|
|
963
|
+
topN: eachChart.topN,
|
|
964
|
+
showOthers: eachChart.showOthers,
|
|
965
|
+
showPercent: eachChart.showPercent,
|
|
966
|
+
measure: eachChart.queryBaseType,
|
|
967
|
+
}).points.map(function (eachPoint) {
|
|
968
|
+
return eachPoint.x === chartResults_1.OTHERS_LABEL && eachPoint.key === undefined
|
|
969
|
+
? __assign(__assign({}, eachPoint), { query: undefined }) : eachPoint;
|
|
970
|
+
});
|
|
971
|
+
};
|
|
519
972
|
var renderChartCardIcon = function (spaceIcon, isCompact, emoji) {
|
|
520
973
|
if (emoji)
|
|
521
974
|
return (react_1.default.createElement("span", { "aria-hidden": "true", className: "flex items-center justify-center leading-none ".concat(isCompact ? "h-4 w-4 text-sm" : "h-5 w-5 text-base") }, emoji));
|
|
@@ -537,162 +990,173 @@ function DataGraph(props) {
|
|
|
537
990
|
};
|
|
538
991
|
var renderChartOptionFilter = function (eachChart, index) {
|
|
539
992
|
var _a, _b, _c, _d;
|
|
540
|
-
if (eachChart)
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
})) !== null && _b !== void 0 ? _b : [];
|
|
554
|
-
}
|
|
555
|
-
var isFilter = eachChart.queryAttributeId
|
|
556
|
-
? eachChart.queryAttributeId.length > 0
|
|
557
|
-
: false;
|
|
558
|
-
return (react_1.default.createElement("div", { className: "flex flex-col sm:flex-row gap-2 sm:ml-5 justify-ends" }, isFilter && (react_1.default.createElement(select_1.Select, { label: "", options: options, value: (_d = (_c = graphAnalyticsFilter[eachChart.title]) === null || _c === void 0 ? void 0 : _c.filter) !== null && _d !== void 0 ? _d : (options.length > 0 ? options[0].key : "-"), onChange: function (value) {
|
|
559
|
-
handleUpdateChartData(index, value, "filter");
|
|
560
|
-
} }))));
|
|
561
|
-
}
|
|
993
|
+
if (!eachChart)
|
|
994
|
+
return null;
|
|
995
|
+
var options = [];
|
|
996
|
+
if (eachChart && Array.isArray(eachChart.queryAttributeId)) {
|
|
997
|
+
options =
|
|
998
|
+
(_b = (_a = eachChart === null || eachChart === void 0 ? void 0 : eachChart.queryAttributeId) === null || _a === void 0 ? void 0 : _a.map(function (eachFilter) {
|
|
999
|
+
var _a;
|
|
1000
|
+
var column = handleFindColumn(eachFilter);
|
|
1001
|
+
return {
|
|
1002
|
+
key: eachFilter,
|
|
1003
|
+
label: (_a = column === null || column === void 0 ? void 0 : column.name) !== null && _a !== void 0 ? _a : eachFilter.charAt(0).toUpperCase() + eachFilter.slice(1),
|
|
1004
|
+
};
|
|
1005
|
+
})) !== null && _b !== void 0 ? _b : [];
|
|
562
1006
|
}
|
|
1007
|
+
// INFO: one measured column needs no picker — there is nothing to switch to
|
|
1008
|
+
var isFilter = options.length > 1;
|
|
1009
|
+
return (react_1.default.createElement("div", { className: "flex flex-col sm:flex-row gap-2 sm:ml-5 justify-ends" }, isFilter && (react_1.default.createElement(select_1.Select, { label: "", options: options, value: (_d = (_c = graphAnalyticsFilter[eachChart.title]) === null || _c === void 0 ? void 0 : _c.filter) !== null && _d !== void 0 ? _d : (options.length > 0 ? options[0].key : "-"), onChange: function (value) {
|
|
1010
|
+
handleUpdateChartData(index, value, "filter");
|
|
1011
|
+
} }))));
|
|
563
1012
|
};
|
|
564
|
-
var
|
|
565
|
-
var
|
|
566
|
-
|
|
1013
|
+
var renderChartError = function (item, error, spanClass) {
|
|
1014
|
+
var isOpen = !!detailsOpen[item.title];
|
|
1015
|
+
return (react_1.default.createElement("div", { className: spanClass },
|
|
1016
|
+
react_1.default.createElement("div", { className: "h-full rounded-lg bg-white p-5 shadow", "data-testid": "chart-error" },
|
|
1017
|
+
react_1.default.createElement("p", { className: "text-lg font-medium text-gray-900" }, item.title),
|
|
1018
|
+
react_1.default.createElement("div", { className: "mt-3 flex items-start gap-2" },
|
|
1019
|
+
react_1.default.createElement(solid_1.ExclamationTriangleIcon, { className: "mt-0.5 h-5 w-5 flex-shrink-0 text-amber-500" }),
|
|
1020
|
+
react_1.default.createElement("p", { className: "text-sm text-gray-700" }, error.message)),
|
|
1021
|
+
react_1.default.createElement("div", { className: "mt-3 flex items-center gap-4" },
|
|
1022
|
+
react_1.default.createElement(textButton_1.TextButton, { text: "Retry", onClick: function () { return handleRetryChart(item); } }),
|
|
1023
|
+
error.details && (react_1.default.createElement(textButton_1.TextButton, { text: isOpen ? "Hide details" : "Details", onClick: function () {
|
|
1024
|
+
return setDetailsOpen(function (prev) {
|
|
1025
|
+
var _a;
|
|
1026
|
+
return (__assign(__assign({}, prev), (_a = {}, _a[item.title] = !isOpen, _a)));
|
|
1027
|
+
});
|
|
1028
|
+
} }))),
|
|
1029
|
+
isOpen && error.details && (react_1.default.createElement("p", { className: "mt-2 break-words font-mono text-xs text-gray-500" }, error.details)))));
|
|
1030
|
+
};
|
|
1031
|
+
var renderChart = function (item, points, index, segments) {
|
|
1032
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1033
|
+
var spanClass = (_a = GRID_SPAN_CLASS[item.gridSize]) !== null && _a !== void 0 ? _a : "col-span-1";
|
|
1034
|
+
if (graphAnalyticsFilter[(_b = item.title) !== null && _b !== void 0 ? _b : ""] &&
|
|
567
1035
|
graphAnalyticsFilter[item.title].loading) {
|
|
568
|
-
return (react_1.default.createElement("div", { className: "
|
|
1036
|
+
return (react_1.default.createElement("div", { className: "".concat(spanClass, " flex items-center") },
|
|
569
1037
|
react_1.default.createElement(loading_1.Loading, null)));
|
|
570
1038
|
}
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
1039
|
+
var seriesData = points.map(function (eachPoint) { return ({
|
|
1040
|
+
x: eachPoint.x,
|
|
1041
|
+
y: eachPoint.y,
|
|
1042
|
+
}); });
|
|
1043
|
+
var pieSeries = points.map(function (eachPoint) { return eachPoint.y; });
|
|
1044
|
+
var pieLabels = points.map(function (eachPoint) { return eachPoint.x; });
|
|
1045
|
+
var isPercent = !!item.showPercent && !segments;
|
|
1046
|
+
var unit = isPercent ? "%" : undefined;
|
|
1047
|
+
// INFO: a chart bucketed by day, week or month covers a longer default
|
|
1048
|
+
// than the picker's own week, so the picker is told what was counted
|
|
1049
|
+
var customDate = (_d = (_c = graphAnalyticsFilter[item.title]) === null || _c === void 0 ? void 0 : _c.range) !== null && _d !== void 0 ? _d : (item.queryDateInterval && item.queryBaseDateId && !item.groupBy
|
|
1050
|
+
? handleResolveRange(item)
|
|
1051
|
+
: undefined);
|
|
1052
|
+
var handleClickPoint = function (label) {
|
|
1053
|
+
return handleDrillDown(item, points.find(function (eachPoint) { return eachPoint.x === label; }));
|
|
1054
|
+
};
|
|
1055
|
+
return (react_1.default.createElement("div", { className: spanClass },
|
|
1056
|
+
item.type === "card" && (react_1.default.createElement(card_1.Card, { icon: renderChartCardIcon(item.cardIcon, item.cardSize === "compact", item.cardEmoji), iconBgColor: item.cardIconBgColor, size: item.cardSize, title: item.title, description: (_e = item.description) !== null && _e !== void 0 ? _e : "", count: points.length > 0 ? points[0].y : 0, dateRangeVisible: item.queryBaseDateId ? true : false, customDate: customDate, onChangeDate: function (dateRange) {
|
|
1057
|
+
handleUpdateChartData(index, dateRange);
|
|
1058
|
+
} })),
|
|
1059
|
+
item.type === "pie" && (react_1.default.createElement(pieChart_1.PieChart, { title: item.title, type: item.pieType, series: pieSeries, labels: pieLabels, customDate: customDate, tool: renderChartOptionFilter(item, index), colors: item.colors, dateRangeVisible: item.queryBaseDateId ? true : false, onChangeDate: function (dateRange) {
|
|
1060
|
+
handleUpdateChartData(index, dateRange);
|
|
1061
|
+
}, onClick: props.onDrillDown
|
|
1062
|
+
? function (pointIndex) {
|
|
1063
|
+
return handleDrillDown(item, points[pointIndex]);
|
|
1064
|
+
}
|
|
1065
|
+
: undefined })),
|
|
1066
|
+
item.type === "bar" && (react_1.default.createElement(barChart_1.BarChart, { title: item.title, seriesName: "Value", seriesUnit: unit, seriesData: segments ? undefined : seriesData, categories: segments ? pieLabels : undefined, stackedBarSeries: segments, orientation: (_f = item.orientation) !== null && _f !== void 0 ? _f : "row", customDate: customDate, tool: renderChartOptionFilter(item, index), dateRangeVisible: item.queryBaseDateId ? true : false, onChangeDate: function (dateRange) {
|
|
1067
|
+
handleUpdateChartData(index, dateRange);
|
|
1068
|
+
}, colors: item.colors, stackedVertical: segments ? true : item.stackedVertical, distributed: !segments && item.colors && ((_g = item.colors) === null || _g === void 0 ? void 0 : _g.length) > 0
|
|
1069
|
+
? true
|
|
1070
|
+
: false, onClick: props.onDrillDown ? handleClickPoint : undefined })),
|
|
1071
|
+
item.type === "table" &&
|
|
1072
|
+
renderTableChart(item, points, index, customDate, segments),
|
|
1073
|
+
item.type === "line" && (react_1.default.createElement(lineChart_1.LineChart, { title: item.title, categories: pieLabels, seriesData: pieSeries, multiLineSeries: segments, seriesName: "Value", seriesUnit: unit, showDataLabels: true, xaxisTitle: "Date", yaxisTitle: "Value", containerStyle: "mb-10", customDate: customDate, tool: renderChartOptionFilter(item, index), dateRangeVisible: item.queryBaseDateId ? true : false, enableGradient: true, colors: item.colors, onChangeDate: function (dateRange) {
|
|
1074
|
+
handleUpdateChartData(index, dateRange);
|
|
1075
|
+
} }))));
|
|
601
1076
|
};
|
|
602
|
-
var renderTableChart = function (item,
|
|
603
|
-
var total =
|
|
1077
|
+
var renderTableChart = function (item, points, index, customDate, segments) {
|
|
1078
|
+
var total = points.reduce(function (sum, eachPoint) { return sum + eachPoint.y; }, 0);
|
|
604
1079
|
// INFO: a total of averages means nothing, so only count and sum get one
|
|
605
|
-
var showTotal = item.queryBaseType !== "avg";
|
|
1080
|
+
var showTotal = item.queryBaseType !== "avg" && !item.cumulative;
|
|
1081
|
+
var canDrill = !!props.onDrillDown;
|
|
1082
|
+
var isPercent = !!item.showPercent && !segments;
|
|
1083
|
+
var handleFormat = function (value) {
|
|
1084
|
+
return "".concat(Number.isInteger(value) ? value : value.toFixed(2)).concat(isPercent ? "%" : "");
|
|
1085
|
+
};
|
|
606
1086
|
return (react_1.default.createElement("div", { className: "h-full overflow-hidden rounded-lg bg-white p-5 shadow" },
|
|
607
1087
|
react_1.default.createElement("p", { className: "mb-3 text-lg font-medium text-gray-900" }, item.title),
|
|
608
|
-
react_1.default.createElement("
|
|
609
|
-
react_1.default.createElement("
|
|
610
|
-
react_1.default.createElement("
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
1088
|
+
react_1.default.createElement("div", { className: "overflow-x-auto" },
|
|
1089
|
+
react_1.default.createElement("table", { className: "min-w-full divide-y divide-gray-200 text-sm" },
|
|
1090
|
+
segments && (react_1.default.createElement("thead", null,
|
|
1091
|
+
react_1.default.createElement("tr", null,
|
|
1092
|
+
react_1.default.createElement("th", null),
|
|
1093
|
+
segments.map(function (eachSegment) { return (react_1.default.createElement("th", { key: eachSegment.name, className: "py-2 pl-4 text-right font-medium text-gray-500" }, eachSegment.name)); }),
|
|
1094
|
+
react_1.default.createElement("th", { className: "py-2 pl-4 text-right font-medium text-gray-500" }, "Total")))),
|
|
1095
|
+
react_1.default.createElement("tbody", { className: "divide-y divide-gray-100" }, points.map(function (eachPoint, pointIndex) { return (react_1.default.createElement("tr", { key: "".concat(pointIndex, "-").concat(eachPoint.x), className: canDrill && eachPoint.query
|
|
1096
|
+
? "cursor-pointer hover:bg-gray-50"
|
|
1097
|
+
: "", onClick: function () {
|
|
1098
|
+
return eachPoint.query && handleDrillDown(item, eachPoint);
|
|
1099
|
+
} },
|
|
1100
|
+
react_1.default.createElement("td", { className: "py-2 pr-4 text-gray-600" }, eachPoint.x), segments === null || segments === void 0 ? void 0 :
|
|
1101
|
+
segments.map(function (eachSegment) {
|
|
1102
|
+
var _a;
|
|
1103
|
+
return (react_1.default.createElement("td", { key: eachSegment.name, className: "py-2 pl-4 text-right text-gray-700" }, handleFormat((_a = eachSegment.data[pointIndex]) !== null && _a !== void 0 ? _a : 0)));
|
|
1104
|
+
}),
|
|
1105
|
+
react_1.default.createElement("td", { className: "py-2 pl-4 text-right font-medium text-gray-900" }, handleFormat(eachPoint.y)))); })),
|
|
1106
|
+
showTotal && !isPercent && (react_1.default.createElement("tfoot", null,
|
|
1107
|
+
react_1.default.createElement("tr", { className: "border-t border-gray-300" },
|
|
1108
|
+
react_1.default.createElement("td", { className: "py-2 pr-4 font-semibold text-gray-900" }, "Total"), segments === null || segments === void 0 ? void 0 :
|
|
1109
|
+
segments.map(function (eachSegment) { return (react_1.default.createElement("td", { key: eachSegment.name, className: "py-2 pl-4 text-right font-semibold text-gray-900" }, handleFormat(eachSegment.data.reduce(function (sum, each) { return sum + each; }, 0)))); }),
|
|
1110
|
+
react_1.default.createElement("td", { className: "py-2 pl-4 text-right font-semibold text-gray-900" }, handleFormat(Math.round(total * 100) / 100))))))),
|
|
616
1111
|
item.queryBaseDateId && (react_1.default.createElement(DateRange_1.DateRange, { customDate: customDate, onChangeDate: function (dateRange) {
|
|
617
1112
|
handleUpdateChartData(index, dateRange);
|
|
618
1113
|
}, className: "mt-3" }))));
|
|
619
1114
|
};
|
|
620
1115
|
var renderRadarChart = function (item, index) {
|
|
621
|
-
var _a;
|
|
1116
|
+
var _a, _b;
|
|
1117
|
+
var spanClass = (_a = GRID_SPAN_CLASS[item.gridSize]) !== null && _a !== void 0 ? _a : "col-span-1";
|
|
622
1118
|
if (!graphAnalyticsData[item.title]) {
|
|
623
|
-
return (react_1.default.createElement("div", { className: "
|
|
1119
|
+
return (react_1.default.createElement("div", { className: "".concat(spanClass, " flex items-center") },
|
|
624
1120
|
react_1.default.createElement(loading_1.Loading, null)));
|
|
625
1121
|
}
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
name: eachData.id,
|
|
632
|
-
data: Array.isArray(eachData.value)
|
|
633
|
-
? eachData.value
|
|
634
|
-
: [eachData.value],
|
|
635
|
-
});
|
|
636
|
-
return null;
|
|
1122
|
+
var radarData = [];
|
|
1123
|
+
graphAnalyticsData[item.title].forEach(function (eachData) {
|
|
1124
|
+
radarData.push({
|
|
1125
|
+
name: eachData.id,
|
|
1126
|
+
data: Array.isArray(eachData.value) ? eachData.value : [eachData.value],
|
|
637
1127
|
});
|
|
638
|
-
|
|
1128
|
+
});
|
|
1129
|
+
var labels = ((_b = item.queryAttributeId) !== null && _b !== void 0 ? _b : []).map(function (eachAttribute) { var _a, _b; return (_b = (_a = handleFindColumn(eachAttribute)) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : eachAttribute; });
|
|
1130
|
+
return (react_1.default.createElement("div", { className: spanClass },
|
|
1131
|
+
react_1.default.createElement(radarChart_1.RadarChart, { title: item.title, data: radarData, labels: labels, dateRangeVisible: item.queryBaseDateId ? true : false, onChangeDate: function (dateRange) {
|
|
639
1132
|
handleUpdateChartData(index, dateRange);
|
|
640
|
-
}, showLegend: true })))
|
|
1133
|
+
}, showLegend: true })));
|
|
1134
|
+
};
|
|
1135
|
+
var renderEachChart = function (eachChart, index) {
|
|
1136
|
+
var _a;
|
|
1137
|
+
var spanClass = (_a = GRID_SPAN_CLASS[eachChart.gridSize]) !== null && _a !== void 0 ? _a : "col-span-1";
|
|
1138
|
+
var error = graphAnalyticsError[eachChart.title];
|
|
1139
|
+
if (error)
|
|
1140
|
+
return renderChartError(eachChart, error, spanClass);
|
|
1141
|
+
if (eachChart.type === "radar")
|
|
1142
|
+
return renderRadarChart(eachChart, index);
|
|
1143
|
+
if ((0, exports.handleIsShapedChart)(eachChart)) {
|
|
1144
|
+
var series = graphSeries[eachChart.title];
|
|
1145
|
+
if (!series)
|
|
1146
|
+
return (react_1.default.createElement("div", { className: "".concat(spanClass, " flex items-center") },
|
|
1147
|
+
react_1.default.createElement(loading_1.Loading, null)));
|
|
1148
|
+
return renderChart(eachChart, series.points, index, series.segments);
|
|
641
1149
|
}
|
|
1150
|
+
return renderChart(eachChart, handleBuildLegacyPoints(eachChart), index);
|
|
642
1151
|
};
|
|
643
1152
|
var renderCharts = function () {
|
|
644
1153
|
var _a;
|
|
645
1154
|
return (react_1.default.createElement(react_1.default.Fragment, null, (_a = props.charts) === null || _a === void 0 ? void 0 : _a.map(function (eachChart, index) {
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
652
|
-
var title = eachData._id;
|
|
653
|
-
var dates = (_b = (_a = eachData._id) === null || _a === void 0 ? void 0 : _a.split("-")) !== null && _b !== void 0 ? _b : [];
|
|
654
|
-
if (dates.length === 2) {
|
|
655
|
-
var format = "DD/MM/YY";
|
|
656
|
-
if (graphAnalyticsFilter[(_c = eachChart.title) !== null && _c !== void 0 ? _c : ""] &&
|
|
657
|
-
graphAnalyticsFilter[(_d = eachChart.title) !== null && _d !== void 0 ? _d : ""].range &&
|
|
658
|
-
(0, dayjs_1.default)(graphAnalyticsFilter[(_e = eachChart.title) !== null && _e !== void 0 ? _e : ""].range
|
|
659
|
-
.startDate).isSame((0, dayjs_1.default)(graphAnalyticsFilter[(_f = eachChart.title) !== null && _f !== void 0 ? _f : ""].range
|
|
660
|
-
.endDate), "day")) {
|
|
661
|
-
format = "HH:mm";
|
|
662
|
-
}
|
|
663
|
-
var startDate = (0, dayjs_1.default)(dates[0], "DD/MM/YYYY HH:mm:ss").format(format);
|
|
664
|
-
var endDate = (0, dayjs_1.default)(dates[1], "DD/MM/YYYY HH:mm:ss").format(format);
|
|
665
|
-
title = "".concat(startDate, " - ").concat(endDate);
|
|
666
|
-
}
|
|
667
|
-
var seriesLabel = (_g = eachChart.seriesLabels) === null || _g === void 0 ? void 0 : _g[index];
|
|
668
|
-
if (seriesLabel && eachChart.type !== "line") {
|
|
669
|
-
title = seriesLabel;
|
|
670
|
-
}
|
|
671
|
-
else if (selectedChart_1 &&
|
|
672
|
-
Array.isArray(selectedChart_1) &&
|
|
673
|
-
eachChart.type !== "line") {
|
|
674
|
-
var queryId = (_j = (_h = selectedChart_1[index]) === null || _h === void 0 ? void 0 : _h.queryId) !== null && _j !== void 0 ? _j : "";
|
|
675
|
-
var type = (_l = (_k = selectedChart_1[index]) === null || _k === void 0 ? void 0 : _k.type) !== null && _l !== void 0 ? _l : "";
|
|
676
|
-
var value = (_o = (_m = selectedChart_1[index]) === null || _m === void 0 ? void 0 : _m.value) !== null && _o !== void 0 ? _o : "";
|
|
677
|
-
title =
|
|
678
|
-
queryId && type && value
|
|
679
|
-
? "".concat(queryId, " ").concat(type, " ").concat(value)
|
|
680
|
-
: title;
|
|
681
|
-
}
|
|
682
|
-
seriesData_1.push({
|
|
683
|
-
x: title,
|
|
684
|
-
y: Number(eachData.value) % 1 !== 0
|
|
685
|
-
? Number(eachData.value).toFixed(2)
|
|
686
|
-
: eachData.value,
|
|
687
|
-
});
|
|
688
|
-
return null;
|
|
689
|
-
});
|
|
690
|
-
}
|
|
691
|
-
return renderChart(eachChart, seriesData_1, index);
|
|
692
|
-
}
|
|
693
|
-
else {
|
|
694
|
-
return renderRadarChart(eachChart, index);
|
|
695
|
-
}
|
|
1155
|
+
var _a;
|
|
1156
|
+
return (react_1.default.createElement(chartErrorBoundary_1.ChartErrorBoundary, { key: "".concat(index, "-").concat(eachChart.title), resetKey: "".concat((_a = retryCount[eachChart.title]) !== null && _a !== void 0 ? _a : 0, "-").concat(JSON.stringify(eachChart)), renderFallback: function (drawError) {
|
|
1157
|
+
var _a;
|
|
1158
|
+
return renderChartError(eachChart, { message: chartErrors_1.CHART_DRAW_FAILED, details: drawError.message }, (_a = GRID_SPAN_CLASS[eachChart.gridSize]) !== null && _a !== void 0 ? _a : "col-span-1");
|
|
1159
|
+
} }, renderEachChart(eachChart, index)));
|
|
696
1160
|
})));
|
|
697
1161
|
};
|
|
698
1162
|
var gridSize = "grid-cols-1 sm:grid-cols-2 lg:grid-cols-4";
|