/* * SonarQube * Copyright (C) 2009-2023 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 classNames from 'classnames'; import { ChevronRightIcon, CopyIcon, DeferredSpinner, HoverLink, InteractiveIcon, LightLabel, Link, ThemeProp, UnfoldIcon, themeColor, withTheme, } from 'design-system'; import * as React from 'react'; import Tooltip from '../../../components/controls/Tooltip'; import { ClipboardBase } from '../../../components/controls/clipboard'; import { getBranchLikeQuery } from '../../../helpers/branch-like'; import { translate } from '../../../helpers/l10n'; import { collapsedDirFromPath, fileFromPath } from '../../../helpers/path'; import { getBranchLikeUrl, getComponentIssuesUrl, getPathUrlAsString } from '../../../helpers/urls'; import { BranchLike } from '../../../types/branch-like'; import { ComponentQualifier } from '../../../types/component'; import { SourceViewerFile } from '../../../types/types'; export const INTERACTIVE_TOOLTIP_DELAY = 0.5; export interface Props { branchLike: BranchLike | undefined; className?: string; expandable?: boolean; displayProjectName?: boolean; linkToProject?: boolean; loading?: boolean; onExpand?: () => void; sourceViewerFile: SourceViewerFile; } function IssueSourceViewerHeader(props: Props & ThemeProp) { const { branchLike, className, expandable, displayProjectName = true, linkToProject = true, loading, onExpand, sourceViewerFile, theme, } = props; const { measures, path, project, projectName, q } = sourceViewerFile; const isProjectRoot = q === ComponentQualifier.Project; const borderColor = themeColor('codeLineBorder')({ theme }); const IssueSourceViewerStyle = styled.div` border: 1px solid ${borderColor}; border-bottom: none; `; return (
{displayProjectName && ( <> {linkToProject ? ( {projectName} ) : ( {projectName} )} )} {!isProjectRoot && ( <> {displayProjectName && } {collapsedDirFromPath(path)} {fileFromPath(path)} {({ setCopyButton, copySuccess }) => { return ( {translate(copySuccess ? 'copied_action' : 'copy_to_clipboard')}
} {...(copySuccess ? { visible: copySuccess } : undefined)} > ); }} )} {!isProjectRoot && measures.issues !== undefined && (
{translate('source_viewer.view_all_issues')}
)} {expandable && !loading && (
)}
); } export default withTheme(IssueSourceViewerHeader);