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

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.
@@ -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 } 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,YAAYC,EAAuD,CACjE,KAAM,CAAE,OAAAC,EAAQ,SAAAC,EAAU,SAAAC,CAAS,EAAIH,EACvC,MAAMC,CAAM,EACZ,KAAK,SAAWC,EAChB,KAAK,SAAWC,CAClB,CASQ,sBACNC,EACAC,EACU,CACV,OAAOD,EACJ,IACEE,IAA6B,CAC5B,YAAa,KAAK,sBAAsBA,CAAO,EAC/C,QAAS,KAAK,WAAWA,EAASD,CAAa,CACjD,EACF,EACC,KAAK,KAAK,kBAAkB,C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B,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",
4
+ "sourcesContent": ["import Dict = NodeJS.Dict\nimport { components } from '../../types/api'\nimport { Cell, DataTable } from '../DataTableBuilder/types'\nimport type { SummaryTemplate, Template } from '../../types/Templates'\nimport DataTableBuilder from '../DataTableBuilder/DataTableBuilder'\nimport { distinct } from '../arrayUtils'\nimport SummaryDataTableBuilder from '../SummaryDataTableBuilder/SummaryDataTableBuilder'\nimport { SectionSortKey } from './types'\n\nclass SectionedDataTableBuilder extends DataTableBuilder {\n sections: Array<string>\n\n template: Template\n\n constructor(specification: components['schemas']['Specification']) {\n const { fields, sections, template } = specification\n super(fields)\n this.sections = sections\n this.template = template\n }\n\n /**\n * Creates the section heading strings\n *\n * @param {Dict<string>[]} data\n * @param {FieldDefinition[]} sectionFields\n * @return {*} {string[]} array of section headings\n */\n private createSectionHeadings(\n data: Dict<string>[],\n sectionFields: components['schemas']['FieldDefinition'][],\n ): string[] {\n return data\n .map(\n (rowData): SectionSortKey => ({\n description: this.mapSectionDescription(rowData),\n sortKey: this.getSortKey(rowData, sectionFields),\n }),\n )\n .sort(this.sortKeyComparison())\n .map((s) => s.description)\n .reduce(distinct, [])\n }\n\n /**\n * Initialise section heading arrays\n *\n * @private\n * @param {string[]} sectionDescriptions\n * @return {*}\n * @memberof SectionedDataTableBuilder\n */\n initSectionData(sectionDescriptions: string[]) {\n const sectionedData: Dict<Cell[][]> | Dict<Array<Dict<string>>> = {}\n sectionDescriptions.forEach((sectionDescription) => {\n sectionedData[sectionDescription] = []\n })\n return sectionedData\n }\n\n /**\n * Maps the rows to the correct section\n *\n * @private\n * @param {Array<Dict<string>>} data\n * @param {Dict<Cell[][]>} sectionedData\n * @return {*}\n * @memberof SectionedDataTableBuilder\n */\n private mapRowsToSection(data: Array<Dict<string>>, sectionedData: Dict<Cell[][]>) {\n return data.reduce((previousValue, rowData) => {\n const sectionDescription: string = this.mapSectionDescription(rowData)\n const mappedData = this.mapRow(rowData)\n const previousValueDescription = previousValue[sectionDescription]\n\n return {\n ...previousValue,\n ...(previousValueDescription && {\n [sectionDescription]: previousValueDescription.concat([mappedData]),\n }),\n }\n }, sectionedData)\n }\n\n /**\n * Maps the rows to the correct section\n *\n * @private\n * @param {Array<Dict<string>>} data\n * @param {Dict<Cell[][]>} sectionedData\n * @return {*}\n * @memberof SectionedDataTableBuilder\n */\n private mapDataToSection(data: Array<Dict<string>>, sectionedData: Dict<Array<Dict<string>>>) {\n return data.reduce((previousValue, rowData) => {\n const sectionDescription: string = this.mapSectionDescription(rowData)\n const previousValueDescription = previousValue[sectionDescription]\n const section = {\n ...previousValue,\n ...(previousValueDescription && {\n [sectionDescription]: previousValueDescription.concat([rowData]),\n }),\n }\n return section\n }, sectionedData)\n }\n\n /**\n * Gets the counts for rows in section\n *\n * @param {Dict<Cell[][]>} sectionedData\n * @param {string} sectionDescription\n * @return {*}\n * @memberof SectionedDataTableBuilder\n */\n getSectionCount(sectionedData: Dict<Cell[][]> | Dict<Dict<string>[]>, sectionDescription: string) {\n const count = sectionedData[sectionDescription] ? sectionedData[sectionDescription].length : 0\n const countDescription = `${count} result${count === 1 ? '' : 's'}`\n\n return {\n count,\n countDescription,\n }\n }\n\n /**\n * Creates the summaries and builds the table with summaries\n *\n * @private\n * @param {string} sectionDescription\n * @param {Cell[][]} mappedTableData\n * @param {Cell[]} header\n * @return {*}\n * @memberof SectionedDataTableBuilder\n */\n private mapSummariesAndCreateTable(sectionDescription: string, mappedTableData: Cell[][], header: Cell[]) {\n let tableContent: Cell[][] = []\n\n let mappedSectionHeaderSummary: Cell[][] = []\n let mappedHeaderSummary: Cell[][] = []\n let mappedFooterSummary: Cell[][] = []\n let mappedSectionFooterSummary: Cell[][] = []\n\n mappedSectionHeaderSummary = this.mapSectionSummaryTables(sectionDescription, 'section-header', this.columns.length)\n mappedHeaderSummary = this.mapSectionSummaryRows('table-header', sectionDescription)\n mappedFooterSummary = this.mapSectionSummaryRows('table-footer', sectionDescription)\n mappedSectionFooterSummary = this.mapSectionSummaryTables(sectionDescription, 'section-footer', this.columns.length)\n\n tableContent = mappedSectionHeaderSummary\n .concat(mappedTableData.length > 0 ? [header] : [])\n .concat(mappedHeaderSummary)\n .concat(mappedTableData)\n .concat(mappedFooterSummary)\n .concat(mappedSectionFooterSummary)\n\n return tableContent\n }\n\n /**\n * Creates the table data\n * - if summaries are present, includes the summaries data\n *\n * @private\n * @param {string[]} sectionDescriptions\n * @param {Dict<Cell[][]>} sectionedData\n * @param {Cell[]} header\n * @return {*}\n * @memberof SectionedDataTableBuilder\n */\n private createTableContent(sectionDescriptions: string[], sectionedData: Dict<Cell[][]>, header: Cell[]) {\n return sectionDescriptions.flatMap((sectionDescription, index) => {\n const { count, countDescription } = this.getSectionCount(sectionedData, sectionDescription)\n const mappedTableData = sectionedData[sectionDescription]\n\n let tableContent: Cell[][] = []\n if (mappedTableData) {\n if (Object.keys(this.reportSummaries).length) {\n tableContent = this.mapSummariesAndCreateTable(sectionDescription, mappedTableData, header)\n } else {\n tableContent = tableContent.concat(mappedTableData.length > 0 ? [header] : []).concat(mappedTableData)\n }\n }\n\n const sectionHeader = this.createSectionHeader(sectionDescription, index, count, countDescription)\n\n return [...sectionHeader, ...tableContent]\n })\n }\n\n createSectionHeader(sectionDescription: string, index: number, count?: number, countDescription?: string) {\n const header = []\n if (index !== 0) {\n header.push([\n {\n classes: 'dpr-section-header-spacer',\n colspan: this.columns.length,\n text: '',\n },\n ])\n }\n header.push([\n {\n classes: 'dpr-section-header',\n colspan: this.columns.length,\n html: `<h2 class=\"govuk-heading-m\">${sectionDescription}${\n count && count > 0 ? ` <span class='govuk-caption-m'>${countDescription}</span>` : ''\n }</h2>`,\n },\n ])\n header.push([\n {\n classes: 'dpr-section-header-spacer-bottom',\n colspan: this.columns.length,\n text: '',\n },\n ])\n return header\n }\n\n private mapSectionSummaryRows(template: SummaryTemplate, sectionDescription: string): Cell[][] {\n if (this.reportSummaries[template]) {\n return this.reportSummaries[template].flatMap((reportSummary) =>\n reportSummary.data\n .filter((rowData) => this.mapSectionDescription(rowData) === sectionDescription)\n .map((rowData) =>\n this.mapRow(\n rowData,\n `dpr-report-summary-cell dpr-report-summary-cell-${template}`,\n <components['schemas']['FieldDefinition'][]>reportSummary.fields,\n ),\n ),\n )\n }\n return []\n }\n\n private mapSectionSummaryTables(\n sectionDescription: string,\n summaryTemplate: SummaryTemplate,\n columnsLength: number,\n ): Cell[][] {\n const summaries = this.reportSummaries[summaryTemplate]\n if (summaries) {\n const htmlTables = summaries.map((summary) => {\n const data = summary.data.filter((row) => this.mapSectionDescription(row) === sectionDescription)\n\n if (data.length > 0) {\n const dataTable = new SummaryDataTableBuilder(summary, this.sections).buildTable(data)\n\n const htmlTable = this.convertDataTableToHtml(dataTable)\n\n return `<div class='dpr-summary-container'>${htmlTable}</div>`\n }\n return ''\n })\n\n const summaryContent = htmlTables.join('')\n if (summaryContent.length > 0) {\n return [\n [\n {\n classes: 'dpr-summary-cell',\n colspan: columnsLength,\n html: `<div class='dpr-summary-container-group dpr-summary-container-group-${summaryTemplate}'>${summaryContent}</div>`,\n },\n ],\n ]\n }\n }\n return []\n }\n\n mapSectionDescription(rowData: NodeJS.Dict<string>): string {\n const { sections } = this\n\n return this.mapNamesToFields(sections)\n .map((s) => `${s.display}: ${this.mapCellValue(s, rowData[s.name])}`)\n .join(', ')\n }\n\n mapSections(data: Array<Dict<string>>) {\n const sectionHeadings = this.initSectionedHeadings(data)\n let { sectionedData } = sectionHeadings\n\n // Maps data to sections\n if (this.template !== 'summary-section') {\n if (this.template === 'parent-child-section') {\n sectionedData = this.mapDataToSection(data, sectionedData as Dict<Dict<string>[]>)\n } else {\n sectionedData = this.mapRowsToSection(data, sectionedData as Dict<Cell[][]>)\n }\n }\n\n return {\n sectionDescriptions: sectionHeadings.sectionDescriptions,\n sectionedData,\n }\n }\n\n initSectionedHeadings(data: Array<Dict<string>>) {\n // Get the section definition data\n const sectionFields = this.mapNamesToFields(this.sections)\n // create the sectionHeadings\n const sectionDescriptions = this.createSectionHeadings(data, sectionFields)\n // init empty sections\n const sectionedData = this.initSectionData(sectionDescriptions)\n\n return {\n sectionDescriptions,\n sectionedData,\n }\n }\n\n /**\n * Creates the table rows.\n *\n * @private\n * @param {Array<Dict<string>>} data\n * @param {Cell[]} header\n * @return {*} {Cell[][]}\n * @memberof SectionedDataTableBuilder\n */\n private mapSectionedData(data: Array<Dict<string>>, header: Cell[]): Cell[][] {\n const { sectionDescriptions, sectionedData } = this.mapSections(data)\n // Create the table\n const tableContent = this.createTableContent(sectionDescriptions, sectionedData as Dict<Cell[][]>, header)\n\n return tableContent\n }\n\n 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,sBACNC,EACAC,EACU,CACV,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,CAACO,EAAeL,IAAY,CAC7C,MAAMI,EAA6B,KAAK,sBAAsBJ,CAAO,EAC/DM,EAAa,KAAK,OAAON,CAAO,EAChCO,EAA2BF,EAAcD,CAAkB,EAEjE,MAAO,CACL,GAAGC,EACH,GAAIE,GAA4B,CAC9B,CAACH,CAAkB,EAAGG,EAAyB,OAAO,CAACD,CAAU,CAAC,CACpE,CACF,CACF,EAAGH,CAAa,CAClB,CAWQ,iBAAiBL,EAA2BK,EAA0C,CAC5F,OAAOL,EAAK,OAAO,CAACO,EAAeL,IAAY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AM,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
  }
@@ -223,7 +223,11 @@ class SectionedDataTableBuilder extends DataTableBuilder {
223
223
  reportSummary.data
224
224
  .filter((rowData) => this.mapSectionDescription(rowData) === sectionDescription)
225
225
  .map((rowData) =>
226
- this.mapRow(rowData, `dpr-report-summary-cell dpr-report-summary-cell-${template}`, reportSummary.fields),
226
+ this.mapRow(
227
+ rowData,
228
+ `dpr-report-summary-cell dpr-report-summary-cell-${template}`,
229
+ <components['schemas']['FieldDefinition'][]>reportSummary.fields,
230
+ ),
227
231
  ),
228
232
  )
229
233
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ministryofjustice/hmpps-digital-prison-reporting-frontend",
3
3
  "description": "The Digital Prison Reporting Frontend contains templates and code to help display data effectively in UI applications.",
4
- "version": "4.15.2",
4
+ "version": "4.15.3",
5
5
  "main": "dpr/all.mjs",
6
6
  "sass": "dpr/all.scss",
7
7
  "engines": {