[HOTE-974] feat: [SonarQube] Address issues in UI#291
Merged
Conversation
Contributor
There was a problem hiding this comment.
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
renderTextWithLinksconditional 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
lookupPostcodeperforms a rawfetchdirectly inside the context provider; in this UI codebase new API calls are expected to go through aui/src/lib/services/*service module to centralise request options (headers, error handling) and keep components/hooks thin. Move the/postcode-lookupcall into a dedicated service (e.g.postcode-lookup-service.ts) and call that service from the context instead of usingfetchhere.
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");
}
|
TSeelig
approved these changes
Mar 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Description
https://nhsd-jira.digital.nhs.uk/browse/HOTE-974
Context
Type of changes
Checklist
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.