@ministryofjustice/hmpps-digital-prison-reporting-frontend 4.28.8 → 4.29.0
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/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
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
import Dict = NodeJS.Dict
|
|
2
|
-
import { components } from '../../types/api'
|
|
3
|
-
import { Cell, DataTable } from '../DataTableBuilder/types'
|
|
4
|
-
import DataTableBuilder from '../DataTableBuilder/DataTableBuilder'
|
|
5
|
-
import { distinct } from '../arrayUtils'
|
|
6
|
-
import { ChildData, ParentChildSortKey } from './types'
|
|
7
|
-
import SectionedDataTableBuilder from '../SectionedDataTableBuilder/SectionedDataTableBuilder'
|
|
8
|
-
|
|
9
|
-
class ParentChildDataTableBuilder extends SectionedDataTableBuilder {
|
|
10
|
-
variant: components['schemas']['VariantDefinition']
|
|
11
|
-
|
|
12
|
-
childVariants: components['schemas']['ChildVariantDefinition'][]
|
|
13
|
-
|
|
14
|
-
childData: Array<ChildData> = []
|
|
15
|
-
|
|
16
|
-
constructor(variant: components['schemas']['VariantDefinition']) {
|
|
17
|
-
const { specification } = variant
|
|
18
|
-
const { sections, template } = <components['schemas']['Specification']>specification
|
|
19
|
-
super(<components['schemas']['Specification']>specification)
|
|
20
|
-
|
|
21
|
-
this.sections = sections
|
|
22
|
-
this.template = template
|
|
23
|
-
this.variant = variant
|
|
24
|
-
this.childVariants = this.variant.childVariants || []
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
private createParentChildTable(parentData: Array<Dict<string>>, header: Cell[]) {
|
|
28
|
-
let sectionedParentChildData: Dict<Dict<Array<Dict<string>>>> = {}
|
|
29
|
-
const joinFields = this.mapNamesToFields(this.childVariants.flatMap((c) => c.joinFields).reduce(distinct, []))
|
|
30
|
-
// Get the parent-child joins definition data
|
|
31
|
-
|
|
32
|
-
// Create the section keys and
|
|
33
|
-
const parentChildKeys = this.calculateParentChildKeys(parentData, joinFields)
|
|
34
|
-
parentChildKeys.forEach((parentKey) => {
|
|
35
|
-
sectionedParentChildData[parentKey.sortKey] = {
|
|
36
|
-
parent: [],
|
|
37
|
-
}
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
sectionedParentChildData = this.splitParentDataIntoSections(sectionedParentChildData, parentData, joinFields)
|
|
41
|
-
sectionedParentChildData = this.splitChildDataIntoSections(parentChildKeys, sectionedParentChildData)
|
|
42
|
-
|
|
43
|
-
const childDataTableBuilders = this.createChildDataTableBuilders()
|
|
44
|
-
|
|
45
|
-
const parentChildTable = parentChildKeys.flatMap((key) => {
|
|
46
|
-
const sectionData = sectionedParentChildData[key.sortKey] || {}
|
|
47
|
-
|
|
48
|
-
let parentSectionData: Dict<string>[] = []
|
|
49
|
-
if (sectionData) {
|
|
50
|
-
parentSectionData = sectionData['parent'] ? sectionData['parent'] : []
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return [header].concat(parentSectionData.map((r) => this.mapRow(r, 'dpr-parent-cell'))).concat(
|
|
54
|
-
this.childVariants
|
|
55
|
-
.filter((childVariant) => sectionData && sectionData[childVariant.id])
|
|
56
|
-
.map((childVariant) => {
|
|
57
|
-
const builder = childDataTableBuilders[childVariant.id]
|
|
58
|
-
const section = sectionData[childVariant.id]
|
|
59
|
-
const dataTable = builder && section ? builder.buildTable(section) : undefined
|
|
60
|
-
const dataTableHtml = dataTable ? this.convertDataTableToHtml(dataTable) : ''
|
|
61
|
-
|
|
62
|
-
return [
|
|
63
|
-
{
|
|
64
|
-
classes: 'dpr-child-report-cell',
|
|
65
|
-
format: 'string',
|
|
66
|
-
html: `<div class='dpr-child-report'><h2 class="govuk-heading-s">${childVariant.name}</h2><div class="dpr-child-report_table">${dataTableHtml}</div></div>`,
|
|
67
|
-
colspan: this.columns.length,
|
|
68
|
-
},
|
|
69
|
-
]
|
|
70
|
-
}),
|
|
71
|
-
)
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
return parentChildTable
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
private createParentChildSectionRows(parentData: Array<Dict<string>>, header: Cell[]) {
|
|
78
|
-
const sectionsDetails = this.mapSections(parentData)
|
|
79
|
-
const sectionedData = sectionsDetails.sectionedData as Dict<Array<Dict<string>>>
|
|
80
|
-
const sectionedParentChildSectionedRows: {
|
|
81
|
-
sectionDescription: string
|
|
82
|
-
rows: Cell[][]
|
|
83
|
-
count: number
|
|
84
|
-
countDescription: string
|
|
85
|
-
}[] = []
|
|
86
|
-
|
|
87
|
-
Object.keys(sectionedData).forEach((sectionDescription) => {
|
|
88
|
-
const data = sectionedData[sectionDescription] as Array<Dict<string>>
|
|
89
|
-
|
|
90
|
-
sectionedParentChildSectionedRows.push({
|
|
91
|
-
sectionDescription,
|
|
92
|
-
...this.getSectionCount(sectionedData, sectionDescription),
|
|
93
|
-
rows: this.createParentChildTable(data, header),
|
|
94
|
-
})
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
const rows = sectionedParentChildSectionedRows.flatMap((section, index) => {
|
|
98
|
-
const sectionHeader = this.createSectionHeader(
|
|
99
|
-
section.sectionDescription,
|
|
100
|
-
index,
|
|
101
|
-
section.count,
|
|
102
|
-
section.countDescription,
|
|
103
|
-
)
|
|
104
|
-
return [...sectionHeader, ...section.rows]
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
return rows
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
private mapParentChildData(parentData: Array<Dict<string>>, header: Cell[]): Cell[][] {
|
|
111
|
-
if (this.sections?.length) {
|
|
112
|
-
return this.createParentChildSectionRows(parentData, header)
|
|
113
|
-
}
|
|
114
|
-
return this.createParentChildTable(parentData, header)
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
private createChildDataTableBuilders() {
|
|
118
|
-
const childDataTables: Dict<DataTableBuilder> = this.childVariants.reduce((previousValue, childVariant) => {
|
|
119
|
-
const { specification } = childVariant
|
|
120
|
-
const fields = specification ? specification.fields : []
|
|
121
|
-
const fieldNamesToDisplay = fields.filter((f) => f.visible || f.mandatory).map((f) => f.name)
|
|
122
|
-
|
|
123
|
-
const dataTableBuilder = new DataTableBuilder(fields).withNoHeaderOptions(fieldNamesToDisplay).withSortedData()
|
|
124
|
-
|
|
125
|
-
return {
|
|
126
|
-
...previousValue,
|
|
127
|
-
[childVariant.id]: dataTableBuilder,
|
|
128
|
-
}
|
|
129
|
-
}, {})
|
|
130
|
-
return childDataTables
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
private calculateParentChildKeys(
|
|
134
|
-
parentData: Array<NodeJS.Dict<string>>,
|
|
135
|
-
joinFields: components['schemas']['FieldDefinition'][],
|
|
136
|
-
) {
|
|
137
|
-
return parentData
|
|
138
|
-
.map(
|
|
139
|
-
(rowData): ParentChildSortKey => ({
|
|
140
|
-
sortKey: this.getSortKey(rowData, joinFields),
|
|
141
|
-
childSortKeys: this.childVariants.reduce((previousValue, childVariant) => {
|
|
142
|
-
return {
|
|
143
|
-
...previousValue,
|
|
144
|
-
[childVariant.id]: this.getSortKey(rowData, this.mapNamesToFields(childVariant.joinFields)),
|
|
145
|
-
}
|
|
146
|
-
}, {}),
|
|
147
|
-
}),
|
|
148
|
-
)
|
|
149
|
-
.reduce((previousValue: ParentChildSortKey[], sortKey: ParentChildSortKey) => {
|
|
150
|
-
if (previousValue.find((v) => v.sortKey === sortKey.sortKey)) {
|
|
151
|
-
return previousValue
|
|
152
|
-
}
|
|
153
|
-
return previousValue.concat(sortKey)
|
|
154
|
-
}, [])
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
private splitParentDataIntoSections(
|
|
158
|
-
sectionedParentChildData: NodeJS.Dict<NodeJS.Dict<Array<NodeJS.Dict<string>>>>,
|
|
159
|
-
parentData: Array<NodeJS.Dict<string>>,
|
|
160
|
-
joinFields: components['schemas']['FieldDefinition'][],
|
|
161
|
-
) {
|
|
162
|
-
return parentData.reduce((previousValue, rowData) => {
|
|
163
|
-
const parentKey: string = this.getSortKey(rowData, joinFields)
|
|
164
|
-
const previousParentValue = previousValue[parentKey] ? previousValue[parentKey]['parent'] : []
|
|
165
|
-
|
|
166
|
-
return {
|
|
167
|
-
...previousValue,
|
|
168
|
-
...(previousParentValue && {
|
|
169
|
-
[parentKey]: {
|
|
170
|
-
parent: previousParentValue.concat(rowData),
|
|
171
|
-
},
|
|
172
|
-
}),
|
|
173
|
-
}
|
|
174
|
-
}, sectionedParentChildData)
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
private splitChildDataIntoSections(
|
|
178
|
-
parentKeys: ParentChildSortKey[],
|
|
179
|
-
sectionedParentChildData: Dict<Dict<Array<Dict<string>>>>,
|
|
180
|
-
): Dict<Dict<Array<Dict<string>>>> {
|
|
181
|
-
const sectionedParentChildDataWithChildren = { ...sectionedParentChildData }
|
|
182
|
-
|
|
183
|
-
this.childVariants.forEach((childVariant) => {
|
|
184
|
-
const childFields = this.mapNamesToFields(childVariant.joinFields)
|
|
185
|
-
const matchingChildData = this.childData.find((d) => d.id === childVariant.id)
|
|
186
|
-
const data = matchingChildData ? matchingChildData.data : []
|
|
187
|
-
|
|
188
|
-
data
|
|
189
|
-
.filter((rowData) => {
|
|
190
|
-
const sortKey = this.getSortKey(rowData, childFields)
|
|
191
|
-
return parentKeys.find((p) => p.childSortKeys[childVariant.id] === sortKey)
|
|
192
|
-
})
|
|
193
|
-
.forEach((rowData) => {
|
|
194
|
-
const sortKey = this.getSortKey(rowData, childFields)
|
|
195
|
-
const parent = parentKeys.find((p) => p.childSortKeys[childVariant.id] === sortKey)
|
|
196
|
-
const parentSortKey = parent ? parent.sortKey : ''
|
|
197
|
-
const parentSection = sectionedParentChildDataWithChildren[parentSortKey]
|
|
198
|
-
if (parentSection) {
|
|
199
|
-
const existingChildData = parentSection[childVariant.id] || []
|
|
200
|
-
parentSection[childVariant.id] = existingChildData.concat(rowData)
|
|
201
|
-
}
|
|
202
|
-
})
|
|
203
|
-
})
|
|
204
|
-
|
|
205
|
-
return sectionedParentChildDataWithChildren
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
withChildData(childData: Array<ChildData>) {
|
|
209
|
-
this.childData = childData
|
|
210
|
-
return this
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
override buildTable(data: Array<Dict<string>>): DataTable {
|
|
214
|
-
return {
|
|
215
|
-
head: null,
|
|
216
|
-
rows: this.mapParentChildData(data, this.mapHeader(true, 'govuk-table__header')),
|
|
217
|
-
rowCount: data.length,
|
|
218
|
-
colCount: this.columns.length,
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
export { ParentChildDataTableBuilder }
|
|
224
|
-
export default ParentChildDataTableBuilder
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../dpr/utils/ParentChildDataTableBuilder/types.d.ts"],
|
|
4
|
-
"sourcesContent": ["import { SortKey } from '../DataTableBuilder/types'\nimport Dict = NodeJS.Dict\n\nexport interface ParentChildSortKey extends SortKey {\n childSortKeys: Dict<string>\n}\n\nexport interface ChildData {\n id: string\n data: Array<Dict<string>>\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,311 +0,0 @@
|
|
|
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 SectionedDataTableBuilder_exports = {};
|
|
30
|
-
__export(SectionedDataTableBuilder_exports, {
|
|
31
|
-
SectionedDataTableBuilder: () => SectionedDataTableBuilder,
|
|
32
|
-
default: () => SectionedDataTableBuilder_default
|
|
33
|
-
});
|
|
34
|
-
module.exports = __toCommonJS(SectionedDataTableBuilder_exports);
|
|
35
|
-
var import_DataTableBuilder = __toESM(require("../DataTableBuilder/DataTableBuilder"));
|
|
36
|
-
var import_arrayUtils = require("../arrayUtils");
|
|
37
|
-
var import_SummaryDataTableBuilder = __toESM(require("../SummaryDataTableBuilder/SummaryDataTableBuilder"));
|
|
38
|
-
class SectionedDataTableBuilder extends import_DataTableBuilder.default {
|
|
39
|
-
sections;
|
|
40
|
-
template;
|
|
41
|
-
constructor(specification) {
|
|
42
|
-
const { fields, sections, template } = specification;
|
|
43
|
-
super(fields);
|
|
44
|
-
this.sections = sections;
|
|
45
|
-
this.template = template;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Creates the section heading strings
|
|
49
|
-
*
|
|
50
|
-
* @param {Dict<string>[]} data
|
|
51
|
-
* @param {FieldDefinition[]} sectionFields
|
|
52
|
-
* @return {*} {string[]} array of section headings
|
|
53
|
-
*/
|
|
54
|
-
createSectionHeadings(data, sectionFields) {
|
|
55
|
-
return data.map(
|
|
56
|
-
(rowData) => ({
|
|
57
|
-
description: this.mapSectionDescription(rowData),
|
|
58
|
-
sortKey: this.getSortKey(rowData, sectionFields)
|
|
59
|
-
})
|
|
60
|
-
).sort(this.sortKeyComparison()).map((s) => s.description).reduce(import_arrayUtils.distinct, []);
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Initialise section heading arrays
|
|
64
|
-
*
|
|
65
|
-
* @private
|
|
66
|
-
* @param {string[]} sectionDescriptions
|
|
67
|
-
* @return {*}
|
|
68
|
-
* @memberof SectionedDataTableBuilder
|
|
69
|
-
*/
|
|
70
|
-
initSectionData(sectionDescriptions) {
|
|
71
|
-
const sectionedData = {};
|
|
72
|
-
sectionDescriptions.forEach((sectionDescription) => {
|
|
73
|
-
sectionedData[sectionDescription] = [];
|
|
74
|
-
});
|
|
75
|
-
return sectionedData;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Maps the rows to the correct section
|
|
79
|
-
*
|
|
80
|
-
* @private
|
|
81
|
-
* @param {Array<Dict<string>>} data
|
|
82
|
-
* @param {Dict<Cell[][]>} sectionedData
|
|
83
|
-
* @return {*}
|
|
84
|
-
* @memberof SectionedDataTableBuilder
|
|
85
|
-
*/
|
|
86
|
-
mapRowsToSection(data, sectionedData) {
|
|
87
|
-
return data.reduce((previousValue, rowData) => {
|
|
88
|
-
const sectionDescription = this.mapSectionDescription(rowData);
|
|
89
|
-
const mappedData = this.mapRow(rowData);
|
|
90
|
-
const previousValueDescription = previousValue[sectionDescription];
|
|
91
|
-
return {
|
|
92
|
-
...previousValue,
|
|
93
|
-
...previousValueDescription && {
|
|
94
|
-
[sectionDescription]: previousValueDescription.concat([mappedData])
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
}, sectionedData);
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Maps the rows to the correct section
|
|
101
|
-
*
|
|
102
|
-
* @private
|
|
103
|
-
* @param {Array<Dict<string>>} data
|
|
104
|
-
* @param {Dict<Cell[][]>} sectionedData
|
|
105
|
-
* @return {*}
|
|
106
|
-
* @memberof SectionedDataTableBuilder
|
|
107
|
-
*/
|
|
108
|
-
mapDataToSection(data, sectionedData) {
|
|
109
|
-
return data.reduce((previousValue, rowData) => {
|
|
110
|
-
const sectionDescription = this.mapSectionDescription(rowData);
|
|
111
|
-
const previousValueDescription = previousValue[sectionDescription];
|
|
112
|
-
const section = {
|
|
113
|
-
...previousValue,
|
|
114
|
-
...previousValueDescription && {
|
|
115
|
-
[sectionDescription]: previousValueDescription.concat([rowData])
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
return section;
|
|
119
|
-
}, sectionedData);
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Gets the counts for rows in section
|
|
123
|
-
*
|
|
124
|
-
* @param {Dict<Cell[][]>} sectionedData
|
|
125
|
-
* @param {string} sectionDescription
|
|
126
|
-
* @return {*}
|
|
127
|
-
* @memberof SectionedDataTableBuilder
|
|
128
|
-
*/
|
|
129
|
-
getSectionCount(sectionedData, sectionDescription) {
|
|
130
|
-
const count = sectionedData[sectionDescription] ? sectionedData[sectionDescription].length : 0;
|
|
131
|
-
const countDescription = `${count} result${count === 1 ? "" : "s"}`;
|
|
132
|
-
return {
|
|
133
|
-
count,
|
|
134
|
-
countDescription
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Creates the summaries and builds the table with summaries
|
|
139
|
-
*
|
|
140
|
-
* @private
|
|
141
|
-
* @param {string} sectionDescription
|
|
142
|
-
* @param {Cell[][]} mappedTableData
|
|
143
|
-
* @param {Cell[]} header
|
|
144
|
-
* @return {*}
|
|
145
|
-
* @memberof SectionedDataTableBuilder
|
|
146
|
-
*/
|
|
147
|
-
mapSummariesAndCreateTable(sectionDescription, mappedTableData, header) {
|
|
148
|
-
let tableContent = [];
|
|
149
|
-
let mappedSectionHeaderSummary = [];
|
|
150
|
-
let mappedHeaderSummary = [];
|
|
151
|
-
let mappedFooterSummary = [];
|
|
152
|
-
let mappedSectionFooterSummary = [];
|
|
153
|
-
mappedSectionHeaderSummary = this.mapSectionSummaryTables(sectionDescription, "section-header", this.columns.length);
|
|
154
|
-
mappedHeaderSummary = this.mapSectionSummaryRows("table-header", sectionDescription);
|
|
155
|
-
mappedFooterSummary = this.mapSectionSummaryRows("table-footer", sectionDescription);
|
|
156
|
-
mappedSectionFooterSummary = this.mapSectionSummaryTables(sectionDescription, "section-footer", this.columns.length);
|
|
157
|
-
tableContent = mappedSectionHeaderSummary.concat(mappedTableData.length > 0 ? [header] : []).concat(mappedHeaderSummary).concat(mappedTableData).concat(mappedFooterSummary).concat(mappedSectionFooterSummary);
|
|
158
|
-
return tableContent;
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Creates the table data
|
|
162
|
-
* - if summaries are present, includes the summaries data
|
|
163
|
-
*
|
|
164
|
-
* @private
|
|
165
|
-
* @param {string[]} sectionDescriptions
|
|
166
|
-
* @param {Dict<Cell[][]>} sectionedData
|
|
167
|
-
* @param {Cell[]} header
|
|
168
|
-
* @return {*}
|
|
169
|
-
* @memberof SectionedDataTableBuilder
|
|
170
|
-
*/
|
|
171
|
-
createTableContent(sectionDescriptions, sectionedData, header) {
|
|
172
|
-
return sectionDescriptions.flatMap((sectionDescription, index) => {
|
|
173
|
-
const { count, countDescription } = this.getSectionCount(sectionedData, sectionDescription);
|
|
174
|
-
const mappedTableData = sectionedData[sectionDescription];
|
|
175
|
-
let tableContent = [];
|
|
176
|
-
if (mappedTableData) {
|
|
177
|
-
if (Object.keys(this.reportSummaries).length) {
|
|
178
|
-
tableContent = this.mapSummariesAndCreateTable(sectionDescription, mappedTableData, header);
|
|
179
|
-
} else {
|
|
180
|
-
tableContent = tableContent.concat(mappedTableData.length > 0 ? [header] : []).concat(mappedTableData);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
const sectionHeader = this.createSectionHeader(sectionDescription, index, count, countDescription);
|
|
184
|
-
return [...sectionHeader, ...tableContent];
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
createSectionHeader(sectionDescription, index, count, countDescription) {
|
|
188
|
-
const header = [];
|
|
189
|
-
if (index !== 0) {
|
|
190
|
-
header.push([
|
|
191
|
-
{
|
|
192
|
-
classes: "dpr-section-header-spacer",
|
|
193
|
-
colspan: this.columns.length,
|
|
194
|
-
text: ""
|
|
195
|
-
}
|
|
196
|
-
]);
|
|
197
|
-
}
|
|
198
|
-
header.push([
|
|
199
|
-
{
|
|
200
|
-
classes: "dpr-section-header",
|
|
201
|
-
colspan: this.columns.length,
|
|
202
|
-
html: `<h2 class="govuk-heading-m">${sectionDescription}${count && count > 0 ? ` <span class='govuk-caption-m'>${countDescription}</span>` : ""}</h2>`
|
|
203
|
-
}
|
|
204
|
-
]);
|
|
205
|
-
header.push([
|
|
206
|
-
{
|
|
207
|
-
classes: "dpr-section-header-spacer-bottom",
|
|
208
|
-
colspan: this.columns.length,
|
|
209
|
-
text: ""
|
|
210
|
-
}
|
|
211
|
-
]);
|
|
212
|
-
return header;
|
|
213
|
-
}
|
|
214
|
-
mapSectionSummaryRows(template, sectionDescription) {
|
|
215
|
-
if (this.reportSummaries[template]) {
|
|
216
|
-
return this.reportSummaries[template].flatMap(
|
|
217
|
-
(reportSummary) => reportSummary.data.filter((rowData) => this.mapSectionDescription(rowData) === sectionDescription).map(
|
|
218
|
-
(rowData) => this.mapRow(
|
|
219
|
-
rowData,
|
|
220
|
-
`dpr-report-summary-cell dpr-report-summary-cell-${template}`,
|
|
221
|
-
reportSummary.fields
|
|
222
|
-
)
|
|
223
|
-
)
|
|
224
|
-
);
|
|
225
|
-
}
|
|
226
|
-
return [];
|
|
227
|
-
}
|
|
228
|
-
mapSectionSummaryTables(sectionDescription, summaryTemplate, columnsLength) {
|
|
229
|
-
const summaries = this.reportSummaries[summaryTemplate];
|
|
230
|
-
if (summaries) {
|
|
231
|
-
const htmlTables = summaries.map((summary) => {
|
|
232
|
-
const data = summary.data.filter((row) => this.mapSectionDescription(row) === sectionDescription);
|
|
233
|
-
if (data.length > 0) {
|
|
234
|
-
const dataTable = new import_SummaryDataTableBuilder.default(summary, this.sections).buildTable(data);
|
|
235
|
-
const htmlTable = this.convertDataTableToHtml(dataTable);
|
|
236
|
-
return `<div class='dpr-summary-container'>${htmlTable}</div>`;
|
|
237
|
-
}
|
|
238
|
-
return "";
|
|
239
|
-
});
|
|
240
|
-
const summaryContent = htmlTables.join("");
|
|
241
|
-
if (summaryContent.length > 0) {
|
|
242
|
-
return [
|
|
243
|
-
[
|
|
244
|
-
{
|
|
245
|
-
classes: "dpr-summary-cell",
|
|
246
|
-
colspan: columnsLength,
|
|
247
|
-
html: `<div class='dpr-summary-container-group dpr-summary-container-group-${summaryTemplate}'>${summaryContent}</div>`
|
|
248
|
-
}
|
|
249
|
-
]
|
|
250
|
-
];
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
return [];
|
|
254
|
-
}
|
|
255
|
-
mapSectionDescription(rowData) {
|
|
256
|
-
const { sections } = this;
|
|
257
|
-
return this.mapNamesToFields(sections).map((s) => `${s.display}: ${this.mapCellValue(s, rowData[s.name])}`).join(", ");
|
|
258
|
-
}
|
|
259
|
-
mapSections(data) {
|
|
260
|
-
const sectionHeadings = this.initSectionedHeadings(data);
|
|
261
|
-
let { sectionedData } = sectionHeadings;
|
|
262
|
-
if (this.template !== "summary-section") {
|
|
263
|
-
if (this.template === "parent-child-section") {
|
|
264
|
-
sectionedData = this.mapDataToSection(data, sectionedData);
|
|
265
|
-
} else {
|
|
266
|
-
sectionedData = this.mapRowsToSection(data, sectionedData);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
return {
|
|
270
|
-
sectionDescriptions: sectionHeadings.sectionDescriptions,
|
|
271
|
-
sectionedData
|
|
272
|
-
};
|
|
273
|
-
}
|
|
274
|
-
initSectionedHeadings(data) {
|
|
275
|
-
const sectionFields = this.mapNamesToFields(this.sections);
|
|
276
|
-
const sectionDescriptions = this.createSectionHeadings(data, sectionFields);
|
|
277
|
-
const sectionedData = this.initSectionData(sectionDescriptions);
|
|
278
|
-
return {
|
|
279
|
-
sectionDescriptions,
|
|
280
|
-
sectionedData
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
/**
|
|
284
|
-
* Creates the table rows.
|
|
285
|
-
*
|
|
286
|
-
* @private
|
|
287
|
-
* @param {Array<Dict<string>>} data
|
|
288
|
-
* @param {Cell[]} header
|
|
289
|
-
* @return {*} {Cell[][]}
|
|
290
|
-
* @memberof SectionedDataTableBuilder
|
|
291
|
-
*/
|
|
292
|
-
mapSectionedData(data, header) {
|
|
293
|
-
const { sectionDescriptions, sectionedData } = this.mapSections(data);
|
|
294
|
-
const tableContent = this.createTableContent(sectionDescriptions, sectionedData, header);
|
|
295
|
-
return tableContent;
|
|
296
|
-
}
|
|
297
|
-
buildTable(data) {
|
|
298
|
-
return {
|
|
299
|
-
head: null,
|
|
300
|
-
rows: this.mapSectionedData(data, this.mapHeader(true, "govuk-table__header")),
|
|
301
|
-
rowCount: data.length,
|
|
302
|
-
colCount: this.columns.length
|
|
303
|
-
};
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
var SectionedDataTableBuilder_default = SectionedDataTableBuilder;
|
|
307
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
308
|
-
0 && (module.exports = {
|
|
309
|
-
SectionedDataTableBuilder
|
|
310
|
-
});
|
|
311
|
-
//# sourceMappingURL=SectionedDataTableBuilder.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../dpr/utils/SectionedDataTableBuilder/SectionedDataTableBuilder.ts"],
|
|
4
|
-
"sourcesContent": ["import Dict = NodeJS.Dict\nimport { components } from '../../types/api'\nimport { Cell, DataTable } from '../DataTableBuilder/types'\nimport type { SummaryTemplate, Template } from '../../types/Templates'\nimport DataTableBuilder from '../DataTableBuilder/DataTableBuilder'\nimport { distinct } from '../arrayUtils'\nimport SummaryDataTableBuilder from '../SummaryDataTableBuilder/SummaryDataTableBuilder'\nimport { SectionSortKey } from './types'\n\nclass SectionedDataTableBuilder extends DataTableBuilder {\n sections: Array<string>\n\n template: Template\n\n constructor(specification: components['schemas']['Specification']) {\n const { fields, sections, template } = specification\n super(fields)\n this.sections = sections\n this.template = template\n }\n\n /**\n * Creates the section heading strings\n *\n * @param {Dict<string>[]} data\n * @param {FieldDefinition[]} sectionFields\n * @return {*} {string[]} array of section headings\n */\n private createSectionHeadings(\n data: Dict<string>[],\n sectionFields: components['schemas']['FieldDefinition'][],\n ): string[] {\n return data\n .map(\n (rowData): SectionSortKey => ({\n description: this.mapSectionDescription(rowData),\n sortKey: this.getSortKey(rowData, sectionFields),\n }),\n )\n .sort(this.sortKeyComparison())\n .map((s) => s.description)\n .reduce(distinct, [])\n }\n\n /**\n * Initialise section heading arrays\n *\n * @private\n * @param {string[]} sectionDescriptions\n * @return {*}\n * @memberof SectionedDataTableBuilder\n */\n initSectionData(sectionDescriptions: string[]) {\n const sectionedData: Dict<Cell[][]> | Dict<Array<Dict<string>>> = {}\n sectionDescriptions.forEach((sectionDescription) => {\n sectionedData[sectionDescription] = []\n })\n return sectionedData\n }\n\n /**\n * Maps the rows to the correct section\n *\n * @private\n * @param {Array<Dict<string>>} data\n * @param {Dict<Cell[][]>} sectionedData\n * @return {*}\n * @memberof SectionedDataTableBuilder\n */\n private mapRowsToSection(data: Array<Dict<string>>, sectionedData: Dict<Cell[][]>) {\n return data.reduce((previousValue, rowData) => {\n const sectionDescription: string = this.mapSectionDescription(rowData)\n const mappedData = this.mapRow(rowData)\n const previousValueDescription = previousValue[sectionDescription]\n\n return {\n ...previousValue,\n ...(previousValueDescription && {\n [sectionDescription]: previousValueDescription.concat([mappedData]),\n }),\n }\n }, sectionedData)\n }\n\n /**\n * Maps the rows to the correct section\n *\n * @private\n * @param {Array<Dict<string>>} data\n * @param {Dict<Cell[][]>} sectionedData\n * @return {*}\n * @memberof SectionedDataTableBuilder\n */\n private mapDataToSection(data: Array<Dict<string>>, sectionedData: Dict<Array<Dict<string>>>) {\n return data.reduce((previousValue, rowData) => {\n const sectionDescription: string = this.mapSectionDescription(rowData)\n const previousValueDescription = previousValue[sectionDescription]\n const section = {\n ...previousValue,\n ...(previousValueDescription && {\n [sectionDescription]: previousValueDescription.concat([rowData]),\n }),\n }\n return section\n }, sectionedData)\n }\n\n /**\n * Gets the counts for rows in section\n *\n * @param {Dict<Cell[][]>} sectionedData\n * @param {string} sectionDescription\n * @return {*}\n * @memberof SectionedDataTableBuilder\n */\n getSectionCount(sectionedData: Dict<Cell[][]> | Dict<Dict<string>[]>, sectionDescription: string) {\n const count = sectionedData[sectionDescription] ? sectionedData[sectionDescription].length : 0\n const countDescription = `${count} result${count === 1 ? '' : 's'}`\n\n return {\n count,\n countDescription,\n }\n }\n\n /**\n * Creates the summaries and builds the table with summaries\n *\n * @private\n * @param {string} sectionDescription\n * @param {Cell[][]} mappedTableData\n * @param {Cell[]} header\n * @return {*}\n * @memberof SectionedDataTableBuilder\n */\n private mapSummariesAndCreateTable(sectionDescription: string, mappedTableData: Cell[][], header: Cell[]) {\n let tableContent: Cell[][] = []\n\n let mappedSectionHeaderSummary: Cell[][] = []\n let mappedHeaderSummary: Cell[][] = []\n let mappedFooterSummary: Cell[][] = []\n let mappedSectionFooterSummary: Cell[][] = []\n\n mappedSectionHeaderSummary = this.mapSectionSummaryTables(sectionDescription, 'section-header', this.columns.length)\n mappedHeaderSummary = this.mapSectionSummaryRows('table-header', sectionDescription)\n mappedFooterSummary = this.mapSectionSummaryRows('table-footer', sectionDescription)\n mappedSectionFooterSummary = this.mapSectionSummaryTables(sectionDescription, 'section-footer', this.columns.length)\n\n tableContent = mappedSectionHeaderSummary\n .concat(mappedTableData.length > 0 ? [header] : [])\n .concat(mappedHeaderSummary)\n .concat(mappedTableData)\n .concat(mappedFooterSummary)\n .concat(mappedSectionFooterSummary)\n\n return tableContent\n }\n\n /**\n * Creates the table data\n * - if summaries are present, includes the summaries data\n *\n * @private\n * @param {string[]} sectionDescriptions\n * @param {Dict<Cell[][]>} sectionedData\n * @param {Cell[]} header\n * @return {*}\n * @memberof SectionedDataTableBuilder\n */\n private createTableContent(sectionDescriptions: string[], sectionedData: Dict<Cell[][]>, header: Cell[]) {\n return sectionDescriptions.flatMap((sectionDescription, index) => {\n const { count, countDescription } = this.getSectionCount(sectionedData, sectionDescription)\n const mappedTableData = sectionedData[sectionDescription]\n\n let tableContent: Cell[][] = []\n if (mappedTableData) {\n if (Object.keys(this.reportSummaries).length) {\n tableContent = this.mapSummariesAndCreateTable(sectionDescription, mappedTableData, header)\n } else {\n tableContent = tableContent.concat(mappedTableData.length > 0 ? [header] : []).concat(mappedTableData)\n }\n }\n\n const sectionHeader = this.createSectionHeader(sectionDescription, index, count, countDescription)\n\n return [...sectionHeader, ...tableContent]\n })\n }\n\n createSectionHeader(sectionDescription: string, index: number, count?: number, countDescription?: string) {\n const header = []\n if (index !== 0) {\n header.push([\n {\n classes: 'dpr-section-header-spacer',\n colspan: this.columns.length,\n text: '',\n },\n ])\n }\n header.push([\n {\n classes: 'dpr-section-header',\n colspan: this.columns.length,\n html: `<h2 class=\"govuk-heading-m\">${sectionDescription}${\n count && count > 0 ? ` <span class='govuk-caption-m'>${countDescription}</span>` : ''\n }</h2>`,\n },\n ])\n header.push([\n {\n classes: 'dpr-section-header-spacer-bottom',\n colspan: this.columns.length,\n text: '',\n },\n ])\n return header\n }\n\n private mapSectionSummaryRows(template: SummaryTemplate, sectionDescription: string): Cell[][] {\n if (this.reportSummaries[template]) {\n return this.reportSummaries[template].flatMap((reportSummary) =>\n reportSummary.data\n .filter((rowData) => this.mapSectionDescription(rowData) === sectionDescription)\n .map((rowData) =>\n this.mapRow(\n rowData,\n `dpr-report-summary-cell dpr-report-summary-cell-${template}`,\n <components['schemas']['FieldDefinition'][]>reportSummary.fields,\n ),\n ),\n )\n }\n return []\n }\n\n private mapSectionSummaryTables(\n sectionDescription: string,\n summaryTemplate: SummaryTemplate,\n columnsLength: number,\n ): Cell[][] {\n const summaries = this.reportSummaries[summaryTemplate]\n if (summaries) {\n const htmlTables = summaries.map((summary) => {\n const data = summary.data.filter((row) => this.mapSectionDescription(row) === sectionDescription)\n\n if (data.length > 0) {\n const dataTable = new SummaryDataTableBuilder(summary, this.sections).buildTable(data)\n\n const htmlTable = this.convertDataTableToHtml(dataTable)\n\n return `<div class='dpr-summary-container'>${htmlTable}</div>`\n }\n return ''\n })\n\n const summaryContent = htmlTables.join('')\n if (summaryContent.length > 0) {\n return [\n [\n {\n classes: 'dpr-summary-cell',\n colspan: columnsLength,\n html: `<div class='dpr-summary-container-group dpr-summary-container-group-${summaryTemplate}'>${summaryContent}</div>`,\n },\n ],\n ]\n }\n }\n return []\n }\n\n mapSectionDescription(rowData: NodeJS.Dict<string>): string {\n const { sections } = this\n\n return this.mapNamesToFields(sections)\n .map((s) => `${s.display}: ${this.mapCellValue(s, rowData[s.name])}`)\n .join(', ')\n }\n\n mapSections(data: Array<Dict<string>>) {\n const sectionHeadings = this.initSectionedHeadings(data)\n let { sectionedData } = sectionHeadings\n\n // Maps data to sections\n if (this.template !== 'summary-section') {\n if (this.template === 'parent-child-section') {\n sectionedData = this.mapDataToSection(data, sectionedData as Dict<Dict<string>[]>)\n } else {\n sectionedData = this.mapRowsToSection(data, sectionedData as Dict<Cell[][]>)\n }\n }\n\n return {\n sectionDescriptions: sectionHeadings.sectionDescriptions,\n sectionedData,\n }\n }\n\n initSectionedHeadings(data: Array<Dict<string>>) {\n // Get the section definition data\n const sectionFields = this.mapNamesToFields(this.sections)\n // create the sectionHeadings\n const sectionDescriptions = this.createSectionHeadings(data, sectionFields)\n // init empty sections\n const sectionedData = this.initSectionData(sectionDescriptions)\n\n return {\n sectionDescriptions,\n sectionedData,\n }\n }\n\n /**\n * Creates the table rows.\n *\n * @private\n * @param {Array<Dict<string>>} data\n * @param {Cell[]} header\n * @return {*} {Cell[][]}\n * @memberof SectionedDataTableBuilder\n */\n private mapSectionedData(data: Array<Dict<string>>, header: Cell[]): Cell[][] {\n const { sectionDescriptions, sectionedData } = this.mapSections(data)\n // Create the table\n const tableContent = this.createTableContent(sectionDescriptions, sectionedData as Dict<Cell[][]>, header)\n\n return tableContent\n }\n\n override buildTable(data: Array<Dict<string>>): DataTable {\n return {\n head: null,\n rows: this.mapSectionedData(data, this.mapHeader(true, 'govuk-table__header')),\n rowCount: data.length,\n colCount: this.columns.length,\n }\n }\n}\n\nexport { SectionedDataTableBuilder }\nexport default SectionedDataTableBuilder\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,8BAA6B;AAC7B,wBAAyB;AACzB,qCAAoC;AAGpC,MAAM,kCAAkC,wBAAAA,QAAiB;AAAA,EACvD;AAAA,EAEA;AAAA,EAEA,YAAY,eAAuD;AACjE,UAAM,EAAE,QAAQ,UAAU,SAAS,IAAI;AACvC,UAAM,MAAM;AACZ,SAAK,WAAW;AAChB,SAAK,WAAW;AAAA,EAClB;A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