aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web
diff options
context:
space:
mode:
authorStas Vilchik <vilchiks@gmail.com>2017-01-24 13:11:34 +0100
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2017-01-24 17:37:23 +0100
commitbe36f35e637ace99705b843c7d4ef31d2eb9d59f (patch)
tree09982a725ee2d32112b7d873dac076924563125b /server/sonar-web
parentf55c90fa06e82cd70639eda3c2a6f686a13fbee7 (diff)
downloadsonarqube-be36f35e637ace99705b843c7d4ef31d2eb9d59f.tar.gz
sonarqube-be36f35e637ace99705b843c7d4ef31d2eb9d59f.zip
SONAR-8692 Replace calls to api/timemachine/index WS by api/measures/search_history
Diffstat (limited to 'server/sonar-web')
-rw-r--r--server/sonar-web/src/main/js/api/time-machine.js29
-rw-r--r--server/sonar-web/src/main/js/apps/component-measures/details/history/MeasureHistory.js36
-rw-r--r--server/sonar-web/src/main/js/apps/overview/components/OverviewApp.js15
3 files changed, 42 insertions, 38 deletions
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<string>, other?: {}): Promise<Response> => (
+ 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 (
- <div>
- {this.renderLineChart(this.state.snapshots, metric, 0)}
- {this.renderLineChart(this.state.snapshots, this.state.comparisonMetric, 1)}
- </div>
- );
- }
-
render () {
const { fetching, snapshots } = this.state;
@@ -175,7 +161,7 @@ export default class MeasureHistory extends React.Component {
return (
<div className="measure-details-history">
- {this.renderLineCharts()}
+ {this.renderLineChart(this.state.snapshots, this.props.metric)}
</div>
);
}
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 });