@ministryofjustice/hmpps-digital-prison-reporting-frontend 3.19.2 → 3.19.4

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.
@@ -43,3 +43,18 @@ interface RequestedReportStateItem {
43
43
  failed?: string
44
44
  }
45
45
  }
46
+
47
+ export interface RenderFiltersReturnValue {
48
+ reportData: {
49
+ reportName: string
50
+ variantName: string
51
+ description: string
52
+ reportId: string
53
+ variantId: string
54
+ definitionPath: string | string[] | ParsedQs | ParsedQs[]
55
+ csrfToken: string
56
+ template: string
57
+ }
58
+ filters: FilterValue[]
59
+ sortBy: FilterValue[]
60
+ }
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.updateStore = void 0;
6
7
  const moment_1 = __importDefault(require("moment"));
7
8
  const utils_1 = __importDefault(require("../filters/utils"));
8
9
  const enum_1 = require("../filter-input/enum");
@@ -10,17 +11,45 @@ const sortByTemplate_1 = __importDefault(require("./sortByTemplate"));
10
11
  const definitionUtils_1 = __importDefault(require("../../utils/definitionUtils"));
11
12
  const reportSummaryHelper_1 = require("../../utils/reportSummaryHelper");
12
13
  /**
13
- * Initialises the filters from the definition data
14
+ * Initialises the filters & Sort from the definition data
14
15
  *
15
16
  * @param {components['schemas']['VariantDefinition']} definition
16
17
  * @return {*}
17
18
  */
18
19
  const initFiltersFromDefinition = (definition) => {
20
+ return {
21
+ filters: getFiltersFromDefinition(definition),
22
+ sortBy: getSortByFromDefinition(definition),
23
+ };
24
+ };
25
+ /**
26
+ * Initialises the sortData from the definition
27
+ *
28
+ * @param {components['schemas']['VariantDefinition']} definition
29
+ * @return {*}
30
+ */
31
+ const getSortByFromDefinition = (definition) => {
19
32
  const sortBy = sortByTemplate_1.default.sortByTemplate();
20
- const filters = definition.specification.fields
33
+ sortBy[0].options = definition.specification.fields
34
+ .filter((f) => f.sortable)
35
+ .map((f) => {
36
+ if (f.defaultsort)
37
+ sortBy[0].value = f.name;
38
+ return { value: f.name, text: f.display };
39
+ });
40
+ return sortBy;
41
+ };
42
+ /**
43
+ * Initialises the filters from the definition
44
+ *
45
+ * @param {components['schemas']['VariantDefinition']} definition
46
+ * @return {*}
47
+ */
48
+ const getFiltersFromDefinition = (definition) => {
49
+ return definition.specification.fields
21
50
  .filter((f) => f.filter)
22
51
  .map((f) => {
23
- const { display: text, name, filter, sortable, defaultsort } = f;
52
+ const { display: text, name, filter } = f;
24
53
  const { type, staticOptions, dynamicOptions, defaultValue, mandatory, pattern } = filter;
25
54
  let filterData = {
26
55
  text,
@@ -59,16 +88,8 @@ const initFiltersFromDefinition = (definition) => {
59
88
  max,
60
89
  };
61
90
  }
62
- if (sortable)
63
- sortBy[0].options.push({ value: name, text });
64
- if (defaultsort)
65
- sortBy[0].value = name;
66
91
  return filterData;
67
92
  });
68
- return {
69
- filters,
70
- sortBy,
71
- };
72
93
  };
73
94
  /**
74
95
  * Updates the store with the request details
@@ -105,6 +126,7 @@ const updateStore = async (req, services, fields, querySummaryData, executionId,
105
126
  await setTimestamps(refreshId, services, 'refresh');
106
127
  return reportData.url.polling.pathname;
107
128
  };
129
+ exports.updateStore = updateStore;
108
130
  const setTimestamps = async (id, services, type) => {
109
131
  await services.asyncReportsStore.setReportTimestamp(id, type);
110
132
  await services.recentlyViewedStoreService.setReportTimestamp(id, type);
@@ -171,7 +193,7 @@ exports.default = {
171
193
  * @param {AsyncReportUtilsParams} { req, res, dataSources }
172
194
  * @return {*}
173
195
  */
174
- renderFilters: async ({ req, res, services, next }) => {
196
+ renderFilters: async ({ req, res, services, next, }) => {
175
197
  var _a;
176
198
  try {
177
199
  const token = ((_a = res.locals.user) === null || _a === void 0 ? void 0 : _a.token) ? res.locals.user.token : 'token';
@@ -211,7 +233,7 @@ exports.default = {
211
233
  });
212
234
  let redirect = '';
213
235
  if (executionId && tableId) {
214
- redirect = await updateStore(req, services, fields, querySummaryData, executionId, tableId);
236
+ redirect = await (0, exports.updateStore)(req, services, fields, querySummaryData, executionId, tableId);
215
237
  }
216
238
  return redirect;
217
239
  },
@@ -10,19 +10,50 @@ import { AsyncReportUtilsParams } from '../../types/AsyncReportUtils'
10
10
  import DefinitionUtils from '../../utils/definitionUtils'
11
11
  import { getDuplicateRequestIds } from '../../utils/reportSummaryHelper'
12
12
  import { Services } from '../../types/Services'
13
+ import { RenderFiltersReturnValue } from './types'
13
14
 
14
15
  /**
15
- * Initialises the filters from the definition data
16
+ * Initialises the filters & Sort from the definition data
16
17
  *
17
18
  * @param {components['schemas']['VariantDefinition']} definition
18
19
  * @return {*}
19
20
  */
20
21
  const initFiltersFromDefinition = (definition: components['schemas']['VariantDefinition']) => {
22
+ return {
23
+ filters: getFiltersFromDefinition(definition),
24
+ sortBy: getSortByFromDefinition(definition),
25
+ }
26
+ }
27
+
28
+ /**
29
+ * Initialises the sortData from the definition
30
+ *
31
+ * @param {components['schemas']['VariantDefinition']} definition
32
+ * @return {*}
33
+ */
34
+ const getSortByFromDefinition = (definition: components['schemas']['VariantDefinition']) => {
21
35
  const sortBy = SortHelper.sortByTemplate()
22
- const filters = definition.specification.fields
36
+ sortBy[0].options = definition.specification.fields
37
+ .filter((f) => f.sortable)
38
+ .map((f) => {
39
+ if (f.defaultsort) sortBy[0].value = f.name
40
+ return { value: f.name, text: f.display }
41
+ })
42
+
43
+ return sortBy
44
+ }
45
+
46
+ /**
47
+ * Initialises the filters from the definition
48
+ *
49
+ * @param {components['schemas']['VariantDefinition']} definition
50
+ * @return {*}
51
+ */
52
+ const getFiltersFromDefinition = (definition: components['schemas']['VariantDefinition']) => {
53
+ return definition.specification.fields
23
54
  .filter((f) => f.filter)
24
55
  .map((f) => {
25
- const { display: text, name, filter, sortable, defaultsort } = f
56
+ const { display: text, name, filter } = f
26
57
  const { type, staticOptions, dynamicOptions, defaultValue, mandatory, pattern } = filter
27
58
 
28
59
  let filterData: FilterValue = {
@@ -65,16 +96,8 @@ const initFiltersFromDefinition = (definition: components['schemas']['VariantDef
65
96
  }
66
97
  }
67
98
 
68
- if (sortable) sortBy[0].options.push({ value: name, text })
69
- if (defaultsort) sortBy[0].value = name
70
-
71
99
  return filterData
72
100
  })
73
-
74
- return {
75
- filters,
76
- sortBy,
77
- }
78
101
  }
79
102
 
80
103
  /**
@@ -88,7 +111,7 @@ const initFiltersFromDefinition = (definition: components['schemas']['VariantDef
88
111
  * @param {string} tableId
89
112
  * @return {*} {Promise<string>}
90
113
  */
91
- const updateStore = async (
114
+ export const updateStore = async (
92
115
  req: Request,
93
116
  services: Services,
94
117
  fields: components['schemas']['FieldDefinition'][],
@@ -211,7 +234,12 @@ export default {
211
234
  * @param {AsyncReportUtilsParams} { req, res, dataSources }
212
235
  * @return {*}
213
236
  */
214
- renderFilters: async ({ req, res, services, next }: AsyncReportUtilsParams) => {
237
+ renderFilters: async ({
238
+ req,
239
+ res,
240
+ services,
241
+ next,
242
+ }: AsyncReportUtilsParams): Promise<RenderFiltersReturnValue | boolean> => {
215
243
  try {
216
244
  const token = res.locals.user?.token ? res.locals.user.token : 'token'
217
245
  const csrfToken = (res.locals.csrfToken as unknown as string) || 'csrfToken'
@@ -7,6 +7,7 @@ import * as AsyncReportUtils from '../utils/renderAsyncReport'
7
7
 
8
8
  import { Services } from '../types/Services'
9
9
  import logger from '../utils/logger'
10
+ import { RenderFiltersReturnValue } from '../components/async-filters/types'
10
11
 
11
12
  export default function routes({
12
13
  router,
@@ -39,7 +40,7 @@ export default function routes({
39
40
 
40
41
  const getReportFiltersHandler: RequestHandler = async (req, res, next) => {
41
42
  try {
42
- const filtersRenderData = await AsyncFiltersUtils.renderFilters({
43
+ const filtersRenderData = <RenderFiltersReturnValue>await AsyncFiltersUtils.renderFilters({
43
44
  req,
44
45
  res,
45
46
  services,
@@ -10,11 +10,11 @@ const getStatus = async ({ req, res, services }) => {
10
10
  const { reportId, variantId, executionId, status: currentStatus, dataProductDefinitionsPath, requestedAt } = req.body;
11
11
  try {
12
12
  const timeoutExemptStatuses = [AsyncReport_1.RequestStatus.READY, AsyncReport_1.RequestStatus.EXPIRED, AsyncReport_1.RequestStatus.FAILED];
13
- if (timeoutRequest(requestedAt) && !timeoutExemptStatuses.includes(currentStatus)) {
14
- throw new Error('Request taking too long. Request Halted');
15
- }
16
13
  const statusResponse = await services.reportingService.getAsyncReportStatus(token, reportId, variantId, executionId, dataProductDefinitionsPath);
17
14
  status = statusResponse.status;
15
+ if (timeoutRequest(requestedAt) && !timeoutExemptStatuses.includes(status)) {
16
+ throw new Error('Request taking too long. Request Halted');
17
+ }
18
18
  if (status === AsyncReport_1.RequestStatus.FAILED) {
19
19
  errorMessage = statusResponse.error;
20
20
  }
@@ -15,10 +15,6 @@ export const getStatus = async ({ req, res, services }: AsyncReportUtilsParams):
15
15
 
16
16
  try {
17
17
  const timeoutExemptStatuses = [RequestStatus.READY, RequestStatus.EXPIRED, RequestStatus.FAILED]
18
- if (timeoutRequest(requestedAt) && !timeoutExemptStatuses.includes(currentStatus)) {
19
- throw new Error('Request taking too long. Request Halted')
20
- }
21
-
22
18
  const statusResponse = await services.reportingService.getAsyncReportStatus(
23
19
  token,
24
20
  reportId,
@@ -28,6 +24,10 @@ export const getStatus = async ({ req, res, services }: AsyncReportUtilsParams):
28
24
  )
29
25
  status = statusResponse.status as RequestStatus
30
26
 
27
+ if (timeoutRequest(requestedAt) && !timeoutExemptStatuses.includes(status)) {
28
+ throw new Error('Request taking too long. Request Halted')
29
+ }
30
+
31
31
  if (status === RequestStatus.FAILED) {
32
32
  errorMessage = statusResponse.error
33
33
  }
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": "3.19.2",
4
+ "version": "3.19.4",
5
5
  "main": "dpr/assets/js/all.mjs",
6
6
  "sass": "dpr/all.scss",
7
7
  "engines": {
package/package.zip CHANGED
Binary file