From 7dec8953ddce0cb7445740d3c5df0d426cfee354 Mon Sep 17 00:00:00 2001 From: Sarath Nair <91882341+sarath-nair-sonarsource@users.noreply.github.com> Date: Fri, 23 Aug 2024 10:43:56 +0200 Subject: SONAR-22853 Correctly navigate user in case of sync failure (#11591) --- .../app/components/AlmSynchronisationWarning.tsx | 47 ++++++++++++---------- .../components/GitHubSynchronisationWarning.tsx | 3 +- .../components/GitLabSynchronisationWarning.tsx | 3 +- .../main/js/apps/users/__tests__/UsersApp-it.tsx | 5 +++ 4 files changed, 35 insertions(+), 23 deletions(-) (limited to 'server/sonar-web/src/main/js') diff --git a/server/sonar-web/src/main/js/app/components/AlmSynchronisationWarning.tsx b/server/sonar-web/src/main/js/app/components/AlmSynchronisationWarning.tsx index be2ee41fbd7..c7b7663fa7c 100644 --- a/server/sonar-web/src/main/js/app/components/AlmSynchronisationWarning.tsx +++ b/server/sonar-web/src/main/js/app/components/AlmSynchronisationWarning.tsx @@ -25,20 +25,23 @@ import { CheckIcon, FlagMessage, FlagWarningIcon, themeColor } from 'design-syst import * as React from 'react'; import { FormattedMessage } from 'react-intl'; import { translate, translateWithParameters } from '../../helpers/l10n'; +import { AlmKeys } from '../../types/alm-settings'; import { AlmSyncStatus } from '../../types/provisioning'; import { TaskStatuses } from '../../types/tasks'; interface SynchronisationWarningProps { data: AlmSyncStatus; + provisionedBy: AlmKeys.GitHub | AlmKeys.GitLab; short?: boolean; } interface LastSyncProps { info: AlmSyncStatus['lastSync']; + provisionedBy: AlmKeys.GitHub | AlmKeys.GitLab; short?: boolean; } -function LastSyncAlert({ info, short }: Readonly) { +function LastSyncAlert({ info, provisionedBy, short }: Readonly) { if (info === undefined) { return null; } @@ -62,21 +65,24 @@ function LastSyncAlert({ info, short }: Readonly) { {warningMessage ? ( - {translate('settings.authentication.github.synchronization_details_link')} + + {translate('settings.authentication.synchronization_details_link')} ), }} /> ) : ( translateWithParameters( - 'settings.authentication.github.synchronization_successful', + 'settings.authentication.synchronization_successful', formattedDate, ) )} @@ -86,14 +92,15 @@ function LastSyncAlert({ info, short }: Readonly) {
- {translate('settings.authentication.github.synchronization_details_link')} + + {translate('settings.authentication.synchronization_details_link')} ), }} @@ -114,7 +121,7 @@ function LastSyncAlert({ info, short }: Readonly) { {status === TaskStatuses.Success ? ( <> {translateWithParameters( - 'settings.authentication.github.synchronization_successful', + 'settings.authentication.synchronization_successful', formattedDate, )} @@ -126,7 +133,7 @@ function LastSyncAlert({ info, short }: Readonly) {
{translateWithParameters( - 'settings.authentication.github.synchronization_failed', + 'settings.authentication.synchronization_failed', formattedDate, )}
@@ -146,16 +153,14 @@ function LastSyncAlert({ info, short }: Readonly) { ); } -export default function AlmSynchronisationWarning({ - data, - short, -}: Readonly) { +export default function AlmSynchronisationWarning(props: Readonly) { + const { data, provisionedBy, short } = props; const loadingLabel = data.nextSync && translate( data.nextSync.status === TaskStatuses.Pending - ? 'settings.authentication.github.synchronization_pending' - : 'settings.authentication.github.synchronization_in_progress', + ? 'settings.authentication.synchronization_pending' + : 'settings.authentication.synchronization_in_progress', ); return ( @@ -168,7 +173,7 @@ export default function AlmSynchronisationWarning({
)} - + ); } diff --git a/server/sonar-web/src/main/js/app/components/GitHubSynchronisationWarning.tsx b/server/sonar-web/src/main/js/app/components/GitHubSynchronisationWarning.tsx index 12c1592adb7..3a6c1eb24c1 100644 --- a/server/sonar-web/src/main/js/app/components/GitHubSynchronisationWarning.tsx +++ b/server/sonar-web/src/main/js/app/components/GitHubSynchronisationWarning.tsx @@ -19,6 +19,7 @@ */ import * as React from 'react'; import { useGitHubSyncStatusQuery } from '../../queries/identity-provider/github'; +import { AlmKeys } from '../../types/alm-settings'; import AlmSynchronisationWarning from './AlmSynchronisationWarning'; interface Props { @@ -32,7 +33,7 @@ function GitHubSynchronisationWarning({ short }: Readonly) { return null; } - return ; + return ; } export default GitHubSynchronisationWarning; diff --git a/server/sonar-web/src/main/js/app/components/GitLabSynchronisationWarning.tsx b/server/sonar-web/src/main/js/app/components/GitLabSynchronisationWarning.tsx index 806882fa76b..4afc872b933 100644 --- a/server/sonar-web/src/main/js/app/components/GitLabSynchronisationWarning.tsx +++ b/server/sonar-web/src/main/js/app/components/GitLabSynchronisationWarning.tsx @@ -19,6 +19,7 @@ */ import * as React from 'react'; import { useGitLabSyncStatusQuery } from '../../queries/identity-provider/gitlab'; +import { AlmKeys } from '../../types/alm-settings'; import AlmSynchronisationWarning from './AlmSynchronisationWarning'; interface Props { @@ -32,7 +33,7 @@ function GitLabSynchronisationWarning({ short }: Readonly) { return null; } - return ; + return ; } export default GitLabSynchronisationWarning; diff --git a/server/sonar-web/src/main/js/apps/users/__tests__/UsersApp-it.tsx b/server/sonar-web/src/main/js/apps/users/__tests__/UsersApp-it.tsx index 42eda7113ff..2201fe6f32a 100644 --- a/server/sonar-web/src/main/js/apps/users/__tests__/UsersApp-it.tsx +++ b/server/sonar-web/src/main/js/apps/users/__tests__/UsersApp-it.tsx @@ -152,6 +152,7 @@ const ui = { githubProvisioningSuccess: byText(/synchronization_successful/), githubProvisioningWarning: byText(/synchronization_successful.with_warning/), githubProvisioningAlert: byText(/synchronization_failed_short/), + githubProvisioningAlertDetailsLink: byText(/synchronization_failed_short/).byRole('link'), expiresInSelector: byRole('combobox', { name: 'users.tokens.expires_in' }), }; @@ -673,6 +674,10 @@ describe('in manage mode', () => { }); renderUsersApp([Feature.GithubProvisioning]); expect(await ui.githubProvisioningAlert.find()).toBeInTheDocument(); + expect(ui.githubProvisioningAlertDetailsLink.get()).toHaveAttribute( + 'href', + '/admin/settings?category=authentication&tab=github', + ); expect(screen.queryByText('Error Message')).not.toBeInTheDocument(); expect(ui.githubProvisioningSuccess.query()).not.toBeInTheDocument(); }); -- cgit v1.2.3