aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Davis <jeremy.davis@sonarsource.com>2022-11-24 11:49:01 +0800
committersonartech <sonartech@sonarsource.com>2022-11-24 20:02:50 +0000
commit27c3b0ea8319fd621fa7130d3cf466f73f1bab7b (patch)
tree654fd8771a590ce0b0127fcc6518e91ce0a0f1a0
parent328840a47701c59977549ed01ce8adec11633a40 (diff)
downloadsonarqube-27c3b0ea8319fd621fa7130d3cf466f73f1bab7b.tar.gz
sonarqube-27c3b0ea8319fd621fa7130d3cf466f73f1bab7b.zip
SONAR-17644 Fix snippet expansion
-rw-r--r--server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/ComponentSourceSnippetGroupViewer.tsx12
-rw-r--r--server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/__tests__/ComponentSourceSnippetGroupViewer-test.tsx7
2 files changed, 10 insertions, 9 deletions
diff --git a/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/ComponentSourceSnippetGroupViewer.tsx b/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/ComponentSourceSnippetGroupViewer.tsx
index f1b755af332..55e00c1fd61 100644
--- a/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/ComponentSourceSnippetGroupViewer.tsx
+++ b/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/ComponentSourceSnippetGroupViewer.tsx
@@ -106,13 +106,17 @@ export default class ComponentSourceSnippetGroupViewer extends React.PureCompone
createSnippetsFromProps() {
const { issue, snippetGroup } = this.props;
+ const locations = [...snippetGroup.locations];
+
+ // Add primary location if the component matches
+ if (issue.component === snippetGroup.component.key) {
+ locations.unshift(getPrimaryLocation(issue));
+ }
+
const snippets = createSnippets({
component: snippetGroup.component.key,
issue,
- locations:
- snippetGroup.locations.length === 0
- ? [getPrimaryLocation(issue)]
- : [getPrimaryLocation(issue), ...snippetGroup.locations],
+ locations,
});
this.setState({ snippets });
diff --git a/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/__tests__/ComponentSourceSnippetGroupViewer-test.tsx b/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/__tests__/ComponentSourceSnippetGroupViewer-test.tsx
index 457fc4d9a46..c7f3e5ce0a9 100644
--- a/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/__tests__/ComponentSourceSnippetGroupViewer-test.tsx
+++ b/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/__tests__/ComponentSourceSnippetGroupViewer-test.tsx
@@ -244,10 +244,7 @@ it('should expand full component', async () => {
it('should get the right branch when expanding', async () => {
(getSources as jest.Mock).mockResolvedValueOnce(
- Object.values(
- mockSnippetsByComponent('a', 'project', [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17])
- .sources
- )
+ Object.values(mockSnippetsByComponent('a', 'project', range(8, 67)).sources)
);
const snippetGroup: SnippetGroup = {
locations: [mockFlowLocation()],
@@ -262,7 +259,7 @@ it('should get the right branch when expanding', async () => {
wrapper.instance().expandBlock(0, 'down');
await waitAndUpdate(wrapper);
- expect(getSources).toHaveBeenCalledWith({ branch: 'asdf', from: 36, key: 'project:a', to: 95 });
+ expect(getSources).toHaveBeenCalledWith({ branch: 'asdf', from: 8, key: 'project:a', to: 67 });
});
it('should handle symbol highlighting', () => {