@ministryofjustice/hmpps-digital-prison-reporting-frontend 4.15.0 → 4.15.2

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 (38) hide show
  1. package/dpr/components/_charts/chart/heatmap/Heatmap.js +2 -0
  2. package/dpr/components/_charts/chart/heatmap/Heatmap.js.map +7 -0
  3. package/dpr/components/_charts/chart/heatmap/Heatmap.ts +278 -0
  4. package/dpr/components/_charts/utils.js +1 -1
  5. package/dpr/components/_charts/utils.js.map +3 -3
  6. package/dpr/components/_charts/utils.ts +2 -2
  7. package/dpr/components/_dashboards/dashboard/types.js +1 -1
  8. package/dpr/components/_dashboards/dashboard/types.js.map +2 -2
  9. package/dpr/components/_dashboards/dashboard/types.ts +8 -0
  10. package/dpr/components/_dashboards/dashboard-list/utils.js +1 -1
  11. package/dpr/components/_dashboards/dashboard-list/utils.js.map +3 -3
  12. package/dpr/components/_dashboards/dashboard-list/utils.ts +3 -2
  13. package/dpr/components/user-reports/utils.js +1 -1
  14. package/dpr/components/user-reports/utils.js.map +3 -3
  15. package/dpr/components/user-reports/utils.ts +13 -3
  16. package/dpr/routes/journeys/view-report/async/report/tests.cy.js +1 -1
  17. package/dpr/routes/journeys/view-report/async/report/tests.cy.js.map +2 -2
  18. package/dpr/routes/journeys/view-report/async/report/tests.cy.ts +44 -8
  19. package/dpr/routes/journeys/view-report/utils.js +1 -1
  20. package/dpr/routes/journeys/view-report/utils.js.map +3 -3
  21. package/dpr/routes/journeys/view-report/utils.ts +6 -1
  22. package/dpr/utils/DataTableBuilder/DataTableBuilder.js +1 -1
  23. package/dpr/utils/DataTableBuilder/DataTableBuilder.js.map +2 -2
  24. package/dpr/utils/DataTableBuilder/DataTableBuilder.ts +37 -19
  25. package/dpr/utils/ParentChildDataTableBuilder/ParentChildDataTableBuilder.js +1 -1
  26. package/dpr/utils/ParentChildDataTableBuilder/ParentChildDataTableBuilder.js.map +2 -2
  27. package/dpr/utils/ParentChildDataTableBuilder/ParentChildDataTableBuilder.ts +6 -3
  28. package/dpr/utils/SectionedDataTableBuilder/SectionedDataTableBuilder.js.map +2 -2
  29. package/dpr/utils/SectionedDataTableBuilder/SectionedDataTableBuilder.ts +5 -2
  30. package/dpr/utils/SummaryDataTableBuilder/SummaryDataTableBuilder.js +1 -1
  31. package/dpr/utils/SummaryDataTableBuilder/SummaryDataTableBuilder.js.map +2 -2
  32. package/dpr/utils/SummaryDataTableBuilder/SummaryDataTableBuilder.ts +2 -1
  33. package/dpr/utils/UserStoreItemBuilder.js.map +1 -1
  34. package/dpr/utils/UserStoreItemBuilder.ts +1 -1
  35. package/package.json +1 -1
  36. package/dpr/components/_charts/chart/heatmap/utils.js +0 -2
  37. package/dpr/components/_charts/chart/heatmap/utils.js.map +0 -7
  38. package/dpr/components/_charts/chart/heatmap/utils.ts +0 -182
@@ -1,2 +1,2 @@
1
- var g=Object.create;var m=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,C=Object.prototype.hasOwnProperty;var w=(o,t)=>{for(var e in t)m(o,e,{get:t[e],enumerable:!0})},d=(o,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of b(t))!C.call(o,a)&&a!==e&&m(o,a,{get:()=>t[a],enumerable:!(r=D(t,a))||r.enumerable});return o};var h=(o,t,e)=>(e=o!=null?g(S(o)):{},d(t||!o||!o.__esModule?m(e,"default",{value:o,enumerable:!0}):e,o)),v=o=>d(m({},"__esModule",{value:!0}),o);var A={};w(A,{DataTableBuilder:()=>c,default:()=>F});module.exports=v(A);var p=h(require("../urlHelper")),y=h(require("../DateMapper/DateMapper"));class c{constructor(t,e=!1){this.columns=[];this.reportSummaries={};this.reportQuery=null;this.currentQueryParams=null;this.dateMapper=new y.default;this.fields=t,this.sortData=e}mapDate(t){return t?this.dateMapper.toDateString(t,"local-datetime-short-year"):""}mapBoolean(t){return t?t.substring(0,1).toUpperCase()+t.substring(1).toLowerCase():""}mapRow(t,e="",r=[]){return this.fields.filter(a=>this.columns.includes(a.name)).map(a=>{const s=r.find(n=>n.name===a.name)??a;return this.mapCell(s,t,e)})}mapCell(t,e,r=""){const a=this.mapCellValue(t,e[t.name]);let i="string",s=r;t.wordWrap&&(s+=` data-table-cell-wrap-${t.wordWrap.toLowerCase()}`),t.header&&(s+=" govuk-table__header"),(t.type==="double"||t.type==="long")&&(i="numeric");const n=t.type==="HTML";return{fieldName:t.name,...n?{html:a}:{text:a},format:i,classes:s.trim()}}mapCellValue(t,e){if(t.calculated)return e;switch(t.type){case"boolean":return this.mapBoolean(e);case"date":case"time":return this.mapDate(e);default:return e}}mapHeader(t=!1,e=null){return this.fields.filter(r=>this.columns.includes(r.name)).map(r=>{if(this.reportQuery&&!t&&r.sortable){let a="none",i=(0,p.default)(this.currentQueryParams||{},{sortColumn:r.name,sortedAsc:"true"});return r.name===this.reportQuery.sortColumn&&(a=this.reportQuery.sortedAsc?"ascending":"descending",this.reportQuery.sortedAsc&&(i=(0,p.default)(this.currentQueryParams||{},{sortColumn:r.name,sortedAsc:"false"}))),{html:`<a data-column="${r.name}" class="data-table-header-button data-table-header-button-sort-${a}" href="${i}">${r.display}</a>`,...e&&{classes:e}}}return{text:r.display,...e&&{classes:e}}})}mapData(t){const e=this.mapSummary("table-header"),r=this.mergeCells(t.map(i=>this.mapRow(i))),a=this.mapSummary("table-footer");return e.concat(r).concat(a)}mergeCells(t){const e=this.fields.filter(a=>a.mergeRows).map(a=>a.name);if(e.length===0)return t;const r={};return e.forEach(a=>{r[a]=t.reduce((i,s)=>{const n=this.getCellByFieldName(s,a);let l="";return n&&(l=n.text||n.html||""),{...i,[l]:(i[l]??0)+1}},{})}),t.map(a=>{let i=[...a];return e.forEach(s=>{const n=this.getCellByFieldName(a,s);let l,u;if(n&&r[s])switch(l=n.text||n.html||"",u=r[s][l],u){case-1:i=i.filter(f=>f.fieldName!==s);break;case 1:break;default:n.rowspan=u,r[s][l]=-1}}),i})}getCellByFieldName(t,e){return t.find(r=>r.fieldName===e)}mapSummary(t){return this.reportSummaries[t]?this.reportSummaries[t].flatMap(e=>e.data.map(r=>this.mapRow(r,`dpr-report-summary-cell dpr-report-summary-cell-${t}`,e.fields))):[]}sort(t){return this.appendSortKeyToData(t).sort(this.sortKeyComparison()).map(e=>({...e}))}sortKeyComparison(){return(t,e)=>{const r=t.sortKey,a=e.sortKey;return r===a?0:r<a?-1:1}}appendSortKeyToData(t,e=null){const r=e||this.fields;return t.map(a=>{const i=this.getSortKey(a,r);return{...a,sortKey:i}})}mapNamesToFields(t){return t.map(e=>this.fields.find(r=>r.name===e)).filter(e=>e!==void 0)}getSortKey(t,e){return e.map(r=>{const a=t[r.name];return a&&this.dateMapper.isDate(a)?this.dateMapper.toDateString(a,"iso"):this.mapCellValue(r,a)}).join("-").toLowerCase()}convertDataTableToHtml(t){const r=(t.head||[]).map(i=>`<th scope='col' class='govuk-table__header'>${i.html??i.text}</th>`),a=t.rows.map(i=>`<tr class='govuk-table__row'>${i.map(s=>`<td class='govuk-table__cell govuk-table__cell--${s.format} ${s.classes}'>${s.html??s.text}</td>`).join("")}</tr>`);return`<table class='govuk-table'><thead class='govuk-table__head'>${r.join("")}</thead><tbody class='govuk-table__body'>${a.join("")}</tbody></table>`}withHeaderOptions({reportQuery:t,columns:e,interactive:r}){return r&&t?this.withHeaderSortOptions(t):this.withNoHeaderOptions(e)}withHeaderSortOptions(t){return this.reportQuery=t,this.columns=t.columns,this.currentQueryParams=this.reportQuery.toRecordWithFilterPrefix(),this}withNoHeaderOptions(t){return this.columns=t,this}buildTable(t){const e=this.mapData(this.sortData?this.sort(t):t);return{head:this.mapHeader(),rows:e,rowCount:t.length,colCount:this.columns.length}}withSummaries(t){return this.reportSummaries=t,this}withSortedData(t=!0){return this.sortData=t,this}}var F=c;0&&(module.exports={DataTableBuilder});
1
+ var g=Object.create;var m=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,C=Object.prototype.hasOwnProperty;var w=(i,e)=>{for(var t in e)m(i,t,{get:e[t],enumerable:!0})},d=(i,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of b(e))!C.call(i,a)&&a!==t&&m(i,a,{get:()=>e[a],enumerable:!(r=D(e,a))||r.enumerable});return i};var h=(i,e,t)=>(t=i!=null?g(S(i)):{},d(e||!i||!i.__esModule?m(t,"default",{value:i,enumerable:!0}):t,i)),v=i=>d(m({},"__esModule",{value:!0}),i);var K={};w(K,{DataTableBuilder:()=>u,default:()=>F});module.exports=v(K);var p=h(require("../urlHelper")),y=h(require("../DateMapper/DateMapper"));class u{constructor(e,t=!1){this.columns=[];this.reportSummaries={};this.reportQuery=null;this.currentQueryParams=null;this.dateMapper=new y.default;this.fields=e,this.sortData=t}mapDate(e){return e?this.dateMapper.toDateString(e,"local-datetime-short-year"):""}mapBoolean(e){return e?e.substring(0,1).toUpperCase()+e.substring(1).toLowerCase():""}mapRow(e,t="",r=[]){return this.fields.filter(a=>this.columns.includes(a.name)).map(a=>{const o=r.find(n=>n.name===a.name)??a;return this.mapCell(o,e,t)})}mapCell(e,t,r=""){const a=this.mapCellValue(e,t[e.name]);let s="string",o=r;e.wordWrap&&(o+=` data-table-cell-wrap-${e.wordWrap.toLowerCase()}`),e.header&&(o+=" govuk-table__header"),(e.type==="double"||e.type==="long")&&(s="numeric");const n=e.type==="HTML";return{fieldName:e.name,...n?{html:a}:{text:a},format:s,classes:o.trim()}}mapCellValue(e,t){if(e.calculated)return t;switch(e.type){case"boolean":return this.mapBoolean(t);case"date":case"time":return this.mapDate(t);default:return t}}mapHeader(e=!1,t=null){return this.fields.filter(r=>this.columns.includes(r.name)).map(r=>{if(this.reportQuery&&!e&&r.sortable){let a="none",s=(0,p.default)(this.currentQueryParams||{},{sortColumn:r.name,sortedAsc:"true"},this.fields);return r.name===this.reportQuery.sortColumn&&(a=this.reportQuery.sortedAsc?"ascending":"descending",this.reportQuery.sortedAsc&&(s=(0,p.default)(this.currentQueryParams||{},{sortColumn:r.name,sortedAsc:"false"},this.fields))),{html:`<a data-column="${r.name}" class="data-table-header-button data-table-header-button-sort-${a}" href="${s}">${r.display}</a>`,...t&&{classes:t}}}return{text:r.display,...t&&{classes:t}}})}mapData(e){const t=this.mapSummary("table-header"),r=this.mergeCells(e.map(s=>this.mapRow(s))),a=this.mapSummary("table-footer");return t.concat(r).concat(a)}mergeCells(e){const t=this.fields.filter(a=>a.mergeRows).map(a=>a.name);if(t.length===0)return e;const r={};return t.forEach(a=>{r[a]=e.reduce((s,o)=>{const n=this.getCellByFieldName(o,a);let l="";return n&&(l=n.text||n.html||""),{...s,[l]:(s[l]??0)+1}},{})}),e.map(a=>{let s=[...a];return t.forEach(o=>{const n=this.getCellByFieldName(a,o);let l,c;if(n&&r[o])switch(l=n.text||n.html||"",c=r[o][l],c){case-1:s=s.filter(f=>f.fieldName!==o);break;case 1:break;default:n.rowspan=c,r[o][l]=-1}}),s})}getCellByFieldName(e,t){return e.find(r=>r.fieldName===t)}mapSummary(e){return this.reportSummaries[e]?this.reportSummaries[e].flatMap(t=>t.data.map(r=>this.mapRow(r,`dpr-report-summary-cell dpr-report-summary-cell-${e}`,t.fields))):[]}sort(e){return this.appendSortKeyToData(e).sort(this.sortKeyComparison()).map(t=>({...t}))}sortKeyComparison(){return(e,t)=>{const r=e.sortKey,a=t.sortKey;return r===a?0:r<a?-1:1}}appendSortKeyToData(e,t=null){const r=t||this.fields;return e.map(a=>{const s=this.getSortKey(a,r);return{...a,sortKey:s}})}mapNamesToFields(e){return e.map(t=>this.fields.find(r=>r.name===t)).filter(t=>t!==void 0)}getSortKey(e,t){return t.map(r=>{const a=e[r.name];return a&&this.dateMapper.isDate(a)?this.dateMapper.toDateString(a,"iso"):this.mapCellValue(r,a)}).join("-").toLowerCase()}convertDataTableToHtml(e){const r=(e.head||[]).map(s=>`<th scope='col' class='govuk-table__header'>${s.html??s.text}</th>`),a=e.rows.map(s=>`<tr class='govuk-table__row'>${s.map(o=>`<td class='govuk-table__cell govuk-table__cell--${o.format} ${o.classes}'>${o.html??o.text}</td>`).join("")}</tr>`);return`<table class='govuk-table'><thead class='govuk-table__head'>${r.join("")}</thead><tbody class='govuk-table__body'>${a.join("")}</tbody></table>`}withHeaderOptions({reportQuery:e,columns:t,interactive:r}){return r&&e?this.withHeaderSortOptions(e):this.withNoHeaderOptions(t)}withHeaderSortOptions(e){return this.reportQuery=e,this.columns=e.columns,this.currentQueryParams=this.reportQuery.toRecordWithFilterPrefix(),this}withNoHeaderOptions(e){return this.columns=e,this}buildTable(e){const t=this.mapData(this.sortData?this.sort(e):e);return{head:this.mapHeader(),rows:t,rowCount:e.length,colCount:this.columns.length}}withSummaries(e){return this.reportSummaries=e,this}withSortedData(e=!0){return this.sortData=e,this}}var F=u;0&&(module.exports={DataTableBuilder});
2
2
  //# sourceMappingURL=DataTableBuilder.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/dpr/utils/DataTableBuilder/DataTableBuilder.ts"],
4
- "sourcesContent": ["import Dict = NodeJS.Dict\nimport ReportQuery from '../../types/ReportQuery'\nimport { Cell, CellFormat, DataTable, FieldDefinition, SortKey } from './types'\nimport createUrlForParameters from '../urlHelper'\nimport type { SummaryTemplate } from '../../types/Templates'\nimport { AsyncSummary } from '../../types/UserReports'\nimport DateMapper from '../DateMapper/DateMapper'\n\nclass DataTableBuilder {\n protected fields: Array<FieldDefinition>\n\n private sortData: boolean\n\n protected columns: Array<string> = []\n\n protected reportSummaries: Dict<Array<AsyncSummary>> = {}\n\n // Sortable headers only\n private reportQuery: ReportQuery | null = null\n\n private currentQueryParams: NodeJS.Dict<string | Array<string>> | null = null\n\n private dateMapper = new DateMapper()\n\n constructor(fields: Array<FieldDefinition>, sortData = false) {\n this.fields = fields\n this.sortData = sortData\n }\n\n private mapDate(isoDate?: string) {\n if (!isoDate) return ''\n\n return this.dateMapper.toDateString(isoDate, 'local-datetime-short-year')\n }\n\n private mapBoolean(value?: string) {\n if (!value) return ''\n return value.substring(0, 1).toUpperCase() + value.substring(1).toLowerCase()\n }\n\n protected mapRow(\n rowData: NodeJS.Dict<string>,\n extraClasses = '',\n overrideFields: Array<FieldDefinition> = [],\n ): Cell[] {\n return this.fields\n .filter((f) => this.columns.includes(f.name))\n .map((f) => {\n const overrideField = overrideFields.find((o) => o.name === f.name)\n const field = overrideField ?? f\n return this.mapCell(field, rowData, extraClasses)\n })\n }\n\n private mapCell(field: FieldDefinition, rowData: NodeJS.Dict<string>, extraClasses = '') {\n const textValue = this.mapCellValue(field, rowData[field.name])\n let fieldFormat: CellFormat = 'string'\n\n let classes = extraClasses\n\n if (field.wordWrap) {\n classes += ` data-table-cell-wrap-${field.wordWrap.toLowerCase()}`\n }\n\n if (field.header) {\n classes += ' govuk-table__header'\n }\n\n if (field.type === 'double' || field.type === 'long') {\n fieldFormat = 'numeric'\n }\n\n const isHtml = field.type === 'HTML'\n const cell: Cell = {\n fieldName: field.name,\n ...(isHtml ? { html: textValue } : { text: textValue }),\n format: fieldFormat,\n classes: classes.trim(),\n }\n\n return cell\n }\n\n protected mapCellValue(field: FieldDefinition, cellData?: string) {\n if (field.calculated) {\n return cellData\n }\n\n switch (field.type) {\n case 'boolean':\n return this.mapBoolean(cellData)\n\n case 'date':\n case 'time':\n return this.mapDate(cellData)\n\n default:\n return cellData\n }\n }\n\n protected mapHeader(disableSort = false, extraClasses: string | null = null): Cell[] {\n return this.fields\n .filter((field) => this.columns.includes(field.name))\n .map((f) => {\n if (this.reportQuery && !disableSort) {\n if (f.sortable) {\n let sortDirection = 'none'\n let url = createUrlForParameters(this.currentQueryParams || {}, {\n sortColumn: f.name,\n sortedAsc: 'true',\n })\n\n if (f.name === this.reportQuery.sortColumn) {\n sortDirection = this.reportQuery.sortedAsc ? 'ascending' : 'descending'\n\n if (this.reportQuery.sortedAsc) {\n url = createUrlForParameters(this.currentQueryParams || {}, {\n sortColumn: f.name,\n sortedAsc: 'false',\n })\n }\n }\n\n return {\n html:\n `<a ` +\n `data-column=\"${f.name}\" ` +\n `class=\"data-table-header-button data-table-header-button-sort-${sortDirection}\" ` +\n `href=\"${url}\"` +\n `>${f.display}</a>`,\n ...(extraClasses && { classes: extraClasses }),\n }\n }\n }\n return {\n text: f.display,\n ...(extraClasses && { classes: extraClasses }),\n }\n })\n }\n\n protected mapData(data: Array<Dict<string>>): Cell[][] {\n const mappedHeaderSummary = this.mapSummary('table-header')\n const mappedTableData = this.mergeCells(data.map((rowData) => this.mapRow(rowData)))\n const mappedFooterSummary = this.mapSummary('table-footer')\n\n return mappedHeaderSummary.concat(mappedTableData).concat(mappedFooterSummary)\n }\n\n private mergeCells(rows: Cell[][]): Cell[][] {\n const mergeFieldNames = this.fields.filter((f) => f.mergeRows).map((f) => f.name)\n\n if (mergeFieldNames.length === 0) {\n return rows\n }\n\n const occurrences: Dict<Dict<number>> = {}\n mergeFieldNames.forEach((f) => {\n occurrences[f] = rows.reduce((accumulator: Dict<number>, currentRow) => {\n const currentCell = this.getCellByFieldName(currentRow, f)\n let cellValue = ''\n if (currentCell) {\n cellValue = currentCell.text || currentCell.html || ''\n }\n\n return {\n ...accumulator,\n [cellValue]: (accumulator[cellValue] ?? 0) + 1,\n }\n }, {})\n })\n\n return rows.map((row) => {\n let mergedRow = [...row]\n\n mergeFieldNames.forEach((mergeFieldName) => {\n const currentRowCell = this.getCellByFieldName(row, mergeFieldName)\n let cellValue\n let occurrencesOfValue\n if (currentRowCell && occurrences[mergeFieldName]) {\n cellValue = currentRowCell.text || currentRowCell.html || ''\n occurrencesOfValue = occurrences[mergeFieldName][cellValue]\n\n switch (occurrencesOfValue) {\n case -1:\n mergedRow = mergedRow.filter((c) => c.fieldName !== mergeFieldName)\n break\n\n case 1:\n break\n\n default:\n currentRowCell.rowspan = occurrencesOfValue\n occurrences[mergeFieldName][cellValue] = -1\n }\n }\n })\n\n return mergedRow\n })\n }\n\n private getCellByFieldName(row: Cell[], fieldName: string) {\n return row.find((c) => c.fieldName === fieldName)\n }\n\n private mapSummary(template: SummaryTemplate): Cell[][] {\n if (this.reportSummaries[template]) {\n return this.reportSummaries[template].flatMap((reportSummary) =>\n reportSummary.data.map((rowData) =>\n this.mapRow(rowData, `dpr-report-summary-cell dpr-report-summary-cell-${template}`, reportSummary.fields),\n ),\n )\n }\n return []\n }\n\n protected sort(data: Dict<string>[]): Dict<string>[] {\n return this.appendSortKeyToData(data)\n .sort(this.sortKeyComparison())\n .map((d: SortKey) => ({\n ...d,\n }))\n }\n\n protected sortKeyComparison() {\n return (a: SortKey, b: SortKey) => {\n const aValue = a.sortKey\n const bValue = b.sortKey\n\n if (aValue === bValue) {\n return 0\n }\n\n if (aValue < bValue) {\n return -1\n }\n\n return 1\n }\n }\n\n private appendSortKeyToData(data: Dict<string>[], fields: FieldDefinition[] | null = null): SortKey[] {\n const sortFields = fields || this.fields\n\n return data.map((rowData) => {\n const sortKey = this.getSortKey(rowData, sortFields)\n\n return {\n ...rowData,\n sortKey,\n }\n })\n }\n\n protected mapNamesToFields(names: string[]): FieldDefinition[] {\n return names.map((s) => this.fields.find((f) => f.name === s)).filter((n) => n !== undefined)\n }\n\n protected getSortKey(rowData: NodeJS.Dict<string>, sortFields: FieldDefinition[]) {\n return sortFields\n .map((f) => {\n const value = rowData[f.name]\n if (value && this.dateMapper.isDate(value)) {\n return this.dateMapper.toDateString(value, 'iso')\n }\n\n return this.mapCellValue(f, value)\n })\n .join('-')\n .toLowerCase()\n }\n\n protected convertDataTableToHtml(dataTable: DataTable): string {\n const head = dataTable.head || []\n const headers = head.map((h) => `<th scope='col' class='govuk-table__header'>${h.html ?? h.text}</th>`)\n const rows = dataTable.rows.map(\n (r) =>\n `<tr class='govuk-table__row'>${r\n .map(\n (c) => `<td class='govuk-table__cell govuk-table__cell--${c.format} ${c.classes}'>${c.html ?? c.text}</td>`,\n )\n .join('')}</tr>`,\n )\n\n return (\n \"<table class='govuk-table'>\" +\n `<thead class='govuk-table__head'>${headers.join('')}</thead>` +\n `<tbody class='govuk-table__body'>${rows.join('')}</tbody>` +\n '</table>'\n )\n }\n\n withHeaderOptions({\n reportQuery,\n columns,\n interactive,\n }: {\n reportQuery?: ReportQuery\n columns: string[]\n interactive: boolean\n }) {\n if (interactive && reportQuery) {\n return this.withHeaderSortOptions(reportQuery)\n }\n return this.withNoHeaderOptions(columns)\n }\n\n withHeaderSortOptions(reportQuery: ReportQuery) {\n this.reportQuery = reportQuery\n this.columns = reportQuery.columns\n this.currentQueryParams = this.reportQuery.toRecordWithFilterPrefix()\n\n return this\n }\n\n withNoHeaderOptions(columns: string[]) {\n this.columns = columns\n return this\n }\n\n buildTable(data: Array<Dict<string>>): DataTable {\n const mappedData = this.mapData(this.sortData ? this.sort(data) : data)\n\n return {\n head: this.mapHeader(),\n rows: mappedData,\n rowCount: data.length,\n colCount: this.columns.length,\n }\n }\n\n withSummaries(reportSummaries: Dict<Array<AsyncSummary>>) {\n this.reportSummaries = reportSummaries\n return this\n }\n\n withSortedData(sortData = true) {\n this.sortData = sortData\n return this\n }\n}\n\nexport { DataTableBuilder }\nexport default DataTableBuilder\n"],
5
- "mappings": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,sBAAAE,EAAA,YAAAC,IAAA,eAAAC,EAAAJ,GAGA,IAAAK,EAAmC,2BAGnCC,EAAuB,uCAEvB,MAAMJ,CAAiB,CAgBrB,YAAYK,EAAgCC,EAAW,GAAO,CAX9D,KAAU,QAAyB,CAAC,EAEpC,KAAU,gBAA6C,CAAC,EAGxD,KAAQ,YAAkC,KAE1C,KAAQ,mBAAiE,KAEzE,KAAQ,WAAa,IAAI,EAAAC,QAGvB,KAAK,OAASF,EACd,KAAK,SAAWC,CAClB,CAEQ,QAAQE,EAAkB,CAChC,OAAKA,EAEE,KAAK,WAAW,aAAaA,EAAS,2BAA2B,EAFnD,EAGvB,CAEQ,WAAWC,EAAgB,CACjC,OAAKA,EACEA,EAAM,UAAU,EAAG,CAAC,EAAE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EA,WAAWnC,EAAsC,CAC/C,MAAMqC,EAAa,KAAK,QAAQ,KAAK,SAAW,KAAK,KAAKrC,CAAI,EAAIA,CAAI,EAEtE,MAAO,CACL,KAAM,KAAK,UAAU,EACrB,KAAMqC,EACN,SAAUrC,EAAK,OACf,SAAU,KAAK,QAAQ,MACzB,CACF,CAEA,cAAcsC,EAA4C,CACxD,YAAK,gBAAkBA,EAChB,IACT,CAEA,eAAezD,EAAW,GAAM,CAC9B,YAAK,SAAWA,EACT,IACT,CACF,CAGA,IAAOL,EAAQD",
4
+ "sourcesContent": ["import Dict = NodeJS.Dict\nimport ReportQuery from '../../types/ReportQuery'\nimport { Cell, CellFormat, DataTable, SortKey } from './types'\nimport createUrlForParameters from '../urlHelper'\nimport type { SummaryTemplate } from '../../types/Templates'\nimport { AsyncSummary } from '../../types/UserReports'\nimport DateMapper from '../DateMapper/DateMapper'\nimport { components } from '../../types/api'\n\nclass DataTableBuilder {\n protected fields: components['schemas']['FieldDefinition'][]\n\n private sortData: boolean\n\n protected columns: Array<string> = []\n\n protected reportSummaries: Dict<Array<AsyncSummary>> = {}\n\n // Sortable headers only\n private reportQuery: ReportQuery | null = null\n\n private currentQueryParams: NodeJS.Dict<string | Array<string>> | null = null\n\n private dateMapper = new DateMapper()\n\n constructor(fields: components['schemas']['FieldDefinition'][], sortData = false) {\n this.fields = fields\n this.sortData = sortData\n }\n\n private mapDate(isoDate?: string) {\n if (!isoDate) return ''\n\n return this.dateMapper.toDateString(isoDate, 'local-datetime-short-year')\n }\n\n private mapBoolean(value?: string) {\n if (!value) return ''\n return value.substring(0, 1).toUpperCase() + value.substring(1).toLowerCase()\n }\n\n protected mapRow(\n rowData: NodeJS.Dict<string>,\n extraClasses = '',\n overrideFields: components['schemas']['FieldDefinition'][] = [],\n ): Cell[] {\n return this.fields\n .filter((f) => this.columns.includes(f.name))\n .map((f) => {\n const overrideField = overrideFields.find((o) => o.name === f.name)\n const field = overrideField ?? f\n return this.mapCell(field, rowData, extraClasses)\n })\n }\n\n private mapCell(field: components['schemas']['FieldDefinition'], rowData: NodeJS.Dict<string>, extraClasses = '') {\n const textValue = this.mapCellValue(field, rowData[field.name])\n let fieldFormat: CellFormat = 'string'\n\n let classes = extraClasses\n\n if (field.wordWrap) {\n classes += ` data-table-cell-wrap-${field.wordWrap.toLowerCase()}`\n }\n\n if (field.header) {\n classes += ' govuk-table__header'\n }\n\n if (field.type === 'double' || field.type === 'long') {\n fieldFormat = 'numeric'\n }\n\n const isHtml = field.type === 'HTML'\n const cell: Cell = {\n fieldName: field.name,\n ...(isHtml ? { html: textValue } : { text: textValue }),\n format: fieldFormat,\n classes: classes.trim(),\n }\n\n return cell\n }\n\n protected mapCellValue(field: components['schemas']['FieldDefinition'], cellData?: string) {\n if (field.calculated) {\n return cellData\n }\n\n switch (field.type) {\n case 'boolean':\n return this.mapBoolean(cellData)\n\n case 'date':\n case 'time':\n return this.mapDate(cellData)\n\n default:\n return cellData\n }\n }\n\n protected mapHeader(disableSort = false, extraClasses: string | null = null): Cell[] {\n return this.fields\n .filter((field) => this.columns.includes(field.name))\n .map((f) => {\n if (this.reportQuery && !disableSort) {\n if (f.sortable) {\n let sortDirection = 'none'\n let url = createUrlForParameters(\n this.currentQueryParams || {},\n {\n sortColumn: f.name,\n sortedAsc: 'true',\n },\n this.fields,\n )\n\n if (f.name === this.reportQuery.sortColumn) {\n sortDirection = this.reportQuery.sortedAsc ? 'ascending' : 'descending'\n\n if (this.reportQuery.sortedAsc) {\n url = createUrlForParameters(\n this.currentQueryParams || {},\n {\n sortColumn: f.name,\n sortedAsc: 'false',\n },\n this.fields,\n )\n }\n }\n\n return {\n html:\n `<a ` +\n `data-column=\"${f.name}\" ` +\n `class=\"data-table-header-button data-table-header-button-sort-${sortDirection}\" ` +\n `href=\"${url}\"` +\n `>${f.display}</a>`,\n ...(extraClasses && { classes: extraClasses }),\n }\n }\n }\n return {\n text: f.display,\n ...(extraClasses && { classes: extraClasses }),\n }\n })\n }\n\n protected mapData(data: Array<Dict<string>>): Cell[][] {\n const mappedHeaderSummary = this.mapSummary('table-header')\n const mappedTableData = this.mergeCells(data.map((rowData) => this.mapRow(rowData)))\n const mappedFooterSummary = this.mapSummary('table-footer')\n\n return mappedHeaderSummary.concat(mappedTableData).concat(mappedFooterSummary)\n }\n\n private mergeCells(rows: Cell[][]): Cell[][] {\n const mergeFieldNames = this.fields\n .filter((f) => (<components['schemas']['SummaryField']>f).mergeRows)\n .map((f) => f.name)\n\n if (mergeFieldNames.length === 0) {\n return rows\n }\n\n const occurrences: Dict<Dict<number>> = {}\n mergeFieldNames.forEach((f) => {\n occurrences[f] = rows.reduce((accumulator: Dict<number>, currentRow) => {\n const currentCell = this.getCellByFieldName(currentRow, f)\n let cellValue = ''\n if (currentCell) {\n cellValue = currentCell.text || currentCell.html || ''\n }\n\n return {\n ...accumulator,\n [cellValue]: (accumulator[cellValue] ?? 0) + 1,\n }\n }, {})\n })\n\n return rows.map((row) => {\n let mergedRow = [...row]\n\n mergeFieldNames.forEach((mergeFieldName) => {\n const currentRowCell = this.getCellByFieldName(row, mergeFieldName)\n let cellValue\n let occurrencesOfValue\n if (currentRowCell && occurrences[mergeFieldName]) {\n cellValue = currentRowCell.text || currentRowCell.html || ''\n occurrencesOfValue = occurrences[mergeFieldName][cellValue]\n\n switch (occurrencesOfValue) {\n case -1:\n mergedRow = mergedRow.filter((c) => c.fieldName !== mergeFieldName)\n break\n\n case 1:\n break\n\n default:\n currentRowCell.rowspan = occurrencesOfValue\n occurrences[mergeFieldName][cellValue] = -1\n }\n }\n })\n\n return mergedRow\n })\n }\n\n private getCellByFieldName(row: Cell[], fieldName: string) {\n return row.find((c) => c.fieldName === fieldName)\n }\n\n private mapSummary(template: SummaryTemplate): Cell[][] {\n if (this.reportSummaries[template]) {\n return this.reportSummaries[template].flatMap((reportSummary) =>\n reportSummary.data.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 protected sort(data: Dict<string>[]): Dict<string>[] {\n return this.appendSortKeyToData(data)\n .sort(this.sortKeyComparison())\n .map((d: SortKey) => ({\n ...d,\n }))\n }\n\n protected sortKeyComparison() {\n return (a: SortKey, b: SortKey) => {\n const aValue = a.sortKey\n const bValue = b.sortKey\n\n if (aValue === bValue) {\n return 0\n }\n\n if (aValue < bValue) {\n return -1\n }\n\n return 1\n }\n }\n\n private appendSortKeyToData(\n data: Dict<string>[],\n fields: components['schemas']['FieldDefinition'][] | null = null,\n ): SortKey[] {\n const sortFields = fields || this.fields\n\n return data.map((rowData) => {\n const sortKey = this.getSortKey(rowData, sortFields)\n\n return {\n ...rowData,\n sortKey,\n }\n })\n }\n\n protected mapNamesToFields(names: string[]): components['schemas']['FieldDefinition'][] {\n return names.map((s) => this.fields.find((f) => f.name === s)).filter((n) => n !== undefined)\n }\n\n protected getSortKey(rowData: NodeJS.Dict<string>, sortFields: components['schemas']['FieldDefinition'][]) {\n return sortFields\n .map((f) => {\n const value = rowData[f.name]\n if (value && this.dateMapper.isDate(value)) {\n return this.dateMapper.toDateString(value, 'iso')\n }\n\n return this.mapCellValue(f, value)\n })\n .join('-')\n .toLowerCase()\n }\n\n protected convertDataTableToHtml(dataTable: DataTable): string {\n const head = dataTable.head || []\n const headers = head.map((h) => `<th scope='col' class='govuk-table__header'>${h.html ?? h.text}</th>`)\n const rows = dataTable.rows.map(\n (r) =>\n `<tr class='govuk-table__row'>${r\n .map(\n (c) => `<td class='govuk-table__cell govuk-table__cell--${c.format} ${c.classes}'>${c.html ?? c.text}</td>`,\n )\n .join('')}</tr>`,\n )\n\n return (\n \"<table class='govuk-table'>\" +\n `<thead class='govuk-table__head'>${headers.join('')}</thead>` +\n `<tbody class='govuk-table__body'>${rows.join('')}</tbody>` +\n '</table>'\n )\n }\n\n withHeaderOptions({\n reportQuery,\n columns,\n interactive,\n }: {\n reportQuery?: ReportQuery\n columns: string[]\n interactive: boolean\n }) {\n if (interactive && reportQuery) {\n return this.withHeaderSortOptions(reportQuery)\n }\n return this.withNoHeaderOptions(columns)\n }\n\n withHeaderSortOptions(reportQuery: ReportQuery) {\n this.reportQuery = reportQuery\n this.columns = reportQuery.columns\n this.currentQueryParams = this.reportQuery.toRecordWithFilterPrefix()\n\n return this\n }\n\n withNoHeaderOptions(columns: string[]) {\n this.columns = columns\n return this\n }\n\n buildTable(data: Array<Dict<string>>): DataTable {\n const mappedData = this.mapData(this.sortData ? this.sort(data) : data)\n\n return {\n head: this.mapHeader(),\n rows: mappedData,\n rowCount: data.length,\n colCount: this.columns.length,\n }\n }\n\n withSummaries(reportSummaries: Dict<Array<AsyncSummary>>) {\n this.reportSummaries = reportSummaries\n return this\n }\n\n withSortedData(sortData = true) {\n this.sortData = sortData\n return this\n }\n}\n\nexport { DataTableBuilder }\nexport default DataTableBuilder\n"],
5
+ "mappings": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,sBAAAE,EAAA,YAAAC,IAAA,eAAAC,EAAAJ,GAGA,IAAAK,EAAmC,2BAGnCC,EAAuB,uCAGvB,MAAMJ,CAAiB,CAgBrB,YAAYK,EAAoDC,EAAW,GAAO,CAXlF,KAAU,QAAyB,CAAC,EAEpC,KAAU,gBAA6C,CAAC,EAGxD,KAAQ,YAAkC,KAE1C,KAAQ,mBAAiE,KAEzE,KAAQ,WAAa,IAAI,EAAAC,QAGvB,KAAK,OAASF,EACd,KAAK,SAAWC,CAClB,CAEQ,QAAQE,EAAkB,CAChC,OAAKA,EAEE,KAAK,WAAW,aAAaA,EAAS,2BAA2B,EAFnD,EAGvB,CAEQ,WAAWC,EAAgB,CACjC,OAAKA,EACEA,EAAM,UAAU,EAAG,CAAC,EAAE,YAAY,EAAIA,EAAM,UAAU,CAAC,EAAE,YAAY,EADzD,EAErB,CAEU,OACRC,EACAC,EAAe,GACfC,EAA6D,CAAC,EACtD,CACR,OAAO,KAAK,OACT,OAAQC,GAAM,K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B,KAAMqC,EACN,SAAUrC,EAAK,OACf,SAAU,KAAK,QAAQ,MACzB,CACF,CAEA,cAAcsC,EAA4C,CACxD,YAAK,gBAAkBA,EAChB,IACT,CAEA,eAAezD,EAAW,GAAM,CAC9B,YAAK,SAAWA,EACT,IACT,CACF,CAGA,IAAOL,EAAQD",
6
6
  "names": ["DataTableBuilder_exports", "__export", "DataTableBuilder", "DataTableBuilder_default", "__toCommonJS", "import_urlHelper", "import_DateMapper", "fields", "sortData", "DateMapper", "isoDate", "value", "rowData", "extraClasses", "overrideFields", "f", "field", "o", "textValue", "fieldFormat", "classes", "isHtml", "cellData", "disableSort", "sortDirection", "url", "createUrlForParameters", "data", "mappedHeaderSummary", "mappedTableData", "mappedFooterSummary", "rows", "mergeFieldNames", "occurrences", "accumulator", "currentRow", "currentCell", "cellValue", "row", "mergedRow", "mergeFieldName", "currentRowCell", "occurrencesOfValue", "c", "fieldName", "template", "reportSummary", "d", "a", "b", "aValue", "bValue", "sortFields", "sortKey", "names", "s", "n", "dataTable", "headers", "h", "r", "reportQuery", "columns", "interactive", "mappedData", "reportSummaries"]
7
7
  }
@@ -1,13 +1,14 @@
1
1
  import Dict = NodeJS.Dict
2
2
  import ReportQuery from '../../types/ReportQuery'
3
- import { Cell, CellFormat, DataTable, FieldDefinition, SortKey } from './types'
3
+ import { Cell, CellFormat, DataTable, SortKey } from './types'
4
4
  import createUrlForParameters from '../urlHelper'
5
5
  import type { SummaryTemplate } from '../../types/Templates'
6
6
  import { AsyncSummary } from '../../types/UserReports'
7
7
  import DateMapper from '../DateMapper/DateMapper'
8
+ import { components } from '../../types/api'
8
9
 
9
10
  class DataTableBuilder {
10
- protected fields: Array<FieldDefinition>
11
+ protected fields: components['schemas']['FieldDefinition'][]
11
12
 
12
13
  private sortData: boolean
13
14
 
@@ -22,7 +23,7 @@ class DataTableBuilder {
22
23
 
23
24
  private dateMapper = new DateMapper()
24
25
 
25
- constructor(fields: Array<FieldDefinition>, sortData = false) {
26
+ constructor(fields: components['schemas']['FieldDefinition'][], sortData = false) {
26
27
  this.fields = fields
27
28
  this.sortData = sortData
28
29
  }
@@ -41,7 +42,7 @@ class DataTableBuilder {
41
42
  protected mapRow(
42
43
  rowData: NodeJS.Dict<string>,
43
44
  extraClasses = '',
44
- overrideFields: Array<FieldDefinition> = [],
45
+ overrideFields: components['schemas']['FieldDefinition'][] = [],
45
46
  ): Cell[] {
46
47
  return this.fields
47
48
  .filter((f) => this.columns.includes(f.name))
@@ -52,7 +53,7 @@ class DataTableBuilder {
52
53
  })
53
54
  }
54
55
 
55
- private mapCell(field: FieldDefinition, rowData: NodeJS.Dict<string>, extraClasses = '') {
56
+ private mapCell(field: components['schemas']['FieldDefinition'], rowData: NodeJS.Dict<string>, extraClasses = '') {
56
57
  const textValue = this.mapCellValue(field, rowData[field.name])
57
58
  let fieldFormat: CellFormat = 'string'
58
59
 
@@ -81,7 +82,7 @@ class DataTableBuilder {
81
82
  return cell
82
83
  }
83
84
 
84
- protected mapCellValue(field: FieldDefinition, cellData?: string) {
85
+ protected mapCellValue(field: components['schemas']['FieldDefinition'], cellData?: string) {
85
86
  if (field.calculated) {
86
87
  return cellData
87
88
  }
@@ -106,19 +107,27 @@ class DataTableBuilder {
106
107
  if (this.reportQuery && !disableSort) {
107
108
  if (f.sortable) {
108
109
  let sortDirection = 'none'
109
- let url = createUrlForParameters(this.currentQueryParams || {}, {
110
- sortColumn: f.name,
111
- sortedAsc: 'true',
112
- })
110
+ let url = createUrlForParameters(
111
+ this.currentQueryParams || {},
112
+ {
113
+ sortColumn: f.name,
114
+ sortedAsc: 'true',
115
+ },
116
+ this.fields,
117
+ )
113
118
 
114
119
  if (f.name === this.reportQuery.sortColumn) {
115
120
  sortDirection = this.reportQuery.sortedAsc ? 'ascending' : 'descending'
116
121
 
117
122
  if (this.reportQuery.sortedAsc) {
118
- url = createUrlForParameters(this.currentQueryParams || {}, {
119
- sortColumn: f.name,
120
- sortedAsc: 'false',
121
- })
123
+ url = createUrlForParameters(
124
+ this.currentQueryParams || {},
125
+ {
126
+ sortColumn: f.name,
127
+ sortedAsc: 'false',
128
+ },
129
+ this.fields,
130
+ )
122
131
  }
123
132
  }
124
133
 
@@ -149,7 +158,9 @@ class DataTableBuilder {
149
158
  }
150
159
 
151
160
  private mergeCells(rows: Cell[][]): Cell[][] {
152
- const mergeFieldNames = this.fields.filter((f) => f.mergeRows).map((f) => f.name)
161
+ const mergeFieldNames = this.fields
162
+ .filter((f) => (<components['schemas']['SummaryField']>f).mergeRows)
163
+ .map((f) => f.name)
153
164
 
154
165
  if (mergeFieldNames.length === 0) {
155
166
  return rows
@@ -209,7 +220,11 @@ class DataTableBuilder {
209
220
  if (this.reportSummaries[template]) {
210
221
  return this.reportSummaries[template].flatMap((reportSummary) =>
211
222
  reportSummary.data.map((rowData) =>
212
- this.mapRow(rowData, `dpr-report-summary-cell dpr-report-summary-cell-${template}`, reportSummary.fields),
223
+ this.mapRow(
224
+ rowData,
225
+ `dpr-report-summary-cell dpr-report-summary-cell-${template}`,
226
+ <components['schemas']['FieldDefinition'][]>reportSummary.fields,
227
+ ),
213
228
  ),
214
229
  )
215
230
  }
@@ -241,7 +256,10 @@ class DataTableBuilder {
241
256
  }
242
257
  }
243
258
 
244
- private appendSortKeyToData(data: Dict<string>[], fields: FieldDefinition[] | null = null): SortKey[] {
259
+ private appendSortKeyToData(
260
+ data: Dict<string>[],
261
+ fields: components['schemas']['FieldDefinition'][] | null = null,
262
+ ): SortKey[] {
245
263
  const sortFields = fields || this.fields
246
264
 
247
265
  return data.map((rowData) => {
@@ -254,11 +272,11 @@ class DataTableBuilder {
254
272
  })
255
273
  }
256
274
 
257
- protected mapNamesToFields(names: string[]): FieldDefinition[] {
275
+ protected mapNamesToFields(names: string[]): components['schemas']['FieldDefinition'][] {
258
276
  return names.map((s) => this.fields.find((f) => f.name === s)).filter((n) => n !== undefined)
259
277
  }
260
278
 
261
- protected getSortKey(rowData: NodeJS.Dict<string>, sortFields: FieldDefinition[]) {
279
+ protected getSortKey(rowData: NodeJS.Dict<string>, sortFields: components['schemas']['FieldDefinition'][]) {
262
280
  return sortFields
263
281
  .map((f) => {
264
282
  const value = rowData[f.name]
@@ -1,2 +1,2 @@
1
- var P=Object.create;var u=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var w=Object.getPrototypeOf,F=Object.prototype.hasOwnProperty;var N=(s,c)=>{for(var t in c)u(s,t,{get:c[t],enumerable:!0})},f=(s,c,t,r)=>{if(c&&typeof c=="object"||typeof c=="function")for(let e of A(c))!F.call(s,e)&&e!==t&&u(s,e,{get:()=>c[e],enumerable:!(r=v(c,e))||r.enumerable});return s};var S=(s,c,t)=>(t=s!=null?P(w(s)):{},f(c||!s||!s.__esModule?u(t,"default",{value:s,enumerable:!0}):t,s)),B=s=>f(u({},"__esModule",{value:!0}),s);var J={};N(J,{ParentChildDataTableBuilder:()=>C,default:()=>H});module.exports=B(J);var g=S(require("../DataTableBuilder/DataTableBuilder")),b=require("../arrayUtils"),T=S(require("../SectionedDataTableBuilder/SectionedDataTableBuilder"));class C extends T.default{constructor(t){const{specification:r}=t,{sections:e,template:i}=r;super(r);this.childData=[];this.sections=e,this.template=i,this.variant=t,this.childVariants=this.variant.childVariants||[]}createParentChildTable(t,r){let e={};const i=this.mapNamesToFields(this.childVariants.flatMap(a=>a.joinFields).reduce(b.distinct,[])),n=this.calculateParentChildKeys(t,i);n.forEach(a=>{e[a.sortKey]={parent:[]}}),e=this.splitParentDataIntoSections(e,t,i),e=this.splitChildDataIntoSections(n,e);const l=this.createChildDataTableBuilders();return n.flatMap(a=>{const d=e[a.sortKey]||{};let p=[];return d&&(p=d.parent?d.parent:[]),[r].concat(p.map(h=>this.mapRow(h,"dpr-parent-cell"))).concat(this.childVariants.filter(h=>d&&d[h.id]).map(h=>{const D=l[h.id],m=d[h.id],y=D&&m?D.buildTable(m):void 0,K=y?this.convertDataTableToHtml(y):"";return[{classes:"dpr-child-report-cell",format:"string",html:`<div class='dpr-child-report'><h2 class="govuk-heading-s">${h.name}</h2><div class="dpr-child-report_table">${K}</div></div>`,colspan:this.columns.length}]}))})}createParentChildSectionRows(t,r){const i=this.mapSections(t).sectionedData,n=[];return Object.keys(i).forEach(o=>{const a=i[o];n.push({sectionDescription:o,...this.getSectionCount(i,o),rows:this.createParentChildTable(a,r)})}),n.flatMap((o,a)=>[...this.createSectionHeader(o.sectionDescription,a,o.count,o.countDescription),...o.rows])}mapParentChildData(t,r){return this.sections?.length?this.createParentChildSectionRows(t,r):this.createParentChildTable(t,r)}createChildDataTableBuilders(){return this.childVariants.reduce((r,e)=>{const{specification:i}=e,n=i?i.fields:[],l=n.filter(a=>a.visible||a.mandatory).map(a=>a.name),o=new g.default(n).withNoHeaderOptions(l).withSortedData();return{...r,[e.id]:o}},{})}calculateParentChildKeys(t,r){return t.map(e=>({sortKey:this.getSortKey(e,r),childSortKeys:this.childVariants.reduce((i,n)=>({...i,[n.id]:this.getSortKey(e,this.mapNamesToFields(n.joinFields))}),{})})).reduce((e,i)=>e.find(n=>n.sortKey===i.sortKey)?e:e.concat(i),[])}splitParentDataIntoSections(t,r,e){return r.reduce((i,n)=>{const l=this.getSortKey(n,e),o=i[l]?i[l].parent:[];return{...i,...o&&{[l]:{parent:o.concat(n)}}}},t)}splitChildDataIntoSections(t,r){const e={...r};return this.childVariants.forEach(i=>{const n=this.mapNamesToFields(i.joinFields),l=this.childData.find(a=>a.id===i.id);(l?l.data:[]).filter(a=>{const d=this.getSortKey(a,n);return t.find(p=>p.childSortKeys[i.id]===d)}).forEach(a=>{const d=this.getSortKey(a,n),p=t.find(m=>m.childSortKeys[i.id]===d),h=p?p.sortKey:"",D=e[h];if(D){const m=D[i.id]||[];D[i.id]=m.concat(a)}})}),e}withChildData(t){return this.childData=t,this}buildTable(t){return{head:null,rows:this.mapParentChildData(t,this.mapHeader(!0,"govuk-table__header")),rowCount:t.length,colCount:this.columns.length}}}var H=C;0&&(module.exports={ParentChildDataTableBuilder});
1
+ var P=Object.create;var u=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var w=Object.getPrototypeOf,N=Object.prototype.hasOwnProperty;var F=(n,c)=>{for(var t in c)u(n,t,{get:c[t],enumerable:!0})},f=(n,c,t,r)=>{if(c&&typeof c=="object"||typeof c=="function")for(let e of A(c))!N.call(n,e)&&e!==t&&u(n,e,{get:()=>c[e],enumerable:!(r=v(c,e))||r.enumerable});return n};var S=(n,c,t)=>(t=n!=null?P(w(n)):{},f(c||!n||!n.__esModule?u(t,"default",{value:n,enumerable:!0}):t,n)),B=n=>f(u({},"__esModule",{value:!0}),n);var J={};F(J,{ParentChildDataTableBuilder:()=>C,default:()=>H});module.exports=B(J);var g=S(require("../DataTableBuilder/DataTableBuilder")),b=require("../arrayUtils"),T=S(require("../SectionedDataTableBuilder/SectionedDataTableBuilder"));class C extends T.default{constructor(t){const{specification:r}=t,{sections:e,template:i}=r;super(r);this.childData=[];this.sections=e,this.template=i,this.variant=t,this.childVariants=this.variant.childVariants||[]}createParentChildTable(t,r){let e={};const i=this.mapNamesToFields(this.childVariants.flatMap(a=>a.joinFields).reduce(b.distinct,[])),s=this.calculateParentChildKeys(t,i);s.forEach(a=>{e[a.sortKey]={parent:[]}}),e=this.splitParentDataIntoSections(e,t,i),e=this.splitChildDataIntoSections(s,e);const l=this.createChildDataTableBuilders();return s.flatMap(a=>{const d=e[a.sortKey]||{};let p=[];return d&&(p=d.parent?d.parent:[]),[r].concat(p.map(h=>this.mapRow(h,"dpr-parent-cell"))).concat(this.childVariants.filter(h=>d&&d[h.id]).map(h=>{const D=l[h.id],m=d[h.id],y=D&&m?D.buildTable(m):void 0,K=y?this.convertDataTableToHtml(y):"";return[{classes:"dpr-child-report-cell",format:"string",html:`<div class='dpr-child-report'><h2 class="govuk-heading-s">${h.name}</h2><div class="dpr-child-report_table">${K}</div></div>`,colspan:this.columns.length}]}))})}createParentChildSectionRows(t,r){const i=this.mapSections(t).sectionedData,s=[];return Object.keys(i).forEach(o=>{const a=i[o];s.push({sectionDescription:o,...this.getSectionCount(i,o),rows:this.createParentChildTable(a,r)})}),s.flatMap((o,a)=>[...this.createSectionHeader(o.sectionDescription,a,o.count,o.countDescription),...o.rows])}mapParentChildData(t,r){return this.sections?.length?this.createParentChildSectionRows(t,r):this.createParentChildTable(t,r)}createChildDataTableBuilders(){return this.childVariants.reduce((r,e)=>{const{specification:i}=e,s=i?i.fields:[],l=s.filter(a=>a.visible||a.mandatory).map(a=>a.name),o=new g.default(s).withNoHeaderOptions(l).withSortedData();return{...r,[e.id]:o}},{})}calculateParentChildKeys(t,r){return t.map(e=>({sortKey:this.getSortKey(e,r),childSortKeys:this.childVariants.reduce((i,s)=>({...i,[s.id]:this.getSortKey(e,this.mapNamesToFields(s.joinFields))}),{})})).reduce((e,i)=>e.find(s=>s.sortKey===i.sortKey)?e:e.concat(i),[])}splitParentDataIntoSections(t,r,e){return r.reduce((i,s)=>{const l=this.getSortKey(s,e),o=i[l]?i[l].parent:[];return{...i,...o&&{[l]:{parent:o.concat(s)}}}},t)}splitChildDataIntoSections(t,r){const e={...r};return this.childVariants.forEach(i=>{const s=this.mapNamesToFields(i.joinFields),l=this.childData.find(a=>a.id===i.id);(l?l.data:[]).filter(a=>{const d=this.getSortKey(a,s);return t.find(p=>p.childSortKeys[i.id]===d)}).forEach(a=>{const d=this.getSortKey(a,s),p=t.find(m=>m.childSortKeys[i.id]===d),h=p?p.sortKey:"",D=e[h];if(D){const m=D[i.id]||[];D[i.id]=m.concat(a)}})}),e}withChildData(t){return this.childData=t,this}buildTable(t){return{head:null,rows:this.mapParentChildData(t,this.mapHeader(!0,"govuk-table__header")),rowCount:t.length,colCount:this.columns.length}}}var H=C;0&&(module.exports={ParentChildDataTableBuilder});
2
2
  //# sourceMappingURL=ParentChildDataTableBuilder.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/dpr/utils/ParentChildDataTableBuilder/ParentChildDataTableBuilder.ts"],
4
- "sourcesContent": ["import Dict = NodeJS.Dict\nimport { components } from '../../types/api'\nimport { Cell, DataTable, FieldDefinition } 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(parentData: Array<NodeJS.Dict<string>>, joinFields: FieldDefinition[]) {\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: 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 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": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iCAAAE,EAAA,YAAAC,IAAA,eAAAC,EAAAJ,GAGA,IAAAK,EAA6B,mDAC7BC,EAAyB,yBAEzBC,EAAsC,qEAEtC,MAAML,UAAoC,EAAAM,OAA0B,CAOlE,YAAYC,EAAqD,CAC/D,KAAM,CAAE,cAAAC,CAAc,EAAID,EACpB,CAAE,SAAAE,EAAU,SAAAC,CAAS,EAA4CF,EACvE,MAA8CA,CAAa,EAL7D,eAA8B,CAAC,EAO7B,KAAK,SAAWC,EAChB,KAAK,SAAWC,EAChB,KAAK,QAAUH,EACf,KAAK,cAAgB,KAAK,QAAQ,eAAiB,CAAC,CACtD,CAEQ,uBAAuBI,EAAiCC,EAAgB,CAC9E,IAAIC,EAA4D,CAAC,EACjE,MAAMC,EAAa,KAAK,iBAAiB,KAAK,cAAc,QAASC,GAAMA,EAAE,UAAU,EAAE,OAAO,WAAU,CAAC,CAAC,CAAC,EAIvGC,EAAkB,KAAK,yBAAyBL,EAAYG,CAAU,EAC5EE,EAAgB,QAASC,GAAc,CACrCJ,EAAyBI,EAAU,OAAO,EAAI,CAC5C,OAAQ,CAAC,CACX,CACF,CAAC,EAEDJ,EAA2B,KAAK,4BAA4BA,EAA0BF,EAAYG,CAAU,EAC5GD,EAA2B,KAAK,2BAA2BG,EAAiBH,CAAwB,E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,EAAoB,OAAOH,CAAO,CAC5C,CACF,CACF,CACF,EAAG1B,CAAwB,CAC7B,CAEQ,2BACN8B,EACA9B,EACiC,CACjC,MAAM+B,EAAuC,CAAE,GAAG/B,CAAyB,EAE3E,YAAK,cAAc,QAASU,GAAiB,CAC3C,MAAMsB,EAAc,KAAK,iBAAiBtB,EAAa,UAAU,EAC3DuB,EAAoB,KAAK,UAAU,KAAMC,GAAMA,EAAE,KAAOxB,EAAa,EAAE,GAChEuB,EAAoBA,EAAkB,KAAO,CAAC,GAGxD,OAAQP,GAAY,CACnB,MAAMC,EAAU,KAAK,WAAWD,EAASM,CAAW,EACpD,OAAOF,EAAW,KAAM,GAAM,EAAE,cAAcpB,EAAa,EAAE,IAAMiB,CAAO,CAC5E,CAAC,EACA,QAASD,GAAY,CACpB,MAAMC,EAAU,KAAK,WAAWD,EAASM,CAAW,EAC9CG,EAASL,EAAW,KAAMM,GAAMA,EAAE,cAAc1B,EAAa,EAAE,IAAMiB,CAAO,EAC5EU,EAAgBF,EAASA,EAAO,QAAU,GAC1CG,EAAgBP,EAAqCM,CAAa,EACxE,GAAIC,EAAe,CACjB,MAAMC,EAAoBD,EAAc5B,EAAa,EAAE,GAAK,CAAC,EAC7D4B,EAAc5B,EAAa,EAAE,EAAI6B,EAAkB,OAAOb,CAAO,CACnE,CACF,CAAC,CACL,CAAC,EAEMK,CACT,CAEA,cAAcS,EAA6B,CACzC,YAAK,UAAYA,EACV,IACT,CAEA,WAAWtB,EAAsC,CAC/C,MAAO,CACL,KAAM,KACN,KAAM,KAAK,mBAAmBA,EAAM,KAAK,UAAU,GAAM,qBAAqB,CAAC,EAC/E,SAAUA,EAAK,OACf,SAAU,KAAK,QAAQ,MACzB,CACF,CACF,CAGA,IAAO9B,EAAQD",
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 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": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iCAAAE,EAAA,YAAAC,IAAA,eAAAC,EAAAJ,GAGA,IAAAK,EAA6B,mDAC7BC,EAAyB,yBAEzBC,EAAsC,qEAEtC,MAAML,UAAoC,EAAAM,OAA0B,CAOlE,YAAYC,EAAqD,CAC/D,KAAM,CAAE,cAAAC,CAAc,EAAID,EACpB,CAAE,SAAAE,EAAU,SAAAC,CAAS,EAA4CF,EACvE,MAA8CA,CAAa,EAL7D,eAA8B,CAAC,EAO7B,KAAK,SAAWC,EAChB,KAAK,SAAWC,EAChB,KAAK,QAAUH,EACf,KAAK,cAAgB,KAAK,QAAQ,eAAiB,CAAC,CACtD,CAEQ,uBAAuBI,EAAiCC,EAAgB,CAC9E,IAAIC,EAA4D,CAAC,EACjE,MAAMC,EAAa,KAAK,iBAAiB,KAAK,cAAc,QAASC,GAAMA,EAAE,UAAU,EAAE,OAAO,WAAU,CAAC,CAAC,CAAC,EAIvGC,EAAkB,KAAK,yBAAyBL,EAAYG,CAAU,EAC5EE,EAAgB,QAASC,GAAc,CACrCJ,EAAyBI,EAAU,OAAO,EAAI,CAC5C,OAAQ,CAAC,CACX,CACF,CAAC,EAEDJ,EAA2B,KAAK,4BAA4BA,EAA0BF,EAAYG,CAAU,EAC5GD,EAA2B,KAAK,2BAA2BG,EAAiBH,CAAwB,EAEpG,MAAMK,EAAyB,KAAK,6BAA6B,EA+BjE,OA7ByBF,EAAgB,QAASG,GAAQ,CACxD,MAAMC,EAAcP,EAAyBM,EAAI,OAAO,GAAK,CAAC,EAE9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AE3E,YAAK,cAAc,QAASU,GAAiB,CAC3C,MAAMsB,EAAc,KAAK,iBAAiBtB,EAAa,UAAU,EAC3DuB,EAAoB,KAAK,UAAU,KAAMC,GAAMA,EAAE,KAAOxB,EAAa,EAAE,GAChEuB,EAAoBA,EAAkB,KAAO,CAAC,GAGxD,OAAQP,GAAY,CACnB,MAAMC,EAAU,KAAK,WAAWD,EAASM,CAAW,EACpD,OAAOF,EAAW,KAAM,GAAM,EAAE,cAAcpB,EAAa,EAAE,IAAMiB,CAAO,CAC5E,CAAC,EACA,QAASD,GAAY,CACpB,MAAMC,EAAU,KAAK,WAAWD,EAASM,CAAW,EAC9CG,EAASL,EAAW,KAAMM,GAAMA,EAAE,cAAc1B,EAAa,EAAE,IAAMiB,CAAO,EAC5EU,EAAgBF,EAASA,EAAO,QAAU,GAC1CG,EAAgBP,EAAqCM,CAAa,EACxE,GAAIC,EAAe,CACjB,MAAMC,EAAoBD,EAAc5B,EAAa,EAAE,GAAK,CAAC,EAC7D4B,EAAc5B,EAAa,EAAE,EAAI6B,EAAkB,OAAOb,CAAO,CACnE,CACF,CAAC,CACL,CAAC,EAEMK,CACT,CAEA,cAAcS,EAA6B,CACzC,YAAK,UAAYA,EACV,IACT,CAEA,WAAWtB,EAAsC,CAC/C,MAAO,CACL,KAAM,KACN,KAAM,KAAK,mBAAmBA,EAAM,KAAK,UAAU,GAAM,qBAAqB,CAAC,EAC/E,SAAUA,EAAK,OACf,SAAU,KAAK,QAAQ,MACzB,CACF,CACF,CAGA,IAAO9B,EAAQD",
6
6
  "names": ["ParentChildDataTableBuilder_exports", "__export", "ParentChildDataTableBuilder", "ParentChildDataTableBuilder_default", "__toCommonJS", "import_DataTableBuilder", "import_arrayUtils", "import_SectionedDataTableBuilder", "SectionedDataTableBuilder", "variant", "specification", "sections", "template", "parentData", "header", "sectionedParentChildData", "joinFields", "c", "parentChildKeys", "parentKey", "childDataTableBuilders", "key", "sectionData", "parentSectionData", "r", "childVariant", "builder", "section", "dataTable", "dataTableHtml", "sectionedData", "sectionedParentChildSectionedRows", "sectionDescription", "data", "index", "previousValue", "fields", "fieldNamesToDisplay", "f", "dataTableBuilder", "DataTableBuilder", "rowData", "sortKey", "v", "previousParentValue", "parentKeys", "sectionedParentChildDataWithChildren", "childFields", "matchingChildData", "d", "parent", "p", "parentSortKey", "parentSection", "existingChildData", "childData"]
7
7
  }
@@ -1,6 +1,6 @@
1
1
  import Dict = NodeJS.Dict
2
2
  import { components } from '../../types/api'
3
- import { Cell, DataTable, FieldDefinition } from '../DataTableBuilder/types'
3
+ import { Cell, DataTable } from '../DataTableBuilder/types'
4
4
  import DataTableBuilder from '../DataTableBuilder/DataTableBuilder'
5
5
  import { distinct } from '../arrayUtils'
6
6
  import { ChildData, ParentChildSortKey } from './types'
@@ -130,7 +130,10 @@ class ParentChildDataTableBuilder extends SectionedDataTableBuilder {
130
130
  return childDataTables
131
131
  }
132
132
 
133
- private calculateParentChildKeys(parentData: Array<NodeJS.Dict<string>>, joinFields: FieldDefinition[]) {
133
+ private calculateParentChildKeys(
134
+ parentData: Array<NodeJS.Dict<string>>,
135
+ joinFields: components['schemas']['FieldDefinition'][],
136
+ ) {
134
137
  return parentData
135
138
  .map(
136
139
  (rowData): ParentChildSortKey => ({
@@ -154,7 +157,7 @@ class ParentChildDataTableBuilder extends SectionedDataTableBuilder {
154
157
  private splitParentDataIntoSections(
155
158
  sectionedParentChildData: NodeJS.Dict<NodeJS.Dict<Array<NodeJS.Dict<string>>>>,
156
159
  parentData: Array<NodeJS.Dict<string>>,
157
- joinFields: FieldDefinition[],
160
+ joinFields: components['schemas']['FieldDefinition'][],
158
161
  ) {
159
162
  return parentData.reduce((previousValue, rowData) => {
160
163
  const parentKey: string = this.getSortKey(rowData, joinFields)
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/dpr/utils/SectionedDataTableBuilder/SectionedDataTableBuilder.ts"],
4
- "sourcesContent": ["import Dict = NodeJS.Dict\nimport { components } from '../../types/api'\nimport { Cell, DataTable, FieldDefinition } 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(data: Dict<string>[], sectionFields: FieldDefinition[]): 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(rowData, `dpr-report-summary-cell dpr-report-summary-cell-${template}`, reportSummary.fields),\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 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": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,+BAAAE,EAAA,YAAAC,IAAA,eAAAC,EAAAJ,GAIA,IAAAK,EAA6B,mDAC7BC,EAAyB,yBACzBC,EAAoC,iEAGpC,MAAML,UAAkC,EAAAM,OAAiB,CAKvD,YAAYC,EAAuD,CACjE,KAAM,CAAE,OAAAC,EAAQ,SAAAC,EAAU,SAAAC,CAAS,EAAIH,EACvC,MAAMC,CAAM,EACZ,KAAK,SAAWC,EAChB,KAAK,SAAWC,CAClB,CASQ,sBAAsBC,EAAsBC,EAA4C,CAC9F,OAAOD,EACJ,IACEE,IAA6B,CAC5B,YAAa,KAAK,sBAAsBA,CAAO,EAC/C,QAAS,KAAK,WAAWA,EAASD,CAAa,CACjD,EACF,EACC,KAAK,KAAK,kBAAkB,CAAC,EAC7B,IAAKE,GAAMA,EAAE,WAAW,EACxB,OAAO,WAAU,CAAC,CAAC,CACxB,CAUA,gBAAgBC,EAA+B,CAC7C,MAAMC,EAA4D,CAAC,EACnE,OAAAD,EAAoB,QAASE,GAAuB,CAClDD,EAAcC,CAAkB,EAAI,CAAC,CACvC,CAAC,EACMD,CACT,CAWQ,iBAAiBL,EAA2BK,EAA+B,CACjF,OAAOL,EAAK,OAAO,C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AA2B,CAE/C,MAAMC,EAAgB,KAAK,iBAAiB,KAAK,QAAQ,EAEnDG,EAAsB,KAAK,sBAAsBJ,EAAMC,CAAa,EAEpEI,EAAgB,KAAK,gBAAgBD,CAAmB,EAE9D,MAAO,CACL,oBAAAA,EACA,cAAAC,CACF,CACF,CAWQ,iBAAiBL,EAA2Ba,EAA0B,CAC5E,KAAM,CAAE,oBAAAT,EAAqB,cAAAC,CAAc,EAAI,KAAK,YAAYL,CAAI,EAIpE,OAFqB,KAAK,mBAAmBI,EAAqBC,EAAiCQ,CAAM,CAG3G,CAEA,WAAWb,EAAsC,CAC/C,MAAO,CACL,KAAM,KACN,KAAM,KAAK,iBAAiBA,EAAM,KAAK,UAAU,GAAM,qBAAqB,CAAC,EAC7E,SAAUA,EAAK,OACf,SAAU,KAAK,QAAQ,MACzB,CACF,CACF,CAGA,IAAOV,EAAQD",
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(rowData, `dpr-report-summary-cell dpr-report-summary-cell-${template}`, reportSummary.fields),\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 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": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,+BAAAE,EAAA,YAAAC,IAAA,eAAAC,EAAAJ,GAIA,IAAAK,EAA6B,mDAC7BC,EAAyB,yBACzBC,EAAoC,iEAGpC,MAAML,UAAkC,EAAAM,OAAiB,CAKvD,YA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QACjH,CACF,CACF,CAEJ,CACA,MAAO,CAAC,CACV,CAEA,sBAAsBtB,EAAsC,CAC1D,KAAM,CAAE,SAAAJ,CAAS,EAAI,KAErB,OAAO,KAAK,iBAAiBA,CAAQ,EAClC,IAAKK,GAAM,GAAGA,EAAE,OAAO,KAAK,KAAK,aAAaA,EAAGD,EAAQC,EAAE,IAAI,CAAC,CAAC,EAAE,EACnE,KAAK,IAAI,CACd,CAEA,YAAYH,EAA2B,CACrC,MAAM6B,EAAkB,KAAK,sBAAsB7B,CAAI,EACvD,GAAI,CAAE,cAAAK,CAAc,EAAIwB,EAGxB,OAAI,KAAK,WAAa,oBAChB,KAAK,WAAa,uBACpBxB,EAAgB,KAAK,iBAAiBL,EAAMK,CAAqC,EAEjFA,EAAgB,KAAK,iBAAiBL,EAAMK,CAA+B,GAIxE,CACL,oBAAqBwB,EAAgB,oBACrC,cAAAxB,CACF,CACF,CAEA,sBAAsBL,EAA2B,CAE/C,MAAMC,EAAgB,KAAK,iBAAiB,KAAK,QAAQ,EAEnDG,EAAsB,KAAK,sBAAsBJ,EAAMC,CAAa,EAEpEI,EAAgB,KAAK,gBAAgBD,CAAmB,EAE9D,MAAO,CACL,oBAAAA,EACA,cAAAC,CACF,CACF,CAWQ,iBAAiBL,EAA2Ba,EAA0B,CAC5E,KAAM,CAAE,oBAAAT,EAAqB,cAAAC,CAAc,EAAI,KAAK,YAAYL,CAAI,EAIpE,OAFqB,KAAK,mBAAmBI,EAAqBC,EAAiCQ,CAAM,CAG3G,CAEA,WAAWb,EAAsC,CAC/C,MAAO,CACL,KAAM,KACN,KAAM,KAAK,iBAAiBA,EAAM,KAAK,UAAU,GAAM,qBAAqB,CAAC,EAC7E,SAAUA,EAAK,OACf,SAAU,KAAK,QAAQ,MACzB,CACF,CACF,CAGA,IAAOV,EAAQD",
6
6
  "names": ["SectionedDataTableBuilder_exports", "__export", "SectionedDataTableBuilder", "SectionedDataTableBuilder_default", "__toCommonJS", "import_DataTableBuilder", "import_arrayUtils", "import_SummaryDataTableBuilder", "DataTableBuilder", "specification", "fields", "sections", "template", "data", "sectionFields", "rowData", "s", "sectionDescriptions", "sectionedData", "sectionDescription", "previousValue", "mappedData", "previousValueDescription", "count", "countDescription", "mappedTableData", "header", "tableContent", "mappedSectionHeaderSummary", "mappedHeaderSummary", "mappedFooterSummary", "mappedSectionFooterSummary", "index", "reportSummary", "summaryTemplate", "columnsLength", "summaries", "summaryContent", "summary", "row", "dataTable", "SummaryDataTableBuilder", "sectionHeadings"]
7
7
  }
@@ -1,6 +1,6 @@
1
1
  import Dict = NodeJS.Dict
2
2
  import { components } from '../../types/api'
3
- import { Cell, DataTable, FieldDefinition } from '../DataTableBuilder/types'
3
+ import { Cell, DataTable } from '../DataTableBuilder/types'
4
4
  import type { SummaryTemplate, Template } from '../../types/Templates'
5
5
  import DataTableBuilder from '../DataTableBuilder/DataTableBuilder'
6
6
  import { distinct } from '../arrayUtils'
@@ -26,7 +26,10 @@ class SectionedDataTableBuilder extends DataTableBuilder {
26
26
  * @param {FieldDefinition[]} sectionFields
27
27
  * @return {*} {string[]} array of section headings
28
28
  */
29
- private createSectionHeadings(data: Dict<string>[], sectionFields: FieldDefinition[]): string[] {
29
+ private createSectionHeadings(
30
+ data: Dict<string>[],
31
+ sectionFields: components['schemas']['FieldDefinition'][],
32
+ ): string[] {
30
33
  return data
31
34
  .map(
32
35
  (rowData): SectionSortKey => ({
@@ -1,2 +1,2 @@
1
- var d=Object.create;var m=Object.defineProperty;var n=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty;var b=(a,e)=>{for(var r in e)m(a,r,{get:e[r],enumerable:!0})},i=(a,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of c(e))!y.call(a,t)&&t!==r&&m(a,t,{get:()=>e[t],enumerable:!(s=n(e,t))||s.enumerable});return a};var p=(a,e,r)=>(r=a!=null?d(f(a)):{},i(e||!a||!a.__esModule?m(r,"default",{value:a,enumerable:!0}):r,a)),T=a=>i(m({},"__esModule",{value:!0}),a);var A={};b(A,{SummaryDataTableBuilder:()=>u,default:()=>S});module.exports=T(A);var o=p(require("../DataTableBuilder/DataTableBuilder"));class u extends o.default{constructor(e,r){const s=e.fields.filter(l=>!r||!r.includes(l.name)).map(l=>l.name),t=e.fields.map(l=>({...l,calculated:!1,sortable:!1,defaultsort:!1,mandatory:!0,visible:!0}));super(t,!0),this.summary=e,this.columns=s}buildSummaryTable(){return super.buildTable(this.summary.data)}}var S=u;0&&(module.exports={SummaryDataTableBuilder});
1
+ var n=Object.create;var l=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,p=Object.prototype.hasOwnProperty;var y=(a,e)=>{for(var r in e)l(a,r,{get:e[r],enumerable:!0})},o=(a,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of d(e))!p.call(a,t)&&t!==r&&l(a,t,{get:()=>e[t],enumerable:!(s=c(e,t))||s.enumerable});return a};var b=(a,e,r)=>(r=a!=null?n(f(a)):{},o(e||!a||!a.__esModule?l(r,"default",{value:a,enumerable:!0}):r,a)),T=a=>o(l({},"__esModule",{value:!0}),a);var S={};y(S,{SummaryDataTableBuilder:()=>i,default:()=>D});module.exports=T(S);var u=b(require("../DataTableBuilder/DataTableBuilder"));class i extends u.default{constructor(e,r){const s=e.fields.filter(m=>!r||!r.includes(m.name)).map(m=>m.name),t=e.fields.map(m=>({...m,calculated:!1,sortable:!1,defaultsort:!1,mandatory:!0,visible:!0}));super(t,!0),this.summary=e,this.columns=s}buildSummaryTable(){return super.buildTable(this.summary.data)}}var D=i;0&&(module.exports={SummaryDataTableBuilder});
2
2
  //# sourceMappingURL=SummaryDataTableBuilder.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/dpr/utils/SummaryDataTableBuilder/SummaryDataTableBuilder.ts"],
4
- "sourcesContent": ["import { AsyncSummary } from '../../types/UserReports'\nimport DataTableBuilder from '../DataTableBuilder/DataTableBuilder'\nimport { DataTable } from '../DataTableBuilder/types'\n\nclass SummaryDataTableBuilder extends DataTableBuilder {\n private summary: AsyncSummary\n\n constructor(summary: AsyncSummary, sections?: Array<string>) {\n const columns = summary.fields\n .filter((field) => !sections || !sections.includes(field.name))\n .map((field) => field.name)\n\n const fields = summary.fields.map((field) => ({\n ...field,\n calculated: false,\n sortable: false,\n defaultsort: false,\n mandatory: true,\n visible: true,\n }))\n\n super(fields, true)\n\n this.summary = summary\n this.columns = columns\n }\n\n buildSummaryTable(): DataTable {\n return super.buildTable(this.summary.data)\n }\n}\n\nexport { SummaryDataTableBuilder }\nexport default SummaryDataTableBuilder\n"],
5
- "mappings": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,6BAAAE,EAAA,YAAAC,IAAA,eAAAC,EAAAJ,GACA,IAAAK,EAA6B,mDAG7B,MAAMH,UAAgC,EAAAI,OAAiB,CAGrD,YAAYC,EAAuBC,EAA0B,CAC3D,MAAMC,EAAUF,EAAQ,OACrB,OAAQG,GAAU,CAACF,GAAY,CAACA,EAAS,SAASE,EAAM,IAAI,CAAC,EAC7D,IAAKA,GAAUA,EAAM,IAAI,EAEtBC,EAASJ,EAAQ,OAAO,IAAKG,IAAW,CAC5C,GAAGA,EACH,WAAY,GACZ,SAAU,GACV,YAAa,GACb,UAAW,GACX,QAAS,EACX,EAAE,EAEF,MAAMC,EAAQ,EAAI,EAElB,KAAK,QAAUJ,EACf,KAAK,QAAUE,CACjB,CAEA,mBAA+B,CAC7B,OAAO,MAAM,WAAW,KAAK,QAAQ,IAAI,CAC3C,CACF,CAGA,IAAON,EAAQD",
4
+ "sourcesContent": ["import { components } from '../../types/api'\nimport { AsyncSummary } from '../../types/UserReports'\nimport DataTableBuilder from '../DataTableBuilder/DataTableBuilder'\nimport { DataTable } from '../DataTableBuilder/types'\n\nclass SummaryDataTableBuilder extends DataTableBuilder {\n private summary: AsyncSummary\n\n constructor(summary: AsyncSummary, sections?: Array<string>) {\n const columns = summary.fields\n .filter((field) => !sections || !sections.includes(field.name))\n .map((field) => field.name)\n\n const fields = summary.fields.map((field) => ({\n ...field,\n calculated: false,\n sortable: false,\n defaultsort: false,\n mandatory: true,\n visible: true,\n }))\n\n super(<components['schemas']['FieldDefinition'][]>fields, true)\n\n this.summary = summary\n this.columns = columns\n }\n\n buildSummaryTable(): DataTable {\n return super.buildTable(this.summary.data)\n }\n}\n\nexport { SummaryDataTableBuilder }\nexport default SummaryDataTableBuilder\n"],
5
+ "mappings": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,6BAAAE,EAAA,YAAAC,IAAA,eAAAC,EAAAJ,GAEA,IAAAK,EAA6B,mDAG7B,MAAMH,UAAgC,EAAAI,OAAiB,CAGrD,YAAYC,EAAuBC,EAA0B,CAC3D,MAAMC,EAAUF,EAAQ,OACrB,OAAQG,GAAU,CAACF,GAAY,CAACA,EAAS,SAASE,EAAM,IAAI,CAAC,EAC7D,IAAKA,GAAUA,EAAM,IAAI,EAEtBC,EAASJ,EAAQ,OAAO,IAAKG,IAAW,CAC5C,GAAGA,EACH,WAAY,GACZ,SAAU,GACV,YAAa,GACb,UAAW,GACX,QAAS,EACX,EAAE,EAEF,MAAkDC,EAAQ,EAAI,EAE9D,KAAK,QAAUJ,EACf,KAAK,QAAUE,CACjB,CAEA,mBAA+B,CAC7B,OAAO,MAAM,WAAW,KAAK,QAAQ,IAAI,CAC3C,CACF,CAGA,IAAON,EAAQD",
6
6
  "names": ["SummaryDataTableBuilder_exports", "__export", "SummaryDataTableBuilder", "SummaryDataTableBuilder_default", "__toCommonJS", "import_DataTableBuilder", "DataTableBuilder", "summary", "sections", "columns", "field", "fields"]
7
7
  }
@@ -1,3 +1,4 @@
1
+ import { components } from '../../types/api'
1
2
  import { AsyncSummary } from '../../types/UserReports'
2
3
  import DataTableBuilder from '../DataTableBuilder/DataTableBuilder'
3
4
  import { DataTable } from '../DataTableBuilder/types'
@@ -19,7 +20,7 @@ class SummaryDataTableBuilder extends DataTableBuilder {
19
20
  visible: true,
20
21
  }))
21
22
 
22
- super(fields, true)
23
+ super(<components['schemas']['FieldDefinition'][]>fields, true)
23
24
 
24
25
  this.summary = summary
25
26
  this.columns = columns
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/dpr/utils/UserStoreItemBuilder.ts"],
4
- "sourcesContent": ["import type { Request } from 'express'\nimport parseUrl from 'parseurl'\nimport {\n AsyncReportUrlData,\n LoadType,\n ReportType,\n RequestedReport,\n RequestFormData,\n RequestStatus,\n UserReportData,\n} from '../types/UserReports'\nimport Dict = NodeJS.Dict\nimport { ChildReportExecutionData, ExecutionData } from '../types/ExecutionData'\nimport { DashboardSection } from '../components/_dashboards/dashboard/types'\n\nclass UserStoreItemBuilder {\n userStoreItem: UserReportData\n\n requestFormData: RequestFormData | Record<string, never>\n\n constructor(\n reportData: {\n type: ReportType\n reportId: string\n reportName: string\n description: string\n id: string\n name: string\n },\n requestFormData?: RequestFormData,\n ) {\n this.requestFormData = requestFormData || {}\n this.userStoreItem = this.addReportData(reportData)\n }\n\n build = () => {\n return this.userStoreItem as RequestedReport\n }\n\n addReportData = ({\n type,\n reportId,\n reportName,\n description,\n id,\n name,\n }: {\n type: ReportType\n reportId: string\n reportName: string\n description: string\n id: string\n name: string\n }) => {\n return {\n type: type as ReportType,\n reportId,\n reportName,\n description,\n id,\n name,\n timestamp: {},\n }\n }\n\n addExecutionData = (executionData: ExecutionData) => {\n this.userStoreItem = {\n ...(<UserReportData>this.userStoreItem),\n ...executionData,\n }\n return this\n }\n\n addChildExecutionData = (childExecutionData: Array<ChildReportExecutionData>) => {\n this.userStoreItem = {\n ...(<UserReportData>this.userStoreItem),\n childExecutionData,\n }\n return this\n }\n\n addFilters = (filterData?: Record<string, string>) => {\n const filtersQueryString = new URLSearchParams(filterData).toString()\n this.userStoreItem = {\n ...this.userStoreItem,\n ...{\n filters: {\n data: filterData,\n queryString: filtersQueryString,\n },\n },\n }\n return this\n }\n\n addSortData = (sortData: Record<string, string>) => {\n const sortByQueryString = new URLSearchParams(sortData).toString()\n this.userStoreItem = {\n ...this.userStoreItem,\n ...{\n sortBy: {\n data: sortData,\n queryString: sortByQueryString,\n },\n },\n }\n return this\n }\n\n addRequestUrls = (req: Request) => {\n const { origin, pathname, search, href } = this.requestFormData\n const { executionId, dataProductDefinitionsPath, dpdPathFromQuery } = this.userStoreItem\n\n // Polling path\n let pollingPath = req.baseUrl.replace('/filters', `/${executionId}/status`)\n if (dpdPathFromQuery) {\n pollingPath = `${pollingPath}?dataProductDefinitionsPath=${dataProductDefinitionsPath}`\n }\n const pollingFullUrl = `${origin}${pollingPath}`\n this.userStoreItem = {\n ...this.userStoreItem,\n ...{\n url: {\n origin,\n request: {\n fullUrl: href,\n pathname,\n search,\n },\n polling: {\n fullUrl: pollingFullUrl,\n pathname: pollingPath,\n },\n },\n },\n }\n\n return this\n }\n\n addAsyncUrls = (url: AsyncReportUrlData) => {\n this.userStoreItem = {\n ...this.userStoreItem,\n ...{\n url,\n },\n }\n\n return this\n }\n\n addReportUrls = (req: Request) => {\n const origin = req.get('host')\n const fullUrl = `${req.protocol}://${req.get('host')}${req.originalUrl}`\n const urlData = parseUrl(req)\n\n this.userStoreItem = {\n ...this.userStoreItem,\n ...{\n url: {\n origin: origin || this.userStoreItem.url?.origin || '',\n ...(this.userStoreItem.url?.request && { request: this.userStoreItem.url.request }),\n ...(this.userStoreItem.url?.polling && { polling: this.userStoreItem.url.polling }),\n report: {\n ...(this.userStoreItem.url?.report && this.userStoreItem.url.report),\n fullUrl,\n ...(urlData && urlData.search && { search: urlData.search }),\n },\n },\n },\n }\n\n return this\n }\n\n addLoadType = (loadType: LoadType) => {\n this.userStoreItem = {\n ...this.userStoreItem,\n loadType,\n }\n\n return this\n }\n\n addQuery = (queryData?: { query: Dict<string | string[]>; querySummary: Array<Dict<string>> }) => {\n this.userStoreItem = {\n ...this.userStoreItem,\n ...(queryData && {\n query: {\n data: queryData.query,\n summary: queryData.querySummary,\n },\n }),\n }\n return this\n }\n\n addInteractiveQuery = (queryData?: { query: Dict<string>; querySummary: Array<Dict<string>> }) => {\n if (queryData) {\n this.userStoreItem = {\n ...this.userStoreItem,\n ...{\n interactiveQuery: {\n data: queryData.query,\n summary: queryData.querySummary,\n },\n },\n }\n }\n return this\n }\n\n addStatus = (status: RequestStatus) => {\n this.userStoreItem = {\n ...this.userStoreItem,\n status,\n }\n return this\n }\n\n addMetrics = (metrics: DashboardSection[]) => {\n this.userStoreItem = {\n ...this.userStoreItem,\n metrics: metrics.filter((metric) => metric.display).map((metric) => ({ name: metric.display || '' })),\n }\n return this\n }\n\n addTimestamp = () => {\n const { status } = this.userStoreItem\n const ts = new Date()\n switch (status) {\n case RequestStatus.FAILED:\n this.userStoreItem.timestamp.failed = ts\n break\n case RequestStatus.EXPIRED:\n this.userStoreItem.timestamp.expired = ts\n break\n case RequestStatus.ABORTED:\n this.userStoreItem.timestamp.aborted = ts\n break\n case RequestStatus.FINISHED:\n this.userStoreItem.timestamp.completed = ts\n break\n case RequestStatus.SUBMITTED:\n this.userStoreItem.timestamp.requested = ts\n break\n case RequestStatus.STARTED:\n case RequestStatus.PICKED:\n break\n default:\n this.userStoreItem.timestamp.lastViewed = ts\n break\n }\n return this\n }\n\n addDefinitionsPath = (definitionsPath: string, dpdPathFromQuery: boolean) => {\n if (definitionsPath) {\n this.userStoreItem = {\n ...this.userStoreItem,\n dataProductDefinitionsPath: definitionsPath,\n dpdPathFromQuery,\n }\n }\n return this\n }\n}\n\nexport { UserStoreItemBuilder }\nexport default UserStoreItemBuilder\n"],
4
+ "sourcesContent": ["import type { Request } from 'express'\nimport parseUrl from 'parseurl'\nimport {\n AsyncReportUrlData,\n LoadType,\n ReportType,\n RequestedReport,\n RequestFormData,\n RequestStatus,\n UserReportData,\n} from '../types/UserReports'\nimport Dict = NodeJS.Dict\nimport { ChildReportExecutionData, ExecutionData } from '../types/ExecutionData'\nimport { DashboardSection } from '../components/_dashboards/dashboard/types'\n\nclass UserStoreItemBuilder {\n userStoreItem: UserReportData\n\n requestFormData: RequestFormData | Record<string, never>\n\n constructor(\n reportData: {\n type: ReportType\n reportId: string\n reportName: string\n description: string\n id: string\n name: string\n },\n requestFormData?: RequestFormData,\n ) {\n this.requestFormData = requestFormData || {}\n this.userStoreItem = this.addReportData(reportData)\n }\n\n build = () => {\n return this.userStoreItem as RequestedReport\n }\n\n addReportData = ({\n type,\n reportId,\n reportName,\n description,\n id,\n name,\n }: {\n type: ReportType\n reportId: string\n reportName: string\n description: string\n id: string\n name: string\n }) => {\n return {\n type: type as ReportType,\n reportId,\n reportName,\n description,\n id,\n name,\n timestamp: {},\n }\n }\n\n addExecutionData = (executionData: ExecutionData) => {\n this.userStoreItem = {\n ...(<UserReportData>this.userStoreItem),\n ...executionData,\n }\n return this\n }\n\n addChildExecutionData = (childExecutionData: Array<ChildReportExecutionData>) => {\n this.userStoreItem = {\n ...(<UserReportData>this.userStoreItem),\n childExecutionData,\n }\n return this\n }\n\n addFilters = (filterData?: Record<string, string>) => {\n const filtersQueryString = new URLSearchParams(filterData).toString()\n this.userStoreItem = {\n ...this.userStoreItem,\n ...{\n filters: {\n data: filterData,\n queryString: filtersQueryString,\n },\n },\n }\n return this\n }\n\n addSortData = (sortData: Record<string, string>) => {\n const sortByQueryString = new URLSearchParams(sortData).toString()\n this.userStoreItem = {\n ...this.userStoreItem,\n ...{\n sortBy: {\n data: sortData,\n queryString: sortByQueryString,\n },\n },\n }\n return this\n }\n\n addRequestUrls = (req: Request) => {\n const { origin, pathname, search, href } = this.requestFormData\n const { executionId, dataProductDefinitionsPath, dpdPathFromQuery } = this.userStoreItem\n\n // Polling path\n let pollingPath = req.baseUrl.replace('/filters', `/${executionId}/status`)\n if (dpdPathFromQuery) {\n pollingPath = `${pollingPath}?dataProductDefinitionsPath=${dataProductDefinitionsPath}`\n }\n const pollingFullUrl = `${origin}${pollingPath}`\n this.userStoreItem = {\n ...this.userStoreItem,\n ...{\n url: {\n origin,\n request: {\n fullUrl: href,\n pathname,\n search,\n },\n polling: {\n fullUrl: pollingFullUrl,\n pathname: pollingPath,\n },\n },\n },\n }\n\n return this\n }\n\n addAsyncUrls = (url: AsyncReportUrlData) => {\n this.userStoreItem = {\n ...this.userStoreItem,\n ...{\n url,\n },\n }\n\n return this\n }\n\n addReportUrls = (req: Request) => {\n const origin = req.get('host')\n const fullUrl = `${req.protocol}://${req.get('host')}${req.originalUrl}`\n const urlData = parseUrl(req)\n\n this.userStoreItem = {\n ...this.userStoreItem,\n ...{\n url: {\n origin: origin || this.userStoreItem.url?.origin || '',\n ...(this.userStoreItem.url?.request && { request: this.userStoreItem.url.request }),\n ...(this.userStoreItem.url?.polling && { polling: this.userStoreItem.url.polling }),\n report: {\n ...(this.userStoreItem.url?.report && this.userStoreItem.url.report),\n fullUrl,\n ...(urlData && urlData.search && { search: urlData.search }),\n },\n },\n },\n }\n\n return this\n }\n\n addLoadType = (loadType: LoadType) => {\n this.userStoreItem = {\n ...this.userStoreItem,\n loadType,\n }\n\n return this\n }\n\n addQuery = (queryData?: { query: Dict<string | string[]>; querySummary: Array<Dict<string>> }) => {\n this.userStoreItem = {\n ...this.userStoreItem,\n ...(queryData && {\n query: {\n data: queryData.query,\n summary: queryData.querySummary,\n },\n }),\n }\n return this\n }\n\n addInteractiveQuery = (queryData?: { query: Dict<string | string[]>; querySummary: Array<Dict<string>> }) => {\n if (queryData) {\n this.userStoreItem = {\n ...this.userStoreItem,\n ...{\n interactiveQuery: {\n data: queryData.query,\n summary: queryData.querySummary,\n },\n },\n }\n }\n return this\n }\n\n addStatus = (status: RequestStatus) => {\n this.userStoreItem = {\n ...this.userStoreItem,\n status,\n }\n return this\n }\n\n addMetrics = (metrics: DashboardSection[]) => {\n this.userStoreItem = {\n ...this.userStoreItem,\n metrics: metrics.filter((metric) => metric.display).map((metric) => ({ name: metric.display || '' })),\n }\n return this\n }\n\n addTimestamp = () => {\n const { status } = this.userStoreItem\n const ts = new Date()\n switch (status) {\n case RequestStatus.FAILED:\n this.userStoreItem.timestamp.failed = ts\n break\n case RequestStatus.EXPIRED:\n this.userStoreItem.timestamp.expired = ts\n break\n case RequestStatus.ABORTED:\n this.userStoreItem.timestamp.aborted = ts\n break\n case RequestStatus.FINISHED:\n this.userStoreItem.timestamp.completed = ts\n break\n case RequestStatus.SUBMITTED:\n this.userStoreItem.timestamp.requested = ts\n break\n case RequestStatus.STARTED:\n case RequestStatus.PICKED:\n break\n default:\n this.userStoreItem.timestamp.lastViewed = ts\n break\n }\n return this\n }\n\n addDefinitionsPath = (definitionsPath: string, dpdPathFromQuery: boolean) => {\n if (definitionsPath) {\n this.userStoreItem = {\n ...this.userStoreItem,\n dataProductDefinitionsPath: definitionsPath,\n dpdPathFromQuery,\n }\n }\n return this\n }\n}\n\nexport { UserStoreItemBuilder }\nexport default UserStoreItemBuilder\n"],
5
5
  "mappings": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,0BAAAE,EAAA,YAAAC,IAAA,eAAAC,EAAAJ,GACA,IAAAK,EAAqB,uBACrBC,EAQO,gCAKP,MAAMJ,CAAqB,CAKzB,YACEK,EAQAC,EACA,CAKF,WAAQ,IACC,KAAK,cAGd,mBAAgB,CAAC,CACf,KAAAC,EACA,SAAAC,EACA,WAAAC,EACA,YAAAC,EACA,GAAAC,EACA,KAAAC,CACF,KAQS,CACL,KAAML,EACN,SAAAC,EACA,WAAAC,EACA,YAAAC,EACA,GAAAC,EACA,KAAAC,EACA,UAAW,CAAC,CACd,GAGF,sBAAoBC,IAClB,KAAK,cAAgB,CACnB,GAAoB,KAAK,cACzB,GAAGA,CACL,EACO,MAGT,2BAAyBC,IACvB,KAAK,cAAgB,CACnB,GAAoB,KAAK,cACzB,mBAAAA,CACF,EACO,MAGT,gBAAcC,GAAwC,CACpD,MAAMC,EAAqB,IAAI,gBAAgBD,CAAU,EAAE,SAAS,EAC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UAAU,WAAaA,EAC1C,KACJ,CACA,OAAO,IACT,EAEA,wBAAqB,CAACC,EAAyBb,KACzCa,IACF,KAAK,cAAgB,CACnB,GAAG,KAAK,cACR,2BAA4BA,EAC5B,iBAAAb,CACF,GAEK,MA1OP,KAAK,gBAAkBpB,GAAmB,CAAC,EAC3C,KAAK,cAAgB,KAAK,cAAcD,CAAU,CACpD,CA0OF,CAGA,IAAOJ,EAAQD",
6
6
  "names": ["UserStoreItemBuilder_exports", "__export", "UserStoreItemBuilder", "UserStoreItemBuilder_default", "__toCommonJS", "import_parseurl", "import_UserReports", "reportData", "requestFormData", "type", "reportId", "reportName", "description", "id", "name", "executionData", "childExecutionData", "filterData", "filtersQueryString", "sortData", "sortByQueryString", "req", "origin", "pathname", "search", "href", "executionId", "dataProductDefinitionsPath", "dpdPathFromQuery", "pollingPath", "pollingFullUrl", "url", "fullUrl", "urlData", "parseUrl", "loadType", "queryData", "status", "metrics", "metric", "ts", "definitionsPath"]
7
7
  }
@@ -195,7 +195,7 @@ class UserStoreItemBuilder {
195
195
  return this
196
196
  }
197
197
 
198
- addInteractiveQuery = (queryData?: { query: Dict<string>; querySummary: Array<Dict<string>> }) => {
198
+ addInteractiveQuery = (queryData?: { query: Dict<string | string[]>; querySummary: Array<Dict<string>> }) => {
199
199
  if (queryData) {
200
200
  this.userStoreItem = {
201
201
  ...this.userStoreItem,