aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web
diff options
context:
space:
mode:
authorWouter Admiraal <wouter.admiraal@sonarsource.com>2019-04-09 11:45:50 +0200
committerSonarTech <sonartech@sonarsource.com>2019-04-23 20:21:10 +0200
commit1ba4c3bf9883421bca6fe6914a41462f9694e7fb (patch)
tree7a351bf997e4c5ad2212cf4b687c29ad37d6d95e /server/sonar-web
parent3ed7499cf33e511b8040dcd3b727f821b3d2f968 (diff)
downloadsonarqube-1ba4c3bf9883421bca6fe6914a41462f9694e7fb.tar.gz
sonarqube-1ba4c3bf9883421bca6fe6914a41462f9694e7fb.zip
SONAR-11944 Add security hotspots to Code page
Diffstat (limited to 'server/sonar-web')
-rw-r--r--server/sonar-web/src/main/js/apps/code/code.css3
-rw-r--r--server/sonar-web/src/main/js/apps/code/components/Components.tsx14
-rw-r--r--server/sonar-web/src/main/js/apps/code/components/__tests__/Component-test.tsx46
-rw-r--r--server/sonar-web/src/main/js/apps/code/components/__tests__/Components-test.tsx2
-rw-r--r--server/sonar-web/src/main/js/apps/code/components/__tests__/__snapshots__/Component-test.tsx.snap259
-rw-r--r--server/sonar-web/src/main/js/apps/code/components/__tests__/__snapshots__/Components-test.tsx.snap37
-rw-r--r--server/sonar-web/src/main/js/apps/code/utils.ts2
7 files changed, 325 insertions, 38 deletions
diff --git a/server/sonar-web/src/main/js/apps/code/code.css b/server/sonar-web/src/main/js/apps/code/code.css
index 26d6476f235..e9edb5007df 100644
--- a/server/sonar-web/src/main/js/apps/code/code.css
+++ b/server/sonar-web/src/main/js/apps/code/code.css
@@ -56,8 +56,7 @@
}
.code-components-cell {
- min-width: 80px;
- padding-left: 30px !important;
+ padding-left: calc(2 * var(--gridSize)) !important;
box-sizing: border-box;
}
diff --git a/server/sonar-web/src/main/js/apps/code/components/Components.tsx b/server/sonar-web/src/main/js/apps/code/components/Components.tsx
index b83e015aae5..171e36b9464 100644
--- a/server/sonar-web/src/main/js/apps/code/components/Components.tsx
+++ b/server/sonar-web/src/main/js/apps/code/components/Components.tsx
@@ -18,12 +18,12 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import * as React from 'react';
+import { intersection } from 'lodash';
import Component from './Component';
import ComponentsEmpty from './ComponentsEmpty';
import ComponentsHeader from './ComponentsHeader';
import withKeyboardNavigation from '../../../components/hoc/withKeyboardNavigation';
import { getCodeMetrics } from '../utils';
-import { isDefined } from '../../../helpers/types';
interface Props {
baseComponent?: T.ComponentMeasure;
@@ -37,8 +37,12 @@ interface Props {
export class Components extends React.PureComponent<Props> {
render() {
const { baseComponent, branchLike, components, rootComponent, selected } = this.props;
- const metricKeys = getCodeMetrics(rootComponent.qualifier, branchLike);
- const metrics = metricKeys.map(metric => this.props.metrics[metric]).filter(isDefined);
+ const metricKeys = intersection(
+ getCodeMetrics(rootComponent.qualifier, branchLike),
+ Object.keys(this.props.metrics)
+ );
+ const metrics = metricKeys.map(metric => this.props.metrics[metric]);
+ const colSpan = metrics.length + 4;
return (
<table className="data boxed-padding zebra">
{baseComponent && (
@@ -59,7 +63,7 @@ export class Components extends React.PureComponent<Props> {
/>
<tr className="blank">
<td colSpan={3}>&nbsp;</td>
- <td colSpan={10}>&nbsp;</td>
+ <td colSpan={colSpan}>&nbsp;</td>
</tr>
</tbody>
)}
@@ -83,7 +87,7 @@ export class Components extends React.PureComponent<Props> {
<tr className="blank">
<td colSpan={3} />
- <td colSpan={10} />
+ <td colSpan={colSpan} />
</tr>
</tbody>
</table>
diff --git a/server/sonar-web/src/main/js/apps/code/components/__tests__/Component-test.tsx b/server/sonar-web/src/main/js/apps/code/components/__tests__/Component-test.tsx
new file mode 100644
index 00000000000..222a2cd5f4d
--- /dev/null
+++ b/server/sonar-web/src/main/js/apps/code/components/__tests__/Component-test.tsx
@@ -0,0 +1,46 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 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.
+ */
+import * as React from 'react';
+import { shallow } from 'enzyme';
+import { Component } from '../Component';
+import { mockComponentMeasure, mockMetric } from '../../../../helpers/testMocks';
+
+it('should render correctly', () => {
+ expect(shallowRender()).toMatchSnapshot();
+});
+
+it('should render correctly for a file', () => {
+ expect(shallowRender({ component: mockComponentMeasure(true) })).toMatchSnapshot();
+});
+
+function shallowRender(props: Partial<Component['props']> = {}) {
+ return shallow(
+ <Component
+ component={mockComponentMeasure(false, {
+ key: 'bar',
+ name: 'Bar',
+ measures: [{ metric: 'bugs', value: '12' }, { metric: 'vulnerabilities', value: '1' }]
+ })}
+ metrics={[mockMetric({ key: 'bugs' }), mockMetric({ key: 'vulnerabilities' })]}
+ rootComponent={mockComponentMeasure()}
+ {...props}
+ />
+ );
+}
diff --git a/server/sonar-web/src/main/js/apps/code/components/__tests__/Components-test.tsx b/server/sonar-web/src/main/js/apps/code/components/__tests__/Components-test.tsx
index ab94ce89c03..324e4276002 100644
--- a/server/sonar-web/src/main/js/apps/code/components/__tests__/Components-test.tsx
+++ b/server/sonar-web/src/main/js/apps/code/components/__tests__/Components-test.tsx
@@ -46,7 +46,7 @@ it('renders correctly', () => {
it('renders correctly for a search', () => {
expect(
- shallow(<Components components={[COMPONENT]} metrics={METRICS} rootComponent={COMPONENT} />)
+ shallow(<Components components={[COMPONENT]} metrics={{}} rootComponent={COMPONENT} />)
).toMatchSnapshot();
});
diff --git a/server/sonar-web/src/main/js/apps/code/components/__tests__/__snapshots__/Component-test.tsx.snap b/server/sonar-web/src/main/js/apps/code/components/__tests__/__snapshots__/Component-test.tsx.snap
new file mode 100644
index 00000000000..d7a9a10ec89
--- /dev/null
+++ b/server/sonar-web/src/main/js/apps/code/components/__tests__/__snapshots__/Component-test.tsx.snap
@@ -0,0 +1,259 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`should render correctly 1`] = `
+<tr
+ className=""
+>
+ <td
+ className="blank"
+ />
+ <td
+ className="thin nowrap"
+ >
+ <span
+ className="spacer-right"
+ />
+ </td>
+ <td
+ className="code-name-cell"
+ >
+ <ComponentName
+ canBrowse={false}
+ component={
+ Object {
+ "key": "bar",
+ "measures": Array [
+ Object {
+ "metric": "bugs",
+ "value": "12",
+ },
+ Object {
+ "metric": "vulnerabilities",
+ "value": "1",
+ },
+ ],
+ "name": "Bar",
+ "qualifier": "TRK",
+ }
+ }
+ rootComponent={
+ Object {
+ "key": "foo",
+ "measures": Array [
+ Object {
+ "bestValue": false,
+ "metric": "bugs",
+ "value": "12",
+ },
+ ],
+ "name": "Foo",
+ "qualifier": "TRK",
+ }
+ }
+ />
+ </td>
+ <td
+ className="thin nowrap text-right"
+ key="bugs"
+ >
+ <div
+ className="code-components-cell"
+ >
+ <ComponentMeasure
+ component={
+ Object {
+ "key": "bar",
+ "measures": Array [
+ Object {
+ "metric": "bugs",
+ "value": "12",
+ },
+ Object {
+ "metric": "vulnerabilities",
+ "value": "1",
+ },
+ ],
+ "name": "Bar",
+ "qualifier": "TRK",
+ }
+ }
+ metric={
+ Object {
+ "id": "coverage",
+ "key": "bugs",
+ "name": "Coverage",
+ "type": "PERCENT",
+ }
+ }
+ />
+ </div>
+ </td>
+ <td
+ className="thin nowrap text-right"
+ key="vulnerabilities"
+ >
+ <div
+ className="code-components-cell"
+ >
+ <ComponentMeasure
+ component={
+ Object {
+ "key": "bar",
+ "measures": Array [
+ Object {
+ "metric": "bugs",
+ "value": "12",
+ },
+ Object {
+ "metric": "vulnerabilities",
+ "value": "1",
+ },
+ ],
+ "name": "Bar",
+ "qualifier": "TRK",
+ }
+ }
+ metric={
+ Object {
+ "id": "coverage",
+ "key": "vulnerabilities",
+ "name": "Coverage",
+ "type": "PERCENT",
+ }
+ }
+ />
+ </div>
+ </td>
+ <td
+ className="blank"
+ />
+</tr>
+`;
+
+exports[`should render correctly for a file 1`] = `
+<tr
+ className=""
+>
+ <td
+ className="blank"
+ />
+ <td
+ className="thin nowrap"
+ >
+ <span
+ className="spacer-right"
+ >
+ <ContextConsumer>
+ <Component />
+ </ContextConsumer>
+ </span>
+ </td>
+ <td
+ className="code-name-cell"
+ >
+ <ComponentName
+ canBrowse={false}
+ component={
+ Object {
+ "key": "foo:src/index.tsx",
+ "measures": Array [
+ Object {
+ "bestValue": false,
+ "metric": "bugs",
+ "value": "1",
+ },
+ ],
+ "name": "index.tsx",
+ "path": "src/index.tsx",
+ "qualifier": "FIL",
+ }
+ }
+ rootComponent={
+ Object {
+ "key": "foo",
+ "measures": Array [
+ Object {
+ "bestValue": false,
+ "metric": "bugs",
+ "value": "12",
+ },
+ ],
+ "name": "Foo",
+ "qualifier": "TRK",
+ }
+ }
+ />
+ </td>
+ <td
+ className="thin nowrap text-right"
+ key="bugs"
+ >
+ <div
+ className="code-components-cell"
+ >
+ <ComponentMeasure
+ component={
+ Object {
+ "key": "foo:src/index.tsx",
+ "measures": Array [
+ Object {
+ "bestValue": false,
+ "metric": "bugs",
+ "value": "1",
+ },
+ ],
+ "name": "index.tsx",
+ "path": "src/index.tsx",
+ "qualifier": "FIL",
+ }
+ }
+ metric={
+ Object {
+ "id": "coverage",
+ "key": "bugs",
+ "name": "Coverage",
+ "type": "PERCENT",
+ }
+ }
+ />
+ </div>
+ </td>
+ <td
+ className="thin nowrap text-right"
+ key="vulnerabilities"
+ >
+ <div
+ className="code-components-cell"
+ >
+ <ComponentMeasure
+ component={
+ Object {
+ "key": "foo:src/index.tsx",
+ "measures": Array [
+ Object {
+ "bestValue": false,
+ "metric": "bugs",
+ "value": "1",
+ },
+ ],
+ "name": "index.tsx",
+ "path": "src/index.tsx",
+ "qualifier": "FIL",
+ }
+ }
+ metric={
+ Object {
+ "id": "coverage",
+ "key": "vulnerabilities",
+ "name": "Coverage",
+ "type": "PERCENT",
+ }
+ }
+ />
+ </div>
+ </td>
+ <td
+ className="blank"
+ />
+</tr>
+`;
diff --git a/server/sonar-web/src/main/js/apps/code/components/__tests__/__snapshots__/Components-test.tsx.snap b/server/sonar-web/src/main/js/apps/code/components/__tests__/__snapshots__/Components-test.tsx.snap
index 6d8d7177b40..668294412ec 100644
--- a/server/sonar-web/src/main/js/apps/code/components/__tests__/__snapshots__/Components-test.tsx.snap
+++ b/server/sonar-web/src/main/js/apps/code/components/__tests__/__snapshots__/Components-test.tsx.snap
@@ -14,12 +14,7 @@ exports[`renders correctly 1`] = `
}
metrics={
Array [
- "ncloc",
- "bugs",
- "vulnerabilities",
- "code_smells",
"coverage",
- "duplicated_lines_density",
]
}
rootComponent={
@@ -67,7 +62,7 @@ exports[`renders correctly 1`] = `
 
</td>
<td
- colSpan={10}
+ colSpan={5}
>
 
</td>
@@ -109,7 +104,7 @@ exports[`renders correctly 1`] = `
colSpan={3}
/>
<td
- colSpan={10}
+ colSpan={5}
/>
</tr>
</tbody>
@@ -131,16 +126,7 @@ exports[`renders correctly for a search 1`] = `
}
}
key="foo"
- metrics={
- Array [
- Object {
- "id": "1",
- "key": "coverage",
- "name": "Coverage",
- "type": "PERCENT",
- },
- ]
- }
+ metrics={Array []}
rootComponent={
Object {
"key": "foo",
@@ -156,7 +142,7 @@ exports[`renders correctly for a search 1`] = `
colSpan={3}
/>
<td
- colSpan={10}
+ colSpan={4}
/>
</tr>
</tbody>
@@ -175,16 +161,7 @@ exports[`renders correctly for leak 1`] = `
"qualifier": "TRK",
}
}
- metrics={
- Array [
- "new_lines",
- "bugs",
- "vulnerabilities",
- "code_smells",
- "new_coverage",
- "new_duplicated_lines_density",
- ]
- }
+ metrics={Array []}
rootComponent={
Object {
"key": "foo",
@@ -229,7 +206,7 @@ exports[`renders correctly for leak 1`] = `
 
</td>
<td
- colSpan={10}
+ colSpan={4}
>
 
</td>
@@ -270,7 +247,7 @@ exports[`renders correctly for leak 1`] = `
colSpan={3}
/>
<td
- colSpan={10}
+ colSpan={4}
/>
</tr>
</tbody>
diff --git a/server/sonar-web/src/main/js/apps/code/utils.ts b/server/sonar-web/src/main/js/apps/code/utils.ts
index 98c1921c9e2..ceae7a7f157 100644
--- a/server/sonar-web/src/main/js/apps/code/utils.ts
+++ b/server/sonar-web/src/main/js/apps/code/utils.ts
@@ -33,6 +33,7 @@ const METRICS = [
'bugs',
'vulnerabilities',
'code_smells',
+ 'security_hotspots',
'coverage',
'duplicated_lines_density'
];
@@ -52,6 +53,7 @@ const LEAK_METRICS = [
'bugs',
'vulnerabilities',
'code_smells',
+ 'security_hotspots',
'new_coverage',
'new_duplicated_lines_density'
];