]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-19218 + SONAR-19491 Fix redirection links
authorDavid Cho-Lerat <david.cho-lerat@sonarsource.com>
Mon, 12 Jun 2023 13:34:35 +0000 (15:34 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 13 Jun 2023 20:03:36 +0000 (20:03 +0000)
server/sonar-web/design-system/src/components/MainAppBar.tsx
server/sonar-web/design-system/src/components/__tests__/MainAppBar-test.tsx
server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/IssueSourceViewerHeader.tsx
server/sonar-web/src/main/js/components/SourceViewer/SourceViewerHeader.tsx

index b3575702258afaa22ebd4b652d1f8dd300391a5b..0712a133143925d19c97420738f9e5f692b7111b 100644 (file)
@@ -28,6 +28,7 @@ import {
   LAYOUT_VIEWPORT_MIN_WIDTH,
 } from '../helpers/constants';
 import { themeBorder, themeColor, themeContrast } from '../helpers/theme';
+import { BaseLink } from './Link';
 
 const MainAppBarDiv = styled.div`
   ${tw`sw-sticky sw-top-0`}
@@ -57,7 +58,7 @@ const MainAppBarNavLogoDiv = styled.div`
   }
 `;
 
-const MainAppBarNavLogoLink = styled.a`
+const MainAppBarNavLogoLink = styled(BaseLink)`
   border: none;
 `;
 
@@ -73,7 +74,7 @@ export function MainAppBar({
   return (
     <MainAppBarDiv>
       <MainAppBarNavLogoDiv>
-        <MainAppBarNavLogoLink href="/">
+        <MainAppBarNavLogoLink to="/">
           <Logo />
         </MainAppBarNavLogoLink>
       </MainAppBarNavLogoDiv>
index fdc66f2a44151723b4d587555abbb79d5b457c35..7a8672844620f53a5e384584d5fa0240979c2f6a 100644 (file)
@@ -21,6 +21,7 @@
 /* eslint-disable import/no-extraneous-dependencies */
 
 import { screen } from '@testing-library/react';
+import { MemoryRouter, Route, Routes } from 'react-router-dom';
 import { LAYOUT_LOGO_MAX_HEIGHT, LAYOUT_LOGO_MAX_WIDTH } from '../../helpers/constants';
 import { render } from '../../helpers/testUtils';
 import { FCProps } from '../../types/misc';
@@ -50,5 +51,11 @@ function setupWithProps(
     Logo: () => <img alt="logo" src="http://example.com/logo.png" />,
   }
 ) {
-  return render(<MainAppBar {...props} />);
+  return render(
+    <MemoryRouter initialEntries={['/']}>
+      <Routes>
+        <Route element={<MainAppBar {...props} />} path="/" />
+      </Routes>
+    </MemoryRouter>
+  );
 }
index 5115e878787286d59b6a7513e9c7ef37c6a5bdc3..736dfd99379378e27d7f7c41262ecc8993b7de80 100644 (file)
@@ -39,7 +39,7 @@ import { ClipboardBase } from '../../../components/controls/clipboard';
 import { getBranchLikeQuery } from '../../../helpers/branch-like';
 import { translate } from '../../../helpers/l10n';
 import { collapsedDirFromPath, fileFromPath } from '../../../helpers/path';
-import { getBranchLikeUrl, getComponentIssuesUrl, getPathUrlAsString } from '../../../helpers/urls';
+import { getBranchLikeUrl, getComponentIssuesUrl } from '../../../helpers/urls';
 import { BranchLike } from '../../../types/branch-like';
 import { ComponentQualifier } from '../../../types/component';
 import { SourceViewerFile } from '../../../types/types';
@@ -93,10 +93,7 @@ function IssueSourceViewerHeader(props: Props & ThemeProp) {
         {displayProjectName && (
           <>
             {linkToProject ? (
-              <HoverLink
-                to={getPathUrlAsString(getBranchLikeUrl(project, branchLike))}
-                className="sw-mr-2"
-              >
+              <HoverLink to={getBranchLikeUrl(project, branchLike)} className="sw-mr-2">
                 <LightLabel>{projectName}</LightLabel>
               </HoverLink>
             ) : (
index ce3f530e3c0c1fde1f44b6b6ebaa1ff62856f02d..63cad19a21352b7e7914b7520ff912a189c1b5a6 100644 (file)
@@ -51,7 +51,6 @@ import {
   getCodeUrl,
   getComponentIssuesUrl,
   getComponentSecurityHotspotsUrl,
-  getPathUrlAsString,
 } from '../../helpers/urls';
 
 import { ComponentQualifier } from '../../types/component';
@@ -143,10 +142,7 @@ export default class SourceViewerHeader extends React.PureComponent<Props> {
       >
         <div className="sw-flex sw-flex-1 sw-flex-col sw-gap-1 sw-mr-5 sw-my-1">
           <div className="sw-flex sw-gap-1 sw-items-center">
-            <Link
-              icon={<ProjectIcon />}
-              to={getPathUrlAsString(getBranchLikeUrl(project, this.props.branchLike))}
-            >
+            <Link icon={<ProjectIcon />} to={getBranchLikeUrl(project, this.props.branchLike)}>
               {projectName}
             </Link>
           </div>