From: 7PH Date: Thu, 31 Aug 2023 11:49:59 +0000 (+0200) Subject: SONAR-20283 Fix API call consistently failing after navigating back to an application X-Git-Tag: 10.2.0.77647~9 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7b6de25ed7b86a9c6a4ec44b33c4711011ebea1e;p=sonarqube.git SONAR-20283 Fix API call consistently failing after navigating back to an application --- 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, }); }