From 757aaeb278c06fb7e89b769e9cb2a46274d39ea2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gr=C3=A9goire=20Aubert?= Date: Wed, 12 Jul 2017 12:20:06 +0200 Subject: [PATCH] SONAR-9418 Prevent from autozooming on the graph when selecting a date in the project activity list --- .../components/ProjectActivityGraphs.js | 17 ++++++----------- .../ProjectActivityGraphs-test.js.snap | 8 ++++---- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityGraphs.js b/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityGraphs.js index 8f48ceaf91e..c5b0698f954 100644 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityGraphs.js +++ b/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityGraphs.js @@ -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 + newSeries: ?Array ): ?{ 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) => { diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/__snapshots__/ProjectActivityGraphs-test.js.snap b/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/__snapshots__/ProjectActivityGraphs-test.js.snap index a32cd28f590..7aaf0a0268d 100644 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/__snapshots__/ProjectActivityGraphs-test.js.snap +++ b/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/__snapshots__/ProjectActivityGraphs-test.js.snap @@ -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]} />