@ministryofjustice/hmpps-digital-prison-reporting-frontend 4.14.0 → 4.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var K=Object.create;var f=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var O=Object.getPrototypeOf,v=Object.prototype.hasOwnProperty;var A=(o,d)=>{for(var i in d)f(o,i,{get:d[i],enumerable:!0})},P=(o,d,i,r)=>{if(d&&typeof d=="object"||typeof d=="function")for(let t of R(d))!v.call(o,t)&&t!==i&&f(o,t,{get:()=>d[t],enumerable:!(r=J(d,t))||r.enumerable});return o};var m=(o,d,i)=>(i=o!=null?K(O(o)):{},P(d||!o||!o.__esModule?f(i,"default",{value:o,enumerable:!0}):i,o)),F=o=>P(f({},"__esModule",{value:!0}),o);var B={};A(B,{ParentChildDataTableBuilder:()=>y,default:()=>w});module.exports=F(B);var b=m(require("../DataTableBuilder/DataTableBuilder")),C=require("../arrayUtils"),l=m(require("../logger")),N=m(require("../SectionedDataTableBuilder/SectionedDataTableBuilder"));class y extends N.default{constructor(i){const{specification:r}=i,{sections:t,template:e}=r;super(r);this.childData=[];this.sections=t,this.template=e,this.variant=i,this.childVariants=this.variant.childVariants||[]}createParentChildTable(i,r){let t={};const e=this.mapNamesToFields(this.childVariants.flatMap(n=>n.joinFields).reduce(C.distinct,[]));l.default.info("DPR-Parent-child-template-debugging",JSON.stringify({joinFields:e},null,2));const a=this.calculateParentChildKeys(i,e);l.default.info("DPR-Parent-child-template-debugging",JSON.stringify({parentChildKeys:a},null,2)),a.forEach(n=>{t[n.sortKey]={parent:[]}}),t=this.splitParentDataIntoSections(t,i,e),t=this.splitChildDataIntoSections(a,t),l.default.info("DPR-Parent-child-template-debugging",JSON.stringify({sectionedParentChildData:t},null,2));const c=this.createChildDataTableBuilders(),s=a.flatMap(n=>{const h=t[n.sortKey]||{};let p=[];return h&&(p=h.parent?h.parent:[]),[r].concat(p.map(g=>this.mapRow(g,"dpr-parent-cell"))).concat(this.childVariants.filter(g=>h&&h[g.id]).map(g=>{const u=c[g.id],D=h[g.id],S=u&&D?u.buildTable(D):void 0,T=S?this.convertDataTableToHtml(S):"";return[{classes:"dpr-child-report-cell",format:"string",html:`<div class='dpr-child-report'><h2 class="govuk-heading-s">${g.name}</h2><div class="dpr-child-report_table">${T}</div></div>`,colspan:this.columns.length}]}))});return l.default.info("DPR-Parent-child-template-debugging",JSON.stringify({parentChildTable:s},null,2)),s}createParentChildSectionRows(i,r){const t=this.mapSections(i);l.default.info("DPR-Parent-child-template-debugging",JSON.stringify({sectionsDetails:t},null,2));const e=t.sectionedData,a=[];Object.keys(e).forEach(s=>{l.default.info("DPR-Parent-child-template-debugging",JSON.stringify({sectionDescription:s},null,2));const n=e[s];l.default.info("DPR-Parent-child-template-debugging",JSON.stringify({data:n},null,2)),a.push({sectionDescription:s,...this.getSectionCount(e,s),rows:this.createParentChildTable(n,r)}),l.default.info("DPR-Parent-child-template-debugging",JSON.stringify({sectionedParentChildSectionedRows:a},null,2))});const c=a.flatMap((s,n)=>[...this.createSectionHeader(s.sectionDescription,n,s.count,s.countDescription),...s.rows]);return l.default.info("DPR-Parent-child-template-debugging",JSON.stringify({rows:c},null,2)),c}mapParentChildData(i,r){return this.sections?.length?this.createParentChildSectionRows(i,r):this.createParentChildTable(i,r)}createChildDataTableBuilders(){return this.childVariants.reduce((r,t)=>{const{specification:e}=t,a=e?e.fields:[],c=a.filter(n=>n.visible||n.mandatory).map(n=>n.name),s=new b.default(a).withNoHeaderOptions(c).withSortedData();return{...r,[t.id]:s}},{})}calculateParentChildKeys(i,r){return i.map(t=>({sortKey:this.getSortKey(t,r),childSortKeys:this.childVariants.reduce((e,a)=>({...e,[a.id]:this.getSortKey(t,this.mapNamesToFields(a.joinFields))}),{})})).reduce((t,e)=>t.find(a=>a.sortKey===e.sortKey)?t:t.concat(e),[])}splitParentDataIntoSections(i,r,t){return r.reduce((e,a)=>{const c=this.getSortKey(a,t),s=e[c]?e[c].parent:[];return{...e,...s&&{[c]:{parent:s.concat(a)}}}},i)}splitChildDataIntoSections(i,r){const t={...r};return l.default.info("DPR-Parent-child-template-debugging",JSON.stringify({childData:this.childData},null,2)),this.childVariants.forEach(e=>{const a=this.mapNamesToFields(e.joinFields);l.default.info("DPR-Parent-child-template-debugging splitChildDataIntoSections",JSON.stringify({childFields:a,parentKeys:i},null,2));const c=this.childData.find(n=>(l.default.info("DPR-Parent-child-template-debugging",JSON.stringify({childDataId:n.id,childVariantId:e.id},null,2)),n.id===e.id)),s=c?c.data:[];l.default.info("DPR-Parent-child-template-debugging",JSON.stringify({matchingChildData:c,data:s},null,2)),s.filter(n=>{const h=this.getSortKey(n,a);return i.find(p=>p.childSortKeys[e.id]===h)}).forEach(n=>{l.default.info("DPR-Parent-child-template-debugging",JSON.stringify({rowData:n},null,2));const h=this.getSortKey(n,a),p=i.find(D=>D.childSortKeys[e.id]===h),g=p?p.sortKey:"",u=t[g];if(u){const D=u[e.id]||[];u[e.id]=D.concat(n)}})}),l.default.info("DPR-Parent-child-template-debugging",JSON.stringify({sectionedParentChildDataWithChildren:t},null,2)),t}withChildData(i){return this.childData=i,this}buildTable(i){return{head:null,rows:this.mapParentChildData(i,this.mapHeader(!0,"govuk-table__header")),rowCount:i.length,colCount:this.columns.length}}}var w=y;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 logger from '../logger'\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 logger.info(`DPR-Parent-child-template-debugging`, JSON.stringify({ joinFields }, null, 2))\n // Get the parent-child joins definition data\n\n // Create the section keys and\n const parentChildKeys = this.calculateParentChildKeys(parentData, joinFields)\n logger.info(`DPR-Parent-child-template-debugging`, JSON.stringify({ parentChildKeys }, null, 2))\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 logger.info(`DPR-Parent-child-template-debugging`, JSON.stringify({ sectionedParentChildData }, null, 2))\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 logger.info(`DPR-Parent-child-template-debugging`, JSON.stringify({ parentChildTable }, null, 2))\n\n return parentChildTable\n }\n\n private createParentChildSectionRows(parentData: Array<Dict<string>>, header: Cell[]) {\n const sectionsDetails = this.mapSections(parentData)\n logger.info(`DPR-Parent-child-template-debugging`, JSON.stringify({ sectionsDetails }, null, 2))\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 logger.info(`DPR-Parent-child-template-debugging`, JSON.stringify({ sectionDescription }, null, 2))\n const data = sectionedData[sectionDescription] as Array<Dict<string>>\n logger.info(`DPR-Parent-child-template-debugging`, JSON.stringify({ data }, null, 2))\n\n sectionedParentChildSectionedRows.push({\n sectionDescription,\n ...this.getSectionCount(sectionedData, sectionDescription),\n rows: this.createParentChildTable(data, header),\n })\n logger.info(`DPR-Parent-child-template-debugging`, JSON.stringify({ sectionedParentChildSectionedRows }, null, 2))\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 logger.info(`DPR-Parent-child-template-debugging`, JSON.stringify({ rows }, null, 2))\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 logger.info(\n 'DPR-Parent-child-template-debugging splitChildDataIntoSections',\n JSON.stringify({\n childFields,\n parentKeys,\n }),\n )\n\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,EAAmB,wBACnBC,EAAsC,qEAEtC,MAAMN,UAAoC,EAAAO,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,EA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U,EACvDgC,EAAsBT,EAAcnB,CAAS,EAAImB,EAAcnB,CAAS,EAAE,OAAS,CAAC,EAE1F,MAAO,CACL,GAAGmB,EACH,GAAIS,GAAuB,CACzB,CAAC5B,CAAS,EAAG,CACX,OAAQ4B,EAAoB,OAAOH,CAAO,CAC5C,CACF,CACF,CACF,EAAG9B,CAAwB,CAC7B,CAEQ,2BACNkC,EACAlC,EACiC,CACjC,MAAMmC,EAAuC,CAAE,GAAGnC,CAAyB,EAE3E,
|
|
6
|
-
"names": ["ParentChildDataTableBuilder_exports", "__export", "ParentChildDataTableBuilder", "ParentChildDataTableBuilder_default", "__toCommonJS", "import_DataTableBuilder", "import_arrayUtils", "import_logger", "import_SectionedDataTableBuilder", "SectionedDataTableBuilder", "variant", "specification", "sections", "template", "parentData", "header", "sectionedParentChildData", "joinFields", "c", "logger", "parentChildKeys", "parentKey", "childDataTableBuilders", "parentChildTable", "key", "sectionData", "parentSectionData", "r", "childVariant", "builder", "section", "dataTable", "dataTableHtml", "sectionsDetails", "sectionedData", "sectionedParentChildSectionedRows", "sectionDescription", "data", "rows", "index", "previousValue", "fields", "fieldNamesToDisplay", "f", "dataTableBuilder", "DataTableBuilder", "rowData", "sortKey", "v", "previousParentValue", "parentKeys", "sectionedParentChildDataWithChildren", "childFields", "matchingChildData", "d", "
|
|
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 logger from '../logger'\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 logger.info(`DPR-Parent-child-template-debugging`, JSON.stringify({ joinFields }, null, 2))\n // Get the parent-child joins definition data\n\n // Create the section keys and\n const parentChildKeys = this.calculateParentChildKeys(parentData, joinFields)\n logger.info(`DPR-Parent-child-template-debugging`, JSON.stringify({ parentChildKeys }, null, 2))\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 logger.info(`DPR-Parent-child-template-debugging`, JSON.stringify({ sectionedParentChildData }, null, 2))\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 logger.info(`DPR-Parent-child-template-debugging`, JSON.stringify({ parentChildTable }, null, 2))\n\n return parentChildTable\n }\n\n private createParentChildSectionRows(parentData: Array<Dict<string>>, header: Cell[]) {\n const sectionsDetails = this.mapSections(parentData)\n logger.info(`DPR-Parent-child-template-debugging`, JSON.stringify({ sectionsDetails }, null, 2))\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 logger.info(`DPR-Parent-child-template-debugging`, JSON.stringify({ sectionDescription }, null, 2))\n const data = sectionedData[sectionDescription] as Array<Dict<string>>\n logger.info(`DPR-Parent-child-template-debugging`, JSON.stringify({ data }, null, 2))\n\n sectionedParentChildSectionedRows.push({\n sectionDescription,\n ...this.getSectionCount(sectionedData, sectionDescription),\n rows: this.createParentChildTable(data, header),\n })\n logger.info(`DPR-Parent-child-template-debugging`, JSON.stringify({ sectionedParentChildSectionedRows }, null, 2))\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 logger.info(`DPR-Parent-child-template-debugging`, JSON.stringify({ rows }, null, 2))\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 logger.info('DPR-Parent-child-template-debugging', JSON.stringify({ childData: this.childData }, null, 2))\n\n this.childVariants.forEach((childVariant) => {\n const childFields = this.mapNamesToFields(childVariant.joinFields)\n logger.info(\n 'DPR-Parent-child-template-debugging splitChildDataIntoSections',\n JSON.stringify(\n {\n childFields,\n parentKeys,\n },\n null,\n 2,\n ),\n )\n\n const matchingChildData = this.childData.find((d) => {\n logger.info(\n 'DPR-Parent-child-template-debugging',\n JSON.stringify({ childDataId: d.id, childVariantId: childVariant.id }, null, 2),\n )\n return d.id === childVariant.id\n })\n const data = matchingChildData ? matchingChildData.data : []\n\n logger.info('DPR-Parent-child-template-debugging', JSON.stringify({ matchingChildData, data }, null, 2))\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 logger.info('DPR-Parent-child-template-debugging', JSON.stringify({ rowData }, null, 2))\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 logger.info(\n 'DPR-Parent-child-template-debugging',\n JSON.stringify({ sectionedParentChildDataWithChildren }, null, 2),\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,EAAmB,wBACnBC,EAAsC,qEAEtC,MAAMN,UAAoC,EAAAO,OAA0B,CAOlE,YAAYC,EAAqD,CAC/D,KAAM,CAAE,cAAAC,CAAc,EAAID,EACpB,CAAE,SAAAE,EAAU,SAAAC,CAAS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CAAC,CAAC,EACvF,MAAMC,EAAU,KAAK,WAAWD,EAASM,CAAW,EAC9CG,EAASL,EAAW,KAAMM,GAAMA,EAAE,cAAc5B,EAAa,EAAE,IAAMmB,CAAO,EAC5EU,EAAgBF,EAASA,EAAO,QAAU,GAC1CG,EAAgBP,EAAqCM,CAAa,EACxE,GAAIC,EAAe,CACjB,MAAMC,EAAoBD,EAAc9B,EAAa,EAAE,GAAK,CAAC,EAC7D8B,EAAc9B,EAAa,EAAE,EAAI+B,EAAkB,OAAOb,CAAO,CACnE,CACF,CAAC,CACL,CAAC,EAED,EAAA3B,QAAO,KACL,sCACA,KAAK,UAAU,CAAE,qCAAAgC,CAAqC,EAAG,KAAM,CAAC,CAClE,EAEOA,CACT,CAEA,cAAcS,EAA6B,CACzC,YAAK,UAAYA,EACV,IACT,CAEA,WAAWvB,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,IAAOlC,EAAQD",
|
|
6
|
+
"names": ["ParentChildDataTableBuilder_exports", "__export", "ParentChildDataTableBuilder", "ParentChildDataTableBuilder_default", "__toCommonJS", "import_DataTableBuilder", "import_arrayUtils", "import_logger", "import_SectionedDataTableBuilder", "SectionedDataTableBuilder", "variant", "specification", "sections", "template", "parentData", "header", "sectionedParentChildData", "joinFields", "c", "logger", "parentChildKeys", "parentKey", "childDataTableBuilders", "parentChildTable", "key", "sectionData", "parentSectionData", "r", "childVariant", "builder", "section", "dataTable", "dataTableHtml", "sectionsDetails", "sectionedData", "sectionedParentChildSectionedRows", "sectionDescription", "data", "rows", "index", "previousValue", "fields", "fieldNamesToDisplay", "f", "dataTableBuilder", "DataTableBuilder", "rowData", "sortKey", "v", "previousParentValue", "parentKeys", "sectionedParentChildDataWithChildren", "childFields", "matchingChildData", "d", "parent", "p", "parentSortKey", "parentSection", "existingChildData", "childData"]
|
|
7
7
|
}
|
|
@@ -189,25 +189,40 @@ class ParentChildDataTableBuilder extends SectionedDataTableBuilder {
|
|
|
189
189
|
): Dict<Dict<Array<Dict<string>>>> {
|
|
190
190
|
const sectionedParentChildDataWithChildren = { ...sectionedParentChildData }
|
|
191
191
|
|
|
192
|
+
logger.info('DPR-Parent-child-template-debugging', JSON.stringify({ childData: this.childData }, null, 2))
|
|
193
|
+
|
|
192
194
|
this.childVariants.forEach((childVariant) => {
|
|
193
195
|
const childFields = this.mapNamesToFields(childVariant.joinFields)
|
|
194
196
|
logger.info(
|
|
195
197
|
'DPR-Parent-child-template-debugging splitChildDataIntoSections',
|
|
196
|
-
JSON.stringify(
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
198
|
+
JSON.stringify(
|
|
199
|
+
{
|
|
200
|
+
childFields,
|
|
201
|
+
parentKeys,
|
|
202
|
+
},
|
|
203
|
+
null,
|
|
204
|
+
2,
|
|
205
|
+
),
|
|
200
206
|
)
|
|
201
207
|
|
|
202
|
-
const matchingChildData = this.childData.find((d) =>
|
|
208
|
+
const matchingChildData = this.childData.find((d) => {
|
|
209
|
+
logger.info(
|
|
210
|
+
'DPR-Parent-child-template-debugging',
|
|
211
|
+
JSON.stringify({ childDataId: d.id, childVariantId: childVariant.id }, null, 2),
|
|
212
|
+
)
|
|
213
|
+
return d.id === childVariant.id
|
|
214
|
+
})
|
|
203
215
|
const data = matchingChildData ? matchingChildData.data : []
|
|
204
216
|
|
|
217
|
+
logger.info('DPR-Parent-child-template-debugging', JSON.stringify({ matchingChildData, data }, null, 2))
|
|
218
|
+
|
|
205
219
|
data
|
|
206
220
|
.filter((rowData) => {
|
|
207
221
|
const sortKey = this.getSortKey(rowData, childFields)
|
|
208
222
|
return parentKeys.find((p) => p.childSortKeys[childVariant.id] === sortKey)
|
|
209
223
|
})
|
|
210
224
|
.forEach((rowData) => {
|
|
225
|
+
logger.info('DPR-Parent-child-template-debugging', JSON.stringify({ rowData }, null, 2))
|
|
211
226
|
const sortKey = this.getSortKey(rowData, childFields)
|
|
212
227
|
const parent = parentKeys.find((p) => p.childSortKeys[childVariant.id] === sortKey)
|
|
213
228
|
const parentSortKey = parent ? parent.sortKey : ''
|
|
@@ -219,6 +234,11 @@ class ParentChildDataTableBuilder extends SectionedDataTableBuilder {
|
|
|
219
234
|
})
|
|
220
235
|
})
|
|
221
236
|
|
|
237
|
+
logger.info(
|
|
238
|
+
'DPR-Parent-child-template-debugging',
|
|
239
|
+
JSON.stringify({ sectionedParentChildDataWithChildren }, null, 2),
|
|
240
|
+
)
|
|
241
|
+
|
|
222
242
|
return sectionedParentChildDataWithChildren
|
|
223
243
|
}
|
|
224
244
|
|
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.14.
|
|
4
|
+
"version": "4.14.1",
|
|
5
5
|
"main": "dpr/all.mjs",
|
|
6
6
|
"sass": "dpr/all.scss",
|
|
7
7
|
"engines": {
|