/* * 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 { BareButton, BranchIcon, ChevronDownIcon, Note, StandoutLink } from 'design-system'; import * as React from 'react'; import { FormattedMessage } from 'react-intl'; import { isMainBranch } from '../../helpers/branch-like'; import { translate } from '../../helpers/l10n'; import { getProjectUrl } from '../../helpers/urls'; import { BranchLike } from '../../types/branch-like'; import { AnalysisEvent, ApplicationAnalysisEventCategory, DefinitionChangeType, } from '../../types/project-activity'; import ClickEventBoundary from '../controls/ClickEventBoundary'; export type DefinitionChangeEvent = AnalysisEvent & Required>; export function isDefinitionChangeEvent(event: AnalysisEvent): event is DefinitionChangeEvent { return ( event.category === ApplicationAnalysisEventCategory.DefinitionChange && event.definitionChange !== undefined ); } interface Props { branchLike: BranchLike | undefined; event: DefinitionChangeEvent; readonly?: boolean; } interface State { expanded: boolean; } export class DefinitionChangeEventInner extends React.PureComponent { state: State = { expanded: false }; toggleProjectsList = () => { this.setState((state) => ({ expanded: !state.expanded })); }; renderProjectLink = (project: { key: string; name: string }, branch: string | undefined) => ( {project.name} ); renderBranch = (branch = translate('branches.main_branch')) => ( {branch} ); renderProjectChange(project: { changeType: DefinitionChangeType; key: string; name: string; branch?: string; newBranch?: string; oldBranch?: string; }) { const mainBranch = !this.props.branchLike || isMainBranch(this.props.branchLike); switch (project.changeType) { case DefinitionChangeType.Added: { const message = mainBranch ? 'event.definition_change.added' : 'event.definition_change.branch_added'; return ( ); } case DefinitionChangeType.Removed: { const message = mainBranch ? 'event.definition_change.removed' : 'event.definition_change.branch_removed'; return ( ); } case DefinitionChangeType.BranchChanged: return ( ); } } render() { const { event, readonly } = this.props; const { expanded } = this.state; return (
{translate('event.category', event.category)} {!readonly && ( {expanded ? translate('hide') : translate('more')} )}
{expanded && (
    {event.definitionChange.projects.map((project) => (
  • {this.renderProjectChange(project)}
  • ))}
)}
); } }