]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9418 Prevent from autozooming on the graph when selecting a date in the project...
authorGrégoire Aubert <gregoire.aubert@sonarsource.com>
Wed, 12 Jul 2017 10:20:06 +0000 (12:20 +0200)
committerGrégoire Aubert <gregoire.aubert@sonarsource.com>
Thu, 13 Jul 2017 12:34:17 +0000 (14:34 +0200)
server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityGraphs.js
server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/__snapshots__/ProjectActivityGraphs-test.js.snap

index 8f48ceaf91e818d8de2206a3615afb42f5a3935e..c5b0698f954a53793265e868d2a67c7728c9e874 100644 (file)
@@ -82,11 +82,7 @@ export default class ProjectActivityGraphs extends React.PureComponent {
       );
     }
 
-    const newDates = this.getStateZoomDates(
-      this.props,
-      nextProps,
-      newSeries ? newSeries : this.state.series
-    );
+    const newDates = this.getStateZoomDates(this.props, nextProps, newSeries);
 
     if (newSeries || newDates) {
       let newState = {};
@@ -103,13 +99,15 @@ export default class ProjectActivityGraphs extends React.PureComponent {
   getStateZoomDates = (
     props: ?Props,
     nextProps: Props,
-    series: Array<Serie>
+    newSeries: ?Array<Serie>
   ): ?{ graphEndDate: ?Date, graphStartDate: ?Date } => {
     const newDates = { from: nextProps.query.from || null, to: nextProps.query.to || null };
-    if (props && datesQueryChanged(props.query, nextProps.query)) {
+    if (!props || datesQueryChanged(props.query, nextProps.query)) {
       return { graphEndDate: newDates.to, graphStartDate: newDates.from };
     }
-    if (newDates.to == null && newDates.from == null) {
+
+    if (newDates.to == null && newDates.from == null && newSeries != null) {
+      const series = newSeries ? newSeries : this.state.series;
       const firstValid = minBy(series.map(serie => serie.data.find(p => p.y || p.y === 0)), 'x');
       const lastValid = maxBy(
         series.map(serie => findLast(serie.data, p => p.y || p.y === 0)),
@@ -120,9 +118,6 @@ export default class ProjectActivityGraphs extends React.PureComponent {
         graphStartDate: firstValid ? firstValid.x : newDates.from
       };
     }
-    if (!props) {
-      return { graphEndDate: newDates.to, graphStartDate: newDates.from };
-    }
   };
 
   addCustomMetric = (metric: string) => {
index a32cd28f590f81b4b6a7ab9df6071ca3c44fdac3..7aaf0a0268dddc630259d94e89db6df9837f7b74 100644 (file)
@@ -48,8 +48,8 @@ exports[`should render correctly the graph and legends 1`] = `
     }
     eventFilter=""
     graph="overview"
-    graphEndDate={2016-10-27T14:33:50.000Z}
-    graphStartDate={2016-10-26T10:17:29.000Z}
+    graphEndDate={null}
+    graphStartDate={null}
     leakPeriodDate="2017-05-16T13:50:02+0200"
     loading={false}
     measuresHistory={
@@ -102,8 +102,8 @@ exports[`should render correctly the graph and legends 1`] = `
     updateSelectedDate={[Function]}
   />
   <GraphsZoom
-    graphEndDate={2016-10-27T14:33:50.000Z}
-    graphStartDate={2016-10-26T10:17:29.000Z}
+    graphEndDate={null}
+    graphStartDate={null}
     leakPeriodDate="2017-05-16T13:50:02+0200"
     loading={false}
     metricsType="INT"