@ministryofjustice/hmpps-digital-prison-reporting-frontend 4.28.8 → 4.29.1
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/dpr/all.js +6 -8
- package/dpr/all.js.map +3 -3
- package/dpr/all.scss +296 -414
- package/dpr/all.ts +6 -11
- package/dpr/components/_catalogue/catalogue-list/utils.test.ts +1 -1
- package/dpr/components/_charts/chart/ChartTimeseries.js +3 -2
- package/dpr/components/_charts/chart/ChartTimeseries.js.map +2 -2
- package/dpr/components/_charts/chart/ChartTimeseries.ts +4 -2
- package/dpr/components/_charts/chart/clientClass.js +1 -0
- package/dpr/components/_charts/chart/clientClass.js.map +2 -2
- package/dpr/components/_charts/chart/clientClass.ts +1 -0
- package/dpr/components/_reports/{report-actions → report-heading/report-actions}/actionsTemplate.js.map +1 -1
- package/dpr/components/_reports/{report-actions → report-heading/report-actions}/clientClass.js +1 -1
- package/dpr/components/_reports/report-heading/report-actions/clientClass.js.map +7 -0
- package/dpr/components/_reports/{report-actions → report-heading/report-actions}/clientClass.ts +1 -1
- package/dpr/components/_reports/report-heading/report-actions/types.d.js.map +7 -0
- package/dpr/components/_reports/{report-actions → report-heading/report-actions}/types.d.ts +1 -1
- package/dpr/components/_reports/{report-actions → report-heading/report-actions}/utils.js.map +1 -1
- package/dpr/components/_reports/{report-actions → report-heading/report-actions}/utils.test.ts +2 -2
- package/dpr/components/_reports/{report-columns-form → report-heading/report-columns/report-columns-form}/clientClass.js +1 -3
- package/dpr/components/_reports/report-heading/report-columns/report-columns-form/clientClass.js.map +7 -0
- package/dpr/components/_reports/{report-columns-form → report-heading/report-columns/report-columns-form}/clientClass.ts +1 -3
- package/dpr/components/_reports/{report-columns-form → report-heading/report-columns/report-columns-form}/types.d.js.map +1 -1
- package/dpr/components/_reports/{report-columns-form → report-heading/report-columns/report-columns-form}/utils.js +1 -1
- package/dpr/components/_reports/report-heading/report-columns/report-columns-form/utils.js.map +7 -0
- package/dpr/components/_reports/{report-columns-form → report-heading/report-columns/report-columns-form}/utils.ts +2 -2
- package/dpr/components/_reports/{report-columns → report-heading/report-columns}/view.njk +1 -1
- package/dpr/components/_reports/{report-download-message → report-heading/report-download-message}/clientClass.js +1 -1
- package/dpr/components/_reports/report-heading/report-download-message/clientClass.js.map +7 -0
- package/dpr/components/_reports/{report-download-message → report-heading/report-download-message}/clientClass.ts +1 -1
- package/dpr/components/_reports/{report-filters → report-heading/report-filters}/view.njk +1 -1
- package/dpr/components/_reports/report-heading/view.njk +4 -4
- package/dpr/components/_reports/report-page/report-print-message/view.njk +10 -0
- package/dpr/components/_reports/report-page/report-template/report-no-data-message/styles.scss +8 -0
- package/dpr/components/_reports/report-page/report-template/report-no-data-message/view.njk +11 -0
- package/dpr/components/_reports/{report-pagination → report-page/report-template/report-pagination}/clientClass.js +1 -1
- package/dpr/components/_reports/report-page/report-template/report-pagination/clientClass.js.map +7 -0
- package/dpr/components/_reports/{report-pagination → report-page/report-template/report-pagination}/clientClass.ts +1 -1
- package/dpr/components/_reports/{report-pagination → report-page/report-template/report-pagination}/types.d.js.map +1 -1
- package/dpr/components/_reports/{report-pagination → report-page/report-template/report-pagination}/utils.js.map +1 -1
- package/dpr/components/_reports/report-page/report-template/report-section/parent-child-template/styles.scss +88 -0
- package/dpr/components/_reports/report-page/report-template/report-section/parent-child-template/view.njk +29 -0
- package/dpr/components/_reports/{report-data-table → report-page/report-template/report-section/report-data-table}/clientClass.js +17 -10
- package/dpr/components/_reports/report-page/report-template/report-section/report-data-table/clientClass.js.map +7 -0
- package/dpr/components/_reports/{report-data-table → report-page/report-template/report-section/report-data-table}/clientClass.ts +20 -10
- package/dpr/components/_reports/{report-data-table → report-page/report-template/report-section/report-data-table}/style.scss +35 -185
- package/dpr/components/_reports/report-page/report-template/report-section/report-data-table/types.d.js.map +7 -0
- package/dpr/components/_reports/{report-data-table → report-page/report-template/report-section/report-data-table}/types.d.ts +2 -2
- package/dpr/components/_reports/report-page/report-template/report-section/report-data-table/view.njk +27 -0
- package/dpr/components/_reports/report-page/report-template/report-section/styles.scss +33 -0
- package/dpr/components/_reports/report-page/report-template/report-section/view.njk +58 -0
- package/dpr/components/_reports/{report-summary-table → report-page/report-template/report-summary-table}/styles.scss +21 -4
- package/dpr/components/_reports/{report-totals → report-page/report-template/report-totals}/utils.js.map +1 -1
- package/dpr/components/_reports/report-page/report-template/styles.scss +5 -0
- package/dpr/components/_reports/report-page/report-template/template-config.js +66 -0
- package/dpr/components/_reports/report-page/report-template/template-config.js.map +7 -0
- package/dpr/components/_reports/report-page/report-template/template-config.ts +45 -0
- package/dpr/components/_reports/report-page/report-template/utils.js +82 -0
- package/dpr/components/_reports/report-page/report-template/utils.js.map +7 -0
- package/dpr/components/_reports/report-page/report-template/utils.ts +100 -0
- package/dpr/components/_reports/report-page/report-template/view.njk +61 -0
- package/dpr/components/_reports/{report-wrapper → report-page}/styles.scss +7 -5
- package/dpr/components/_reports/report-page/view.njk +26 -0
- package/dpr/components/card-group/view.njk +0 -4
- package/dpr/components/report-list/utils.js +11 -3
- package/dpr/components/report-list/utils.js.map +2 -2
- package/dpr/components/report-list/utils.ts +11 -1
- package/dpr/components/report-list/view.njk +2 -2
- package/dpr/components/show-more/style.scss +3 -4
- package/dpr/data/reportingClient.js.map +2 -2
- package/dpr/data/reportingClient.ts +4 -4
- package/dpr/routes/journeys/view-report/async/dashboard/utils.js +1 -1
- package/dpr/routes/journeys/view-report/async/dashboard/utils.js.map +1 -1
- package/dpr/routes/journeys/view-report/async/dashboard/utils.ts +1 -1
- package/dpr/routes/journeys/view-report/async/report/controller.js.map +2 -2
- package/dpr/routes/journeys/view-report/async/report/controller.ts +0 -1
- package/dpr/routes/journeys/view-report/async/report/report-variants.cy.js +207 -56
- package/dpr/routes/journeys/view-report/async/report/report-variants.cy.js.map +2 -2
- package/dpr/routes/journeys/view-report/async/report/report-variants.cy.ts +333 -64
- package/dpr/routes/journeys/view-report/async/report/utils.js +9 -17
- package/dpr/routes/journeys/view-report/async/report/utils.js.map +3 -3
- package/dpr/routes/journeys/view-report/async/report/utils.ts +12 -22
- package/dpr/routes/journeys/view-report/report.njk +2 -2
- package/dpr/routes/journeys/view-report/sync/dashboard/utils.js +1 -1
- package/dpr/routes/journeys/view-report/sync/dashboard/utils.js.map +1 -1
- package/dpr/routes/journeys/view-report/sync/dashboard/utils.ts +1 -1
- package/dpr/routes/journeys/view-report/sync/report/utils.js +38 -11
- package/dpr/routes/journeys/view-report/sync/report/utils.js.map +3 -3
- package/dpr/routes/journeys/view-report/sync/report/utils.ts +39 -14
- package/dpr/routes/journeys/view-report/utils.js +1 -1
- package/dpr/routes/journeys/view-report/utils.js.map +1 -1
- package/dpr/routes/journeys/view-report/utils.ts +1 -1
- package/dpr/services/reportingService.js.map +2 -2
- package/dpr/services/reportingService.ts +2 -2
- package/dpr/types/ReportQuery.js +1 -1
- package/dpr/types/ReportQuery.js.map +1 -1
- package/dpr/types/ReportQuery.ts +1 -1
- package/dpr/types/UserReports.js.map +1 -1
- package/dpr/types/UserReports.ts +3 -3
- package/dpr/utils/TemplateBuilder/ParentChildDataBuilder/ParentChildDataBuilder.js +193 -0
- package/dpr/utils/TemplateBuilder/ParentChildDataBuilder/ParentChildDataBuilder.js.map +7 -0
- package/dpr/utils/TemplateBuilder/ParentChildDataBuilder/ParentChildDataBuilder.ts +203 -0
- package/dpr/utils/TemplateBuilder/ParentChildDataBuilder/types.d.js.map +7 -0
- package/dpr/utils/TemplateBuilder/ParentChildDataBuilder/types.d.ts +36 -0
- package/dpr/utils/TemplateBuilder/ReportBuilder/ReportBuilder.js +114 -0
- package/dpr/utils/TemplateBuilder/ReportBuilder/ReportBuilder.js.map +7 -0
- package/dpr/utils/TemplateBuilder/ReportBuilder/ReportBuilder.ts +117 -0
- package/dpr/utils/TemplateBuilder/ReportBuilder/types.d.js.map +7 -0
- package/dpr/utils/TemplateBuilder/ReportBuilder/types.d.ts +6 -0
- package/dpr/utils/TemplateBuilder/SectionedDataHelper/SectionedDataHelper.js +202 -0
- package/dpr/utils/TemplateBuilder/SectionedDataHelper/SectionedDataHelper.js.map +7 -0
- package/dpr/utils/TemplateBuilder/SectionedDataHelper/SectionedDataHelper.ts +246 -0
- package/dpr/utils/TemplateBuilder/SectionedDataHelper/types.js +17 -0
- package/dpr/utils/TemplateBuilder/SectionedDataHelper/types.js.map +7 -0
- package/dpr/utils/TemplateBuilder/SectionedDataHelper/types.ts +41 -0
- package/dpr/utils/{CollatedSummaryBuilder/CollatedSummaryBuilder.js → TemplateBuilder/SummaryDataHelper/SummaryDataHelper.js} +6 -8
- package/dpr/utils/TemplateBuilder/SummaryDataHelper/SummaryDataHelper.js.map +7 -0
- package/dpr/utils/{CollatedSummaryBuilder/CollatedSummaryBuilder.test.ts → TemplateBuilder/SummaryDataHelper/SummaryDataHelper.test.ts} +4 -4
- package/dpr/utils/{CollatedSummaryBuilder/CollatedSummaryBuilder.ts → TemplateBuilder/SummaryDataHelper/SummaryDataHelper.ts} +6 -9
- package/dpr/utils/TemplateBuilder/TemplateBuilder.js +74 -0
- package/dpr/utils/TemplateBuilder/TemplateBuilder.js.map +7 -0
- package/dpr/utils/TemplateBuilder/TemplateBuilder.ts +68 -0
- package/dpr/utils/definitionUtils.js +22 -2
- package/dpr/utils/definitionUtils.js.map +2 -2
- package/dpr/utils/definitionUtils.ts +26 -1
- package/package.json +1 -1
- package/dpr/DprLoadingHelper.js +0 -51
- package/dpr/DprLoadingHelper.js.map +0 -7
- package/dpr/DprLoadingHelper.ts +0 -27
- package/dpr/components/_reports/report/view.njk +0 -40
- package/dpr/components/_reports/report-actions/clientClass.js.map +0 -7
- package/dpr/components/_reports/report-actions/types.d.js.map +0 -7
- package/dpr/components/_reports/report-columns-form/clientClass.js.map +0 -7
- package/dpr/components/_reports/report-columns-form/utils.js.map +0 -7
- package/dpr/components/_reports/report-data-table/clientClass.js.map +0 -7
- package/dpr/components/_reports/report-data-table/types.d.js.map +0 -7
- package/dpr/components/_reports/report-data-table/utils.js +0 -123
- package/dpr/components/_reports/report-data-table/utils.js.map +0 -7
- package/dpr/components/_reports/report-data-table/utils.test.ts +0 -604
- package/dpr/components/_reports/report-data-table/utils.ts +0 -150
- package/dpr/components/_reports/report-data-table/view.njk +0 -24
- package/dpr/components/_reports/report-data-table-wrapper/view.njk +0 -27
- package/dpr/components/_reports/report-download-message/clientClass.js.map +0 -7
- package/dpr/components/_reports/report-no-data-message/styles.scss +0 -4
- package/dpr/components/_reports/report-no-data-message/view.njk +0 -13
- package/dpr/components/_reports/report-pagination/clientClass.js.map +0 -7
- package/dpr/components/_reports/report-print-message/view.njk +0 -8
- package/dpr/components/_reports/report-template/view.njk +0 -44
- package/dpr/components/_reports/report-wrapper/view.njk +0 -19
- package/dpr/components/loading-anim/styles.scss +0 -117
- package/dpr/components/loading-anim/view.njk +0 -18
- package/dpr/utils/CollatedSummaryBuilder/CollatedSummaryBuilder.js.map +0 -7
- package/dpr/utils/ParentChildDataTableBuilder/ParentChildDataTableBuilder.js +0 -202
- package/dpr/utils/ParentChildDataTableBuilder/ParentChildDataTableBuilder.js.map +0 -7
- package/dpr/utils/ParentChildDataTableBuilder/ParentChildDataTableBuilder.test.ts +0 -503
- package/dpr/utils/ParentChildDataTableBuilder/ParentChildDataTableBuilder.ts +0 -224
- package/dpr/utils/ParentChildDataTableBuilder/types.d.js.map +0 -7
- package/dpr/utils/ParentChildDataTableBuilder/types.d.ts +0 -11
- package/dpr/utils/SectionedDataTableBuilder/SectionedDataTableBuilder.js +0 -311
- package/dpr/utils/SectionedDataTableBuilder/SectionedDataTableBuilder.js.map +0 -7
- package/dpr/utils/SectionedDataTableBuilder/SectionedDataTableBuilder.test.ts +0 -492
- package/dpr/utils/SectionedDataTableBuilder/SectionedDataTableBuilder.ts +0 -342
- package/dpr/utils/SectionedDataTableBuilder/types.d.js.map +0 -7
- package/dpr/utils/SectionedDataTableBuilder/types.d.ts +0 -5
- package/dpr/utils/SectionedFieldsTableBuilder/SectionedFieldsTableBuilder.js +0 -146
- package/dpr/utils/SectionedFieldsTableBuilder/SectionedFieldsTableBuilder.js.map +0 -7
- package/dpr/utils/SectionedFieldsTableBuilder/SectionedFieldsTableBuilder.test.ts +0 -140
- package/dpr/utils/SectionedFieldsTableBuilder/SectionedFieldsTableBuilder.ts +0 -150
- /package/dpr/components/_reports/{report-actions → report-heading/report-actions}/actionsTemplate.js +0 -0
- /package/dpr/components/_reports/{report-actions → report-heading/report-actions}/actionsTemplate.ts +0 -0
- /package/dpr/components/_reports/{report-actions → report-heading/report-actions}/style.scss +0 -0
- /package/dpr/components/_reports/{report-actions → report-heading/report-actions}/types.d.js +0 -0
- /package/dpr/components/_reports/{report-actions → report-heading/report-actions}/utils.js +0 -0
- /package/dpr/components/_reports/{report-actions → report-heading/report-actions}/utils.ts +0 -0
- /package/dpr/components/_reports/{report-actions → report-heading/report-actions}/view.njk +0 -0
- /package/dpr/components/_reports/{report-columns-form → report-heading/report-columns/report-columns-form}/style.scss +0 -0
- /package/dpr/components/_reports/{report-columns-form → report-heading/report-columns/report-columns-form}/types.d.js +0 -0
- /package/dpr/components/_reports/{report-columns-form → report-heading/report-columns/report-columns-form}/types.d.ts +0 -0
- /package/dpr/components/_reports/{report-columns-form → report-heading/report-columns/report-columns-form}/view.njk +0 -0
- /package/dpr/components/_reports/{report-columns → report-heading/report-columns}/styles.scss +0 -0
- /package/dpr/components/_reports/{report-download-message → report-heading/report-download-message}/style.scss +0 -0
- /package/dpr/components/_reports/{report-download-message → report-heading/report-download-message}/view.njk +0 -0
- /package/dpr/components/_reports/{report-pagination → report-page/report-template/report-pagination}/style.scss +0 -0
- /package/dpr/components/_reports/{report-data-table → report-page/report-template/report-pagination}/types.d.js +0 -0
- /package/dpr/components/_reports/{report-pagination → report-page/report-template/report-pagination}/types.d.ts +0 -0
- /package/dpr/components/_reports/{report-pagination → report-page/report-template/report-pagination}/utils.js +0 -0
- /package/dpr/components/_reports/{report-pagination → report-page/report-template/report-pagination}/utils.test.ts +0 -0
- /package/dpr/components/_reports/{report-pagination → report-page/report-template/report-pagination}/utils.ts +0 -0
- /package/dpr/components/_reports/{report-pagination → report-page/report-template/report-pagination}/view.njk +0 -0
- /package/dpr/components/_reports/{report-pagination → report-page/report-template/report-section/report-data-table}/types.d.js +0 -0
- /package/dpr/components/_reports/{report-summary-table → report-page/report-template/report-summary-table}/view.njk +0 -0
- /package/dpr/components/_reports/{report-totals → report-page/report-template/report-totals}/style.scss +0 -0
- /package/dpr/components/_reports/{report-totals → report-page/report-template/report-totals}/utils.js +0 -0
- /package/dpr/components/_reports/{report-totals → report-page/report-template/report-totals}/utils.ts +0 -0
- /package/dpr/components/_reports/{report-totals → report-page/report-template/report-totals}/view.njk +0 -0
- /package/dpr/utils/{ParentChildDataTableBuilder → TemplateBuilder/ParentChildDataBuilder}/types.d.js +0 -0
- /package/dpr/utils/{SectionedDataTableBuilder → TemplateBuilder/ReportBuilder}/types.d.js +0 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var ReportBuilder_exports = {};
|
|
30
|
+
__export(ReportBuilder_exports, {
|
|
31
|
+
ReportBuilder: () => ReportBuilder
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(ReportBuilder_exports);
|
|
34
|
+
var import_SummaryDataHelper = require("../SummaryDataHelper/SummaryDataHelper");
|
|
35
|
+
var import_DataTableBuilder = __toESM(require("../../DataTableBuilder/DataTableBuilder"));
|
|
36
|
+
var import_SectionedDataHelper = require("../SectionedDataHelper/SectionedDataHelper");
|
|
37
|
+
var import_TemplateBuilder = require("../TemplateBuilder");
|
|
38
|
+
class ReportBuilder extends import_TemplateBuilder.TemplateBuilder {
|
|
39
|
+
dataTableBuilder;
|
|
40
|
+
sectionBuilder;
|
|
41
|
+
constructor(variant) {
|
|
42
|
+
super(variant);
|
|
43
|
+
}
|
|
44
|
+
buildMainTable(section) {
|
|
45
|
+
const collatedSummaryBuilder = new import_SummaryDataHelper.CollatedSummaryBuilder(this.specification, section.summaries);
|
|
46
|
+
const tableSummaries = collatedSummaryBuilder.collateDataTableSummaries();
|
|
47
|
+
this.dataTableBuilder = new import_DataTableBuilder.default(this.fields);
|
|
48
|
+
return this.dataTableBuilder.withSummaries(tableSummaries).withHeaderOptions({
|
|
49
|
+
columns: this.columns,
|
|
50
|
+
reportQuery: this.reportQuery,
|
|
51
|
+
interactive: Boolean(this.interactive)
|
|
52
|
+
}).buildTable(section.data);
|
|
53
|
+
}
|
|
54
|
+
buildSummaryTables(summaries) {
|
|
55
|
+
const summaryTables = summaries.map((summaryData) => {
|
|
56
|
+
const fields = summaryData.fields;
|
|
57
|
+
const { data, template } = summaryData;
|
|
58
|
+
const summaryTableData = new import_DataTableBuilder.default(fields).withNoHeaderOptions(fields.map((f) => f.name)).buildTable(data);
|
|
59
|
+
return {
|
|
60
|
+
template,
|
|
61
|
+
data: summaryTableData
|
|
62
|
+
};
|
|
63
|
+
});
|
|
64
|
+
return this.groupSummaryTables(summaryTables);
|
|
65
|
+
}
|
|
66
|
+
buildSummariesTables(section) {
|
|
67
|
+
const { summaries } = section;
|
|
68
|
+
const summaryTables = summaries.map((summaryData) => {
|
|
69
|
+
const fields = summaryData.fields;
|
|
70
|
+
const { data, template } = summaryData;
|
|
71
|
+
const summaryTableData = new import_DataTableBuilder.default(fields).withNoHeaderOptions(fields.map((f) => f.name)).buildTable(data);
|
|
72
|
+
return {
|
|
73
|
+
template,
|
|
74
|
+
data: summaryTableData
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
return this.groupSummaryTables(summaryTables);
|
|
78
|
+
}
|
|
79
|
+
groupSummaryTables(summaryTables) {
|
|
80
|
+
return summaryTables.reduce((acc, item) => {
|
|
81
|
+
if (!acc[item.template]) {
|
|
82
|
+
acc[item.template] = [];
|
|
83
|
+
}
|
|
84
|
+
acc[item.template].push(item.data);
|
|
85
|
+
return acc;
|
|
86
|
+
}, {});
|
|
87
|
+
}
|
|
88
|
+
buildSectionedData() {
|
|
89
|
+
const sectionData = new import_SectionedDataHelper.SectionedDataHelper().withData(this.data).withSections(this.sections).withSummaries(this.summaries).withFields(this.fields).withReportQuery(this.reportQuery).build();
|
|
90
|
+
return sectionData.sections.map((section) => {
|
|
91
|
+
const tableData = this.buildMainTable(section);
|
|
92
|
+
const sectionSummaryTables = this.buildSummaryTables(section.summaries);
|
|
93
|
+
return {
|
|
94
|
+
...section,
|
|
95
|
+
summaries: sectionSummaryTables,
|
|
96
|
+
data: tableData
|
|
97
|
+
};
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
build() {
|
|
101
|
+
const pageSummaryTables = this.buildSummaryTables(this.pageSummaries);
|
|
102
|
+
const sections = this.buildSectionedData();
|
|
103
|
+
return {
|
|
104
|
+
rowCount: this.data.length,
|
|
105
|
+
summaries: pageSummaryTables,
|
|
106
|
+
sections
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
111
|
+
0 && (module.exports = {
|
|
112
|
+
ReportBuilder
|
|
113
|
+
});
|
|
114
|
+
//# sourceMappingURL=ReportBuilder.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../dpr/utils/TemplateBuilder/ReportBuilder/ReportBuilder.ts"],
|
|
4
|
+
"sourcesContent": ["import { AsyncSummary } from '../../../types/UserReports'\nimport { SummaryTemplate } from '../../../types/Templates'\nimport { components } from '../../../types/api'\nimport { CollatedSummaryBuilder } from '../SummaryDataHelper/SummaryDataHelper'\nimport DataTableBuilder from '../../DataTableBuilder/DataTableBuilder'\nimport { SectionedDataHelper } from '../SectionedDataHelper/SectionedDataHelper'\nimport { ReportTemplateData, SectionData } from '../SectionedDataHelper/types'\nimport { DataTable } from '../../DataTableBuilder/types'\nimport { TemplateBuilder } from '../TemplateBuilder'\n\nexport class ReportBuilder extends TemplateBuilder {\n dataTableBuilder!: DataTableBuilder\n\n sectionBuilder!: SectionedDataHelper\n\n constructor(variant: components['schemas']['VariantDefinition']) {\n super(variant)\n }\n\n buildMainTable(section: SectionData) {\n const collatedSummaryBuilder = new CollatedSummaryBuilder(this.specification, section.summaries)\n const tableSummaries = collatedSummaryBuilder.collateDataTableSummaries()\n this.dataTableBuilder = new DataTableBuilder(this.fields)\n return this.dataTableBuilder\n .withSummaries(tableSummaries)\n .withHeaderOptions({\n columns: this.columns,\n reportQuery: this.reportQuery,\n interactive: Boolean(this.interactive),\n })\n .buildTable(section.data)\n }\n\n buildSummaryTables(summaries: AsyncSummary[]) {\n const summaryTables = summaries.map((summaryData) => {\n const fields = <components['schemas']['FieldDefinition'][]>summaryData.fields\n const { data, template } = summaryData\n const summaryTableData = new DataTableBuilder(fields)\n .withNoHeaderOptions(fields.map((f) => f.name))\n .buildTable(data)\n\n return {\n template,\n data: summaryTableData,\n }\n })\n\n return this.groupSummaryTables(summaryTables)\n }\n\n buildSummariesTables(section: SectionData) {\n const { summaries } = section\n const summaryTables: {\n template: SummaryTemplate\n data: DataTable\n }[] = summaries.map((summaryData) => {\n const fields = <components['schemas']['FieldDefinition'][]>summaryData.fields\n const { data, template } = summaryData\n const summaryTableData = new DataTableBuilder(fields)\n .withNoHeaderOptions(fields.map((f) => f.name))\n .buildTable(data)\n\n return {\n template,\n data: summaryTableData,\n }\n })\n\n return this.groupSummaryTables(summaryTables)\n }\n\n groupSummaryTables(\n summaryTables: {\n template: SummaryTemplate\n data: DataTable\n }[],\n ) {\n return summaryTables.reduce<Record<string, DataTable[]>>((acc, item) => {\n if (!acc[item.template]) {\n acc[item.template] = []\n }\n acc[item.template].push(item.data)\n return acc\n }, {})\n }\n\n buildSectionedData() {\n const sectionData = new SectionedDataHelper()\n .withData(this.data)\n .withSections(this.sections)\n .withSummaries(this.summaries)\n .withFields(this.fields)\n .withReportQuery(this.reportQuery)\n .build()\n\n return sectionData.sections.map((section: SectionData) => {\n const tableData = this.buildMainTable(section)\n const sectionSummaryTables = this.buildSummaryTables(section.summaries)\n return {\n ...section,\n summaries: sectionSummaryTables,\n data: tableData,\n }\n })\n }\n\n build(): ReportTemplateData {\n const pageSummaryTables = this.buildSummaryTables(this.pageSummaries)\n const sections = this.buildSectionedData()\n\n return {\n rowCount: this.data.length,\n summaries: pageSummaryTables,\n sections,\n }\n }\n}\n"],
|
|
5
|
+
"m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M,EAAE,IAAI,CAAC,EAC7C,WAAW,IAAI;AAElB,aAAO;AAAA,QACL;AAAA,QACA,MAAM;AAAA,MACR;AAAA,IACF,CAAC;AAED,WAAO,KAAK,mBAAmB,aAAa;AAAA,EAC9C;AAAA,EAEA,mBACE,eAIA;AACA,WAAO,cAAc,OAAoC,CAAC,KAAK,SAAS;AACtE,UAAI,CAAC,IAAI,KAAK,QAAQ,GAAG;AACvB,YAAI,KAAK,QAAQ,IAAI,CAAC;AAAA,MACxB;AACA,UAAI,KAAK,QAAQ,EAAE,KAAK,KAAK,IAAI;AACjC,aAAO;AAAA,IACT,GAAG,CAAC,CAAC;AAAA,EACP;AAAA,EAEA,qBAAqB;AACnB,UAAM,cAAc,IAAI,+CAAoB,EACzC,SAAS,KAAK,IAAI,EAClB,aAAa,KAAK,QAAQ,EAC1B,cAAc,KAAK,SAAS,EAC5B,WAAW,KAAK,MAAM,EACtB,gBAAgB,KAAK,WAAW,EAChC,MAAM;AAET,WAAO,YAAY,SAAS,IAAI,CAAC,YAAyB;AACxD,YAAM,YAAY,KAAK,eAAe,OAAO;AAC7C,YAAM,uBAAuB,KAAK,mBAAmB,QAAQ,SAAS;AACtE,aAAO;AAAA,QACL,GAAG;AAAA,QACH,WAAW;AAAA,QACX,MAAM;AAAA,MACR;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEA,QAA4B;AAC1B,UAAM,oBAAoB,KAAK,mBAAmB,KAAK,aAAa;AACpE,UAAM,WAAW,KAAK,mBAAmB;AAEzC,WAAO;AAAA,MACL,UAAU,KAAK,KAAK;AAAA,MACpB,WAAW;AAAA,MACX;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
|
+
"names": ["DataTableBuilder"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { AsyncSummary } from '../../../types/UserReports'
|
|
2
|
+
import { SummaryTemplate } from '../../../types/Templates'
|
|
3
|
+
import { components } from '../../../types/api'
|
|
4
|
+
import { CollatedSummaryBuilder } from '../SummaryDataHelper/SummaryDataHelper'
|
|
5
|
+
import DataTableBuilder from '../../DataTableBuilder/DataTableBuilder'
|
|
6
|
+
import { SectionedDataHelper } from '../SectionedDataHelper/SectionedDataHelper'
|
|
7
|
+
import { ReportTemplateData, SectionData } from '../SectionedDataHelper/types'
|
|
8
|
+
import { DataTable } from '../../DataTableBuilder/types'
|
|
9
|
+
import { TemplateBuilder } from '../TemplateBuilder'
|
|
10
|
+
|
|
11
|
+
export class ReportBuilder extends TemplateBuilder {
|
|
12
|
+
dataTableBuilder!: DataTableBuilder
|
|
13
|
+
|
|
14
|
+
sectionBuilder!: SectionedDataHelper
|
|
15
|
+
|
|
16
|
+
constructor(variant: components['schemas']['VariantDefinition']) {
|
|
17
|
+
super(variant)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
buildMainTable(section: SectionData) {
|
|
21
|
+
const collatedSummaryBuilder = new CollatedSummaryBuilder(this.specification, section.summaries)
|
|
22
|
+
const tableSummaries = collatedSummaryBuilder.collateDataTableSummaries()
|
|
23
|
+
this.dataTableBuilder = new DataTableBuilder(this.fields)
|
|
24
|
+
return this.dataTableBuilder
|
|
25
|
+
.withSummaries(tableSummaries)
|
|
26
|
+
.withHeaderOptions({
|
|
27
|
+
columns: this.columns,
|
|
28
|
+
reportQuery: this.reportQuery,
|
|
29
|
+
interactive: Boolean(this.interactive),
|
|
30
|
+
})
|
|
31
|
+
.buildTable(section.data)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
buildSummaryTables(summaries: AsyncSummary[]) {
|
|
35
|
+
const summaryTables = summaries.map((summaryData) => {
|
|
36
|
+
const fields = <components['schemas']['FieldDefinition'][]>summaryData.fields
|
|
37
|
+
const { data, template } = summaryData
|
|
38
|
+
const summaryTableData = new DataTableBuilder(fields)
|
|
39
|
+
.withNoHeaderOptions(fields.map((f) => f.name))
|
|
40
|
+
.buildTable(data)
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
template,
|
|
44
|
+
data: summaryTableData,
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
return this.groupSummaryTables(summaryTables)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
buildSummariesTables(section: SectionData) {
|
|
52
|
+
const { summaries } = section
|
|
53
|
+
const summaryTables: {
|
|
54
|
+
template: SummaryTemplate
|
|
55
|
+
data: DataTable
|
|
56
|
+
}[] = summaries.map((summaryData) => {
|
|
57
|
+
const fields = <components['schemas']['FieldDefinition'][]>summaryData.fields
|
|
58
|
+
const { data, template } = summaryData
|
|
59
|
+
const summaryTableData = new DataTableBuilder(fields)
|
|
60
|
+
.withNoHeaderOptions(fields.map((f) => f.name))
|
|
61
|
+
.buildTable(data)
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
template,
|
|
65
|
+
data: summaryTableData,
|
|
66
|
+
}
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
return this.groupSummaryTables(summaryTables)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
groupSummaryTables(
|
|
73
|
+
summaryTables: {
|
|
74
|
+
template: SummaryTemplate
|
|
75
|
+
data: DataTable
|
|
76
|
+
}[],
|
|
77
|
+
) {
|
|
78
|
+
return summaryTables.reduce<Record<string, DataTable[]>>((acc, item) => {
|
|
79
|
+
if (!acc[item.template]) {
|
|
80
|
+
acc[item.template] = []
|
|
81
|
+
}
|
|
82
|
+
acc[item.template].push(item.data)
|
|
83
|
+
return acc
|
|
84
|
+
}, {})
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
buildSectionedData() {
|
|
88
|
+
const sectionData = new SectionedDataHelper()
|
|
89
|
+
.withData(this.data)
|
|
90
|
+
.withSections(this.sections)
|
|
91
|
+
.withSummaries(this.summaries)
|
|
92
|
+
.withFields(this.fields)
|
|
93
|
+
.withReportQuery(this.reportQuery)
|
|
94
|
+
.build()
|
|
95
|
+
|
|
96
|
+
return sectionData.sections.map((section: SectionData) => {
|
|
97
|
+
const tableData = this.buildMainTable(section)
|
|
98
|
+
const sectionSummaryTables = this.buildSummaryTables(section.summaries)
|
|
99
|
+
return {
|
|
100
|
+
...section,
|
|
101
|
+
summaries: sectionSummaryTables,
|
|
102
|
+
data: tableData,
|
|
103
|
+
}
|
|
104
|
+
})
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
build(): ReportTemplateData {
|
|
108
|
+
const pageSummaryTables = this.buildSummaryTables(this.pageSummaries)
|
|
109
|
+
const sections = this.buildSectionedData()
|
|
110
|
+
|
|
111
|
+
return {
|
|
112
|
+
rowCount: this.data.length,
|
|
113
|
+
summaries: pageSummaryTables,
|
|
114
|
+
sections,
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../dpr/utils/TemplateBuilder/ReportBuilder/types.d.ts"],
|
|
4
|
+
"sourcesContent": ["import { Cell } from '../../DataTableBuilder/types'\n\nexport interface ListSectionTableData {\n head: Cell[] | null\n rows: Cell[][]\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var SectionedDataHelper_exports = {};
|
|
20
|
+
__export(SectionedDataHelper_exports, {
|
|
21
|
+
SectionedDataHelper: () => SectionedDataHelper
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(SectionedDataHelper_exports);
|
|
24
|
+
var import_definitionUtils = require("../../definitionUtils");
|
|
25
|
+
class SectionedDataHelper {
|
|
26
|
+
sections = [];
|
|
27
|
+
data = [];
|
|
28
|
+
fields = [];
|
|
29
|
+
summariesData = [];
|
|
30
|
+
sectionedDataArray = [];
|
|
31
|
+
sectionedData;
|
|
32
|
+
reportQuery;
|
|
33
|
+
createSectionKey(row) {
|
|
34
|
+
const keyObj = this.sections.map((col) => ({
|
|
35
|
+
name: col,
|
|
36
|
+
value: row[col] ?? ""
|
|
37
|
+
}));
|
|
38
|
+
const keyValues = keyObj.map((v) => v.value).join("");
|
|
39
|
+
const key = keyValues !== "" ? JSON.stringify(keyObj) : "mainSection";
|
|
40
|
+
return {
|
|
41
|
+
keyObj: key === "mainSection" ? [] : keyObj,
|
|
42
|
+
key
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
createSectionTitle(keyObj, fields) {
|
|
46
|
+
return keyObj.map((column) => {
|
|
47
|
+
const fieldName = (0, import_definitionUtils.getFieldDisplayName)(fields, column.name);
|
|
48
|
+
return `${fieldName}: ${column.value}`;
|
|
49
|
+
}).join(", ");
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Groups the data into sections
|
|
53
|
+
*
|
|
54
|
+
* @return {*} {SectionedData}
|
|
55
|
+
* @memberof SectionedDataBuilder
|
|
56
|
+
*/
|
|
57
|
+
groupBySections(data, fields, summary) {
|
|
58
|
+
const sectionMap = data.reduce((acc, row) => {
|
|
59
|
+
const { key, keyObj } = this.createSectionKey(row);
|
|
60
|
+
const title = this.createSectionTitle(keyObj, fields);
|
|
61
|
+
if (!acc[key]) {
|
|
62
|
+
acc[key] = {
|
|
63
|
+
title,
|
|
64
|
+
count: 0,
|
|
65
|
+
key,
|
|
66
|
+
keyObj,
|
|
67
|
+
summaries: [],
|
|
68
|
+
data: []
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
const section = acc[key];
|
|
72
|
+
if (summary) {
|
|
73
|
+
const { id, template } = summary;
|
|
74
|
+
const existingSummary = section.summaries.find((s) => s.template === template);
|
|
75
|
+
if (existingSummary) {
|
|
76
|
+
existingSummary.data.push(row);
|
|
77
|
+
} else {
|
|
78
|
+
section.summaries.push({
|
|
79
|
+
id,
|
|
80
|
+
template,
|
|
81
|
+
fields,
|
|
82
|
+
data: [row]
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
} else {
|
|
86
|
+
section.data.push(row);
|
|
87
|
+
section.count += 1;
|
|
88
|
+
}
|
|
89
|
+
return acc;
|
|
90
|
+
}, {});
|
|
91
|
+
this.sectionedDataArray.push({
|
|
92
|
+
sections: Object.values(sectionMap)
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
createSummarySections() {
|
|
96
|
+
this.summariesData.forEach((summaryData) => {
|
|
97
|
+
const { fields, id, template, data } = summaryData;
|
|
98
|
+
this.groupBySections(data, fields, { id, template });
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
mergeSections() {
|
|
102
|
+
return {
|
|
103
|
+
sections: this.sectionedDataArray.flatMap((input) => input.sections).reduce((acc, section) => {
|
|
104
|
+
const { key, keyObj } = section;
|
|
105
|
+
const existing = acc.find((s) => s.key === key);
|
|
106
|
+
if (!existing) {
|
|
107
|
+
return acc.concat({
|
|
108
|
+
key: section.key || "",
|
|
109
|
+
keyObj: keyObj || [],
|
|
110
|
+
title: section.title || "",
|
|
111
|
+
count: section.count,
|
|
112
|
+
summaries: section.summaries ? [...section.summaries] : [],
|
|
113
|
+
data: section.data ? [...section.data] : []
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
const updated = acc.map(
|
|
117
|
+
(s) => s.key === key ? {
|
|
118
|
+
...s,
|
|
119
|
+
count: s.count + section.count,
|
|
120
|
+
summaries: (s.summaries ?? []).concat(section.summaries ?? []),
|
|
121
|
+
data: (s.data ?? []).concat(section.data ?? [])
|
|
122
|
+
} : s
|
|
123
|
+
);
|
|
124
|
+
return updated;
|
|
125
|
+
}, [])
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
getSortField() {
|
|
129
|
+
const { sortColumn } = this.reportQuery;
|
|
130
|
+
return sortColumn && this.sections.includes(sortColumn) ? [sortColumn] : [];
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Sorts sections based on keyObj values using an optional nameOrder override.
|
|
134
|
+
* - nameOrder can be partial; unspecified names fall back to default order
|
|
135
|
+
* - Default order is derived from the first section's keyObj sequence
|
|
136
|
+
*/
|
|
137
|
+
sortSections(sectionedData) {
|
|
138
|
+
const nameOrder = this.getSortField();
|
|
139
|
+
const { sections } = sectionedData;
|
|
140
|
+
if (sections.length === 0) return sectionedData;
|
|
141
|
+
const defaultOrder = sections[0].keyObj.map((k) => k.name);
|
|
142
|
+
const finalOrder = nameOrder.filter((name) => defaultOrder.includes(name)).concat(defaultOrder.filter((name) => !nameOrder.includes(name)));
|
|
143
|
+
const buildMap = (keyObj) => keyObj.reduce((acc, ko) => ({ ...acc, [ko.name]: ko.value }), {});
|
|
144
|
+
const sortedSections = [...sections].sort((a, b) => {
|
|
145
|
+
const aMap = buildMap(a.keyObj);
|
|
146
|
+
const bMap = buildMap(b.keyObj);
|
|
147
|
+
const comparisons = finalOrder.map((name) => {
|
|
148
|
+
const aVal = aMap[name] ?? "";
|
|
149
|
+
const bVal = bMap[name] ?? "";
|
|
150
|
+
return aVal.localeCompare(bVal, void 0, { numeric: true });
|
|
151
|
+
});
|
|
152
|
+
return comparisons.find((x) => x !== 0) ?? 0;
|
|
153
|
+
});
|
|
154
|
+
return {
|
|
155
|
+
sections: sortedSections
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
withSections(sections) {
|
|
159
|
+
this.sections = sections || [];
|
|
160
|
+
return this;
|
|
161
|
+
}
|
|
162
|
+
withFields(fields) {
|
|
163
|
+
this.fields = (0, import_definitionUtils.getFieldsByName)(this.sections, fields);
|
|
164
|
+
return this;
|
|
165
|
+
}
|
|
166
|
+
withData(data) {
|
|
167
|
+
this.data = data;
|
|
168
|
+
return this;
|
|
169
|
+
}
|
|
170
|
+
withSummaries(summaryData) {
|
|
171
|
+
this.summariesData = summaryData || [];
|
|
172
|
+
return this;
|
|
173
|
+
}
|
|
174
|
+
withReportQuery(reportQuery) {
|
|
175
|
+
this.reportQuery = reportQuery;
|
|
176
|
+
return this;
|
|
177
|
+
}
|
|
178
|
+
build() {
|
|
179
|
+
let sections;
|
|
180
|
+
if (this.sections.length) {
|
|
181
|
+
this.groupBySections(this.data, this.fields);
|
|
182
|
+
this.createSummarySections();
|
|
183
|
+
sections = this.mergeSections();
|
|
184
|
+
sections = this.sortSections(sections);
|
|
185
|
+
} else {
|
|
186
|
+
const singleSection = {
|
|
187
|
+
key: "",
|
|
188
|
+
keyObj: [],
|
|
189
|
+
data: this.data,
|
|
190
|
+
count: this.data.length,
|
|
191
|
+
summaries: this.summariesData
|
|
192
|
+
};
|
|
193
|
+
sections = { sections: [singleSection] };
|
|
194
|
+
}
|
|
195
|
+
return sections;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
199
|
+
0 && (module.exports = {
|
|
200
|
+
SectionedDataHelper
|
|
201
|
+
});
|
|
202
|
+
//# sourceMappingURL=SectionedDataHelper.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../dpr/utils/TemplateBuilder/SectionedDataHelper/SectionedDataHelper.ts"],
|
|
4
|
+
"sourcesContent": ["import ReportQuery from '../../../types/ReportQuery'\nimport { SummaryTemplate } from '../../../types/Templates'\nimport { AsyncSummary } from '../../../types/UserReports'\nimport { components } from '../../../types/api'\nimport { getFieldsByName, getFieldDisplayName } from '../../definitionUtils'\nimport { SectionData, SectionedData, SectionKey } from './types'\n\nexport class SectionedDataHelper {\n sections: Array<string> = []\n\n data: Array<Record<string, string>> = []\n\n fields: components['schemas']['FieldDefinition'][] = []\n\n summariesData: AsyncSummary[] = []\n\n sectionedDataArray: SectionedData[] = []\n\n sectionedData!: SectionedData\n\n reportQuery!: ReportQuery\n\n createSectionKey(row: Record<string, string>): { keyObj: SectionKey[]; key: string } {\n // Build structured entries with column names + values\n const keyObj: SectionKey[] = this.sections.map((col) => ({\n name: col,\n value: row[col] ?? '',\n }))\n const keyValues = keyObj.map((v) => v.value).join('')\n const key = keyValues !== '' ? JSON.stringify(keyObj) : 'mainSection'\n\n return {\n keyObj: key === 'mainSection' ? [] : keyObj,\n key,\n }\n }\n\n createSectionTitle(\n keyObj: SectionKey[],\n fields: components['schemas']['FieldDefinition'][] | components['schemas']['SummaryField'][],\n ) {\n return keyObj\n .map((column) => {\n const fieldName = getFieldDisplayName(fields, column.name)\n return `${fieldName}: ${column.value}`\n })\n .join(', ')\n }\n\n /**\n * Groups the data into sections\n *\n * @return {*} {SectionedData}\n * @memberof SectionedDataBuilder\n */\n groupBySections(\n data: Array<Record<string, string>>,\n fields: components['schemas']['FieldDefinition'][] | components['schemas']['SummaryField'][],\n summary?: {\n template: SummaryTemplate\n id: string\n },\n ) {\n const sectionMap = data.reduce<Record<string, SectionData>>((acc, row) => {\n const { key, keyObj } = this.createSectionKey(row)\n const title = this.createSectionTitle(keyObj, fields)\n\n // Create the section if needed\n if (!acc[key]) {\n acc[key] = {\n title,\n count: 0,\n key,\n keyObj,\n summaries: [],\n data: <Array<Record<string, string>>>[],\n }\n }\n\n const section = acc[key]\n\n if (summary) {\n const { id, template } = summary\n const existingSummary = section.summaries.find((s) => s.template === template)\n if (existingSummary) {\n existingSummary.data.push(row)\n } else {\n section.summaries.push({\n id,\n template,\n fields,\n data: [row],\n })\n }\n } else {\n section.data.push(row)\n section.count += 1\n }\n\n return acc\n }, {})\n\n this.sectionedDataArray.push({\n sections: Object.values(sectionMap),\n })\n }\n\n createSummarySections() {\n this.summariesData.forEach((summaryData) => {\n const { fields, id, template, data } = summaryData\n this.groupBySections(<Array<Record<string, string>>>data, fields, { id, template })\n })\n }\n\n mergeSections(): SectionedData {\n return {\n sections: this.sectionedDataArray\n .flatMap((input) => input.sections)\n .reduce<SectionData[]>((acc, section) => {\n const { key, keyObj } = section\n const existing = acc.find((s) => s.key === key)\n\n // If section doesn't exist yet \u2192 add fresh copy\n if (!existing) {\n return acc.concat({\n key: section.key || '',\n keyObj: keyObj || [],\n title: section.title || '',\n count: section.count,\n summaries: section.summaries ? [...section.summaries] : [],\n data: section.data ? [...section.data] : [],\n })\n }\n\n // If exists \u2192 update it by concatenating data & summaries\n const updated = acc.map((s) =>\n s.key === key\n ? {\n ...s,\n count: s.count + section.count,\n summaries: (s.summaries ?? []).concat(section.summaries ?? []),\n data: (s.data ?? []).concat(section.data ?? []),\n }\n : s,\n )\n\n return updated\n }, []),\n }\n }\n\n getSortField() {\n const { sortColumn } = this.reportQuery\n return sortColumn && this.sections.includes(sortColumn) ? [sortColumn] : []\n }\n\n /**\n * Sorts sections based on keyObj values using an optional nameOrder override.\n * - nameOrder can be partial; unspecified names fall back to default order\n * - Default order is derived from the first section's keyObj sequence\n */\n sortSections(sectionedData: SectionedData): SectionedData {\n const nameOrder = this.getSortField()\n const { sections } = sectionedData\n if (sections.length === 0) return sectionedData\n\n // Default order is the order of the keyObj.name fields in the first section\n const defaultOrder = sections[0].keyObj.map((k) => k.name)\n\n // Merge partial nameOrder with default order\n const finalOrder = nameOrder\n // 1. start with user-specified names\n .filter((name) => defaultOrder.includes(name))\n // 2. append missing names in default order\n .concat(defaultOrder.filter((name) => !nameOrder.includes(name)))\n\n // Build map for fast comparison\n const buildMap = (keyObj: SectionKey[]) =>\n keyObj.reduce<Record<string, string>>((acc, ko) => ({ ...acc, [ko.name]: ko.value }), {})\n\n const sortedSections = [...sections].sort((a, b) => {\n const aMap = buildMap(a.keyObj)\n const bMap = buildMap(b.keyObj)\n\n // Compare using final order\n const comparisons = finalOrder.map((name) => {\n const aVal = aMap[name] ?? ''\n const bVal = bMap[name] ?? ''\n return aVal.localeCompare(bVal, undefined, { numeric: true })\n })\n\n // Return first non-zero comparison\n return comparisons.find((x) => x !== 0) ?? 0\n })\n\n return {\n sections: sortedSections,\n }\n }\n\n withSections(sections: string[]) {\n this.sections = sections || []\n return this\n }\n\n withFields(fields: components['schemas']['FieldDefinition'][]) {\n this.fields = getFieldsByName(this.sections, fields)\n return this\n }\n\n withData(data: Array<Record<string, string>>) {\n this.data = data\n return this\n }\n\n withSummaries(summaryData: Array<AsyncSummary>) {\n this.summariesData = summaryData || []\n return this\n }\n\n withReportQuery(reportQuery: ReportQuery) {\n this.reportQuery = reportQuery\n return this\n }\n\n build(): SectionedData {\n let sections: SectionedData\n if (this.sections.length) {\n this.groupBySections(this.data, this.fields)\n this.createSummarySections()\n sections = this.mergeSections()\n sections = this.sortSections(sections)\n } else {\n const singleSection: SectionData = {\n key: '',\n keyObj: [],\n data: this.data,\n count: this.data.length,\n summaries: this.summariesData,\n }\n sections = { sections: [singleSection] }\n }\n\n return sections\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,6BAAqD;AAG9C,MAAM,oBAAoB;AAAA,EAC/B,WAA0B,CAAC;AAAA,EAE3B,OAAsC,CAAC;AAAA,EAEvC,SAAqD,CAAC;AAAA,EAEtD,gBAAgC,CAAC;AAAA,EAEjC,qBAAsC,CAAC;AAAA,EAEvC;AAAA,EAEA;AAAA,EAE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