aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Cho-Lerat <david.cho-lerat@sonarsource.com>2023-07-25 12:21:04 +0200
committersonartech <sonartech@sonarsource.com>2023-07-25 20:03:08 +0000
commit3a6f4755225e09971e99d7e75ea1b97a85634084 (patch)
treec93e561450d7628df0a8e9acc6a88d68409c3887
parent6d373c90f7737e245a3f3aca1d509da91b1f3429 (diff)
downloadsonarqube-3a6f4755225e09971e99d7e75ea1b97a85634084.tar.gz
sonarqube-3a6f4755225e09971e99d7e75ea1b97a85634084.zip
SONAR-20016 Do not load issues or hotspots twice on page refresh
-rw-r--r--server/sonar-web/src/main/js/apps/issues/components/IssuesApp.tsx6
-rw-r--r--server/sonar-web/src/main/js/apps/security-hotspots/SecurityHotspotsApp.tsx5
-rw-r--r--server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsApp-it.tsx7
-rw-r--r--server/sonar-web/src/main/js/queries/branch.tsx7
4 files changed, 19 insertions, 6 deletions
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<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) {
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<Props, State> {
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<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}
/>
);