]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-20382 Prevent page from refreshing
authorJeremy Davis <jeremy.davis@sonarsource.com>
Mon, 18 Sep 2023 09:04:19 +0000 (11:04 +0200)
committersonartech <sonartech@sonarsource.com>
Mon, 18 Sep 2023 20:02:47 +0000 (20:02 +0000)
server/sonar-web/src/main/js/app/components/ComponentContainer.tsx

index ba21badbec4df0d9e3d15074a0db0a3bf1ed4527..6b37df5b8de47ac797e2f3f3559a2b75313cab2a 100644 (file)
@@ -88,9 +88,25 @@ export class ComponentContainer extends React.PureComponent<Props, State> {
     window.clearTimeout(this.watchStatusTimer);
   }
 
-  fetchComponent = async (shouldRedirectToDashboard = false) => {
+  redirectIfNeeded = (componentWithQualifier: { key: string; qualifier: string }) => {
+    /*
+     * There used to be a redirect from /dashboard to /portfolio which caused issues.
+     * Links should be fixed to not rely on this redirect, but:
+     * This is a fail-safe in case there are still some faulty links remaining.
+     */
+    if (
+      this.props.location.pathname.includes('dashboard') &&
+      isPortfolioLike(componentWithQualifier.qualifier)
+    ) {
+      this.props.router.replace(getPortfolioUrl(componentWithQualifier.key));
+    }
+  };
+
+  fetchComponent = async (shouldRedirectToDashboard = false, backgroundLoading = false) => {
     const { branch, id: key, pullRequest } = this.props.location.query;
-    this.setState({ loading: true });
+    if (!backgroundLoading) {
+      this.setState({ loading: true });
+    }
 
     let componentWithQualifier;
     try {
@@ -102,7 +118,7 @@ export class ComponentContainer extends React.PureComponent<Props, State> {
       componentWithQualifier = this.addQualifier({ ...nav, ...component });
     } catch (e) {
       if (this.mounted) {
-        if (e && e instanceof Response && e.status === HttpStatus.Forbidden) {
+        if (e instanceof Response && e.status === HttpStatus.Forbidden) {
           handleRequiredAuthorization();
         } else {
           this.setState({ component: undefined, loading: false });
@@ -112,17 +128,7 @@ export class ComponentContainer extends React.PureComponent<Props, State> {
       return;
     }
 
-    /*
-     * There used to be a redirect from /dashboard to /portfolio which caused issues.
-     * Links should be fixed to not rely on this redirect, but:
-     * This is a fail-safe in case there are still some faulty links remaining.
-     */
-    if (
-      this.props.location.pathname.includes('dashboard') &&
-      isPortfolioLike(componentWithQualifier.qualifier)
-    ) {
-      this.props.router.replace(getPortfolioUrl(componentWithQualifier.key));
-    }
+    this.redirectIfNeeded(componentWithQualifier);
 
     if (this.mounted) {
       this.setState(
@@ -185,7 +191,7 @@ export class ComponentContainer extends React.PureComponent<Props, State> {
             },
             () => {
               if (shouldFetchComponent) {
-                this.fetchComponent(shouldRedirectToDashboard);
+                this.fetchComponent(shouldRedirectToDashboard, true);
               }
             },
           );