From 7b6de25ed7b86a9c6a4ec44b33c4711011ebea1e Mon Sep 17 00:00:00 2001 From: 7PH Date: Thu, 31 Aug 2023 13:49:59 +0200 Subject: [PATCH] SONAR-20283 Fix API call consistently failing after navigating back to an application --- .../js/app/components/nav/component/AnalysisStatus.tsx | 4 ++-- server/sonar-web/src/main/js/queries/branch.tsx | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/server/sonar-web/src/main/js/app/components/nav/component/AnalysisStatus.tsx b/server/sonar-web/src/main/js/app/components/nav/component/AnalysisStatus.tsx index b76fbe499de..88b2addb6b0 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/AnalysisStatus.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/AnalysisStatus.tsx @@ -20,7 +20,7 @@ import { FlagMessage, Link, Spinner } from 'design-system'; import * as React from 'react'; import { translate } from '../../../../helpers/l10n'; -import { useBranchWarrningQuery } from '../../../../queries/branch'; +import { useBranchWarningQuery } from '../../../../queries/branch'; import { Task, TaskStatuses } from '../../../../types/tasks'; import { Component } from '../../../../types/types'; import { AnalysisErrorModal } from './AnalysisErrorModal'; @@ -35,7 +35,7 @@ export interface HeaderMetaProps { export function AnalysisStatus(props: HeaderMetaProps) { const { component, currentTask, isInProgress, isPending } = props; - const { data: warnings, isLoading } = useBranchWarrningQuery(component); + const { data: warnings, isLoading } = useBranchWarningQuery(component); const [modalIsVisible, setDisplayModal] = React.useState(false); const openModal = React.useCallback(() => { diff --git a/server/sonar-web/src/main/js/queries/branch.tsx b/server/sonar-web/src/main/js/queries/branch.tsx index 8fb5bd706b6..604c347231e 100644 --- a/server/sonar-web/src/main/js/queries/branch.tsx +++ b/server/sonar-web/src/main/js/queries/branch.tsx @@ -166,11 +166,12 @@ export function useBranchStatusQuery(component: Component) { }); } -export function useBranchWarrningQuery(component: Component) { +export function useBranchWarningQuery(component: Component) { const branchQuery = useBranchesQuery(component); const branchLike = branchQuery.data?.branchLike; + const key = useBranchesQueryKey(InnerState.Warning); return useQuery({ - queryKey: useBranchesQueryKey(InnerState.Warning), + queryKey: key, queryFn: async ({ queryKey }) => { const { query, componentKey } = getContext(queryKey); const { component: branchStatus } = await getAnalysisStatus({ @@ -179,7 +180,7 @@ export function useBranchWarrningQuery(component: Component) { }); return branchStatus.warnings; }, - enabled: !!branchLike && isProject(component.qualifier), + enabled: !!branchLike && isProject(component.qualifier) && component.key === key[1], staleTime: BRANCHES_STALE_TIME, }); } -- 2.39.5