Skip to content

Commit c4f12bf

Browse files
Hartesicsonartech
authored andcommitted
SONAR-26043 Make DOP icon clickable if a repository URL is returned with the project binding
GitOrigin-RevId: b52e5743de64558e06a71c91ede7782c6b44b615
1 parent a5de4a9 commit c4f12bf

File tree

5 files changed

+62
-32
lines changed

5 files changed

+62
-32
lines changed

apps/sq-server/src/main/js/app/components/nav/component/ProjectBindingStatus.tsx

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ import {
2222
Badge,
2323
BadgeSize,
2424
BadgeVariety,
25+
Button,
2526
IconLink,
26-
LinkHighlight,
27-
LinkStandalone,
2827
Spinner,
2928
ToggleTip,
3029
Tooltip,
@@ -91,16 +90,33 @@ export function ProjectBindingStatus({
9190

9291
return (
9392
<Spinner isLoading={isLoadingProjectBinding}>
94-
{almKey && (
95-
<Image
96-
alt={imageTitle}
97-
className={classNames('sw-px-1 sw-align-text-top', className)}
98-
height={16}
99-
src={DOP_LOGOS[almKey]}
100-
title={imageTitle}
101-
width={16}
102-
/>
103-
)}
93+
{almKey &&
94+
(projectBinding?.repositoryUrl ? (
95+
<Tooltip
96+
content={<FormattedMessage id={imageTitle} values={{ almKey }} />}
97+
side={TooltipSide.Right}
98+
>
99+
<Button
100+
className={className}
101+
prefix={<Image alt={imageTitle} height={16} src={DOP_LOGOS[almKey]} width={16} />}
102+
to={projectBinding?.repositoryUrl}
103+
>
104+
<FormattedMessage
105+
id="project_navigation.binding_status.view_on_x"
106+
values={{ dop: <FormattedMessage id={almKey} /> }}
107+
/>
108+
</Button>
109+
</Tooltip>
110+
) : (
111+
<Image
112+
alt={imageTitle}
113+
className={classNames('sw-px-1 sw-align-text-top', className)}
114+
height={16}
115+
src={DOP_LOGOS[almKey]}
116+
title={imageTitle}
117+
width={16}
118+
/>
119+
))}
104120

105121
{hasBranchSupport &&
106122
!almKey &&
@@ -118,14 +134,13 @@ export function ProjectBindingStatus({
118134
content={<FormattedMessage id="project_navigation.binding_status.bind.tooltip" />}
119135
side={TooltipSide.Right}
120136
>
121-
<LinkStandalone
137+
<Button
122138
className={className}
123-
highlight={LinkHighlight.Default}
124-
iconLeft={<IconLink />}
139+
prefix={<IconLink />}
125140
to={getProjectSettingsUrl(component.key, PULL_REQUEST_DECORATION_BINDING_CATEGORY)}
126141
>
127142
<FormattedMessage id="project_navigation.binding_status.bind" />
128-
</LinkStandalone>
143+
</Button>
129144
</Tooltip>
130145
)}
131146
</Spinner>

apps/sq-server/src/main/js/app/components/nav/component/legacy/__tests__/Header-test.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import userEvent from '@testing-library/user-event';
2323
import { ComponentQualifier } from '~shared/types/component';
2424
import AlmSettingsServiceMock from '~sq-server-commons/api/mocks/AlmSettingsServiceMock';
2525
import BranchesServiceMock from '~sq-server-commons/api/mocks/BranchesServiceMock';
26+
import { mockProjectAlmBindingResponse } from '~sq-server-commons/helpers/mocks/alm-settings';
2627
import { mockMainBranch, mockPullRequest } from '~sq-server-commons/helpers/mocks/branch-like';
2728
import { mockComponent } from '~sq-server-commons/helpers/mocks/component';
2829
import { mockCurrentUser, mockLoggedInUser } from '~sq-server-commons/helpers/testMocks';
@@ -88,12 +89,14 @@ it('should show the correct help tooltip for applications', async () => {
8889
it('should show the correct help tooltip when branch support is not enabled', async () => {
8990
handler.emptyBranchesAndPullRequest();
9091
handler.addBranch(mockMainBranch());
91-
almHandler.handleSetProjectBinding(AlmKeys.GitLab, {
92-
almSetting: 'key',
93-
project: 'header-project',
94-
repository: 'header-project',
95-
monorepo: true,
96-
});
92+
almHandler.setProjectBinding(
93+
'header-project',
94+
mockProjectAlmBindingResponse({
95+
alm: AlmKeys.GitLab,
96+
repository: 'header-project',
97+
monorepo: true,
98+
}),
99+
);
97100
renderHeader(
98101
{
99102
currentUser: mockLoggedInUser(),

libs/sq-server-commons/src/api/mocks/AlmSettingsServiceMock.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
*/
2020

2121
import { cloneDeep } from 'lodash';
22-
import { mockAlmSettingsInstance } from '../../helpers/mocks/alm-settings';
22+
import {
23+
mockAlmSettingsInstance,
24+
mockProjectAlmBindingResponse,
25+
} from '../../helpers/mocks/alm-settings';
2326
import {
2427
AlmKeys,
2528
AlmSettingsBindingDefinitions,
@@ -318,18 +321,25 @@ export default class AlmSettingsServiceMock {
318321
};
319322

320323
handleSetProjectBinding = (alm: AlmKeys, data: EnhancedProjectAlmBindingParam) => {
321-
this.#projectsBindings[data.project] = {
322-
alm,
323-
key: data.almSetting,
324-
repository: data.repositoryName ?? (data.repository as string),
325-
monorepo: data.monorepo,
326-
slug: data.projectName ?? data.slug,
327-
summaryCommentEnabled: data.summaryCommentEnabled ?? false,
328-
url: 'https://company.com/project',
329-
};
324+
this.setProjectBinding(
325+
data.project,
326+
mockProjectAlmBindingResponse({
327+
alm,
328+
key: data.almSetting,
329+
repository: data.repositoryName ?? (data.repository as string),
330+
monorepo: data.monorepo,
331+
slug: data.projectName ?? data.slug,
332+
summaryCommentEnabled: data.summaryCommentEnabled ?? false,
333+
url: 'https://company.com/project',
334+
}),
335+
);
330336
return this.reply(undefined);
331337
};
332338

339+
setProjectBinding = (project: string, binding: ProjectAlmBindingResponse) => {
340+
this.#projectsBindings[project] = binding;
341+
};
342+
333343
handleSetProjectAzureBinding = (data: AzureProjectAlmBindingParams) => {
334344
return this.handleSetProjectBinding(AlmKeys.Azure, data);
335345
};

libs/sq-server-commons/src/l10n/default.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3441,6 +3441,7 @@ export const defaultMessages = {
34413441
'project_navigation.analysis_status.details_link': 'See details',
34423442
'project_navigation.analysis_status.details_link.label': 'See details about the last analysis',
34433443
'project_navigation.binding_status.bound_to_x': 'Bound to {dop}',
3444+
'project_navigation.binding_status.view_on_x': 'View on {dop}',
34443445
'project_navigation.binding_status.not_bound': 'Not bound',
34453446
'project_navigation.binding_status.not_bound.tooltip':
34463447
'To enable automatically configured PR decoration and privacy settings based on your DevOps platform, ask your admin to bind this project',

libs/sq-server-commons/src/types/alm-settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export interface ProjectAlmBindingResponse {
7474
key: string;
7575
monorepo: boolean;
7676
repository: string;
77+
repositoryUrl?: string;
7778
slug?: string;
7879
summaryCommentEnabled?: boolean;
7980
url?: string;

0 commit comments

Comments
 (0)