UNPKG

@ministryofjustice/hmpps-digital-prison-reporting-frontend

Version:

The Digital Prison Reporting Frontend contains templates and code to help display data effectively in UI applications.

3 lines (2 loc) 3.31 kB
var m=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var P=(s,t)=>{for(var n in t)m(s,n,{get:t[n],enumerable:!0})},A=(s,t,n,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of C(t))!b.call(s,o)&&o!==n&&m(s,o,{get:()=>t[o],enumerable:!(e=x(t,o))||e.enumerable});return s};var R=s=>A(m({},"__esModule",{value:!0}),s);var O={};P(O,{DEFAULT_FILTERS_PREFIX:()=>D,default:()=>f});module.exports=R(O);var u="~clear~";var g=(s,t)=>s.includes(t)?s:s.concat(t);var $=s=>s.filter(t=>t.mandatory).map(t=>t.name),j=s=>s.filter(t=>t.visible).map(t=>t.name),p=(s,t)=>[...$(s),...t].reduce(g,[]),h={getColumns:(s,t=null)=>{let{fields:n}=s;return{name:"columns",options:n.filter(o=>!s.sections||!s.sections.includes(o.name)).map(o=>({text:o.display,value:o.name,disabled:o.mandatory})),text:"Select report columns",value:p(n,t??j(n))}},ensureMandatoryColumns:p};var D="filters.",f=class{constructor({fields:t,template:n,queryParams:e,definitionsPath:o,filtersPrefix:S=D}){if(this.selectedPage=e.selectedPage?Number(e.selectedPage):1,this.pageSize=e.pageSize&&n?Number(e.pageSize):this.getDefaultPageSize(n),this.sortColumn=e.sortColumn?e.sortColumn.toString():this.getDefaultSortColumn(t),this.sortedAsc=e.sortedAsc!=="false",this.dataProductDefinitionsPath=o??(e.dataProductDefinitionsPath?e.dataProductDefinitionsPath.toString():null),this.filtersPrefix=S,e.columns){let i=typeof e.columns=="string"?e.columns.split(","):e.columns;this.columns=h.ensureMandatoryColumns(t,i)}else this.columns=t.filter(i=>i.visible).map(i=>i.name);let l,c,r=t.find(i=>i.type==="date"&&i.filter&&i.filter.type==="daterange"||i.type==="date"&&i.filter&&i.filter.type==="date");r&&({min:l,max:c}=r.filter),this.filters={},Object.keys(e).filter(i=>i.startsWith(this.filtersPrefix)).filter(i=>e[i]).forEach(i=>{let d=i.replace(this.filtersPrefix,""),a=e[i].toString();d.includes(".start")&&l&&new Date(a)<new Date(l)&&(a=l),d.includes(".end")&&c&&new Date(a)>new Date(c)&&(a=c),a!=="no-filter"&&(this.filters[d]=a)}),r&&r.filter.type==="daterange"&&(l&&Object.keys(e).some(i=>i.includes(this.filtersPrefix))&&Object.keys(e).every(i=>!i.includes(".start"))&&(this.filters[`${r.name}.start`]=l),c&&Object.keys(e).some(i=>i.includes(this.filtersPrefix))&&Object.keys(e).every(i=>!i.includes(".end"))&&(this.filters[`${r.name}.end`]=c)),r&&r.filter.type==="date"&&l&&Object.keys(e).some(i=>i.includes(this.filtersPrefix))&&Object.keys(e).every(i=>!i.includes(r.name))&&(this.filters[`${r.name}.start`]=l)}getDefaultSortColumn(t){let n=t.find(e=>e.defaultsort);return n?n.name:t.find(e=>e.sortable)?.name}toRecordWithFilterPrefix(t=!1){let n={selectedPage:this.selectedPage.toString(),pageSize:this.pageSize.toString(),sortColumn:this.sortColumn,sortedAsc:this.sortedAsc.toString(),columns:this.columns};return this.dataProductDefinitionsPath&&(n.dataProductDefinitionsPath=this.dataProductDefinitionsPath),Object.keys(this.filters).forEach(e=>{let o=this.filters[e];(!t||o!==u)&&(n[`${this.filtersPrefix}${e}`]=o)}),n}getDefaultPageSize(t){switch(t){case"list-section":case"summary-section":case"row-section-child":case"parent-child":return 5e4;default:return 20}}};0&&(module.exports={DEFAULT_FILTERS_PREFIX}); //# sourceMappingURL=ReportQuery.js.map