@ministryofjustice/hmpps-digital-prison-reporting-frontend 4.14.0 → 4.14.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.
@@ -1,2 +1,2 @@
1
- var b=Object.create;var a=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var z=Object.getPrototypeOf,C=Object.prototype.hasOwnProperty;var F=(n,i)=>{for(var s in i)a(n,s,{get:i[s],enumerable:!0})},h=(n,i,s,t)=>{if(i&&typeof i=="object"||typeof i=="function")for(let r of R(i))!C.call(n,r)&&r!==s&&a(n,r,{get:()=>i[r],enumerable:!(t=x(i,r))||t.enumerable});return n};var T=(n,i,s)=>(s=n!=null?b(z(n)):{},h(i||!n||!n.__esModule?a(s,"default",{value:n,enumerable:!0}):s,n)),A=n=>h(a({},"__esModule",{value:!0}),n);var j={};F(j,{DEFAULT_FILTERS_PREFIX:()=>S,ReportQuery:()=>g,default:()=>O});module.exports=A(j);var m=require("../utils/urlHelper"),p=T(require("../components/_reports/report-columns-form/utils")),u=require("./UserReports");const S="filters.";class g{constructor({fields:i,template:s,queryParams:t,definitionsPath:r,filtersPrefix:D=S,reportType:P}){if(this.selectedPage=t.selectedPage?Number(t.selectedPage):1,this.pageSize=this.getPageSize(t,s,P),this.sortColumn=t.sortColumn?t.sortColumn.toString():this.getDefaultSortColumn(i),this.sortedAsc=t.sortedAsc!=="false",this.dataProductDefinitionsPath=r??(t.dataProductDefinitionsPath?t.dataProductDefinitionsPath.toString():null),this.filtersPrefix=D,t.columns){const e=typeof t.columns=="string"?t.columns.split(","):t.columns;this.columns=p.default.ensureMandatoryColumns(i,e)}else this.columns=i.filter(e=>e.visible).map(e=>e.name);let l,c;const o=i.find(e=>e.type==="date"&&e.filter&&e.filter.type==="daterange"||e.type==="date"&&e.filter&&e.filter.type==="date");o&&({min:l,max:c}=o.filter),this.filters={},Object.keys(t).filter(e=>e.startsWith(this.filtersPrefix)).filter(e=>t[e]).forEach(e=>{const d=e.replace(this.filtersPrefix,"");let f=t[e].toString();d.includes(".start")&&l&&new Date(f)<new Date(l)&&(f=l),d.includes(".end")&&c&&new Date(f)>new Date(c)&&(f=c),f!=="no-filter"&&(this.filters[d]=f)}),o&&o.filter.type==="daterange"&&(l&&Object.keys(t).some(e=>e.includes(this.filtersPrefix))&&Object.keys(t).every(e=>!e.includes(".start"))&&(this.filters[`${o.name}.start`]=l),c&&Object.keys(t).some(e=>e.includes(this.filtersPrefix))&&Object.keys(t).every(e=>!e.includes(".end"))&&(this.filters[`${o.name}.end`]=c)),o&&o.filter.type==="date"&&l&&Object.keys(t).some(e=>e.includes(this.filtersPrefix))&&Object.keys(t).every(e=>!e.includes(o.name))&&(this.filters[`${o.name}.start`]=l)}getDefaultSortColumn(i){const s=i.find(t=>t.defaultsort);return s?s.name:i.find(t=>t.sortable)?.name}getPageSize(i,s,t){let r;return(!t||t===u.ReportType.REPORT)&&(r=i.pageSize&&s?Number(i.pageSize):this.getDefaultPageSize(s)),r}toRecordWithFilterPrefix(i=!1){const s={selectedPage:this.selectedPage.toString(),...this.pageSize&&{pageSize:this.pageSize.toString()},sortColumn:this.sortColumn,sortedAsc:this.sortedAsc.toString(),columns:this.columns};return this.dataProductDefinitionsPath&&(s.dataProductDefinitionsPath=this.dataProductDefinitionsPath),Object.keys(this.filters).forEach(t=>{const r=this.filters[t];(!i||r!==m.clearFilterValue)&&(s[`${this.filtersPrefix}${t}`]=r)}),s}getDefaultPageSize(i){switch(i){case"list-section":case"summary-section":case"row-section-child":case"parent-child":return 5e5;default:return 20}}}var O=g;0&&(module.exports={DEFAULT_FILTERS_PREFIX,ReportQuery});
1
+ var b=Object.create;var a=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var z=Object.getPrototypeOf,C=Object.prototype.hasOwnProperty;var F=(n,i)=>{for(var s in i)a(n,s,{get:i[s],enumerable:!0})},h=(n,i,s,t)=>{if(i&&typeof i=="object"||typeof i=="function")for(let r of R(i))!C.call(n,r)&&r!==s&&a(n,r,{get:()=>i[r],enumerable:!(t=x(i,r))||t.enumerable});return n};var T=(n,i,s)=>(s=n!=null?b(z(n)):{},h(i||!n||!n.__esModule?a(s,"default",{value:n,enumerable:!0}):s,n)),A=n=>h(a({},"__esModule",{value:!0}),n);var j={};F(j,{DEFAULT_FILTERS_PREFIX:()=>S,ReportQuery:()=>g,default:()=>O});module.exports=A(j);var m=require("../utils/urlHelper"),p=T(require("../components/_reports/report-columns-form/utils")),u=require("./UserReports");const S="filters.";class g{constructor({fields:i,template:s,queryParams:t,definitionsPath:r,filtersPrefix:D=S,reportType:P}){if(this.selectedPage=t.selectedPage?Number(t.selectedPage):1,this.pageSize=this.getPageSize(t,s,P),this.sortColumn=t.sortColumn?t.sortColumn.toString():this.getDefaultSortColumn(i),this.sortedAsc=t.sortedAsc!=="false",this.dataProductDefinitionsPath=r??(t.dataProductDefinitionsPath?t.dataProductDefinitionsPath.toString():null),this.filtersPrefix=D,t.columns){const e=typeof t.columns=="string"?t.columns.split(","):t.columns;this.columns=p.default.ensureMandatoryColumns(i,e)}else this.columns=i.filter(e=>e.visible).map(e=>e.name);let l,c;const o=i.find(e=>e.type==="date"&&e.filter&&e.filter.type==="daterange"||e.type==="date"&&e.filter&&e.filter.type==="date");o&&({min:l,max:c}=o.filter),this.filters={},Object.keys(t).filter(e=>e.startsWith(this.filtersPrefix)).filter(e=>t[e]).forEach(e=>{const d=e.replace(this.filtersPrefix,"");let f=t[e].toString();d.includes(".start")&&l&&new Date(f)<new Date(l)&&(f=l),d.includes(".end")&&c&&new Date(f)>new Date(c)&&(f=c),f!=="no-filter"&&(this.filters[d]=f)}),o&&o.filter.type==="daterange"&&(l&&Object.keys(t).some(e=>e.includes(this.filtersPrefix))&&Object.keys(t).every(e=>!e.includes(".start"))&&(this.filters[`${o.name}.start`]=l),c&&Object.keys(t).some(e=>e.includes(this.filtersPrefix))&&Object.keys(t).every(e=>!e.includes(".end"))&&(this.filters[`${o.name}.end`]=c)),o&&o.filter.type==="date"&&l&&Object.keys(t).some(e=>e.includes(this.filtersPrefix))&&Object.keys(t).every(e=>!e.includes(o.name))&&(this.filters[`${o.name}.start`]=l)}getDefaultSortColumn(i){const s=i.find(t=>t.defaultsort);return s?s.name:i.find(t=>t.sortable)?.name}getPageSize(i,s,t){let r;return(!t||t===u.ReportType.REPORT)&&(r=i.pageSize&&s?Number(i.pageSize):this.getDefaultPageSize(s)),r}toRecordWithFilterPrefix(i=!1){const s={selectedPage:this.selectedPage.toString(),...this.pageSize&&{pageSize:this.pageSize.toString()},sortColumn:this.sortColumn,sortedAsc:this.sortedAsc.toString(),columns:this.columns};return this.dataProductDefinitionsPath&&(s.dataProductDefinitionsPath=this.dataProductDefinitionsPath),Object.keys(this.filters).forEach(t=>{const r=this.filters[t];(!i||r!==m.clearFilterValue)&&(s[`${this.filtersPrefix}${t}`]=r)}),s}getDefaultPageSize(i){switch(i){case"list-section":case"summary-section":case"row-section-child":case"parent-child":case"parent-child-section":return 5e5;default:return 20}}}var O=g;0&&(module.exports={DEFAULT_FILTERS_PREFIX,ReportQuery});
2
2
  //# sourceMappingURL=ReportQuery.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/dpr/types/ReportQuery.ts"],
4
- "sourcesContent": ["import type { ParsedQs } from 'qs'\nimport { FilteredListRequest } from './index'\nimport Dict = NodeJS.Dict\nimport { components } from './api'\nimport { clearFilterValue } from '../utils/urlHelper'\nimport ColumnUtils from '../components/_reports/report-columns-form/utils'\nimport { Template } from './Templates'\nimport { ReportType } from './UserReports'\n\nexport const DEFAULT_FILTERS_PREFIX = 'filters.'\n\nclass ReportQuery implements FilteredListRequest {\n selectedPage: number\n\n pageSize: number | undefined\n\n sortColumn?: string\n\n columns: Array<string>\n\n sortedAsc: boolean\n\n filters: Dict<string>\n\n filtersPrefix: string\n\n dataProductDefinitionsPath?: string\n\n constructor({\n fields,\n template,\n queryParams,\n definitionsPath,\n filtersPrefix = DEFAULT_FILTERS_PREFIX,\n reportType,\n }: {\n fields: components['schemas']['FieldDefinition'][]\n template?: Template\n queryParams: ParsedQs\n definitionsPath?: string\n filtersPrefix?: string\n reportType?: ReportType\n }) {\n this.selectedPage = queryParams.selectedPage ? Number(queryParams.selectedPage) : 1\n this.pageSize = this.getPageSize(queryParams, template, reportType)\n this.sortColumn = queryParams.sortColumn ? queryParams.sortColumn.toString() : this.getDefaultSortColumn(fields)\n this.sortedAsc = queryParams.sortedAsc !== 'false'\n this.dataProductDefinitionsPath =\n definitionsPath ??\n (queryParams.dataProductDefinitionsPath ? queryParams.dataProductDefinitionsPath.toString() : null)\n this.filtersPrefix = filtersPrefix\n\n if (queryParams.columns) {\n const columns =\n typeof queryParams.columns === 'string' ? queryParams.columns.split(',') : (queryParams.columns as string[])\n this.columns = ColumnUtils.ensureMandatoryColumns(fields, columns)\n } else {\n this.columns = fields.filter((f) => f.visible).map((f) => f.name)\n }\n\n let min: string\n let max: string\n const dateField: components['schemas']['FieldDefinition'] = fields.find((f) => {\n return (\n (f.type === 'date' && f.filter && f.filter.type === 'daterange') ||\n (f.type === 'date' && f.filter && f.filter.type === 'date')\n )\n })\n if (dateField) ({ min, max } = dateField.filter)\n\n this.filters = {}\n\n Object.keys(queryParams)\n .filter((key) => key.startsWith(this.filtersPrefix))\n .filter((key) => queryParams[key])\n .forEach((key) => {\n const filter = key.replace(this.filtersPrefix, '')\n let value = queryParams[key].toString()\n if (filter.includes('.start') && min) {\n if (new Date(value) < new Date(min)) value = min\n }\n if (filter.includes('.end') && max) {\n if (new Date(value) > new Date(max)) value = max\n }\n if (value !== 'no-filter') {\n this.filters[filter] = value\n }\n })\n\n if (dateField && dateField.filter.type === 'daterange') {\n if (\n min &&\n Object.keys(queryParams).some((key) => key.includes(this.filtersPrefix)) &&\n Object.keys(queryParams).every((key) => !key.includes('.start'))\n ) {\n this.filters[`${dateField.name}.start`] = min\n }\n\n if (\n max &&\n Object.keys(queryParams).some((key) => key.includes(this.filtersPrefix)) &&\n Object.keys(queryParams).every((key) => !key.includes('.end'))\n ) {\n this.filters[`${dateField.name}.end`] = max\n }\n }\n\n if (dateField && dateField.filter.type === 'date') {\n if (\n min &&\n Object.keys(queryParams).some((key) => key.includes(this.filtersPrefix)) &&\n Object.keys(queryParams).every((key) => !key.includes(dateField.name))\n ) {\n this.filters[`${dateField.name}.start`] = min\n }\n }\n }\n\n private getDefaultSortColumn(fields: components['schemas']['FieldDefinition'][]) {\n const defaultSortColumn = fields.find((f) => f.defaultsort)\n return defaultSortColumn ? defaultSortColumn.name : fields.find((f) => f.sortable)?.name\n }\n\n getPageSize(queryParams: ParsedQs, template: Template, reportType?: ReportType): number | undefined {\n let pageSize\n if (!reportType || reportType === ReportType.REPORT) {\n pageSize = queryParams.pageSize && template ? Number(queryParams.pageSize) : this.getDefaultPageSize(template)\n }\n return pageSize\n }\n\n toRecordWithFilterPrefix(removeClearedFilters = false): Record<string, string | Array<string>> {\n const record: Record<string, string | Array<string>> = {\n selectedPage: this.selectedPage.toString(),\n ...(this.pageSize && { pageSize: this.pageSize.toString() }),\n sortColumn: this.sortColumn,\n sortedAsc: this.sortedAsc.toString(),\n columns: this.columns,\n }\n\n if (this.dataProductDefinitionsPath) {\n record.dataProductDefinitionsPath = this.dataProductDefinitionsPath\n }\n\n Object.keys(this.filters).forEach((filterName) => {\n const value = this.filters[filterName]\n if (!removeClearedFilters || value !== clearFilterValue) {\n record[`${this.filtersPrefix}${filterName}`] = value\n }\n })\n\n return record\n }\n\n private getDefaultPageSize(template: Template) {\n const maxResultsSize = 500000\n const standardPage = 20\n\n switch (template) {\n case 'list-section':\n case 'summary-section':\n case 'row-section-child':\n case 'parent-child':\n return maxResultsSize\n\n default:\n return standardPage\n }\n }\n}\n\nexport { ReportQuery }\nexport default ReportQuery\n"],
5
- "mappings": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,4BAAAE,EAAA,gBAAAC,EAAA,Y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EAA6C,CAClG,IAAIW,EACJ,OAAI,CAACX,GAAcA,IAAe,aAAW,UAC3CW,EAAWd,EAAY,UAAYD,EAAW,OAAOC,EAAY,QAAQ,EAAI,KAAK,mBAAmBD,CAAQ,GAExGe,CACT,CAEA,yBAAyBC,EAAuB,GAA+C,CAC7F,MAAMC,EAAiD,CACrD,aAAc,KAAK,aAAa,SAAS,EACzC,GAAI,KAAK,UAAY,CAAE,SAAU,KAAK,SAAS,SAAS,CAAE,EAC1D,WAAY,KAAK,WACjB,UAAW,KAAK,UAAU,SAAS,EACnC,QAAS,KAAK,OAChB,EAEA,OAAI,KAAK,6BACPA,EAAO,2BAA6B,KAAK,4BAG3C,OAAO,KAAK,KAAK,OAAO,EAAE,QAASC,GAAe,CAChD,MAAML,EAAQ,KAAK,QAAQK,CAAU,GACjC,CAACF,GAAwBH,IAAU,sBACrCI,EAAO,GAAG,KAAK,aAAa,GAAGC,CAAU,EAAE,EAAIL,EAEnD,CAAC,EAEMI,CACT,CAEQ,mBAAmBjB,EAAoB,CAI7C,OAAQA,EAAU,CAChB,IAAK,eACL,IAAK,kBACL,IAAK,oBACL,IAAK,eACH,MAAO,KAET,QACE,MAAO,GACX,CACF,CACF,CAGA,IAAON,EAAQD",
4
+ "sourcesContent": ["import type { ParsedQs } from 'qs'\nimport { FilteredListRequest } from './index'\nimport Dict = NodeJS.Dict\nimport { components } from './api'\nimport { clearFilterValue } from '../utils/urlHelper'\nimport ColumnUtils from '../components/_reports/report-columns-form/utils'\nimport { Template } from './Templates'\nimport { ReportType } from './UserReports'\n\nexport const DEFAULT_FILTERS_PREFIX = 'filters.'\n\nclass ReportQuery implements FilteredListRequest {\n selectedPage: number\n\n pageSize: number | undefined\n\n sortColumn?: string\n\n columns: Array<string>\n\n sortedAsc: boolean\n\n filters: Dict<string>\n\n filtersPrefix: string\n\n dataProductDefinitionsPath?: string\n\n constructor({\n fields,\n template,\n queryParams,\n definitionsPath,\n filtersPrefix = DEFAULT_FILTERS_PREFIX,\n reportType,\n }: {\n fields: components['schemas']['FieldDefinition'][]\n template?: Template\n queryParams: ParsedQs\n definitionsPath?: string\n filtersPrefix?: string\n reportType?: ReportType\n }) {\n this.selectedPage = queryParams.selectedPage ? Number(queryParams.selectedPage) : 1\n this.pageSize = this.getPageSize(queryParams, template, reportType)\n this.sortColumn = queryParams.sortColumn ? queryParams.sortColumn.toString() : this.getDefaultSortColumn(fields)\n this.sortedAsc = queryParams.sortedAsc !== 'false'\n this.dataProductDefinitionsPath =\n definitionsPath ??\n (queryParams.dataProductDefinitionsPath ? queryParams.dataProductDefinitionsPath.toString() : null)\n this.filtersPrefix = filtersPrefix\n\n if (queryParams.columns) {\n const columns =\n typeof queryParams.columns === 'string' ? queryParams.columns.split(',') : (queryParams.columns as string[])\n this.columns = ColumnUtils.ensureMandatoryColumns(fields, columns)\n } else {\n this.columns = fields.filter((f) => f.visible).map((f) => f.name)\n }\n\n let min: string\n let max: string\n const dateField: components['schemas']['FieldDefinition'] = fields.find((f) => {\n return (\n (f.type === 'date' && f.filter && f.filter.type === 'daterange') ||\n (f.type === 'date' && f.filter && f.filter.type === 'date')\n )\n })\n if (dateField) ({ min, max } = dateField.filter)\n\n this.filters = {}\n\n Object.keys(queryParams)\n .filter((key) => key.startsWith(this.filtersPrefix))\n .filter((key) => queryParams[key])\n .forEach((key) => {\n const filter = key.replace(this.filtersPrefix, '')\n let value = queryParams[key].toString()\n if (filter.includes('.start') && min) {\n if (new Date(value) < new Date(min)) value = min\n }\n if (filter.includes('.end') && max) {\n if (new Date(value) > new Date(max)) value = max\n }\n if (value !== 'no-filter') {\n this.filters[filter] = value\n }\n })\n\n if (dateField && dateField.filter.type === 'daterange') {\n if (\n min &&\n Object.keys(queryParams).some((key) => key.includes(this.filtersPrefix)) &&\n Object.keys(queryParams).every((key) => !key.includes('.start'))\n ) {\n this.filters[`${dateField.name}.start`] = min\n }\n\n if (\n max &&\n Object.keys(queryParams).some((key) => key.includes(this.filtersPrefix)) &&\n Object.keys(queryParams).every((key) => !key.includes('.end'))\n ) {\n this.filters[`${dateField.name}.end`] = max\n }\n }\n\n if (dateField && dateField.filter.type === 'date') {\n if (\n min &&\n Object.keys(queryParams).some((key) => key.includes(this.filtersPrefix)) &&\n Object.keys(queryParams).every((key) => !key.includes(dateField.name))\n ) {\n this.filters[`${dateField.name}.start`] = min\n }\n }\n }\n\n private getDefaultSortColumn(fields: components['schemas']['FieldDefinition'][]) {\n const defaultSortColumn = fields.find((f) => f.defaultsort)\n return defaultSortColumn ? defaultSortColumn.name : fields.find((f) => f.sortable)?.name\n }\n\n getPageSize(queryParams: ParsedQs, template: Template, reportType?: ReportType): number | undefined {\n let pageSize\n if (!reportType || reportType === ReportType.REPORT) {\n pageSize = queryParams.pageSize && template ? Number(queryParams.pageSize) : this.getDefaultPageSize(template)\n }\n return pageSize\n }\n\n toRecordWithFilterPrefix(removeClearedFilters = false): Record<string, string | Array<string>> {\n const record: Record<string, string | Array<string>> = {\n selectedPage: this.selectedPage.toString(),\n ...(this.pageSize && { pageSize: this.pageSize.toString() }),\n sortColumn: this.sortColumn,\n sortedAsc: this.sortedAsc.toString(),\n columns: this.columns,\n }\n\n if (this.dataProductDefinitionsPath) {\n record.dataProductDefinitionsPath = this.dataProductDefinitionsPath\n }\n\n Object.keys(this.filters).forEach((filterName) => {\n const value = this.filters[filterName]\n if (!removeClearedFilters || value !== clearFilterValue) {\n record[`${this.filtersPrefix}${filterName}`] = value\n }\n })\n\n return record\n }\n\n private getDefaultPageSize(template: Template) {\n const maxResultsSize = 500000\n const standardPage = 20\n\n switch (template) {\n case 'list-section':\n case 'summary-section':\n case 'row-section-child':\n case 'parent-child':\n case 'parent-child-section':\n return maxResultsSize\n\n default:\n return standardPage\n }\n }\n}\n\nexport { ReportQuery }\nexport default ReportQuery\n"],
5
+ "mappings": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,4BAAAE,EAAA,gBAAAC,EAAA,YAAAC,IAAA,eAAAC,EAAAL,GAIA,IAA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X,GAAcA,IAAe,aAAW,UAC3CW,EAAWd,EAAY,UAAYD,EAAW,OAAOC,EAAY,QAAQ,EAAI,KAAK,mBAAmBD,CAAQ,GAExGe,CACT,CAEA,yBAAyBC,EAAuB,GAA+C,CAC7F,MAAMC,EAAiD,CACrD,aAAc,KAAK,aAAa,SAAS,EACzC,GAAI,KAAK,UAAY,CAAE,SAAU,KAAK,SAAS,SAAS,CAAE,EAC1D,WAAY,KAAK,WACjB,UAAW,KAAK,UAAU,SAAS,EACnC,QAAS,KAAK,OAChB,EAEA,OAAI,KAAK,6BACPA,EAAO,2BAA6B,KAAK,4BAG3C,OAAO,KAAK,KAAK,OAAO,EAAE,QAASC,GAAe,CAChD,MAAML,EAAQ,KAAK,QAAQK,CAAU,GACjC,CAACF,GAAwBH,IAAU,sBACrCI,EAAO,GAAG,KAAK,aAAa,GAAGC,CAAU,EAAE,EAAIL,EAEnD,CAAC,EAEMI,CACT,CAEQ,mBAAmBjB,EAAoB,CAI7C,OAAQA,EAAU,CAChB,IAAK,eACL,IAAK,kBACL,IAAK,oBACL,IAAK,eACL,IAAK,uBACH,MAAO,KAET,QACE,MAAO,GACX,CACF,CACF,CAGA,IAAON,EAAQD",
6
6
  "names": ["ReportQuery_exports", "__export", "DEFAULT_FILTERS_PREFIX", "ReportQuery", "ReportQuery_default", "__toCommonJS", "import_urlHelper", "import_utils", "import_UserReports", "fields", "template", "queryParams", "definitionsPath", "filtersPrefix", "reportType", "columns", "ColumnUtils", "f", "min", "max", "dateField", "key", "filter", "value", "defaultSortColumn", "pageSize", "removeClearedFilters", "record", "filterName"]
7
7
  }
@@ -161,6 +161,7 @@ class ReportQuery implements FilteredListRequest {
161
161
  case 'summary-section':
162
162
  case 'row-section-child':
163
163
  case 'parent-child':
164
+ case 'parent-child-section':
164
165
  return maxResultsSize
165
166
 
166
167
  default:
@@ -1,2 +1,2 @@
1
- var N=Object.create;var m=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var A=Object.getPrototypeOf,R=Object.prototype.hasOwnProperty;var O=(l,c)=>{for(var t in c)m(l,t,{get:c[t],enumerable:!0})},C=(l,c,t,r)=>{if(c&&typeof c=="object"||typeof c=="function")for(let i of v(c))!R.call(l,i)&&i!==t&&m(l,i,{get:()=>c[i],enumerable:!(r=J(c,i))||r.enumerable});return l};var f=(l,c,t)=>(t=l!=null?N(A(l)):{},C(c||!l||!l.__esModule?m(t,"default",{value:l,enumerable:!0}):t,l)),w=l=>C(m({},"__esModule",{value:!0}),l);var B={};O(B,{ParentChildDataTableBuilder:()=>y,default:()=>F});module.exports=w(B);var P=f(require("../DataTableBuilder/DataTableBuilder")),b=require("../arrayUtils"),h=f(require("../logger")),T=f(require("../SectionedDataTableBuilder/SectionedDataTableBuilder"));class y extends T.default{constructor(t){const{specification:r}=t,{sections:i,template:e}=r;super(r);this.childData=[];this.sections=i,this.template=e,this.variant=t,this.childVariants=this.variant.childVariants||[]}createParentChildTable(t,r){let i={};const e=this.mapNamesToFields(this.childVariants.flatMap(a=>a.joinFields).reduce(b.distinct,[]));h.default.info("DPR-Parent-child-template-debugging",JSON.stringify({joinFields:e},null,2));const n=this.calculateParentChildKeys(t,e);h.default.info("DPR-Parent-child-template-debugging",JSON.stringify({parentChildKeys:n},null,2)),n.forEach(a=>{i[a.sortKey]={parent:[]}}),i=this.splitParentDataIntoSections(i,t,e),i=this.splitChildDataIntoSections(n,i),h.default.info("DPR-Parent-child-template-debugging",JSON.stringify({sectionedParentChildData:i},null,2));const o=this.createChildDataTableBuilders(),s=n.flatMap(a=>{const d=i[a.sortKey]||{};let g=[];return d&&(g=d.parent?d.parent:[]),[r].concat(g.map(p=>this.mapRow(p,"dpr-parent-cell"))).concat(this.childVariants.filter(p=>d&&d[p.id]).map(p=>{const D=o[p.id],u=d[p.id],S=D&&u?D.buildTable(u):void 0,K=S?this.convertDataTableToHtml(S):"";return[{classes:"dpr-child-report-cell",format:"string",html:`<div class='dpr-child-report'><h2 class="govuk-heading-s">${p.name}</h2><div class="dpr-child-report_table">${K}</div></div>`,colspan:this.columns.length}]}))});return h.default.info("DPR-Parent-child-template-debugging",JSON.stringify({parentChildTable:s},null,2)),s}createParentChildSectionRows(t,r){const i=this.mapSections(t);h.default.info("DPR-Parent-child-template-debugging",JSON.stringify({sectionsDetails:i},null,2));const e=i.sectionedData,n=[];Object.keys(e).forEach(s=>{h.default.info("DPR-Parent-child-template-debugging",JSON.stringify({sectionDescription:s},null,2));const a=e[s];h.default.info("DPR-Parent-child-template-debugging",JSON.stringify({data:a},null,2)),n.push({sectionDescription:s,...this.getSectionCount(e,s),rows:this.createParentChildTable(a,r)}),h.default.info("DPR-Parent-child-template-debugging",JSON.stringify({sectionedParentChildSectionedRows:n},null,2))});const o=n.flatMap((s,a)=>[...this.createSectionHeader(s.sectionDescription,a,s.count,s.countDescription),...s.rows]);return h.default.info("DPR-Parent-child-template-debugging",JSON.stringify({rows:o},null,2)),o}mapParentChildData(t,r){return this.sections?.length?this.createParentChildSectionRows(t,r):this.createParentChildTable(t,r)}createChildDataTableBuilders(){return this.childVariants.reduce((r,i)=>{const{specification:e}=i,n=e?e.fields:[],o=n.filter(a=>a.visible||a.mandatory).map(a=>a.name),s=new P.default(n).withNoHeaderOptions(o).withSortedData();return{...r,[i.id]:s}},{})}calculateParentChildKeys(t,r){return t.map(i=>({sortKey:this.getSortKey(i,r),childSortKeys:this.childVariants.reduce((e,n)=>({...e,[n.id]:this.getSortKey(i,this.mapNamesToFields(n.joinFields))}),{})})).reduce((i,e)=>i.find(n=>n.sortKey===e.sortKey)?i:i.concat(e),[])}splitParentDataIntoSections(t,r,i){return r.reduce((e,n)=>{const o=this.getSortKey(n,i),s=e[o]?e[o].parent:[];return{...e,...s&&{[o]:{parent:s.concat(n)}}}},t)}splitChildDataIntoSections(t,r){const i={...r};return this.childVariants.forEach(e=>{const n=this.mapNamesToFields(e.joinFields);h.default.info("DPR-Parent-child-template-debugging splitChildDataIntoSections",JSON.stringify({childFields:n,parentKeys:t}));const o=this.childData.find(a=>a.id===e.id);(o?o.data:[]).filter(a=>{const d=this.getSortKey(a,n);return t.find(g=>g.childSortKeys[e.id]===d)}).forEach(a=>{const d=this.getSortKey(a,n),g=t.find(u=>u.childSortKeys[e.id]===d),p=g?g.sortKey:"",D=i[p];if(D){const u=D[e.id]||[];D[e.id]=u.concat(a)}})}),i}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 F=y;0&&(module.exports={ParentChildDataTableBuilder});
1
+ var P=Object.create;var u=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var w=Object.getPrototypeOf,F=Object.prototype.hasOwnProperty;var N=(s,c)=>{for(var t in c)u(s,t,{get:c[t],enumerable:!0})},f=(s,c,t,r)=>{if(c&&typeof c=="object"||typeof c=="function")for(let e of A(c))!F.call(s,e)&&e!==t&&u(s,e,{get:()=>c[e],enumerable:!(r=v(c,e))||r.enumerable});return s};var S=(s,c,t)=>(t=s!=null?P(w(s)):{},f(c||!s||!s.__esModule?u(t,"default",{value:s,enumerable:!0}):t,s)),B=s=>f(u({},"__esModule",{value:!0}),s);var J={};N(J,{ParentChildDataTableBuilder:()=>C,default:()=>H});module.exports=B(J);var g=S(require("../DataTableBuilder/DataTableBuilder")),b=require("../arrayUtils"),T=S(require("../SectionedDataTableBuilder/SectionedDataTableBuilder"));class C extends T.default{constructor(t){const{specification:r}=t,{sections:e,template:i}=r;super(r);this.childData=[];this.sections=e,this.template=i,this.variant=t,this.childVariants=this.variant.childVariants||[]}createParentChildTable(t,r){let e={};const i=this.mapNamesToFields(this.childVariants.flatMap(a=>a.joinFields).reduce(b.distinct,[])),n=this.calculateParentChildKeys(t,i);n.forEach(a=>{e[a.sortKey]={parent:[]}}),e=this.splitParentDataIntoSections(e,t,i),e=this.splitChildDataIntoSections(n,e);const l=this.createChildDataTableBuilders();return n.flatMap(a=>{const d=e[a.sortKey]||{};let p=[];return d&&(p=d.parent?d.parent:[]),[r].concat(p.map(h=>this.mapRow(h,"dpr-parent-cell"))).concat(this.childVariants.filter(h=>d&&d[h.id]).map(h=>{const D=l[h.id],m=d[h.id],y=D&&m?D.buildTable(m):void 0,K=y?this.convertDataTableToHtml(y):"";return[{classes:"dpr-child-report-cell",format:"string",html:`<div class='dpr-child-report'><h2 class="govuk-heading-s">${h.name}</h2><div class="dpr-child-report_table">${K}</div></div>`,colspan:this.columns.length}]}))})}createParentChildSectionRows(t,r){const i=this.mapSections(t).sectionedData,n=[];return Object.keys(i).forEach(o=>{const a=i[o];n.push({sectionDescription:o,...this.getSectionCount(i,o),rows:this.createParentChildTable(a,r)})}),n.flatMap((o,a)=>[...this.createSectionHeader(o.sectionDescription,a,o.count,o.countDescription),...o.rows])}mapParentChildData(t,r){return this.sections?.length?this.createParentChildSectionRows(t,r):this.createParentChildTable(t,r)}createChildDataTableBuilders(){return this.childVariants.reduce((r,e)=>{const{specification:i}=e,n=i?i.fields:[],l=n.filter(a=>a.visible||a.mandatory).map(a=>a.name),o=new g.default(n).withNoHeaderOptions(l).withSortedData();return{...r,[e.id]:o}},{})}calculateParentChildKeys(t,r){return t.map(e=>({sortKey:this.getSortKey(e,r),childSortKeys:this.childVariants.reduce((i,n)=>({...i,[n.id]:this.getSortKey(e,this.mapNamesToFields(n.joinFields))}),{})})).reduce((e,i)=>e.find(n=>n.sortKey===i.sortKey)?e:e.concat(i),[])}splitParentDataIntoSections(t,r,e){return r.reduce((i,n)=>{const l=this.getSortKey(n,e),o=i[l]?i[l].parent:[];return{...i,...o&&{[l]:{parent:o.concat(n)}}}},t)}splitChildDataIntoSections(t,r){const e={...r};return this.childVariants.forEach(i=>{const n=this.mapNamesToFields(i.joinFields),l=this.childData.find(a=>a.id===i.id);(l?l.data:[]).filter(a=>{const d=this.getSortKey(a,n);return t.find(p=>p.childSortKeys[i.id]===d)}).forEach(a=>{const d=this.getSortKey(a,n),p=t.find(m=>m.childSortKeys[i.id]===d),h=p?p.sortKey:"",D=e[h];if(D){const m=D[i.id]||[];D[i.id]=m.concat(a)}})}),e}withChildData(t){return this.childData=t,this}buildTable(t){return{head:null,rows:this.mapParentChildData(t,this.mapHeader(!0,"govuk-table__header")),rowCount:t.length,colCount:this.columns.length}}}var H=C;0&&(module.exports={ParentChildDataTableBuilder});
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,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,EAC7G,EAAAC,QAAO,KAAK,sCAAuC,KAAK,UAAU,CAAE,WAAAF,CAAW,EAAG,KAAM,CAAC,CAAC,EAI1F,MAAMG,EAAkB,KAAK,yBAAyBN,EAAYG,CAAU,EAC5E,EAAAE,QAAO,KAAK,sCAAuC,KAAK,UAAU,CAAE,gBAAAC,CAAgB,EAAG,KAAM,CAAC,CAAC,EAC/FA,EAAgB,QAASC,GAAc,CACrCL,EAAyBK,EAAU,OAAO,EAAI,CAC5C,OAAQ,CAAC,CACX,CACF,CAAC,EAEDL,EAA2B,KAAK,4BAA4BA,EAA0BF,EAAYG,CAAU,EAC5GD,EAA2B,KAAK,2BAA2BI,EAAiBJ,CAAwB,EAEpG,EAAAG,QAAO,KAAK,sCAAuC,KAAK,UA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A,QAASD,GAAY,CACpB,MAAMC,EAAU,KAAK,WAAWD,EAASM,CAAW,EAC9CI,EAASN,EAAW,KAAMK,GAAMA,EAAE,cAAc3B,EAAa,EAAE,IAAMmB,CAAO,EAC5EU,EAAgBD,EAASA,EAAO,QAAU,GAC1CE,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,EAEMK,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", "p", "parent", "parentSortKey", "parentSection", "existingChildData", "childData"]
4
+ "sourcesContent": ["import Dict = NodeJS.Dict\nimport { components } from '../../types/api'\nimport { Cell, DataTable, FieldDefinition } from '../DataTableBuilder/types'\nimport DataTableBuilder from '../DataTableBuilder/DataTableBuilder'\nimport { distinct } from '../arrayUtils'\nimport { ChildData, ParentChildSortKey } from './types'\nimport SectionedDataTableBuilder from '../SectionedDataTableBuilder/SectionedDataTableBuilder'\n\nclass ParentChildDataTableBuilder extends SectionedDataTableBuilder {\n variant: components['schemas']['VariantDefinition']\n\n childVariants: components['schemas']['ChildVariantDefinition'][]\n\n childData: Array<ChildData> = []\n\n constructor(variant: components['schemas']['VariantDefinition']) {\n const { specification } = variant\n const { sections, template } = <components['schemas']['Specification']>specification\n super(<components['schemas']['Specification']>specification)\n\n this.sections = sections\n this.template = template\n this.variant = variant\n this.childVariants = this.variant.childVariants || []\n }\n\n private createParentChildTable(parentData: Array<Dict<string>>, header: Cell[]) {\n let sectionedParentChildData: Dict<Dict<Array<Dict<string>>>> = {}\n const joinFields = this.mapNamesToFields(this.childVariants.flatMap((c) => c.joinFields).reduce(distinct, []))\n // Get the parent-child joins definition data\n\n // Create the section keys and\n const parentChildKeys = this.calculateParentChildKeys(parentData, joinFields)\n parentChildKeys.forEach((parentKey) => {\n sectionedParentChildData[parentKey.sortKey] = {\n parent: [],\n }\n })\n\n sectionedParentChildData = this.splitParentDataIntoSections(sectionedParentChildData, parentData, joinFields)\n sectionedParentChildData = this.splitChildDataIntoSections(parentChildKeys, sectionedParentChildData)\n\n const childDataTableBuilders = this.createChildDataTableBuilders()\n\n const parentChildTable = parentChildKeys.flatMap((key) => {\n const sectionData = sectionedParentChildData[key.sortKey] || {}\n\n let parentSectionData: Dict<string>[] = []\n if (sectionData) {\n parentSectionData = sectionData.parent ? sectionData.parent : []\n }\n\n return [header].concat(parentSectionData.map((r) => this.mapRow(r, 'dpr-parent-cell'))).concat(\n this.childVariants\n .filter((childVariant) => sectionData && sectionData[childVariant.id])\n .map((childVariant) => {\n const builder = childDataTableBuilders[childVariant.id]\n const section = sectionData[childVariant.id]\n const dataTable = builder && section ? builder.buildTable(section) : undefined\n const dataTableHtml = dataTable ? this.convertDataTableToHtml(dataTable) : ''\n\n return [\n {\n classes: 'dpr-child-report-cell',\n format: 'string',\n html: `<div class='dpr-child-report'><h2 class=\"govuk-heading-s\">${childVariant.name}</h2><div class=\"dpr-child-report_table\">${dataTableHtml}</div></div>`,\n colspan: this.columns.length,\n },\n ]\n }),\n )\n })\n\n return parentChildTable\n }\n\n private createParentChildSectionRows(parentData: Array<Dict<string>>, header: Cell[]) {\n const sectionsDetails = this.mapSections(parentData)\n const sectionedData = sectionsDetails.sectionedData as Dict<Array<Dict<string>>>\n const sectionedParentChildSectionedRows: {\n sectionDescription: string\n rows: Cell[][]\n count: number\n countDescription: string\n }[] = []\n\n Object.keys(sectionedData).forEach((sectionDescription) => {\n const data = sectionedData[sectionDescription] as Array<Dict<string>>\n\n sectionedParentChildSectionedRows.push({\n sectionDescription,\n ...this.getSectionCount(sectionedData, sectionDescription),\n rows: this.createParentChildTable(data, header),\n })\n })\n\n const rows = sectionedParentChildSectionedRows.flatMap((section, index) => {\n const sectionHeader = this.createSectionHeader(\n section.sectionDescription,\n index,\n section.count,\n section.countDescription,\n )\n return [...sectionHeader, ...section.rows]\n })\n\n return rows\n }\n\n private mapParentChildData(parentData: Array<Dict<string>>, header: Cell[]): Cell[][] {\n if (this.sections?.length) {\n return this.createParentChildSectionRows(parentData, header)\n }\n return this.createParentChildTable(parentData, header)\n }\n\n private createChildDataTableBuilders() {\n const childDataTables: Dict<DataTableBuilder> = this.childVariants.reduce((previousValue, childVariant) => {\n const { specification } = childVariant\n const fields = specification ? specification.fields : []\n const fieldNamesToDisplay = fields.filter((f) => f.visible || f.mandatory).map((f) => f.name)\n\n const dataTableBuilder = new DataTableBuilder(fields).withNoHeaderOptions(fieldNamesToDisplay).withSortedData()\n\n return {\n ...previousValue,\n [childVariant.id]: dataTableBuilder,\n }\n }, {})\n return childDataTables\n }\n\n private calculateParentChildKeys(parentData: Array<NodeJS.Dict<string>>, joinFields: FieldDefinition[]) {\n return parentData\n .map(\n (rowData): ParentChildSortKey => ({\n sortKey: this.getSortKey(rowData, joinFields),\n childSortKeys: this.childVariants.reduce((previousValue, childVariant) => {\n return {\n ...previousValue,\n [childVariant.id]: this.getSortKey(rowData, this.mapNamesToFields(childVariant.joinFields)),\n }\n }, {}),\n }),\n )\n .reduce((previousValue: ParentChildSortKey[], sortKey: ParentChildSortKey) => {\n if (previousValue.find((v) => v.sortKey === sortKey.sortKey)) {\n return previousValue\n }\n return previousValue.concat(sortKey)\n }, [])\n }\n\n private splitParentDataIntoSections(\n sectionedParentChildData: NodeJS.Dict<NodeJS.Dict<Array<NodeJS.Dict<string>>>>,\n parentData: Array<NodeJS.Dict<string>>,\n joinFields: FieldDefinition[],\n ) {\n return parentData.reduce((previousValue, rowData) => {\n const parentKey: string = this.getSortKey(rowData, joinFields)\n const previousParentValue = previousValue[parentKey] ? previousValue[parentKey].parent : []\n\n return {\n ...previousValue,\n ...(previousParentValue && {\n [parentKey]: {\n parent: previousParentValue.concat(rowData),\n },\n }),\n }\n }, sectionedParentChildData)\n }\n\n private splitChildDataIntoSections(\n parentKeys: ParentChildSortKey[],\n sectionedParentChildData: Dict<Dict<Array<Dict<string>>>>,\n ): Dict<Dict<Array<Dict<string>>>> {\n const sectionedParentChildDataWithChildren = { ...sectionedParentChildData }\n\n this.childVariants.forEach((childVariant) => {\n const childFields = this.mapNamesToFields(childVariant.joinFields)\n const matchingChildData = this.childData.find((d) => d.id === childVariant.id)\n const data = matchingChildData ? matchingChildData.data : []\n\n data\n .filter((rowData) => {\n const sortKey = this.getSortKey(rowData, childFields)\n return parentKeys.find((p) => p.childSortKeys[childVariant.id] === sortKey)\n })\n .forEach((rowData) => {\n const sortKey = this.getSortKey(rowData, childFields)\n const parent = parentKeys.find((p) => p.childSortKeys[childVariant.id] === sortKey)\n const parentSortKey = parent ? parent.sortKey : ''\n const parentSection = sectionedParentChildDataWithChildren[parentSortKey]\n if (parentSection) {\n const existingChildData = parentSection[childVariant.id] || []\n parentSection[childVariant.id] = existingChildData.concat(rowData)\n }\n })\n })\n\n return sectionedParentChildDataWithChildren\n }\n\n withChildData(childData: Array<ChildData>) {\n this.childData = childData\n return this\n }\n\n buildTable(data: Array<Dict<string>>): DataTable {\n return {\n head: null,\n rows: this.mapParentChildData(data, this.mapHeader(true, 'govuk-table__header')),\n rowCount: data.length,\n colCount: this.columns.length,\n }\n }\n}\n\nexport { ParentChildDataTableBuilder }\nexport default ParentChildDataTableBuilder\n"],
5
+ "mappings": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iCAAAE,EAAA,YAAAC,IAAA,eAAAC,EAAAJ,GAGA,IAAAK,EAA6B,mDAC7BC,EAAyB,yBAEzBC,EAAsC,qEAEtC,MAAML,UAAoC,EAAAM,OAA0B,CAOlE,YAAYC,EAAqD,CAC/D,KAAM,CAAE,cAAAC,CAAc,EAAID,EACpB,CAAE,SAAAE,EAAU,SAAAC,CAAS,EAA4CF,EACvE,MAA8CA,CAAa,EAL7D,eAA8B,CAAC,EAO7B,KAAK,SAAWC,EAChB,KAAK,SAAWC,EAChB,KAAK,QAAUH,EACf,KAAK,cAAgB,KAAK,QAAQ,eAAiB,CAAC,CACtD,CAEQ,uBAAuBI,EAAiCC,EAAgB,CAC9E,IAAIC,EAA4D,CAAC,EACjE,MAAMC,EAAa,KAAK,iBAAiB,KAAK,cAAc,QAASC,GAAMA,EAAE,UAAU,EAAE,OAAO,WAAU,CAAC,CAAC,CAAC,EAIvGC,EAAkB,KAAK,yBAAyBL,EAAYG,CAAU,EAC5EE,EAAgB,QAASC,GAAc,CACrCJ,EAAyBI,EAAU,OAAO,EAAI,CAC5C,OAAQ,CAAC,CACX,CACF,CAAC,EAEDJ,EAA2B,KAAK,4BAA4BA,EAA0BF,EAAYG,CAAU,EAC5GD,EAA2B,KAAK,2BAA2BG,EAAiBH,CAAwB,EAEpG,MAAMK,EAAyB,KAAK,6BAA6B,EA+BjE,OA7ByBF,EAAgB,QAASG,GAAQ,CACxD,MAAMC,EA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EACiC,CACjC,MAAM+B,EAAuC,CAAE,GAAG/B,CAAyB,EAE3E,YAAK,cAAc,QAASU,GAAiB,CAC3C,MAAMsB,EAAc,KAAK,iBAAiBtB,EAAa,UAAU,EAC3DuB,EAAoB,KAAK,UAAU,KAAMC,GAAMA,EAAE,KAAOxB,EAAa,EAAE,GAChEuB,EAAoBA,EAAkB,KAAO,CAAC,GAGxD,OAAQP,GAAY,CACnB,MAAMC,EAAU,KAAK,WAAWD,EAASM,CAAW,EACpD,OAAOF,EAAW,KAAM,GAAM,EAAE,cAAcpB,EAAa,EAAE,IAAMiB,CAAO,CAC5E,CAAC,EACA,QAASD,GAAY,CACpB,MAAMC,EAAU,KAAK,WAAWD,EAASM,CAAW,EAC9CG,EAASL,EAAW,KAAMM,GAAMA,EAAE,cAAc1B,EAAa,EAAE,IAAMiB,CAAO,EAC5EU,EAAgBF,EAASA,EAAO,QAAU,GAC1CG,EAAgBP,EAAqCM,CAAa,EACxE,GAAIC,EAAe,CACjB,MAAMC,EAAoBD,EAAc5B,EAAa,EAAE,GAAK,CAAC,EAC7D4B,EAAc5B,EAAa,EAAE,EAAI6B,EAAkB,OAAOb,CAAO,CACnE,CACF,CAAC,CACL,CAAC,EAEMK,CACT,CAEA,cAAcS,EAA6B,CACzC,YAAK,UAAYA,EACV,IACT,CAEA,WAAWtB,EAAsC,CAC/C,MAAO,CACL,KAAM,KACN,KAAM,KAAK,mBAAmBA,EAAM,KAAK,UAAU,GAAM,qBAAqB,CAAC,EAC/E,SAAUA,EAAK,OACf,SAAU,KAAK,QAAQ,MACzB,CACF,CACF,CAGA,IAAO9B,EAAQD",
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
  }
@@ -4,7 +4,6 @@ import { Cell, DataTable, FieldDefinition } from '../DataTableBuilder/types'
4
4
  import DataTableBuilder from '../DataTableBuilder/DataTableBuilder'
5
5
  import { distinct } from '../arrayUtils'
6
6
  import { ChildData, ParentChildSortKey } from './types'
7
- import logger from '../logger'
8
7
  import SectionedDataTableBuilder from '../SectionedDataTableBuilder/SectionedDataTableBuilder'
9
8
 
10
9
  class ParentChildDataTableBuilder extends SectionedDataTableBuilder {
@@ -28,12 +27,10 @@ class ParentChildDataTableBuilder extends SectionedDataTableBuilder {
28
27
  private createParentChildTable(parentData: Array<Dict<string>>, header: Cell[]) {
29
28
  let sectionedParentChildData: Dict<Dict<Array<Dict<string>>>> = {}
30
29
  const joinFields = this.mapNamesToFields(this.childVariants.flatMap((c) => c.joinFields).reduce(distinct, []))
31
- logger.info(`DPR-Parent-child-template-debugging`, JSON.stringify({ joinFields }, null, 2))
32
30
  // Get the parent-child joins definition data
33
31
 
34
32
  // Create the section keys and
35
33
  const parentChildKeys = this.calculateParentChildKeys(parentData, joinFields)
36
- logger.info(`DPR-Parent-child-template-debugging`, JSON.stringify({ parentChildKeys }, null, 2))
37
34
  parentChildKeys.forEach((parentKey) => {
38
35
  sectionedParentChildData[parentKey.sortKey] = {
39
36
  parent: [],
@@ -43,8 +40,6 @@ class ParentChildDataTableBuilder extends SectionedDataTableBuilder {
43
40
  sectionedParentChildData = this.splitParentDataIntoSections(sectionedParentChildData, parentData, joinFields)
44
41
  sectionedParentChildData = this.splitChildDataIntoSections(parentChildKeys, sectionedParentChildData)
45
42
 
46
- logger.info(`DPR-Parent-child-template-debugging`, JSON.stringify({ sectionedParentChildData }, null, 2))
47
-
48
43
  const childDataTableBuilders = this.createChildDataTableBuilders()
49
44
 
50
45
  const parentChildTable = parentChildKeys.flatMap((key) => {
@@ -76,14 +71,11 @@ class ParentChildDataTableBuilder extends SectionedDataTableBuilder {
76
71
  )
77
72
  })
78
73
 
79
- logger.info(`DPR-Parent-child-template-debugging`, JSON.stringify({ parentChildTable }, null, 2))
80
-
81
74
  return parentChildTable
82
75
  }
83
76
 
84
77
  private createParentChildSectionRows(parentData: Array<Dict<string>>, header: Cell[]) {
85
78
  const sectionsDetails = this.mapSections(parentData)
86
- logger.info(`DPR-Parent-child-template-debugging`, JSON.stringify({ sectionsDetails }, null, 2))
87
79
  const sectionedData = sectionsDetails.sectionedData as Dict<Array<Dict<string>>>
88
80
  const sectionedParentChildSectionedRows: {
89
81
  sectionDescription: string
@@ -93,16 +85,13 @@ class ParentChildDataTableBuilder extends SectionedDataTableBuilder {
93
85
  }[] = []
94
86
 
95
87
  Object.keys(sectionedData).forEach((sectionDescription) => {
96
- logger.info(`DPR-Parent-child-template-debugging`, JSON.stringify({ sectionDescription }, null, 2))
97
88
  const data = sectionedData[sectionDescription] as Array<Dict<string>>
98
- logger.info(`DPR-Parent-child-template-debugging`, JSON.stringify({ data }, null, 2))
99
89
 
100
90
  sectionedParentChildSectionedRows.push({
101
91
  sectionDescription,
102
92
  ...this.getSectionCount(sectionedData, sectionDescription),
103
93
  rows: this.createParentChildTable(data, header),
104
94
  })
105
- logger.info(`DPR-Parent-child-template-debugging`, JSON.stringify({ sectionedParentChildSectionedRows }, null, 2))
106
95
  })
107
96
 
108
97
  const rows = sectionedParentChildSectionedRows.flatMap((section, index) => {
@@ -114,7 +103,6 @@ class ParentChildDataTableBuilder extends SectionedDataTableBuilder {
114
103
  )
115
104
  return [...sectionHeader, ...section.rows]
116
105
  })
117
- logger.info(`DPR-Parent-child-template-debugging`, JSON.stringify({ rows }, null, 2))
118
106
 
119
107
  return rows
120
108
  }
@@ -191,14 +179,6 @@ class ParentChildDataTableBuilder extends SectionedDataTableBuilder {
191
179
 
192
180
  this.childVariants.forEach((childVariant) => {
193
181
  const childFields = this.mapNamesToFields(childVariant.joinFields)
194
- logger.info(
195
- 'DPR-Parent-child-template-debugging splitChildDataIntoSections',
196
- JSON.stringify({
197
- childFields,
198
- parentKeys,
199
- }),
200
- )
201
-
202
182
  const matchingChildData = this.childData.find((d) => d.id === childVariant.id)
203
183
  const data = matchingChildData ? matchingChildData.data : []
204
184
 
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.0",
4
+ "version": "4.14.2",
5
5
  "main": "dpr/all.mjs",
6
6
  "sass": "dpr/all.scss",
7
7
  "engines": {