key: 'component1',
name: 'Component1',
uuid: 'id1',
+ enabled: true,
...override,
};
}
+function generateReferenceComponentsForIssues(issueData: IssueData[]) {
+ return issueData
+ .reduce((componentKeys, response) => {
+ const componentKey = response.issue.component;
+ if (!componentKeys.includes(componentKey)) {
+ return [...componentKeys, componentKey];
+ }
+
+ return componentKeys;
+ }, [] as string[])
+ .map((key) => mockReferenceComponent({ key, enabled: true }));
+}
+
interface IssueData {
issue: RawIssue;
snippets: Dict<SnippetsByComponent>;
};
});
return this.reply({
- components: [mockReferenceComponent()],
+ components: generateReferenceComponentsForIssues(this.list),
effortTotal: 199629,
facets,
issues: this.list.map((line) => line.issue),
Object {
"actions": Array [],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
Object {
"actions": Array [],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
Object {
"actions": Array [],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
Object {
"actions": Array [],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
Object {
"actions": Array [],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
Object {
"actions": Array [],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
Object {
"actions": Array [],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
Object {
"actions": Array [],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
Object {
"actions": Array [],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
Object {
"actions": Array [],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
Object {
"actions": Array [],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
Object {
"actions": Array [],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
Object {
"actions": Array [],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
Object {
"actions": Array [],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
Object {
"actions": Array [],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
const { branchLike, isLastOccurenceOfPrimaryComponent, issue, lastSnippetGroup, snippetGroup } =
this.props;
const { additionalLines, loading, snippets } = this.state;
- const locations =
- issue.component === snippetGroup.component.key && issue.textRange !== undefined
- ? locationsByLine([issue])
- : {};
-
- const fullyShown =
- snippets.length === 1 &&
- snippetGroup.component.measures &&
- snippets[0].end - snippets[0].start ===
- parseInt(snippetGroup.component.measures.lines || '', 10);
const snippetLines = linesForSnippets(snippets, {
...snippetGroup.sources,
...additionalLines,
});
- const isFlow = issue.secondaryLocations.length === 0;
- const includeIssueLocation = isFlow ? isLastOccurenceOfPrimaryComponent : true;
-
const issueIsClosed = issue.status === IssueStatus.Closed;
- const issueIsFileLevel = issue.componentQualifier === ComponentQualifier.File;
+ const issueIsFileLevel =
+ issue.componentQualifier === ComponentQualifier.File && issue.componentEnabled;
const closedIssueMessageKey = issueIsFileLevel
? 'issue.closed.file_level'
: 'issue.closed.project_level';
<IssueSourceViewerHeader
branchLike={branchLike}
className={issueIsClosed && !issueIsFileLevel ? 'null-spacer-bottom' : ''}
- expandable={!fullyShown && isFile(snippetGroup.component.q)}
+ expandable={isExpandable(snippets, snippetGroup)}
loading={loading}
onExpand={this.expandComponent}
sourceViewerFile={snippetGroup.component}
lastSnippetOfLastGroup={lastSnippetGroup && index === snippets.length - 1}
loadDuplications={this.loadDuplications}
locations={this.props.locations}
- locationsByLine={includeIssueLocation ? locations : {}}
+ locationsByLine={getLocationsByLine(
+ issue,
+ snippetGroup,
+ isLastOccurenceOfPrimaryComponent
+ )}
onLocationSelect={this.props.onLocationSelect}
renderDuplicationPopup={this.renderDuplicationPopup}
snippet={snippet}
);
}
}
+
+function getLocationsByLine(
+ issue: TypeIssue,
+ snippetGroup: SnippetGroup,
+ isLastOccurenceOfPrimaryComponent: boolean
+) {
+ const isFlow = issue.secondaryLocations.length === 0;
+ const includeIssueLocation = isFlow ? isLastOccurenceOfPrimaryComponent : true;
+
+ return includeIssueLocation &&
+ issue.component === snippetGroup.component.key &&
+ issue.textRange !== undefined
+ ? locationsByLine([issue])
+ : {};
+}
+
+function isExpandable(snippets: Snippet[], snippetGroup: SnippetGroup) {
+ const fullyShown =
+ snippets.length === 1 &&
+ snippetGroup.component.measures &&
+ snippets[0].end - snippets[0].start ===
+ parseInt(snippetGroup.component.measures.lines || '', 10);
+
+ return !fullyShown && isFile(snippetGroup.component.q);
+}
issue.status === IssueStatus.Closed ? {} : await getIssueFlowSnippets(issue.key);
if (components[issue.component] === undefined) {
const issueComponent = await getComponentForSourceViewer({
- component: issue.component,
+ // If the issue's component doesn't exist anymore (typically a deleted file), use the project
+ component: issue.componentEnabled ? issue.component : issue.project,
...getBranchLikeQuery(branchLike),
});
components[issue.component] = { component: issueComponent, sources: [] };
});
it.each([
- ['file-level', ComponentQualifier.File, 'issue.closed.file_level'],
- ['project-level', ComponentQualifier.Project, 'issue.closed.project_level'],
+ ['file-level', ComponentQualifier.File, true, 'issue.closed.file_level'],
+ ['file-level', ComponentQualifier.File, false, 'issue.closed.project_level'],
+ ['project-level', ComponentQualifier.Project, false, 'issue.closed.project_level'],
])(
'should render a closed %s issue correctly',
- async (_level, componentQualifier, expectedLabel) => {
+ async (_level, componentQualifier, componentEnabled, expectedLabel) => {
// issue with secondary locations and no primary location
const issue = mockIssue(true, {
component: 'project:main.js',
componentQualifier,
+ componentEnabled,
flows: [],
textRange: undefined,
status: IssueStatus.Closed,
*/
import { shallow } from 'enzyme';
import * as React from 'react';
-import { getDuplications } from '../../../../api/components';
+import { getComponentForSourceViewer, getDuplications } from '../../../../api/components';
import { getIssueFlowSnippets } from '../../../../api/issues';
import {
mockSnippetsByComponent,
expect(getIssueFlowSnippets).toHaveBeenCalledWith('foo');
});
-it('Should handle a closed issue', async () => {
- const wrapper = shallowRender({ issue: mockIssue(true, { status: IssueStatus.Closed }) });
+it.each([
+ ['on a deleted file', false, { component: 'myproject' }],
+ ['', true, { component: 'main.js' }],
+])('Should handle a closed issue %s', async (_, componentEnabled, expected) => {
+ const wrapper = shallowRender({
+ issue: mockIssue(true, { componentEnabled, status: IssueStatus.Closed }),
+ });
wrapper.instance().fetchIssueFlowSnippets();
await waitAndUpdate(wrapper);
expect(getIssueFlowSnippets).not.toHaveBeenCalled();
+ expect(getComponentForSourceViewer).toHaveBeenCalledWith(expect.objectContaining(expected));
});
it('Should handle no access rights', async () => {
Object {
"actions": Array [],
"component": "project:main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
Object {
"actions": Array [],
"component": "test.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
Object {
"actions": Array [],
"component": "test.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
Object {
"actions": Array [],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
Object {
"actions": Array [],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
Object {
"actions": Array [],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
Object {
"actions": Array [],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
Object {
"actions": Array [],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
},
],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
},
],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
},
],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
"comment",
],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
"comment",
],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
"comment",
],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
"comment",
],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
"comment",
],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
Object {
"actions": Array [],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
Object {
"actions": Array [],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
Object {
"actions": Array [],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
Object {
"actions": Array [],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
Object {
"actions": Array [],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
Object {
"actions": Array [],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
Object {
"actions": Array [],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
Object {
"actions": Array [],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
Object {
"actions": Array [],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
Object {
"actions": Array [],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
Object {
"actions": Array [],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
Object {
"actions": Array [],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
Object {
"actions": Array [],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
Object {
"actions": Array [],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
Object {
"actions": Array [],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
Object {
"actions": Array [],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
Object {
"actions": Array [],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
Object {
"actions": Array [],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
Object {
"actions": Array [],
"component": "main.js",
+ "componentEnabled": true,
"componentLongName": "main.js",
"componentQualifier": "FIL",
"componentUuid": "foo1234",
const issue: Issue = {
actions: [],
component: 'main.js',
+ componentEnabled: true,
componentLongName: 'main.js',
componentQualifier: 'FIL',
componentUuid: 'foo1234',
key: string;
name: string;
path?: string;
+ enabled?: boolean;
+ longName?: string;
uuid: string;
}
branch?: string;
comments?: IssueComment[];
component: string;
+ componentEnabled?: boolean;
componentLongName: string;
componentQualifier: string;
componentUuid: string;