@ministryofjustice/hmpps-digital-prison-reporting-frontend 4.15.1 → 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.
- package/dpr/utils/ParentChildDataTableBuilder/ParentChildDataTableBuilder.js +1 -1
- package/dpr/utils/ParentChildDataTableBuilder/ParentChildDataTableBuilder.js.map +2 -2
- package/dpr/utils/ParentChildDataTableBuilder/ParentChildDataTableBuilder.ts +6 -3
- package/dpr/utils/SectionedDataTableBuilder/SectionedDataTableBuilder.js.map +2 -2
- package/dpr/utils/SectionedDataTableBuilder/SectionedDataTableBuilder.ts +5 -2
- package/dpr/utils/SummaryDataTableBuilder/SummaryDataTableBuilder.js +1 -1
- package/dpr/utils/SummaryDataTableBuilder/SummaryDataTableBuilder.js.map +2 -2
- package/dpr/utils/SummaryDataTableBuilder/SummaryDataTableBuilder.ts +2 -1
- package/package.json +1 -1
|
@@ -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,
|
|
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
|
|
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,Q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AgB,CAEpF,MAAMgB,EADkB,KAAK,YAAYjB,CAAU,EACb,cAChCkB,EAKA,CAAC,EAEP,cAAO,KAAKD,CAAa,EAAE,QAASE,GAAuB,CACzD,MAAMC,EAAOH,EAAcE,CAAkB,EAE7CD,EAAkC,KAAK,CACrC,mBAAAC,EACA,GAAG,KAAK,gBAAgBF,EAAeE,CAAkB,EACzD,KAAM,KAAK,uBAAuBC,EAAMnB,CAAM,CAChD,CAAC,CACH,CAAC,EAEYiB,EAAkC,QAAQ,CAACJ,EAASO,IAOxD,CAAC,GANc,KAAK,oBACzBP,EAAQ,mBACRO,EACAP,EAAQ,MACRA,EAAQ,gBACV,EAC0B,GAAGA,EAAQ,IAAI,CAC1C,CAGH,CAEQ,mBAAmBd,EAAiCC,EAA0B,CACpF,OAAI,KAAK,UAAU,OACV,KAAK,6BAA6BD,EAAYC,CAAM,EAEtD,KAAK,uBAAuBD,EAAYC,CAAM,CACvD,CAEQ,8BAA+B,CAarC,OAZgD,KAAK,cAAc,OAAO,CAACqB,EAAeV,IAAiB,CACzG,KAAM,CAAE,cAAAf,CAAc,EAAIe,EACpBW,EAAS1B,EAAgBA,EAAc,OAAS,CAAC,EACjD2B,EAAsBD,EAAO,OAAQE,GAAMA,EAAE,SAAWA,EAAE,SAAS,EAAE,IAAKA,GAAMA,EAAE,IAAI,EAEtFC,EAAmB,IAAI,EAAAC,QAAiBJ,CAAM,EAAE,oBAAoBC,CAAmB,EAAE,eAAe,EAE9G,MAAO,CACL,GAAGF,EACH,CAACV,EAAa,EAAE,EAAGc,CACrB,CACF,EAAG,CAAC,CAAC,CAEP,CAEQ,
|
|
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,EAE9D,IAAIE,EAAoC,CAAC,EACzC,OAAID,IACFC,EAAoBD,EAAY,OAASA,EAAY,OAAS,CAA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AAU,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
|
|
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(
|
|
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,
|
|
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,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,CAC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E,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
|
|
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(
|
|
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
|
|
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,
|
|
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
|
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.
|
|
4
|
+
"version": "4.15.2",
|
|
5
5
|
"main": "dpr/all.mjs",
|
|
6
6
|
"sass": "dpr/all.scss",
|
|
7
7
|
"engines": {
|