From 836ba2ade1f86931dfcb3180e39ce857d63cfbad Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Mon, 17 Dec 2018 11:52:03 +0100 Subject: [PATCH] SONAR-10062 improve the way to truncate project names in dashboard --- .../nav/component/ComponentNavHeader.tsx | 20 +++++++------------ .../__tests__/ComponentNavHeader-test.tsx | 16 +++++++-------- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavHeader.tsx b/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavHeader.tsx index 6e847bd13bd..ac4bc1690c6 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavHeader.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavHeader.tsx @@ -22,22 +22,17 @@ import { connect } from 'react-redux'; import { Link } from 'react-router'; import ComponentNavBranch from './ComponentNavBranch'; import QualifierIcon from '../../../../components/icons-components/QualifierIcon'; -import { - getOrganizationByKey, - areThereCustomOrganizations, - Store -} from '../../../../store/rootReducer'; +import { getOrganizationByKey, Store } from '../../../../store/rootReducer'; import OrganizationAvatar from '../../../../components/common/OrganizationAvatar'; import OrganizationHelmet from '../../../../components/common/OrganizationHelmet'; import OrganizationLink from '../../../../components/ui/OrganizationLink'; import { sanitizeAlmId } from '../../../../helpers/almIntegrations'; -import { collapsePath, limitComponentName } from '../../../../helpers/path'; +import { collapsePath } from '../../../../helpers/path'; import { getProjectUrl, getBaseUrl } from '../../../../helpers/urls'; import { isSonarCloud } from '../../../../helpers/system'; interface StateProps { organization?: T.Organization; - shouldOrganizationBeDisplayed?: boolean; } interface OwnProps { @@ -50,16 +45,16 @@ interface OwnProps { interface Props extends StateProps, OwnProps {} export function ComponentNavHeader(props: Props) { - const { component, organization, shouldOrganizationBeDisplayed } = props; + const { component, organization } = props; return (
{organization && - shouldOrganizationBeDisplayed && ( + isSonarCloud() && ( <> { const isPath = item.qualifier === 'DIR'; - const itemName = isPath ? collapsePath(item.name, 15) : limitComponentName(item.name); + const itemName = isPath ? collapsePath(item.name, 15) : item.name; return ( @@ -122,8 +117,7 @@ function renderBreadcrumbs(breadcrumbs: T.Breadcrumb[]) { } const mapStateToProps = (state: Store, ownProps: OwnProps): StateProps => ({ - organization: getOrganizationByKey(state, ownProps.component.organization), - shouldOrganizationBeDisplayed: areThereCustomOrganizations(state) + organization: getOrganizationByKey(state, ownProps.component.organization) }); export default connect(mapStateToProps)(ComponentNavHeader); diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavHeader-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavHeader-test.tsx index d28d94a1e11..cc651f73d1b 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavHeader-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavHeader-test.tsx @@ -41,20 +41,20 @@ const organization: T.Organization = { projectVisibility: 'public' }; +beforeEach(() => { + (isSonarCloud as jest.Mock).mockReturnValue(false); +}); + it('should not render breadcrumbs with one element', () => { expect( shallow( - + ) ).toMatchSnapshot(); }); it('should render organization', () => { + (isSonarCloud as jest.Mock).mockReturnValue(true); expect( shallow( { component={component} currentBranchLike={undefined} organization={organization} - shouldOrganizationBeDisplayed={true} /> ) ).toMatchSnapshot(); }); it('should render alm links', () => { - (isSonarCloud as jest.Mock).mockReturnValueOnce(true); + (isSonarCloud as jest.Mock).mockReturnValue(true); expect( shallow( { }} currentBranchLike={undefined} organization={organization} - shouldOrganizationBeDisplayed={true} /> ) ).toMatchSnapshot(); -- 2.39.5