Skip to content

[HOTE-974] feat: [SonarQube] Address issues in UI#291

Merged
cptiv2020 merged 2 commits intomainfrom
feature/hote-974/sonarqube
Mar 27, 2026
Merged

[HOTE-974] feat: [SonarQube] Address issues in UI#291
cptiv2020 merged 2 commits intomainfrom
feature/hote-974/sonarqube

Conversation

@cptiv2020
Copy link
Copy Markdown
Contributor

Description

https://nhsd-jira.digital.nhs.uk/browse/HOTE-974

Context

Type of changes

  • Refactoring (non-breaking change)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would change existing functionality)
  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I am familiar with the contributing guidelines
  • I have followed the code style of the project
  • I have added tests to cover my changes
  • I have updated the documentation accordingly
  • This PR is a result of pair or mob programming

Sensitive Information Declaration

To ensure the utmost confidentiality and protect your and others privacy, we kindly ask you to NOT including PII (Personal Identifiable Information) / PID (Personal Identifiable Data) or any other sensitive data in this PR (Pull Request) and the codebase changes. We will remove any PR that do contain any sensitive information. We really appreciate your cooperation in this matter.

  • I confirm that neither PII/PID nor sensitive data are included in this PR and the codebase changes.

Copilot AI review requested due to automatic review settings March 27, 2026 11:00
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 27, 2026

UI Coverage Report

Lines Statements Branches Functions
Coverage: 95%
95.5% (5583/5846) 87.28% (652/747) 87.5% (203/232)

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 27, 2026

Lambdas Coverage Report

Lines Statements Branches Functions
Coverage: 96%
97% (1164/1200) 89.9% (365/406) 94.14% (177/188)

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses SonarQube-reported issues in the UI by improving React hook stability (memoised context values/callbacks) and adjusting a couple of JSX patterns.

Changes:

  • Memoise context provider values (and relevant callbacks) to reduce unnecessary re-renders.
  • Tidy renderTextWithLinks conditional flow / imports.
  • Update address rendering to avoid using array index keys (but see comment re: key uniqueness).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
ui/src/utils/renderTextWithLinks.tsx Minor refactor of branching/import formatting.
ui/src/state/PostcodeLookupContext.tsx Memoises lookupPostcode and provider value.
ui/src/state/OrderContext.tsx Memoises provider value object.
ui/src/state/NavigationContext.tsx Memoises provider value object.
ui/src/routes/get-self-test-kit-for-HIV-journey/CheckYourAnswersPage.tsx Switches to React.Fragment with non-index keys for address line rendering.
Comments suppressed due to low confidence (1)

ui/src/state/PostcodeLookupContext.tsx:124

  • lookupPostcode performs a raw fetch directly inside the context provider; in this UI codebase new API calls are expected to go through a ui/src/lib/services/* service module to centralise request options (headers, error handling) and keep components/hooks thin. Move the /postcode-lookup call into a dedicated service (e.g. postcode-lookup-service.ts) and call that service from the context instead of using fetch here.
  const lookupPostcode = useCallback(async (postcodeValue: string): Promise<void> => {
    setIsLoading(true);
    setError(null);
    setAddresses([]);

    try {
      const url = new URL(`${backendUrl}/postcode-lookup`);
      url.searchParams.append("postcode", postcodeValue);
      const response = await fetch(url.toString());

      if (!response.ok) {
        throw new Error("Failed to lookup postcode");
      }

Comment thread ui/src/routes/get-self-test-kit-for-HIV-journey/CheckYourAnswersPage.tsx Outdated
@sonarqubecloud
Copy link
Copy Markdown

@cptiv2020 cptiv2020 merged commit d8cc208 into main Mar 27, 2026
11 checks passed
@cptiv2020 cptiv2020 deleted the feature/hote-974/sonarqube branch March 27, 2026 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants