|
1 | 1 | import React from "react";
|
2 | 2 | import "./MetricsSummaryTab.css";
|
3 | 3 | import MetricsSummaryPanel from '../MetricsSummaryPanel';
|
| 4 | +import {findMetricsSummaryMeasures} from '../../api.js'; |
| 5 | +import {getJSON} from 'sonar-request'; |
| 6 | + |
| 7 | +const NESTING = 0; |
| 8 | +const RATIO_COMMENT = 1; |
| 9 | +const COMPLEXITY_SIMPLIFIED = 2; |
| 10 | +const LOC = 3; |
| 11 | + |
| 12 | +const metricKeysTabF77 = [ |
| 13 | + 'icode-f77-nesting-min', |
| 14 | + 'icode-f77-nesting-mean', |
| 15 | + 'icode-f77-nesting-max', |
| 16 | + 'icode-f77-ratio-comment-min', |
| 17 | + 'icode-f77-ratio-comment-mean', |
| 18 | + 'icode-f77-ratio-comment-max', |
| 19 | + 'icode-f77-cyclomatic-complexity-min', |
| 20 | + 'icode-f77-cyclomatic-complexity-mean', |
| 21 | + 'icode-f77-cyclomatic-complexity-max', |
| 22 | + 'icode-f77-loc', |
| 23 | + 'icode-f77-loc-min', |
| 24 | + 'icode-f77-loc-mean', |
| 25 | + 'icode-f77-loc-max']; |
| 26 | + |
| 27 | +const metricKeysTabF90 = [ |
| 28 | + 'icode-f90-nesting-min', |
| 29 | + 'icode-f90-nesting-mean', |
| 30 | + 'icode-f90-nesting-max', |
| 31 | + 'icode-f90-ratio-comment-min', |
| 32 | + 'icode-f90-ratio-comment-mean', |
| 33 | + 'icode-f90-ratio-comment-max', |
| 34 | + 'icode-f90-cyclomatic-complexity-min', |
| 35 | + 'icode-f90-cyclomatic-complexity-mean', |
| 36 | + 'icode-f90-cyclomatic-complexity-max', |
| 37 | + 'icode-f90-loc', |
| 38 | + 'icode-f90-loc-min', |
| 39 | + 'icode-f90-loc-mean', |
| 40 | + 'icode-f90-loc-max']; |
| 41 | + |
| 42 | +const metricKeysTabSH = [ |
| 43 | + 'icode-shell-nesting-min', |
| 44 | + 'icode-shell-nesting-mean', |
| 45 | + 'icode-shell-nesting-max', |
| 46 | + 'icode-shell-ratio-comment-min', |
| 47 | + 'icode-shell-ratio-comment-mean', |
| 48 | + 'icode-shell-ratio-comment-max', |
| 49 | + 'icode-shell-cyclomatic-complexity-min', |
| 50 | + 'icode-shell-cyclomatic-complexity-mean', |
| 51 | + 'icode-shell-cyclomatic-complexity-max', |
| 52 | + 'icode-shell-loc', |
| 53 | + 'icode-shell-loc-min', |
| 54 | + 'icode-shell-loc-mean', |
| 55 | + 'icode-shell-loc-max']; |
| 56 | + |
| 57 | +function findMeasuresF77(componentName) { |
| 58 | + return new Promise(function(resolve, reject) { |
| 59 | + |
| 60 | + let metricKeys = metricKeysTabF77.reduce((accumulator, currentValue) => accumulator + ',' + currentValue); |
| 61 | + |
| 62 | + let measure_component = getJSON('/api/measures/component', { |
| 63 | + metricKeys:metricKeys, |
| 64 | + component:componentName |
| 65 | + }).then(function (measure_component) { |
| 66 | + console.log(measure_component); |
| 67 | + |
| 68 | + // Build map 'metric:value' |
| 69 | + let allMetrics = new Map(); |
| 70 | + measure_component.component.measures.forEach(element => { |
| 71 | + for (let index = 0; index < metricKeysTabF77.length; index++) { |
| 72 | + const key = metricKeysTabF77[index]; |
| 73 | + if(element.metric === key){ |
| 74 | + allMetrics.set(element.metric, element.value); |
| 75 | + } |
| 76 | + } |
| 77 | + }); |
| 78 | + console.log(allMetrics); |
| 79 | + |
| 80 | + // Build result table |
| 81 | + let res=[ |
| 82 | + {name:'Nesting', |
| 83 | + total: '-', |
| 84 | + min: allMetrics.get('icode-f77-nesting-min'), |
| 85 | + mean: allMetrics.get('icode-f77-nesting-mean'), |
| 86 | + max: allMetrics.get('icode-f77-nesting-max') |
| 87 | + }, |
| 88 | + {name:'Ratio Comment', |
| 89 | + total: '-', |
| 90 | + min: allMetrics.get('icode-f77-ratio-comment-min'), |
| 91 | + mean: allMetrics.get('icode-f77-ratio-comment-mean'), |
| 92 | + max: allMetrics.get('icode-f77-ratio-comment-max') |
| 93 | + }, |
| 94 | + {name:'Complexity Simplified', |
| 95 | + total: '-', |
| 96 | + min: allMetrics.get('icode-f77-cyclomatic-complexity-min'), |
| 97 | + mean: allMetrics.get('icode-f77-cyclomatic-complexity-mean'), |
| 98 | + max: allMetrics.get('icode-f77-cyclomatic-complexity-max') |
| 99 | + }, |
| 100 | + {name:'Line Of Code', |
| 101 | + total: allMetrics.get('icode-f77-loc'), |
| 102 | + min: allMetrics.get('icode-f77-loc-min'), |
| 103 | + mean: allMetrics.get('icode-f77-loc-mean'), |
| 104 | + max: allMetrics.get('icode-f77-loc-max') |
| 105 | + } |
| 106 | + ]; |
| 107 | + console.log(res); |
| 108 | + |
| 109 | + resolve(res); |
| 110 | + }).catch(function(error) { |
| 111 | + console.log('No measures found: ' + error.message); |
| 112 | + reject(null); |
| 113 | + }); |
| 114 | +}); |
| 115 | +} |
4 | 116 |
|
5 | 117 | class MetricsSummaryTab extends React.Component {
|
6 | 118 |
|
7 | 119 | state = {
|
8 | 120 | dataF77: [],
|
9 | 121 | dataF90: [],
|
10 |
| - dataSH: [] |
| 122 | + dataSH: [], |
| 123 | + data:[] |
11 | 124 | };
|
12 | 125 |
|
13 | 126 | componentDidMount() {
|
| 127 | + |
| 128 | + findMeasuresF77(this.props.project.key).then((item) => { |
| 129 | + this.setState({ |
| 130 | + dataF77: item |
| 131 | + }); |
| 132 | + }); |
14 | 133 |
|
15 | 134 | this.setState({
|
16 |
| - dataF77: [ |
| 135 | +/* dataF77: [ |
17 | 136 | { name: 'Nesting', total: '-', min: 5, mean: 5.2, max: 6 },
|
18 | 137 | { name: 'Ratio Comment', total: '-', min: 18.6, mean: 29.8, max: 38.9 },
|
19 | 138 | { name: 'Complexity Simplified', total: '-', min: 26, mean: 33.6, max: 58 },
|
20 | 139 | { name: 'Line Of Code', total: 601, min: 101, mean: 110.2, max: 182 }
|
21 |
| - ], |
| 140 | + ],*/ |
22 | 141 | dataF90: [
|
23 | 142 | { name: 'Nesting', total: '-', min: '-', mean: '-', max: '-' },
|
24 | 143 | { name: 'Ratio Comment', total: '-', min: '-', mean: '-', max: '-' },
|
|
0 commit comments