@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.
@@ -376,13 +376,13 @@ class DprQueryParamClass extends DprClientClass {
376
376
  } else {
377
377
  const { name } = input;
378
378
  let { value } = input;
379
- let { staticOptionValue } = input;
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 && staticOptionValue ? staticOptionValue : value;
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.staticOptionValue) {
1013
- formData.set(input.name, input.staticOptionValue);
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 && item.innerText.trim().toLowerCase().includes(searchValue)) {
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.staticOptionValue = event.target.dataset.staticOptionValue;
1592
+ textInput.staticOptionNameValue = event.target.dataset.staticOptionNameValue;
1579
1593
  textInput.focus();
1580
1594
  const changeEvent = new Event('change');
1581
1595
  textInput.dispatchEvent(changeEvent);
@@ -69,7 +69,7 @@
69
69
  classes: "govuk-button--inverse autocomplete-text-input-list-button",
70
70
  attributes: {
71
71
  "data-parent-input": options.id,
72
- "data-static-option-value": item.value
72
+ "data-static-option-name-value": item.value
73
73
  }
74
74
  }) }}
75
75
  </li>
@@ -108,10 +108,10 @@ const formatTableRow = (data, type) => {
108
108
  },
109
109
  ];
110
110
  };
111
- const getTotals = (reportData, maxRows) => {
111
+ const getTotals = (formattedCount, maxRows) => {
112
112
  return {
113
- amount: reportData.length,
114
- shown: reportData.length > maxRows ? maxRows : reportData.length,
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(reportsData, maxRows),
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 = (reportData: UserReportData[], maxRows: number) => {
143
+ const getTotals = (formattedCount: number, maxRows: number) => {
144
144
  return {
145
- amount: reportData.length,
146
- shown: reportData.length > maxRows ? maxRows : reportData.length,
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(reportsData, maxRows),
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.0",
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