]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-20016 Do not load issues or hotspots twice on page refresh
authorDavid Cho-Lerat <david.cho-lerat@sonarsource.com>
Tue, 25 Jul 2023 10:21:04 +0000 (12:21 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 25 Jul 2023 20:03:08 +0000 (20:03 +0000)
server/sonar-web/src/main/js/apps/issues/components/IssuesApp.tsx
server/sonar-web/src/main/js/apps/security-hotspots/SecurityHotspotsApp.tsx
server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsApp-it.tsx
server/sonar-web/src/main/js/queries/branch.tsx

index b8ac93b2d810fdf2df0dcc044879de927dade8fd..a10a9e735403f149cf488c6813107dff7de9b5a6 100644 (file)
@@ -112,6 +112,7 @@ interface Props extends WithIndexationContextProps {
   branchLike?: BranchLike;
   component?: Component;
   currentUser: CurrentUser;
+  isFetchingBranch?: boolean;
   location: Location;
   router: Router;
 }
@@ -217,7 +218,10 @@ export class App extends React.PureComponent<Props, State> {
     addWhitePageClass();
     addSideBarClass();
     this.attachShortcuts();
-    this.fetchFirstIssues(true).catch(() => undefined);
+
+    if (!this.props.isFetchingBranch) {
+      this.fetchFirstIssues(true).catch(() => undefined);
+    }
   }
 
   componentDidUpdate(prevProps: Props, prevState: State) {
index b9c9a1947cdbbb4ab4f3fd374e53ca66d63b23b5..f72eef42dbf3deadaf6eccf296c966561157addb 100644 (file)
@@ -55,6 +55,7 @@ interface Props {
   branchLike?: BranchLike;
   currentUser: CurrentUser;
   component: Component;
+  isFetchingBranch?: boolean;
   location: Location;
   router: Router;
 }
@@ -111,7 +112,9 @@ export class SecurityHotspotsApp extends React.PureComponent<Props, State> {
   componentDidMount() {
     this.mounted = true;
 
-    this.fetchInitialData();
+    if (!this.props.isFetchingBranch) {
+      this.fetchInitialData();
+    }
 
     this.registerKeyboardEvents();
   }
index 931c291c9e7fcb1dde0a968b81b3342559fe721c..07d5ffe584b5e56731c54e723f00390d96206ffb 100644 (file)
@@ -18,7 +18,7 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
 
-import { act, screen } from '@testing-library/react';
+import { act, screen, waitFor } from '@testing-library/react';
 import userEvent from '@testing-library/user-event';
 import React from 'react';
 import { Route } from 'react-router-dom';
@@ -172,7 +172,10 @@ describe('rendering', () => {
       `security_hotspots?id=guillaume-peoch-sonarsource_benflix_AYGpXq2bd8qy4i0eO9ed&files=src%2Findex.js&cwe=foo&inNewCodePeriod=true`
     );
 
-    expect(ui.filterDropdown.query()).not.toBeInTheDocument();
+    await waitFor(() => {
+      expect(ui.filterDropdown.query()).not.toBeInTheDocument();
+    });
+
     expect(ui.filterToReview.query()).not.toBeInTheDocument();
 
     // Drop selection
index add79f22f144639ced399012c17dbc6732dfe036..f7e7ae28896323f5d8d72ecd0857bc10afdd7aee 100644 (file)
@@ -324,14 +324,17 @@ export function useRefreshBranches() {
 }
 
 export function withBranchLikes<P extends { component?: Component }>(
-  WrappedComponent: React.ComponentType<P & { branchLikes?: BranchLike[]; branchLike?: BranchLike }>
+  WrappedComponent: React.ComponentType<
+    P & { branchLikes?: BranchLike[]; branchLike?: BranchLike; isFetchingBranch?: boolean }
+  >
 ): React.ComponentType<Omit<P, 'branchLike' | 'branchLikes'>> {
   return function WithBranchLike(p: P) {
-    const { data } = useBranchesQuery(p.component);
+    const { data, isFetching } = useBranchesQuery(p.component);
     return (
       <WrappedComponent
         branchLikes={data?.branchLikes ?? []}
         branchLike={data?.branchLike}
+        isFetchingBranch={isFetching}
         {...p}
       />
     );