/*
* 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 { connect } from 'react-redux';
import { keyBy } from 'lodash';
import { Link } from 'react-router';
import AboutProjects from './AboutProjects';
import EntryIssueTypes from './EntryIssueTypes';
import AboutLanguages from './AboutLanguages';
import AboutCleanCode from './AboutCleanCode';
import AboutQualityModel from './AboutQualityModel';
import AboutQualityGates from './AboutQualityGates';
import AboutLeakPeriod from './AboutLeakPeriod';
import AboutStandards from './AboutStandards';
import AboutScanners from './AboutScanners';
import { searchProjects } from '../../../api/components';
import { getFacet } from '../../../api/issues';
import { getAppState, getCurrentUser, getSettingValue } from '../../../store/rootReducer';
import { translate } from '../../../helpers/l10n';
import { fetchAboutPageSettings } from '../actions';
import AboutAppForSonarQubeDotComLazyLoader from './AboutAppForSonarQubeDotComLazyLoader';
import '../styles.css';
type State = {
loading: boolean,
projectsCount: number,
issueTypes?: {
[key: string]: ?{
count: number
}
}
};
class AboutApp extends React.PureComponent {
mounted: boolean;
props: {
appState: {
defaultOrganization: string,
organizationsEnabled: boolean
},
currentUser: { isLoggedIn: boolean },
customText?: string,
fetchAboutPageSettings: () => Promise<*>,
sonarqubeDotCom?: { value: string }
};
state: State = {
loading: true,
projectsCount: 0
};
componentDidMount() {
this.mounted = true;
this.loadData();
}
componentWillUnmount() {
this.mounted = false;
}
loadProjects() {
return searchProjects({ ps: 1 }).then(r => r.paging.total);
}
loadIssues() {
return getFacet({ resolved: false }, 'types');
}
loadCustomText() {
return this.props.fetchAboutPageSettings();
}
loadData() {
Promise.all([this.loadProjects(), this.loadIssues(), this.loadCustomText()]).then(responses => {
if (this.mounted) {
const [projectsCount, issues] = responses;
const issueTypes = keyBy(issues.facet, 'val');
this.setState({
projectsCount,
issueTypes,
loading: false
});
}
});
}
render() {
if (this.state.loading) {
return null;
}
const { customText, sonarqubeDotCom } = this.props;
// $FlowFixMe
const bugs = this.state.issueTypes['BUG'].count;
// $FlowFixMe
const vulnerabilities = this.state.issueTypes['VULNERABILITY'].count;
// $FlowFixMe
const codeSmells = this.state.issueTypes['CODE_SMELL'].count;
if (sonarqubeDotCom && sonarqubeDotCom.value === 'true') {
return (