From: Jeremy Davis Date: Wed, 6 Dec 2023 16:32:05 +0000 (+0100) Subject: SONAR-20022 disable overview tab when in tutorial X-Git-Tag: 10.4.0.87286~342 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d9af6f7cec86e6586cab285ecbc647d3e24f56de;p=sonarqube.git SONAR-20022 disable overview tab when in tutorial --- diff --git a/server/sonar-web/src/main/js/app/components/nav/component/Menu.tsx b/server/sonar-web/src/main/js/app/components/nav/component/Menu.tsx index 0ebe49b816c..088cae08160 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/Menu.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/Menu.tsx @@ -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) { 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 ( -
  • - - - {label} - - -
  • + ); }; @@ -140,6 +137,17 @@ export function Menu(props: Props) { ) : null; } + const showingTutorial = location.pathname.includes('/tutorials'); + + if (showingTutorial) { + return ( + + ); + } + if (isApplicationChildInaccessble) { return renderLinkWhenInaccessibleChild(translate('overview.page')); } diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/Menu-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/Menu-test.tsx index 1953d456f1e..5f74eab6940 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/Menu-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/Menu-test.tsx @@ -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(); });