@ministryofjustice/hmpps-digital-prison-reporting-frontend 4.1.2 → 4.1.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.
- package/dpr/assets/js/all.mjs +9 -6
- package/dpr/components/_filters/filters-selected/utils.js +1 -1
- package/dpr/components/_filters/filters-selected/utils.ts +1 -1
- package/dpr/components/_inputs/mulitselect/utils.js +9 -4
- package/dpr/components/_inputs/mulitselect/utils.ts +9 -5
- package/dpr/components/report-list/utils.js +11 -10
- package/dpr/components/report-list/utils.ts +8 -12
- package/package.json +1 -1
- package/package.zip +0 -0
package/dpr/assets/js/all.mjs
CHANGED
|
@@ -344,7 +344,7 @@ class DprQueryParamClass extends DprClientClass {
|
|
|
344
344
|
initInputEvents(elements) {
|
|
345
345
|
Array.from(elements).forEach((input) => {
|
|
346
346
|
input.addEventListener('change', () => {
|
|
347
|
-
this.setQueryParamFromInput(input, true);
|
|
347
|
+
this.setQueryParamFromInput(input, true, false);
|
|
348
348
|
});
|
|
349
349
|
});
|
|
350
350
|
}
|
|
@@ -357,7 +357,7 @@ class DprQueryParamClass extends DprClientClass {
|
|
|
357
357
|
*/
|
|
358
358
|
initQueryParamsFromInputs(elements) {
|
|
359
359
|
Array.from(elements).forEach((input) => {
|
|
360
|
-
if (input.type !== 'hidden') this.setQueryParamFromInput(input);
|
|
360
|
+
if (input.type !== 'hidden') this.setQueryParamFromInput(input, false, true);
|
|
361
361
|
});
|
|
362
362
|
}
|
|
363
363
|
|
|
@@ -368,10 +368,10 @@ class DprQueryParamClass extends DprClientClass {
|
|
|
368
368
|
* @param {*} toggleCheckbox
|
|
369
369
|
* @memberof DprQueryParamClass
|
|
370
370
|
*/
|
|
371
|
-
setQueryParamFromInput(input, toggleCheckbox = false) {
|
|
371
|
+
setQueryParamFromInput(input, toggleCheckbox = false, init = false) {
|
|
372
372
|
const { type } = input;
|
|
373
373
|
if (type === 'checkbox' || type === 'radio') {
|
|
374
|
-
this.setMultiSelectQueryParam(input, toggleCheckbox);
|
|
374
|
+
this.setMultiSelectQueryParam(input, toggleCheckbox, init);
|
|
375
375
|
} else {
|
|
376
376
|
const { name } = input;
|
|
377
377
|
let { value } = input;
|
|
@@ -393,12 +393,15 @@ class DprQueryParamClass extends DprClientClass {
|
|
|
393
393
|
* @param {*} toggle - adds the delete step on toggle
|
|
394
394
|
* @memberof DprQueryParamClass
|
|
395
395
|
*/
|
|
396
|
-
setMultiSelectQueryParam(input, toggle) {
|
|
396
|
+
setMultiSelectQueryParam(input, toggle, init) {
|
|
397
397
|
this.queryParams = new URLSearchParams(window.location.search);
|
|
398
398
|
const { name, value, checked, type } = input;
|
|
399
399
|
if (checked && !this.queryParams.has(name, value)) {
|
|
400
400
|
let updateType;
|
|
401
|
-
if (type === 'checkbox')
|
|
401
|
+
if (type === 'checkbox') {
|
|
402
|
+
updateType = 'append';
|
|
403
|
+
if (!init && name !== 'columns') this.updateQueryParam('preventDefault', true);
|
|
404
|
+
}
|
|
402
405
|
this.updateQueryParam(name, value, updateType);
|
|
403
406
|
} else if (!checked && this.queryParams.has(name, value) && toggle) {
|
|
404
407
|
this.updateQueryParam(name, value, 'delete');
|
|
@@ -163,7 +163,7 @@ const disabledDateRange = (f, value, displayValue) => {
|
|
|
163
163
|
};
|
|
164
164
|
const disabledDate = (f, value, displayValue) => {
|
|
165
165
|
const { min, max } = f;
|
|
166
|
-
if (value[0].includes(min) || value[
|
|
166
|
+
if (value[0].includes(min) || value[0].includes(max)) {
|
|
167
167
|
let valueType;
|
|
168
168
|
if (value[0].includes(min))
|
|
169
169
|
valueType = 'min';
|
|
@@ -171,7 +171,7 @@ const disabledDateRange = (f: DateFilterValue, value: (string | DateRange)[], di
|
|
|
171
171
|
|
|
172
172
|
const disabledDate = (f: DateFilterValue, value: (string | DateRange)[], displayValue: string) => {
|
|
173
173
|
const { min, max } = <DateFilterValue>f
|
|
174
|
-
if ((<string>value[0]).includes(min) || (<string>value[
|
|
174
|
+
if ((<string>value[0]).includes(min) || (<string>value[0]).includes(max)) {
|
|
175
175
|
let valueType
|
|
176
176
|
if ((<string>value[0]).includes(min)) valueType = 'min'
|
|
177
177
|
if ((<string>value[0]).includes(max)) valueType = 'max'
|
|
@@ -2,14 +2,19 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const setValueFromRequest = (filter, req, prefix) => {
|
|
4
4
|
const { preventDefault } = req.query;
|
|
5
|
-
const
|
|
6
|
-
|
|
5
|
+
const queryValue = req.query[`${prefix}${filter.name}`];
|
|
6
|
+
let valueArr;
|
|
7
|
+
let valueString;
|
|
8
|
+
if (queryValue === null || queryValue === void 0 ? void 0 : queryValue.length) {
|
|
9
|
+
valueArr = Array.isArray(queryValue) ? queryValue : [queryValue];
|
|
10
|
+
valueString = valueArr.join(',');
|
|
11
|
+
}
|
|
7
12
|
const defaultValue = preventDefault ? null : filter.value;
|
|
8
13
|
let defaultValues = filter.value ? filter.value.split(',') : [];
|
|
9
14
|
defaultValues = preventDefault ? [] : defaultValues;
|
|
10
15
|
return {
|
|
11
|
-
requestfilterValue: valueString || defaultValue,
|
|
12
|
-
requestfilterValues: valueArr || defaultValues,
|
|
16
|
+
requestfilterValue: valueString || defaultValue || null,
|
|
17
|
+
requestfilterValues: valueArr || defaultValues || [],
|
|
13
18
|
};
|
|
14
19
|
};
|
|
15
20
|
exports.default = {
|
|
@@ -3,17 +3,21 @@ import { FilterValue } from '../../_filters/types'
|
|
|
3
3
|
|
|
4
4
|
const setValueFromRequest = (filter: FilterValue, req: Request, prefix: string) => {
|
|
5
5
|
const { preventDefault } = req.query
|
|
6
|
+
const queryValue = <string[] | string | undefined>req.query[`${prefix}${filter.name}`]
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
let valueArr: string[]
|
|
9
|
+
let valueString: string
|
|
10
|
+
if (queryValue?.length) {
|
|
11
|
+
valueArr = Array.isArray(queryValue) ? queryValue : [queryValue]
|
|
12
|
+
valueString = valueArr.join(',')
|
|
13
|
+
}
|
|
9
14
|
const defaultValue = preventDefault ? null : filter.value
|
|
10
|
-
|
|
11
15
|
let defaultValues = filter.value ? (<string>filter.value).split(',') : []
|
|
12
16
|
defaultValues = preventDefault ? [] : defaultValues
|
|
13
17
|
|
|
14
18
|
return {
|
|
15
|
-
requestfilterValue: valueString || defaultValue,
|
|
16
|
-
requestfilterValues: valueArr || defaultValues,
|
|
19
|
+
requestfilterValue: valueString || defaultValue || null,
|
|
20
|
+
requestfilterValues: valueArr || defaultValues || [],
|
|
17
21
|
}
|
|
18
22
|
}
|
|
19
23
|
|
|
@@ -13,7 +13,7 @@ const UserReports_1 = require("../../types/UserReports");
|
|
|
13
13
|
function isListWithWarnings(data) {
|
|
14
14
|
return data.data !== undefined;
|
|
15
15
|
}
|
|
16
|
-
async function renderList(listData, variantDefinition, reportQuery, request, response, next, title, layoutTemplate,
|
|
16
|
+
async function renderList(listData, variantDefinition, reportQuery, request, response, next, title, layoutTemplate, otherOptions, reportName) {
|
|
17
17
|
await Promise.all([listData.data, listData.count])
|
|
18
18
|
.then(async (resolvedData) => {
|
|
19
19
|
let data;
|
|
@@ -48,7 +48,7 @@ async function renderList(listData, variantDefinition, reportQuery, request, res
|
|
|
48
48
|
renderData: {
|
|
49
49
|
...reportRenderData,
|
|
50
50
|
reportName,
|
|
51
|
-
name: variantName,
|
|
51
|
+
name: title || variantName,
|
|
52
52
|
description,
|
|
53
53
|
count,
|
|
54
54
|
classification,
|
|
@@ -66,28 +66,30 @@ async function renderList(listData, variantDefinition, reportQuery, request, res
|
|
|
66
66
|
})
|
|
67
67
|
.catch((err) => next(err));
|
|
68
68
|
}
|
|
69
|
-
const renderListWithDefinition = async ({ title, definitionName, variantName, request, response, next, otherOptions, layoutTemplate, token, apiUrl, apiTimeout,
|
|
69
|
+
const renderListWithDefinition = async ({ title, definitionName, variantName, request, response, next, otherOptions, layoutTemplate, token, apiUrl, apiTimeout, definitionsPath, }) => {
|
|
70
70
|
const reportingClient = new reportingClient_1.default({
|
|
71
71
|
url: apiUrl,
|
|
72
72
|
agent: {
|
|
73
73
|
timeout: apiTimeout,
|
|
74
74
|
},
|
|
75
75
|
});
|
|
76
|
+
const { dataProductDefinitionsPath } = request.query;
|
|
77
|
+
const reportDef = dataProductDefinitionsPath || definitionsPath;
|
|
76
78
|
try {
|
|
77
|
-
const reportDefinition = await reportingClient.getDefinition(token, definitionName, variantName,
|
|
79
|
+
const reportDefinition = await reportingClient.getDefinition(token, definitionName, variantName, reportDef);
|
|
78
80
|
const reportName = reportDefinition.name;
|
|
79
81
|
const variantDefinition = reportDefinition.variant;
|
|
80
82
|
const reportQuery = new ReportQuery_1.default({
|
|
81
83
|
fields: variantDefinition.specification.fields,
|
|
82
84
|
template: variantDefinition.specification.template,
|
|
83
85
|
queryParams: request.query,
|
|
84
|
-
definitionsPath:
|
|
86
|
+
definitionsPath: reportDef,
|
|
85
87
|
});
|
|
86
88
|
const getListData = {
|
|
87
89
|
data: reportingClient.getListWithWarnings(variantDefinition.resourceName, token, reportQuery),
|
|
88
90
|
count: reportingClient.getCount(variantDefinition.resourceName, token, reportQuery),
|
|
89
91
|
};
|
|
90
|
-
await renderList(getListData, variantDefinition, reportQuery, request, response, next,
|
|
92
|
+
await renderList(getListData, variantDefinition, reportQuery, request, response, next, variantName || `${variantDefinition.name}`, layoutTemplate, otherOptions, title || `${reportName}`);
|
|
91
93
|
}
|
|
92
94
|
catch (error) {
|
|
93
95
|
next(error);
|
|
@@ -95,7 +97,7 @@ const renderListWithDefinition = async ({ title, definitionName, variantName, re
|
|
|
95
97
|
};
|
|
96
98
|
exports.renderListWithDefinition = renderListWithDefinition;
|
|
97
99
|
exports.default = {
|
|
98
|
-
renderListWithData: async ({ title, reportName, variantDefinition, request, response, next, getListDataSources, otherOptions, layoutTemplate,
|
|
100
|
+
renderListWithData: async ({ title, reportName, variantDefinition, request, response, next, getListDataSources, otherOptions, layoutTemplate, }) => {
|
|
99
101
|
const { specification } = variantDefinition;
|
|
100
102
|
const reportQuery = new ReportQuery_1.default({
|
|
101
103
|
fields: specification.fields,
|
|
@@ -104,9 +106,9 @@ exports.default = {
|
|
|
104
106
|
definitionsPath: request.query.dataProductDefinitionsPath,
|
|
105
107
|
});
|
|
106
108
|
const listData = getListDataSources(reportQuery);
|
|
107
|
-
await renderList(listData, variantDefinition, reportQuery, request, response, next, title, layoutTemplate,
|
|
109
|
+
await renderList(listData, variantDefinition, reportQuery, request, response, next, title, layoutTemplate, otherOptions, reportName);
|
|
108
110
|
},
|
|
109
|
-
createReportListRequestHandler: ({ title, definitionName, variantName, apiUrl, apiTimeout, otherOptions, layoutTemplate, tokenProvider,
|
|
111
|
+
createReportListRequestHandler: ({ title, definitionName, variantName, apiUrl, apiTimeout, otherOptions, layoutTemplate, tokenProvider, definitionsPath, }) => {
|
|
110
112
|
return (request, response, next) => {
|
|
111
113
|
(0, exports.renderListWithDefinition)({
|
|
112
114
|
title,
|
|
@@ -120,7 +122,6 @@ exports.default = {
|
|
|
120
122
|
token: tokenProvider(request, response, next),
|
|
121
123
|
apiUrl,
|
|
122
124
|
apiTimeout,
|
|
123
|
-
dynamicAutocompleteEndpoint,
|
|
124
125
|
definitionsPath,
|
|
125
126
|
});
|
|
126
127
|
};
|
|
@@ -30,7 +30,6 @@ export async function renderList(
|
|
|
30
30
|
next: NextFunction,
|
|
31
31
|
title: string,
|
|
32
32
|
layoutTemplate: string,
|
|
33
|
-
dynamicAutocompleteEndpoint?: string,
|
|
34
33
|
otherOptions?: NodeJS.Dict<object>,
|
|
35
34
|
reportName?: string,
|
|
36
35
|
) {
|
|
@@ -77,7 +76,7 @@ export async function renderList(
|
|
|
77
76
|
renderData: {
|
|
78
77
|
...reportRenderData,
|
|
79
78
|
reportName,
|
|
80
|
-
name: variantName,
|
|
79
|
+
name: title || variantName,
|
|
81
80
|
description,
|
|
82
81
|
count,
|
|
83
82
|
classification,
|
|
@@ -109,7 +108,6 @@ export const renderListWithDefinition = async ({
|
|
|
109
108
|
token,
|
|
110
109
|
apiUrl,
|
|
111
110
|
apiTimeout,
|
|
112
|
-
dynamicAutocompleteEndpoint,
|
|
113
111
|
definitionsPath,
|
|
114
112
|
}: RenderListWithDefinitionInput) => {
|
|
115
113
|
const reportingClient = new ReportingClient({
|
|
@@ -119,8 +117,11 @@ export const renderListWithDefinition = async ({
|
|
|
119
117
|
},
|
|
120
118
|
})
|
|
121
119
|
|
|
120
|
+
const { dataProductDefinitionsPath } = request.query
|
|
121
|
+
const reportDef = <string>dataProductDefinitionsPath || definitionsPath
|
|
122
|
+
|
|
122
123
|
try {
|
|
123
|
-
const reportDefinition = await reportingClient.getDefinition(token, definitionName, variantName,
|
|
124
|
+
const reportDefinition = await reportingClient.getDefinition(token, definitionName, variantName, reportDef)
|
|
124
125
|
const reportName: string = reportDefinition.name
|
|
125
126
|
const variantDefinition = reportDefinition.variant
|
|
126
127
|
|
|
@@ -128,7 +129,7 @@ export const renderListWithDefinition = async ({
|
|
|
128
129
|
fields: variantDefinition.specification.fields,
|
|
129
130
|
template: variantDefinition.specification.template as Template,
|
|
130
131
|
queryParams: request.query,
|
|
131
|
-
definitionsPath:
|
|
132
|
+
definitionsPath: reportDef,
|
|
132
133
|
})
|
|
133
134
|
|
|
134
135
|
const getListData: ListDataSources = {
|
|
@@ -143,11 +144,10 @@ export const renderListWithDefinition = async ({
|
|
|
143
144
|
request,
|
|
144
145
|
response,
|
|
145
146
|
next,
|
|
146
|
-
|
|
147
|
+
variantName || `${variantDefinition.name}`,
|
|
147
148
|
layoutTemplate,
|
|
148
|
-
dynamicAutocompleteEndpoint,
|
|
149
149
|
otherOptions,
|
|
150
|
-
reportName
|
|
150
|
+
title || `${reportName}`,
|
|
151
151
|
)
|
|
152
152
|
} catch (error) {
|
|
153
153
|
next(error)
|
|
@@ -165,7 +165,6 @@ export default {
|
|
|
165
165
|
getListDataSources,
|
|
166
166
|
otherOptions,
|
|
167
167
|
layoutTemplate,
|
|
168
|
-
dynamicAutocompleteEndpoint,
|
|
169
168
|
}: RenderListWithDataInput) => {
|
|
170
169
|
const { specification } = variantDefinition
|
|
171
170
|
const reportQuery = new ReportQuery({
|
|
@@ -185,7 +184,6 @@ export default {
|
|
|
185
184
|
next,
|
|
186
185
|
title,
|
|
187
186
|
layoutTemplate,
|
|
188
|
-
dynamicAutocompleteEndpoint,
|
|
189
187
|
otherOptions,
|
|
190
188
|
reportName,
|
|
191
189
|
)
|
|
@@ -199,7 +197,6 @@ export default {
|
|
|
199
197
|
otherOptions,
|
|
200
198
|
layoutTemplate,
|
|
201
199
|
tokenProvider,
|
|
202
|
-
dynamicAutocompleteEndpoint,
|
|
203
200
|
definitionsPath,
|
|
204
201
|
}: CreateRequestHandlerInput): RequestHandler => {
|
|
205
202
|
return (request: Request, response: Response, next: NextFunction) => {
|
|
@@ -215,7 +212,6 @@ export default {
|
|
|
215
212
|
token: tokenProvider(request, response, next),
|
|
216
213
|
apiUrl,
|
|
217
214
|
apiTimeout,
|
|
218
|
-
dynamicAutocompleteEndpoint,
|
|
219
215
|
definitionsPath,
|
|
220
216
|
})
|
|
221
217
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ministryofjustice/hmpps-digital-prison-reporting-frontend",
|
|
3
3
|
"description": "The Digital Prison Reporting Frontend contains templates and code to help display data effectively in UI applications.",
|
|
4
|
-
"version": "4.1.
|
|
4
|
+
"version": "4.1.4",
|
|
5
5
|
"main": "dpr/assets/js/all.mjs",
|
|
6
6
|
"sass": "dpr/all.scss",
|
|
7
7
|
"engines": {
|
package/package.zip
CHANGED
|
Binary file
|