@ministryofjustice/hmpps-digital-prison-reporting-frontend 4.17.0 → 4.17.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.
Files changed (168) hide show
  1. package/dpr/components/_catalogue/catalogue-list/utils.js +1 -1
  2. package/dpr/components/_catalogue/catalogue-list/utils.js.map +3 -3
  3. package/dpr/components/_catalogue/catalogue-list/utils.ts +4 -5
  4. package/dpr/components/_charts/chart/Buckets.js +1 -1
  5. package/dpr/components/_charts/chart/Buckets.js.map +3 -3
  6. package/dpr/components/_charts/chart/Buckets.ts +44 -36
  7. package/dpr/components/_charts/chart/heatmap/HeatmapChart.js +1 -1
  8. package/dpr/components/_charts/chart/heatmap/HeatmapChart.js.map +2 -2
  9. package/dpr/components/_charts/chart/heatmap/HeatmapChart.ts +22 -14
  10. package/dpr/components/_charts/chart/heatmap/types.js +2 -0
  11. package/dpr/components/_charts/chart/heatmap/types.js.map +7 -0
  12. package/dpr/components/_charts/chart/heatmap/types.ts +6 -0
  13. package/dpr/components/_charts/utils.js +1 -1
  14. package/dpr/components/_charts/utils.js.map +3 -3
  15. package/dpr/components/_charts/utils.test.ts +10 -7
  16. package/dpr/components/_charts/utils.ts +57 -50
  17. package/dpr/components/_dashboards/dashboard/view.njk +1 -1
  18. package/dpr/components/_dashboards/dashboard-list/utils.js +1 -1
  19. package/dpr/components/_dashboards/dashboard-list/utils.js.map +2 -2
  20. package/dpr/components/_dashboards/dashboard-list/utils.test.ts +3 -3
  21. package/dpr/components/_dashboards/dashboard-list/utils.ts +16 -12
  22. package/dpr/components/_dashboards/dashboard-section/view.njk +1 -1
  23. package/dpr/components/_dashboards/dashboard-visualisation/DashboardVisualisation.js +2 -0
  24. package/dpr/components/_dashboards/dashboard-visualisation/DashboardVisualisation.js.map +7 -0
  25. package/dpr/components/_dashboards/dashboard-visualisation/DashboardVisualisation.ts +40 -0
  26. package/dpr/components/_dashboards/dashboard-visualisation/types.js +2 -0
  27. package/dpr/components/_dashboards/dashboard-visualisation/types.js.map +7 -0
  28. package/dpr/components/_dashboards/dashboard-visualisation/types.ts +102 -0
  29. package/dpr/components/_dashboards/dashboard-visualisation/view.njk +1 -1
  30. package/dpr/components/_dashboards/scorecard/Scorecard.js +1 -1
  31. package/dpr/components/_dashboards/scorecard/Scorecard.js.map +2 -2
  32. package/dpr/components/_dashboards/scorecard/Scorecard.ts +37 -29
  33. package/dpr/components/_dashboards/scorecard/types.js.map +1 -1
  34. package/dpr/components/_dashboards/scorecard/types.ts +1 -0
  35. package/dpr/components/_dashboards/scorecard/utils.js +1 -1
  36. package/dpr/components/_dashboards/scorecard/utils.js.map +2 -2
  37. package/dpr/components/_dashboards/scorecard/utils.test.ts +13 -4
  38. package/dpr/components/_dashboards/scorecard/utils.ts +6 -5
  39. package/dpr/components/_dashboards/scorecard/view.njk +6 -5
  40. package/dpr/components/_dashboards/scorecard-group/view.njk +4 -4
  41. package/dpr/components/_reports/report-actions/types.d.js.map +1 -1
  42. package/dpr/components/_reports/report-actions/types.d.ts +1 -1
  43. package/dpr/components/_reports/report-heading/view.njk +1 -1
  44. package/dpr/data/dashboardClient.js +1 -1
  45. package/dpr/data/dashboardClient.js.map +2 -2
  46. package/dpr/data/dashboardClient.ts +8 -7
  47. package/dpr/data/reportingClient.js +1 -1
  48. package/dpr/data/reportingClient.js.map +1 -1
  49. package/dpr/data/reportingClient.ts +1 -1
  50. package/dpr/middleware/reportAuthoriser.js +1 -1
  51. package/dpr/middleware/reportAuthoriser.js.map +3 -3
  52. package/dpr/middleware/reportAuthoriser.ts +9 -20
  53. package/dpr/routes/journeys/download-report/controller.js +1 -1
  54. package/dpr/routes/journeys/download-report/controller.js.map +3 -3
  55. package/dpr/routes/journeys/download-report/controller.ts +4 -1
  56. package/dpr/routes/journeys/download-report/request-download/form/submitted/tests.cy.js +1 -1
  57. package/dpr/routes/journeys/download-report/request-download/form/submitted/tests.cy.js.map +2 -2
  58. package/dpr/routes/journeys/download-report/request-download/form/submitted/tests.cy.ts +1 -0
  59. package/dpr/routes/journeys/download-report/request-download/form/tests.cy.js +1 -1
  60. package/dpr/routes/journeys/download-report/request-download/form/tests.cy.js.map +2 -2
  61. package/dpr/routes/journeys/download-report/request-download/form/tests.cy.ts +1 -0
  62. package/dpr/routes/journeys/download-report/tests.cy.js +1 -1
  63. package/dpr/routes/journeys/download-report/tests.cy.js.map +2 -2
  64. package/dpr/routes/journeys/download-report/tests.cy.ts +2 -8
  65. package/dpr/routes/journeys/download-report/utils.js +1 -1
  66. package/dpr/routes/journeys/download-report/utils.js.map +3 -3
  67. package/dpr/routes/journeys/download-report/utils.ts +10 -7
  68. package/dpr/routes/journeys/my-reports/bookmarks/list/tests.cy.js +1 -1
  69. package/dpr/routes/journeys/my-reports/bookmarks/list/tests.cy.js.map +2 -2
  70. package/dpr/routes/journeys/my-reports/bookmarks/list/tests.cy.ts +1 -0
  71. package/dpr/routes/journeys/my-reports/bookmarks/tests.cy.js +1 -1
  72. package/dpr/routes/journeys/my-reports/bookmarks/tests.cy.js.map +3 -3
  73. package/dpr/routes/journeys/my-reports/bookmarks/tests.cy.ts +5 -14
  74. package/dpr/routes/journeys/my-reports/bookmarks/utils.js +1 -1
  75. package/dpr/routes/journeys/my-reports/bookmarks/utils.js.map +3 -3
  76. package/dpr/routes/journeys/my-reports/bookmarks/utils.ts +11 -5
  77. package/dpr/routes/journeys/my-reports/recently-viewed/list/tests.cy.js +1 -1
  78. package/dpr/routes/journeys/my-reports/recently-viewed/list/tests.cy.js.map +3 -3
  79. package/dpr/routes/journeys/my-reports/recently-viewed/list/tests.cy.ts +4 -7
  80. package/dpr/routes/journeys/my-reports/requested-reports/list/tests.cy.js +1 -1
  81. package/dpr/routes/journeys/my-reports/requested-reports/list/tests.cy.js.map +2 -2
  82. package/dpr/routes/journeys/my-reports/requested-reports/list/tests.cy.ts +1 -0
  83. package/dpr/routes/journeys/request-missing-report/form/tests.cy.js +1 -1
  84. package/dpr/routes/journeys/request-missing-report/form/tests.cy.js.map +2 -2
  85. package/dpr/routes/journeys/request-missing-report/form/tests.cy.ts +1 -0
  86. package/dpr/routes/journeys/request-missing-report/tests.cy.js +1 -1
  87. package/dpr/routes/journeys/request-missing-report/tests.cy.js.map +2 -2
  88. package/dpr/routes/journeys/request-missing-report/tests.cy.ts +3 -5
  89. package/dpr/routes/journeys/request-report/filters/tests.cy.js +1 -1
  90. package/dpr/routes/journeys/request-report/filters/tests.cy.js.map +3 -3
  91. package/dpr/routes/journeys/request-report/filters/tests.cy.ts +3 -6
  92. package/dpr/routes/journeys/request-report/filters/utils.js +1 -1
  93. package/dpr/routes/journeys/request-report/filters/utils.js.map +2 -2
  94. package/dpr/routes/journeys/request-report/filters/utils.ts +2 -3
  95. package/dpr/routes/journeys/request-report/status/tests.cy.js +1 -1
  96. package/dpr/routes/journeys/request-report/status/tests.cy.js.map +2 -2
  97. package/dpr/routes/journeys/request-report/status/tests.cy.ts +2 -7
  98. package/dpr/routes/journeys/request-report/tests.cy.js +1 -1
  99. package/dpr/routes/journeys/request-report/tests.cy.js.map +3 -3
  100. package/dpr/routes/journeys/request-report/tests.cy.ts +5 -21
  101. package/dpr/routes/journeys/view-report/async/controller.js.map +2 -2
  102. package/dpr/routes/journeys/view-report/async/controller.ts +2 -2
  103. package/dpr/routes/journeys/view-report/async/dashboard/tests.cy.js +1 -1
  104. package/dpr/routes/journeys/view-report/async/dashboard/tests.cy.js.map +2 -2
  105. package/dpr/routes/journeys/view-report/async/dashboard/tests.cy.ts +2 -10
  106. package/dpr/routes/journeys/view-report/async/dashboard/utils.js +1 -1
  107. package/dpr/routes/journeys/view-report/async/dashboard/utils.js.map +3 -3
  108. package/dpr/routes/journeys/view-report/async/dashboard/utils.ts +100 -95
  109. package/dpr/routes/journeys/view-report/async/report/controller.js +1 -1
  110. package/dpr/routes/journeys/view-report/async/report/controller.js.map +3 -3
  111. package/dpr/routes/journeys/view-report/async/report/controller.ts +4 -6
  112. package/dpr/routes/journeys/view-report/async/report/tests.cy.js +1 -1
  113. package/dpr/routes/journeys/view-report/async/report/tests.cy.js.map +2 -2
  114. package/dpr/routes/journeys/view-report/async/report/tests.cy.ts +8 -19
  115. package/dpr/routes/journeys/view-report/async/report/types.js +2 -0
  116. package/dpr/routes/journeys/view-report/async/report/types.js.map +7 -0
  117. package/dpr/routes/journeys/view-report/async/report/types.ts +31 -0
  118. package/dpr/routes/journeys/view-report/async/report/utils.js +1 -1
  119. package/dpr/routes/journeys/view-report/async/report/utils.js.map +3 -3
  120. package/dpr/routes/journeys/view-report/async/report/utils.ts +173 -136
  121. package/dpr/routes/journeys/view-report/sync/tests.cy.js +1 -1
  122. package/dpr/routes/journeys/view-report/sync/tests.cy.js.map +3 -3
  123. package/dpr/routes/journeys/view-report/sync/tests.cy.ts +3 -5
  124. package/dpr/services/dashboardService.js +1 -1
  125. package/dpr/services/dashboardService.js.map +2 -2
  126. package/dpr/services/dashboardService.ts +7 -5
  127. package/dpr/services/productCollection/productCollectionService.js +1 -1
  128. package/dpr/services/productCollection/productCollectionService.js.map +2 -2
  129. package/dpr/services/productCollection/productCollectionService.ts +3 -3
  130. package/dpr/services/reportingService.js +1 -1
  131. package/dpr/services/reportingService.js.map +1 -1
  132. package/dpr/services/reportingService.ts +1 -1
  133. package/dpr/types/AsyncReportUtils.js.map +1 -1
  134. package/dpr/types/AsyncReportUtils.ts +3 -4
  135. package/dpr/types/Charts.js +1 -1
  136. package/dpr/types/Charts.js.map +3 -3
  137. package/dpr/types/Charts.ts +0 -82
  138. package/dpr/types/Metrics.js +1 -1
  139. package/dpr/types/Metrics.js.map +1 -1
  140. package/dpr/types/Metrics.ts +7 -0
  141. package/dpr/types/ReportQuery.js +1 -1
  142. package/dpr/types/ReportQuery.js.map +3 -3
  143. package/dpr/types/ReportQuery.ts +24 -15
  144. package/dpr/types/Services.d.js +1 -1
  145. package/dpr/types/Services.d.js.map +1 -1
  146. package/dpr/types/Services.d.ts +2 -0
  147. package/dpr/types/api.d.js.map +1 -1
  148. package/dpr/types/api.d.ts +14 -16
  149. package/dpr/utils/Personalisation/personalisationUtils.js +1 -1
  150. package/dpr/utils/Personalisation/personalisationUtils.js.map +3 -3
  151. package/dpr/utils/Personalisation/personalisationUtils.ts +15 -6
  152. package/dpr/utils/UserStoreItemBuilder.js +1 -1
  153. package/dpr/utils/UserStoreItemBuilder.js.map +1 -1
  154. package/dpr/utils/UserStoreItemBuilder.ts +2 -2
  155. package/dpr/utils/datasetHelper.js +1 -1
  156. package/dpr/utils/datasetHelper.js.map +3 -3
  157. package/dpr/utils/datasetHelper.test.ts +11 -11
  158. package/dpr/utils/datasetHelper.ts +23 -8
  159. package/dpr/utils/logger.js +1 -1
  160. package/dpr/utils/logger.js.map +3 -3
  161. package/dpr/utils/logger.ts +6 -1
  162. package/package.json +2 -1
  163. package/dpr/components/_charts/chart/DashboardVisualisation.js +0 -2
  164. package/dpr/components/_charts/chart/DashboardVisualisation.js.map +0 -7
  165. package/dpr/components/_charts/chart/DashboardVisualisation.ts +0 -43
  166. package/dpr/components/_dashboards/dashboard/types.js +0 -2
  167. package/dpr/components/_dashboards/dashboard/types.js.map +0 -7
  168. package/dpr/components/_dashboards/dashboard/types.ts +0 -120
@@ -1,2 +1,2 @@
1
- var P=Object.create;var S=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var V=Object.getPrototypeOf,F=Object.prototype.hasOwnProperty;var O=(e,t)=>{for(var o in t)S(e,o,{get:t[o],enumerable:!0})},R=(e,t,o,D)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of E(t))!F.call(e,a)&&a!==o&&S(e,a,{get:()=>t[a],enumerable:!(D=B(t,a))||D.enumerable});return e};var M=(e,t,o)=>(o=e!=null?P(V(e)):{},R(t||!e||!e.__esModule?S(o,"default",{value:e,enumerable:!0}):o,e)),U=e=>R(S({},"__esModule",{value:!0}),e);var $={};O($,{default:()=>Y,getReportsList:()=>A});module.exports=U($);var c=require("../../../types/UserReports"),w=M(require("../../show-more/utils")),l=require("../../../utils/reportListsHelper"),x=M(require("../../../utils/localsHelper"));const A=async(e,t,o)=>{const{definitions:D,csrfToken:a,bookmarkingEnabled:H,dprUser:v}=x.default.getValues(e),C=D.sort((s,i)=>s.name<i.name?-1:s.name>i.name?1:0).flatMap(s=>{const{id:i,name:g,description:m,variants:T,dashboards:f,authorised:k}=s,p=T.map(r=>{const{id:n,name:u,description:d,isMissing:b}=r,N=r.loadType||c.LoadType.ASYNC;return{reportName:g,reportId:i,id:n,name:u,description:d,type:c.ReportType.REPORT,loadType:N,authorised:k,isMissing:b,...m&&m.length&&{reportDescription:m}}});let h=[];f&&(h=f.map(r=>{const{id:n,name:u,description:d,isMissing:b}=r;return{reportName:g,reportId:i,id:n,name:u,description:d,type:c.ReportType.DASHBOARD,reportDescription:m,authorised:k,isMissing:b,loadType:c.LoadType.ASYNC}}));const y=[...h,...p];return y.sort((r,n)=>r.name<n.name?-1:r.name>n.name?1:0),y}),I=await t.bookmarkService.getState(v.id),L=await Promise.all(C.map(async s=>{const{id:i,name:g,description:m,reportName:T,reportId:f,reportDescription:k,type:p,loadType:h,authorised:y,isMissing:r}=s,n=m||k||"",u=(0,l.setInitialHref)(h,p,f,i,e,r);let d;return(o?.bookmarkingEnabled!==void 0?o?.bookmarkingEnabled:H)&&(d=await t.bookmarkService.createBookMarkToggleHtml({userConfig:I,reportId:f,id:i,csrfToken:a,ctxId:"reports-list",reportType:p,isMissing:r})),[{html:`<p class="govuk-body-s">${T}</p>`},{html:(0,l.createListItemProductMin)(g,p)},{html:w.default.createShowMoreHtml(n)},{html:(0,l.createListActions)(u,p,h,d,y,r)}]}));return{head:[{text:"Product",classes:"dpr-product-head"},{text:"Name",classes:"dpr-name-head"},{text:"Description",classes:"dpr-description-head"},{text:"Actions",classes:"dpr-bookmark-head"}],rows:L,id:"dpr-reports-catalogue"}};var Y={getReportsList:A};0&&(module.exports={getReportsList});
1
+ var P=Object.create;var b=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var V=Object.getPrototypeOf,F=Object.prototype.hasOwnProperty;var O=(e,t)=>{for(var o in t)b(e,o,{get:t[o],enumerable:!0})},R=(e,t,o,D)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of E(t))!F.call(e,n)&&n!==o&&b(e,n,{get:()=>t[n],enumerable:!(D=B(t,n))||D.enumerable});return e};var M=(e,t,o)=>(o=e!=null?P(V(e)):{},R(t||!e||!e.__esModule?b(o,"default",{value:e,enumerable:!0}):o,e)),U=e=>R(b({},"__esModule",{value:!0}),e);var $={};O($,{default:()=>Y,getReportsList:()=>A});module.exports=U($);var d=require("../../../types/UserReports"),w=M(require("../../show-more/utils")),l=require("../../../utils/reportListsHelper"),x=M(require("../../../utils/localsHelper"));const A=async(e,t,o)=>{const{definitions:D,csrfToken:n,bookmarkingEnabled:H,dprUser:v}=x.default.getValues(e),C=D.sort((a,i)=>a.name<i.name?-1:a.name>i.name?1:0).flatMap(a=>{const{id:i,name:g,description:m,variants:S,dashboards:f,authorised:k}=a,p=S.map(r=>{const{id:s,name:u,description:c,isMissing:T}=r,N=r.loadType||d.LoadType.ASYNC;return{reportName:g,reportId:i,id:s,name:u,description:c,type:d.ReportType.REPORT,loadType:N,authorised:k,isMissing:T,...m&&m.length&&{reportDescription:m}}});let h=[];f&&(h=f.map(r=>{const{id:s,name:u,description:c}=r;return{reportName:g,reportId:i,id:s,name:u,description:c,type:d.ReportType.DASHBOARD,reportDescription:m,authorised:k,isMissing:!1,loadType:d.LoadType.ASYNC}}));const y=[...h,...p];return y.sort((r,s)=>r.name<s.name?-1:r.name>s.name?1:0),y}),I=await t.bookmarkService.getState(v.id),L=await Promise.all(C.map(async a=>{const{id:i,name:g,description:m,reportName:S,reportId:f,reportDescription:k,type:p,loadType:h,authorised:y,isMissing:r}=a,s=m||k||"",u=(0,l.setInitialHref)(h,p,f,i,e,r);let c;return(o?.bookmarkingEnabled!==void 0?o?.bookmarkingEnabled:H)&&(c=await t.bookmarkService.createBookMarkToggleHtml({userConfig:I,reportId:f,id:i,csrfToken:n,ctxId:"reports-list",reportType:p,isMissing:r})),[{html:`<p class="govuk-body-s">${S}</p>`},{html:(0,l.createListItemProductMin)(g,p)},{html:w.default.createShowMoreHtml(s)},{html:(0,l.createListActions)(u,p,h,c,y,r)}]}));return{head:[{text:"Product",classes:"dpr-product-head"},{text:"Name",classes:"dpr-name-head"},{text:"Description",classes:"dpr-description-head"},{text:"Actions",classes:"dpr-bookmark-head"}],rows:L,id:"dpr-reports-catalogue"}};var Y={getReportsList:A};0&&(module.exports={getReportsList});
2
2
  //# sourceMappingURL=utils.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/dpr/components/_catalogue/catalogue-list/utils.ts"],
4
- "sourcesContent": ["import { Response } from 'express'\nimport { components } from '../../../types/api'\nimport { Services } from '../../../types/Services'\nimport { DashboardDefinition } from '../../_dashboards/dashboard/types'\nimport { DefinitionData, LoadType, ReportType } from '../../../types/UserReports'\nimport ShowMoreUtils from '../../show-more/utils'\nimport { createListItemProductMin, createListActions, setInitialHref } from '../../../utils/reportListsHelper'\nimport { CatalogueFeatures } from '../catalogue/types'\nimport LocalsHelper from '../../../utils/localsHelper'\n\nexport const getReportsList = async (\n res: Response,\n services: Services,\n features?: CatalogueFeatures,\n): Promise<{ head: { text: string }[]; rows: { text?: string; html?: string }[]; id: string }> => {\n const { definitions, csrfToken, bookmarkingEnabled, dprUser } = LocalsHelper.getValues(res)\n\n // Sort report Definitions by product name\n const sortedDefinitions = definitions.sort(\n (a: components['schemas']['ReportDefinitionSummary'], b: components['schemas']['ReportDefinitionSummary']) => {\n if (a.name < b.name) return -1\n if (a.name > b.name) return 1\n return 0\n },\n )\n\n // Sort by variant/dashboard name\n const sortedVariants = sortedDefinitions.flatMap(\n (\n def: components['schemas']['ReportDefinitionSummary'] & {\n dashboards: DashboardDefinition[]\n authorised: boolean\n },\n ) => {\n const { id: reportId, name: reportName, description: reportDescription, variants, dashboards, authorised } = def\n\n const variantsArray: DefinitionData[] = variants.map(\n (variant: components['schemas']['VariantDefinitionSummary']) => {\n const { id, name, description, isMissing } = variant\n\n // NOTE: loadType added to VariantDefinitionSummary mocked data to dictate the load/request journey. Not present in API response. To discuss\n const loadType = variant.loadType || LoadType.ASYNC\n\n return {\n reportName,\n reportId,\n id,\n name,\n description,\n type: ReportType.REPORT,\n loadType,\n authorised,\n isMissing,\n ...(reportDescription && reportDescription.length && { reportDescription }),\n }\n },\n )\n\n let dashboardsArray: DefinitionData[] = []\n if (dashboards) {\n dashboardsArray = dashboards.map((dashboard: DashboardDefinition) => {\n const { id, name, description, isMissing } = dashboard\n return {\n reportName,\n reportId,\n id,\n name,\n description,\n type: ReportType.DASHBOARD,\n reportDescription,\n authorised,\n isMissing,\n loadType: LoadType.ASYNC,\n }\n })\n }\n\n const mergedArray = [...dashboardsArray, ...variantsArray]\n\n mergedArray.sort((a: DefinitionData, b: DefinitionData) => {\n if (a.name < b.name) return -1\n if (a.name > b.name) return 1\n return 0\n })\n\n return mergedArray\n },\n )\n\n const userConfig = await services.bookmarkService.getState(dprUser.id)\n const rows = await Promise.all(\n sortedVariants.map(async (v: DefinitionData) => {\n const { id, name, description, reportName, reportId, reportDescription, type, loadType, authorised, isMissing } =\n v\n const desc = description || reportDescription || ''\n\n const href = setInitialHref(loadType, type, reportId, id, res, isMissing)\n\n let bookmarkHtml\n const showBookMarkToggle =\n features?.bookmarkingEnabled !== undefined ? features?.bookmarkingEnabled : bookmarkingEnabled\n\n if (showBookMarkToggle) {\n bookmarkHtml = await services.bookmarkService.createBookMarkToggleHtml({\n userConfig,\n reportId,\n id,\n csrfToken,\n ctxId: 'reports-list',\n reportType: type,\n isMissing,\n })\n }\n\n return [\n { html: `<p class=\"govuk-body-s\">${reportName}</p>` },\n { html: createListItemProductMin(name, <ReportType>type) },\n { html: ShowMoreUtils.createShowMoreHtml(desc) },\n { html: createListActions(href, type, loadType, bookmarkHtml, authorised, isMissing) },\n ]\n }),\n )\n\n const head = [\n { text: 'Product', classes: 'dpr-product-head' },\n { text: 'Name', classes: 'dpr-name-head' },\n { text: 'Description', classes: 'dpr-description-head' },\n { text: 'Actions', classes: 'dpr-bookmark-head' },\n ]\n\n return {\n head,\n rows,\n id: 'dpr-reports-catalogue',\n }\n}\n\nexport default {\n getReportsList,\n}\n"],
5
- "mappings": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,mBAAAC,IAAA,eAAAC,EAAAJ,GAIA,IAAAK,EAAqD,sCACrDC,EAA0B,oCAC1BC,EAA4E,4CAE5EC,EAAyB,0CAElB,MAAML,EAAiB,MAC5BM,EACAC,EACAC,IACgG,CAChG,KAAM,CAAE,YAAAC,EAAa,UAAAC,EAAW,mBAAAC,EAAoB,QAAAC,CAAQ,EAAI,EAAAC,QAAa,UAAUP,CAAG,EAYpFQ,EAToBL,EAAY,KACpC,CAACM,EAAqDC,IAChDD,EAAE,KAAOC,EAAE,KAAa,GACxBD,EAAE,KAAOC,EAAE,KAAa,EACrB,CAEX,EAGyC,QAErCC,GAIG,CACH,KAAM,CAAE,GAAIC,EAAU,KAAMC,EAAY,YAAaC,EAAmB,SAAAC,EAAU,WAAAC,EAAY,WAAAC,CAAW,EAAIN,EAEvGO,EAAkCH,EAAS,IAC9CI,GAA+D,CAC9D,KAAM,CAAE,GAAAC,EAAI,KAAAC,EAAM,YAAAC,EAAa,UAAAC,CAAU,EAAIJ,EAGvCK,EAAWL,EAAQ,UAAY,WAAS,MAE9C,MAAO,CACL,WAAAN,EACA,SAAAD,EACA,GAAAQ,EACA,KAAAC,EACA,YAAAC,EACA,KAAM,aAAW,OACjB,SAAAE,EACA,WAAAP,EACA,UAAAM,EACA,GAAIT,GAAqBA,EAAkB,QAAU,CAAE,kBAAAA,CAAkB,CAC3E,CACF,CACF,EAEA,IAAIW,EAAoC,CAAC,EACrCT,IACFS,EAAkBT,EAAW,IAAKU,GAAmC,CACnE,KAAM,C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AS,CAAE,CACvF,CACF,CAAC,CACH,EASA,MAAO,CACL,KARW,CACX,CAAE,KAAM,UAAW,QAAS,kBAAmB,EAC/C,CAAE,KAAM,OAAQ,QAAS,eAAgB,EACzC,CAAE,KAAM,cAAe,QAAS,sBAAuB,EACvD,CAAE,KAAM,UAAW,QAAS,mBAAoB,CAClD,EAIE,KAAAM,EACA,GAAI,uBACN,CACF,EAEA,IAAOpC,EAAQ,CACb,eAAAC,CACF",
6
- "names": ["utils_exports", "__export", "utils_default", "getReportsList", "__toCommonJS", "import_UserReports", "import_utils", "import_reportListsHelper", "import_localsHelper", "res", "services", "features", "definitions", "csrfToken", "bookmarkingEnabled", "dprUser", "LocalsHelper", "sortedVariants", "a", "b", "def", "reportId", "reportName", "reportDescription", "variants", "dashboards", "authorised", "variantsArray", "variant", "id", "name", "description", "isMissing", "loadType", "dashboardsArray", "dashboard", "mergedArray", "userConfig", "rows", "v", "type", "desc", "href", "bookmarkHtml", "ShowMoreUtils"]
4
+ "sourcesContent": ["import { Response } from 'express'\nimport { components } from '../../../types/api'\nimport { Services } from '../../../types/Services'\nimport { DefinitionData, LoadType, ReportType } from '../../../types/UserReports'\nimport ShowMoreUtils from '../../show-more/utils'\nimport { createListItemProductMin, createListActions, setInitialHref } from '../../../utils/reportListsHelper'\nimport { CatalogueFeatures } from '../catalogue/types'\nimport LocalsHelper from '../../../utils/localsHelper'\n\nexport const getReportsList = async (\n res: Response,\n services: Services,\n features?: CatalogueFeatures,\n): Promise<{ head: { text: string }[]; rows: { text?: string; html?: string }[]; id: string }> => {\n const { definitions, csrfToken, bookmarkingEnabled, dprUser } = LocalsHelper.getValues(res)\n\n // Sort report Definitions by product name\n const sortedDefinitions = definitions.sort(\n (a: components['schemas']['ReportDefinitionSummary'], b: components['schemas']['ReportDefinitionSummary']) => {\n if (a.name < b.name) return -1\n if (a.name > b.name) return 1\n return 0\n },\n )\n\n // Sort by variant/dashboard name\n const sortedVariants = sortedDefinitions.flatMap(\n (\n def: components['schemas']['ReportDefinitionSummary'] & {\n dashboards: components['schemas']['DashboardDefinition'][]\n authorised: boolean\n },\n ) => {\n const { id: reportId, name: reportName, description: reportDescription, variants, dashboards, authorised } = def\n\n const variantsArray: DefinitionData[] = variants.map(\n (variant: components['schemas']['VariantDefinitionSummary']) => {\n const { id, name, description, isMissing } = variant\n\n // NOTE: loadType added to VariantDefinitionSummary mocked data to dictate the load/request journey. Not present in API response. To discuss\n const loadType = variant.loadType || LoadType.ASYNC\n\n return {\n reportName,\n reportId,\n id,\n name,\n description,\n type: ReportType.REPORT,\n loadType,\n authorised,\n isMissing,\n ...(reportDescription && reportDescription.length && { reportDescription }),\n }\n },\n )\n\n let dashboardsArray: DefinitionData[] = []\n if (dashboards) {\n dashboardsArray = dashboards.map((dashboard: components['schemas']['DashboardDefinition']) => {\n const { id, name, description } = dashboard\n return {\n reportName,\n reportId,\n id,\n name,\n description,\n type: ReportType.DASHBOARD,\n reportDescription,\n authorised,\n isMissing: false,\n loadType: LoadType.ASYNC,\n }\n })\n }\n\n const mergedArray = [...dashboardsArray, ...variantsArray]\n\n mergedArray.sort((a: DefinitionData, b: DefinitionData) => {\n if (a.name < b.name) return -1\n if (a.name > b.name) return 1\n return 0\n })\n\n return mergedArray\n },\n )\n\n const userConfig = await services.bookmarkService.getState(dprUser.id)\n const rows = await Promise.all(\n sortedVariants.map(async (v: DefinitionData) => {\n const { id, name, description, reportName, reportId, reportDescription, type, loadType, authorised, isMissing } =\n v\n const desc = description || reportDescription || ''\n\n const href = setInitialHref(loadType, type, reportId, id, res, isMissing)\n\n let bookmarkHtml\n const showBookMarkToggle =\n features?.bookmarkingEnabled !== undefined ? features?.bookmarkingEnabled : bookmarkingEnabled\n\n if (showBookMarkToggle) {\n bookmarkHtml = await services.bookmarkService.createBookMarkToggleHtml({\n userConfig,\n reportId,\n id,\n csrfToken,\n ctxId: 'reports-list',\n reportType: type,\n isMissing,\n })\n }\n\n return [\n { html: `<p class=\"govuk-body-s\">${reportName}</p>` },\n { html: createListItemProductMin(name, <ReportType>type) },\n { html: ShowMoreUtils.createShowMoreHtml(desc) },\n { html: createListActions(href, type, loadType, bookmarkHtml, authorised, isMissing) },\n ]\n }),\n )\n\n const head = [\n { text: 'Product', classes: 'dpr-product-head' },\n { text: 'Name', classes: 'dpr-name-head' },\n { text: 'Description', classes: 'dpr-description-head' },\n { text: 'Actions', classes: 'dpr-bookmark-head' },\n ]\n\n return {\n head,\n rows,\n id: 'dpr-reports-catalogue',\n }\n}\n\nexport default {\n getReportsList,\n}\n"],
5
+ "mappings": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,mBAAAC,IAAA,eAAAC,EAAAJ,GAGA,IAAAK,EAAqD,sCACrDC,EAA0B,oCAC1BC,EAA4E,4CAE5EC,EAAyB,0CAElB,MAAML,EAAiB,MAC5BM,EACAC,EACAC,IACgG,CAChG,KAAM,CAAE,YAAAC,EAAa,UAAAC,EAAW,mBAAAC,EAAoB,QAAAC,CAAQ,EAAI,EAAAC,QAAa,UAAUP,CAAG,EAYpFQ,EAToBL,EAAY,KACpC,CAAC,EAAqDM,IAChD,EAAE,KAAOA,EAAE,KAAa,GACxB,EAAE,KAAOA,EAAE,KAAa,EACrB,CAEX,EAGyC,QAErCC,GAIG,CACH,KAAM,CAAE,GAAIC,EAAU,KAAMC,EAAY,YAAaC,EAAmB,SAAAC,EAAU,WAAAC,EAAY,WAAAC,CAAW,EAAIN,EAEvGO,EAAkCH,EAAS,IAC9CI,GAA+D,CAC9D,KAAM,CAAE,GAAAC,EAAI,KAAAC,EAAM,YAAAC,EAAa,UAAAC,CAAU,EAAIJ,EAGvCK,EAAWL,EAAQ,UAAY,WAAS,MAE9C,MAAO,CACL,WAAAN,EACA,SAAAD,EACA,GAAAQ,EACA,KAAAC,EACA,YAAAC,EACA,KAAM,aAAW,OACjB,SAAAE,EACA,WAAAP,EACA,UAAAM,EACA,GAAIT,GAAqBA,EAAkB,QAAU,CAAE,kBAAAA,CAA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mBAAmBH,CAAI,CAAE,EAC/C,CAAE,QAAM,qBAAkBC,EAAMF,EAAMR,EAAUW,EAAclB,EAAYM,CAAS,CAAE,CACvF,CACF,CAAC,CACH,EASA,MAAO,CACL,KARW,CACX,CAAE,KAAM,UAAW,QAAS,kBAAmB,EAC/C,CAAE,KAAM,OAAQ,QAAS,eAAgB,EACzC,CAAE,KAAM,cAAe,QAAS,sBAAuB,EACvD,CAAE,KAAM,UAAW,QAAS,mBAAoB,CAClD,EAIE,KAAAO,EACA,GAAI,uBACN,CACF,EAEA,IAAOpC,EAAQ,CACb,eAAAC,CACF",
6
+ "names": ["utils_exports", "__export", "utils_default", "getReportsList", "__toCommonJS", "import_UserReports", "import_utils", "import_reportListsHelper", "import_localsHelper", "res", "services", "features", "definitions", "csrfToken", "bookmarkingEnabled", "dprUser", "LocalsHelper", "sortedVariants", "b", "def", "reportId", "reportName", "reportDescription", "variants", "dashboards", "authorised", "variantsArray", "variant", "id", "name", "description", "isMissing", "loadType", "dashboardsArray", "dashboard", "mergedArray", "a", "userConfig", "rows", "v", "type", "desc", "href", "bookmarkHtml", "ShowMoreUtils"]
7
7
  }
@@ -1,7 +1,6 @@
1
1
  import { Response } from 'express'
2
2
  import { components } from '../../../types/api'
3
3
  import { Services } from '../../../types/Services'
4
- import { DashboardDefinition } from '../../_dashboards/dashboard/types'
5
4
  import { DefinitionData, LoadType, ReportType } from '../../../types/UserReports'
6
5
  import ShowMoreUtils from '../../show-more/utils'
7
6
  import { createListItemProductMin, createListActions, setInitialHref } from '../../../utils/reportListsHelper'
@@ -28,7 +27,7 @@ export const getReportsList = async (
28
27
  const sortedVariants = sortedDefinitions.flatMap(
29
28
  (
30
29
  def: components['schemas']['ReportDefinitionSummary'] & {
31
- dashboards: DashboardDefinition[]
30
+ dashboards: components['schemas']['DashboardDefinition'][]
32
31
  authorised: boolean
33
32
  },
34
33
  ) => {
@@ -58,8 +57,8 @@ export const getReportsList = async (
58
57
 
59
58
  let dashboardsArray: DefinitionData[] = []
60
59
  if (dashboards) {
61
- dashboardsArray = dashboards.map((dashboard: DashboardDefinition) => {
62
- const { id, name, description, isMissing } = dashboard
60
+ dashboardsArray = dashboards.map((dashboard: components['schemas']['DashboardDefinition']) => {
61
+ const { id, name, description } = dashboard
63
62
  return {
64
63
  reportName,
65
64
  reportId,
@@ -69,7 +68,7 @@ export const getReportsList = async (
69
68
  type: ReportType.DASHBOARD,
70
69
  reportDescription,
71
70
  authorised,
72
- isMissing,
71
+ isMissing: false,
73
72
  loadType: LoadType.ASYNC,
74
73
  }
75
74
  })
@@ -1,2 +1,2 @@
1
- var h=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var m=(a,t)=>{for(var s in t)h(a,s,{get:t[s],enumerable:!0})},C=(a,t,s,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of k(t))!b.call(a,i)&&i!==s&&h(a,i,{get:()=>t[i],enumerable:!(e=p(t,i))||e.enumerable});return a};var d=a=>C(h({},"__esModule",{value:!0}),a);var g={};m(g,{Buckets:()=>c,default:()=>f});module.exports=d(g);var l=require("with-alpha-hex");class c{constructor(t,s,e,i,o){this.baseColour="#1d70b8";this.ragColours=["#00703c","#ffdd00","#d4351c"];this.buckets=[];this.hasRagScore=!1;this.initFromOptions=t=>{this.options=t.options||{},this.baseColour=this.options?.baseColour||this.baseColour,this.useRagColours=this.options?.useRagColours||!1,this.onlyBucketColoursDefined=this.options?.buckets?.every(s=>!s.max&&!s.min&&s.hexColour!==void 0)};this.initBuckets=()=>{const{buckets:t}=this.options;this.setBucketCount(),this.initBucketColours(),t?this.hasRagScore?this.onlyBucketColoursDefined&&(this.buckets=t):!this.hasRagScore&&this.onlyBucketColoursDefined&&this.autoBucketing?this.initAutomaticThresholdBucket():this.initCustomThresholdBuckets():!t&&!this.hasRagScore&&this.autoBucketing&&this.initAutomaticThresholdBucket()};this.initCustomThresholdBuckets=()=>{this.buckets=this.options.buckets.map((t,s)=>({...this.buckets[s],...t}))};this.initAutomaticThresholdBucket=()=>{const{min:t,max:s,bucketSize:e}=this.setAutomaticThresholdSize();let i=0;this.buckets=this.buckets.map((o,u)=>{let r=t;return u!==0&&(r=i+1),i=e*(u+1)+t,u===this.buckets.length-1&&(i=s),{hexColour:this.options?.buckets?this.options.buckets[u]?.hexColour:o.hexColour,min:r,max:i}})};this.initBucketColours=()=>{if(this.useRagColours&&this.bucketCount===3)this.buckets=Array.from(new Array(this.bucketCount)).map((t,s)=>({hexColour:this.ragColours[s]}));else{const t=1/this.bucketCount;this.buckets=Array.from(new Array(this.bucketCount)).map((s,e)=>{const i=t*(e+1);return{hexColour:(0,l.withAlphaHex)(this.baseColour,i)}})}};this.setAutomaticThresholdSize=()=>{const t=this.responseData.map(o=>Number(o[this.valueKey].raw)),s=Math.min(...t),e=Math.max(...t),i=Math.ceil((e-s)/this.bucketCount);return{min:s,max:e,bucketSize:i}};this.setBucketCount=()=>{const{buckets:t}=this.options;this.hasRagScore?this.useRagColours?this.bucketCount=3:this.bucketCount=Math.max(...this.responseData.map(s=>s[this.valueKey].rag))+1:t?this.bucketCount=t.length:this.bucketCount=3};this.getBucketForValue=(t,s)=>{let e,i;return s!==void 0?{colour:this.buckets[s].hexColour,score:s}:(this.buckets.forEach((o,u)=>{const{min:r,max:n}=o;!r&&n&&t<=n&&(e=o.hexColour,i=u.toString()),r&&t>=o.min&&n&&t<=o.max&&(e=o.hexColour,i=u.toString()),r&&!n&&t>=r&&(e=o.hexColour,i=u.toString())}),{colour:e,score:i})};this.getBuckets=()=>this.buckets;this.responseData=t,this.initFromOptions(s),this.valueKey=e,this.hasRagScore=t[0][this.valueKey].rag!==void 0,this.autoBucketing=i,o&&(this.ragColours=o),this.initBuckets()}}var f=c;0&&(module.exports={Buckets});
1
+ var h=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var m=(u,t)=>{for(var s in t)h(u,s,{get:t[s],enumerable:!0})},f=(u,t,s,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of k(t))!b.call(u,e)&&e!==s&&h(u,e,{get:()=>t[e],enumerable:!(i=p(t,e))||i.enumerable});return u};var C=u=>f(h({},"__esModule",{value:!0}),u);var g={};m(g,{Buckets:()=>c,default:()=>d});module.exports=C(g);var l=require("with-alpha-hex");class c{constructor(t,s,i,e,o){this.baseColour="#1d70b8";this.ragColours=["#00703c","#ffdd00","#d4351c"];this.buckets=[];this.useRagColour=!1;this.bucketCount=0;this.onlyBucketColoursDefined=!1;this.autoBucketing=!1;this.hasRagScore=!1;this.options={};this.initFromOptions=t=>{this.options=t.options||{},this.baseColour=this.options?.baseColour||this.baseColour,this.useRagColour=this.options?.useRagColour||!1,this.onlyBucketColoursDefined=this.options&&this.options.buckets?this.options?.buckets?.every(s=>!s.max&&!s.min&&s.hexColour!==void 0):!1};this.initBuckets=()=>{const{buckets:t}=this.options;this.setBucketCount(),this.initBucketColours(),t?this.hasRagScore?this.onlyBucketColoursDefined&&(this.buckets=t):!this.hasRagScore&&this.onlyBucketColoursDefined&&this.autoBucketing?this.initAutomaticThresholdBucket():this.initCustomThresholdBuckets():!t&&!this.hasRagScore&&this.autoBucketing&&this.initAutomaticThresholdBucket()};this.initCustomThresholdBuckets=()=>{this.buckets=this.options.buckets?this.options.buckets.map((t,s)=>({...this.buckets[s],...t})):[]};this.initAutomaticThresholdBucket=()=>{const{min:t,max:s,bucketSize:i}=this.setAutomaticThresholdSize();let e=0;this.buckets=this.buckets.map((o,a)=>{let r=t;return a!==0&&(r=e+1),e=i*(a+1)+t,a===this.buckets.length-1&&(e=s),{hexColour:this.options?.buckets?this.options.buckets[a]?.hexColour:o.hexColour,min:r,max:e}})};this.initBucketColours=()=>{if(this.useRagColour&&this.bucketCount===3)this.buckets=Array.from(new Array(this.bucketCount)).map((t,s)=>({hexColour:this.ragColours[s]}));else{const t=1/this.bucketCount;this.buckets=Array.from(new Array(this.bucketCount)).map((s,i)=>{const e=t*(i+1);return{hexColour:(0,l.withAlphaHex)(this.baseColour,e)}})}};this.setAutomaticThresholdSize=()=>{const t=this.responseData.map(o=>Number(o[this.valueKey].raw)),s=Math.min(...t),i=Math.max(...t),e=Math.ceil((i-s)/this.bucketCount);return{min:s,max:i,bucketSize:e}};this.setBucketCount=()=>{const{buckets:t}=this.options;if(this.hasRagScore)if(this.useRagColour)this.bucketCount=3;else{const s=this.responseData.reduce((i,e)=>(e[this.valueKey].rag!==void 0&&i.push(e[this.valueKey].rag),i),[]);this.bucketCount=Math.max(...s)+1}else t?this.bucketCount=t.length:this.bucketCount=3};this.getBucketForValue=(t,s)=>{let i="",e=0;return s!==void 0?{colour:this.buckets[s].hexColour||i,score:s}:(this.buckets.forEach((o,a)=>{const{min:r,max:n}=o;!r&&n&&t<=n&&(i=o.hexColour||i,e=a),r&&t>=r&&n&&t<=n&&(i=o.hexColour||i,e=a),r&&!n&&t>=r&&(i=o.hexColour||i,e=a)}),{colour:i,score:e})};this.getBuckets=()=>this.buckets;this.responseData=t,this.initFromOptions(s),this.valueKey=i,this.hasRagScore=t[0][this.valueKey].rag!==void 0,this.autoBucketing=!!e,o&&(this.ragColours=o),this.initBuckets()}}var d=c;0&&(module.exports={Buckets});
2
2
  //# sourceMappingURL=Buckets.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/dpr/components/_charts/chart/Buckets.ts"],
4
- "sourcesContent": ["/* eslint-disable prefer-destructuring */\nimport { withAlphaHex } from 'with-alpha-hex'\nimport { DashboardDataResponse } from '../../../types/Metrics'\nimport {\n DashboardVisualisation,\n DashboardVisualisationBucket,\n BucketDashboardVisualisationOptions,\n} from '../../_dashboards/dashboard/types'\n\nclass Buckets {\n private baseColour = '#1d70b8'\n\n private ragColours: string[] = ['#00703c', '#ffdd00', '#d4351c']\n\n private buckets: DashboardVisualisationBucket[] = []\n\n private useRagColours: boolean\n\n private bucketCount: number\n\n private onlyBucketColoursDefined: boolean\n\n private autoBucketing: boolean\n\n private hasRagScore = false\n\n private valueKey: string\n\n private options: BucketDashboardVisualisationOptions\n\n responseData: DashboardDataResponse[]\n\n constructor(\n responseData: DashboardDataResponse[],\n definition: DashboardVisualisation,\n valueKey: string,\n autoBucketing?: boolean,\n ragColours?: string[],\n ) {\n this.responseData = responseData\n this.initFromOptions(definition)\n this.valueKey = valueKey\n this.hasRagScore = responseData[0][this.valueKey].rag !== undefined\n this.autoBucketing = autoBucketing\n if (ragColours) this.ragColours = ragColours\n this.initBuckets()\n }\n\n private initFromOptions = (definition: DashboardVisualisation) => {\n this.options = <BucketDashboardVisualisationOptions>definition.options || {}\n this.baseColour = this.options?.baseColour || this.baseColour\n this.useRagColours = this.options?.useRagColours || false\n this.onlyBucketColoursDefined = this.options?.buckets?.every(\n (bucket) => !bucket.max && !bucket.min && bucket.hexColour !== undefined,\n )\n }\n\n private initBuckets = () => {\n const { buckets } = this.options\n\n this.setBucketCount()\n this.initBucketColours()\n\n if (buckets) {\n if (this.hasRagScore) {\n if (this.onlyBucketColoursDefined) {\n this.buckets = buckets\n }\n } else if (!this.hasRagScore && this.onlyBucketColoursDefined && this.autoBucketing) {\n this.initAutomaticThresholdBucket()\n } else {\n this.initCustomThresholdBuckets()\n }\n } else if (!buckets && !this.hasRagScore && this.autoBucketing) {\n this.initAutomaticThresholdBucket()\n }\n }\n\n private initCustomThresholdBuckets = () => {\n this.buckets = this.options.buckets.map((bucket, i) => {\n return {\n ...this.buckets[i],\n ...bucket,\n }\n })\n }\n\n /**\n * Initialises the bucket thresholds by defining the range between the min and max\n * and dividing into 3 equal parts\n */\n private initAutomaticThresholdBucket = () => {\n const { min, max, bucketSize } = this.setAutomaticThresholdSize()\n let maxValue = 0\n this.buckets = this.buckets.map((bucket, i) => {\n let minValue = min\n if (i !== 0) minValue = maxValue + 1\n maxValue = bucketSize * (i + 1) + min\n if (i === this.buckets.length - 1) maxValue = max\n\n return {\n hexColour: this.options?.buckets ? this.options.buckets[i]?.hexColour : bucket.hexColour,\n min: minValue,\n max: maxValue,\n }\n })\n }\n\n private initBucketColours = () => {\n if (this.useRagColours && this.bucketCount === 3) {\n this.buckets = Array.from(new Array(this.bucketCount)).map((d, i) => {\n return {\n hexColour: this.ragColours[i],\n }\n })\n } else {\n const alphaDivision = 1 / this.bucketCount\n this.buckets = Array.from(new Array(this.bucketCount)).map((d, i) => {\n const division = alphaDivision * (i + 1)\n return {\n hexColour: withAlphaHex(this.baseColour, division),\n }\n })\n }\n }\n\n private setAutomaticThresholdSize = () => {\n const values = this.responseData.map((resData) => Number(resData[this.valueKey].raw))\n const min = Math.min(...values)\n const max = Math.max(...values)\n const bucketSize = Math.ceil((max - min) / this.bucketCount)\n\n return {\n min,\n max,\n bucketSize,\n }\n }\n\n private setBucketCount = () => {\n const { buckets } = this.options\n if (this.hasRagScore) {\n if (this.useRagColours) {\n this.bucketCount = 3\n } else {\n this.bucketCount =\n Math.max(...this.responseData.map((resData: DashboardDataResponse) => resData[this.valueKey].rag)) + 1\n }\n } else if (buckets) {\n this.bucketCount = buckets.length\n } else {\n this.bucketCount = 3\n }\n }\n\n getBucketForValue = (value: number, ragScore?: number) => {\n let colour\n let score\n\n if (ragScore !== undefined) {\n return {\n colour: this.buckets[ragScore].hexColour,\n score: ragScore,\n }\n }\n\n this.buckets.forEach((bucket, index) => {\n const { min, max } = bucket\n // First bucket\n if (!min && max && value <= max) {\n colour = bucket.hexColour\n score = index.toString()\n }\n // middle buckets\n if (min && value >= bucket.min && max && value <= bucket.max) {\n colour = bucket.hexColour\n score = index.toString()\n }\n // last bucket\n if (min && !max && value >= min) {\n colour = bucket.hexColour\n score = index.toString()\n }\n })\n\n return {\n colour,\n score,\n }\n }\n\n getBuckets = () => {\n return this.buckets\n }\n}\n\nexport { Buckets }\nexport default Buckets\n"],
5
- "mappings": "4ZAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,YAAAC,IAAA,eAAAC,EAAAJ,GAC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ACAC,EAEJ,OAAIF,IAAa,OACR,CACL,OAAQ,KAAK,QAAQA,CAAQ,EAAE,UAC/B,MAAOA,CACT,GAGF,KAAK,QAAQ,QAAQ,CAACd,EAAQiB,IAAU,CACtC,KAAM,CAAE,IAAAd,EAAK,IAAAC,CAAI,EAAIJ,EAEjB,CAACG,GAAOC,GAAOS,GAAST,IAC1BW,EAASf,EAAO,UAChBgB,EAAQC,EAAM,SAAS,GAGrBd,GAAOU,GAASb,EAAO,KAAOI,GAAOS,GAASb,EAAO,MACvDe,EAASf,EAAO,UAChBgB,EAAQC,EAAM,SAAS,GAGrBd,GAAO,CAACC,GAAOS,GAASV,IAC1BY,EAASf,EAAO,UAChBgB,EAAQC,EAAM,SAAS,EAE3B,CAAC,EAEM,CACL,OAAAF,EACA,MAAAC,CACF,EACF,EAEA,gBAAa,IACJ,KAAK,QAzJZ,KAAK,aAAerB,EACpB,KAAK,gBAAgBC,CAAU,EAC/B,KAAK,SAAWC,EAChB,KAAK,YAAcF,EAAa,CAAC,EAAE,KAAK,QAAQ,EAAE,MAAQ,OAC1D,KAAK,cAAgBG,EACjBC,IAAY,KAAK,WAAaA,GAClC,KAAK,YAAY,CACnB,CAoJF,CAGA,IAAOP,EAAQD",
6
- "names": ["Buckets_exports", "__export", "Buckets", "Buckets_default", "__toCommonJS", "import_with_alpha_hex", "responseData", "definition", "valueKey", "autoBucketing", "ragColours", "bucket", "buckets", "i", "min", "max", "bucketSize", "maxValue", "minValue", "d", "alphaDivision", "division", "values", "resData", "value", "ragScore", "colour", "score", "index"]
4
+ "sourcesContent": ["/* eslint-disable prefer-destructuring */\nimport { withAlphaHex } from 'with-alpha-hex'\nimport { DashboardDataResponse, DashboardDataResponseWithRag } from '../../../types/Metrics'\nimport {\n DashboardVisualisationBucket,\n BucketDashboardVisualisationOptions,\n} from '../../_dashboards/dashboard-visualisation/types'\nimport { components } from '../../../types/api'\n\nclass Buckets {\n private baseColour = '#1d70b8'\n\n private ragColours: string[] = ['#00703c', '#ffdd00', '#d4351c']\n\n private buckets: DashboardVisualisationBucket[] = []\n\n private useRagColour = false\n\n private bucketCount = 0\n\n private onlyBucketColoursDefined = false\n\n private autoBucketing = false\n\n private hasRagScore = false\n\n private valueKey: string\n\n private options: BucketDashboardVisualisationOptions = {}\n\n responseData: DashboardDataResponse[]\n\n constructor(\n responseData: DashboardDataResponse[],\n definition: components['schemas']['DashboardVisualisationDefinition'],\n valueKey: string,\n autoBucketing?: boolean,\n ragColours?: string[],\n ) {\n this.responseData = responseData\n this.initFromOptions(definition)\n this.valueKey = valueKey\n this.hasRagScore = responseData[0][this.valueKey].rag !== undefined\n this.autoBucketing = Boolean(autoBucketing)\n if (ragColours) this.ragColours = ragColours\n this.initBuckets()\n }\n\n private initFromOptions = (definition: components['schemas']['DashboardVisualisationDefinition']) => {\n this.options = <BucketDashboardVisualisationOptions>definition.options || {}\n this.baseColour = this.options?.baseColour || this.baseColour\n this.useRagColour = this.options?.useRagColour || false\n this.onlyBucketColoursDefined =\n this.options && this.options.buckets\n ? this.options?.buckets?.every((bucket) => !bucket.max && !bucket.min && bucket.hexColour !== undefined)\n : false\n }\n\n private initBuckets = () => {\n const { buckets } = this.options\n\n this.setBucketCount()\n this.initBucketColours()\n\n if (buckets) {\n if (this.hasRagScore) {\n if (this.onlyBucketColoursDefined) {\n this.buckets = buckets\n }\n } else if (!this.hasRagScore && this.onlyBucketColoursDefined && this.autoBucketing) {\n this.initAutomaticThresholdBucket()\n } else {\n this.initCustomThresholdBuckets()\n }\n } else if (!buckets && !this.hasRagScore && this.autoBucketing) {\n this.initAutomaticThresholdBucket()\n }\n }\n\n private initCustomThresholdBuckets = () => {\n this.buckets = this.options.buckets\n ? this.options.buckets.map((bucket, i) => {\n return {\n ...this.buckets[i],\n ...bucket,\n }\n })\n : []\n }\n\n /**\n * Initialises the bucket thresholds by defining the range between the min and max\n * and dividing into 3 equal parts\n */\n private initAutomaticThresholdBucket = () => {\n const { min, max, bucketSize } = this.setAutomaticThresholdSize()\n let maxValue = 0\n this.buckets = this.buckets.map((bucket, i) => {\n let minValue = min\n if (i !== 0) minValue = maxValue + 1\n maxValue = bucketSize * (i + 1) + min\n if (i === this.buckets.length - 1) maxValue = max\n\n return {\n hexColour: this.options?.buckets ? this.options.buckets[i]?.hexColour : bucket.hexColour,\n min: minValue,\n max: maxValue,\n }\n })\n }\n\n private initBucketColours = () => {\n if (this.useRagColour && this.bucketCount === 3) {\n this.buckets = Array.from(new Array(this.bucketCount)).map((d, i) => {\n return {\n hexColour: this.ragColours[i],\n }\n })\n } else {\n const alphaDivision = 1 / this.bucketCount\n this.buckets = Array.from(new Array(this.bucketCount)).map((d, i) => {\n const division = alphaDivision * (i + 1)\n return {\n hexColour: withAlphaHex(this.baseColour, division),\n }\n })\n }\n }\n\n private setAutomaticThresholdSize = () => {\n const values = this.responseData.map((resData) => Number(resData[this.valueKey].raw))\n const min = Math.min(...values)\n const max = Math.max(...values)\n const bucketSize = Math.ceil((max - min) / this.bucketCount)\n\n return {\n min,\n max,\n bucketSize,\n }\n }\n\n private setBucketCount = () => {\n const { buckets } = this.options\n if (this.hasRagScore) {\n if (this.useRagColour) {\n this.bucketCount = 3\n } else {\n const allRags: number[] = this.responseData.reduce((acc: number[], resData: DashboardDataResponse) => {\n if (resData[this.valueKey].rag !== undefined) {\n acc.push(<number>resData[this.valueKey].rag)\n }\n return acc\n }, [])\n this.bucketCount = Math.max(...allRags) + 1\n }\n } else if (buckets) {\n this.bucketCount = buckets.length\n } else {\n this.bucketCount = 3\n }\n }\n\n getBucketForValue = (value: number, ragScore?: number): { colour: string; score: number } => {\n let colour = ''\n let score = 0\n\n if (ragScore !== undefined) {\n return {\n colour: this.buckets[ragScore].hexColour || colour,\n score: ragScore,\n }\n }\n\n this.buckets.forEach((bucket, index) => {\n const { min, max } = bucket\n // First bucket\n if (!min && max && value <= max) {\n colour = bucket.hexColour || colour\n score = index\n }\n // middle buckets\n if (min && value >= min && max && value <= max) {\n colour = bucket.hexColour || colour\n score = index\n }\n // last bucket\n if (min && !max && value >= min) {\n colour = bucket.hexColour || colour\n score = index\n }\n })\n\n return {\n colour,\n score,\n }\n }\n\n getBuckets = () => {\n return this.buckets\n }\n}\n\nexport { Buckets }\nexport default Buckets\n"],
5
+ "mappings": "4ZAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,YAAAC,IAAA,eAAAC,EAAAJ,GACA,IAAAK,EAA6B,0BAQ7B,MAAMH,CAAQ,CAuBZ,YACEI,EACAC,EACAC,EACAC,EACAC,EACA,CA5BF,KAAQ,WAAa,UAErB,KAAQ,WAAuB,CAAC,UAAW,UAAW,SAAS,EAE/D,KAAQ,QAA0C,CAAC,EAEnD,KAAQ,aAAe,GAEvB,KAAQ,YAAc,EAEtB,KAAQ,yBAA2B,GAEnC,KAAQ,cAAgB,GAExB,KAAQ,YAAc,GAItB,KAAQ,QAA+C,CAAC,EAoBxD,KAAQ,gBAAmBH,GAA0E,CACnG,KAAK,QAA+CA,EAAW,SAAW,CAAC,EAC3E,KAAK,WAAa,KAAK,SAAS,YAAc,KAAK,WACnD,KAAK,aAAe,KAAK,SAAS,cAAgB,GAClD,KAAK,yBACH,KAAK,SAAW,KAAK,QAAQ,QACzB,KAAK,SAAS,SAAS,MAAOI,GAAW,CAACA,EAAO,KAAO,CAACA,EAAO,KAAOA,EAAO,YAAc,MAAS,EACrG,EACR,EAEA,KAAQ,YAAc,IAAM,CAC1B,KAAM,CAAE,QAAAC,CAAQ,EAAI,KAAK,QAEzB,KAAK,eAAe,EACpB,KAAK,kBAAkB,EAEnBA,EACE,KAAK,YACH,KAAK,2BACP,KAAK,QAAUA,GAER,CAAC,KAAK,aAAe,KAAK,0BAA4B,KAAK,cACpE,KAAK,6BAA6B,EAElC,KAAK,2BAA2B,EAEzB,CAACA,GAAW,CAAC,KAAK,aAAe,KAAK,eAC/C,KAAK,6BAA6B,CAEtC,EAEA,KAAQ,2BAA6B,IAAM,CACzC,KAAK,QAAU,KAAK,QAAQ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D,KAAK,cAAgB,EAAQG,EACzBC,IAAY,KAAK,WAAaA,GAClC,KAAK,YAAY,CACnB,CA4JF,CAGA,IAAOP,EAAQD",
6
+ "names": ["Buckets_exports", "__export", "Buckets", "Buckets_default", "__toCommonJS", "import_with_alpha_hex", "responseData", "definition", "valueKey", "autoBucketing", "ragColours", "bucket", "buckets", "i", "min", "max", "bucketSize", "maxValue", "minValue", "d", "alphaDivision", "division", "values", "resData", "allRags", "acc", "value", "ragScore", "colour", "score", "index"]
7
7
  }
@@ -1,11 +1,11 @@
1
1
  /* eslint-disable prefer-destructuring */
2
2
  import { withAlphaHex } from 'with-alpha-hex'
3
- import { DashboardDataResponse } from '../../../types/Metrics'
3
+ import { DashboardDataResponse, DashboardDataResponseWithRag } from '../../../types/Metrics'
4
4
  import {
5
- DashboardVisualisation,
6
5
  DashboardVisualisationBucket,
7
6
  BucketDashboardVisualisationOptions,
8
- } from '../../_dashboards/dashboard/types'
7
+ } from '../../_dashboards/dashboard-visualisation/types'
8
+ import { components } from '../../../types/api'
9
9
 
10
10
  class Buckets {
11
11
  private baseColour = '#1d70b8'
@@ -14,25 +14,25 @@ class Buckets {
14
14
 
15
15
  private buckets: DashboardVisualisationBucket[] = []
16
16
 
17
- private useRagColours: boolean
17
+ private useRagColour = false
18
18
 
19
- private bucketCount: number
19
+ private bucketCount = 0
20
20
 
21
- private onlyBucketColoursDefined: boolean
21
+ private onlyBucketColoursDefined = false
22
22
 
23
- private autoBucketing: boolean
23
+ private autoBucketing = false
24
24
 
25
25
  private hasRagScore = false
26
26
 
27
27
  private valueKey: string
28
28
 
29
- private options: BucketDashboardVisualisationOptions
29
+ private options: BucketDashboardVisualisationOptions = {}
30
30
 
31
31
  responseData: DashboardDataResponse[]
32
32
 
33
33
  constructor(
34
34
  responseData: DashboardDataResponse[],
35
- definition: DashboardVisualisation,
35
+ definition: components['schemas']['DashboardVisualisationDefinition'],
36
36
  valueKey: string,
37
37
  autoBucketing?: boolean,
38
38
  ragColours?: string[],
@@ -41,18 +41,19 @@ class Buckets {
41
41
  this.initFromOptions(definition)
42
42
  this.valueKey = valueKey
43
43
  this.hasRagScore = responseData[0][this.valueKey].rag !== undefined
44
- this.autoBucketing = autoBucketing
44
+ this.autoBucketing = Boolean(autoBucketing)
45
45
  if (ragColours) this.ragColours = ragColours
46
46
  this.initBuckets()
47
47
  }
48
48
 
49
- private initFromOptions = (definition: DashboardVisualisation) => {
49
+ private initFromOptions = (definition: components['schemas']['DashboardVisualisationDefinition']) => {
50
50
  this.options = <BucketDashboardVisualisationOptions>definition.options || {}
51
51
  this.baseColour = this.options?.baseColour || this.baseColour
52
- this.useRagColours = this.options?.useRagColours || false
53
- this.onlyBucketColoursDefined = this.options?.buckets?.every(
54
- (bucket) => !bucket.max && !bucket.min && bucket.hexColour !== undefined,
55
- )
52
+ this.useRagColour = this.options?.useRagColour || false
53
+ this.onlyBucketColoursDefined =
54
+ this.options && this.options.buckets
55
+ ? this.options?.buckets?.every((bucket) => !bucket.max && !bucket.min && bucket.hexColour !== undefined)
56
+ : false
56
57
  }
57
58
 
58
59
  private initBuckets = () => {
@@ -77,12 +78,14 @@ class Buckets {
77
78
  }
78
79
 
79
80
  private initCustomThresholdBuckets = () => {
80
- this.buckets = this.options.buckets.map((bucket, i) => {
81
- return {
82
- ...this.buckets[i],
83
- ...bucket,
84
- }
85
- })
81
+ this.buckets = this.options.buckets
82
+ ? this.options.buckets.map((bucket, i) => {
83
+ return {
84
+ ...this.buckets[i],
85
+ ...bucket,
86
+ }
87
+ })
88
+ : []
86
89
  }
87
90
 
88
91
  /**
@@ -107,7 +110,7 @@ class Buckets {
107
110
  }
108
111
 
109
112
  private initBucketColours = () => {
110
- if (this.useRagColours && this.bucketCount === 3) {
113
+ if (this.useRagColour && this.bucketCount === 3) {
111
114
  this.buckets = Array.from(new Array(this.bucketCount)).map((d, i) => {
112
115
  return {
113
116
  hexColour: this.ragColours[i],
@@ -140,11 +143,16 @@ class Buckets {
140
143
  private setBucketCount = () => {
141
144
  const { buckets } = this.options
142
145
  if (this.hasRagScore) {
143
- if (this.useRagColours) {
146
+ if (this.useRagColour) {
144
147
  this.bucketCount = 3
145
148
  } else {
146
- this.bucketCount =
147
- Math.max(...this.responseData.map((resData: DashboardDataResponse) => resData[this.valueKey].rag)) + 1
149
+ const allRags: number[] = this.responseData.reduce((acc: number[], resData: DashboardDataResponse) => {
150
+ if (resData[this.valueKey].rag !== undefined) {
151
+ acc.push(<number>resData[this.valueKey].rag)
152
+ }
153
+ return acc
154
+ }, [])
155
+ this.bucketCount = Math.max(...allRags) + 1
148
156
  }
149
157
  } else if (buckets) {
150
158
  this.bucketCount = buckets.length
@@ -153,13 +161,13 @@ class Buckets {
153
161
  }
154
162
  }
155
163
 
156
- getBucketForValue = (value: number, ragScore?: number) => {
157
- let colour
158
- let score
164
+ getBucketForValue = (value: number, ragScore?: number): { colour: string; score: number } => {
165
+ let colour = ''
166
+ let score = 0
159
167
 
160
168
  if (ragScore !== undefined) {
161
169
  return {
162
- colour: this.buckets[ragScore].hexColour,
170
+ colour: this.buckets[ragScore].hexColour || colour,
163
171
  score: ragScore,
164
172
  }
165
173
  }
@@ -168,18 +176,18 @@ class Buckets {
168
176
  const { min, max } = bucket
169
177
  // First bucket
170
178
  if (!min && max && value <= max) {
171
- colour = bucket.hexColour
172
- score = index.toString()
179
+ colour = bucket.hexColour || colour
180
+ score = index
173
181
  }
174
182
  // middle buckets
175
- if (min && value >= bucket.min && max && value <= bucket.max) {
176
- colour = bucket.hexColour
177
- score = index.toString()
183
+ if (min && value >= min && max && value <= max) {
184
+ colour = bucket.hexColour || colour
185
+ score = index
178
186
  }
179
187
  // last bucket
180
188
  if (min && !max && value >= min) {
181
- colour = bucket.hexColour
182
- score = index.toString()
189
+ colour = bucket.hexColour || colour
190
+ score = index
183
191
  }
184
192
  })
185
193
 
@@ -1,2 +1,2 @@
1
- var g=Object.create;var h=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var F=Object.getPrototypeOf,V=Object.prototype.hasOwnProperty;var x=(e,i)=>{for(var t in i)h(e,t,{get:i[t],enumerable:!0})},p=(e,i,t,a)=>{if(i&&typeof i=="object"||typeof i=="function")for(let s of w(i))!V.call(e,s)&&s!==t&&h(e,s,{get:()=>i[s],enumerable:!(a=M(i,s))||a.enumerable});return e};var d=(e,i,t)=>(t=e!=null?g(F(e)):{},p(i||!e||!e.__esModule?h(t,"default",{value:e,enumerable:!0}):t,e)),B=e=>p(h({},"__esModule",{value:!0}),e);var C={};x(C,{HeatmapChart:()=>m,default:()=>Y});module.exports=B(C);var n=d(require("dayjs")),y=require("../../../_dashboards/dashboard/types"),D=d(require("../../../../utils/datasetHelper")),b=d(require("../DashboardVisualisation")),f=d(require("../Buckets"));class m extends b.default{constructor(t,a,s){super(t,s);this.data=[];this.dayDateFormat="DD/MM/YYYY";this.buckets=[];this.initUnit=()=>{this.unit=this.columns.measures[0].unit?this.columns.measures[0].unit:void 0};this.setLabel=()=>{const{id:t,display:a}=this.columns.measures[1];this.valueKey=t,this.label=a};this.validateDefinition=()=>{const{id:t,columns:a,type:s}=this.definition,o=[];if(a.measures.length!==2?o.push(`Measures should only have 2 columns defined. Only found ${a.measures.length}`):s===y.DashboardVisualisationType.MATRIX_TIMESERIES&&a.measures[0].id!=="ts"&&o.push(`measure at index 0 has incorrect ID. Expected ID to be "ts". Found "${a.measures[0].id}"`),o.length){const r=`Validation: Visualisaton definition: ID: ${t}, type: ${s}, errors: ${o.join(",")}`;throw new Error(r)}};this.initTimeseriesData=()=>{const t=D.default.groupRowsByTimestamp(this.responseData);this.data=t.map(a=>{const{raw:s,rag:o}=a[0][this.valueKey],r=a[0].ts.raw,k=Number(s),v=o!==void 0?Number(a[0][this.valueKey].rag):void 0;let u,l;switch(this.granularity){case"hourly":break;case"weekly":u=(0,n.default)(r,this.dayDateFormat).format("ddd"),l=(0,n.default)(r,this.dayDateFormat).week();break;case"daily":u=(0,n.default)(r,this.dayDateFormat).format("MMM YY"),l=(0,n.default)(r,this.dayDateFormat).format("D");break;case"monthly":{const c=r.split(" ");u=c[1],l=c[0]}break;case"annually":u="year",l=r;break;default:u=(0,n.default)(r,this.dayDateFormat).format("MMM YY"),l=(0,n.default)(r,this.dayDateFormat).format("D");break}return{y:l,x:u,v:k,r:v}})};this.bucketData=()=>{this.data=this.data.map(t=>{const{v:a,r:s}=t,o=this.bucketsHelper.getBucketForValue(a,s);return{...t,c:o.colour}})};this.build=()=>(this.validateDefinition(),this.initTimeseriesData(),this.bucketData(),{type:this.type,unit:this.unit,timeseries:!0,data:{datasets:[{label:this.label,data:this.data}]}});this.granularity=a,this.setLabel(),this.initUnit(),this.bucketsHelper=new f.default(t,this.definition,this.valueKey,!0),this.buckets=this.bucketsHelper.getBuckets()}}var Y=m;0&&(module.exports={HeatmapChart});
1
+ var M=Object.create;var l=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var V=Object.getPrototypeOf,T=Object.prototype.hasOwnProperty;var w=(e,s)=>{for(var t in s)l(e,t,{get:s[t],enumerable:!0})},D=(e,s,t,a)=>{if(s&&typeof s=="object"||typeof s=="function")for(let i of x(s))!T.call(e,i)&&i!==t&&l(e,i,{get:()=>s[i],enumerable:!(a=g(s,i))||a.enumerable});return e};var m=(e,s,t)=>(t=e!=null?M(V(e)):{},D(s||!e||!e.__esModule?l(t,"default",{value:e,enumerable:!0}):t,e)),C=e=>D(l({},"__esModule",{value:!0}),e);var F={};w(F,{HeatmapChart:()=>p,default:()=>E});module.exports=C(F);var n=m(require("dayjs")),d=require("../../../_dashboards/dashboard-visualisation/types"),y=m(require("../../../../utils/datasetHelper")),b=m(require("../../../_dashboards/dashboard-visualisation/DashboardVisualisation")),f=m(require("../Buckets"));class p extends b.default{constructor(t,a,i){super(t,i);this.data=[];this.dayDateFormat="DD/MM/YYYY";this.valueKey="";this.label="";this.buckets=[];this.initUnit=()=>{this.unit=this.columns.measures[0].unit?this.columns.measures[0].unit:void 0};this.setLabel=()=>{const{id:t,display:a}=this.columns.measures[1];this.valueKey=t,this.label=a||""};this.validateDefinition=()=>{const{id:t,columns:a,type:i}=this.definition,o=[];if(a.measures.length!==2?o.push(`Measures should only have 2 columns defined. Only found ${a.measures.length}`):i===d.DashboardVisualisationType.MATRIX_TIMESERIES&&a.measures[0].id!=="ts"&&o.push(`measure at index 0 has incorrect ID. Expected ID to be "ts". Found "${a.measures[0].id}"`),o.length){const r=`Validation: Visualisaton definition: ID: ${t}, type: ${i}, errors: ${o.join(",")}`;throw new Error(r)}};this.initTimeseriesData=()=>{const t=y.default.groupRowsByTimestamp(this.responseData);this.data=t.map(a=>{const{raw:i,rag:o}=a[0][this.valueKey],r=a[0].ts.raw,k=Number(i),v=o!==void 0?Number(a[0][this.valueKey].rag):void 0;let u=0,h=0;switch(this.granularity){case"hourly":break;case"weekly":u=(0,n.default)(r,this.dayDateFormat).format("ddd"),h=(0,n.default)(r,this.dayDateFormat).week();break;case"daily":u=(0,n.default)(r,this.dayDateFormat).format("MMM YY"),h=(0,n.default)(r,this.dayDateFormat).format("D");break;case"monthly":{const c=r.split(" ");u=c[1],h=c[0]}break;case"annually":u="year",h=r;break;default:u=(0,n.default)(r,this.dayDateFormat).format("MMM YY"),h=(0,n.default)(r,this.dayDateFormat).format("D");break}return{y:h,x:u,v:k,r:v}})};this.bucketData=()=>{this.data=this.data.map(t=>{const{v:a,r:i}=t,o=this.bucketsHelper.getBucketForValue(a,i);return{...t,c:o.colour}})};this.build=()=>(this.validateDefinition(),this.initTimeseriesData(),this.bucketData(),{type:this.type,unit:this.unit,timeseries:!0,data:{datasets:[{label:this.label,data:this.data}]}});this.granularity=a,this.isTimeseriesChart=this.type===d.DashboardVisualisationType.LINE_TIMESERIES,this.setLabel(),this.initUnit(),this.bucketsHelper=new f.default(t,this.definition,this.valueKey,!0),this.buckets=this.bucketsHelper.getBuckets()}}var E=p;0&&(module.exports={HeatmapChart});
2
2
  //# sourceMappingURL=HeatmapChart.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/dpr/components/_charts/chart/heatmap/HeatmapChart.ts"],
4
- "sourcesContent": ["/* eslint-disable prefer-destructuring */\nimport dayjs from 'dayjs'\nimport { Granularity } from '../../../_inputs/granular-date-range/types'\nimport { DashboardDataResponse } from '../../../../types/Metrics'\nimport {\n DashboardVisualisation,\n DashboardVisualisationType,\n DashboardVisualisationBucket,\n} from '../../../_dashboards/dashboard/types'\nimport { ChartData, MatrixChartData } from '../../../../types/Charts'\nimport DatasetHelper from '../../../../utils/datasetHelper'\nimport DashboardVisualisationClass from '../DashboardVisualisation'\nimport Buckets from '../Buckets'\n\nclass HeatmapChart extends DashboardVisualisationClass {\n private granularity: Granularity\n\n private data: MatrixChartData[] = []\n\n private dayDateFormat = 'DD/MM/YYYY'\n\n private valueKey: string\n\n private label: string\n\n private buckets: DashboardVisualisationBucket[] = []\n\n private bucketsHelper: Buckets\n\n constructor(responseData: DashboardDataResponse[], granularity: Granularity, definition: DashboardVisualisation) {\n super(responseData, definition)\n\n this.granularity = granularity\n this.setLabel()\n this.initUnit()\n this.bucketsHelper = new Buckets(responseData, this.definition, this.valueKey, true)\n this.buckets = this.bucketsHelper.getBuckets()\n }\n\n initUnit = () => {\n // todo\n this.unit = this.columns.measures[0].unit ? this.columns.measures[0].unit : undefined\n }\n\n private setLabel = () => {\n const { id, display } = this.columns.measures[1]\n this.valueKey = id\n this.label = display\n }\n\n private validateDefinition = () => {\n const { id, columns, type } = this.definition\n const errors = []\n\n // Validate measures\n if (columns.measures.length !== 2) {\n errors.push(`Measures should only have 2 columns defined. Only found ${columns.measures.length}`)\n } else if (type === DashboardVisualisationType.MATRIX_TIMESERIES) {\n if (columns.measures[0].id !== 'ts') {\n errors.push(`measure at index 0 has incorrect ID. Expected ID to be \"ts\". Found \"${columns.measures[0].id}\"`)\n }\n }\n\n // Throw the error\n if (errors.length) {\n const message = `Validation: Visualisaton definition: ID: ${id}, type: ${type}, errors: ${errors.join(',')}`\n throw new Error(message)\n }\n }\n\n private initTimeseriesData = () => {\n const timeBlockData = DatasetHelper.groupRowsByTimestamp(this.responseData)\n\n this.data = timeBlockData.map((tsData) => {\n const { raw, rag } = tsData[0][this.valueKey]\n const tsRaw = tsData[0].ts.raw\n\n const v = Number(raw)\n const r = rag !== undefined ? Number(tsData[0][this.valueKey].rag) : undefined\n let x\n let y\n\n switch (this.granularity) {\n case 'hourly':\n break\n case 'weekly':\n x = dayjs(tsRaw, this.dayDateFormat).format('ddd')\n y = dayjs(tsRaw, this.dayDateFormat).week()\n break\n case 'daily':\n x = dayjs(tsRaw, this.dayDateFormat).format('MMM YY')\n y = dayjs(tsRaw, this.dayDateFormat).format('D')\n break\n case 'monthly':\n {\n const ts = (<string>tsRaw).split(' ')\n x = ts[1]\n y = ts[0]\n }\n break\n case 'annually':\n x = 'year'\n y = <string>tsRaw\n break\n default:\n x = dayjs(tsRaw, this.dayDateFormat).format('MMM YY')\n y = dayjs(tsRaw, this.dayDateFormat).format('D')\n break\n }\n return { y, x, v, r }\n })\n }\n\n private bucketData = () => {\n this.data = this.data.map((d) => {\n const { v, r } = d\n const bucketData = this.bucketsHelper.getBucketForValue(v, r)\n return { ...d, c: bucketData.colour }\n })\n }\n\n build = (): ChartData => {\n this.validateDefinition()\n this.initTimeseriesData()\n this.bucketData()\n\n return {\n type: this.type,\n unit: this.unit,\n timeseries: true,\n data: {\n datasets: [\n {\n label: this.label,\n data: this.data,\n },\n ],\n },\n }\n }\n}\n\nexport { HeatmapChart }\nexport default HeatmapChart\n"],
5
- "mappings": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kBAAAE,EAAA,YAAAC,IAAA,eAAAC,EAAAJ,GACA,IAAAK,EAAkB,oBAGlBC,EAIO,gDAEPC,EAA0B,8CAC1BC,EAAwC,wCACxCC,EAAoB,yBAEpB,MAAMP,UAAqB,EAAAQ,OAA4B,CAerD,YAAYC,EAAuCC,EAA0BC,EAAoC,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QvB,EAAc,KAAK,WAAY,KAAK,SAAU,EAAI,EACnF,KAAK,QAAU,KAAK,cAAc,WAAW,CAC/C,CAuGF,CAGA,IAAOR,EAAQD",
4
+ "sourcesContent": ["/* eslint-disable prefer-destructuring */\nimport dayjs from 'dayjs'\nimport { Granularity } from '../../../_inputs/granular-date-range/types'\nimport { DashboardDataResponse } from '../../../../types/Metrics'\nimport {\n DashboardVisualisationType,\n DashboardVisualisationBucket,\n DashboardVisualisationData,\n} from '../../../_dashboards/dashboard-visualisation/types'\nimport { MatrixChartData } from './types'\nimport DatasetHelper from '../../../../utils/datasetHelper'\nimport DashboardVisualisationClass from '../../../_dashboards/dashboard-visualisation/DashboardVisualisation'\nimport Buckets from '../Buckets'\nimport { components } from '../../../../types/api'\n\nclass HeatmapChart extends DashboardVisualisationClass {\n private granularity: Granularity\n\n private data: MatrixChartData[] = []\n\n private dayDateFormat = 'DD/MM/YYYY'\n\n private valueKey = ''\n\n private label = ''\n\n private buckets: DashboardVisualisationBucket[] = []\n\n private bucketsHelper: Buckets\n\n private isTimeseriesChart: boolean\n\n constructor(\n responseData: DashboardDataResponse[],\n granularity: Granularity,\n definition: components['schemas']['DashboardVisualisationDefinition'],\n ) {\n super(responseData, definition)\n\n this.granularity = granularity\n this.isTimeseriesChart = <DashboardVisualisationType>this.type === DashboardVisualisationType.LINE_TIMESERIES\n this.setLabel()\n this.initUnit()\n this.bucketsHelper = new Buckets(responseData, this.definition, this.valueKey, true)\n this.buckets = this.bucketsHelper.getBuckets()\n }\n\n initUnit = () => {\n // todo\n this.unit = this.columns.measures[0].unit ? this.columns.measures[0].unit : undefined\n }\n\n private setLabel = () => {\n const { id, display } = this.columns.measures[1]\n this.valueKey = id\n this.label = display || ''\n }\n\n private validateDefinition = () => {\n const { id, columns, type } = this.definition\n const errors = []\n\n // Validate measures\n if (columns.measures.length !== 2) {\n errors.push(`Measures should only have 2 columns defined. Only found ${columns.measures.length}`)\n } else if (<DashboardVisualisationType>type === DashboardVisualisationType.MATRIX_TIMESERIES) {\n if (columns.measures[0].id !== 'ts') {\n errors.push(`measure at index 0 has incorrect ID. Expected ID to be \"ts\". Found \"${columns.measures[0].id}\"`)\n }\n }\n\n // Throw the error\n if (errors.length) {\n const message = `Validation: Visualisaton definition: ID: ${id}, type: ${type}, errors: ${errors.join(',')}`\n throw new Error(message)\n }\n }\n\n private initTimeseriesData = () => {\n const timeBlockData = DatasetHelper.groupRowsByTimestamp(this.responseData)\n\n this.data = timeBlockData.map((tsData) => {\n const { raw, rag } = tsData[0][this.valueKey]\n const tsRaw = tsData[0].ts.raw\n\n const v: MatrixChartData['v'] = Number(raw)\n const r: MatrixChartData['r'] = rag !== undefined ? Number(tsData[0][this.valueKey].rag) : undefined\n let x: MatrixChartData['x'] = 0\n let y: MatrixChartData['y'] = 0\n\n switch (this.granularity) {\n case 'hourly':\n break\n case 'weekly':\n x = dayjs(tsRaw, this.dayDateFormat).format('ddd')\n y = dayjs(tsRaw, this.dayDateFormat).week()\n break\n case 'daily':\n x = dayjs(tsRaw, this.dayDateFormat).format('MMM YY')\n y = dayjs(tsRaw, this.dayDateFormat).format('D')\n break\n case 'monthly':\n {\n const ts = (<string>tsRaw).split(' ')\n x = ts[1]\n y = ts[0]\n }\n break\n case 'annually':\n x = 'year'\n y = <string>tsRaw\n break\n default:\n x = dayjs(tsRaw, this.dayDateFormat).format('MMM YY')\n y = dayjs(tsRaw, this.dayDateFormat).format('D')\n break\n }\n return { y, x, v, r }\n })\n }\n\n private bucketData = () => {\n this.data = this.data.map((d) => {\n const { v, r } = d\n const bucketData = this.bucketsHelper.getBucketForValue(v, r)\n return { ...d, c: bucketData.colour }\n })\n }\n\n build = (): DashboardVisualisationData => {\n this.validateDefinition()\n this.initTimeseriesData()\n this.bucketData()\n\n return {\n type: this.type,\n unit: this.unit,\n timeseries: true,\n data: {\n datasets: [\n {\n label: this.label,\n data: this.data,\n },\n ],\n },\n }\n }\n}\n\nexport { HeatmapChart }\nexport default HeatmapChart\n"],
5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,MAAO,CACtC,CAAC,CACH,EAEA,WAAQ,KACN,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,WAAW,EAET,CACL,KAAM,KAAK,KACX,KAAM,KAAK,KACX,WAAY,GACZ,KAAM,CACJ,SAAU,CACR,CACE,MAAO,KAAK,MACZ,KAAM,KAAK,IACb,CACF,CACF,CACF,GA3GA,KAAK,YAAcrB,EACnB,KAAK,kBAAgD,KAAK,OAAS,6BAA2B,gBAC9F,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,cAAgB,IAAI,EAAAsB,QAAQvB,EAAc,KAAK,WAAY,KAAK,SAAU,EAAI,EACnF,KAAK,QAAU,KAAK,cAAc,WAAW,CAC/C,CAuGF,CAGA,IAAOR,EAAQD",
6
6
  "names": ["HeatmapChart_exports", "__export", "HeatmapChart", "HeatmapChart_default", "__toCommonJS", "import_dayjs", "import_types", "import_datasetHelper", "import_DashboardVisualisation", "import_Buckets", "DashboardVisualisationClass", "responseData", "granularity", "definition", "id", "display", "columns", "type", "errors", "message", "timeBlockData", "DatasetHelper", "tsData", "raw", "rag", "tsRaw", "v", "r", "x", "y", "dayjs", "ts", "d", "bucketData", "Buckets"]
7
7
  }
@@ -3,14 +3,15 @@ import dayjs from 'dayjs'
3
3
  import { Granularity } from '../../../_inputs/granular-date-range/types'
4
4
  import { DashboardDataResponse } from '../../../../types/Metrics'
5
5
  import {
6
- DashboardVisualisation,
7
6
  DashboardVisualisationType,
8
7
  DashboardVisualisationBucket,
9
- } from '../../../_dashboards/dashboard/types'
10
- import { ChartData, MatrixChartData } from '../../../../types/Charts'
8
+ DashboardVisualisationData,
9
+ } from '../../../_dashboards/dashboard-visualisation/types'
10
+ import { MatrixChartData } from './types'
11
11
  import DatasetHelper from '../../../../utils/datasetHelper'
12
- import DashboardVisualisationClass from '../DashboardVisualisation'
12
+ import DashboardVisualisationClass from '../../../_dashboards/dashboard-visualisation/DashboardVisualisation'
13
13
  import Buckets from '../Buckets'
14
+ import { components } from '../../../../types/api'
14
15
 
15
16
  class HeatmapChart extends DashboardVisualisationClass {
16
17
  private granularity: Granularity
@@ -19,18 +20,25 @@ class HeatmapChart extends DashboardVisualisationClass {
19
20
 
20
21
  private dayDateFormat = 'DD/MM/YYYY'
21
22
 
22
- private valueKey: string
23
+ private valueKey = ''
23
24
 
24
- private label: string
25
+ private label = ''
25
26
 
26
27
  private buckets: DashboardVisualisationBucket[] = []
27
28
 
28
29
  private bucketsHelper: Buckets
29
30
 
30
- constructor(responseData: DashboardDataResponse[], granularity: Granularity, definition: DashboardVisualisation) {
31
+ private isTimeseriesChart: boolean
32
+
33
+ constructor(
34
+ responseData: DashboardDataResponse[],
35
+ granularity: Granularity,
36
+ definition: components['schemas']['DashboardVisualisationDefinition'],
37
+ ) {
31
38
  super(responseData, definition)
32
39
 
33
40
  this.granularity = granularity
41
+ this.isTimeseriesChart = <DashboardVisualisationType>this.type === DashboardVisualisationType.LINE_TIMESERIES
34
42
  this.setLabel()
35
43
  this.initUnit()
36
44
  this.bucketsHelper = new Buckets(responseData, this.definition, this.valueKey, true)
@@ -45,7 +53,7 @@ class HeatmapChart extends DashboardVisualisationClass {
45
53
  private setLabel = () => {
46
54
  const { id, display } = this.columns.measures[1]
47
55
  this.valueKey = id
48
- this.label = display
56
+ this.label = display || ''
49
57
  }
50
58
 
51
59
  private validateDefinition = () => {
@@ -55,7 +63,7 @@ class HeatmapChart extends DashboardVisualisationClass {
55
63
  // Validate measures
56
64
  if (columns.measures.length !== 2) {
57
65
  errors.push(`Measures should only have 2 columns defined. Only found ${columns.measures.length}`)
58
- } else if (type === DashboardVisualisationType.MATRIX_TIMESERIES) {
66
+ } else if (<DashboardVisualisationType>type === DashboardVisualisationType.MATRIX_TIMESERIES) {
59
67
  if (columns.measures[0].id !== 'ts') {
60
68
  errors.push(`measure at index 0 has incorrect ID. Expected ID to be "ts". Found "${columns.measures[0].id}"`)
61
69
  }
@@ -75,10 +83,10 @@ class HeatmapChart extends DashboardVisualisationClass {
75
83
  const { raw, rag } = tsData[0][this.valueKey]
76
84
  const tsRaw = tsData[0].ts.raw
77
85
 
78
- const v = Number(raw)
79
- const r = rag !== undefined ? Number(tsData[0][this.valueKey].rag) : undefined
80
- let x
81
- let y
86
+ const v: MatrixChartData['v'] = Number(raw)
87
+ const r: MatrixChartData['r'] = rag !== undefined ? Number(tsData[0][this.valueKey].rag) : undefined
88
+ let x: MatrixChartData['x'] = 0
89
+ let y: MatrixChartData['y'] = 0
82
90
 
83
91
  switch (this.granularity) {
84
92
  case 'hourly':
@@ -119,7 +127,7 @@ class HeatmapChart extends DashboardVisualisationClass {
119
127
  })
120
128
  }
121
129
 
122
- build = (): ChartData => {
130
+ build = (): DashboardVisualisationData => {
123
131
  this.validateDefinition()
124
132
  this.initTimeseriesData()
125
133
  this.bucketData()
@@ -0,0 +1,2 @@
1
+ var a=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var x=(e,r,b,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of m(r))!u.call(e,n)&&n!==b&&a(e,n,{get:()=>r[n],enumerable:!(t=i(r,n))||t.enumerable});return e};var g=e=>x(a({},"__esModule",{value:!0}),e);var s={};module.exports=g(s);
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../src/dpr/components/_charts/chart/heatmap/types.ts"],
4
+ "sourcesContent": ["export interface MatrixChartData {\n x: number | string\n y: number | string\n r?: number\n v: number\n}\n"],
5
+ "mappings": "kWAAA,IAAAA,EAAA,kBAAAC,EAAAD",
6
+ "names": ["types_exports", "__toCommonJS"]
7
+ }
@@ -0,0 +1,6 @@
1
+ export interface MatrixChartData {
2
+ x: number | string
3
+ y: number | string
4
+ r?: number
5
+ v: number
6
+ }
@@ -1,2 +1,2 @@
1
- var G=Object.create;var b=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var F=Object.getPrototypeOf,H=Object.prototype.hasOwnProperty;var j=(a,t)=>{for(var e in t)b(a,e,{get:t[e],enumerable:!0})},w=(a,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of A(t))!H.call(a,o)&&o!==e&&b(a,o,{get:()=>t[o],enumerable:!(s=$(t,o))||s.enumerable});return a};var p=(a,t,e)=>(e=a!=null?G(F(a)):{},w(t||!a||!a.__esModule?b(e,"default",{value:a,enumerable:!0}):e,a)),v=a=>w(b({},"__esModule",{value:!0}),a);var Q={};j(Q,{createChart:()=>M,createMatrixChart:()=>S,createTimeseriesCharts:()=>L,default:()=>P});module.exports=v(Q);var T=p(require("dayjs")),x=p(require("dayjs/plugin/weekOfYear")),D=p(require("../../utils/datasetHelper")),f=p(require("../_dashboards/dashboard-list/utils")),B=require("../_inputs/granular-date-range/types"),k=p(require("./chart/heatmap/HeatmapChart"));T.default.extend(x.default);const M=(a,t)=>{let e,s,o;const{dataSetRows:r,snapshotData:l}=O(a,t);return r.length&&(s=Y(a,l),e=z(a,r),o=R(a,r)),{details:o,table:e,chart:s}},L=(a,t)=>{let e,s,o;const{latestData:r,dataSetRows:l,timeseriesData:u}=g(a,t);return l.length&&(s=N(a,u),e=V(a,u),o=R(a,r,!0)),{details:o,table:e,chart:s}},S=(a,t,e)=>{let s,o,r,l=B.Granularity.DAILY;Object.keys(e).forEach(h=>{h.includes("granularity")&&(l=e[h])});const{latestData:u,dataSetRows:n,timeseriesData:i}=g(a,t);return n.length&&(o=new k.default(i,l,a).build(),s=V(a,i),r=R(a,u,!0)),{details:r,table:s,chart:o}},O=(a,t)=>{const e=D.default.getLastestDataset(t),s=D.default.getDatasetRows(a,e),o=D.default.filterRowsByDisplayColumns(a,s,!0);return{dataSetRows:s,snapshotData:o}},g=(a,t)=>{const e=D.default.getLastestDataset(t),s=D.default.getDatasetRows(a,t),o=D.default.filterRowsByDisplayColumns(a,s,!0);return{latestData:e,dataSetRows:s,timeseriesData:o}},R=(a,t,e=!1)=>{const s=[],o=W(a,t,e);return t[0]?.ts&&s.push({label:"Values for:",value:t[0]?.ts.raw}),{meta:s,headlines:o}},W=(a,t,e=!1)=>{const s=[],{columns:o}=a,{measures:r}=o,l=!!r.find(d=>d.axis);let u,n,i,h;return e?(n=r.find(d=>d.id!=="ts"),n&&(h=`${t[0].ts.raw}`,i=+t[0][n.id].raw,u={label:h,value:i})):(n=l?r.find(d=>d.axis&&d.axis==="y"):r[0],n&&(h=`Total ${n.display.toLowerCase()}`,i=t.reduce((d,c)=>d+ +c[n.id].raw,0),u={label:h,value:i})),s.push(u),s},Y=(a,t)=>{const{type:e,columns:s}=a,{measures:o}=s,r=!!o.find(i=>i.axis);let l,u,n;return r?{labels:l,unit:u,datasets:n}=U(s,t):{labels:l,unit:u,datasets:n}=E(s,t),{type:e,unit:u,data:{labels:l,datasets:n}}},E=(a,t)=>{const{keys:e,measures:s}=a,o=s.map(n=>n.display),r=e[e.length-1]?.id,l=s[0].unit?s[0].unit:void 0,u=t.map(n=>{const i=n[r]?`${n[r].raw}`:"All",h=s.map(c=>{const m=c.id;return n[m]?+n[m].raw:0}),d=h.reduce((c,m)=>c+m,0);return{label:i,data:h,total:d}});return{labels:o,unit:l,datasets:u}},U=(a,t)=>{const{measures:e,keys:s}=a,o=e.find(d=>d.axis==="x"),r=e.find(d=>d.axis==="y"),l=r?.unit||void 0,u=D.default.getGroupKey(s,t),n=u?D.default.groupRowsByKey(t,u.id):[t],i=n[0]?.map(d=>`${d[o.id].raw}`),h=n.map(d=>{const c=d.map(m=>+m[r.id].raw);return{label:u?`${d[0][u.id].raw}`:r.display,data:c,total:c.reduce((m,C)=>m+C,0)}});return{labels:i,unit:l,datasets:h}},z=(a,t)=>{const{columns:e}=a,{keys:s,measures:o}=e,l=[...s,...o].map(i=>({text:i.display})),u=D.default.filterRowsByDisplayColumns(a,t,!0),n=f.default.createTableRows(u);return{head:l,rows:n}},N=(a,t)=>{const{columns:e}=a,{keys:s,measures:o}=e,r=o[0].unit?o[0].unit:void 0,l=a.type.split("-")[0],n=D.default.getGroupKey(s,t).id,i=D.default.groupRowsByTimestamp(t),h=i.map(m=>m[0].ts.raw),d=i[0].length,c=[];for(let m=0;m<d;m+=1){const C=i.map(y=>+y[m][o[1].id].raw),J=C.reduce((y,K)=>y+K,0),I=i[0][m][n].raw;c.push({data:C,label:I,total:J})}return{type:l,unit:r,timeseries:!0,data:{labels:h,datasets:c}}},V=(a,t)=>{const{columns:e}=a,{keys:s,measures:o}=e;let r=t.flat(),l=[...o];if(t.length>1){const i=l.findIndex(c=>c.id==="ts"),h=l[i];l.splice(i,1),l=[...s.filter(c=>c.id!=="ts"),...l],l.unshift(h)}else r=D.default.filterRowsByDisplayColumns(a,r);const u=l.map(i=>({text:i.display})),n=f.default.createTableRows(r);return{head:u,rows:n}};var P={createChart:M,createTimeseriesCharts:L,createMatrixChart:S};0&&(module.exports={createChart,createMatrixChart,createTimeseriesCharts});
1
+ var G=Object.create;var f=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var F=Object.getPrototypeOf,H=Object.prototype.hasOwnProperty;var j=(a,s)=>{for(var e in s)f(a,e,{get:s[e],enumerable:!0})},V=(a,s,e,t)=>{if(s&&typeof s=="object"||typeof s=="function")for(let o of A(s))!H.call(a,o)&&o!==e&&f(a,o,{get:()=>s[o],enumerable:!(t=$(s,o))||t.enumerable});return a};var p=(a,s,e)=>(e=a!=null?G(F(a)):{},V(s||!a||!a.__esModule?f(e,"default",{value:a,enumerable:!0}):e,a)),v=a=>V(f({},"__esModule",{value:!0}),a);var Q={};j(Q,{createChart:()=>S,createMatrixChart:()=>B,createTimeseriesCharts:()=>L,default:()=>P});module.exports=v(Q);var x=p(require("dayjs")),T=p(require("dayjs/plugin/weekOfYear")),h=p(require("../../utils/datasetHelper")),R=p(require("../_dashboards/dashboard-list/utils")),k=require("../_inputs/granular-date-range/types"),M=p(require("./chart/heatmap/HeatmapChart"));x.default.extend(T.default);const S=(a,s)=>{let e,t,o;const{dataSetRows:n,snapshotData:r}=O(a,s);return n.length&&(t=Y(a,r),e=z(a,n),o=C(a,n)),{details:o,table:e,chart:t}},L=(a,s)=>{let e,t,o;const{latestData:n,dataSetRows:r,timeseriesData:u}=g(a,s);return r.length&&(t=N(a,u),e=w(a,u),o=C(a,n,!0)),{details:o,table:e,chart:t}},B=(a,s,e)=>{let t,o,n,r=k.Granularity.DAILY;Object.keys(e).forEach(c=>{c.includes("granularity")&&(r=e[c])});const{latestData:u,dataSetRows:i,timeseriesData:l}=g(a,s);return i.length&&(o=new M.default(l,r,a).build(),t=w(a,l),n=C(a,u,!0)),{details:n,table:t,chart:o}},O=(a,s)=>{const e=h.default.getLastestDataset(s),t=h.default.getDatasetRows(a,e),o=h.default.filterRowsByDisplayColumns(a,t,!0);return{dataSetRows:t,snapshotData:o}},g=(a,s)=>{const e=h.default.getLastestDataset(s),t=h.default.getDatasetRows(a,s),o=h.default.filterRowsByDisplayColumns(a,t,!0);return{latestData:e,dataSetRows:t,timeseriesData:o}},C=(a,s,e=!1)=>{const t=[],o=W(a,s,e);return s[0]?.ts&&t.push({label:"Values for:",value:s[0]?.ts.raw}),{meta:t,headlines:o}},W=(a,s,e=!1)=>{const t=[],{columns:o}=a,{measures:n}=o,r=!!n.find(d=>d.axis);let u,i,l,c;return e?(i=n.find(d=>d.id!=="ts"),i&&(c=`${s[0].ts.raw}`,l=+s[0][i.id].raw,u={label:c,value:l})):(i=r?n.find(d=>d.axis&&d.axis==="y"):n[0],i&&(c=`Total ${i.display.toLowerCase()}`,l=s.reduce((d,D)=>d+ +D[i.id].raw,0),u={label:c,value:l})),t.push(u),t},Y=(a,s)=>{const{type:e,columns:t}=a,{measures:o}=t,n=!!o.find(l=>l.axis);let r,u,i;return n?{labels:r,unit:u,datasets:i}=U(t,s):{labels:r,unit:u,datasets:i}=E(t,s),{type:e,unit:u,data:{labels:r,datasets:i}}},E=(a,s)=>{const{keys:e,measures:t}=a,o=t.map(i=>i.display),n=e[e.length-1]?.id,r=t[0].unit?t[0].unit:void 0,u=s.map(i=>{const l=i[n]?`${i[n].raw}`:"All",c=t.map(D=>{const m=D.id;return i[m]?+i[m].raw:0}),d=c.reduce((D,m)=>D+m,0);return{label:l,data:c,total:d}});return{labels:o,unit:r,datasets:u}},U=(a,s)=>{const{measures:e,keys:t}=a,o=e.find(d=>d.axis==="x"),n=e.find(d=>d.axis==="y"),r=n?.unit||void 0,u=h.default.getGroupKey(t,s),i=u?h.default.groupRowsByKey(s,u.id):[s],l=i[0]?.map(d=>`${d[o.id].raw}`),c=i.map(d=>{const D=d.map(m=>+m[n.id].raw);return{label:u?`${d[0][u.id].raw}`:n.display,data:D,total:D.reduce((m,b)=>m+b,0)}});return{labels:l,unit:r,datasets:c}},z=(a,s)=>{const{columns:e}=a,{keys:t,measures:o}=e,r=[...t,...o].map(l=>({text:l.display})),u=h.default.filterRowsByDisplayColumns(a,s,!0),i=R.default.createTableRows(u);return{head:r,rows:i}},N=(a,s)=>{const{columns:e}=a,{keys:t,measures:o}=e,n=o[0].unit?o[0].unit:void 0,r=a.type.split("-")[0],i=h.default.getGroupKey(t,s).id,l=h.default.groupRowsByTimestamp(s),c=l.map(m=>m[0].ts.raw),d=l[0].length,D=[];for(let m=0;m<d;m+=1){const b=l.map(y=>+y[m][o[1].id].raw),J=b.reduce((y,K)=>y+K,0),I=l[0][m][i].raw;D.push({data:b,label:I,total:J})}return{type:r,unit:n,timeseries:!0,data:{labels:c,datasets:D}}},w=(a,s)=>{const{columns:e}=a,{keys:t,measures:o}=e;let n=s.flat(),r=[...o];if(s.length>1){const l=r.findIndex(D=>D.id==="ts"),c=r[l];r.splice(l,1),r=[...t.filter(D=>D.id!=="ts"),...r],r.unshift(c)}else n=h.default.filterRowsByDisplayColumns(a,n);const u=r.map(l=>({text:l.display})),i=R.default.createTableRows(n);return{head:u,rows:i}};var P={createChart:S,createTimeseriesCharts:L,createMatrixChart:B};0&&(module.exports={createChart,createMatrixChart,createTimeseriesCharts});
2
2
  //# sourceMappingURL=utils.js.map