aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src
diff options
context:
space:
mode:
authorGrégoire Aubert <gregoire.aubert@sonarsource.com>2017-11-06 17:19:12 +0100
committerGuillaume Jambet <guillaume.jambet@gmail.com>2017-11-08 13:51:31 +0100
commit20091d38661b5bb43b101b034e3be363a0bad3d7 (patch)
treead4db1c1c3939e554211458b2f71fc1a635f1301 /server/sonar-web/src
parentcfed131070e85a90c1e41af492235b8cf488a8eb (diff)
downloadsonarqube-20091d38661b5bb43b101b034e3be363a0bad3d7.tar.gz
sonarqube-20091d38661b5bb43b101b034e3be363a0bad3d7.zip
SONAR-10040 Update usage of api/metrics/search
Diffstat (limited to 'server/sonar-web/src')
-rw-r--r--server/sonar-web/src/main/js/api/metrics.ts27
-rw-r--r--server/sonar-web/src/main/js/apps/overview/events/AnalysesList.js23
-rw-r--r--server/sonar-web/src/main/js/apps/portfolio/components/Activity.tsx4
-rw-r--r--server/sonar-web/src/main/js/apps/portfolio/components/__tests__/Activity-test.tsx8
-rw-r--r--server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityAppContainer.js6
-rw-r--r--server/sonar-web/src/main/js/components/SourceViewer/views/measures-overlay.js18
-rw-r--r--server/sonar-web/src/main/js/store/rootActions.js4
7 files changed, 54 insertions, 36 deletions
diff --git a/server/sonar-web/src/main/js/api/metrics.ts b/server/sonar-web/src/main/js/api/metrics.ts
index 0cdc333aef0..1e9fdfdc1f9 100644
--- a/server/sonar-web/src/main/js/api/metrics.ts
+++ b/server/sonar-web/src/main/js/api/metrics.ts
@@ -21,8 +21,31 @@ import { getJSON } from '../helpers/request';
import { Metric } from '../app/types';
import throwGlobalError from '../app/utils/throwGlobalError';
-export function getMetrics(): Promise<Metric[]> {
- return getJSON('/api/metrics/search', { ps: 9999 }).then(r => r.metrics);
+interface MetricsResponse {
+ metrics: Metric[];
+ p: number;
+ ps: number;
+ total: number;
+}
+
+export function getMetrics(data: { p?: number; ps?: number }): Promise<MetricsResponse> {
+ return getJSON('/api/metrics/search', data).catch(throwGlobalError);
+}
+
+export function getAllMetrics(data?: { p?: number; ps?: number }): Promise<Metric[]> {
+ return inner(data);
+ function inner(
+ data: { p?: number; ps?: number } = { ps: 500 },
+ prev?: MetricsResponse
+ ): Promise<Metric[]> {
+ return getMetrics(data).then(r => {
+ const result = prev ? prev.metrics.concat(r.metrics) : r.metrics;
+ if (r.p * r.ps >= r.total) {
+ return result;
+ }
+ return inner({ ...data, p: r.p + 1 }, { ...r, metrics: result });
+ });
+ }
}
export function getMetricDomains(): Promise<string[]> {
diff --git a/server/sonar-web/src/main/js/apps/overview/events/AnalysesList.js b/server/sonar-web/src/main/js/apps/overview/events/AnalysesList.js
index e70fa1cb1fb..81fd6181acb 100644
--- a/server/sonar-web/src/main/js/apps/overview/events/AnalysesList.js
+++ b/server/sonar-web/src/main/js/apps/overview/events/AnalysesList.js
@@ -21,7 +21,7 @@
import React from 'react';
import { Link } from 'react-router';
import Analysis from './Analysis';
-import { getMetrics } from '../../../api/metrics';
+import { getAllMetrics } from '../../../api/metrics';
import { getProjectActivity } from '../../../api/projectActivity';
import PreviewGraph from '../../../components/preview-graph/PreviewGraph';
import { translate } from '../../../helpers/l10n';
@@ -88,12 +88,23 @@ export default class AnalysesList extends React.PureComponent {
project: this.getTopLevelComponent(),
ps: PAGE_SIZE
}),
- getMetrics()
- ]).then(response => {
- if (this.mounted) {
- this.setState({ analyses: response[0].analyses, metrics: response[1], loading: false });
+ getAllMetrics()
+ ]).then(
+ response => {
+ if (this.mounted) {
+ this.setState({
+ analyses: response[0].analyses,
+ metrics: response[1],
+ loading: false
+ });
+ }
+ },
+ () => {
+ if (this.mounted) {
+ this.setState({ loading: false });
+ }
}
- });
+ );
}
renderList(analyses /*: Array<AnalysisType> */) {
diff --git a/server/sonar-web/src/main/js/apps/portfolio/components/Activity.tsx b/server/sonar-web/src/main/js/apps/portfolio/components/Activity.tsx
index 7816da08c76..dc9f9db6669 100644
--- a/server/sonar-web/src/main/js/apps/portfolio/components/Activity.tsx
+++ b/server/sonar-web/src/main/js/apps/portfolio/components/Activity.tsx
@@ -20,7 +20,7 @@
import * as React from 'react';
import { getDisplayedHistoryMetrics, DEFAULT_GRAPH } from '../../projectActivity/utils';
import PreviewGraph from '../../../components/preview-graph/PreviewGraph';
-import { getMetrics } from '../../../api/metrics';
+import { getAllMetrics } from '../../../api/metrics';
import { getAllTimeMachineData } from '../../../api/time-machine';
import { Metric } from '../../../app/types';
import { parseDate } from '../../../helpers/dates';
@@ -71,7 +71,7 @@ export default class Activity extends React.PureComponent<Props> {
}
this.setState({ loading: true });
- return Promise.all([getAllTimeMachineData(component, graphMetrics), getMetrics()]).then(
+ return Promise.all([getAllTimeMachineData(component, graphMetrics), getAllMetrics()]).then(
([timeMachine, metrics]) => {
if (this.mounted) {
const history: History = {};
diff --git a/server/sonar-web/src/main/js/apps/portfolio/components/__tests__/Activity-test.tsx b/server/sonar-web/src/main/js/apps/portfolio/components/__tests__/Activity-test.tsx
index e0fc5b8ff9d..c343e8c0193 100644
--- a/server/sonar-web/src/main/js/apps/portfolio/components/__tests__/Activity-test.tsx
+++ b/server/sonar-web/src/main/js/apps/portfolio/components/__tests__/Activity-test.tsx
@@ -24,7 +24,7 @@ jest.mock('../../../../helpers/storage', () => ({
}));
jest.mock('../../../../api/metrics', () => ({
- getMetrics: jest.fn(() => Promise.resolve([]))
+ getAllMetrics: jest.fn(() => Promise.resolve([]))
}));
jest.mock('../../../../api/time-machine', () => ({
@@ -47,12 +47,12 @@ import * as React from 'react';
import { mount, shallow } from 'enzyme';
import Activity from '../Activity';
-const getMetrics = require('../../../../api/metrics').getMetrics as jest.Mock<any>;
+const getAllMetrics = require('../../../../api/metrics').getAllMetrics as jest.Mock<any>;
const getAllTimeMachineData = require('../../../../api/time-machine')
.getAllTimeMachineData as jest.Mock<any>;
beforeEach(() => {
- getMetrics.mockClear();
+ getAllMetrics.mockClear();
getAllTimeMachineData.mockClear();
});
@@ -73,6 +73,6 @@ it('renders', () => {
it('fetches history', () => {
mount(<Activity component="foo" />);
- expect(getMetrics).toBeCalled();
+ expect(getAllMetrics).toBeCalled();
expect(getAllTimeMachineData).toBeCalledWith('foo', ['coverage']);
});
diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityAppContainer.js b/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityAppContainer.js
index d201c600c01..080842999d8 100644
--- a/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityAppContainer.js
+++ b/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityAppContainer.js
@@ -23,7 +23,7 @@ import PropTypes from 'prop-types';
import ProjectActivityApp from './ProjectActivityApp';
import throwGlobalError from '../../../app/utils/throwGlobalError';
import { getAllTimeMachineData } from '../../../api/time-machine';
-import { getMetrics } from '../../../api/metrics';
+import { getAllMetrics } from '../../../api/metrics';
import * as api from '../../../api/projectActivity';
import * as actions from '../actions';
import { getBranchName } from '../../../helpers/branches';
@@ -206,8 +206,6 @@ export default class ProjectActivityAppContainer extends React.PureComponent {
);
};
- fetchMetrics = () => getMetrics().catch(throwGlobalError);
-
loadAllActivities = (
project /*: string */,
prevResult /*: ?{ analyses: Array<Analysis>, paging: Paging } */
@@ -246,7 +244,7 @@ export default class ProjectActivityAppContainer extends React.PureComponent {
const topLevelComponent = this.getTopLevelComponent(component);
Promise.all([
this.fetchActivity(topLevelComponent, 1, 100, serializeQuery(query)),
- this.fetchMetrics(),
+ getAllMetrics(),
this.fetchMeasuresHistory(graphMetrics)
]).then(
response => {
diff --git a/server/sonar-web/src/main/js/components/SourceViewer/views/measures-overlay.js b/server/sonar-web/src/main/js/components/SourceViewer/views/measures-overlay.js
index ad4ca78efaa..0faa854f57c 100644
--- a/server/sonar-web/src/main/js/components/SourceViewer/views/measures-overlay.js
+++ b/server/sonar-web/src/main/js/components/SourceViewer/views/measures-overlay.js
@@ -25,7 +25,7 @@ import ModalView from '../../common/modals';
import Template from './templates/source-viewer-measures.hbs';
import { searchIssues } from '../../../api/issues';
import { getMeasures } from '../../../api/measures';
-import { getMetrics } from '../../../api/metrics';
+import { getAllMetrics } from '../../../api/metrics';
import { getTests, getCoveredFiles } from '../../../api/tests';
import * as theme from '../../../app/theme';
import { getLocalizedMetricName, getLocalizedMetricDomain } from '../../../helpers/l10n';
@@ -108,20 +108,6 @@ export default ModalView.extend({
this.$('.js-test-list').scrollTop(this.testsScroll);
},
- getMetrics() {
- let metrics = '';
- const url = window.baseUrl + '/api/metrics/search';
- $.ajax({
- url,
- async: false,
- data: { ps: 9999 }
- }).done(data => {
- metrics = data.metrics.filter(metric => metric.type !== 'DATA' && !metric.hidden);
- metrics = sortBy(metrics, 'name');
- });
- return metrics;
- },
-
calcAdditionalMeasures(measures) {
measures.issuesRemediationEffort =
(Number(measures.sqale_index_raw) || 0) +
@@ -153,7 +139,7 @@ export default ModalView.extend({
},
requestMeasures() {
- return getMetrics().then(metrics => {
+ return getAllMetrics().then(metrics => {
const metricsToRequest = metrics
.filter(metric => metric.type !== 'DATA' && !metric.hidden)
.map(metric => metric.key);
diff --git a/server/sonar-web/src/main/js/store/rootActions.js b/server/sonar-web/src/main/js/store/rootActions.js
index 84ecaba4dd1..3f41686b567 100644
--- a/server/sonar-web/src/main/js/store/rootActions.js
+++ b/server/sonar-web/src/main/js/store/rootActions.js
@@ -21,7 +21,7 @@ import { getLanguages } from '../api/languages';
import { getGlobalNavigation } from '../api/nav';
import * as auth from '../api/auth';
import { getOrganizations } from '../api/organizations';
-import { getMetrics } from '../api/metrics';
+import { getAllMetrics } from '../api/metrics';
import { receiveLanguages } from './languages/actions';
import { receiveMetrics } from './metrics/actions';
import { addGlobalErrorMessage } from './globalMessages/duck';
@@ -42,7 +42,7 @@ export const fetchLanguages = () => dispatch =>
getLanguages().then(languages => dispatch(receiveLanguages(languages)), onFail(dispatch));
export const fetchMetrics = () => dispatch =>
- getMetrics().then(metrics => dispatch(receiveMetrics(metrics)), onFail(dispatch));
+ getAllMetrics().then(metrics => dispatch(receiveMetrics(metrics)), onFail(dispatch));
export const fetchOrganizations = (organizations /*: Array<string> | void */) => dispatch =>
getOrganizations(organizations).then(