From: David Cho-Lerat Date: Tue, 25 Jul 2023 10:21:04 +0000 (+0200) Subject: SONAR-20016 Do not load issues or hotspots twice on page refresh X-Git-Tag: 10.2.0.77647~299 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3a6f4755225e09971e99d7e75ea1b97a85634084;p=sonarqube.git SONAR-20016 Do not load issues or hotspots twice on page refresh --- diff --git a/server/sonar-web/src/main/js/apps/issues/components/IssuesApp.tsx b/server/sonar-web/src/main/js/apps/issues/components/IssuesApp.tsx index b8ac93b2d81..a10a9e73540 100644 --- a/server/sonar-web/src/main/js/apps/issues/components/IssuesApp.tsx +++ b/server/sonar-web/src/main/js/apps/issues/components/IssuesApp.tsx @@ -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 { addWhitePageClass(); addSideBarClass(); this.attachShortcuts(); - this.fetchFirstIssues(true).catch(() => undefined); + + if (!this.props.isFetchingBranch) { + this.fetchFirstIssues(true).catch(() => undefined); + } } componentDidUpdate(prevProps: Props, prevState: State) { diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/SecurityHotspotsApp.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/SecurityHotspotsApp.tsx index b9c9a1947cd..f72eef42dbf 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/SecurityHotspotsApp.tsx +++ b/server/sonar-web/src/main/js/apps/security-hotspots/SecurityHotspotsApp.tsx @@ -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 { componentDidMount() { this.mounted = true; - this.fetchInitialData(); + if (!this.props.isFetchingBranch) { + this.fetchInitialData(); + } this.registerKeyboardEvents(); } diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsApp-it.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsApp-it.tsx index 931c291c9e7..07d5ffe584b 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsApp-it.tsx +++ b/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsApp-it.tsx @@ -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 diff --git a/server/sonar-web/src/main/js/queries/branch.tsx b/server/sonar-web/src/main/js/queries/branch.tsx index add79f22f14..f7e7ae28896 100644 --- a/server/sonar-web/src/main/js/queries/branch.tsx +++ b/server/sonar-web/src/main/js/queries/branch.tsx @@ -324,14 +324,17 @@ export function useRefreshBranches() { } export function withBranchLikes

( - WrappedComponent: React.ComponentType

+ WrappedComponent: React.ComponentType< + P & { branchLikes?: BranchLike[]; branchLike?: BranchLike; isFetchingBranch?: boolean } + > ): React.ComponentType> { return function WithBranchLike(p: P) { - const { data } = useBranchesQuery(p.component); + const { data, isFetching } = useBranchesQuery(p.component); return ( );