From e8e8e65535302366470e8275a8ddd0e34a94855b Mon Sep 17 00:00:00 2001 From: ColinBruce Date: Mon, 23 Sep 2024 12:54:02 +0100 Subject: [PATCH 1/2] AP-5315: Fix SCA proceeding search bug When LFA returns a code that is not present on the page, i.e. an SCA related proceeding on an initial search, previously it showed the failure message and returned from the loop. This updates the proceedings javascript so that it counts successfully displayed proceedings, using a new, `shown`, variable. After the loop is complete it then sets the ariaText and shows/hides the no-proceeding-items element accordingly. --- app/javascript/src/modules/proceedings.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/app/javascript/src/modules/proceedings.js b/app/javascript/src/modules/proceedings.js index b4a35bde45..84ac455278 100644 --- a/app/javascript/src/modules/proceedings.js +++ b/app/javascript/src/modules/proceedings.js @@ -109,6 +109,7 @@ function showResults (results, inputText) { if (results.length > 0) { deselectPreviousProceedingItem() const codes = results.map(obj => obj.ccms_code) + let shown = 0 let proceedingsContainer = document.querySelector('.govuk-radios') // with MP flag on if (proceedingsContainer == null) { proceedingsContainer = document.querySelector('#proceeding-list') } // with MP flag off codes.forEach((code, idx) => { @@ -119,12 +120,9 @@ function showResults (results, inputText) { // proceedings is turned off, then codes will only contain those proceeding types // that are not filtered out by the LegalFramework::ProceedingTypes::All service, // so we just ignore them here if they aren't in the list - if (element == null) { - show(document.querySelector('.no-proceeding-items')) - ariaText = `No results found matching ${inputText}` - return - } + if (element == null) { return } + shown++ // increment the count if this code is actually shown to the user // We want to highlight anything in the label or hint text that // matches the user's search criteria const label = element.querySelector('label') @@ -153,11 +151,18 @@ function showResults (results, inputText) { proceedingsContainer.insertBefore(element, proceedingsContainer.children[idx]) // show hidden proceedings item show(element) - hide(document.querySelector('.no-proceeding-items')) }) - // the below alerts screen reader users that results appeared on the page - const pluralizedMatches = pluralize(codes.length, 'match', 'matches') - ariaText = `${codes.length} ${pluralizedMatches} found for ${inputText}, use tab to move to options` + // once we have looped over all returned codes, check if any were shown to the user + // and set the appropriate ariaText and show/hide the no-proceedings found element + if (shown > 0) { + // the below alerts screen reader users that results appeared on the page + const pluralizedMatches = pluralize(codes.length, 'match', 'matches') + ariaText = `${codes.length} ${pluralizedMatches} found for ${inputText}, use tab to move to options` + hide(document.querySelector('.no-proceeding-items')) + } else { + show(document.querySelector('.no-proceeding-items')) + ariaText = `No results found matching ${inputText}` + } } else { show(document.querySelector('.no-proceeding-items')) ariaText = `No results found matching ${inputText}` From 03a4053b43bd7450f24378c5d8a83561ece9900a Mon Sep 17 00:00:00 2001 From: ColinBruce Date: Tue, 24 Sep 2024 07:43:30 +0100 Subject: [PATCH 2/2] AP-5315: extract repeated code to method --- app/javascript/src/modules/proceedings.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/javascript/src/modules/proceedings.js b/app/javascript/src/modules/proceedings.js index 84ac455278..cd2faf76dd 100644 --- a/app/javascript/src/modules/proceedings.js +++ b/app/javascript/src/modules/proceedings.js @@ -160,15 +160,18 @@ function showResults (results, inputText) { ariaText = `${codes.length} ${pluralizedMatches} found for ${inputText}, use tab to move to options` hide(document.querySelector('.no-proceeding-items')) } else { - show(document.querySelector('.no-proceeding-items')) - ariaText = `No results found matching ${inputText}` + showNoResults(inputText) } } else { - show(document.querySelector('.no-proceeding-items')) - ariaText = `No results found matching ${inputText}` + showNoResults(inputText) } } +function showNoResults (inputText) { + show(document.querySelector('.no-proceeding-items')) + ariaText = `No results found matching ${inputText}` +} + // Hide any search results and the 'no results found' text function hideProceeedingsItems () { document