/* * SonarQube * Copyright (C) 2009-2018 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 { stringify } from 'querystring'; import * as React from 'react'; import { Link } from 'react-router'; import * as PropTypes from 'prop-types'; import MeasuresOverlay from './components/MeasuresOverlay'; import { SourceViewerFile, BranchLike } from '../../app/types'; import QualifierIcon from '../shared/QualifierIcon'; import FavoriteContainer from '../controls/FavoriteContainer'; import { WorkspaceContext } from '../workspace/context'; import { getPathUrlAsString, getBranchLikeUrl, getComponentIssuesUrl, getBaseUrl } from '../../helpers/urls'; import { collapsedDirFromPath, fileFromPath } from '../../helpers/path'; import { translate } from '../../helpers/l10n'; import { getBranchLikeQuery } from '../../helpers/branches'; import { formatMeasure } from '../../helpers/measures'; import { omitNil } from '../../helpers/request'; interface Props { branchLike: BranchLike | undefined; sourceViewerFile: SourceViewerFile; } interface State { measuresOverlay: boolean; } export default class SourceViewerHeader extends React.PureComponent { // prettier-ignore context!: { workspace: WorkspaceContext }; static contextTypes = { workspace: PropTypes.object.isRequired }; state: State = { measuresOverlay: false }; handleShowMeasuresClick = (event: React.SyntheticEvent) => { event.preventDefault(); this.setState({ measuresOverlay: true }); }; handleMeasuresOverlayClose = () => { this.setState({ measuresOverlay: false }); }; openInWorkspace = (event: React.SyntheticEvent) => { event.preventDefault(); const { key } = this.props.sourceViewerFile; this.context.workspace.openComponent({ branchLike: this.props.branchLike, key }); }; render() { const { key, measures, path, project, projectName, q, subProject, subProjectName, uuid } = this.props.sourceViewerFile; const isUnitTest = q === 'UTS'; const workspace = false; const rawSourcesLink = getBaseUrl() + '/api/sources/raw?' + stringify(omitNil({ key, ...getBranchLikeQuery(this.props.branchLike) })); // TODO favorite return (
{subProject != null && ( )}
{collapsedDirFromPath(path)} {fileFromPath(path)} {this.props.sourceViewerFile.canMarkAsFavorite && ( )}
{isUnitTest && (
{formatMeasure(measures.tests, 'SHORT_INT')} {translate('metric.tests.name')}
)} {!isUnitTest && (
{formatMeasure(measures.lines, 'SHORT_INT')} {translate('metric.lines.name')}
)}
{measures.issues != null ? formatMeasure(measures.issues, 'SHORT_INT') : 0} {translate('metric.violations.name')}
{measures.coverage != null && (
{formatMeasure(measures.coverage, 'PERCENT')} {translate('metric.coverage.name')}
)} {measures.duplicationDensity != null && (
{formatMeasure(measures.duplicationDensity, 'PERCENT')} {translate('duplications')}
)}
); } }