summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStas Vilchik <vilchiks@gmail.com>2016-03-25 13:38:55 +0100
committerStas Vilchik <vilchiks@gmail.com>2016-03-25 13:39:01 +0100
commit46c1052e04652b318ac1cf2e934bfad9c152d690 (patch)
treef321d0767012ea6150f6fc276fb672e14f611bb5
parentdcb221abc2896304e55e92d7f366c503cafc2a50 (diff)
downloadsonarqube-46c1052e04652b318ac1cf2e934bfad9c152d690.tar.gz
sonarqube-46c1052e04652b318ac1cf2e934bfad9c152d690.zip
SONAR-7409 use period parameter
-rw-r--r--server/sonar-web/src/main/js/apps/component-measures/details/MeasureDetails.js21
-rw-r--r--server/sonar-web/src/main/js/apps/component-measures/details/MeasureDetailsContainer.js2
-rw-r--r--server/sonar-web/src/main/js/apps/component-measures/details/actions.js4
-rw-r--r--server/sonar-web/src/main/js/apps/component-measures/details/drilldown/ListView.js3
-rw-r--r--server/sonar-web/src/main/js/apps/component-measures/details/drilldown/ListViewContainer.js2
-rw-r--r--server/sonar-web/src/main/js/apps/component-measures/details/drilldown/TreeView.js3
-rw-r--r--server/sonar-web/src/main/js/apps/component-measures/details/drilldown/TreeViewContainer.js2
-rw-r--r--server/sonar-web/src/main/js/apps/component-measures/store/listViewActions.js15
-rw-r--r--server/sonar-web/src/main/js/apps/component-measures/store/treeViewActions.js36
-rw-r--r--server/sonar-web/src/main/js/apps/component-measures/store/treeViewReducer.js2
-rw-r--r--server/sonar-web/src/main/js/apps/component-measures/utils.js16
-rw-r--r--server/sonar-web/src/main/js/helpers/periods.js8
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/app/controllers/drilldown_controller.rb7
13 files changed, 69 insertions, 52 deletions
diff --git a/server/sonar-web/src/main/js/apps/component-measures/details/MeasureDetails.js b/server/sonar-web/src/main/js/apps/component-measures/details/MeasureDetails.js
index 93ccd1e32e0..3b9fd8f6589 100644
--- a/server/sonar-web/src/main/js/apps/component-measures/details/MeasureDetails.js
+++ b/server/sonar-web/src/main/js/apps/component-measures/details/MeasureDetails.js
@@ -23,7 +23,7 @@ import { Link, IndexLink } from 'react-router';
import Spinner from './../components/Spinner';
import MeasureDetailsHeader from './MeasureDetailsHeader';
import MeasureDrilldown from './drilldown/MeasureDrilldown';
-import { getLeakPeriod, getPeriodDate, getPeriodLabel } from '../../../helpers/periods';
+import { getPeriod, getPeriodDate, getPeriodLabel } from '../../../helpers/periods';
import { translate, translateWithParameters } from '../../../helpers/l10n';
export default class MeasureDetails extends React.Component {
@@ -44,12 +44,14 @@ export default class MeasureDetails extends React.Component {
}
componentDidMount () {
- this.props.fetchMeasure(this.props.params.metricKey);
+ const periodIndex = this.props.location.query.period || 1;
+ this.props.fetchMeasure(this.props.params.metricKey, Number(periodIndex));
}
componentDidUpdate (nextProps) {
if (nextProps.params.metricKey !== this.props.params.metricKey) {
- this.props.fetchMeasure(nextProps.params.metricKey);
+ const periodIndex = nextProps.location.query.period || 1;
+ this.props.fetchMeasure(nextProps.params.metricKey, Number(periodIndex));
}
}
@@ -61,9 +63,10 @@ export default class MeasureDetails extends React.Component {
}
const { tab } = this.props.params;
- const leakPeriod = getLeakPeriod(periods);
- const leakPeriodLabel = getPeriodLabel(leakPeriod);
- const leakPeriodDate = getPeriodDate(leakPeriod);
+ const periodIndex = this.props.location.query.period || 1;
+ const period = getPeriod(periods, Number(periodIndex));
+ const periodLabel = getPeriodLabel(period);
+ const periodDate = getPeriodDate(period);
return (
<section id="component-measures-details" className="page page-container page-limited">
@@ -86,15 +89,15 @@ export default class MeasureDetails extends React.Component {
measure={measure}
metric={metric}
secondaryMeasure={secondaryMeasure}
- leakPeriodLabel={leakPeriodLabel}/>
+ leakPeriodLabel={periodLabel}/>
{measure && (
<MeasureDrilldown
component={component}
metric={metric}
tab={tab}
- leakPeriod={leakPeriod}
- leakPeriodDate={leakPeriodDate}>
+ leakPeriod={period}
+ leakPeriodDate={periodDate}>
{children}
</MeasureDrilldown>
)}
diff --git a/server/sonar-web/src/main/js/apps/component-measures/details/MeasureDetailsContainer.js b/server/sonar-web/src/main/js/apps/component-measures/details/MeasureDetailsContainer.js
index 3d009be366b..af344e20413 100644
--- a/server/sonar-web/src/main/js/apps/component-measures/details/MeasureDetailsContainer.js
+++ b/server/sonar-web/src/main/js/apps/component-measures/details/MeasureDetailsContainer.js
@@ -35,7 +35,7 @@ const mapStateToProps = state => {
const mapDispatchToProps = dispatch => {
return {
- fetchMeasure: metricKey => dispatch(fetchMeasure(metricKey))
+ fetchMeasure: (metricKey, periodIndex) => dispatch(fetchMeasure(metricKey, periodIndex))
};
};
diff --git a/server/sonar-web/src/main/js/apps/component-measures/details/actions.js b/server/sonar-web/src/main/js/apps/component-measures/details/actions.js
index 8992f530580..b6d4bcaf163 100644
--- a/server/sonar-web/src/main/js/apps/component-measures/details/actions.js
+++ b/server/sonar-web/src/main/js/apps/component-measures/details/actions.js
@@ -45,7 +45,7 @@ function receiveMeasure (measure, secondaryMeasure, periods) {
* Workflow
*/
-export function fetchMeasure (metricKey) {
+export function fetchMeasure (metricKey, periodIndex = 1) {
return (dispatch, getState) => {
const { component, metrics } = getState().app;
const metricsToRequest = [metricKey];
@@ -68,7 +68,7 @@ export function fetchMeasure (metricKey) {
metricsToRequest,
{ additionalFields: 'periods' }
).then(r => {
- const measures = enhanceWithLeak(r.component.measures);
+ const measures = enhanceWithLeak(r.component.measures, periodIndex);
const measure = measures.find(m => m.metric === metricKey);
const secondaryMeasure = measures.find(m => m.metric !== metricKey);
dispatch(receiveMeasure(measure, secondaryMeasure, r.periods));
diff --git a/server/sonar-web/src/main/js/apps/component-measures/details/drilldown/ListView.js b/server/sonar-web/src/main/js/apps/component-measures/details/drilldown/ListView.js
index 1ade9e39ba4..92696dd56c7 100644
--- a/server/sonar-web/src/main/js/apps/component-measures/details/drilldown/ListView.js
+++ b/server/sonar-web/src/main/js/apps/component-measures/details/drilldown/ListView.js
@@ -65,7 +65,8 @@ export default class ListView extends React.Component {
handleChangeBaseComponent (baseComponent) {
const { metric, onFetchList } = this.props;
- onFetchList(baseComponent, metric);
+ const periodIndex = this.props.location.query.period || 1;
+ onFetchList(baseComponent, metric, Number(periodIndex));
}
changeSelected (selected) {
diff --git a/server/sonar-web/src/main/js/apps/component-measures/details/drilldown/ListViewContainer.js b/server/sonar-web/src/main/js/apps/component-measures/details/drilldown/ListViewContainer.js
index 74e1faba30e..6759d25be95 100644
--- a/server/sonar-web/src/main/js/apps/component-measures/details/drilldown/ListViewContainer.js
+++ b/server/sonar-web/src/main/js/apps/component-measures/details/drilldown/ListViewContainer.js
@@ -40,7 +40,7 @@ const mapStateToProps = state => {
const mapDispatchToProps = dispatch => {
return {
- onFetchList: (baseComponent, metric) => dispatch(fetchList(baseComponent, metric)),
+ onFetchList: (baseComponent, metric, periodIndex) => dispatch(fetchList(baseComponent, metric, periodIndex)),
onFetchMore: (baseComponent, metric) => dispatch(fetchMore(baseComponent, metric)),
onSelect: component => dispatch(selectComponent(component)),
onSelectNext: component => dispatch(selectNext(component)),
diff --git a/server/sonar-web/src/main/js/apps/component-measures/details/drilldown/TreeView.js b/server/sonar-web/src/main/js/apps/component-measures/details/drilldown/TreeView.js
index 7a4048589e1..b66b5686bda 100644
--- a/server/sonar-web/src/main/js/apps/component-measures/details/drilldown/TreeView.js
+++ b/server/sonar-web/src/main/js/apps/component-measures/details/drilldown/TreeView.js
@@ -59,7 +59,8 @@ export default class TreeView extends React.Component {
handleChangeBaseComponent (baseComponent) {
const { metric, onStart } = this.props;
- onStart(baseComponent, metric);
+ const periodIndex = this.props.location.query.period || 1;
+ onStart(baseComponent, metric, Number(periodIndex));
}
changeSelected (selected) {
diff --git a/server/sonar-web/src/main/js/apps/component-measures/details/drilldown/TreeViewContainer.js b/server/sonar-web/src/main/js/apps/component-measures/details/drilldown/TreeViewContainer.js
index f32bc7d222c..5643effcbc3 100644
--- a/server/sonar-web/src/main/js/apps/component-measures/details/drilldown/TreeViewContainer.js
+++ b/server/sonar-web/src/main/js/apps/component-measures/details/drilldown/TreeViewContainer.js
@@ -49,7 +49,7 @@ const mapStateToProps = state => {
const mapDispatchToProps = dispatch => {
return {
- onStart: (rootComponent, metric) => dispatch(start(rootComponent, metric)),
+ onStart: (rootComponent, metric, periodIndex) => dispatch(start(rootComponent, metric, periodIndex)),
onFetchMore: () => dispatch(fetchMore()),
onDrilldown: component => dispatch(drilldown(component)),
onUseBreadcrumbs: component => dispatch(useBreadcrumbs(component)),
diff --git a/server/sonar-web/src/main/js/apps/component-measures/store/listViewActions.js b/server/sonar-web/src/main/js/apps/component-measures/store/listViewActions.js
index 6826e012786..a10dad931f8 100644
--- a/server/sonar-web/src/main/js/apps/component-measures/store/listViewActions.js
+++ b/server/sonar-web/src/main/js/apps/component-measures/store/listViewActions.js
@@ -27,7 +27,7 @@ function updateStore (state) {
return { type: UPDATE_STORE, state };
}
-function makeRequest (baseComponent, metric, options) {
+function makeRequest (baseComponent, metric, options, periodIndex = 1) {
const asc = metric.direction === 1;
const ps = 100;
const finalOptions = { asc, ps };
@@ -36,7 +36,7 @@ function makeRequest (baseComponent, metric, options) {
Object.assign(options, {
s: 'metricPeriod,name',
metricSort: metric.key,
- metricPeriodSort: 1
+ metricPeriodSort: periodIndex
});
} else {
Object.assign(options, {
@@ -49,11 +49,11 @@ function makeRequest (baseComponent, metric, options) {
return getComponentTree('leaves', baseComponent.key, [metric.key], finalOptions);
}
-function fetchLeaves (baseComponent, metric, pageIndex = 1) {
+function fetchLeaves (baseComponent, metric, pageIndex = 1, periodIndex = 1) {
const options = { p: pageIndex };
- return makeRequest(baseComponent, metric, options).then(r => {
- const nextComponents = enhanceWithSingleMeasure(r.components);
+ return makeRequest(baseComponent, metric, options, periodIndex).then(r => {
+ const nextComponents = enhanceWithSingleMeasure(r.components, periodIndex);
return {
components: nextComponents,
@@ -67,8 +67,9 @@ function fetchLeaves (baseComponent, metric, pageIndex = 1) {
* Fetch the first page of components for a given base component
* @param baseComponent
* @param metric
+ * @param periodIndex
*/
-export function fetchList (baseComponent, metric) {
+export function fetchList (baseComponent, metric, periodIndex = 1) {
return (dispatch, getState) => {
const { list } = getState();
if (list.baseComponent === baseComponent && list.metric === metric) {
@@ -76,7 +77,7 @@ export function fetchList (baseComponent, metric) {
}
dispatch(startFetching());
- return fetchLeaves(baseComponent, metric).then(r => {
+ return fetchLeaves(baseComponent, metric, 1, periodIndex).then(r => {
dispatch(updateStore({
...r,
baseComponent,
diff --git a/server/sonar-web/src/main/js/apps/component-measures/store/treeViewActions.js b/server/sonar-web/src/main/js/apps/component-measures/store/treeViewActions.js
index a45cf2dfa5c..5701ffb1498 100644
--- a/server/sonar-web/src/main/js/apps/component-measures/store/treeViewActions.js
+++ b/server/sonar-web/src/main/js/apps/component-measures/store/treeViewActions.js
@@ -49,10 +49,11 @@ function updateStore (state) {
* Init tree view drilldown for the given root component and given metric
* @param rootComponent
* @param metric
+ * @param periodIndex
* @returns {{type: string, rootComponent: *, metric: *}}
*/
-function init (rootComponent, metric) {
- return { type: INIT, rootComponent, metric };
+function init (rootComponent, metric, periodIndex = 1) {
+ return { type: INIT, rootComponent, metric, periodIndex };
}
@@ -60,7 +61,7 @@ function init (rootComponent, metric) {
* Workflow
*/
-function makeRequest (baseComponent, metric, options) {
+function makeRequest (baseComponent, metric, options, periodIndex = 1) {
const asc = metric.direction === 1;
const ps = 100;
const finalOptions = { asc, ps };
@@ -69,7 +70,7 @@ function makeRequest (baseComponent, metric, options) {
Object.assign(options, {
s: 'metricPeriod,name',
metricSort: metric.key,
- metricPeriodSort: 1
+ metricPeriodSort: periodIndex
});
} else {
Object.assign(options, {
@@ -82,11 +83,11 @@ function makeRequest (baseComponent, metric, options) {
return getComponentTree('children', baseComponent.key, [metric.key], finalOptions);
}
-function fetchComponents (baseComponent, metric, pageIndex = 1) {
+function fetchComponents (baseComponent, metric, pageIndex = 1, periodIndex = 1) {
const options = { p: pageIndex };
- return makeRequest(baseComponent, metric, options).then(r => {
- const nextComponents = enhanceWithSingleMeasure(r.components);
+ return makeRequest(baseComponent, metric, options, periodIndex).then(r => {
+ const nextComponents = enhanceWithSingleMeasure(r.components, periodIndex);
return {
baseComponent,
@@ -103,10 +104,10 @@ function fetchComponents (baseComponent, metric, pageIndex = 1) {
*/
function fetchList (baseComponent) {
return (dispatch, getState) => {
- const { metric } = getState().tree;
+ const { metric, periodIndex } = getState().tree;
dispatch(startFetching());
- return fetchComponents(baseComponent, metric).then(r => {
+ return fetchComponents(baseComponent, metric, 1, periodIndex).then(r => {
dispatch(updateStore({
...r,
baseComponent,
@@ -122,16 +123,17 @@ function fetchList (baseComponent) {
* Fetch the first page of components if needed.
* @param rootComponent
* @param metric
+ * @param periodIndex
* @returns {function()}
*/
-export function start (rootComponent, metric) {
+export function start (rootComponent, metric, periodIndex = 1) {
return (dispatch, getState) => {
const { tree } = getState();
if (rootComponent === tree.rootComponent && metric === tree.metric) {
return Promise.resolve();
}
- dispatch(init(rootComponent, metric));
+ dispatch(init(rootComponent, metric, periodIndex));
dispatch(fetchList(rootComponent));
};
}
@@ -141,9 +143,9 @@ export function start (rootComponent, metric) {
*/
export function fetchMore () {
return (dispatch, getState) => {
- const { metric, baseComponent, components, pageIndex } = getState().tree;
+ const { metric, baseComponent, components, pageIndex, periodIndex } = getState().tree;
dispatch(startFetching());
- return fetchComponents(baseComponent, metric, pageIndex + 1).then(r => {
+ return fetchComponents(baseComponent, metric, pageIndex + 1, periodIndex).then(r => {
dispatch(updateStore({
...r,
components: [...components, ...r.components]
@@ -159,9 +161,9 @@ export function fetchMore () {
*/
export function drilldown (component) {
return (dispatch, getState) => {
- const { metric, breadcrumbs } = getState().tree;
+ const { metric, breadcrumbs, periodIndex } = getState().tree;
dispatch(startFetching());
- return fetchComponents(component, metric).then(r => {
+ return fetchComponents(component, metric, 1, periodIndex).then(r => {
dispatch(updateStore({
...r,
breadcrumbs: [...breadcrumbs, component],
@@ -178,10 +180,10 @@ export function drilldown (component) {
*/
export function useBreadcrumbs (component) {
return (dispatch, getState) => {
- const { metric, breadcrumbs } = getState().tree;
+ const { metric, breadcrumbs, periodIndex } = getState().tree;
const index = breadcrumbs.indexOf(component);
dispatch(startFetching());
- return fetchComponents(component, metric).then(r => {
+ return fetchComponents(component, metric, 1, periodIndex).then(r => {
dispatch(updateStore({
...r,
breadcrumbs: breadcrumbs.slice(0, index + 1),
diff --git a/server/sonar-web/src/main/js/apps/component-measures/store/treeViewReducer.js b/server/sonar-web/src/main/js/apps/component-measures/store/treeViewReducer.js
index b647b538816..99b6c0fc374 100644
--- a/server/sonar-web/src/main/js/apps/component-measures/store/treeViewReducer.js
+++ b/server/sonar-web/src/main/js/apps/component-measures/store/treeViewReducer.js
@@ -35,7 +35,7 @@ export default function drilldownReducer (state = initialState, action = {}) {
case UPDATE_STORE:
return { ...state, ...action.state };
case INIT:
- return { ...state, ...pick(action, ['rootComponent', 'metric']) };
+ return { ...state, ...pick(action, ['rootComponent', 'metric', 'periodIndex']) };
default:
return state;
}
diff --git a/server/sonar-web/src/main/js/apps/component-measures/utils.js b/server/sonar-web/src/main/js/apps/component-measures/utils.js
index 3e54ffe49da..6a35c90f8d6 100644
--- a/server/sonar-web/src/main/js/apps/component-measures/utils.js
+++ b/server/sonar-web/src/main/js/apps/component-measures/utils.js
@@ -24,13 +24,13 @@ export function isDiffMetric (metric) {
return metric.key.indexOf('new_') === 0;
}
-export function getLeakValue (measure) {
+export function getLeakValue (measure, periodIndex = 1) {
if (!measure) {
return null;
}
const period = measure.periods ?
- measure.periods.find(period => period.index === 1) : null;
+ measure.periods.find(period => period.index === periodIndex) : null;
return period ? period.value : null;
}
@@ -43,7 +43,7 @@ export function getSingleMeasureValue (measures) {
return measures[0].value;
}
-export function getSingleLeakValue (measures) {
+export function getSingleLeakValue (measures, periodIndex = 1) {
if (!measures || !measures.length) {
return null;
}
@@ -51,7 +51,7 @@ export function getSingleLeakValue (measures) {
const measure = measures[0];
const period = measure.periods ?
- measure.periods.find(period => period.index === 1) : null;
+ measure.periods.find(period => period.index === periodIndex) : null;
return period ? period.value : null;
}
@@ -64,9 +64,9 @@ export function formatLeak (value, metric) {
}
}
-export function enhanceWithLeak (measures) {
+export function enhanceWithLeak (measures, periodIndex = 1) {
function enhanceSingle (measure) {
- return { ...measure, leak: getLeakValue(measure) };
+ return { ...measure, leak: getLeakValue(measure, periodIndex) };
}
if (Array.isArray(measures)) {
@@ -76,13 +76,13 @@ export function enhanceWithLeak (measures) {
}
}
-export function enhanceWithSingleMeasure (components) {
+export function enhanceWithSingleMeasure (components, periodIndex = 1) {
return components
.map(component => {
return {
...component,
value: getSingleMeasureValue(component.measures),
- leak: getSingleLeakValue(component.measures)
+ leak: getSingleLeakValue(component.measures, periodIndex)
};
});
}
diff --git a/server/sonar-web/src/main/js/helpers/periods.js b/server/sonar-web/src/main/js/helpers/periods.js
index b87a15ca004..cf146897b49 100644
--- a/server/sonar-web/src/main/js/helpers/periods.js
+++ b/server/sonar-web/src/main/js/helpers/periods.js
@@ -20,12 +20,16 @@
import moment from 'moment';
import { translate, translateWithParameters } from './l10n';
-export function getLeakPeriod (periods) {
+export function getPeriod (periods, index) {
if (!Array.isArray(periods)) {
return null;
}
- return periods.find(period => period.index === 1);
+ return periods.find(period => period.index === index);
+}
+
+export function getLeakPeriod (periods) {
+ return getPeriod(periods, 1);
}
export function getPeriodLabel (period) {
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/drilldown_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/drilldown_controller.rb
index 7d6c243c921..4289af1991e 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/drilldown_controller.rb
+++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/drilldown_controller.rb
@@ -24,7 +24,12 @@ class DrilldownController < ApplicationController
def measures
metric = params[:metric] || 'ncloc'
- return redirect_to("/component_measures/metric/#{metric}?id=#{url_encode(@resource.key)}")
+ period = params[:period].to_i if params[:period].present? && params[:period].to_i > 0
+ if period
+ return redirect_to("/component_measures/metric/#{metric}?id=#{url_encode(@resource.key)}&period=#{period}")
+ else
+ return redirect_to("/component_measures/metric/#{metric}?id=#{url_encode(@resource.key)}")
+ end
end
def issues