]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-20022 disable overview tab when in tutorial
authorJeremy Davis <jeremy.davis@sonarsource.com>
Wed, 6 Dec 2023 16:32:05 +0000 (17:32 +0100)
committersonartech <sonartech@sonarsource.com>
Thu, 7 Dec 2023 20:02:52 +0000 (20:02 +0000)
server/sonar-web/src/main/js/app/components/nav/component/Menu.tsx
server/sonar-web/src/main/js/app/components/nav/component/__tests__/Menu-test.tsx

index 0ebe49b816c81f9f20e9a6f35bb33d923e1e96c1..088cae081609cd498409964b83008a5bd57ef430 100644 (file)
@@ -26,7 +26,7 @@ import {
   PopupZLevel,
 } from 'design-system';
 import * as React from 'react';
-import Tooltip from '../../../../components/controls/Tooltip';
+import { useLocation } from '../../../../components/hoc/withRouter';
 import { DEFAULT_ISSUES_QUERY } from '../../../../components/shared/utils';
 import { getBranchLikeQuery, isPullRequest } from '../../../../helpers/branch-like';
 import { hasMessage, translate, translateWithParameters } from '../../../../helpers/l10n';
@@ -69,12 +69,14 @@ interface Props extends WithAvailableFeaturesProps {
 
 type Query = BranchParameters & { id: string };
 
-export function Menu(props: Props) {
+export function Menu(props: Readonly<Props>) {
   const { component, isInProgress, isPending } = props;
   const { extensions = [], canBrowseAllChildProjects, qualifier, configuration = {} } = component;
   const { data: { branchLikes, branchLike } = { branchLikes: [] } } = useBranchesQuery(component);
   const isApplicationChildInaccessble = isApplication(qualifier) && !canBrowseAllChildProjects;
 
+  const location = useLocation();
+
   const hasAnalysis = () => {
     const hasBranches = branchLikes.length > 1;
     return hasBranches || isInProgress || isPending || component.analysisDate !== undefined;
@@ -88,20 +90,15 @@ export function Menu(props: Props) {
     return { id: component.key, ...getBranchLikeQuery(branchLike) };
   };
 
-  const renderLinkWhenInaccessibleChild = (label: React.ReactNode) => {
+  const renderLinkWhenInaccessibleChild = (label: string) => {
     return (
-      <li>
-        <Tooltip
-          overlay={translateWithParameters(
-            'layout.all_project_must_be_accessible',
-            translate('qualifier', qualifier),
-          )}
-        >
-          <a aria-disabled="true" className="disabled-link">
-            {label}
-          </a>
-        </Tooltip>
-      </li>
+      <DisabledTabLink
+        overlay={translateWithParameters(
+          'layout.all_project_must_be_accessible',
+          translate('qualifier', qualifier),
+        )}
+        label={label}
+      />
     );
   };
 
@@ -140,6 +137,17 @@ export function Menu(props: Props) {
       ) : null;
     }
 
+    const showingTutorial = location.pathname.includes('/tutorials');
+
+    if (showingTutorial) {
+      return (
+        <DisabledTabLink
+          overlay={translate('layout.must_be_configured')}
+          label={translate('overview.page')}
+        />
+      );
+    }
+
     if (isApplicationChildInaccessble) {
       return renderLinkWhenInaccessibleChild(translate('overview.page'));
     }
index 1953d456f1e368666759ea21f64d6bcdc240df67..5f74eab6940c80589eafc61dd220864779c638b9 100644 (file)
@@ -139,9 +139,15 @@ it('should disable links if no analysis has been done', () => {
       analysisDate: undefined,
     },
   });
-  expect(screen.getByRole('link', { name: 'overview.page' })).toBeInTheDocument();
-  expect(screen.queryByRole('link', { name: 'issues.page' })).toHaveClass('disabled-link');
-  expect(screen.queryByRole('link', { name: 'layout.measures' })).toHaveClass('disabled-link');
+
+  expect(screen.queryByRole('link', { name: 'issues.page' })).toHaveAttribute(
+    'aria-disabled',
+    'true',
+  );
+  expect(screen.queryByRole('link', { name: 'layout.measures' })).toHaveAttribute(
+    'aria-disabled',
+    'true',
+  );
   expect(screen.getByRole('link', { name: 'project.info.title' })).toBeInTheDocument();
 });
 
@@ -153,9 +159,18 @@ it('should disable links if application has inaccessible projects', () => {
       canBrowseAllChildProjects: false,
     },
   });
-  expect(screen.queryByRole('link', { name: 'overview.page' })).not.toBeInTheDocument();
-  expect(screen.queryByRole('link', { name: 'issues.page' })).not.toBeInTheDocument();
-  expect(screen.queryByRole('link', { name: 'layout.measures' })).not.toBeInTheDocument();
+  expect(screen.queryByRole('link', { name: 'overview.page' })).toHaveAttribute(
+    'aria-disabled',
+    'true',
+  );
+  expect(screen.queryByRole('link', { name: 'issues.page' })).toHaveAttribute(
+    'aria-disabled',
+    'true',
+  );
+  expect(screen.queryByRole('link', { name: 'layout.measures' })).toHaveAttribute(
+    'aria-disabled',
+    'true',
+  );
   expect(screen.queryByRole('button', { name: 'application.info.title' })).not.toBeInTheDocument();
 });