/* * SonarQube * Copyright (C) 2009-2024 SonarSource SA * mailto:info AT sonarsource DOT com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import styled from '@emotion/styled'; import { formatDistance } from 'date-fns'; import { CheckIcon, FlagMessage, FlagWarningIcon, Link, Spinner, themeColor } from 'design-system'; import * as React from 'react'; import { FormattedMessage } from 'react-intl'; import { translate, translateWithParameters } from '../../helpers/l10n'; import { AlmSyncStatus } from '../../types/provisioning'; import { TaskStatuses } from '../../types/tasks'; import './SystemAnnouncement.css'; interface SynchronisationWarningProps { short?: boolean; data: AlmSyncStatus; } interface LastSyncProps { short?: boolean; info: AlmSyncStatus['lastSync']; } function LastSyncAlert({ info, short }: Readonly) { if (info === undefined) { return null; } const { finishedAt, errorMessage, status, summary, warningMessage } = info; const formattedDate = finishedAt ? formatDistance(new Date(finishedAt), new Date()) : ''; if (short) { return status === TaskStatuses.Success ? (
{warningMessage ? ( ) : ( )} {warningMessage ? ( {translate('settings.authentication.github.synchronization_details_link')} ), }} /> ) : ( translateWithParameters( 'settings.authentication.github.synchronization_successful', formattedDate, ) )}
) : (
{translate('settings.authentication.github.synchronization_details_link')} ), }} />
); } return ( <>
{status === TaskStatuses.Success ? ( <> {translateWithParameters( 'settings.authentication.github.synchronization_successful', formattedDate, )}
{summary ?? ''} ) : (
{translateWithParameters( 'settings.authentication.github.synchronization_failed', formattedDate, )}

{errorMessage ?? ''}
)}
{warningMessage} ); } export default function AlmSynchronisationWarning({ short, data, }: Readonly) { const loadingLabel = data.nextSync && translate( data.nextSync.status === TaskStatuses.Pending ? 'settings.authentication.github.synchronization_pending' : 'settings.authentication.github.synchronization_in_progress', ); return ( <> {!short && (
{data.nextSync && loadingLabel}
)} ); } const IconWrapper = styled.span` color: ${themeColor('iconSuccess')}; `;