@ministryofjustice/hmpps-digital-prison-reporting-frontend 4.28.8 → 4.29.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (197) 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/ChartTimeseries.js +3 -2
  7. package/dpr/components/_charts/chart/ChartTimeseries.js.map +2 -2
  8. package/dpr/components/_charts/chart/ChartTimeseries.ts +4 -2
  9. package/dpr/components/_charts/chart/clientClass.js +1 -0
  10. package/dpr/components/_charts/chart/clientClass.js.map +2 -2
  11. package/dpr/components/_charts/chart/clientClass.ts +1 -0
  12. package/dpr/components/_reports/{report-actions → report-heading/report-actions}/actionsTemplate.js.map +1 -1
  13. package/dpr/components/_reports/{report-actions → report-heading/report-actions}/clientClass.js +1 -1
  14. package/dpr/components/_reports/report-heading/report-actions/clientClass.js.map +7 -0
  15. package/dpr/components/_reports/{report-actions → report-heading/report-actions}/clientClass.ts +1 -1
  16. package/dpr/components/_reports/report-heading/report-actions/types.d.js.map +7 -0
  17. package/dpr/components/_reports/{report-actions → report-heading/report-actions}/types.d.ts +1 -1
  18. package/dpr/components/_reports/{report-actions → report-heading/report-actions}/utils.js.map +1 -1
  19. package/dpr/components/_reports/{report-actions → report-heading/report-actions}/utils.test.ts +2 -2
  20. package/dpr/components/_reports/{report-columns-form → report-heading/report-columns/report-columns-form}/clientClass.js +1 -3
  21. package/dpr/components/_reports/report-heading/report-columns/report-columns-form/clientClass.js.map +7 -0
  22. package/dpr/components/_reports/{report-columns-form → report-heading/report-columns/report-columns-form}/clientClass.ts +1 -3
  23. package/dpr/components/_reports/{report-columns-form → report-heading/report-columns/report-columns-form}/types.d.js.map +1 -1
  24. package/dpr/components/_reports/{report-columns-form → report-heading/report-columns/report-columns-form}/utils.js +1 -1
  25. package/dpr/components/_reports/report-heading/report-columns/report-columns-form/utils.js.map +7 -0
  26. package/dpr/components/_reports/{report-columns-form → report-heading/report-columns/report-columns-form}/utils.ts +2 -2
  27. package/dpr/components/_reports/{report-columns → report-heading/report-columns}/view.njk +1 -1
  28. package/dpr/components/_reports/{report-download-message → report-heading/report-download-message}/clientClass.js +1 -1
  29. package/dpr/components/_reports/report-heading/report-download-message/clientClass.js.map +7 -0
  30. package/dpr/components/_reports/{report-download-message → report-heading/report-download-message}/clientClass.ts +1 -1
  31. package/dpr/components/_reports/{report-filters → report-heading/report-filters}/view.njk +1 -1
  32. package/dpr/components/_reports/report-heading/view.njk +4 -4
  33. package/dpr/components/_reports/report-page/report-print-message/view.njk +10 -0
  34. package/dpr/components/_reports/report-page/report-template/report-no-data-message/styles.scss +8 -0
  35. package/dpr/components/_reports/report-page/report-template/report-no-data-message/view.njk +11 -0
  36. package/dpr/components/_reports/{report-pagination → report-page/report-template/report-pagination}/clientClass.js +1 -1
  37. package/dpr/components/_reports/report-page/report-template/report-pagination/clientClass.js.map +7 -0
  38. package/dpr/components/_reports/{report-pagination → report-page/report-template/report-pagination}/clientClass.ts +1 -1
  39. package/dpr/components/_reports/{report-pagination → report-page/report-template/report-pagination}/types.d.js.map +1 -1
  40. package/dpr/components/_reports/{report-pagination → report-page/report-template/report-pagination}/utils.js.map +1 -1
  41. package/dpr/components/_reports/report-page/report-template/report-section/parent-child-template/styles.scss +88 -0
  42. package/dpr/components/_reports/report-page/report-template/report-section/parent-child-template/view.njk +29 -0
  43. package/dpr/components/_reports/{report-data-table → report-page/report-template/report-section/report-data-table}/clientClass.js +17 -10
  44. package/dpr/components/_reports/report-page/report-template/report-section/report-data-table/clientClass.js.map +7 -0
  45. package/dpr/components/_reports/{report-data-table → report-page/report-template/report-section/report-data-table}/clientClass.ts +20 -10
  46. package/dpr/components/_reports/{report-data-table → report-page/report-template/report-section/report-data-table}/style.scss +35 -185
  47. package/dpr/components/_reports/report-page/report-template/report-section/report-data-table/types.d.js.map +7 -0
  48. package/dpr/components/_reports/{report-data-table → report-page/report-template/report-section/report-data-table}/types.d.ts +2 -2
  49. package/dpr/components/_reports/report-page/report-template/report-section/report-data-table/view.njk +27 -0
  50. package/dpr/components/_reports/report-page/report-template/report-section/styles.scss +33 -0
  51. package/dpr/components/_reports/report-page/report-template/report-section/view.njk +58 -0
  52. package/dpr/components/_reports/{report-summary-table → report-page/report-template/report-summary-table}/styles.scss +21 -4
  53. package/dpr/components/_reports/{report-totals → report-page/report-template/report-totals}/utils.js.map +1 -1
  54. package/dpr/components/_reports/report-page/report-template/styles.scss +5 -0
  55. package/dpr/components/_reports/report-page/report-template/template-config.js +66 -0
  56. package/dpr/components/_reports/report-page/report-template/template-config.js.map +7 -0
  57. package/dpr/components/_reports/report-page/report-template/template-config.ts +45 -0
  58. package/dpr/components/_reports/report-page/report-template/utils.js +82 -0
  59. package/dpr/components/_reports/report-page/report-template/utils.js.map +7 -0
  60. package/dpr/components/_reports/report-page/report-template/utils.ts +100 -0
  61. package/dpr/components/_reports/report-page/report-template/view.njk +61 -0
  62. package/dpr/components/_reports/{report-wrapper → report-page}/styles.scss +7 -5
  63. package/dpr/components/_reports/report-page/view.njk +26 -0
  64. package/dpr/components/card-group/view.njk +0 -4
  65. package/dpr/components/report-list/utils.js +11 -3
  66. package/dpr/components/report-list/utils.js.map +2 -2
  67. package/dpr/components/report-list/utils.ts +11 -1
  68. package/dpr/components/report-list/view.njk +2 -2
  69. package/dpr/components/show-more/style.scss +3 -4
  70. package/dpr/data/reportingClient.js.map +2 -2
  71. package/dpr/data/reportingClient.ts +4 -4
  72. package/dpr/routes/journeys/view-report/async/dashboard/utils.js +1 -1
  73. package/dpr/routes/journeys/view-report/async/dashboard/utils.js.map +1 -1
  74. package/dpr/routes/journeys/view-report/async/dashboard/utils.ts +1 -1
  75. package/dpr/routes/journeys/view-report/async/report/controller.js.map +2 -2
  76. package/dpr/routes/journeys/view-report/async/report/controller.ts +0 -1
  77. package/dpr/routes/journeys/view-report/async/report/report-variants.cy.js +207 -56
  78. package/dpr/routes/journeys/view-report/async/report/report-variants.cy.js.map +2 -2
  79. package/dpr/routes/journeys/view-report/async/report/report-variants.cy.ts +333 -64
  80. package/dpr/routes/journeys/view-report/async/report/utils.js +9 -17
  81. package/dpr/routes/journeys/view-report/async/report/utils.js.map +3 -3
  82. package/dpr/routes/journeys/view-report/async/report/utils.ts +12 -22
  83. package/dpr/routes/journeys/view-report/report.njk +2 -2
  84. package/dpr/routes/journeys/view-report/sync/dashboard/utils.js +1 -1
  85. package/dpr/routes/journeys/view-report/sync/dashboard/utils.js.map +1 -1
  86. package/dpr/routes/journeys/view-report/sync/dashboard/utils.ts +1 -1
  87. package/dpr/routes/journeys/view-report/sync/report/utils.js +38 -11
  88. package/dpr/routes/journeys/view-report/sync/report/utils.js.map +3 -3
  89. package/dpr/routes/journeys/view-report/sync/report/utils.ts +39 -14
  90. package/dpr/routes/journeys/view-report/utils.js +1 -1
  91. package/dpr/routes/journeys/view-report/utils.js.map +1 -1
  92. package/dpr/routes/journeys/view-report/utils.ts +1 -1
  93. package/dpr/services/reportingService.js.map +2 -2
  94. package/dpr/services/reportingService.ts +2 -2
  95. package/dpr/types/ReportQuery.js +1 -1
  96. package/dpr/types/ReportQuery.js.map +1 -1
  97. package/dpr/types/ReportQuery.ts +1 -1
  98. package/dpr/types/UserReports.js.map +1 -1
  99. package/dpr/types/UserReports.ts +3 -3
  100. package/dpr/utils/TemplateBuilder/ParentChildDataBuilder/ParentChildDataBuilder.js +193 -0
  101. package/dpr/utils/TemplateBuilder/ParentChildDataBuilder/ParentChildDataBuilder.js.map +7 -0
  102. package/dpr/utils/TemplateBuilder/ParentChildDataBuilder/ParentChildDataBuilder.ts +203 -0
  103. package/dpr/utils/TemplateBuilder/ParentChildDataBuilder/types.d.js.map +7 -0
  104. package/dpr/utils/TemplateBuilder/ParentChildDataBuilder/types.d.ts +36 -0
  105. package/dpr/utils/TemplateBuilder/ReportBuilder/ReportBuilder.js +114 -0
  106. package/dpr/utils/TemplateBuilder/ReportBuilder/ReportBuilder.js.map +7 -0
  107. package/dpr/utils/TemplateBuilder/ReportBuilder/ReportBuilder.ts +117 -0
  108. package/dpr/utils/TemplateBuilder/ReportBuilder/types.d.js.map +7 -0
  109. package/dpr/utils/TemplateBuilder/ReportBuilder/types.d.ts +6 -0
  110. package/dpr/utils/TemplateBuilder/SectionedDataHelper/SectionedDataHelper.js +202 -0
  111. package/dpr/utils/TemplateBuilder/SectionedDataHelper/SectionedDataHelper.js.map +7 -0
  112. package/dpr/utils/TemplateBuilder/SectionedDataHelper/SectionedDataHelper.ts +246 -0
  113. package/dpr/utils/TemplateBuilder/SectionedDataHelper/types.js +17 -0
  114. package/dpr/utils/TemplateBuilder/SectionedDataHelper/types.js.map +7 -0
  115. package/dpr/utils/TemplateBuilder/SectionedDataHelper/types.ts +41 -0
  116. package/dpr/utils/{CollatedSummaryBuilder/CollatedSummaryBuilder.js → TemplateBuilder/SummaryDataHelper/SummaryDataHelper.js} +6 -8
  117. package/dpr/utils/TemplateBuilder/SummaryDataHelper/SummaryDataHelper.js.map +7 -0
  118. package/dpr/utils/{CollatedSummaryBuilder/CollatedSummaryBuilder.test.ts → TemplateBuilder/SummaryDataHelper/SummaryDataHelper.test.ts} +4 -4
  119. package/dpr/utils/{CollatedSummaryBuilder/CollatedSummaryBuilder.ts → TemplateBuilder/SummaryDataHelper/SummaryDataHelper.ts} +6 -9
  120. package/dpr/utils/TemplateBuilder/TemplateBuilder.js +74 -0
  121. package/dpr/utils/TemplateBuilder/TemplateBuilder.js.map +7 -0
  122. package/dpr/utils/TemplateBuilder/TemplateBuilder.ts +68 -0
  123. package/dpr/utils/definitionUtils.js +22 -2
  124. package/dpr/utils/definitionUtils.js.map +2 -2
  125. package/dpr/utils/definitionUtils.ts +26 -1
  126. package/package.json +1 -1
  127. package/dpr/DprLoadingHelper.js +0 -51
  128. package/dpr/DprLoadingHelper.js.map +0 -7
  129. package/dpr/DprLoadingHelper.ts +0 -27
  130. package/dpr/components/_reports/report/view.njk +0 -40
  131. package/dpr/components/_reports/report-actions/clientClass.js.map +0 -7
  132. package/dpr/components/_reports/report-actions/types.d.js.map +0 -7
  133. package/dpr/components/_reports/report-columns-form/clientClass.js.map +0 -7
  134. package/dpr/components/_reports/report-columns-form/utils.js.map +0 -7
  135. package/dpr/components/_reports/report-data-table/clientClass.js.map +0 -7
  136. package/dpr/components/_reports/report-data-table/types.d.js.map +0 -7
  137. package/dpr/components/_reports/report-data-table/utils.js +0 -123
  138. package/dpr/components/_reports/report-data-table/utils.js.map +0 -7
  139. package/dpr/components/_reports/report-data-table/utils.test.ts +0 -604
  140. package/dpr/components/_reports/report-data-table/utils.ts +0 -150
  141. package/dpr/components/_reports/report-data-table/view.njk +0 -24
  142. package/dpr/components/_reports/report-data-table-wrapper/view.njk +0 -27
  143. package/dpr/components/_reports/report-download-message/clientClass.js.map +0 -7
  144. package/dpr/components/_reports/report-no-data-message/styles.scss +0 -4
  145. package/dpr/components/_reports/report-no-data-message/view.njk +0 -13
  146. package/dpr/components/_reports/report-pagination/clientClass.js.map +0 -7
  147. package/dpr/components/_reports/report-print-message/view.njk +0 -8
  148. package/dpr/components/_reports/report-template/view.njk +0 -44
  149. package/dpr/components/_reports/report-wrapper/view.njk +0 -19
  150. package/dpr/components/loading-anim/styles.scss +0 -117
  151. package/dpr/components/loading-anim/view.njk +0 -18
  152. package/dpr/utils/CollatedSummaryBuilder/CollatedSummaryBuilder.js.map +0 -7
  153. package/dpr/utils/ParentChildDataTableBuilder/ParentChildDataTableBuilder.js +0 -202
  154. package/dpr/utils/ParentChildDataTableBuilder/ParentChildDataTableBuilder.js.map +0 -7
  155. package/dpr/utils/ParentChildDataTableBuilder/ParentChildDataTableBuilder.test.ts +0 -503
  156. package/dpr/utils/ParentChildDataTableBuilder/ParentChildDataTableBuilder.ts +0 -224
  157. package/dpr/utils/ParentChildDataTableBuilder/types.d.js.map +0 -7
  158. package/dpr/utils/ParentChildDataTableBuilder/types.d.ts +0 -11
  159. package/dpr/utils/SectionedDataTableBuilder/SectionedDataTableBuilder.js +0 -311
  160. package/dpr/utils/SectionedDataTableBuilder/SectionedDataTableBuilder.js.map +0 -7
  161. package/dpr/utils/SectionedDataTableBuilder/SectionedDataTableBuilder.test.ts +0 -492
  162. package/dpr/utils/SectionedDataTableBuilder/SectionedDataTableBuilder.ts +0 -342
  163. package/dpr/utils/SectionedDataTableBuilder/types.d.js.map +0 -7
  164. package/dpr/utils/SectionedDataTableBuilder/types.d.ts +0 -5
  165. package/dpr/utils/SectionedFieldsTableBuilder/SectionedFieldsTableBuilder.js +0 -146
  166. package/dpr/utils/SectionedFieldsTableBuilder/SectionedFieldsTableBuilder.js.map +0 -7
  167. package/dpr/utils/SectionedFieldsTableBuilder/SectionedFieldsTableBuilder.test.ts +0 -140
  168. package/dpr/utils/SectionedFieldsTableBuilder/SectionedFieldsTableBuilder.ts +0 -150
  169. /package/dpr/components/_reports/{report-actions → report-heading/report-actions}/actionsTemplate.js +0 -0
  170. /package/dpr/components/_reports/{report-actions → report-heading/report-actions}/actionsTemplate.ts +0 -0
  171. /package/dpr/components/_reports/{report-actions → report-heading/report-actions}/style.scss +0 -0
  172. /package/dpr/components/_reports/{report-actions → report-heading/report-actions}/types.d.js +0 -0
  173. /package/dpr/components/_reports/{report-actions → report-heading/report-actions}/utils.js +0 -0
  174. /package/dpr/components/_reports/{report-actions → report-heading/report-actions}/utils.ts +0 -0
  175. /package/dpr/components/_reports/{report-actions → report-heading/report-actions}/view.njk +0 -0
  176. /package/dpr/components/_reports/{report-columns-form → report-heading/report-columns/report-columns-form}/style.scss +0 -0
  177. /package/dpr/components/_reports/{report-columns-form → report-heading/report-columns/report-columns-form}/types.d.js +0 -0
  178. /package/dpr/components/_reports/{report-columns-form → report-heading/report-columns/report-columns-form}/types.d.ts +0 -0
  179. /package/dpr/components/_reports/{report-columns-form → report-heading/report-columns/report-columns-form}/view.njk +0 -0
  180. /package/dpr/components/_reports/{report-columns → report-heading/report-columns}/styles.scss +0 -0
  181. /package/dpr/components/_reports/{report-download-message → report-heading/report-download-message}/style.scss +0 -0
  182. /package/dpr/components/_reports/{report-download-message → report-heading/report-download-message}/view.njk +0 -0
  183. /package/dpr/components/_reports/{report-pagination → report-page/report-template/report-pagination}/style.scss +0 -0
  184. /package/dpr/components/_reports/{report-data-table → report-page/report-template/report-pagination}/types.d.js +0 -0
  185. /package/dpr/components/_reports/{report-pagination → report-page/report-template/report-pagination}/types.d.ts +0 -0
  186. /package/dpr/components/_reports/{report-pagination → report-page/report-template/report-pagination}/utils.js +0 -0
  187. /package/dpr/components/_reports/{report-pagination → report-page/report-template/report-pagination}/utils.test.ts +0 -0
  188. /package/dpr/components/_reports/{report-pagination → report-page/report-template/report-pagination}/utils.ts +0 -0
  189. /package/dpr/components/_reports/{report-pagination → report-page/report-template/report-pagination}/view.njk +0 -0
  190. /package/dpr/components/_reports/{report-pagination → report-page/report-template/report-section/report-data-table}/types.d.js +0 -0
  191. /package/dpr/components/_reports/{report-summary-table → report-page/report-template/report-summary-table}/view.njk +0 -0
  192. /package/dpr/components/_reports/{report-totals → report-page/report-template/report-totals}/style.scss +0 -0
  193. /package/dpr/components/_reports/{report-totals → report-page/report-template/report-totals}/utils.js +0 -0
  194. /package/dpr/components/_reports/{report-totals → report-page/report-template/report-totals}/utils.ts +0 -0
  195. /package/dpr/components/_reports/{report-totals → report-page/report-template/report-totals}/view.njk +0 -0
  196. /package/dpr/utils/{ParentChildDataTableBuilder → TemplateBuilder/ParentChildDataBuilder}/types.d.js +0 -0
  197. /package/dpr/utils/{SectionedDataTableBuilder → TemplateBuilder/ReportBuilder}/types.d.js +0 -0
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../dpr/utils/ParentChildDataTableBuilder/ParentChildDataTableBuilder.ts"],
4
- "sourcesContent": ["import Dict = NodeJS.Dict\nimport { components } from '../../types/api'\nimport { Cell, DataTable } from '../DataTableBuilder/types'\nimport DataTableBuilder from '../DataTableBuilder/DataTableBuilder'\nimport { distinct } from '../arrayUtils'\nimport { ChildData, ParentChildSortKey } from './types'\nimport SectionedDataTableBuilder from '../SectionedDataTableBuilder/SectionedDataTableBuilder'\n\nclass ParentChildDataTableBuilder extends SectionedDataTableBuilder {\n variant: components['schemas']['VariantDefinition']\n\n childVariants: components['schemas']['ChildVariantDefinition'][]\n\n childData: Array<ChildData> = []\n\n constructor(variant: components['schemas']['VariantDefinition']) {\n const { specification } = variant\n const { sections, template } = <components['schemas']['Specification']>specification\n super(<components['schemas']['Specification']>specification)\n\n this.sections = sections\n this.template = template\n this.variant = variant\n this.childVariants = this.variant.childVariants || []\n }\n\n private createParentChildTable(parentData: Array<Dict<string>>, header: Cell[]) {\n let sectionedParentChildData: Dict<Dict<Array<Dict<string>>>> = {}\n const joinFields = this.mapNamesToFields(this.childVariants.flatMap((c) => c.joinFields).reduce(distinct, []))\n // Get the parent-child joins definition data\n\n // Create the section keys and\n const parentChildKeys = this.calculateParentChildKeys(parentData, joinFields)\n parentChildKeys.forEach((parentKey) => {\n sectionedParentChildData[parentKey.sortKey] = {\n parent: [],\n }\n })\n\n sectionedParentChildData = this.splitParentDataIntoSections(sectionedParentChildData, parentData, joinFields)\n sectionedParentChildData = this.splitChildDataIntoSections(parentChildKeys, sectionedParentChildData)\n\n const childDataTableBuilders = this.createChildDataTableBuilders()\n\n const parentChildTable = parentChildKeys.flatMap((key) => {\n const sectionData = sectionedParentChildData[key.sortKey] || {}\n\n let parentSectionData: Dict<string>[] = []\n if (sectionData) {\n parentSectionData = sectionData['parent'] ? sectionData['parent'] : []\n }\n\n return [header].concat(parentSectionData.map((r) => this.mapRow(r, 'dpr-parent-cell'))).concat(\n this.childVariants\n .filter((childVariant) => sectionData && sectionData[childVariant.id])\n .map((childVariant) => {\n const builder = childDataTableBuilders[childVariant.id]\n const section = sectionData[childVariant.id]\n const dataTable = builder && section ? builder.buildTable(section) : undefined\n const dataTableHtml = dataTable ? this.convertDataTableToHtml(dataTable) : ''\n\n return [\n {\n classes: 'dpr-child-report-cell',\n format: 'string',\n html: `<div class='dpr-child-report'><h2 class=\"govuk-heading-s\">${childVariant.name}</h2><div class=\"dpr-child-report_table\">${dataTableHtml}</div></div>`,\n colspan: this.columns.length,\n },\n ]\n }),\n )\n })\n\n return parentChildTable\n }\n\n private createParentChildSectionRows(parentData: Array<Dict<string>>, header: Cell[]) {\n const sectionsDetails = this.mapSections(parentData)\n const sectionedData = sectionsDetails.sectionedData as Dict<Array<Dict<string>>>\n const sectionedParentChildSectionedRows: {\n sectionDescription: string\n rows: Cell[][]\n count: number\n countDescription: string\n }[] = []\n\n Object.keys(sectionedData).forEach((sectionDescription) => {\n const data = sectionedData[sectionDescription] as Array<Dict<string>>\n\n sectionedParentChildSectionedRows.push({\n sectionDescription,\n ...this.getSectionCount(sectionedData, sectionDescription),\n rows: this.createParentChildTable(data, header),\n })\n })\n\n const rows = sectionedParentChildSectionedRows.flatMap((section, index) => {\n const sectionHeader = this.createSectionHeader(\n section.sectionDescription,\n index,\n section.count,\n section.countDescription,\n )\n return [...sectionHeader, ...section.rows]\n })\n\n return rows\n }\n\n private mapParentChildData(parentData: Array<Dict<string>>, header: Cell[]): Cell[][] {\n if (this.sections?.length) {\n return this.createParentChildSectionRows(parentData, header)\n }\n return this.createParentChildTable(parentData, header)\n }\n\n private createChildDataTableBuilders() {\n const childDataTables: Dict<DataTableBuilder> = this.childVariants.reduce((previousValue, childVariant) => {\n const { specification } = childVariant\n const fields = specification ? specification.fields : []\n const fieldNamesToDisplay = fields.filter((f) => f.visible || f.mandatory).map((f) => f.name)\n\n const dataTableBuilder = new DataTableBuilder(fields).withNoHeaderOptions(fieldNamesToDisplay).withSortedData()\n\n return {\n ...previousValue,\n [childVariant.id]: dataTableBuilder,\n }\n }, {})\n return childDataTables\n }\n\n private calculateParentChildKeys(\n parentData: Array<NodeJS.Dict<string>>,\n joinFields: components['schemas']['FieldDefinition'][],\n ) {\n return parentData\n .map(\n (rowData): ParentChildSortKey => ({\n sortKey: this.getSortKey(rowData, joinFields),\n childSortKeys: this.childVariants.reduce((previousValue, childVariant) => {\n return {\n ...previousValue,\n [childVariant.id]: this.getSortKey(rowData, this.mapNamesToFields(childVariant.joinFields)),\n }\n }, {}),\n }),\n )\n .reduce((previousValue: ParentChildSortKey[], sortKey: ParentChildSortKey) => {\n if (previousValue.find((v) => v.sortKey === sortKey.sortKey)) {\n return previousValue\n }\n return previousValue.concat(sortKey)\n }, [])\n }\n\n private splitParentDataIntoSections(\n sectionedParentChildData: NodeJS.Dict<NodeJS.Dict<Array<NodeJS.Dict<string>>>>,\n parentData: Array<NodeJS.Dict<string>>,\n joinFields: components['schemas']['FieldDefinition'][],\n ) {\n return parentData.reduce((previousValue, rowData) => {\n const parentKey: string = this.getSortKey(rowData, joinFields)\n const previousParentValue = previousValue[parentKey] ? previousValue[parentKey]['parent'] : []\n\n return {\n ...previousValue,\n ...(previousParentValue && {\n [parentKey]: {\n parent: previousParentValue.concat(rowData),\n },\n }),\n }\n }, sectionedParentChildData)\n }\n\n private splitChildDataIntoSections(\n parentKeys: ParentChildSortKey[],\n sectionedParentChildData: Dict<Dict<Array<Dict<string>>>>,\n ): Dict<Dict<Array<Dict<string>>>> {\n const sectionedParentChildDataWithChildren = { ...sectionedParentChildData }\n\n this.childVariants.forEach((childVariant) => {\n const childFields = this.mapNamesToFields(childVariant.joinFields)\n const matchingChildData = this.childData.find((d) => d.id === childVariant.id)\n const data = matchingChildData ? matchingChildData.data : []\n\n data\n .filter((rowData) => {\n const sortKey = this.getSortKey(rowData, childFields)\n return parentKeys.find((p) => p.childSortKeys[childVariant.id] === sortKey)\n })\n .forEach((rowData) => {\n const sortKey = this.getSortKey(rowData, childFields)\n const parent = parentKeys.find((p) => p.childSortKeys[childVariant.id] === sortKey)\n const parentSortKey = parent ? parent.sortKey : ''\n const parentSection = sectionedParentChildDataWithChildren[parentSortKey]\n if (parentSection) {\n const existingChildData = parentSection[childVariant.id] || []\n parentSection[childVariant.id] = existingChildData.concat(rowData)\n }\n })\n })\n\n return sectionedParentChildDataWithChildren\n }\n\n withChildData(childData: Array<ChildData>) {\n this.childData = childData\n return this\n }\n\n override buildTable(data: Array<Dict<string>>): DataTable {\n return {\n head: null,\n rows: this.mapParentChildData(data, this.mapHeader(true, 'govuk-table__header')),\n rowCount: data.length,\n colCount: this.columns.length,\n }\n }\n}\n\nexport { ParentChildDataTableBuilder }\nexport default ParentChildDataTableBuilder\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,8BAA6B;AAC7B,wBAAyB;AAEzB,uCAAsC;AAEtC,MAAM,oCAAoC,iCAAAA,QAA0B;AAAA,EAClE;AAAA,EAEA;AAAA,EAEA,YAA8B,CAAC;AAAA,EAE/B,YAAY,SAAqD;AAC/D,UAAM,EAAE,cAAc,IAAI;AAC1B,UAAM,EAAE,UAAU,SAAS,IAA4C;AACvE,UAA8C,aAAa;AAE3D,SAAK,WAAW;AAChB,SAAK,WAAW;AAChB,SAAK,UAAU;AACf,SAAK,gBAAgB,KAAK,QAAQ,iBAAiB,CAAC;AAAA,EACtD;AAAA,EAEQ,uBAAuB,YAAiC,QAAgB;AAC9E,QAAI,2BAA4D,CAAC;AACjE,UAAM,aAAa,KAAK,iBAAiB,KAAK,cAAc,QAAQ,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,4BAAU,CAAC,CAAC,CAAC;AAI7G,UAAM,kBAAkB,KAAK,yBAAyB,YAAY,UAAU;AAC5E,oBAAgB,QAAQ,CAAC,cAAc;AACrC,+BAAyB,UAAU,OAAO,IAAI;AAAA,QAC5C,QAAQ,CAAC;AAAA,MACX;AAAA,IACF,CAAC;AAED,+BAA2B,KAAK,4BAA4B,0BAA0B,YAAY,UAAU;AAC5G,+BAA2B,KAAK,2BAA2B,iBAAiB,wBAAwB;AAEpG,UAAM,yBAAyB,KAAK,6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AAqC,aAAa;AACxE,YAAI,eAAe;AACjB,gBAAM,oBAAoB,cAAc,aAAa,EAAE,KAAK,CAAC;AAC7D,wBAAc,aAAa,EAAE,IAAI,kBAAkB,OAAO,OAAO;AAAA,QACnE;AAAA,MACF,CAAC;AAAA,IACL,CAAC;AAED,WAAO;AAAA,EACT;AAAA,EAEA,cAAc,WAA6B;AACzC,SAAK,YAAY;AACjB,WAAO;AAAA,EACT;AAAA,EAES,WAAW,MAAsC;AACxD,WAAO;AAAA,MACL,MAAM;AAAA,MACN,MAAM,KAAK,mBAAmB,MAAM,KAAK,UAAU,MAAM,qBAAqB,CAAC;AAAA,MAC/E,UAAU,KAAK;AAAA,MACf,UAAU,KAAK,QAAQ;AAAA,IACzB;AAAA,EACF;AACF;AAGA,IAAO,sCAAQ;",
6
- "names": ["SectionedDataTableBuilder", "DataTableBuilder"]
7
- }
@@ -1,503 +0,0 @@
1
- import { expect } from '@jest/globals'
2
- import Dict = NodeJS.Dict
3
- import { components } from '../../types/api'
4
- import ParentChildDataTableBuilder from './ParentChildDataTableBuilder'
5
-
6
- const data: Array<Dict<string>> = [
7
- {
8
- sectionOne: 'A',
9
- sectionTwo: '01/02/03',
10
- oranges: '5',
11
- lemons: 'Yes',
12
- section: 'one',
13
- },
14
- {
15
- sectionOne: 'A',
16
- sectionTwo: '01/02/03',
17
- oranges: '6',
18
- lemons: 'No',
19
- section: 'one',
20
- },
21
- {
22
- sectionOne: 'A',
23
- sectionTwo: '02/01/03',
24
- oranges: '7',
25
- lemons: 'Yeah',
26
- section: 'two',
27
- },
28
- {
29
- sectionOne: 'B',
30
- sectionTwo: '02/01/03',
31
- oranges: '8',
32
- lemons: 'Nah',
33
- section: 'two',
34
- },
35
- ]
36
-
37
- const childData: Array<Dict<string>> = [
38
- {
39
- sectionOne: 'A',
40
- sectionTwo: '01/02/03',
41
- cheese: 'No',
42
- },
43
- {
44
- sectionOne: 'A',
45
- sectionTwo: '01/02/03',
46
- cheese: 'Wendsleydale',
47
- },
48
- {
49
- sectionOne: 'A',
50
- sectionTwo: '02/01/03',
51
- cheese: 'Cheddar',
52
- },
53
- {
54
- sectionOne: 'B',
55
- sectionTwo: '02/01/03',
56
- cheese: 'Gouda',
57
- },
58
- ]
59
-
60
- const parentFields: Array<components['schemas']['FieldDefinition']> = [
61
- {
62
- header: false,
63
- name: 'sectionOne',
64
- display: 'Section One',
65
- sortable: true,
66
- defaultsort: false,
67
- type: 'string',
68
- mandatory: false,
69
- visible: true,
70
- calculated: false,
71
- },
72
- {
73
- header: false,
74
- name: 'sectionTwo',
75
- display: 'Section Two',
76
- sortable: true,
77
- defaultsort: false,
78
- type: 'string',
79
- mandatory: false,
80
- visible: true,
81
- calculated: false,
82
- },
83
- {
84
- header: false,
85
- name: 'oranges',
86
- display: 'Oranges!',
87
- sortable: true,
88
- defaultsort: true,
89
- type: 'long',
90
- mandatory: false,
91
- visible: true,
92
- calculated: false,
93
- },
94
- {
95
- header: false,
96
- name: 'lemons',
97
- display: 'Lemons?!',
98
- sortable: true,
99
- defaultsort: false,
100
- type: 'string',
101
- mandatory: false,
102
- visible: true,
103
- calculated: false,
104
- },
105
- {
106
- header: false,
107
- name: 'section',
108
- display: 'Section',
109
- sortable: true,
110
- defaultsort: false,
111
- type: 'string',
112
- mandatory: false,
113
- visible: false,
114
- calculated: false,
115
- },
116
- ]
117
-
118
- const childFields: Array<components['schemas']['FieldDefinition']> = [
119
- {
120
- header: false,
121
- name: 'sectionOne',
122
- display: 'Section One',
123
- sortable: true,
124
- defaultsort: false,
125
- type: 'string',
126
- mandatory: false,
127
- visible: false,
128
- calculated: false,
129
- },
130
- {
131
- header: false,
132
- name: 'sectionTwo',
133
- display: 'Section Two',
134
- sortable: true,
135
- defaultsort: false,
136
- type: 'string',
137
- mandatory: false,
138
- visible: false,
139
- calculated: false,
140
- },
141
- {
142
- header: false,
143
- name: 'cheese',
144
- display: 'Cheese',
145
- sortable: true,
146
- defaultsort: true,
147
- type: 'long',
148
- mandatory: false,
149
- visible: true,
150
- calculated: false,
151
- },
152
- ]
153
-
154
- const parentSpecification: components['schemas']['Specification'] = {
155
- fields: parentFields,
156
- template: 'parent-child',
157
- sections: [],
158
- }
159
-
160
- const childSpecification: components['schemas']['Specification'] = {
161
- fields: childFields,
162
- template: 'list',
163
- sections: [],
164
- }
165
-
166
- const parentVariant: components['schemas']['VariantDefinition'] = {
167
- id: 'parentId',
168
- name: 'Parent',
169
- resourceName: '/parent',
170
- specification: parentSpecification,
171
- childVariants: [
172
- {
173
- id: 'childId',
174
- name: 'Child',
175
- resourceName: '/child',
176
- joinFields: ['sectionOne', 'sectionTwo'],
177
- specification: childSpecification,
178
- },
179
- ],
180
- }
181
-
182
- const headerResultRow = [
183
- {
184
- classes: 'govuk-table__header',
185
- text: 'Section One',
186
- },
187
- {
188
- classes: 'govuk-table__header',
189
- text: 'Section Two',
190
- },
191
- {
192
- classes: 'govuk-table__header',
193
- text: 'Oranges!',
194
- },
195
- {
196
- classes: 'govuk-table__header',
197
- text: 'Lemons?!',
198
- },
199
- ]
200
-
201
- const resultRows = [
202
- [
203
- {
204
- classes: 'dpr-parent-cell',
205
- fieldName: 'sectionOne',
206
- format: 'string',
207
- text: 'A',
208
- },
209
- {
210
- classes: 'dpr-parent-cell',
211
- fieldName: 'sectionTwo',
212
- format: 'string',
213
- text: '01/02/03',
214
- },
215
- {
216
- classes: 'dpr-parent-cell',
217
- fieldName: 'oranges',
218
- format: 'numeric',
219
- text: '5',
220
- },
221
- {
222
- classes: 'dpr-parent-cell',
223
- fieldName: 'lemons',
224
- format: 'string',
225
- text: 'Yes',
226
- },
227
- ],
228
- [
229
- {
230
- classes: 'dpr-parent-cell',
231
- fieldName: 'sectionOne',
232
- format: 'string',
233
- text: 'A',
234
- },
235
- {
236
- classes: 'dpr-parent-cell',
237
- fieldName: 'sectionTwo',
238
- format: 'string',
239
- text: '01/02/03',
240
- },
241
- {
242
- classes: 'dpr-parent-cell',
243
- fieldName: 'oranges',
244
- format: 'numeric',
245
- text: '6',
246
- },
247
- {
248
- classes: 'dpr-parent-cell',
249
- fieldName: 'lemons',
250
- format: 'string',
251
- text: 'No',
252
- },
253
- ],
254
- [
255
- {
256
- classes: 'dpr-parent-cell',
257
- fieldName: 'sectionOne',
258
- format: 'string',
259
- text: 'A',
260
- },
261
- {
262
- classes: 'dpr-parent-cell',
263
- fieldName: 'sectionTwo',
264
- format: 'string',
265
- text: '02/01/03',
266
- },
267
- {
268
- classes: 'dpr-parent-cell',
269
- fieldName: 'oranges',
270
- format: 'numeric',
271
- text: '7',
272
- },
273
- {
274
- classes: 'dpr-parent-cell',
275
- fieldName: 'lemons',
276
- format: 'string',
277
- text: 'Yeah',
278
- },
279
- ],
280
- [
281
- {
282
- classes: 'dpr-parent-cell',
283
- fieldName: 'sectionOne',
284
- format: 'string',
285
- text: 'B',
286
- },
287
- {
288
- classes: 'dpr-parent-cell',
289
- fieldName: 'sectionTwo',
290
- format: 'string',
291
- text: '02/01/03',
292
- },
293
- {
294
- classes: 'dpr-parent-cell',
295
- fieldName: 'oranges',
296
- format: 'numeric',
297
- text: '8',
298
- },
299
- {
300
- classes: 'dpr-parent-cell',
301
- fieldName: 'lemons',
302
- format: 'string',
303
- text: 'Nah',
304
- },
305
- ],
306
- ]
307
-
308
- const childResultTables = [
309
- [
310
- {
311
- classes: 'dpr-child-report-cell',
312
- colspan: 4,
313
- format: 'string',
314
- html: "<div class='dpr-child-report'><h2 class=\"govuk-heading-s\">Child</h2><div class=\"dpr-child-report_table\"><table class='govuk-table'><thead class='govuk-table__head'><th scope='col' class='govuk-table__header'>Cheese</th></thead><tbody class='govuk-table__body'><tr class='govuk-table__row'><td class='govuk-table__cell govuk-table__cell--numeric '>Cheddar</td></tr></tbody></table></div></div>",
315
- },
316
- ],
317
- [
318
- {
319
- classes: 'dpr-child-report-cell',
320
- colspan: 4,
321
- format: 'string',
322
- html: "<div class='dpr-child-report'><h2 class=\"govuk-heading-s\">Child</h2><div class=\"dpr-child-report_table\"><table class='govuk-table'><thead class='govuk-table__head'><th scope='col' class='govuk-table__header'>Cheese</th></thead><tbody class='govuk-table__body'><tr class='govuk-table__row'><td class='govuk-table__cell govuk-table__cell--numeric '>No</td></tr><tr class='govuk-table__row'><td class='govuk-table__cell govuk-table__cell--numeric '>Wendsleydale</td></tr></tbody></table></div></div>",
323
- },
324
- ],
325
- [
326
- {
327
- classes: 'dpr-child-report-cell',
328
- colspan: 4,
329
- format: 'string',
330
- html: "<div class='dpr-child-report'><h2 class=\"govuk-heading-s\">Child</h2><div class=\"dpr-child-report_table\"><table class='govuk-table'><thead class='govuk-table__head'><th scope='col' class='govuk-table__header'>Cheese</th></thead><tbody class='govuk-table__body'><tr class='govuk-table__row'><td class='govuk-table__cell govuk-table__cell--numeric '>Gouda</td></tr></tbody></table></div></div>",
331
- },
332
- ],
333
- ]
334
-
335
- describe('ParentChildDataTableBuilder', () => {
336
- it('Parent child sections added correctly', () => {
337
- const mapped = new ParentChildDataTableBuilder(parentVariant)
338
- .withNoHeaderOptions(['sectionOne', 'sectionTwo', 'oranges', 'lemons'])
339
- .withChildData([
340
- {
341
- id: 'childId',
342
- data: childData,
343
- },
344
- ])
345
- .buildTable(data)
346
-
347
- expect(mapped.rows).toEqual([
348
- headerResultRow,
349
- resultRows[0],
350
- resultRows[1],
351
- childResultTables[1],
352
- headerResultRow,
353
- resultRows[2],
354
- childResultTables[0],
355
- headerResultRow,
356
- resultRows[3],
357
- childResultTables[2],
358
- ])
359
- expect(mapped.head).toBeNull()
360
- expect(mapped.colCount).toEqual(4)
361
- expect(mapped.rowCount).toEqual(4)
362
- })
363
-
364
- it('Missing child data doesnt fail', () => {
365
- const mapped = new ParentChildDataTableBuilder(parentVariant)
366
- .withNoHeaderOptions(['sectionOne', 'sectionTwo', 'oranges', 'lemons'])
367
- .withChildData([])
368
- .buildTable(data)
369
-
370
- expect(mapped.rows).toEqual([
371
- headerResultRow,
372
- resultRows[0],
373
- resultRows[1],
374
- headerResultRow,
375
- resultRows[2],
376
- headerResultRow,
377
- resultRows[3],
378
- ])
379
- expect(mapped.head).toBeNull()
380
- expect(mapped.colCount).toEqual(4)
381
- expect(mapped.rowCount).toEqual(4)
382
- })
383
-
384
- it('sections added correctly', () => {
385
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
386
- parentVariant.specification!.sections = ['section']
387
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
388
- parentVariant.specification!.template = 'parent-child-section'
389
- const mapped = new ParentChildDataTableBuilder(parentVariant)
390
- .withNoHeaderOptions(['sectionOne', 'sectionTwo', 'oranges', 'lemons'])
391
- .withChildData([
392
- {
393
- id: 'childId',
394
- data: childData,
395
- },
396
- ])
397
- .buildTable(data)
398
-
399
- expect(mapped.rows).toEqual([
400
- [
401
- {
402
- classes: 'dpr-section-header',
403
- colspan: 4,
404
- html: '<h2 class="govuk-heading-m">Section: one <span class=\'govuk-caption-m\'>2 results</span></h2>',
405
- },
406
- ],
407
- [
408
- {
409
- classes: 'dpr-section-header-spacer-bottom',
410
- colspan: 4,
411
- text: '',
412
- },
413
- ],
414
- [
415
- { text: 'Section One', classes: 'govuk-table__header' },
416
- { text: 'Section Two', classes: 'govuk-table__header' },
417
- { text: 'Oranges!', classes: 'govuk-table__header' },
418
- { text: 'Lemons?!', classes: 'govuk-table__header' },
419
- ],
420
- [
421
- { fieldName: 'sectionOne', text: 'A', format: 'string', classes: 'dpr-parent-cell' },
422
- { fieldName: 'sectionTwo', text: '01/02/03', format: 'string', classes: 'dpr-parent-cell' },
423
- { fieldName: 'oranges', text: '5', format: 'numeric', classes: 'dpr-parent-cell' },
424
- { fieldName: 'lemons', text: 'Yes', format: 'string', classes: 'dpr-parent-cell' },
425
- ],
426
- [
427
- { fieldName: 'sectionOne', text: 'A', format: 'string', classes: 'dpr-parent-cell' },
428
- { fieldName: 'sectionTwo', text: '01/02/03', format: 'string', classes: 'dpr-parent-cell' },
429
- { fieldName: 'oranges', text: '6', format: 'numeric', classes: 'dpr-parent-cell' },
430
- { fieldName: 'lemons', text: 'No', format: 'string', classes: 'dpr-parent-cell' },
431
- ],
432
- [
433
- {
434
- classes: 'dpr-child-report-cell',
435
- format: 'string',
436
- html: "<div class='dpr-child-report'><h2 class=\"govuk-heading-s\">Child</h2><div class=\"dpr-child-report_table\"><table class='govuk-table'><thead class='govuk-table__head'><th scope='col' class='govuk-table__header'>Cheese</th></thead><tbody class='govuk-table__body'><tr class='govuk-table__row'><td class='govuk-table__cell govuk-table__cell--numeric '>No</td></tr><tr class='govuk-table__row'><td class='govuk-table__cell govuk-table__cell--numeric '>Wendsleydale</td></tr></tbody></table></div></div>",
437
- colspan: 4,
438
- },
439
- ],
440
- [
441
- {
442
- classes: 'dpr-section-header-spacer',
443
- colspan: 4,
444
- text: '',
445
- },
446
- ],
447
- [
448
- {
449
- classes: 'dpr-section-header',
450
- colspan: 4,
451
- html: '<h2 class="govuk-heading-m">Section: two <span class=\'govuk-caption-m\'>2 results</span></h2>',
452
- },
453
- ],
454
- [
455
- {
456
- classes: 'dpr-section-header-spacer-bottom',
457
- colspan: 4,
458
- text: '',
459
- },
460
- ],
461
- [
462
- { text: 'Section One', classes: 'govuk-table__header' },
463
- { text: 'Section Two', classes: 'govuk-table__header' },
464
- { text: 'Oranges!', classes: 'govuk-table__header' },
465
- { text: 'Lemons?!', classes: 'govuk-table__header' },
466
- ],
467
- [
468
- { fieldName: 'sectionOne', text: 'A', format: 'string', classes: 'dpr-parent-cell' },
469
- { fieldName: 'sectionTwo', text: '02/01/03', format: 'string', classes: 'dpr-parent-cell' },
470
- { fieldName: 'oranges', text: '7', format: 'numeric', classes: 'dpr-parent-cell' },
471
- { fieldName: 'lemons', text: 'Yeah', format: 'string', classes: 'dpr-parent-cell' },
472
- ],
473
- [
474
- {
475
- classes: 'dpr-child-report-cell',
476
- format: 'string',
477
- html: "<div class='dpr-child-report'><h2 class=\"govuk-heading-s\">Child</h2><div class=\"dpr-child-report_table\"><table class='govuk-table'><thead class='govuk-table__head'><th scope='col' class='govuk-table__header'>Cheese</th></thead><tbody class='govuk-table__body'><tr class='govuk-table__row'><td class='govuk-table__cell govuk-table__cell--numeric '>Cheddar</td></tr></tbody></table></div></div>",
478
- colspan: 4,
479
- },
480
- ],
481
- [
482
- { text: 'Section One', classes: 'govuk-table__header' },
483
- { text: 'Section Two', classes: 'govuk-table__header' },
484
- { text: 'Oranges!', classes: 'govuk-table__header' },
485
- { text: 'Lemons?!', classes: 'govuk-table__header' },
486
- ],
487
- [
488
- { fieldName: 'sectionOne', text: 'B', format: 'string', classes: 'dpr-parent-cell' },
489
- { fieldName: 'sectionTwo', text: '02/01/03', format: 'string', classes: 'dpr-parent-cell' },
490
- { fieldName: 'oranges', text: '8', format: 'numeric', classes: 'dpr-parent-cell' },
491
- { fieldName: 'lemons', text: 'Nah', format: 'string', classes: 'dpr-parent-cell' },
492
- ],
493
- [
494
- {
495
- classes: 'dpr-child-report-cell',
496
- format: 'string',
497
- html: "<div class='dpr-child-report'><h2 class=\"govuk-heading-s\">Child</h2><div class=\"dpr-child-report_table\"><table class='govuk-table'><thead class='govuk-table__head'><th scope='col' class='govuk-table__header'>Cheese</th></thead><tbody class='govuk-table__body'><tr class='govuk-table__row'><td class='govuk-table__cell govuk-table__cell--numeric '>Gouda</td></tr></tbody></table></div></div>",
498
- colspan: 4,
499
- },
500
- ],
501
- ])
502
- })
503
- })