/* * SonarQube * Copyright (C) 2009-2017 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. */ // @flow import React from 'react'; import { Link } from 'react-router'; import QualifierIcon from '../shared/qualifier-icon'; import FavoriteContainer from '../controls/FavoriteContainer'; import { getProjectUrl, getIssuesUrl } from '../../helpers/urls'; import { collapsedDirFromPath, fileFromPath } from '../../helpers/path'; import { translate } from '../../helpers/l10n'; import { formatMeasure } from '../../helpers/measures'; export default class SourceViewerHeader extends React.PureComponent { props: { component: { canMarkAsFavorite: boolean, key: string, measures: { coverage?: string, duplicationDensity?: string, issues?: string, lines?: string, tests?: string }, path: string, project: string, projectName: string, q: string, subProject?: string, subProjectName?: string }, openNewWindow: () => void, showMeasures: () => void }; showMeasures = (e: SyntheticInputEvent) => { e.preventDefault(); this.props.showMeasures(); }; openNewWindow = (e: SyntheticInputEvent) => { e.preventDefault(); this.props.openNewWindow(); }; openInWorkspace = (e: SyntheticInputEvent) => { e.preventDefault(); const { key } = this.props.component; const Workspace = require('../workspace/main').default; Workspace.openComponent({ key }); }; render() { const { key, measures, path, project, projectName, q, subProject, subProjectName } = this.props.component; const isUnitTest = q === 'UTS'; // TODO check if source viewer is displayed inside workspace const workspace = false; const rawSourcesLink = `${window.baseUrl}/api/sources/raw?key=${encodeURIComponent(this.props.component.key)}`; // TODO favorite return (
{projectName}
{subProject != null &&
{subProjectName}
}
{' '} {collapsedDirFromPath(path)} {fileFromPath(path)} {this.props.component.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')}
}
); } }