@@ -20,16 +20,18 @@ | |||
import { getJSON, post, postJSON } from 'sonar-ui-common/helpers/request'; | |||
import throwGlobalError from '../app/utils/throwGlobalError'; | |||
import { BranchParameters } from '../types/branch-like'; | |||
import { | |||
MeasuresAndMetaWithMetrics, | |||
MeasuresAndMetaWithPeriod, | |||
MeasuresForProjects | |||
} from '../types/measures'; | |||
const COMPONENT_URL = '/api/measures/component'; | |||
export function getMeasures( | |||
data: { component: string; metricKeys: string } & BranchParameters | |||
): Promise<T.Measure[]> { | |||
return getJSON('/api/measures/component', data).then(r => r.component.measures, throwGlobalError); | |||
} | |||
interface MeasuresAndMetaWithMetrics { | |||
component: T.ComponentMeasure; | |||
metrics: T.Metric[]; | |||
return getJSON(COMPONENT_URL, data).then(r => r.component.measures, throwGlobalError); | |||
} | |||
export function getMeasuresWithMetrics( | |||
@@ -37,7 +39,7 @@ export function getMeasuresWithMetrics( | |||
metrics: string[], | |||
branchParameters?: BranchParameters | |||
): Promise<MeasuresAndMetaWithMetrics> { | |||
return getJSON('/api/measures/component', { | |||
return getJSON(COMPONENT_URL, { | |||
additionalFields: 'metrics', | |||
component, | |||
metricKeys: metrics.join(','), | |||
@@ -45,17 +47,12 @@ export function getMeasuresWithMetrics( | |||
}).catch(throwGlobalError); | |||
} | |||
interface MeasuresAndMetaWithPeriod { | |||
component: T.ComponentMeasure; | |||
period: T.Period; | |||
} | |||
export function getMeasuresWithPeriod( | |||
component: string, | |||
metrics: string[], | |||
branchParameters?: BranchParameters | |||
): Promise<MeasuresAndMetaWithPeriod> { | |||
return getJSON('/api/measures/component', { | |||
return getJSON(COMPONENT_URL, { | |||
additionalFields: 'period', | |||
component, | |||
metricKeys: metrics.join(','), | |||
@@ -68,7 +65,7 @@ export function getMeasuresWithPeriodAndMetrics( | |||
metrics: string[], | |||
branchParameters?: BranchParameters | |||
): Promise<MeasuresAndMetaWithPeriod & MeasuresAndMetaWithMetrics> { | |||
return getJSON('/api/measures/component', { | |||
return getJSON(COMPONENT_URL, { | |||
additionalFields: 'period,metrics', | |||
component, | |||
metricKeys: metrics.join(','), | |||
@@ -76,13 +73,6 @@ export function getMeasuresWithPeriodAndMetrics( | |||
}).catch(throwGlobalError); | |||
} | |||
interface MeasuresForProjects { | |||
component: string; | |||
metric: string; | |||
periods?: T.PeriodMeasure[]; | |||
value?: string; | |||
} | |||
export function getMeasuresForProjects( | |||
projectKeys: string[], | |||
metricKeys: string[] |
@@ -169,13 +169,11 @@ exports[`should render correctly: measures loaded 1`] = ` | |||
Object { | |||
"bestValue": true, | |||
"metric": "bugs", | |||
"periods": Array [ | |||
Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
], | |||
"period": Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
"value": "1.0", | |||
}, | |||
] |
@@ -13,12 +13,10 @@ Array [ | |||
"name": "Lines to Cover", | |||
"type": "INT", | |||
}, | |||
"periods": Array [ | |||
Object { | |||
"index": 1, | |||
"value": "70", | |||
}, | |||
], | |||
"period": Object { | |||
"index": 1, | |||
"value": "70", | |||
}, | |||
"value": "431", | |||
}, | |||
Object { | |||
@@ -30,12 +28,10 @@ Array [ | |||
"name": "Coverage", | |||
"type": "PERCENT", | |||
}, | |||
"periods": Array [ | |||
Object { | |||
"index": 1, | |||
"value": "0.0999999999999943", | |||
}, | |||
], | |||
"period": Object { | |||
"index": 1, | |||
"value": "0.0999999999999943", | |||
}, | |||
"value": "99.3", | |||
}, | |||
], | |||
@@ -52,12 +48,10 @@ Array [ | |||
"name": "Duplicated Lines (%)", | |||
"type": "PERCENT", | |||
}, | |||
"periods": Array [ | |||
Object { | |||
"index": 1, | |||
"value": "0.0", | |||
}, | |||
], | |||
"period": Object { | |||
"index": 1, | |||
"value": "0.0", | |||
}, | |||
"value": "3.2", | |||
}, | |||
], |
@@ -31,7 +31,7 @@ const MEASURES = [ | |||
domain: 'Coverage' | |||
}, | |||
value: '431', | |||
periods: [{ index: 1, value: '70' }], | |||
period: { index: 1, value: '70' }, | |||
leak: '70' | |||
}, | |||
{ | |||
@@ -43,7 +43,7 @@ const MEASURES = [ | |||
domain: 'Coverage' | |||
}, | |||
value: '99.3', | |||
periods: [{ index: 1, value: '0.0999999999999943' }], | |||
period: { index: 1, value: '0.0999999999999943' }, | |||
leak: '0.0999999999999943' | |||
}, | |||
{ | |||
@@ -55,7 +55,7 @@ const MEASURES = [ | |||
domain: 'Duplications' | |||
}, | |||
value: '3.2', | |||
periods: [{ index: 1, value: '0.0' }], | |||
period: { index: 1, value: '0.0' }, | |||
leak: '0.0' | |||
} | |||
]; | |||
@@ -163,17 +163,17 @@ describe('extract measure', () => { | |||
{ | |||
metric: 'alert_status', | |||
value: '3.2', | |||
periods: [{ index: 1, value: '0.0' }] | |||
period: { index: 1, value: '0.0' } | |||
}, | |||
{ | |||
metric: 'releasability_rating', | |||
value: '3.2', | |||
periods: [{ index: 1, value: '0.0' }] | |||
period: { index: 1, value: '0.0' } | |||
}, | |||
{ | |||
metric: 'releasability_effort', | |||
value: '3.2', | |||
periods: [{ index: 1, value: '0.0' }] | |||
period: { index: 1, value: '0.0' } | |||
} | |||
] | |||
}; |
@@ -27,7 +27,7 @@ import { getMeasures } from '../../../api/measures'; | |||
import A11ySkipTarget from '../../../app/components/a11y/A11ySkipTarget'; | |||
import SourceViewer from '../../../components/SourceViewer/SourceViewer'; | |||
import { getBranchLikeQuery, isSameBranchLike } from '../../../helpers/branch-like'; | |||
import { getPeriodValue, isDiffMetric } from '../../../helpers/measures'; | |||
import { isDiffMetric } from '../../../helpers/measures'; | |||
import { getProjectUrl } from '../../../helpers/urls'; | |||
import { BranchLike } from '../../../types/branch-like'; | |||
import { MetricKey } from '../../../types/metrics'; | |||
@@ -299,7 +299,7 @@ export default class MeasureContent extends React.PureComponent<Props, State> { | |||
} | |||
const measureValue = | |||
measure && (isDiffMetric(measure.metric) ? getPeriodValue(measure, 1) : measure.value); | |||
measure && (isDiffMetric(measure.metric) ? measure.period?.value : measure.value); | |||
const isFile = isFileType(baseComponent); | |||
const selectedIdx = this.getSelectedIndex(); | |||
@@ -123,7 +123,7 @@ export default class FilesView extends React.PureComponent<Props, State> { | |||
const { metric } = this.props; | |||
const focusedMeasure = component.measures.find(measure => measure.metric.key === metric.key); | |||
if (focusedMeasure && isDiffMetric(metric.key)) { | |||
return isPeriodBestValue(focusedMeasure, 1); | |||
return isPeriodBestValue(focusedMeasure); | |||
} | |||
return Boolean(focusedMeasure && focusedMeasure.bestValue); | |||
}; |
@@ -87,7 +87,7 @@ function shallowRender(props: Partial<DomainFacet['props']> = {}) { | |||
domain: 'Reliability' | |||
}, | |||
value: '5', | |||
periods: [{ index: 1, value: '5' }], | |||
period: { index: 1, value: '5' }, | |||
leak: '5' | |||
}, | |||
{ | |||
@@ -98,7 +98,7 @@ function shallowRender(props: Partial<DomainFacet['props']> = {}) { | |||
name: 'New Bugs', | |||
domain: 'Reliability' | |||
}, | |||
periods: [{ index: 1, value: '5' }], | |||
period: { index: 1, value: '5' }, | |||
leak: '5' | |||
} | |||
] |
@@ -30,7 +30,7 @@ const MEASURE = { | |||
domain: 'Reliability' | |||
}, | |||
value: '5', | |||
periods: [{ index: 1, value: '5' }], | |||
period: { index: 1, value: '5' }, | |||
leak: '5' | |||
}; | |||
const LEAK_MEASURE = { | |||
@@ -41,7 +41,7 @@ const LEAK_MEASURE = { | |||
name: 'New Bugs', | |||
domain: 'Reliability' | |||
}, | |||
periods: [{ index: 1, value: '5' }], | |||
period: { index: 1, value: '5' }, | |||
leak: '5' | |||
}; | |||
@@ -47,7 +47,7 @@ function shallowRender(props = {}) { | |||
domain: 'Coverage' | |||
}, | |||
value: '431', | |||
periods: [{ index: 1, value: '70' }], | |||
period: { index: 1, value: '70' }, | |||
leak: '70' | |||
}, | |||
{ | |||
@@ -59,7 +59,7 @@ function shallowRender(props = {}) { | |||
domain: 'Coverage' | |||
}, | |||
value: '99.3', | |||
periods: [{ index: 1, value: '0.0999999999999943' }], | |||
period: { index: 1, value: '0.0999999999999943' }, | |||
leak: '0.0999999999999943' | |||
}, | |||
{ | |||
@@ -71,7 +71,7 @@ function shallowRender(props = {}) { | |||
domain: 'Duplications' | |||
}, | |||
value: '3.2', | |||
periods: [{ index: 1, value: '0.0' }], | |||
period: { index: 1, value: '0.0' }, | |||
leak: '0.0' | |||
} | |||
]} |
@@ -71,12 +71,10 @@ exports[`should display facet item list 1`] = ` | |||
"name": "New Bugs", | |||
"type": "INT", | |||
}, | |||
"periods": Array [ | |||
Object { | |||
"index": 1, | |||
"value": "5", | |||
}, | |||
], | |||
"period": Object { | |||
"index": 1, | |||
"value": "5", | |||
}, | |||
} | |||
} | |||
/> | |||
@@ -122,12 +120,10 @@ exports[`should display facet item list 1`] = ` | |||
"name": "Bugs", | |||
"type": "INT", | |||
}, | |||
"periods": Array [ | |||
Object { | |||
"index": 1, | |||
"value": "5", | |||
}, | |||
], | |||
"period": Object { | |||
"index": 1, | |||
"value": "5", | |||
}, | |||
"value": "5", | |||
} | |||
} | |||
@@ -215,12 +211,10 @@ exports[`should display facet item list with bugs selected 1`] = ` | |||
"name": "New Bugs", | |||
"type": "INT", | |||
}, | |||
"periods": Array [ | |||
Object { | |||
"index": 1, | |||
"value": "5", | |||
}, | |||
], | |||
"period": Object { | |||
"index": 1, | |||
"value": "5", | |||
}, | |||
} | |||
} | |||
/> | |||
@@ -266,12 +260,10 @@ exports[`should display facet item list with bugs selected 1`] = ` | |||
"name": "Bugs", | |||
"type": "INT", | |||
}, | |||
"periods": Array [ | |||
Object { | |||
"index": 1, | |||
"value": "5", | |||
}, | |||
], | |||
"period": Object { | |||
"index": 1, | |||
"value": "5", | |||
}, | |||
"value": "5", | |||
} | |||
} |
@@ -25,12 +25,10 @@ exports[`should display two facets 1`] = ` | |||
"name": "Lines to Cover", | |||
"type": "INT", | |||
}, | |||
"periods": Array [ | |||
Object { | |||
"index": 1, | |||
"value": "70", | |||
}, | |||
], | |||
"period": Object { | |||
"index": 1, | |||
"value": "70", | |||
}, | |||
"value": "431", | |||
}, | |||
Object { | |||
@@ -42,12 +40,10 @@ exports[`should display two facets 1`] = ` | |||
"name": "Coverage", | |||
"type": "PERCENT", | |||
}, | |||
"periods": Array [ | |||
Object { | |||
"index": 1, | |||
"value": "0.0999999999999943", | |||
}, | |||
], | |||
"period": Object { | |||
"index": 1, | |||
"value": "0.0999999999999943", | |||
}, | |||
"value": "99.3", | |||
}, | |||
], | |||
@@ -74,12 +70,10 @@ exports[`should display two facets 1`] = ` | |||
"name": "Duplicated Lines (%)", | |||
"type": "PERCENT", | |||
}, | |||
"periods": Array [ | |||
Object { | |||
"index": 1, | |||
"value": "0.0", | |||
}, | |||
], | |||
"period": Object { | |||
"index": 1, | |||
"value": "0.0", | |||
}, | |||
"value": "3.2", | |||
}, | |||
], |
@@ -67,7 +67,7 @@ jest.mock('../../../../api/measures', () => { | |||
measures.push( | |||
mockMeasure({ | |||
metric: key, | |||
...(isDiffMetric(key) ? { leak: '1' } : { periods: undefined }) | |||
...(isDiffMetric(key) ? { leak: '1' } : { period: undefined }) | |||
}) | |||
); | |||
}); |
@@ -69,13 +69,11 @@ exports[`should render correctly 1`] = ` | |||
}, | |||
], | |||
"metric": "bugs", | |||
"periods": Array [ | |||
Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
], | |||
"period": Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
"value": "1.0", | |||
}, | |||
] | |||
@@ -241,13 +239,11 @@ exports[`should render correctly 2`] = ` | |||
}, | |||
], | |||
"metric": "bugs", | |||
"periods": Array [ | |||
Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
], | |||
"period": Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
"value": "1.0", | |||
}, | |||
] |
@@ -93,13 +93,11 @@ exports[`should render correctly 1`] = ` | |||
"name": "Coverage", | |||
"type": "PERCENT", | |||
}, | |||
"periods": Array [ | |||
Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
], | |||
"period": Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
"value": "1.0", | |||
}, | |||
] | |||
@@ -203,13 +201,11 @@ exports[`should render correctly 2`] = ` | |||
"name": "Coverage", | |||
"type": "PERCENT", | |||
}, | |||
"periods": Array [ | |||
Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
], | |||
"period": Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
"value": "1.0", | |||
}, | |||
] | |||
@@ -312,13 +308,11 @@ exports[`should render correctly 3`] = ` | |||
"name": "Coverage", | |||
"type": "PERCENT", | |||
}, | |||
"periods": Array [ | |||
Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
], | |||
"period": Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
"value": "1.0", | |||
}, | |||
] |
@@ -76,13 +76,11 @@ exports[`should render correctly for applications 1`] = ` | |||
"name": "Coverage", | |||
"type": "PERCENT", | |||
}, | |||
"periods": Array [ | |||
Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
], | |||
"period": Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
"value": "1.0", | |||
}, | |||
"metric": "foo", | |||
@@ -137,13 +135,11 @@ exports[`should render correctly for applications 1`] = ` | |||
"name": "Coverage", | |||
"type": "PERCENT", | |||
}, | |||
"periods": Array [ | |||
Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
], | |||
"period": Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
"value": "1.0", | |||
}, | |||
"metric": "foo", | |||
@@ -162,13 +158,11 @@ exports[`should render correctly for applications 1`] = ` | |||
"name": "New_code_smells", | |||
"type": "PERCENT", | |||
}, | |||
"periods": Array [ | |||
Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
], | |||
"period": Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
"value": "1.0", | |||
}, | |||
"metric": "new_code_smells", | |||
@@ -263,13 +257,11 @@ exports[`should render correctly for applications 2`] = ` | |||
"name": "Coverage", | |||
"type": "PERCENT", | |||
}, | |||
"periods": Array [ | |||
Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
], | |||
"period": Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
"value": "1.0", | |||
}, | |||
"metric": "foo", | |||
@@ -399,13 +391,11 @@ exports[`should render correctly for projects 1`] = ` | |||
"name": "Coverage", | |||
"type": "PERCENT", | |||
}, | |||
"periods": Array [ | |||
Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
], | |||
"period": Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
"value": "1.0", | |||
}, | |||
"metric": "foo", | |||
@@ -551,13 +541,11 @@ exports[`should render correctly for projects 3`] = ` | |||
"name": "Coverage", | |||
"type": "PERCENT", | |||
}, | |||
"periods": Array [ | |||
Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
], | |||
"period": Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
"value": "1.0", | |||
}, | |||
"metric": "foo", |
@@ -26,13 +26,11 @@ exports[`should render correctly 1`] = ` | |||
"name": "Coverage", | |||
"type": "PERCENT", | |||
}, | |||
"periods": Array [ | |||
Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
], | |||
"period": Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
"value": "1.0", | |||
}, | |||
"metric": "bugs", | |||
@@ -51,13 +49,11 @@ exports[`should render correctly 1`] = ` | |||
"name": "Coverage", | |||
"type": "PERCENT", | |||
}, | |||
"periods": Array [ | |||
Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
], | |||
"period": Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
"value": "1.0", | |||
}, | |||
"metric": "new_bugs", | |||
@@ -85,13 +81,11 @@ exports[`should render correctly 1`] = ` | |||
"name": "Coverage", | |||
"type": "PERCENT", | |||
}, | |||
"periods": Array [ | |||
Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
], | |||
"period": Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
"value": "1.0", | |||
}, | |||
"metric": "new_bugs", | |||
@@ -122,13 +116,11 @@ exports[`should render correctly 1`] = ` | |||
"name": "Coverage", | |||
"type": "PERCENT", | |||
}, | |||
"periods": Array [ | |||
Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
], | |||
"period": Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
"value": "1.0", | |||
}, | |||
"metric": "bugs", | |||
@@ -147,13 +139,11 @@ exports[`should render correctly 1`] = ` | |||
"name": "Coverage", | |||
"type": "PERCENT", | |||
}, | |||
"periods": Array [ | |||
Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
], | |||
"period": Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
"value": "1.0", | |||
}, | |||
"metric": "new_bugs", | |||
@@ -181,13 +171,11 @@ exports[`should render correctly 1`] = ` | |||
"name": "Coverage", | |||
"type": "PERCENT", | |||
}, | |||
"periods": Array [ | |||
Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
], | |||
"period": Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
"value": "1.0", | |||
}, | |||
"metric": "bugs", | |||
@@ -230,13 +218,11 @@ exports[`should render correctly 2`] = ` | |||
"name": "Coverage", | |||
"type": "PERCENT", | |||
}, | |||
"periods": Array [ | |||
Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
], | |||
"period": Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
"value": "1.0", | |||
}, | |||
"metric": "bugs", | |||
@@ -255,13 +241,11 @@ exports[`should render correctly 2`] = ` | |||
"name": "Coverage", | |||
"type": "PERCENT", | |||
}, | |||
"periods": Array [ | |||
Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
], | |||
"period": Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
"value": "1.0", | |||
}, | |||
"metric": "new_bugs", | |||
@@ -289,13 +273,11 @@ exports[`should render correctly 2`] = ` | |||
"name": "Coverage", | |||
"type": "PERCENT", | |||
}, | |||
"periods": Array [ | |||
Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
], | |||
"period": Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
"value": "1.0", | |||
}, | |||
"metric": "new_bugs", | |||
@@ -326,13 +308,11 @@ exports[`should render correctly 2`] = ` | |||
"name": "Coverage", | |||
"type": "PERCENT", | |||
}, | |||
"periods": Array [ | |||
Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
], | |||
"period": Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
"value": "1.0", | |||
}, | |||
"metric": "bugs", | |||
@@ -351,13 +331,11 @@ exports[`should render correctly 2`] = ` | |||
"name": "Coverage", | |||
"type": "PERCENT", | |||
}, | |||
"periods": Array [ | |||
Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
], | |||
"period": Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
"value": "1.0", | |||
}, | |||
"metric": "new_bugs", | |||
@@ -385,13 +363,11 @@ exports[`should render correctly 2`] = ` | |||
"name": "Coverage", | |||
"type": "PERCENT", | |||
}, | |||
"periods": Array [ | |||
Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
], | |||
"period": Object { | |||
"bestValue": true, | |||
"index": 1, | |||
"value": "1.0", | |||
}, | |||
"value": "1.0", | |||
}, | |||
"metric": "bugs", |
@@ -26,7 +26,7 @@ import { formatMeasure } from 'sonar-ui-common/helpers/measures'; | |||
import Measure from '../../../components/measure/Measure'; | |||
import DrilldownLink from '../../../components/shared/DrilldownLink'; | |||
import { getBranchLikeQuery } from '../../../helpers/branch-like'; | |||
import { getPeriodValue, isDiffMetric } from '../../../helpers/measures'; | |||
import { isDiffMetric } from '../../../helpers/measures'; | |||
import { getComponentIssuesUrl } from '../../../helpers/urls'; | |||
import { BranchLike } from '../../../types/branch-like'; | |||
import { QualityGateStatusConditionEnhanced } from '../../../types/quality-gates'; | |||
@@ -120,9 +120,7 @@ export default class QualityGateCondition extends React.PureComponent<Props> { | |||
const isDiff = isDiffMetric(metric.key); | |||
const threshold = (condition.level === 'ERROR' ? condition.error : condition.warning) as string; | |||
const actual = (condition.period | |||
? getPeriodValue(measure, condition.period) | |||
: measure.value) as string; | |||
const actual = (condition.period ? measure.period?.value : measure.value) as string; | |||
let operator = translate('quality_gates.operator', condition.op); | |||
@@ -102,7 +102,7 @@ function quickMock( | |||
type | |||
}), | |||
value: '3', | |||
...(addPeriod ? { periods: [{ value: '3', index: 1 }] } : {}) | |||
...(addPeriod ? { period: { value: '3', index: 1 } } : {}) | |||
}, | |||
metric, | |||
...(addPeriod ? { period: 1 } : {}) |
@@ -27,7 +27,7 @@ jest.mock('../../../api/components', () => ({ | |||
jest.mock('../../../api/measures', () => ({ | |||
getMeasuresForProjects: jest.fn().mockResolvedValue([ | |||
{ component: 'foo', metric: 'new_coverage', periods: [{ index: 1, value: '10' }] }, | |||
{ component: 'foo', metric: 'new_coverage', period: { index: 1, value: '10' } }, | |||
{ component: 'bar', metric: 'languages', value: '20' } | |||
]) | |||
})); |
@@ -23,7 +23,7 @@ import { RequestData } from 'sonar-ui-common/helpers/request'; | |||
import { Facet, searchProjects } from '../../api/components'; | |||
import { getMeasuresForProjects } from '../../api/measures'; | |||
import { getOrganizations } from '../../api/organizations'; | |||
import { getPeriodValue, isDiffMetric } from '../../helpers/measures'; | |||
import { isDiffMetric } from '../../helpers/measures'; | |||
import { MetricKey } from '../../types/metrics'; | |||
import { convertToFilter, Query } from './query'; | |||
@@ -225,9 +225,7 @@ export function fetchProjects( | |||
measures | |||
.filter(measure => measure.component === component.key) | |||
.forEach(measure => { | |||
const value = isDiffMetric(measure.metric) | |||
? getPeriodValue(measure, 1) | |||
: measure.value; | |||
const value = isDiffMetric(measure.metric) ? measure.period?.value : measure.value; | |||
if (value !== undefined) { | |||
componentMeasures[measure.metric] = value; | |||
} |
@@ -18,7 +18,6 @@ | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
import { getRatingTooltip as nextGetRatingTooltip, isDiffMetric } from '../../helpers/measures'; | |||
import { getLeakPeriod } from '../../helpers/periods'; | |||
const KNOWN_RATINGS = [ | |||
'sqale_rating', | |||
@@ -37,11 +36,7 @@ export function enhanceMeasure(measure: T.Measure, metrics: T.Dict<T.Metric>): T | |||
} | |||
export function getLeakValue(measure: T.MeasureIntern | undefined): string | undefined { | |||
if (!measure || !measure.periods) { | |||
return undefined; | |||
} | |||
const period = getLeakPeriod(measure.periods); | |||
return period && period.value; | |||
return measure?.period?.value; | |||
} | |||
export function getRatingTooltip(metricKey: string, value: number): string | undefined { |
@@ -17,14 +17,14 @@ | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
import { enhanceConditionWithMeasure } from '../measures'; | |||
import { enhanceConditionWithMeasure, isPeriodBestValue } from '../measures'; | |||
import { mockQualityGateStatusCondition } from '../mocks/quality-gates'; | |||
import { mockMeasureEnhanced, mockMetric } from '../testMocks'; | |||
describe('enhanceConditionWithMeasure', () => { | |||
it('should correctly map enhance conditions with measure data', () => { | |||
const measures = [ | |||
mockMeasureEnhanced({ metric: mockMetric({ key: 'bugs' }), periods: undefined }), | |||
mockMeasureEnhanced({ metric: mockMetric({ key: 'bugs' }), period: undefined }), | |||
mockMeasureEnhanced({ metric: mockMetric({ key: 'new_bugs' }) }) | |||
]; | |||
@@ -48,3 +48,19 @@ describe('enhanceConditionWithMeasure', () => { | |||
expect(enhanceConditionWithMeasure(mockQualityGateStatusCondition(), [])).toBeUndefined(); | |||
}); | |||
}); | |||
describe('isPeriodBestValue', () => { | |||
it('should work as expected', () => { | |||
expect(isPeriodBestValue(mockMeasureEnhanced({ period: undefined }))).toBe(false); | |||
expect( | |||
isPeriodBestValue( | |||
mockMeasureEnhanced({ period: { index: 1, value: '1.0', bestValue: false } }) | |||
) | |||
).toBe(false); | |||
expect( | |||
isPeriodBestValue( | |||
mockMeasureEnhanced({ period: { index: 1, value: '1.0', bestValue: true } }) | |||
) | |||
).toBe(true); | |||
}); | |||
}); |
@@ -62,30 +62,15 @@ export function enhanceConditionWithMeasure( | |||
// Make sure we have a period index. This is necessary when dealing with | |||
// applications. | |||
let { period } = condition; | |||
if (measure && measure.periods && !period) { | |||
period = measure.periods[0].index; | |||
if (measure && measure.period && !period) { | |||
period = measure.period.index; | |||
} | |||
return measure && { ...condition, period, measure }; | |||
} | |||
/** Get period value of a measure */ | |||
export function getPeriodValue( | |||
measure: T.Measure | T.MeasureEnhanced, | |||
periodIndex: number | |||
): string | undefined { | |||
const { periods } = measure; | |||
const period = periods && periods.find(period => period.index === periodIndex); | |||
return period ? period.value : undefined; | |||
} | |||
export function isPeriodBestValue( | |||
measure: T.Measure | T.MeasureEnhanced, | |||
periodIndex: number | |||
): boolean { | |||
const { periods } = measure; | |||
const period = periods && periods.find(period => period.index === periodIndex); | |||
return (period && period.bestValue) || false; | |||
export function isPeriodBestValue(measure: T.Measure | T.MeasureEnhanced): boolean { | |||
return measure.period?.bestValue || false; | |||
} | |||
/** Check if metric is differential */ |
@@ -21,17 +21,6 @@ import { parseDate } from 'sonar-ui-common/helpers/dates'; | |||
import { translate, translateWithParameters } from 'sonar-ui-common/helpers/l10n'; | |||
import { ApplicationPeriod } from '../types/application'; | |||
function getPeriod<T extends T.Period | T.PeriodMeasure>(periods: T[] | undefined, index: number) { | |||
if (!Array.isArray(periods)) { | |||
return undefined; | |||
} | |||
return periods.find(period => period.index === index); | |||
} | |||
export function getLeakPeriod<T extends T.Period | T.PeriodMeasure>(periods: T[] | undefined) { | |||
return getPeriod(periods, 1); | |||
} | |||
export function getPeriodLabel( | |||
period: T.Period | undefined, | |||
dateFormatter: (date: string) => string |
@@ -470,13 +470,11 @@ export function mockMeasure(overrides: Partial<T.Measure> = {}): T.Measure { | |||
return { | |||
bestValue: true, | |||
metric: 'bugs', | |||
periods: [ | |||
{ | |||
bestValue: true, | |||
index: 1, | |||
value: '1.0' | |||
} | |||
], | |||
period: { | |||
bestValue: true, | |||
index: 1, | |||
value: '1.0' | |||
}, | |||
value: '1.0', | |||
...overrides | |||
}; | |||
@@ -487,13 +485,11 @@ export function mockMeasureEnhanced(overrides: Partial<T.MeasureEnhanced> = {}): | |||
bestValue: true, | |||
leak: '1', | |||
metric: mockMetric({ ...(overrides.metric || {}) }), | |||
periods: [ | |||
{ | |||
bestValue: true, | |||
index: 1, | |||
value: '1.0' | |||
} | |||
], | |||
period: { | |||
bestValue: true, | |||
index: 1, | |||
value: '1.0' | |||
}, | |||
value: '1.0', | |||
...overrides | |||
}; |
@@ -0,0 +1,35 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2020 SonarSource SA | |||
* mailto:info AT sonarsource DOT com | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
export interface MeasuresForProjects { | |||
component: string; | |||
metric: string; | |||
period?: T.PeriodMeasure; | |||
value?: string; | |||
} | |||
export interface MeasuresAndMetaWithMetrics { | |||
component: T.ComponentMeasure; | |||
metrics: T.Metric[]; | |||
} | |||
export interface MeasuresAndMetaWithPeriod { | |||
component: T.ComponentMeasure; | |||
period: T.Period; | |||
} |
@@ -452,7 +452,7 @@ declare namespace T { | |||
interface MeasureIntern { | |||
bestValue?: boolean; | |||
periods?: PeriodMeasure[]; | |||
period?: PeriodMeasure; | |||
value?: string; | |||
} | |||