@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,246 @@
|
|
|
1
|
+
import ReportQuery from '../../../types/ReportQuery'
|
|
2
|
+
import { SummaryTemplate } from '../../../types/Templates'
|
|
3
|
+
import { AsyncSummary } from '../../../types/UserReports'
|
|
4
|
+
import { components } from '../../../types/api'
|
|
5
|
+
import { getFieldsByName, getFieldDisplayName } from '../../definitionUtils'
|
|
6
|
+
import { SectionData, SectionedData, SectionKey } from './types'
|
|
7
|
+
|
|
8
|
+
export class SectionedDataHelper {
|
|
9
|
+
sections: Array<string> = []
|
|
10
|
+
|
|
11
|
+
data: Array<Record<string, string>> = []
|
|
12
|
+
|
|
13
|
+
fields: components['schemas']['FieldDefinition'][] = []
|
|
14
|
+
|
|
15
|
+
summariesData: AsyncSummary[] = []
|
|
16
|
+
|
|
17
|
+
sectionedDataArray: SectionedData[] = []
|
|
18
|
+
|
|
19
|
+
sectionedData!: SectionedData
|
|
20
|
+
|
|
21
|
+
reportQuery!: ReportQuery
|
|
22
|
+
|
|
23
|
+
createSectionKey(row: Record<string, string>): { keyObj: SectionKey[]; key: string } {
|
|
24
|
+
// Build structured entries with column names + values
|
|
25
|
+
const keyObj: SectionKey[] = this.sections.map((col) => ({
|
|
26
|
+
name: col,
|
|
27
|
+
value: row[col] ?? '',
|
|
28
|
+
}))
|
|
29
|
+
const keyValues = keyObj.map((v) => v.value).join('')
|
|
30
|
+
const key = keyValues !== '' ? JSON.stringify(keyObj) : 'mainSection'
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
keyObj: key === 'mainSection' ? [] : keyObj,
|
|
34
|
+
key,
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
createSectionTitle(
|
|
39
|
+
keyObj: SectionKey[],
|
|
40
|
+
fields: components['schemas']['FieldDefinition'][] | components['schemas']['SummaryField'][],
|
|
41
|
+
) {
|
|
42
|
+
return keyObj
|
|
43
|
+
.map((column) => {
|
|
44
|
+
const fieldName = getFieldDisplayName(fields, column.name)
|
|
45
|
+
return `${fieldName}: ${column.value}`
|
|
46
|
+
})
|
|
47
|
+
.join(', ')
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Groups the data into sections
|
|
52
|
+
*
|
|
53
|
+
* @return {*} {SectionedData}
|
|
54
|
+
* @memberof SectionedDataBuilder
|
|
55
|
+
*/
|
|
56
|
+
groupBySections(
|
|
57
|
+
data: Array<Record<string, string>>,
|
|
58
|
+
fields: components['schemas']['FieldDefinition'][] | components['schemas']['SummaryField'][],
|
|
59
|
+
summary?: {
|
|
60
|
+
template: SummaryTemplate
|
|
61
|
+
id: string
|
|
62
|
+
},
|
|
63
|
+
) {
|
|
64
|
+
const sectionMap = data.reduce<Record<string, SectionData>>((acc, row) => {
|
|
65
|
+
const { key, keyObj } = this.createSectionKey(row)
|
|
66
|
+
const title = this.createSectionTitle(keyObj, fields)
|
|
67
|
+
|
|
68
|
+
// Create the section if needed
|
|
69
|
+
if (!acc[key]) {
|
|
70
|
+
acc[key] = {
|
|
71
|
+
title,
|
|
72
|
+
count: 0,
|
|
73
|
+
key,
|
|
74
|
+
keyObj,
|
|
75
|
+
summaries: [],
|
|
76
|
+
data: <Array<Record<string, string>>>[],
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const section = acc[key]
|
|
81
|
+
|
|
82
|
+
if (summary) {
|
|
83
|
+
const { id, template } = summary
|
|
84
|
+
const existingSummary = section.summaries.find((s) => s.template === template)
|
|
85
|
+
if (existingSummary) {
|
|
86
|
+
existingSummary.data.push(row)
|
|
87
|
+
} else {
|
|
88
|
+
section.summaries.push({
|
|
89
|
+
id,
|
|
90
|
+
template,
|
|
91
|
+
fields,
|
|
92
|
+
data: [row],
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
} else {
|
|
96
|
+
section.data.push(row)
|
|
97
|
+
section.count += 1
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return acc
|
|
101
|
+
}, {})
|
|
102
|
+
|
|
103
|
+
this.sectionedDataArray.push({
|
|
104
|
+
sections: Object.values(sectionMap),
|
|
105
|
+
})
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
createSummarySections() {
|
|
109
|
+
this.summariesData.forEach((summaryData) => {
|
|
110
|
+
const { fields, id, template, data } = summaryData
|
|
111
|
+
this.groupBySections(<Array<Record<string, string>>>data, fields, { id, template })
|
|
112
|
+
})
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
mergeSections(): SectionedData {
|
|
116
|
+
return {
|
|
117
|
+
sections: this.sectionedDataArray
|
|
118
|
+
.flatMap((input) => input.sections)
|
|
119
|
+
.reduce<SectionData[]>((acc, section) => {
|
|
120
|
+
const { key, keyObj } = section
|
|
121
|
+
const existing = acc.find((s) => s.key === key)
|
|
122
|
+
|
|
123
|
+
// If section doesn't exist yet → add fresh copy
|
|
124
|
+
if (!existing) {
|
|
125
|
+
return acc.concat({
|
|
126
|
+
key: section.key || '',
|
|
127
|
+
keyObj: keyObj || [],
|
|
128
|
+
title: section.title || '',
|
|
129
|
+
count: section.count,
|
|
130
|
+
summaries: section.summaries ? [...section.summaries] : [],
|
|
131
|
+
data: section.data ? [...section.data] : [],
|
|
132
|
+
})
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// If exists → update it by concatenating data & summaries
|
|
136
|
+
const updated = acc.map((s) =>
|
|
137
|
+
s.key === key
|
|
138
|
+
? {
|
|
139
|
+
...s,
|
|
140
|
+
count: s.count + section.count,
|
|
141
|
+
summaries: (s.summaries ?? []).concat(section.summaries ?? []),
|
|
142
|
+
data: (s.data ?? []).concat(section.data ?? []),
|
|
143
|
+
}
|
|
144
|
+
: s,
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
return updated
|
|
148
|
+
}, []),
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
getSortField() {
|
|
153
|
+
const { sortColumn } = this.reportQuery
|
|
154
|
+
return sortColumn && this.sections.includes(sortColumn) ? [sortColumn] : []
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Sorts sections based on keyObj values using an optional nameOrder override.
|
|
159
|
+
* - nameOrder can be partial; unspecified names fall back to default order
|
|
160
|
+
* - Default order is derived from the first section's keyObj sequence
|
|
161
|
+
*/
|
|
162
|
+
sortSections(sectionedData: SectionedData): SectionedData {
|
|
163
|
+
const nameOrder = this.getSortField()
|
|
164
|
+
const { sections } = sectionedData
|
|
165
|
+
if (sections.length === 0) return sectionedData
|
|
166
|
+
|
|
167
|
+
// Default order is the order of the keyObj.name fields in the first section
|
|
168
|
+
const defaultOrder = sections[0].keyObj.map((k) => k.name)
|
|
169
|
+
|
|
170
|
+
// Merge partial nameOrder with default order
|
|
171
|
+
const finalOrder = nameOrder
|
|
172
|
+
// 1. start with user-specified names
|
|
173
|
+
.filter((name) => defaultOrder.includes(name))
|
|
174
|
+
// 2. append missing names in default order
|
|
175
|
+
.concat(defaultOrder.filter((name) => !nameOrder.includes(name)))
|
|
176
|
+
|
|
177
|
+
// Build map for fast comparison
|
|
178
|
+
const buildMap = (keyObj: SectionKey[]) =>
|
|
179
|
+
keyObj.reduce<Record<string, string>>((acc, ko) => ({ ...acc, [ko.name]: ko.value }), {})
|
|
180
|
+
|
|
181
|
+
const sortedSections = [...sections].sort((a, b) => {
|
|
182
|
+
const aMap = buildMap(a.keyObj)
|
|
183
|
+
const bMap = buildMap(b.keyObj)
|
|
184
|
+
|
|
185
|
+
// Compare using final order
|
|
186
|
+
const comparisons = finalOrder.map((name) => {
|
|
187
|
+
const aVal = aMap[name] ?? ''
|
|
188
|
+
const bVal = bMap[name] ?? ''
|
|
189
|
+
return aVal.localeCompare(bVal, undefined, { numeric: true })
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
// Return first non-zero comparison
|
|
193
|
+
return comparisons.find((x) => x !== 0) ?? 0
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
return {
|
|
197
|
+
sections: sortedSections,
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
withSections(sections: string[]) {
|
|
202
|
+
this.sections = sections || []
|
|
203
|
+
return this
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
withFields(fields: components['schemas']['FieldDefinition'][]) {
|
|
207
|
+
this.fields = getFieldsByName(this.sections, fields)
|
|
208
|
+
return this
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
withData(data: Array<Record<string, string>>) {
|
|
212
|
+
this.data = data
|
|
213
|
+
return this
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
withSummaries(summaryData: Array<AsyncSummary>) {
|
|
217
|
+
this.summariesData = summaryData || []
|
|
218
|
+
return this
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
withReportQuery(reportQuery: ReportQuery) {
|
|
222
|
+
this.reportQuery = reportQuery
|
|
223
|
+
return this
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
build(): SectionedData {
|
|
227
|
+
let sections: SectionedData
|
|
228
|
+
if (this.sections.length) {
|
|
229
|
+
this.groupBySections(this.data, this.fields)
|
|
230
|
+
this.createSummarySections()
|
|
231
|
+
sections = this.mergeSections()
|
|
232
|
+
sections = this.sortSections(sections)
|
|
233
|
+
} else {
|
|
234
|
+
const singleSection: SectionData = {
|
|
235
|
+
key: '',
|
|
236
|
+
keyObj: [],
|
|
237
|
+
data: this.data,
|
|
238
|
+
count: this.data.length,
|
|
239
|
+
summaries: this.summariesData,
|
|
240
|
+
}
|
|
241
|
+
sections = { sections: [singleSection] }
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return sections
|
|
245
|
+
}
|
|
246
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
|
17
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../dpr/utils/TemplateBuilder/SectionedDataHelper/types.ts"],
|
|
4
|
+
"sourcesContent": ["import { AsyncSummary } from '../../../types/UserReports'\nimport { SummaryTemplate } from '../../../types/Templates'\nimport { ListSectionTableData } from '../ReportBuilder/types'\nimport { ParentChildTableData } from '../ParentChildDataBuilder/types'\nimport { DataTable } from '../../DataTableBuilder/types'\n\nexport interface SectionedData {\n sections: SectionData[]\n}\n\nexport interface ReportTemplateData {\n rowCount: number\n summaries?: Record<string, DataTable[]>\n sections: SectionDataResult[]\n}\n\nexport interface SectionSummary {\n template: SummaryTemplate\n data: ListSectionTableData // TODO: fix this\n}\n\nexport interface SectionKey {\n name: string\n value: string\n}\n\nexport interface SectionData {\n key?: string\n keyObj: SectionKey[]\n title?: string\n count: number\n summaries: AsyncSummary[]\n data: Array<Record<string, string>>\n}\n\nexport interface SectionDataResult {\n title?: string\n count: number\n summaries: Record<string, DataTable[]>\n data: Array<Record<string, string>> | ParentChildTableData[] | ListSectionTableData\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { AsyncSummary } from '../../../types/UserReports'
|
|
2
|
+
import { SummaryTemplate } from '../../../types/Templates'
|
|
3
|
+
import { ListSectionTableData } from '../ReportBuilder/types'
|
|
4
|
+
import { ParentChildTableData } from '../ParentChildDataBuilder/types'
|
|
5
|
+
import { DataTable } from '../../DataTableBuilder/types'
|
|
6
|
+
|
|
7
|
+
export interface SectionedData {
|
|
8
|
+
sections: SectionData[]
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface ReportTemplateData {
|
|
12
|
+
rowCount: number
|
|
13
|
+
summaries?: Record<string, DataTable[]>
|
|
14
|
+
sections: SectionDataResult[]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface SectionSummary {
|
|
18
|
+
template: SummaryTemplate
|
|
19
|
+
data: ListSectionTableData // TODO: fix this
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface SectionKey {
|
|
23
|
+
name: string
|
|
24
|
+
value: string
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface SectionData {
|
|
28
|
+
key?: string
|
|
29
|
+
keyObj: SectionKey[]
|
|
30
|
+
title?: string
|
|
31
|
+
count: number
|
|
32
|
+
summaries: AsyncSummary[]
|
|
33
|
+
data: Array<Record<string, string>>
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface SectionDataResult {
|
|
37
|
+
title?: string
|
|
38
|
+
count: number
|
|
39
|
+
summaries: Record<string, DataTable[]>
|
|
40
|
+
data: Array<Record<string, string>> | ParentChildTableData[] | ListSectionTableData
|
|
41
|
+
}
|
|
@@ -26,13 +26,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var
|
|
30
|
-
__export(
|
|
31
|
-
CollatedSummaryBuilder: () => CollatedSummaryBuilder
|
|
32
|
-
default: () => CollatedSummaryBuilder_default
|
|
29
|
+
var SummaryDataHelper_exports = {};
|
|
30
|
+
__export(SummaryDataHelper_exports, {
|
|
31
|
+
CollatedSummaryBuilder: () => CollatedSummaryBuilder
|
|
33
32
|
});
|
|
34
|
-
module.exports = __toCommonJS(
|
|
35
|
-
var import_SummaryDataTableBuilder = __toESM(require("
|
|
33
|
+
module.exports = __toCommonJS(SummaryDataHelper_exports);
|
|
34
|
+
var import_SummaryDataTableBuilder = __toESM(require("../../SummaryDataTableBuilder/SummaryDataTableBuilder"));
|
|
36
35
|
class CollatedSummaryBuilder {
|
|
37
36
|
summaries;
|
|
38
37
|
specification;
|
|
@@ -84,9 +83,8 @@ class CollatedSummaryBuilder {
|
|
|
84
83
|
return dataTables;
|
|
85
84
|
}
|
|
86
85
|
}
|
|
87
|
-
var CollatedSummaryBuilder_default = CollatedSummaryBuilder;
|
|
88
86
|
// Annotate the CommonJS export names for ESM import in node:
|
|
89
87
|
0 && (module.exports = {
|
|
90
88
|
CollatedSummaryBuilder
|
|
91
89
|
});
|
|
92
|
-
//# sourceMappingURL=
|
|
90
|
+
//# sourceMappingURL=SummaryDataHelper.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../dpr/utils/TemplateBuilder/SummaryDataHelper/SummaryDataHelper.ts"],
|
|
4
|
+
"sourcesContent": ["import Dict = NodeJS.Dict\nimport { AsyncSummary } from '../../../types/UserReports'\nimport { SummaryTemplate } from '../../../types/Templates'\nimport { components } from '../../../types/api'\nimport { DataTable } from '../../DataTableBuilder/types'\nimport SummaryDataTableBuilder from '../../SummaryDataTableBuilder/SummaryDataTableBuilder'\n\nexport class CollatedSummaryBuilder {\n private summaries: Array<AsyncSummary>\n\n private specification: components['schemas']['Specification']\n\n constructor(specification: components['schemas']['Specification'], summaries: Array<AsyncSummary>) {\n this.specification = specification\n this.summaries = summaries\n }\n\n pageSummaryTemplates: Array<SummaryTemplate> = ['page-header', 'page-footer']\n\n dataTableSummaryTemplates: Array<SummaryTemplate> = [\n 'section-footer',\n 'section-header',\n 'table-footer',\n 'table-header',\n ]\n\n collatePageSummaries(): Dict<Array<DataTable>> {\n return this.collateAndMapToDataTable(this.pageSummaryTemplates)\n }\n\n collateDataTableSummaries(): Dict<Array<AsyncSummary>> {\n return this.collate(this.dataTableSummaryTemplates)\n }\n\n collateAndMapToDataTable(summaryTemplates: Array<SummaryTemplate> = []): Dict<Array<DataTable>> {\n const collatedSummaries = this.collate(summaryTemplates)\n\n return this.mapToDataTables(collatedSummaries)\n }\n\n collate(summaryTemplates: Array<SummaryTemplate> = this.pageSummaryTemplates): Dict<Array<AsyncSummary>> {\n const collatedSummaries: Dict<Array<AsyncSummary>> = {}\n if (this.summaries) {\n this.summaries.forEach((summary: AsyncSummary) => {\n const { template } = summary\n if (summaryTemplates.includes(template)) {\n if (!collatedSummaries[template]) {\n collatedSummaries[template] = []\n }\n collatedSummaries[template].push(summary)\n }\n })\n }\n\n return collatedSummaries\n }\n\n private mapToDataTables(summaries: Dict<Array<AsyncSummary>>): Dict<Array<DataTable>> {\n const dataTables: Dict<Array<DataTable>> = {}\n\n Object.keys(summaries).forEach((summaryType) => {\n if (summaries[summaryType]) {\n dataTables[summaryType] = summaries[summaryType].map((summary) => {\n return new SummaryDataTableBuilder(summary, this.specification.sections).buildSummaryTable()\n })\n }\n })\n\n return dataTables\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,qCAAoC;AAE7B,MAAM,uBAAuB;AAAA,EAC1B;AAAA,EAEA;AAAA,EAER,YAAY,eAAuD,WAAgC;AACjG,SAAK,gBAAgB;AACrB,SAAK,YAAY;AAAA,EACnB;AAAA,EAEA,uBAA+C,CAAC,eAAe,aAAa;AAAA,EAE5E,4BAAoD;AAAA,IAClD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EAEA,uBAA+C;AAC7C,WAAO,KAAK,yBAAyB,KAAK,oBAAoB;AAAA,EAChE;AAAA,EAEA,4BAAuD;AACrD,WAAO,KAAK,QAAQ,KAAK,yBAAyB;AAAA,EACpD;AAAA,EAEA,yBAAyB,mBAA2C,CAAC,GAA2B;AAC9F,UAAM,oBAAoB,KAAK,QAAQ,gBAAgB;AAEvD,WAAO,KAAK,gBAAgB,iBAAiB;AAAA,EAC/C;AAAA,EAEA,QAAQ,mBAA2C,KAAK,sBAAiD;AACvG,UAAM,oBAA+C,CAAC;AACtD,QAAI,KAAK,WAAW;AAClB,WAAK,UAAU,QAAQ,CAAC,YAA0B;AAChD,cAAM,EAAE,SAAS,IAAI;AACrB,YAAI,iBAAiB,SAAS,QAAQ,GAAG;AACvC,cAAI,CAAC,kBAAkB,QAAQ,GAAG;AAChC,8BAAkB,QAAQ,IAAI,CAAC;AAAA,UACjC;AACA,4BAAkB,QAAQ,EAAE,KAAK,OAAO;AAAA,QAC1C;AAAA,MACF,CAAC;AAAA,IACH;AAEA,WAAO;AAAA,EACT;AAAA,EAEQ,gBAAgB,WAA8D;AACpF,UAAM,aAAqC,CAAC;AAE5C,WAAO,KAAK,SAAS,EAAE,QAAQ,CAAC,gBAAgB;AAC9C,UAAI,UAAU,WAAW,GAAG;AAC1B,mBAAW,WAAW,IAAI,UAAU,WAAW,EAAE,IAAI,CAAC,YAAY;AAChE,iBAAO,IAAI,+BAAAA,QAAwB,SAAS,KAAK,cAAc,QAAQ,EAAE,kBAAkB;AAAA,QAC7F,CAAC;AAAA,MACH;AAAA,IACF,CAAC;AAED,WAAO;AAAA,EACT;AACF;",
|
|
6
|
+
"names": ["SummaryDataTableBuilder"]
|
|
7
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { expect } from '@jest/globals'
|
|
2
|
-
import { components } from '
|
|
3
|
-
import CollatedSummaryBuilder from './
|
|
4
|
-
import { AsyncSummary } from '
|
|
5
|
-
import { DataTable } from '
|
|
2
|
+
import { components } from '../../../types/api'
|
|
3
|
+
import { CollatedSummaryBuilder } from './SummaryDataHelper'
|
|
4
|
+
import { AsyncSummary } from '../../../types/UserReports'
|
|
5
|
+
import { DataTable } from '../../DataTableBuilder/types'
|
|
6
6
|
|
|
7
7
|
const activityField: components['schemas']['FieldDefinition'] = {
|
|
8
8
|
header: false,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import Dict = NodeJS.Dict
|
|
2
|
-
import { AsyncSummary } from '
|
|
3
|
-
import { SummaryTemplate } from '
|
|
4
|
-
import { components } from '
|
|
5
|
-
import { DataTable } from '
|
|
6
|
-
import SummaryDataTableBuilder from '
|
|
2
|
+
import { AsyncSummary } from '../../../types/UserReports'
|
|
3
|
+
import { SummaryTemplate } from '../../../types/Templates'
|
|
4
|
+
import { components } from '../../../types/api'
|
|
5
|
+
import { DataTable } from '../../DataTableBuilder/types'
|
|
6
|
+
import SummaryDataTableBuilder from '../../SummaryDataTableBuilder/SummaryDataTableBuilder'
|
|
7
7
|
|
|
8
|
-
class CollatedSummaryBuilder {
|
|
8
|
+
export class CollatedSummaryBuilder {
|
|
9
9
|
private summaries: Array<AsyncSummary>
|
|
10
10
|
|
|
11
11
|
private specification: components['schemas']['Specification']
|
|
@@ -69,6 +69,3 @@ class CollatedSummaryBuilder {
|
|
|
69
69
|
return dataTables
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
-
|
|
73
|
-
export { CollatedSummaryBuilder }
|
|
74
|
-
export default CollatedSummaryBuilder
|
|
@@ -0,0 +1,74 @@
|
|
|
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 TemplateBuilder_exports = {};
|
|
20
|
+
__export(TemplateBuilder_exports, {
|
|
21
|
+
TemplateBuilder: () => TemplateBuilder
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(TemplateBuilder_exports);
|
|
24
|
+
var import_definitionUtils = require("../definitionUtils");
|
|
25
|
+
class TemplateBuilder {
|
|
26
|
+
variant;
|
|
27
|
+
specification;
|
|
28
|
+
columns = [];
|
|
29
|
+
sections = [];
|
|
30
|
+
data;
|
|
31
|
+
fields;
|
|
32
|
+
sectionFields = [];
|
|
33
|
+
template;
|
|
34
|
+
reportQuery;
|
|
35
|
+
interactive = false;
|
|
36
|
+
pageSummaries;
|
|
37
|
+
summaries;
|
|
38
|
+
constructor(variant) {
|
|
39
|
+
const { specification } = (0, import_definitionUtils.validateVariant)(variant);
|
|
40
|
+
const { template, fields, sections } = specification;
|
|
41
|
+
this.variant = variant;
|
|
42
|
+
this.interactive = Boolean(variant.interactive);
|
|
43
|
+
this.specification = specification;
|
|
44
|
+
this.template = template;
|
|
45
|
+
this.fields = fields;
|
|
46
|
+
this.sections = sections;
|
|
47
|
+
}
|
|
48
|
+
withColumns(columns) {
|
|
49
|
+
this.columns = columns;
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
withData(data) {
|
|
53
|
+
this.data = data;
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
withQuery(reportQuery) {
|
|
57
|
+
this.reportQuery = reportQuery;
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
withSummaries(summariesData) {
|
|
61
|
+
this.pageSummaries = summariesData.filter((summary) => {
|
|
62
|
+
return summary.template.includes("page");
|
|
63
|
+
});
|
|
64
|
+
this.summaries = summariesData.filter((summary) => {
|
|
65
|
+
return summary.template.includes("section") || summary.template.includes("table");
|
|
66
|
+
});
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
71
|
+
0 && (module.exports = {
|
|
72
|
+
TemplateBuilder
|
|
73
|
+
});
|
|
74
|
+
//# sourceMappingURL=TemplateBuilder.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../dpr/utils/TemplateBuilder/TemplateBuilder.ts"],
|
|
4
|
+
"sourcesContent": ["import { AsyncSummary } from '../../types/UserReports'\nimport { Template } from '../../types/Templates'\nimport { components } from '../../types/api'\nimport ReportQuery from '../../types/ReportQuery'\nimport { validateVariant } from '../definitionUtils'\n\nexport class TemplateBuilder {\n variant: components['schemas']['VariantDefinition']\n\n specification: components['schemas']['Specification']\n\n columns: Array<string> = []\n\n sections: Array<string> = []\n\n data!: Array<Record<string, string>>\n\n fields: components['schemas']['FieldDefinition'][]\n\n sectionFields: components['schemas']['FieldDefinition'][] = []\n\n template: Template\n\n reportQuery!: ReportQuery\n\n interactive = false\n\n pageSummaries!: AsyncSummary[]\n\n summaries!: AsyncSummary[]\n\n constructor(variant: components['schemas']['VariantDefinition']) {\n const { specification } = validateVariant(variant)\n const { template, fields, sections } = specification\n\n this.variant = variant\n this.interactive = Boolean(variant.interactive)\n this.specification = specification\n this.template = template\n this.fields = fields\n this.sections = sections\n }\n\n withColumns(columns: string[]) {\n this.columns = columns\n return this\n }\n\n withData(data: Array<Record<string, string>>) {\n this.data = data\n return this\n }\n\n withQuery(reportQuery: ReportQuery) {\n this.reportQuery = reportQuery\n return this\n }\n\n withSummaries(summariesData: AsyncSummary[]) {\n this.pageSummaries = summariesData.filter((summary) => {\n return summary.template.includes('page')\n })\n this.summaries = summariesData.filter((summary) => {\n return summary.template.includes('section') || summary.template.includes('table')\n })\n return this\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,6BAAgC;AAEzB,MAAM,gBAAgB;AAAA,EAC3B;AAAA,EAEA;AAAA,EAEA,UAAyB,CAAC;AAAA,EAE1B,WAA0B,CAAC;AAAA,EAE3B;AAAA,EAEA;AAAA,EAEA,gBAA4D,CAAC;AAAA,EAE7D;AAAA,EAEA;AAAA,EAEA,cAAc;AAAA,EAEd;AAAA,EAEA;AAAA,EAEA,YAAY,SAAqD;AAC/D,UAAM,EAAE,cAAc,QAAI,wCAAgB,OAAO;AACjD,UAAM,EAAE,UAAU,QAAQ,SAAS,IAAI;AAEvC,SAAK,UAAU;AACf,SAAK,cAAc,QAAQ,QAAQ,WAAW;AAC9C,SAAK,gBAAgB;AACrB,SAAK,WAAW;AAChB,SAAK,SAAS;AACd,SAAK,WAAW;AAAA,EAClB;AAAA,EAEA,YAAY,SAAmB;AAC7B,SAAK,UAAU;AACf,WAAO;AAAA,EACT;AAAA,EAEA,SAAS,MAAqC;AAC5C,SAAK,OAAO;AACZ,WAAO;AAAA,EACT;AAAA,EAEA,UAAU,aAA0B;AAClC,SAAK,cAAc;AACnB,WAAO;AAAA,EACT;AAAA,EAEA,cAAc,eAA+B;AAC3C,SAAK,gBAAgB,cAAc,OAAO,CAAC,YAAY;AACrD,aAAO,QAAQ,SAAS,SAAS,MAAM;AAAA,IACzC,CAAC;AACD,SAAK,YAAY,cAAc,OAAO,CAAC,YAAY;AACjD,aAAO,QAAQ,SAAS,SAAS,SAAS,KAAK,QAAQ,SAAS,SAAS,OAAO;AAAA,IAClF,CAAC;AACD,WAAO;AAAA,EACT;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { AsyncSummary } from '../../types/UserReports'
|
|
2
|
+
import { Template } from '../../types/Templates'
|
|
3
|
+
import { components } from '../../types/api'
|
|
4
|
+
import ReportQuery from '../../types/ReportQuery'
|
|
5
|
+
import { validateVariant } from '../definitionUtils'
|
|
6
|
+
|
|
7
|
+
export class TemplateBuilder {
|
|
8
|
+
variant: components['schemas']['VariantDefinition']
|
|
9
|
+
|
|
10
|
+
specification: components['schemas']['Specification']
|
|
11
|
+
|
|
12
|
+
columns: Array<string> = []
|
|
13
|
+
|
|
14
|
+
sections: Array<string> = []
|
|
15
|
+
|
|
16
|
+
data!: Array<Record<string, string>>
|
|
17
|
+
|
|
18
|
+
fields: components['schemas']['FieldDefinition'][]
|
|
19
|
+
|
|
20
|
+
sectionFields: components['schemas']['FieldDefinition'][] = []
|
|
21
|
+
|
|
22
|
+
template: Template
|
|
23
|
+
|
|
24
|
+
reportQuery!: ReportQuery
|
|
25
|
+
|
|
26
|
+
interactive = false
|
|
27
|
+
|
|
28
|
+
pageSummaries!: AsyncSummary[]
|
|
29
|
+
|
|
30
|
+
summaries!: AsyncSummary[]
|
|
31
|
+
|
|
32
|
+
constructor(variant: components['schemas']['VariantDefinition']) {
|
|
33
|
+
const { specification } = validateVariant(variant)
|
|
34
|
+
const { template, fields, sections } = specification
|
|
35
|
+
|
|
36
|
+
this.variant = variant
|
|
37
|
+
this.interactive = Boolean(variant.interactive)
|
|
38
|
+
this.specification = specification
|
|
39
|
+
this.template = template
|
|
40
|
+
this.fields = fields
|
|
41
|
+
this.sections = sections
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
withColumns(columns: string[]) {
|
|
45
|
+
this.columns = columns
|
|
46
|
+
return this
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
withData(data: Array<Record<string, string>>) {
|
|
50
|
+
this.data = data
|
|
51
|
+
return this
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
withQuery(reportQuery: ReportQuery) {
|
|
55
|
+
this.reportQuery = reportQuery
|
|
56
|
+
return this
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
withSummaries(summariesData: AsyncSummary[]) {
|
|
60
|
+
this.pageSummaries = summariesData.filter((summary) => {
|
|
61
|
+
return summary.template.includes('page')
|
|
62
|
+
})
|
|
63
|
+
this.summaries = summariesData.filter((summary) => {
|
|
64
|
+
return summary.template.includes('section') || summary.template.includes('table')
|
|
65
|
+
})
|
|
66
|
+
return this
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -33,11 +33,14 @@ __export(definitionUtils_exports, {
|
|
|
33
33
|
getField: () => getField,
|
|
34
34
|
getFieldDisplayName: () => getFieldDisplayName,
|
|
35
35
|
getFields: () => getFields,
|
|
36
|
+
getFieldsByName: () => getFieldsByName,
|
|
36
37
|
getFilter: () => getFilter,
|
|
37
38
|
getFilters: () => getFilters,
|
|
38
39
|
getFiltersDefaultsValues: () => getFiltersDefaultsValues,
|
|
39
40
|
getReportSummary: () => getReportSummary,
|
|
40
|
-
getTemplate: () => getTemplate
|
|
41
|
+
getTemplate: () => getTemplate,
|
|
42
|
+
validateDefinition: () => validateDefinition,
|
|
43
|
+
validateVariant: () => validateVariant
|
|
41
44
|
});
|
|
42
45
|
module.exports = __toCommonJS(definitionUtils_exports);
|
|
43
46
|
var import_filtersTypeEnum = require("../components/_filters/filtersTypeEnum");
|
|
@@ -107,6 +110,20 @@ const getFilters = (fields) => {
|
|
|
107
110
|
const filters = fields.filter((field) => field.filter).map((field) => field.filter);
|
|
108
111
|
return filters.length ? filters : [];
|
|
109
112
|
};
|
|
113
|
+
const getFieldsByName = (names, fields) => {
|
|
114
|
+
return names.map((s) => fields.find((field) => field.name === s)).filter((field) => field !== void 0);
|
|
115
|
+
};
|
|
116
|
+
const validateDefinition = (definition) => {
|
|
117
|
+
const { variant } = definition;
|
|
118
|
+
return validateVariant(variant);
|
|
119
|
+
};
|
|
120
|
+
const validateVariant = (variant) => {
|
|
121
|
+
const { specification } = variant;
|
|
122
|
+
if (!specification) {
|
|
123
|
+
throw new Error("No specification in definition");
|
|
124
|
+
}
|
|
125
|
+
return { variant, specification };
|
|
126
|
+
};
|
|
110
127
|
const getReportSummary = (reportId, reportingService, token, definitionPath) => reportingService.getDefinitionSummary(token, reportId, definitionPath);
|
|
111
128
|
var definitionUtils_default = {
|
|
112
129
|
getCurrentVariantDefinition,
|
|
@@ -125,10 +142,13 @@ var definitionUtils_default = {
|
|
|
125
142
|
getField,
|
|
126
143
|
getFieldDisplayName,
|
|
127
144
|
getFields,
|
|
145
|
+
getFieldsByName,
|
|
128
146
|
getFilter,
|
|
129
147
|
getFilters,
|
|
130
148
|
getFiltersDefaultsValues,
|
|
131
149
|
getReportSummary,
|
|
132
|
-
getTemplate
|
|
150
|
+
getTemplate,
|
|
151
|
+
validateDefinition,
|
|
152
|
+
validateVariant
|
|
133
153
|
});
|
|
134
154
|
//# sourceMappingURL=definitionUtils.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../dpr/utils/definitionUtils.ts"],
|
|
4
|
-
"sourcesContent": ["import { FiltersType } from '../components/_filters/filtersTypeEnum'\nimport ReportingService from '../services/reportingService'\nimport { components } from '../types/api'\nimport { Template } from '../types/Templates'\nimport { ReportType } from '../types/UserReports'\nimport logger from './logger'\n\nexport const getFilter = (\n fields: components['schemas']['FieldDefinition'][],\n fieldId: string,\n): components['schemas']['FilterDefinition'] | undefined => {\n return fields.find((f) => f.name === fieldId)?.filter\n}\n\nexport const getFiltersDefaultsValues = (fields: components['schemas']['FieldDefinition'][]) => {\n return fields\n .filter((field) => field.filter)\n .map((field) => {\n const { name, display } = field\n\n const defaultValue = field.filter?.defaultValue\n const defaultGranularity = field.filter?.defaultGranularity\n const defaultQuickFilterValue = field.filter?.defaultQuickFilterValue\n const type = field.filter?.type || ReportType.REPORT\n const interactive = field.filter?.interactive || FiltersType.REQUEST\n\n return {\n name,\n display,\n type,\n interactive,\n ...(defaultValue && { defaultValue }),\n ...(defaultGranularity && { defaultGranularity }),\n ...(defaultQuickFilterValue && { defaultQuickFilterValue }),\n }\n })\n}\n\nexport const getCurrentVariantDefinition = (\n definitions: components['schemas']['ReportDefinitionSummary'][],\n reportId: string,\n variantId: string,\n): components['schemas']['VariantDefinition'] | undefined => {\n if (!definitions) {\n logger.info('No definitions')\n return undefined\n }\n\n let variantDef: components['schemas']['VariantDefinition']\n const reportDef = definitions.find(\n (report: components['schemas']['ReportDefinitionSummary']) => report.id === reportId,\n )\n\n if (reportDef) {\n // TODO: this needs fixing, we should never be using `as unknown as`, but the types are very mixed up here\n variantDef = reportDef.variants.find(\n (variant) => variantId === variant.id,\n ) as unknown as components['schemas']['VariantDefinition']\n\n return variantDef\n }\n\n return undefined\n}\n\nexport const getFieldDisplayName = (fields: components['schemas']['FieldDefinition'][]
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6BAA4B;AAI5B,yBAA2B;AAC3B,oBAAmB;AAEZ,MAAM,YAAY,CACvB,QACA,YAC0D;AAC1D,SAAO,OAAO,KAAK,CAAC,MAAM,EAAE,SAAS,OAAO,GAAG;AACjD;AAEO,MAAM,2BAA2B,CAAC,WAAuD;AAC9F,SAAO,OACJ,OAAO,CAAC,UAAU,MAAM,MAAM,EAC9B,IAAI,CAAC,UAAU;AACd,UAAM,EAAE,MAAM,QAAQ,IAAI;AAE1B,UAAM,eAAe,MAAM,QAAQ;AACnC,UAAM,qBAAqB,MAAM,QAAQ;AACzC,UAAM,0BAA0B,MAAM,QAAQ;AAC9C,UAAM,OAAO,MAAM,QAAQ,QAAQ,8BAAW;AAC9C,UAAM,cAAc,MAAM,QAAQ,eAAe,mCAAY;AAE7D,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,GAAI,gBAAgB,EAAE,aAAa;AAAA,MACnC,GAAI,sBAAsB,EAAE,mBAAmB;AAAA,MAC/C,GAAI,2BAA2B,EAAE,wBAAwB;AAAA,IAC3D;AAAA,EACF,CAAC;AACL;AAEO,MAAM,8BAA8B,CACzC,aACA,UACA,cAC2D;AAC3D,MAAI,CAAC,aAAa;AAChB,kBAAAA,QAAO,KAAK,gBAAgB;AAC5B,WAAO;AAAA,EACT;AAEA,MAAI;AACJ,QAAM,YAAY,YAAY;AAAA,IAC5B,CAAC,WAA6D,OAAO,OAAO;AAAA,EAC9E;AAEA,MAAI,WAAW;AAEb,iBAAa,UAAU,SAAS;AAAA,MAC9B,CAAC,YAAY,cAAc,QAAQ;AAAA,IACrC;AAEA,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAEO,MAAM,sBAAsB,
|
|
4
|
+
"sourcesContent": ["import { FiltersType } from '../components/_filters/filtersTypeEnum'\nimport ReportingService from '../services/reportingService'\nimport { components } from '../types/api'\nimport { Template } from '../types/Templates'\nimport { ReportType } from '../types/UserReports'\nimport logger from './logger'\n\nexport const getFilter = (\n fields: components['schemas']['FieldDefinition'][],\n fieldId: string,\n): components['schemas']['FilterDefinition'] | undefined => {\n return fields.find((f) => f.name === fieldId)?.filter\n}\n\nexport const getFiltersDefaultsValues = (fields: components['schemas']['FieldDefinition'][]) => {\n return fields\n .filter((field) => field.filter)\n .map((field) => {\n const { name, display } = field\n\n const defaultValue = field.filter?.defaultValue\n const defaultGranularity = field.filter?.defaultGranularity\n const defaultQuickFilterValue = field.filter?.defaultQuickFilterValue\n const type = field.filter?.type || ReportType.REPORT\n const interactive = field.filter?.interactive || FiltersType.REQUEST\n\n return {\n name,\n display,\n type,\n interactive,\n ...(defaultValue && { defaultValue }),\n ...(defaultGranularity && { defaultGranularity }),\n ...(defaultQuickFilterValue && { defaultQuickFilterValue }),\n }\n })\n}\n\nexport const getCurrentVariantDefinition = (\n definitions: components['schemas']['ReportDefinitionSummary'][],\n reportId: string,\n variantId: string,\n): components['schemas']['VariantDefinition'] | undefined => {\n if (!definitions) {\n logger.info('No definitions')\n return undefined\n }\n\n let variantDef: components['schemas']['VariantDefinition']\n const reportDef = definitions.find(\n (report: components['schemas']['ReportDefinitionSummary']) => report.id === reportId,\n )\n\n if (reportDef) {\n // TODO: this needs fixing, we should never be using `as unknown as`, but the types are very mixed up here\n variantDef = reportDef.variants.find(\n (variant) => variantId === variant.id,\n ) as unknown as components['schemas']['VariantDefinition']\n\n return variantDef\n }\n\n return undefined\n}\n\nexport const getFieldDisplayName = (\n fields: components['schemas']['FieldDefinition'][] | components['schemas']['SummaryField'][],\n fieldId: string,\n) => {\n const ids = fieldId.split('.')\n const field = fields.find((f) => {\n return f.name === ids[0]\n })\n if (field) {\n return ids[1] ? `${field.display} ${ids[1]}` : field.display\n }\n return fieldId\n}\n\nexport const getField = (fields: components['schemas']['FieldDefinition'][], fieldId: string) => {\n return fields.find((field) => {\n return field.name === fieldId\n })\n}\n\nexport const getFields = (\n definition: components['schemas']['SingleVariantReportDefinition'],\n): components['schemas']['FieldDefinition'][] => {\n return definition.variant.specification?.fields || []\n}\n\nexport const getTemplate = (definition: components['schemas']['SingleVariantReportDefinition']): Template => {\n return definition.variant.specification?.template || 'list'\n}\n\nexport const getFilters = (\n fields: components['schemas']['FieldDefinition'][],\n): components['schemas']['FilterDefinition'][] => {\n const filters: components['schemas']['FilterDefinition'][] = fields\n .filter((field: components['schemas']['FieldDefinition']) => field.filter)\n .map((field: components['schemas']['FieldDefinition']) => <components['schemas']['FilterDefinition']>field.filter)\n\n return filters.length ? filters : []\n}\n\nexport const getFieldsByName = (\n names: string[],\n fields: components['schemas']['FieldDefinition'][],\n): components['schemas']['FieldDefinition'][] => {\n return names.map((s) => fields.find((field) => field.name === s)).filter((field) => field !== undefined)\n}\n\nexport const validateDefinition = (definition: components['schemas']['SingleVariantReportDefinition']) => {\n const { variant } = definition\n return validateVariant(variant)\n}\n\nexport const validateVariant = (variant: components['schemas']['VariantDefinition']) => {\n const { specification } = variant\n\n if (!specification) {\n throw new Error('No specification in definition')\n }\n\n return { variant, specification }\n}\n\nexport const getReportSummary = (\n reportId: string,\n reportingService: ReportingService,\n token: string,\n definitionPath: string,\n) => reportingService.getDefinitionSummary(token, reportId, definitionPath)\n\nexport default {\n getCurrentVariantDefinition,\n getFieldDisplayName,\n getField,\n getFields,\n getTemplate,\n getFilter,\n getFilters,\n getFiltersDefaultsValues,\n getReportSummary,\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6BAA4B;AAI5B,yBAA2B;AAC3B,oBAAmB;AAEZ,MAAM,YAAY,CACvB,QACA,YAC0D;AAC1D,SAAO,OAAO,KAAK,CAAC,MAAM,EAAE,SAAS,OAAO,GAAG;AACjD;AAEO,MAAM,2BAA2B,CAAC,WAAuD;AAC9F,SAAO,OACJ,OAAO,CAAC,UAAU,MAAM,MAAM,EAC9B,IAAI,CAAC,UAAU;AACd,UAAM,EAAE,MAAM,QAAQ,IAAI;AAE1B,UAAM,eAAe,MAAM,QAAQ;AACnC,UAAM,qBAAqB,MAAM,QAAQ;AACzC,UAAM,0BAA0B,MAAM,QAAQ;AAC9C,UAAM,OAAO,MAAM,QAAQ,QAAQ,8BAAW;AAC9C,UAAM,cAAc,MAAM,QAAQ,eAAe,mCAAY;AAE7D,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,GAAI,gBAAgB,EAAE,aAAa;AAAA,MACnC,GAAI,sBAAsB,EAAE,mBAAmB;AAAA,MAC/C,GAAI,2BAA2B,EAAE,wBAAwB;AAAA,IAC3D;AAAA,EACF,CAAC;AACL;AAEO,MAAM,8BAA8B,CACzC,aACA,UACA,cAC2D;AAC3D,MAAI,CAAC,aAAa;AAChB,kBAAAA,QAAO,KAAK,gBAAgB;AAC5B,WAAO;AAAA,EACT;AAEA,MAAI;AACJ,QAAM,YAAY,YAAY;AAAA,IAC5B,CAAC,WAA6D,OAAO,OAAO;AAAA,EAC9E;AAEA,MAAI,WAAW;AAEb,iBAAa,UAAU,SAAS;AAAA,MAC9B,CAAC,YAAY,cAAc,QAAQ;AAAA,IACrC;AAEA,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAEO,MAAM,sBAAsB,CACjC,QACA,YACG;AACH,QAAM,MAAM,QAAQ,MAAM,GAAG;AAC7B,QAAM,QAAQ,OAAO,KAAK,CAAC,MAAM;AAC/B,WAAO,EAAE,SAAS,IAAI,CAAC;AAAA,EACzB,CAAC;AACD,MAAI,OAAO;AACT,WAAO,IAAI,CAAC,IAAI,GAAG,MAAM,OAAO,IAAI,IAAI,CAAC,CAAC,KAAK,MAAM;AAAA,EACvD;AACA,SAAO;AACT;AAEO,MAAM,WAAW,CAAC,QAAoD,YAAoB;AAC/F,SAAO,OAAO,KAAK,CAAC,UAAU;AAC5B,WAAO,MAAM,SAAS;AAAA,EACxB,CAAC;AACH;AAEO,MAAM,YAAY,CACvB,eAC+C;AAC/C,SAAO,WAAW,QAAQ,eAAe,UAAU,CAAC;AACtD;AAEO,MAAM,cAAc,CAAC,eAAiF;AAC3G,SAAO,WAAW,QAAQ,eAAe,YAAY;AACvD;AAEO,MAAM,aAAa,CACxB,WACgD;AAChD,QAAM,UAAuD,OAC1D,OAAO,CAAC,UAAoD,MAAM,MAAM,EACxE,IAAI,CAAC,UAA+F,MAAM,MAAM;AAEnH,SAAO,QAAQ,SAAS,UAAU,CAAC;AACrC;AAEO,MAAM,kBAAkB,CAC7B,OACA,WAC+C;AAC/C,SAAO,MAAM,IAAI,CAAC,MAAM,OAAO,KAAK,CAAC,UAAU,MAAM,SAAS,CAAC,CAAC,EAAE,OAAO,CAAC,UAAU,UAAU,MAAS;AACzG;AAEO,MAAM,qBAAqB,CAAC,eAAuE;AACxG,QAAM,EAAE,QAAQ,IAAI;AACpB,SAAO,gBAAgB,OAAO;AAChC;AAEO,MAAM,kBAAkB,CAAC,YAAwD;AACtF,QAAM,EAAE,cAAc,IAAI;AAE1B,MAAI,CAAC,eAAe;AAClB,UAAM,IAAI,MAAM,gCAAgC;AAAA,EAClD;AAEA,SAAO,EAAE,SAAS,cAAc;AAClC;AAEO,MAAM,mBAAmB,CAC9B,UACA,kBACA,OACA,mBACG,iBAAiB,qBAAqB,OAAO,UAAU,cAAc;AAE1E,IAAO,0BAAQ;AAAA,EACb;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;",
|
|
6
6
|
"names": ["logger"]
|
|
7
7
|
}
|