@ministryofjustice/hmpps-digital-prison-reporting-frontend 3.34.0 → 3.34.2
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
CHANGED
|
@@ -376,13 +376,13 @@ class DprQueryParamClass extends DprClientClass {
|
|
|
376
376
|
} else {
|
|
377
377
|
const { name } = input;
|
|
378
378
|
let { value } = input;
|
|
379
|
-
let {
|
|
379
|
+
let { staticOptionNameValue } = input;
|
|
380
380
|
let isDateInput = input.classList.contains('moj-js-datepicker-input');
|
|
381
381
|
if (isDateInput) {
|
|
382
382
|
const formatted = dayjs(value, 'D/M/YYYY').format('YYYY-MM-DD');
|
|
383
383
|
value = formatted !== 'Invalid Date' ? formatted : '';
|
|
384
384
|
}
|
|
385
|
-
let valueToUpdate = !isDateInput &&
|
|
385
|
+
let valueToUpdate = !isDateInput && staticOptionNameValue ? staticOptionNameValue : value;
|
|
386
386
|
if (name) this.updateQueryParam(name, valueToUpdate);
|
|
387
387
|
}
|
|
388
388
|
}
|
|
@@ -1009,8 +1009,8 @@ class Filters extends DprClientClass {
|
|
|
1009
1009
|
const formData = new FormData(filtersForm);
|
|
1010
1010
|
let serializedFormData = '';
|
|
1011
1011
|
document.querySelectorAll('.autocomplete-text-input-box').forEach((input) => {
|
|
1012
|
-
if(input.
|
|
1013
|
-
formData.set(input.name, input.
|
|
1012
|
+
if(input.staticOptionNameValue) {
|
|
1013
|
+
formData.set(input.name, input.staticOptionNameValue);
|
|
1014
1014
|
}
|
|
1015
1015
|
});
|
|
1016
1016
|
formData.forEach((v, n) => {
|
|
@@ -1538,7 +1538,8 @@ class Autocomplete extends DprClientClass {
|
|
|
1538
1538
|
this.getElement()
|
|
1539
1539
|
.querySelectorAll(this.listItemsSelector)
|
|
1540
1540
|
.forEach((item) => {
|
|
1541
|
-
if (searchValue.length >= minLength &&
|
|
1541
|
+
if (searchValue.length >= minLength &&
|
|
1542
|
+
this.isMatchingStaticOptionNameOrDisplayPrefix(this.getInputListButton(item), searchValue, item)) {
|
|
1542
1543
|
item.classList.remove('autocomplete-text-input-item-hide');
|
|
1543
1544
|
} else {
|
|
1544
1545
|
item.classList.add('autocomplete-text-input-item-hide');
|
|
@@ -1552,6 +1553,19 @@ class Autocomplete extends DprClientClass {
|
|
|
1552
1553
|
}
|
|
1553
1554
|
}
|
|
1554
1555
|
|
|
1556
|
+
getInputListButton(item) {
|
|
1557
|
+
return item.querySelector('.autocomplete-text-input-list-button')
|
|
1558
|
+
}
|
|
1559
|
+
|
|
1560
|
+
isMatchingStaticOptionNameOrDisplayPrefix(inputListButton, searchValue, item) {
|
|
1561
|
+
return this.isStaticOptionsNamePrefix(inputListButton.dataset.staticOptionNameValue, searchValue)
|
|
1562
|
+
|| item.innerText.trim().toLowerCase().startsWith(searchValue)
|
|
1563
|
+
}
|
|
1564
|
+
|
|
1565
|
+
isStaticOptionsNamePrefix(staticOptionNameValue, searchValue) {
|
|
1566
|
+
return staticOptionNameValue && staticOptionNameValue.trim().toLowerCase().startsWith(searchValue)
|
|
1567
|
+
}
|
|
1568
|
+
|
|
1555
1569
|
async populateOptionsDynamically(resourceEndpoint, searchValue, textInput, templateProvider) {
|
|
1556
1570
|
try {
|
|
1557
1571
|
const response = await fetch(resourceEndpoint.replace('{prefix}', encodeURI(searchValue)));
|
|
@@ -1575,7 +1589,7 @@ class Autocomplete extends DprClientClass {
|
|
|
1575
1589
|
event.preventDefault();
|
|
1576
1590
|
// eslint-disable-next-line no-param-reassign
|
|
1577
1591
|
textInput.value = event.target.innerText.trim();
|
|
1578
|
-
textInput.
|
|
1592
|
+
textInput.staticOptionNameValue = event.target.dataset.staticOptionNameValue;
|
|
1579
1593
|
textInput.focus();
|
|
1580
1594
|
const changeEvent = new Event('change');
|
|
1581
1595
|
textInput.dispatchEvent(changeEvent);
|
|
@@ -108,10 +108,10 @@ const formatTableRow = (data, type) => {
|
|
|
108
108
|
},
|
|
109
109
|
];
|
|
110
110
|
};
|
|
111
|
-
const getTotals = (
|
|
111
|
+
const getTotals = (formattedCount, maxRows) => {
|
|
112
112
|
return {
|
|
113
|
-
amount:
|
|
114
|
-
shown:
|
|
113
|
+
amount: formattedCount,
|
|
114
|
+
shown: formattedCount > maxRows ? maxRows : formattedCount,
|
|
115
115
|
max: maxRows,
|
|
116
116
|
};
|
|
117
117
|
};
|
|
@@ -192,6 +192,7 @@ const renderList = async ({ res, storeService, maxRows, filterFunction, type, })
|
|
|
192
192
|
const { csrfToken, userId } = localsHelper_1.default.getValues(res);
|
|
193
193
|
const reportsData = await storeService.getAllReports(userId);
|
|
194
194
|
let formatted = reportsData.filter(filterFunction).map(formatData);
|
|
195
|
+
const formattedCount = formatted.length;
|
|
195
196
|
if (maxRows)
|
|
196
197
|
formatted = formatted.slice(0, maxRows);
|
|
197
198
|
const tableData = formatTable(formatted, type);
|
|
@@ -202,7 +203,7 @@ const renderList = async ({ res, storeService, maxRows, filterFunction, type, })
|
|
|
202
203
|
const result = {
|
|
203
204
|
head,
|
|
204
205
|
tableData,
|
|
205
|
-
total: getTotals(
|
|
206
|
+
total: getTotals(formattedCount, maxRows),
|
|
206
207
|
meta: getMeta(formatted),
|
|
207
208
|
csrfToken,
|
|
208
209
|
maxRows,
|
|
@@ -140,10 +140,10 @@ const formatTableRow = (data: FormattedUserReportData, type: 'requested' | 'view
|
|
|
140
140
|
]
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
const getTotals = (
|
|
143
|
+
const getTotals = (formattedCount: number, maxRows: number) => {
|
|
144
144
|
return {
|
|
145
|
-
amount:
|
|
146
|
-
shown:
|
|
145
|
+
amount: formattedCount,
|
|
146
|
+
shown: formattedCount > maxRows ? maxRows : formattedCount,
|
|
147
147
|
max: maxRows,
|
|
148
148
|
}
|
|
149
149
|
}
|
|
@@ -242,6 +242,7 @@ const renderList = async ({
|
|
|
242
242
|
const reportsData: UserReportData[] = await storeService.getAllReports(userId)
|
|
243
243
|
|
|
244
244
|
let formatted = reportsData.filter(filterFunction).map(formatData)
|
|
245
|
+
const formattedCount = formatted.length
|
|
245
246
|
if (maxRows) formatted = formatted.slice(0, maxRows)
|
|
246
247
|
const tableData = formatTable(formatted, type)
|
|
247
248
|
|
|
@@ -252,7 +253,7 @@ const renderList = async ({
|
|
|
252
253
|
const result = {
|
|
253
254
|
head,
|
|
254
255
|
tableData,
|
|
255
|
-
total: getTotals(
|
|
256
|
+
total: getTotals(formattedCount, maxRows),
|
|
256
257
|
meta: getMeta(formatted),
|
|
257
258
|
csrfToken,
|
|
258
259
|
maxRows,
|
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.34.
|
|
4
|
+
"version": "3.34.2",
|
|
5
5
|
"main": "dpr/assets/js/all.mjs",
|
|
6
6
|
"sass": "dpr/all.scss",
|
|
7
7
|
"engines": {
|
package/package.zip
CHANGED
|
Binary file
|