@ministryofjustice/hmpps-digital-prison-reporting-frontend 2.1.1 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,17 +1,27 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ const querystringify_1 = __importDefault(require("querystringify"));
7
+ const addAdditionalQueryParams = (path, additionalQueryParams) => {
8
+ if (additionalQueryParams && Object.keys(additionalQueryParams).length > 0) {
9
+ return `${path}${querystringify_1.default.stringify(additionalQueryParams, true)}`;
10
+ }
11
+ return path;
12
+ };
3
13
  exports.default = {
4
- reportDefinitionsToCards: (reportDefinitions, pathPrefix) => {
14
+ reportDefinitionsToCards: (reportDefinitions, pathPrefix, additionalQueryParams) => {
5
15
  return reportDefinitions.map((d) => ({
6
16
  text: d.name,
7
- href: `${pathPrefix}/${d.id}`,
17
+ href: addAdditionalQueryParams(`${pathPrefix}/${d.id}`, additionalQueryParams),
8
18
  description: d.description,
9
19
  }));
10
20
  },
11
- variantDefinitionsToCards: (reportDefinition, pathPrefix) => {
21
+ variantDefinitionsToCards: (reportDefinition, pathPrefix, additionalQueryParams) => {
12
22
  return reportDefinition.variants.map((v) => ({
13
23
  text: v.name,
14
- href: `${pathPrefix}/${reportDefinition.id}/${v.id}`,
24
+ href: addAdditionalQueryParams(`${pathPrefix}/${reportDefinition.id}/${v.id}`, additionalQueryParams),
15
25
  description: v.description,
16
26
  }));
17
27
  },
@@ -1,13 +1,23 @@
1
+ import qs from 'querystringify'
1
2
  import { components } from '../../types/api'
2
3
 
4
+ const addAdditionalQueryParams = (path: string, additionalQueryParams?: NodeJS.Dict<string>) => {
5
+ if (additionalQueryParams && Object.keys(additionalQueryParams).length > 0) {
6
+ return `${path}${qs.stringify(additionalQueryParams, true)}`
7
+ }
8
+
9
+ return path
10
+ }
11
+
3
12
  export default {
4
13
  reportDefinitionsToCards: (
5
14
  reportDefinitions: Array<components['schemas']['ReportDefinitionSummary']>,
6
15
  pathPrefix: string,
16
+ additionalQueryParams?: NodeJS.Dict<string>,
7
17
  ) => {
8
18
  return reportDefinitions.map((d: components['schemas']['ReportDefinitionSummary']) => ({
9
19
  text: d.name,
10
- href: `${pathPrefix}/${d.id}`,
20
+ href: addAdditionalQueryParams(`${pathPrefix}/${d.id}`, additionalQueryParams),
11
21
  description: d.description,
12
22
  }))
13
23
  },
@@ -15,10 +25,11 @@ export default {
15
25
  variantDefinitionsToCards: (
16
26
  reportDefinition: components['schemas']['ReportDefinitionSummary'],
17
27
  pathPrefix: string,
28
+ additionalQueryParams?: NodeJS.Dict<string>,
18
29
  ) => {
19
30
  return reportDefinition.variants.map((v: components['schemas']['VariantDefinitionSummary']) => ({
20
31
  text: v.name,
21
- href: `${pathPrefix}/${reportDefinition.id}/${v.id}`,
32
+ href: addAdditionalQueryParams(`${pathPrefix}/${reportDefinition.id}/${v.id}`, additionalQueryParams),
22
33
  description: v.description,
23
34
  }))
24
35
  },
@@ -37,11 +37,12 @@ class ReportingClient {
37
37
  },
38
38
  }));
39
39
  }
40
- getDefinitions(token) {
40
+ getDefinitions(token, definitionsPath) {
41
41
  logger_1.default.info(`Reporting client: Get definitions`);
42
42
  const params = {
43
43
  query: {
44
44
  renderMethod: 'HTML',
45
+ dataProductDefinitionsPath: definitionsPath,
45
46
  },
46
47
  };
47
48
  return this.restClient
@@ -52,23 +53,29 @@ class ReportingClient {
52
53
  })
53
54
  .then((response) => response);
54
55
  }
55
- getDefinition(token, reportId, variantId) {
56
+ getDefinition(token, reportId, variantId, definitionsPath) {
56
57
  logger_1.default.info(`Reporting client: Get single variant definition`);
58
+ const query = {
59
+ dataProductDefinitionsPath: definitionsPath,
60
+ };
57
61
  return this.restClient
58
62
  .get({
59
63
  path: `/definitions/${reportId}/${variantId}`,
64
+ query,
60
65
  token,
61
66
  })
62
67
  .then((response) => response);
63
68
  }
64
- getFieldValues({ token, definitionName, variantName, fieldName, prefix, }) {
69
+ getFieldValues({ token, definitionName, variantName, fieldName, prefix, definitionsPath, }) {
70
+ const query = {
71
+ dataProductDefinitionsPath: definitionsPath,
72
+ prefix,
73
+ };
65
74
  return this.restClient
66
75
  .get({
67
76
  path: `/reports/${definitionName}/${variantName}/${fieldName}`,
68
77
  token,
69
- query: {
70
- prefix,
71
- },
78
+ query,
72
79
  })
73
80
  .then((response) => response);
74
81
  }
@@ -46,12 +46,16 @@ export default class ReportingClient {
46
46
  }))
47
47
  }
48
48
 
49
- getDefinitions(token: string): Promise<Array<components['schemas']['ReportDefinitionSummary']>> {
49
+ getDefinitions(
50
+ token: string,
51
+ definitionsPath?: string,
52
+ ): Promise<Array<components['schemas']['ReportDefinitionSummary']>> {
50
53
  logger.info(`Reporting client: Get definitions`)
51
54
 
52
55
  const params: operations['definitions']['parameters'] = {
53
56
  query: {
54
57
  renderMethod: 'HTML',
58
+ dataProductDefinitionsPath: definitionsPath,
55
59
  },
56
60
  }
57
61
 
@@ -68,12 +72,18 @@ export default class ReportingClient {
68
72
  token: string,
69
73
  reportId: string,
70
74
  variantId: string,
75
+ definitionsPath?: string,
71
76
  ): Promise<components['schemas']['SingleVariantReportDefinition']> {
72
77
  logger.info(`Reporting client: Get single variant definition`)
73
78
 
79
+ const query = {
80
+ dataProductDefinitionsPath: definitionsPath,
81
+ }
82
+
74
83
  return this.restClient
75
84
  .get({
76
85
  path: `/definitions/${reportId}/${variantId}`,
86
+ query,
77
87
  token,
78
88
  })
79
89
  .then((response) => <components['schemas']['SingleVariantReportDefinition']>response)
@@ -85,14 +95,17 @@ export default class ReportingClient {
85
95
  variantName,
86
96
  fieldName,
87
97
  prefix,
98
+ definitionsPath,
88
99
  }: FieldValuesRequest): Promise<Array<string>> {
100
+ const query = {
101
+ dataProductDefinitionsPath: definitionsPath,
102
+ prefix,
103
+ }
89
104
  return this.restClient
90
105
  .get({
91
106
  path: `/reports/${definitionName}/${variantName}/${fieldName}`,
92
107
  token,
93
- query: {
94
- prefix,
95
- },
108
+ query,
96
109
  })
97
110
  .then((response) => <Array<string>>response)
98
111
  }
@@ -33,4 +33,5 @@ export interface FieldValuesRequest {
33
33
  variantName: string
34
34
  fieldName: string
35
35
  prefix: string
36
+ definitionsPath?: string
36
37
  }
@@ -7,6 +7,9 @@ class ReportQuery {
7
7
  this.pageSize = queryParams.pageSize ? Number(queryParams.pageSize) : 20;
8
8
  this.sortColumn = queryParams.sortColumn ? queryParams.sortColumn.toString() : defaultSortColumn;
9
9
  this.sortedAsc = queryParams.sortedAsc !== 'false';
10
+ this.dataProductDefinitionsPath = queryParams.dataProductDefinitionsPath
11
+ ? queryParams.dataProductDefinitionsPath.toString()
12
+ : null;
10
13
  this.filtersPrefix = filtersPrefix;
11
14
  this.filters = {};
12
15
  Object.keys(queryParams)
@@ -23,6 +26,9 @@ class ReportQuery {
23
26
  sortColumn: this.sortColumn,
24
27
  sortedAsc: this.sortedAsc.toString(),
25
28
  };
29
+ if (this.dataProductDefinitionsPath) {
30
+ record.dataProductDefinitionsPath = this.dataProductDefinitionsPath;
31
+ }
26
32
  Object.keys(this.filters).forEach((filterName) => {
27
33
  const value = this.filters[filterName];
28
34
  if (!removeClearedFilters || value !== urlHelper_1.clearFilterValue) {
@@ -17,6 +17,8 @@ export default class ReportQuery implements FilteredListRequest {
17
17
 
18
18
  filtersPrefix: string
19
19
 
20
+ dataProductDefinitionsPath?: string
21
+
20
22
  constructor(
21
23
  fields: Array<components['schemas']['FieldDefinition']>,
22
24
  queryParams: ParsedQs,
@@ -27,6 +29,9 @@ export default class ReportQuery implements FilteredListRequest {
27
29
  this.pageSize = queryParams.pageSize ? Number(queryParams.pageSize) : 20
28
30
  this.sortColumn = queryParams.sortColumn ? queryParams.sortColumn.toString() : defaultSortColumn
29
31
  this.sortedAsc = queryParams.sortedAsc !== 'false'
32
+ this.dataProductDefinitionsPath = queryParams.dataProductDefinitionsPath
33
+ ? queryParams.dataProductDefinitionsPath.toString()
34
+ : null
30
35
  this.filtersPrefix = filtersPrefix
31
36
 
32
37
  this.filters = {}
@@ -46,6 +51,10 @@ export default class ReportQuery implements FilteredListRequest {
46
51
  sortedAsc: this.sortedAsc.toString(),
47
52
  }
48
53
 
54
+ if (this.dataProductDefinitionsPath) {
55
+ record.dataProductDefinitionsPath = this.dataProductDefinitionsPath
56
+ }
57
+
49
58
  Object.keys(this.filters).forEach((filterName) => {
50
59
  const value = this.filters[filterName]
51
60
  if (!removeClearedFilters || value !== clearFilterValue) {
@@ -27,6 +27,7 @@ const createUrlForParameters = (currentQueryParams, updateQueryParams) => {
27
27
  pageSize: currentQueryParams.pageSize,
28
28
  sortColumn: currentQueryParams.sortColumn,
29
29
  sortedAsc: currentQueryParams.sortedAsc,
30
+ dataProductDefinitionsPath: currentQueryParams.dataProductDefinitionsPath,
30
31
  };
31
32
  }
32
33
  const nonEmptyQueryParams = {};
@@ -25,6 +25,7 @@ const createUrlForParameters = (currentQueryParams: NodeJS.Dict<string>, updateQ
25
25
  pageSize: currentQueryParams.pageSize,
26
26
  sortColumn: currentQueryParams.sortColumn,
27
27
  sortedAsc: currentQueryParams.sortedAsc,
28
+ dataProductDefinitionsPath: currentQueryParams.dataProductDefinitionsPath,
28
29
  }
29
30
  }
30
31
 
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": "2.1.1",
4
+ "version": "2.2.1",
5
5
  "main": "dpr/assets/js/client.js",
6
6
  "sass": "dpr/all.scss",
7
7
  "engines": {
@@ -28,6 +28,7 @@
28
28
  "govuk-frontend": "^4.7",
29
29
  "jquery": "^3.6.4",
30
30
  "nunjucks": "^3.2.4",
31
+ "querystringify": "^2.2.0",
31
32
  "superagent": "^8.1.2"
32
33
  },
33
34
  "author": "HMPPS Digital Prison Reporting Team",
package/package.zip CHANGED
Binary file