diff options
author | Sarath Nair <91882341+sarath-nair-sonarsource@users.noreply.github.com> | 2024-08-23 10:43:56 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2024-08-23 20:02:33 +0000 |
commit | 7dec8953ddce0cb7445740d3c5df0d426cfee354 (patch) | |
tree | b7cb95abf4544cc33f5a65e9bef4951caa0bb855 /server/sonar-web | |
parent | a5b6cf1c23b872b82a09dbedade8f0ce78af5345 (diff) | |
download | sonarqube-7dec8953ddce0cb7445740d3c5df0d426cfee354.tar.gz sonarqube-7dec8953ddce0cb7445740d3c5df0d426cfee354.zip |
SONAR-22853 Correctly navigate user in case of sync failure (#11591)
Diffstat (limited to 'server/sonar-web')
4 files changed, 35 insertions, 23 deletions
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<LastSyncProps>) { +function LastSyncAlert({ info, provisionedBy, short }: Readonly<LastSyncProps>) { if (info === undefined) { return null; } @@ -62,21 +65,24 @@ function LastSyncAlert({ info, short }: Readonly<LastSyncProps>) { {warningMessage ? ( <FormattedMessage defaultMessage={translate( - 'settings.authentication.github.synchronization_successful.with_warning', + 'settings.authentication.synchronization_successful.with_warning', )} - id="settings.authentication.github.synchronization_successful.with_warning" + id="settings.authentication.synchronization_successful.with_warning" values={{ date: formattedDate, details: ( - <Link className="sw-ml-2" to="/admin/settings?category=authentication&tab=github"> - {translate('settings.authentication.github.synchronization_details_link')} + <Link + className="sw-ml-2" + to={`/admin/settings?category=authentication&tab=${provisionedBy}`} + > + {translate('settings.authentication.synchronization_details_link')} </Link> ), }} /> ) : ( translateWithParameters( - 'settings.authentication.github.synchronization_successful', + 'settings.authentication.synchronization_successful', formattedDate, ) )} @@ -86,14 +92,15 @@ function LastSyncAlert({ info, short }: Readonly<LastSyncProps>) { <FlagMessage variant="error"> <div> <FormattedMessage - defaultMessage={translate( - 'settings.authentication.github.synchronization_failed_short', - )} - id="settings.authentication.github.synchronization_failed_short" + defaultMessage={translate('settings.authentication.synchronization_failed_short')} + id="settings.authentication.synchronization_failed_short" values={{ details: ( - <Link className="sw-ml-2" to="/admin/settings?category=authentication&tab=github"> - {translate('settings.authentication.github.synchronization_details_link')} + <Link + className="sw-ml-2" + to={`/admin/settings?category=authentication&tab=${provisionedBy}`} + > + {translate('settings.authentication.synchronization_details_link')} </Link> ), }} @@ -114,7 +121,7 @@ function LastSyncAlert({ info, short }: Readonly<LastSyncProps>) { {status === TaskStatuses.Success ? ( <> {translateWithParameters( - 'settings.authentication.github.synchronization_successful', + 'settings.authentication.synchronization_successful', formattedDate, )} @@ -126,7 +133,7 @@ function LastSyncAlert({ info, short }: Readonly<LastSyncProps>) { <React.Fragment key={`synch-alert-${finishedAt}`}> <div> {translateWithParameters( - 'settings.authentication.github.synchronization_failed', + 'settings.authentication.synchronization_failed', formattedDate, )} </div> @@ -146,16 +153,14 @@ function LastSyncAlert({ info, short }: Readonly<LastSyncProps>) { ); } -export default function AlmSynchronisationWarning({ - data, - short, -}: Readonly<SynchronisationWarningProps>) { +export default function AlmSynchronisationWarning(props: Readonly<SynchronisationWarningProps>) { + 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({ </div> )} - <LastSyncAlert short={short} info={data.lastSync} /> + <LastSyncAlert short={short} info={data.lastSync} provisionedBy={provisionedBy} /> </> ); } 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<Props>) { return null; } - return <AlmSynchronisationWarning short={short} data={data} />; + return <AlmSynchronisationWarning short={short} data={data} provisionedBy={AlmKeys.GitHub} />; } 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<Props>) { return null; } - return <AlmSynchronisationWarning short={short} data={data} />; + return <AlmSynchronisationWarning short={short} data={data} provisionedBy={AlmKeys.GitLab} />; } 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(); }); |