@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.
Files changed (194) hide show
  1. package/dpr/all.js +6 -8
  2. package/dpr/all.js.map +3 -3
  3. package/dpr/all.scss +296 -414
  4. package/dpr/all.ts +6 -11
  5. package/dpr/components/_catalogue/catalogue-list/utils.test.ts +1 -1
  6. package/dpr/components/_charts/chart/clientClass.js +1 -0
  7. package/dpr/components/_charts/chart/clientClass.js.map +2 -2
  8. package/dpr/components/_charts/chart/clientClass.ts +1 -0
  9. package/dpr/components/_reports/{report-actions → report-heading/report-actions}/actionsTemplate.js.map +1 -1
  10. package/dpr/components/_reports/{report-actions → report-heading/report-actions}/clientClass.js +1 -1
  11. package/dpr/components/_reports/report-heading/report-actions/clientClass.js.map +7 -0
  12. package/dpr/components/_reports/{report-actions → report-heading/report-actions}/clientClass.ts +1 -1
  13. package/dpr/components/_reports/report-heading/report-actions/types.d.js.map +7 -0
  14. package/dpr/components/_reports/{report-actions → report-heading/report-actions}/types.d.ts +1 -1
  15. package/dpr/components/_reports/{report-actions → report-heading/report-actions}/utils.js.map +1 -1
  16. package/dpr/components/_reports/{report-actions → report-heading/report-actions}/utils.test.ts +2 -2
  17. package/dpr/components/_reports/{report-columns-form → report-heading/report-columns/report-columns-form}/clientClass.js +1 -3
  18. package/dpr/components/_reports/report-heading/report-columns/report-columns-form/clientClass.js.map +7 -0
  19. package/dpr/components/_reports/{report-columns-form → report-heading/report-columns/report-columns-form}/clientClass.ts +1 -3
  20. package/dpr/components/_reports/{report-columns-form → report-heading/report-columns/report-columns-form}/types.d.js.map +1 -1
  21. package/dpr/components/_reports/{report-columns-form → report-heading/report-columns/report-columns-form}/utils.js +1 -1
  22. package/dpr/components/_reports/report-heading/report-columns/report-columns-form/utils.js.map +7 -0
  23. package/dpr/components/_reports/{report-columns-form → report-heading/report-columns/report-columns-form}/utils.ts +2 -2
  24. package/dpr/components/_reports/{report-columns → report-heading/report-columns}/view.njk +1 -1
  25. package/dpr/components/_reports/{report-download-message → report-heading/report-download-message}/clientClass.js +1 -1
  26. package/dpr/components/_reports/report-heading/report-download-message/clientClass.js.map +7 -0
  27. package/dpr/components/_reports/{report-download-message → report-heading/report-download-message}/clientClass.ts +1 -1
  28. package/dpr/components/_reports/{report-filters → report-heading/report-filters}/view.njk +1 -1
  29. package/dpr/components/_reports/report-heading/view.njk +4 -4
  30. package/dpr/components/_reports/report-page/report-print-message/view.njk +10 -0
  31. package/dpr/components/_reports/report-page/report-template/report-no-data-message/styles.scss +8 -0
  32. package/dpr/components/_reports/report-page/report-template/report-no-data-message/view.njk +11 -0
  33. package/dpr/components/_reports/{report-pagination → report-page/report-template/report-pagination}/clientClass.js +1 -1
  34. package/dpr/components/_reports/report-page/report-template/report-pagination/clientClass.js.map +7 -0
  35. package/dpr/components/_reports/{report-pagination → report-page/report-template/report-pagination}/clientClass.ts +1 -1
  36. package/dpr/components/_reports/{report-pagination → report-page/report-template/report-pagination}/types.d.js.map +1 -1
  37. package/dpr/components/_reports/{report-pagination → report-page/report-template/report-pagination}/utils.js.map +1 -1
  38. package/dpr/components/_reports/report-page/report-template/report-section/parent-child-template/styles.scss +88 -0
  39. package/dpr/components/_reports/report-page/report-template/report-section/parent-child-template/view.njk +29 -0
  40. package/dpr/components/_reports/{report-data-table → report-page/report-template/report-section/report-data-table}/clientClass.js +17 -10
  41. package/dpr/components/_reports/report-page/report-template/report-section/report-data-table/clientClass.js.map +7 -0
  42. package/dpr/components/_reports/{report-data-table → report-page/report-template/report-section/report-data-table}/clientClass.ts +20 -10
  43. package/dpr/components/_reports/{report-data-table → report-page/report-template/report-section/report-data-table}/style.scss +35 -185
  44. package/dpr/components/_reports/report-page/report-template/report-section/report-data-table/types.d.js.map +7 -0
  45. package/dpr/components/_reports/{report-data-table → report-page/report-template/report-section/report-data-table}/types.d.ts +2 -2
  46. package/dpr/components/_reports/report-page/report-template/report-section/report-data-table/view.njk +27 -0
  47. package/dpr/components/_reports/report-page/report-template/report-section/styles.scss +33 -0
  48. package/dpr/components/_reports/report-page/report-template/report-section/view.njk +58 -0
  49. package/dpr/components/_reports/{report-summary-table → report-page/report-template/report-summary-table}/styles.scss +21 -4
  50. package/dpr/components/_reports/{report-totals → report-page/report-template/report-totals}/utils.js.map +1 -1
  51. package/dpr/components/_reports/report-page/report-template/styles.scss +5 -0
  52. package/dpr/components/_reports/report-page/report-template/template-config.js +66 -0
  53. package/dpr/components/_reports/report-page/report-template/template-config.js.map +7 -0
  54. package/dpr/components/_reports/report-page/report-template/template-config.ts +45 -0
  55. package/dpr/components/_reports/report-page/report-template/utils.js +82 -0
  56. package/dpr/components/_reports/report-page/report-template/utils.js.map +7 -0
  57. package/dpr/components/_reports/report-page/report-template/utils.ts +100 -0
  58. package/dpr/components/_reports/report-page/report-template/view.njk +61 -0
  59. package/dpr/components/_reports/{report-wrapper → report-page}/styles.scss +7 -5
  60. package/dpr/components/_reports/report-page/view.njk +26 -0
  61. package/dpr/components/card-group/view.njk +0 -4
  62. package/dpr/components/report-list/utils.js +11 -3
  63. package/dpr/components/report-list/utils.js.map +2 -2
  64. package/dpr/components/report-list/utils.ts +11 -1
  65. package/dpr/components/report-list/view.njk +2 -2
  66. package/dpr/components/show-more/style.scss +3 -4
  67. package/dpr/data/reportingClient.js.map +2 -2
  68. package/dpr/data/reportingClient.ts +4 -4
  69. package/dpr/routes/journeys/view-report/async/dashboard/utils.js +1 -1
  70. package/dpr/routes/journeys/view-report/async/dashboard/utils.js.map +1 -1
  71. package/dpr/routes/journeys/view-report/async/dashboard/utils.ts +1 -1
  72. package/dpr/routes/journeys/view-report/async/report/controller.js.map +2 -2
  73. package/dpr/routes/journeys/view-report/async/report/controller.ts +0 -1
  74. package/dpr/routes/journeys/view-report/async/report/report-variants.cy.js +207 -56
  75. package/dpr/routes/journeys/view-report/async/report/report-variants.cy.js.map +2 -2
  76. package/dpr/routes/journeys/view-report/async/report/report-variants.cy.ts +333 -64
  77. package/dpr/routes/journeys/view-report/async/report/utils.js +9 -17
  78. package/dpr/routes/journeys/view-report/async/report/utils.js.map +3 -3
  79. package/dpr/routes/journeys/view-report/async/report/utils.ts +12 -22
  80. package/dpr/routes/journeys/view-report/report.njk +2 -2
  81. package/dpr/routes/journeys/view-report/sync/dashboard/utils.js +1 -1
  82. package/dpr/routes/journeys/view-report/sync/dashboard/utils.js.map +1 -1
  83. package/dpr/routes/journeys/view-report/sync/dashboard/utils.ts +1 -1
  84. package/dpr/routes/journeys/view-report/sync/report/utils.js +38 -11
  85. package/dpr/routes/journeys/view-report/sync/report/utils.js.map +3 -3
  86. package/dpr/routes/journeys/view-report/sync/report/utils.ts +39 -14
  87. package/dpr/routes/journeys/view-report/utils.js +1 -1
  88. package/dpr/routes/journeys/view-report/utils.js.map +1 -1
  89. package/dpr/routes/journeys/view-report/utils.ts +1 -1
  90. package/dpr/services/reportingService.js.map +2 -2
  91. package/dpr/services/reportingService.ts +2 -2
  92. package/dpr/types/ReportQuery.js +1 -1
  93. package/dpr/types/ReportQuery.js.map +1 -1
  94. package/dpr/types/ReportQuery.ts +1 -1
  95. package/dpr/types/UserReports.js.map +1 -1
  96. package/dpr/types/UserReports.ts +3 -3
  97. package/dpr/utils/TemplateBuilder/ParentChildDataBuilder/ParentChildDataBuilder.js +193 -0
  98. package/dpr/utils/TemplateBuilder/ParentChildDataBuilder/ParentChildDataBuilder.js.map +7 -0
  99. package/dpr/utils/TemplateBuilder/ParentChildDataBuilder/ParentChildDataBuilder.ts +203 -0
  100. package/dpr/utils/TemplateBuilder/ParentChildDataBuilder/types.d.js.map +7 -0
  101. package/dpr/utils/TemplateBuilder/ParentChildDataBuilder/types.d.ts +36 -0
  102. package/dpr/utils/TemplateBuilder/ReportBuilder/ReportBuilder.js +114 -0
  103. package/dpr/utils/TemplateBuilder/ReportBuilder/ReportBuilder.js.map +7 -0
  104. package/dpr/utils/TemplateBuilder/ReportBuilder/ReportBuilder.ts +117 -0
  105. package/dpr/utils/TemplateBuilder/ReportBuilder/types.d.js.map +7 -0
  106. package/dpr/utils/TemplateBuilder/ReportBuilder/types.d.ts +6 -0
  107. package/dpr/utils/TemplateBuilder/SectionedDataHelper/SectionedDataHelper.js +202 -0
  108. package/dpr/utils/TemplateBuilder/SectionedDataHelper/SectionedDataHelper.js.map +7 -0
  109. package/dpr/utils/TemplateBuilder/SectionedDataHelper/SectionedDataHelper.ts +246 -0
  110. package/dpr/utils/TemplateBuilder/SectionedDataHelper/types.js +17 -0
  111. package/dpr/utils/TemplateBuilder/SectionedDataHelper/types.js.map +7 -0
  112. package/dpr/utils/TemplateBuilder/SectionedDataHelper/types.ts +41 -0
  113. package/dpr/utils/{CollatedSummaryBuilder/CollatedSummaryBuilder.js → TemplateBuilder/SummaryDataHelper/SummaryDataHelper.js} +6 -8
  114. package/dpr/utils/TemplateBuilder/SummaryDataHelper/SummaryDataHelper.js.map +7 -0
  115. package/dpr/utils/{CollatedSummaryBuilder/CollatedSummaryBuilder.test.ts → TemplateBuilder/SummaryDataHelper/SummaryDataHelper.test.ts} +4 -4
  116. package/dpr/utils/{CollatedSummaryBuilder/CollatedSummaryBuilder.ts → TemplateBuilder/SummaryDataHelper/SummaryDataHelper.ts} +6 -9
  117. package/dpr/utils/TemplateBuilder/TemplateBuilder.js +74 -0
  118. package/dpr/utils/TemplateBuilder/TemplateBuilder.js.map +7 -0
  119. package/dpr/utils/TemplateBuilder/TemplateBuilder.ts +68 -0
  120. package/dpr/utils/definitionUtils.js +22 -2
  121. package/dpr/utils/definitionUtils.js.map +2 -2
  122. package/dpr/utils/definitionUtils.ts +26 -1
  123. package/package.json +1 -1
  124. package/dpr/DprLoadingHelper.js +0 -51
  125. package/dpr/DprLoadingHelper.js.map +0 -7
  126. package/dpr/DprLoadingHelper.ts +0 -27
  127. package/dpr/components/_reports/report/view.njk +0 -40
  128. package/dpr/components/_reports/report-actions/clientClass.js.map +0 -7
  129. package/dpr/components/_reports/report-actions/types.d.js.map +0 -7
  130. package/dpr/components/_reports/report-columns-form/clientClass.js.map +0 -7
  131. package/dpr/components/_reports/report-columns-form/utils.js.map +0 -7
  132. package/dpr/components/_reports/report-data-table/clientClass.js.map +0 -7
  133. package/dpr/components/_reports/report-data-table/types.d.js.map +0 -7
  134. package/dpr/components/_reports/report-data-table/utils.js +0 -123
  135. package/dpr/components/_reports/report-data-table/utils.js.map +0 -7
  136. package/dpr/components/_reports/report-data-table/utils.test.ts +0 -604
  137. package/dpr/components/_reports/report-data-table/utils.ts +0 -150
  138. package/dpr/components/_reports/report-data-table/view.njk +0 -24
  139. package/dpr/components/_reports/report-data-table-wrapper/view.njk +0 -27
  140. package/dpr/components/_reports/report-download-message/clientClass.js.map +0 -7
  141. package/dpr/components/_reports/report-no-data-message/styles.scss +0 -4
  142. package/dpr/components/_reports/report-no-data-message/view.njk +0 -13
  143. package/dpr/components/_reports/report-pagination/clientClass.js.map +0 -7
  144. package/dpr/components/_reports/report-print-message/view.njk +0 -8
  145. package/dpr/components/_reports/report-template/view.njk +0 -44
  146. package/dpr/components/_reports/report-wrapper/view.njk +0 -19
  147. package/dpr/components/loading-anim/styles.scss +0 -117
  148. package/dpr/components/loading-anim/view.njk +0 -18
  149. package/dpr/utils/CollatedSummaryBuilder/CollatedSummaryBuilder.js.map +0 -7
  150. package/dpr/utils/ParentChildDataTableBuilder/ParentChildDataTableBuilder.js +0 -202
  151. package/dpr/utils/ParentChildDataTableBuilder/ParentChildDataTableBuilder.js.map +0 -7
  152. package/dpr/utils/ParentChildDataTableBuilder/ParentChildDataTableBuilder.test.ts +0 -503
  153. package/dpr/utils/ParentChildDataTableBuilder/ParentChildDataTableBuilder.ts +0 -224
  154. package/dpr/utils/ParentChildDataTableBuilder/types.d.js.map +0 -7
  155. package/dpr/utils/ParentChildDataTableBuilder/types.d.ts +0 -11
  156. package/dpr/utils/SectionedDataTableBuilder/SectionedDataTableBuilder.js +0 -311
  157. package/dpr/utils/SectionedDataTableBuilder/SectionedDataTableBuilder.js.map +0 -7
  158. package/dpr/utils/SectionedDataTableBuilder/SectionedDataTableBuilder.test.ts +0 -492
  159. package/dpr/utils/SectionedDataTableBuilder/SectionedDataTableBuilder.ts +0 -342
  160. package/dpr/utils/SectionedDataTableBuilder/types.d.js.map +0 -7
  161. package/dpr/utils/SectionedDataTableBuilder/types.d.ts +0 -5
  162. package/dpr/utils/SectionedFieldsTableBuilder/SectionedFieldsTableBuilder.js +0 -146
  163. package/dpr/utils/SectionedFieldsTableBuilder/SectionedFieldsTableBuilder.js.map +0 -7
  164. package/dpr/utils/SectionedFieldsTableBuilder/SectionedFieldsTableBuilder.test.ts +0 -140
  165. package/dpr/utils/SectionedFieldsTableBuilder/SectionedFieldsTableBuilder.ts +0 -150
  166. /package/dpr/components/_reports/{report-actions → report-heading/report-actions}/actionsTemplate.js +0 -0
  167. /package/dpr/components/_reports/{report-actions → report-heading/report-actions}/actionsTemplate.ts +0 -0
  168. /package/dpr/components/_reports/{report-actions → report-heading/report-actions}/style.scss +0 -0
  169. /package/dpr/components/_reports/{report-actions → report-heading/report-actions}/types.d.js +0 -0
  170. /package/dpr/components/_reports/{report-actions → report-heading/report-actions}/utils.js +0 -0
  171. /package/dpr/components/_reports/{report-actions → report-heading/report-actions}/utils.ts +0 -0
  172. /package/dpr/components/_reports/{report-actions → report-heading/report-actions}/view.njk +0 -0
  173. /package/dpr/components/_reports/{report-columns-form → report-heading/report-columns/report-columns-form}/style.scss +0 -0
  174. /package/dpr/components/_reports/{report-columns-form → report-heading/report-columns/report-columns-form}/types.d.js +0 -0
  175. /package/dpr/components/_reports/{report-columns-form → report-heading/report-columns/report-columns-form}/types.d.ts +0 -0
  176. /package/dpr/components/_reports/{report-columns-form → report-heading/report-columns/report-columns-form}/view.njk +0 -0
  177. /package/dpr/components/_reports/{report-columns → report-heading/report-columns}/styles.scss +0 -0
  178. /package/dpr/components/_reports/{report-download-message → report-heading/report-download-message}/style.scss +0 -0
  179. /package/dpr/components/_reports/{report-download-message → report-heading/report-download-message}/view.njk +0 -0
  180. /package/dpr/components/_reports/{report-pagination → report-page/report-template/report-pagination}/style.scss +0 -0
  181. /package/dpr/components/_reports/{report-data-table → report-page/report-template/report-pagination}/types.d.js +0 -0
  182. /package/dpr/components/_reports/{report-pagination → report-page/report-template/report-pagination}/types.d.ts +0 -0
  183. /package/dpr/components/_reports/{report-pagination → report-page/report-template/report-pagination}/utils.js +0 -0
  184. /package/dpr/components/_reports/{report-pagination → report-page/report-template/report-pagination}/utils.test.ts +0 -0
  185. /package/dpr/components/_reports/{report-pagination → report-page/report-template/report-pagination}/utils.ts +0 -0
  186. /package/dpr/components/_reports/{report-pagination → report-page/report-template/report-pagination}/view.njk +0 -0
  187. /package/dpr/components/_reports/{report-pagination → report-page/report-template/report-section/report-data-table}/types.d.js +0 -0
  188. /package/dpr/components/_reports/{report-summary-table → report-page/report-template/report-summary-table}/view.njk +0 -0
  189. /package/dpr/components/_reports/{report-totals → report-page/report-template/report-totals}/style.scss +0 -0
  190. /package/dpr/components/_reports/{report-totals → report-page/report-template/report-totals}/utils.js +0 -0
  191. /package/dpr/components/_reports/{report-totals → report-page/report-template/report-totals}/utils.ts +0 -0
  192. /package/dpr/components/_reports/{report-totals → report-page/report-template/report-totals}/view.njk +0 -0
  193. /package/dpr/utils/{ParentChildDataTableBuilder → TemplateBuilder/ParentChildDataBuilder}/types.d.js +0 -0
  194. /package/dpr/utils/{SectionedDataTableBuilder → TemplateBuilder/ReportBuilder}/types.d.js +0 -0
@@ -1,342 +0,0 @@
1
- import Dict = NodeJS.Dict
2
- import { components } from '../../types/api'
3
- import { Cell, DataTable } from '../DataTableBuilder/types'
4
- import type { SummaryTemplate, Template } from '../../types/Templates'
5
- import DataTableBuilder from '../DataTableBuilder/DataTableBuilder'
6
- import { distinct } from '../arrayUtils'
7
- import SummaryDataTableBuilder from '../SummaryDataTableBuilder/SummaryDataTableBuilder'
8
- import { SectionSortKey } from './types'
9
-
10
- class SectionedDataTableBuilder extends DataTableBuilder {
11
- sections: Array<string>
12
-
13
- template: Template
14
-
15
- constructor(specification: components['schemas']['Specification']) {
16
- const { fields, sections, template } = specification
17
- super(fields)
18
- this.sections = sections
19
- this.template = template
20
- }
21
-
22
- /**
23
- * Creates the section heading strings
24
- *
25
- * @param {Dict<string>[]} data
26
- * @param {FieldDefinition[]} sectionFields
27
- * @return {*} {string[]} array of section headings
28
- */
29
- private createSectionHeadings(
30
- data: Dict<string>[],
31
- sectionFields: components['schemas']['FieldDefinition'][],
32
- ): string[] {
33
- return data
34
- .map(
35
- (rowData): SectionSortKey => ({
36
- description: this.mapSectionDescription(rowData),
37
- sortKey: this.getSortKey(rowData, sectionFields),
38
- }),
39
- )
40
- .sort(this.sortKeyComparison())
41
- .map((s) => s.description)
42
- .reduce(distinct, [])
43
- }
44
-
45
- /**
46
- * Initialise section heading arrays
47
- *
48
- * @private
49
- * @param {string[]} sectionDescriptions
50
- * @return {*}
51
- * @memberof SectionedDataTableBuilder
52
- */
53
- initSectionData(sectionDescriptions: string[]) {
54
- const sectionedData: Dict<Cell[][]> | Dict<Array<Dict<string>>> = {}
55
- sectionDescriptions.forEach((sectionDescription) => {
56
- sectionedData[sectionDescription] = []
57
- })
58
- return sectionedData
59
- }
60
-
61
- /**
62
- * Maps the rows to the correct section
63
- *
64
- * @private
65
- * @param {Array<Dict<string>>} data
66
- * @param {Dict<Cell[][]>} sectionedData
67
- * @return {*}
68
- * @memberof SectionedDataTableBuilder
69
- */
70
- private mapRowsToSection(data: Array<Dict<string>>, sectionedData: Dict<Cell[][]>) {
71
- return data.reduce((previousValue, rowData) => {
72
- const sectionDescription: string = this.mapSectionDescription(rowData)
73
- const mappedData = this.mapRow(rowData)
74
- const previousValueDescription = previousValue[sectionDescription]
75
-
76
- return {
77
- ...previousValue,
78
- ...(previousValueDescription && {
79
- [sectionDescription]: previousValueDescription.concat([mappedData]),
80
- }),
81
- }
82
- }, sectionedData)
83
- }
84
-
85
- /**
86
- * Maps the rows to the correct section
87
- *
88
- * @private
89
- * @param {Array<Dict<string>>} data
90
- * @param {Dict<Cell[][]>} sectionedData
91
- * @return {*}
92
- * @memberof SectionedDataTableBuilder
93
- */
94
- private mapDataToSection(data: Array<Dict<string>>, sectionedData: Dict<Array<Dict<string>>>) {
95
- return data.reduce((previousValue, rowData) => {
96
- const sectionDescription: string = this.mapSectionDescription(rowData)
97
- const previousValueDescription = previousValue[sectionDescription]
98
- const section = {
99
- ...previousValue,
100
- ...(previousValueDescription && {
101
- [sectionDescription]: previousValueDescription.concat([rowData]),
102
- }),
103
- }
104
- return section
105
- }, sectionedData)
106
- }
107
-
108
- /**
109
- * Gets the counts for rows in section
110
- *
111
- * @param {Dict<Cell[][]>} sectionedData
112
- * @param {string} sectionDescription
113
- * @return {*}
114
- * @memberof SectionedDataTableBuilder
115
- */
116
- getSectionCount(sectionedData: Dict<Cell[][]> | Dict<Dict<string>[]>, sectionDescription: string) {
117
- const count = sectionedData[sectionDescription] ? sectionedData[sectionDescription].length : 0
118
- const countDescription = `${count} result${count === 1 ? '' : 's'}`
119
-
120
- return {
121
- count,
122
- countDescription,
123
- }
124
- }
125
-
126
- /**
127
- * Creates the summaries and builds the table with summaries
128
- *
129
- * @private
130
- * @param {string} sectionDescription
131
- * @param {Cell[][]} mappedTableData
132
- * @param {Cell[]} header
133
- * @return {*}
134
- * @memberof SectionedDataTableBuilder
135
- */
136
- private mapSummariesAndCreateTable(sectionDescription: string, mappedTableData: Cell[][], header: Cell[]) {
137
- let tableContent: Cell[][] = []
138
-
139
- let mappedSectionHeaderSummary: Cell[][] = []
140
- let mappedHeaderSummary: Cell[][] = []
141
- let mappedFooterSummary: Cell[][] = []
142
- let mappedSectionFooterSummary: Cell[][] = []
143
-
144
- mappedSectionHeaderSummary = this.mapSectionSummaryTables(sectionDescription, 'section-header', this.columns.length)
145
- mappedHeaderSummary = this.mapSectionSummaryRows('table-header', sectionDescription)
146
- mappedFooterSummary = this.mapSectionSummaryRows('table-footer', sectionDescription)
147
- mappedSectionFooterSummary = this.mapSectionSummaryTables(sectionDescription, 'section-footer', this.columns.length)
148
-
149
- tableContent = mappedSectionHeaderSummary
150
- .concat(mappedTableData.length > 0 ? [header] : [])
151
- .concat(mappedHeaderSummary)
152
- .concat(mappedTableData)
153
- .concat(mappedFooterSummary)
154
- .concat(mappedSectionFooterSummary)
155
-
156
- return tableContent
157
- }
158
-
159
- /**
160
- * Creates the table data
161
- * - if summaries are present, includes the summaries data
162
- *
163
- * @private
164
- * @param {string[]} sectionDescriptions
165
- * @param {Dict<Cell[][]>} sectionedData
166
- * @param {Cell[]} header
167
- * @return {*}
168
- * @memberof SectionedDataTableBuilder
169
- */
170
- private createTableContent(sectionDescriptions: string[], sectionedData: Dict<Cell[][]>, header: Cell[]) {
171
- return sectionDescriptions.flatMap((sectionDescription, index) => {
172
- const { count, countDescription } = this.getSectionCount(sectionedData, sectionDescription)
173
- const mappedTableData = sectionedData[sectionDescription]
174
-
175
- let tableContent: Cell[][] = []
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
-
184
- const sectionHeader = this.createSectionHeader(sectionDescription, index, count, countDescription)
185
-
186
- return [...sectionHeader, ...tableContent]
187
- })
188
- }
189
-
190
- createSectionHeader(sectionDescription: string, index: number, count?: number, countDescription?: string) {
191
- const header = []
192
- if (index !== 0) {
193
- header.push([
194
- {
195
- classes: 'dpr-section-header-spacer',
196
- colspan: this.columns.length,
197
- text: '',
198
- },
199
- ])
200
- }
201
- header.push([
202
- {
203
- classes: 'dpr-section-header',
204
- colspan: this.columns.length,
205
- html: `<h2 class="govuk-heading-m">${sectionDescription}${
206
- count && count > 0 ? ` <span class='govuk-caption-m'>${countDescription}</span>` : ''
207
- }</h2>`,
208
- },
209
- ])
210
- header.push([
211
- {
212
- classes: 'dpr-section-header-spacer-bottom',
213
- colspan: this.columns.length,
214
- text: '',
215
- },
216
- ])
217
- return header
218
- }
219
-
220
- private mapSectionSummaryRows(template: SummaryTemplate, sectionDescription: string): Cell[][] {
221
- if (this.reportSummaries[template]) {
222
- return this.reportSummaries[template].flatMap((reportSummary) =>
223
- reportSummary.data
224
- .filter((rowData) => this.mapSectionDescription(rowData) === sectionDescription)
225
- .map((rowData) =>
226
- this.mapRow(
227
- rowData,
228
- `dpr-report-summary-cell dpr-report-summary-cell-${template}`,
229
- <components['schemas']['FieldDefinition'][]>reportSummary.fields,
230
- ),
231
- ),
232
- )
233
- }
234
- return []
235
- }
236
-
237
- private mapSectionSummaryTables(
238
- sectionDescription: string,
239
- summaryTemplate: SummaryTemplate,
240
- columnsLength: number,
241
- ): Cell[][] {
242
- const summaries = this.reportSummaries[summaryTemplate]
243
- if (summaries) {
244
- const htmlTables = summaries.map((summary) => {
245
- const data = summary.data.filter((row) => this.mapSectionDescription(row) === sectionDescription)
246
-
247
- if (data.length > 0) {
248
- const dataTable = new SummaryDataTableBuilder(summary, this.sections).buildTable(data)
249
-
250
- const htmlTable = this.convertDataTableToHtml(dataTable)
251
-
252
- return `<div class='dpr-summary-container'>${htmlTable}</div>`
253
- }
254
- return ''
255
- })
256
-
257
- const summaryContent = htmlTables.join('')
258
- if (summaryContent.length > 0) {
259
- return [
260
- [
261
- {
262
- classes: 'dpr-summary-cell',
263
- colspan: columnsLength,
264
- html: `<div class='dpr-summary-container-group dpr-summary-container-group-${summaryTemplate}'>${summaryContent}</div>`,
265
- },
266
- ],
267
- ]
268
- }
269
- }
270
- return []
271
- }
272
-
273
- mapSectionDescription(rowData: NodeJS.Dict<string>): string {
274
- const { sections } = this
275
-
276
- return this.mapNamesToFields(sections)
277
- .map((s) => `${s.display}: ${this.mapCellValue(s, rowData[s.name])}`)
278
- .join(', ')
279
- }
280
-
281
- mapSections(data: Array<Dict<string>>) {
282
- const sectionHeadings = this.initSectionedHeadings(data)
283
- let { sectionedData } = sectionHeadings
284
-
285
- // Maps data to sections
286
- if (this.template !== 'summary-section') {
287
- if (this.template === 'parent-child-section') {
288
- sectionedData = this.mapDataToSection(data, sectionedData as Dict<Dict<string>[]>)
289
- } else {
290
- sectionedData = this.mapRowsToSection(data, sectionedData as Dict<Cell[][]>)
291
- }
292
- }
293
-
294
- return {
295
- sectionDescriptions: sectionHeadings.sectionDescriptions,
296
- sectionedData,
297
- }
298
- }
299
-
300
- initSectionedHeadings(data: Array<Dict<string>>) {
301
- // Get the section definition data
302
- const sectionFields = this.mapNamesToFields(this.sections)
303
- // create the sectionHeadings
304
- const sectionDescriptions = this.createSectionHeadings(data, sectionFields)
305
- // init empty sections
306
- const sectionedData = this.initSectionData(sectionDescriptions)
307
-
308
- return {
309
- sectionDescriptions,
310
- sectionedData,
311
- }
312
- }
313
-
314
- /**
315
- * Creates the table rows.
316
- *
317
- * @private
318
- * @param {Array<Dict<string>>} data
319
- * @param {Cell[]} header
320
- * @return {*} {Cell[][]}
321
- * @memberof SectionedDataTableBuilder
322
- */
323
- private mapSectionedData(data: Array<Dict<string>>, header: Cell[]): Cell[][] {
324
- const { sectionDescriptions, sectionedData } = this.mapSections(data)
325
- // Create the table
326
- const tableContent = this.createTableContent(sectionDescriptions, sectionedData as Dict<Cell[][]>, header)
327
-
328
- return tableContent
329
- }
330
-
331
- override buildTable(data: Array<Dict<string>>): DataTable {
332
- return {
333
- head: null,
334
- rows: this.mapSectionedData(data, this.mapHeader(true, 'govuk-table__header')),
335
- rowCount: data.length,
336
- colCount: this.columns.length,
337
- }
338
- }
339
- }
340
-
341
- export { SectionedDataTableBuilder }
342
- export default SectionedDataTableBuilder
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../dpr/utils/SectionedDataTableBuilder/types.d.ts"],
4
- "sourcesContent": ["import { SortKey } from '../DataTableBuilder/types'\n\nexport interface SectionSortKey extends SortKey {\n description: string\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
6
- "names": []
7
- }
@@ -1,5 +0,0 @@
1
- import { SortKey } from '../DataTableBuilder/types'
2
-
3
- export interface SectionSortKey extends SortKey {
4
- description: string
5
- }
@@ -1,146 +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 SectionedFieldsTableBuilder_exports = {};
30
- __export(SectionedFieldsTableBuilder_exports, {
31
- SectionedFieldsDataTableBuilder: () => SectionedFieldsDataTableBuilder,
32
- default: () => SectionedFieldsTableBuilder_default
33
- });
34
- module.exports = __toCommonJS(SectionedFieldsTableBuilder_exports);
35
- var import_ParentChildDataTableBuilder = __toESM(require("../ParentChildDataTableBuilder/ParentChildDataTableBuilder"));
36
- class SectionedFieldsDataTableBuilder extends import_ParentChildDataTableBuilder.default {
37
- // TODO: change this to use schema type if ever implemented in the backend
38
- sectionedFields;
39
- constructor(variant) {
40
- const { sectionedFields, template } = variant.specification;
41
- super(variant);
42
- this.sectionedFields = sectionedFields;
43
- this.sections = this.sectionedFields.map((f) => f.name);
44
- this.template = template;
45
- this.childVariants = this.variant.childVariants || [];
46
- }
47
- getChildFields(childId) {
48
- const childVariant = this.childVariants.find((child) => child.id === childId);
49
- let fields = [];
50
- if (childVariant) {
51
- const { specification } = childVariant;
52
- fields = specification ? specification.fields : fields;
53
- }
54
- return fields;
55
- }
56
- getJoinKey() {
57
- return this.childVariants[0].joinFields[0];
58
- }
59
- initSectionedData(data) {
60
- return data.flatMap((row) => {
61
- const initialisedSectionsWithFields = this.sectionedFields.map((section) => {
62
- const sectionHeader = this.mapNamesToFields([section.name])[0];
63
- let fields = [];
64
- const { child } = section;
65
- if (section.fields) {
66
- fields = this.mapNamesToFields(section.fields);
67
- } else if (section.child) {
68
- fields = this.getChildFields(section.child);
69
- }
70
- return {
71
- header: sectionHeader,
72
- fields,
73
- child
74
- };
75
- });
76
- return initialisedSectionsWithFields.map((section) => {
77
- if (section.child) {
78
- const childData = this.getChildData(section.child);
79
- const displayFields = section.fields.filter((f) => f.visible);
80
- const joinKey = this.getJoinKey();
81
- return {
82
- header: section.header.display,
83
- fields: childData ? childData.data.filter((cd) => cd[joinKey] === row[joinKey]).map((cd) => {
84
- return {
85
- heading: cd[displayFields[0]?.name] || "Not found",
86
- data: cd[displayFields[1]?.name] || "Not found"
87
- };
88
- }) : []
89
- };
90
- }
91
- return {
92
- header: section.header.display,
93
- fields: section.fields.filter((f) => f.visible).map((f) => {
94
- return {
95
- heading: f.display,
96
- data: row[f.name]
97
- };
98
- })
99
- };
100
- });
101
- });
102
- }
103
- getChildData(childId) {
104
- return this.childData.find((d) => d.id === childId);
105
- }
106
- createRows(data) {
107
- const sectionedData = this.initSectionedData(data);
108
- const rows = sectionedData.flatMap((section, index) => {
109
- let sectionHeaderRow = [];
110
- if (section.header) {
111
- sectionHeaderRow = this.createSectionHeader(section.header, index);
112
- }
113
- const sectionRows = section.fields.map((field) => {
114
- return [
115
- {
116
- text: field.heading,
117
- classes: "dpr-row-heading"
118
- },
119
- {
120
- text: field.data,
121
- classes: "dpr-row-heading-data"
122
- }
123
- ];
124
- });
125
- return [...sectionHeaderRow, ...sectionRows];
126
- });
127
- return rows;
128
- }
129
- buildTable(data) {
130
- return {
131
- head: [
132
- // { text: '', classes: 'dpr-row-section-header' },
133
- // { text: '', classes: 'dpr-row-section-header-value' },
134
- ],
135
- rows: this.createRows(data),
136
- rowCount: data.length,
137
- colCount: this.columns.length
138
- };
139
- }
140
- }
141
- var SectionedFieldsTableBuilder_default = SectionedFieldsDataTableBuilder;
142
- // Annotate the CommonJS export names for ESM import in node:
143
- 0 && (module.exports = {
144
- SectionedFieldsDataTableBuilder
145
- });
146
- //# sourceMappingURL=SectionedFieldsTableBuilder.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../dpr/utils/SectionedFieldsTableBuilder/SectionedFieldsTableBuilder.ts"],
4
- "sourcesContent": ["import Dict = NodeJS.Dict\nimport { components } from '../../types/api'\nimport { Cell, DataTable, FieldDefinition } from '../DataTableBuilder/types'\nimport type { Template } from '../../types/Templates'\nimport ParentChildDataTableBuilder from '../ParentChildDataTableBuilder/ParentChildDataTableBuilder'\n\nexport interface SectionedField {\n name: string\n fields?: string[]\n child?: string\n}\n\nclass SectionedFieldsDataTableBuilder extends ParentChildDataTableBuilder {\n // TODO: change this to use schema type if ever implemented in the backend\n sectionedFields: SectionedField[]\n\n declare template: Template\n\n declare childVariants: components['schemas']['ChildVariantDefinition'][]\n\n constructor(variant: components['schemas']['VariantDefinition']) {\n // TODO: removed the union if sectionedFields changed to use schema type\n const { sectionedFields, template } = variant.specification as components['schemas']['Specification'] & {\n sectionedFields: SectionedField[]\n }\n super(variant)\n\n this.sectionedFields = sectionedFields\n this.sections = this.sectionedFields.map((f) => f.name)\n this.template = template\n this.childVariants = this.variant.childVariants || []\n }\n\n getChildFields(childId: string): FieldDefinition[] {\n const childVariant = this.childVariants.find((child) => child.id === childId)\n let fields: FieldDefinition[] = []\n if (childVariant) {\n const { specification } = childVariant\n fields = specification ? specification.fields : fields\n }\n return fields\n }\n\n getJoinKey() {\n return this.childVariants[0].joinFields[0]\n }\n\n initSectionedData(data: Array<Dict<string>>) {\n return data.flatMap((row) => {\n const initialisedSectionsWithFields = this.sectionedFields.map((section) => {\n const sectionHeader = this.mapNamesToFields([section.name])[0]\n\n let fields: FieldDefinition[] = []\n const { child } = section\n\n if (section.fields) {\n fields = this.mapNamesToFields(section.fields)\n } else if (section.child) {\n fields = this.getChildFields(section.child)\n }\n\n return {\n header: sectionHeader,\n fields,\n child,\n }\n })\n\n return initialisedSectionsWithFields.map((section) => {\n if (section.child) {\n const childData = this.getChildData(section.child)\n const displayFields = section.fields.filter((f) => f.visible)\n const joinKey = this.getJoinKey()\n\n return {\n header: section.header.display,\n fields: childData\n ? childData.data\n .filter((cd) => cd[joinKey] === row[joinKey])\n .map((cd) => {\n return {\n heading: cd[displayFields[0]?.name] || 'Not found',\n data: cd[displayFields[1]?.name] || 'Not found',\n }\n })\n : [],\n }\n }\n return {\n header: section.header.display,\n fields: section.fields\n .filter((f) => f.visible)\n .map((f) => {\n return {\n heading: f.display,\n data: row[f.name],\n }\n }),\n }\n })\n })\n }\n\n getChildData(childId: string) {\n return this.childData.find((d) => d.id === childId)\n }\n\n createRows(data: Array<Dict<string>>): Cell[][] {\n const sectionedData = this.initSectionedData(data)\n\n const rows = sectionedData.flatMap((section, index) => {\n let sectionHeaderRow: Cell[][] = []\n if (section.header) {\n sectionHeaderRow = this.createSectionHeader(section.header, index)\n }\n\n const sectionRows = section.fields.map((field) => {\n return [\n {\n text: field.heading,\n classes: 'dpr-row-heading',\n },\n {\n text: field.data,\n classes: 'dpr-row-heading-data',\n },\n ]\n })\n\n return [...sectionHeaderRow, ...sectionRows]\n })\n\n return rows\n }\n\n override buildTable(data: Array<Dict<string>>): DataTable {\n return {\n head: [\n // { text: '', classes: 'dpr-row-section-header' },\n // { text: '', classes: 'dpr-row-section-header-value' },\n ],\n rows: this.createRows(data),\n rowCount: data.length,\n colCount: this.columns.length,\n }\n }\n}\n\nexport { SectionedFieldsDataTableBuilder }\nexport default SectionedFieldsDataTableBuilder\n"],
5
- "mappings": "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",
6
- "names": ["ParentChildDataTableBuilder"]
7
- }
@@ -1,140 +0,0 @@
1
- import { expect } from '@jest/globals'
2
- import { components } from '../../types/api'
3
- import SectionedFieldsTableBuilder from './SectionedFieldsTableBuilder'
4
-
5
- // Definitions
6
- import variant30 from '../../../../test-app/mocks/mockClients/reports/mockVariants/report-templates/row-section'
7
- import variant31 from '../../../../test-app/mocks/mockClients/reports/mockVariants/report-templates/row-section-child'
8
-
9
- // Data
10
- import variant30Data from '../../../../test-app/mocks/mockClients/reports/mockVariants/data/row-section'
11
- import variant31Data from '../../../../test-app/mocks/mockClients/reports/mockVariants/data/row-section-child'
12
-
13
- describe('SectionedFieldsDataTableBuilder', () => {
14
- let rowSectionVariant: components['schemas']['VariantDefinition']
15
- let rowSectionChildVariant: components['schemas']['VariantDefinition']
16
-
17
- beforeEach(() => {
18
- rowSectionVariant = variant30 as unknown as components['schemas']['VariantDefinition']
19
- rowSectionChildVariant = variant31 as unknown as components['schemas']['VariantDefinition']
20
- })
21
-
22
- it('Sections added correctly', () => {
23
- const table = new SectionedFieldsTableBuilder(rowSectionVariant)
24
- .withHeaderOptions({
25
- columns: new Array(2),
26
- interactive: Boolean(rowSectionVariant.interactive),
27
- })
28
- .withChildData([])
29
- .buildTable(variant30Data)
30
-
31
- expect(table).toEqual({
32
- head: [],
33
- rows: [
34
- [{ classes: 'dpr-section-header', colspan: 2, html: '<h2 class="govuk-heading-m">Section 1 title</h2>' }],
35
- [{ classes: 'dpr-section-header-spacer-bottom', colspan: 2, text: '' }],
36
- [
37
- { text: 'Field One', classes: 'dpr-row-heading' },
38
- { text: 'Value 1', classes: 'dpr-row-heading-data' },
39
- ],
40
- [
41
- { text: 'Field Two', classes: 'dpr-row-heading' },
42
- { text: 'Value 2', classes: 'dpr-row-heading-data' },
43
- ],
44
- [{ classes: 'dpr-section-header-spacer', colspan: 2, text: '' }],
45
- [{ classes: 'dpr-section-header', colspan: 2, html: '<h2 class="govuk-heading-m">Second 2 title</h2>' }],
46
- [{ classes: 'dpr-section-header-spacer-bottom', colspan: 2, text: '' }],
47
- [
48
- { text: 'Field Three', classes: 'dpr-row-heading' },
49
- { text: 'Value 3', classes: 'dpr-row-heading-data' },
50
- ],
51
- [
52
- { text: 'Field Four', classes: 'dpr-row-heading' },
53
- { text: 'Value 4', classes: 'dpr-row-heading-data' },
54
- ],
55
- [{ classes: 'dpr-section-header-spacer', colspan: 2, text: '' }],
56
- [{ classes: 'dpr-section-header', colspan: 2, html: '<h2 class="govuk-heading-m">Section 3 title</h2>' }],
57
- [{ classes: 'dpr-section-header-spacer-bottom', colspan: 2, text: '' }],
58
- [
59
- { text: 'Field Five', classes: 'dpr-row-heading' },
60
- { text: 'Value 5', classes: 'dpr-row-heading-data' },
61
- ],
62
- [
63
- { text: 'Field Six', classes: 'dpr-row-heading' },
64
- { text: 'Value 6', classes: 'dpr-row-heading-data' },
65
- ],
66
- ],
67
- rowCount: 1,
68
- colCount: 2,
69
- })
70
- })
71
-
72
- it('Sections and children added correctly', () => {
73
- const table = new SectionedFieldsTableBuilder(rowSectionChildVariant)
74
- .withHeaderOptions({
75
- columns: new Array(2),
76
- interactive: Boolean(rowSectionChildVariant.interactive),
77
- })
78
- .withChildData([
79
- {
80
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
81
- id: rowSectionChildVariant.childVariants![0].id,
82
- data: variant31Data.childData(),
83
- },
84
- {
85
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
86
- id: rowSectionChildVariant.childVariants![1].id,
87
- data: variant31Data.childData2(),
88
- },
89
- ])
90
- .buildTable(variant31Data.parentData())
91
-
92
- expect(table).toEqual({
93
- head: [],
94
- rows: [
95
- [{ classes: 'dpr-section-header', colspan: 2, html: '<h2 class="govuk-heading-m">Data columns as rows</h2>' }],
96
- [{ classes: 'dpr-section-header-spacer-bottom', colspan: 2, text: '' }],
97
- [
98
- { text: 'Field One', classes: 'dpr-row-heading' },
99
- { text: 'Value 1', classes: 'dpr-row-heading-data' },
100
- ],
101
- [
102
- { text: 'Field Two', classes: 'dpr-row-heading' },
103
- { text: 'Value 2', classes: 'dpr-row-heading-data' },
104
- ],
105
- [{ classes: 'dpr-section-header-spacer', colspan: 2, text: '' }],
106
- [{ classes: 'dpr-section-header', colspan: 2, html: '<h2 class="govuk-heading-m">Child report</h2>' }],
107
- [{ classes: 'dpr-section-header-spacer-bottom', colspan: 2, text: '' }],
108
- [
109
- { text: 'Han Solo', classes: 'dpr-row-heading' },
110
- { text: 'Never tell me the odds.', classes: 'dpr-row-heading-data' },
111
- ],
112
- [
113
- { text: 'Master Yoda', classes: 'dpr-row-heading' },
114
- { text: 'Do or do not. There is no try', classes: 'dpr-row-heading-data' },
115
- ],
116
- [
117
- { text: 'Obi-wan Kenobi', classes: 'dpr-row-heading' },
118
- { text: 'Hello there', classes: 'dpr-row-heading-data' },
119
- ],
120
- [{ classes: 'dpr-section-header-spacer', colspan: 2, text: '' }],
121
- [{ classes: 'dpr-section-header', colspan: 2, html: '<h2 class="govuk-heading-m">Child report 2</h2>' }],
122
- [{ classes: 'dpr-section-header-spacer-bottom', colspan: 2, text: '' }],
123
- [
124
- { text: 'Homer Simpson', classes: 'dpr-row-heading' },
125
- { text: 'Doh!', classes: 'dpr-row-heading-data' },
126
- ],
127
- [
128
- { text: 'Mr Burns', classes: 'dpr-row-heading' },
129
- { text: 'Excellent!', classes: 'dpr-row-heading-data' },
130
- ],
131
- [
132
- { text: 'Ned Flanders', classes: 'dpr-row-heading' },
133
- { text: 'Hi-diddly-ho, neighborino', classes: 'dpr-row-heading-data' },
134
- ],
135
- ],
136
- rowCount: 1,
137
- colCount: 2,
138
- })
139
- })
140
- })