duplications?: T.Duplication[];
duplicationsByLine?: { [line: number]: number[] };
highlightedLocationMessage: { index: number; text: string | undefined } | undefined;
+ isLastOccurenceOfPrimaryComponent: boolean;
issue: T.Issue;
issuePopup?: { issue: string; name: string };
issuesByLine: T.IssuesByLine;
render() {
const {
branchLike,
+ isLastOccurenceOfPrimaryComponent,
issue,
issuesByLine,
issuePopup,
});
const isFlow = issue.secondaryLocations.length === 0;
- const includeIssueLocation = (snippetIndex: number) =>
- isFlow ? lastSnippetGroup && snippetIndex === snippets.length - 1 : snippetIndex === 0;
+ const includeIssueLocation = isFlow ? isLastOccurenceOfPrimaryComponent : true;
return (
<div className="component-source-container" ref={this.rootNodeRef}>
snippet,
index: snippets[index].index,
issuesByLine,
- locationsByLine: includeIssueLocation(index) ? locations : {},
+ locationsByLine: includeIssueLocation ? locations : {},
lastSnippetOfLastGroup: lastSnippetGroup && index === snippets.length - 1
})}
</div>
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+import { findLastIndex } from 'lodash';
import * as React from 'react';
import { Alert } from 'sonar-ui-common/components/ui/Alert';
import DeferredSpinner from 'sonar-ui-common/components/ui/DeferredSpinner';
const issuesByComponent = issuesByComponentAndLine(this.props.issues);
const locationsByComponent = groupLocationsByComponent(issue, locations, components);
+ const lastOccurenceOfPrimaryComponent = findLastIndex(
+ locationsByComponent,
+ ({ component }) => component.key === issue.component
+ );
+
return (
<div>
{locationsByComponent.map((snippetGroup, i) => {
issue={issue}
issuePopup={this.state.issuePopup}
issuesByLine={issuesByComponent[snippetGroup.component.key] || {}}
+ isLastOccurenceOfPrimaryComponent={i === lastOccurenceOfPrimaryComponent}
lastSnippetGroup={i === locationsByComponent.length - 1}
loadDuplications={this.fetchDuplications}
locations={snippetGroup.locations || []}
mockSourceViewerFile
} from '../../../../helpers/testMocks';
import ComponentSourceSnippetGroupViewer from '../ComponentSourceSnippetGroupViewer';
+import SnippetViewer from '../SnippetViewer';
jest.mock('../../../../api/components', () => ({
getSources: jest.fn().mockResolvedValue([])
expect(wrapper.state('snippets')).toHaveLength(2);
expect(wrapper.state('snippets')[0]).toEqual({ index: 0, start: 29, end: 39 });
expect(wrapper.state('snippets')[1]).toEqual({ index: 1, start: 69, end: 79 });
+
+ // Check that locationsByLine is defined when isLastOccurenceOfPrimaryComponent
+ expect(
+ wrapper
+ .find(SnippetViewer)
+ .at(0)
+ .props().locationsByLine
+ ).not.toEqual({});
+
+ // If not, it should be an empty object:
+ const snippets = shallowRender({
+ isLastOccurenceOfPrimaryComponent: false,
+ issue,
+ snippetGroup
+ }).find(SnippetViewer);
+
+ expect(snippets.at(0).props().locationsByLine).toEqual({});
+ expect(snippets.at(1).props().locationsByLine).toEqual({});
});
it('should render file-level issue correctly', () => {
<ComponentSourceSnippetGroupViewer
branchLike={mockMainBranch()}
highlightedLocationMessage={{ index: 0, text: '' }}
+ isLastOccurenceOfPrimaryComponent={true}
issue={mockIssue()}
issuesByLine={{}}
lastSnippetGroup={false}
<ComponentSourceSnippetGroupViewer
branchLike={mockMainBranch()}
highlightedLocationMessage={{ index: 0, text: '' }}
+ isLastOccurenceOfPrimaryComponent={true}
issue={mockIssue()}
issuesByLine={{}}
lastSnippetGroup={false}
<ComponentSourceSnippetGroupViewer
branchLike={mockMainBranch()}
highlightedLocationMessage={{ index: 0, text: '' }}
+ isLastOccurenceOfPrimaryComponent={true}
issue={mockIssue()}
issuesByLine={{}}
lastSnippetGroup={false}
>
<ComponentSourceSnippetGroupViewer
duplicationsByLine={Object {}}
+ isLastOccurenceOfPrimaryComponent={true}
issue={
Object {
"actions": Array [],