import React from 'react';
import moment from 'moment';
import { isEqual, sortBy } from 'lodash';
+import DeferredSpinner from '../../../components/common/DeferredSpinner';
import GraphHistory from './GraphHistory';
import { EVENT_TYPES, getSeriesMetricType, hasHistoryData, isCustomGraph } from '../utils';
import { translate } from '../../../helpers/l10n';
updateTooltip = (selectedDate /*: ?Date */) => this.setState({ selectedDate });
render() {
- const { graph, series } = this.props;
+ const { graph, loading, series } = this.props;
const isCustom = isCustomGraph(graph);
- if (this.props.loading) {
+ if (loading) {
return (
<div className="project-activity-graph-container">
<div className="text-center">
- <i className="spinner" />
+ <DeferredSpinner className="" loading={loading} />
</div>
</div>
);
changeEvent: (event: string, name: string) => Promise<*>,
deleteAnalysis: (analysis: string) => Promise<*>,
deleteEvent: (analysis: string, event: string) => Promise<*>,
- loading: boolean,
+ initializing: boolean,
project: { qualifier: string },
query: Query,
updateQuery: Object => void
if (this.props.analyses.length === 0 || !hasFilteredData) {
return (
<div className={this.props.className}>
- {this.props.loading
+ {this.props.initializing
? <div className="text-center">
<i className="spinner" />
</div>
deleteAnalysis: (analysis: string) => Promise<*>,
deleteEvent: (analysis: string, event: string) => Promise<*>,
graphLoading: boolean,
- loading: boolean,
+ initializing: boolean,
project: {
configuration?: { showHistory: boolean },
key: string,
changeEvent={props.changeEvent}
deleteAnalysis={props.deleteAnalysis}
deleteEvent={props.deleteEvent}
- loading={props.loading}
+ initializing={props.initializing}
project={props.project}
query={props.query}
updateQuery={props.updateQuery}
this.fetchActivity(query.project, 1, 100, serializeQuery(query)),
this.fetchMetrics(),
this.fetchMeasuresHistory(graphMetrics)
- ]).then(response => {
- if (this.mounted) {
- this.setState({
- analyses: response[0].analyses,
- analysesLoading: true,
- graphLoading: false,
- initialized: true,
- measuresHistory: response[2],
- metrics: response[1],
- paging: response[0].paging
- });
+ ]).then(
+ response => {
+ if (this.mounted) {
+ this.setState({
+ analyses: response[0].analyses,
+ analysesLoading: true,
+ graphLoading: false,
+ initialized: true,
+ measuresHistory: response[2],
+ metrics: response[1],
+ paging: response[0].paging
+ });
- this.loadAllActivities(query.project).then(({ analyses, paging }) => {
- if (this.mounted) {
- this.setState({
- analyses,
- analysesLoading: false,
- paging
- });
- }
- });
+ this.loadAllActivities(query.project).then(({ analyses, paging }) => {
+ if (this.mounted) {
+ this.setState({
+ analyses,
+ analysesLoading: false,
+ paging
+ });
+ }
+ });
+ }
+ },
+ () => {
+ if (this.mounted) {
+ this.setState({ initialized: true, analysesLoading: false, graphLoading: false });
+ }
}
- });
+ );
}
updateGraphData = (graph /*: string */, customMetrics /*: Array<string> */) => {
const graphMetrics = getHistoryMetrics(graph, customMetrics);
this.setState({ graphLoading: true });
- this.fetchMeasuresHistory(graphMetrics).then((measuresHistory /*: Array<MeasureHistory> */) =>
- this.setState({ graphLoading: false, measuresHistory })
+ this.fetchMeasuresHistory(graphMetrics).then(
+ (measuresHistory /*: Array<MeasureHistory> */) => {
+ if (this.mounted) {
+ this.setState({ graphLoading: false, measuresHistory });
+ }
+ },
+ () => {
+ if (this.mounted) {
+ this.setState({ graphLoading: false, measuresHistory: [] });
+ }
+ }
);
};
deleteAnalysis={this.deleteAnalysis}
deleteEvent={this.deleteEvent}
graphLoading={!this.state.initialized || this.state.graphLoading}
- loading={!this.state.initialized}
+ initializing={!this.state.initialized}
metrics={this.state.metrics}
measuresHistory={this.state.measuresHistory}
project={this.props.project}
it('should show a loading view instead of the graph', () => {
expect(
- shallow(<GraphsHistory {...DEFAULT_PROPS} loading={true} />).find('.spinner')
+ shallow(<GraphsHistory {...DEFAULT_PROPS} loading={true} />).find('DeferredSpinner')
).toHaveLength(1);
});
changeEvent: () => {},
deleteAnalysis: () => {},
deleteEvent: () => {},
- loading: false,
+ inizializing: false,
project: { qualifier: 'TRK' },
query: { category: '', graph: DEFAULT_GRAPH, project: 'org.sonarsource.sonarqube:sonarqube' },
updateQuery: () => {}
deleteAnalysis: () => {},
deleteEvent: () => {},
graphLoading: false,
- loading: false,
+ initializing: false,
project: {
key: 'org.sonarsource.sonarqube:sonarqube',
leakPeriodDate: '2017-05-16T13:50:02+0200'
className="boxed-group-inner"
deleteAnalysis={[Function]}
deleteEvent={[Function]}
- loading={false}
+ initializing={false}
project={
Object {
"key": "org.sonarsource.sonarqube:sonarqube",