]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-20283 Fix API call consistently failing after navigating back to an application
author7PH <benjamin.raymond@sonarsource.com>
Thu, 31 Aug 2023 11:49:59 +0000 (13:49 +0200)
committersonartech <sonartech@sonarsource.com>
Thu, 31 Aug 2023 20:02:57 +0000 (20:02 +0000)
server/sonar-web/src/main/js/app/components/nav/component/AnalysisStatus.tsx
server/sonar-web/src/main/js/queries/branch.tsx

index b76fbe499de26a2616e2d62de6f1fe30681b0dfd..88b2addb6b05c1991bb59729f6ea3e7483e9357f 100644 (file)
@@ -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(() => {
index 8fb5bd706b6baeb7f9ba3005c74bb0a4529e1559..604c347231e7c96a9ae733f272f223439670c7e4 100644 (file)
@@ -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,
   });
 }