aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/apps/overview/meta/Meta.tsx
blob: c2145d14c3b0254e4168652bb1c282be720a7d50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
 * 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 * as React from 'react';
import * as PropTypes from 'prop-types';
import MetaKey from './MetaKey';
import MetaOrganizationKey from './MetaOrganizationKey';
import MetaLinks from './MetaLinks';
import MetaQualityGate from './MetaQualityGate';
import MetaQualityProfiles from './MetaQualityProfiles';
import MetaSize from './MetaSize';
import MetaTags from './MetaTags';
import BadgesModal from '../badges/BadgesModal';
import AnalysesList from '../events/AnalysesList';
import { Visibility, Component, Metric, BranchLike } from '../../../app/types';
import { History } from '../../../api/time-machine';
import { translate } from '../../../helpers/l10n';
import { MeasureEnhanced } from '../../../helpers/measures';

interface Props {
  branchLike?: BranchLike;
  component: Component;
  history?: History;
  measures: MeasureEnhanced[];
  metrics: { [key: string]: Metric };
  onComponentChange: (changes: {}) => void;
}

export default class Meta extends React.PureComponent<Props> {
  static contextTypes = {
    organizationsEnabled: PropTypes.bool
  };

  render() {
    const { organizationsEnabled } = this.context;
    const { branchLike, component, metrics } = this.props;
    const { qualifier, description, qualityProfiles, qualityGate, visibility } = component;

    const isProject = qualifier === 'TRK';
    const isApp = qualifier === 'APP';
    const isPrivate = visibility === Visibility.Private;

    return (
      <div className="overview-meta">
        <div className="overview-meta-card">
          <h4 className="overview-meta-header">
            {translate('overview.about_this_project', qualifier)}
          </h4>
          {description !== undefined && <p className="overview-meta-description">{description}</p>}
          {isProject && (
            <MetaTags component={component} onComponentChange={this.props.onComponentChange} />
          )}
          <MetaSize branchLike={branchLike} component={component} measures={this.props.measures} />
        </div>

        <AnalysesList
          branchLike={branchLike}
          component={component}
          history={this.props.history}
          metrics={metrics}
          qualifier={component.qualifier}
        />

        {isProject && (
          <div className="overview-meta-card">
            {qualityGate && (
              <MetaQualityGate
                organization={organizationsEnabled ? component.organization : undefined}
                qualityGate={qualityGate}
              />
            )}

            {qualityProfiles &&
              qualityProfiles.length > 0 && (
                <MetaQualityProfiles
                  headerClassName={qualityGate ? 'big-spacer-top' : undefined}
                  organization={organizationsEnabled ? component.organization : undefined}
                  profiles={qualityProfiles}
                />
              )}
          </div>
        )}

        {isProject && <MetaLinks component={component} />}

        <div className="overview-meta-card">
          <MetaKey componentKey={component.key} qualifier={component.qualifier} />
          {organizationsEnabled && <MetaOrganizationKey organization={component.organization} />}
        </div>

        {!isPrivate &&
          (isProject || isApp) && (
            <BadgesModal
              branchLike={branchLike}
              metrics={metrics}
              project={component.key}
              qualifier={component.qualifier}
            />
          )}
      </div>
    );
  }
}