From: Stas Vilchik Date: Tue, 24 Jan 2017 12:11:34 +0000 (+0100) Subject: SONAR-8692 Replace calls to api/timemachine/index WS by api/measures/search_history X-Git-Tag: 6.3-RC1~436 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=be36f35e637ace99705b843c7d4ef31d2eb9d59f;p=sonarqube.git SONAR-8692 Replace calls to api/timemachine/index WS by api/measures/search_history --- diff --git a/server/sonar-web/src/main/js/api/time-machine.js b/server/sonar-web/src/main/js/api/time-machine.js index 25d65c43c71..8f81cd82f94 100644 --- a/server/sonar-web/src/main/js/api/time-machine.js +++ b/server/sonar-web/src/main/js/api/time-machine.js @@ -17,10 +17,29 @@ * 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 { getJSON } from '../helpers/request'; -export function getTimeMachineData (componentKey, metrics) { - const url = '/api/timemachine/index'; - const data = { resource: componentKey, metrics }; - return getJSON(url, data); -} +type Response = { + measures: Array<{ + metric: string, + history: Array<{ + date: string, + value: string + }> + }>, + paging: { + pageIndex: number, + pageSize: number, + total: number + } +}; + +export const getTimeMachineData = (component: string, metrics: Array, other?: {}): Promise => ( + getJSON('/api/measures/search_history', { + component, + metrics: metrics.join(), + ps: 1000, + ...other + }) +); diff --git a/server/sonar-web/src/main/js/apps/component-measures/details/history/MeasureHistory.js b/server/sonar-web/src/main/js/apps/component-measures/details/history/MeasureHistory.js index fb365808e3d..6b0859d9e40 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/details/history/MeasureHistory.js +++ b/server/sonar-web/src/main/js/apps/component-measures/details/history/MeasureHistory.js @@ -29,10 +29,6 @@ import { translate } from '../../../../helpers/l10n'; const HEIGHT = 500; -function parseValue (value, type) { - return type === 'RATING' && typeof value === 'string' ? value.charCodeAt(0) - 'A'.charCodeAt(0) + 1 : value; -} - export default class MeasureHistory extends React.Component { state = { components: [], @@ -79,13 +75,14 @@ export default class MeasureHistory extends React.Component { metricsToRequest.push(comparisonMetric); } - return getTimeMachineData(this.props.component.key, metricsToRequest.join()).then(r => { - return r[0].cells.map(cell => { - return { - date: moment(cell.d).toDate(), - values: cell.v - }; - }); + return getTimeMachineData(this.props.component.key, metricsToRequest).then(r => { + if (r.measures.length === 0) { + return []; + } + return r.measures[0].history.map(analysis => ({ + date: moment(analysis.date).toDate(), + value: analysis.value + })); }); } @@ -104,7 +101,7 @@ export default class MeasureHistory extends React.Component { }); } - renderLineChart (snapshots, metric, index) { + renderLineChart (snapshots, metric) { if (!metric) { return null; } @@ -116,7 +113,7 @@ export default class MeasureHistory extends React.Component { const data = snapshots.map(snapshot => { return { x: snapshot.date, - y: parseValue(snapshot.values[index], metric.type) + y: Number(snapshot.value) }; }); @@ -139,17 +136,6 @@ export default class MeasureHistory extends React.Component { ); } - renderLineCharts () { - const { metric } = this.props; - - return ( -
- {this.renderLineChart(this.state.snapshots, metric, 0)} - {this.renderLineChart(this.state.snapshots, this.state.comparisonMetric, 1)} -
- ); - } - render () { const { fetching, snapshots } = this.state; @@ -175,7 +161,7 @@ export default class MeasureHistory extends React.Component { return (
- {this.renderLineCharts()} + {this.renderLineChart(this.state.snapshots, this.props.metric)}
); } diff --git a/server/sonar-web/src/main/js/apps/overview/components/OverviewApp.js b/server/sonar-web/src/main/js/apps/overview/components/OverviewApp.js index a2791781168..f65429c3c25 100644 --- a/server/sonar-web/src/main/js/apps/overview/components/OverviewApp.js +++ b/server/sonar-web/src/main/js/apps/overview/components/OverviewApp.js @@ -131,16 +131,15 @@ export default class OverviewApp extends React.Component { } loadHistory (component) { - const metrics = HISTORY_METRICS_LIST.join(','); - return getTimeMachineData(component.key, metrics).then(r => { + return getTimeMachineData(component.key, HISTORY_METRICS_LIST).then(r => { if (this.mounted) { const history = {}; - r[0].cols.forEach((col, index) => { - history[col.metric] = r[0].cells.map(cell => { - const date = moment(cell.d).toDate(); - const value = cell.v[index] || 0; - return { date, value }; - }); + r.measures.forEach(measure => { + const measureHistory = measure.history.map(analysis => ({ + date: moment(analysis.date).toDate(), + value: analysis.value + })); + history[measure.metric] = measureHistory; }); const historyStartDate = history[HISTORY_METRICS_LIST[0]][0].date; this.setState({ history, historyStartDate });