diff options
author | Jeremy Davis <jeremy.davis@sonarsource.com> | 2023-09-18 11:04:19 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2023-09-18 20:02:47 +0000 |
commit | 2d51ef57c9c00f6e1627e66443f42c8fde7d0bed (patch) | |
tree | 9bfaa0d42e59e9b070b9742e4763090a2f682d89 | |
parent | 252bd91fa084768f2733474bb73022b66d7e623e (diff) | |
download | sonarqube-2d51ef57c9c00f6e1627e66443f42c8fde7d0bed.tar.gz sonarqube-2d51ef57c9c00f6e1627e66443f42c8fde7d0bed.zip |
SONAR-20382 Prevent page from refreshing
-rw-r--r-- | server/sonar-web/src/main/js/app/components/ComponentContainer.tsx | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/server/sonar-web/src/main/js/app/components/ComponentContainer.tsx b/server/sonar-web/src/main/js/app/components/ComponentContainer.tsx index ba21badbec4..6b37df5b8de 100644 --- a/server/sonar-web/src/main/js/app/components/ComponentContainer.tsx +++ b/server/sonar-web/src/main/js/app/components/ComponentContainer.tsx @@ -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); } }, ); |