@@ -29,46 +29,28 @@ import ListStyleFacet from '../../../components/facet/ListStyleFacet'; | |||
import { getBranchLikeQuery } from '../../../helpers/branch-like'; | |||
import { BranchLike } from '../../../types/branch-like'; | |||
import { TreeComponentWithPath } from '../../../types/component'; | |||
import { Facet, Query, ReferencedComponent } from '../utils'; | |||
import { Facet, Query } from '../utils'; | |||
interface Props { | |||
branchLike?: BranchLike; | |||
componentKey: string; | |||
fetching: boolean; | |||
fileUuids: string[]; | |||
files: string[]; | |||
loadSearchResultCount: (property: string, changes: Partial<Query>) => Promise<Facet>; | |||
onChange: (changes: Partial<Query>) => void; | |||
onToggle: (property: string) => void; | |||
open: boolean; | |||
query: Query; | |||
referencedComponents: T.Dict<ReferencedComponent>; | |||
stats: Facet | undefined; | |||
} | |||
export default class FileFacet extends React.PureComponent<Props> { | |||
getFilePath = (fileUuid: string) => { | |||
const { referencedComponents } = this.props; | |||
return referencedComponents[fileUuid] | |||
? collapsePath(referencedComponents[fileUuid].path || '', 15) | |||
: fileUuid; | |||
}; | |||
getReferencedComponent = (key: string) => { | |||
const { referencedComponents } = this.props; | |||
const fileUuid = Object.keys(referencedComponents).find(uuid => { | |||
return referencedComponents[uuid].key === key; | |||
}); | |||
return fileUuid ? referencedComponents[fileUuid] : undefined; | |||
}; | |||
getFacetItemText = (fileUuid: string) => { | |||
const { referencedComponents } = this.props; | |||
return referencedComponents[fileUuid] ? referencedComponents[fileUuid].path || '' : fileUuid; | |||
getFacetItemText = (path: string) => { | |||
return path; | |||
}; | |||
getSearchResultKey = (file: TreeComponentWithPath) => { | |||
const component = this.getReferencedComponent(file.key); | |||
return component ? component.uuid : file.key; | |||
return file.path; | |||
}; | |||
getSearchResultText = (file: TreeComponentWithPath) => { | |||
@@ -94,8 +76,7 @@ export default class FileFacet extends React.PureComponent<Props> { | |||
return this.props.loadSearchResultCount('files', { | |||
files: files | |||
.map(file => { | |||
const component = this.getReferencedComponent(file.key); | |||
return component && component.uuid; | |||
return file.path; | |||
}) | |||
.filter(isDefined) | |||
}); | |||
@@ -108,9 +89,8 @@ export default class FileFacet extends React.PureComponent<Props> { | |||
</> | |||
); | |||
renderFacetItem = (fileUuid: string) => { | |||
const name = this.getFilePath(fileUuid); | |||
return this.renderFile(name); | |||
renderFacetItem = (path: string) => { | |||
return this.renderFile(path); | |||
}; | |||
renderSearchResult = (file: TreeComponentWithPath, term: string) => { | |||
@@ -137,7 +117,7 @@ export default class FileFacet extends React.PureComponent<Props> { | |||
renderSearchResult={this.renderSearchResult} | |||
searchPlaceholder={translate('search.search_for_files')} | |||
stats={this.props.stats} | |||
values={this.props.fileUuids} | |||
values={this.props.files} | |||
/> | |||
); | |||
} |
@@ -88,9 +88,8 @@ export class Sidebar extends React.PureComponent<Props> { | |||
<FileFacet | |||
branchLike={branchLike} | |||
fetching={loadingFacets.files === true} | |||
fileUuids={query.files} | |||
files={query.files} | |||
open={!!openFacets.files} | |||
referencedComponents={this.props.referencedComponentsById} | |||
stats={facets.files} | |||
{...commonProps} | |||
/> |
@@ -24,7 +24,7 @@ import ListStyleFacet from '../../../../components/facet/ListStyleFacet'; | |||
import { mockBranch } from '../../../../helpers/mocks/branch-like'; | |||
import { mockComponent } from '../../../../helpers/testMocks'; | |||
import { TreeComponentWithPath } from '../../../../types/component'; | |||
import { Query, ReferencedComponent } from '../../utils'; | |||
import { Query } from '../../utils'; | |||
import FileFacet from '../FileFacet'; | |||
jest.mock('../../../../api/components', () => ({ | |||
@@ -76,12 +76,12 @@ describe("ListStyleFacet's callback props", () => { | |||
}); | |||
it('#getSearchResultKey()', () => { | |||
expect(instance.getSearchResultKey({ key: 'foo' } as TreeComponentWithPath)).toBe('fooUuid'); | |||
expect(instance.getSearchResultKey({ key: 'bar' } as TreeComponentWithPath)).toBe('bar'); | |||
expect(instance.getSearchResultKey({ key: 'bar', path: 'bar' } as TreeComponentWithPath)).toBe( | |||
'bar' | |||
); | |||
}); | |||
it('#getFacetItemText()', () => { | |||
expect(instance.getFacetItemText('fooUuid')).toBe('foo/bar.js'); | |||
expect(instance.getFacetItemText('bar')).toBe('bar'); | |||
}); | |||
}); | |||
@@ -92,15 +92,12 @@ function shallowRender(props: Partial<FileFacet['props']> = {}) { | |||
branchLike={branch} | |||
componentKey={component.key} | |||
fetching={false} | |||
fileUuids={['foo', 'bar']} | |||
files={['foo', 'bar']} | |||
loadSearchResultCount={jest.fn()} | |||
onChange={jest.fn()} | |||
onToggle={jest.fn()} | |||
open={false} | |||
query={{} as Query} | |||
referencedComponents={{ | |||
fooUuid: { key: 'foo', uuid: 'fooUuid', path: 'foo/bar.js' } as ReferencedComponent | |||
}} | |||
stats={undefined} | |||
{...props} | |||
/> |
@@ -50,6 +50,6 @@ exports[`should render correctly 3`] = ` | |||
className="little-spacer-right" | |||
qualifier="FIL" | |||
/> | |||
foo/bar.js | |||
fooUuid | |||
</React.Fragment> | |||
`; |
@@ -87,7 +87,7 @@ export function parseQuery(query: T.RawQuery): Query { | |||
createdInLast: parseAsString(query.createdInLast), | |||
cwe: parseAsArray(query.cwe, parseAsString), | |||
directories: parseAsArray(query.directories, parseAsString), | |||
files: parseAsArray(query.fileUuids, parseAsString), | |||
files: parseAsArray(query.files, parseAsString), | |||
issues: parseAsArray(query.issues, parseAsString), | |||
languages: parseAsArray(query.languages, parseAsString), | |||
modules: parseAsArray(query.moduleUuids, parseAsString), | |||
@@ -125,7 +125,7 @@ export function serializeQuery(query: Query): T.RawQuery { | |||
createdInLast: serializeString(query.createdInLast), | |||
cwe: serializeStringArray(query.cwe), | |||
directories: serializeStringArray(query.directories), | |||
fileUuids: serializeStringArray(query.files), | |||
files: serializeStringArray(query.files), | |||
issues: serializeStringArray(query.issues), | |||
languages: serializeStringArray(query.languages), | |||
moduleUuids: serializeStringArray(query.modules), | |||
@@ -161,7 +161,6 @@ export interface Facet { | |||
export function mapFacet(facet: string) { | |||
const propertyMapping: T.Dict<string> = { | |||
files: 'fileUuids', | |||
modules: 'moduleUuids' | |||
}; | |||
return propertyMapping[facet] || facet; | |||
@@ -174,7 +173,6 @@ export function parseFacets(facets: RawFacet[]): T.Dict<Facet> { | |||
// for readability purpose | |||
const propertyMapping: T.Dict<string> = { | |||
fileUuids: 'files', | |||
moduleUuids: 'modules' | |||
}; | |||
@@ -81,7 +81,7 @@ export default class SourceViewerHeader extends React.PureComponent<Props, State | |||
{ISSUE_TYPES.map((type: T.IssueType) => { | |||
const params = { | |||
...getBranchLikeQuery(branchLike), | |||
fileUuids: sourceViewerFile.uuid, | |||
files: sourceViewerFile.path, | |||
resolved: 'false', | |||
types: type | |||
}; |
@@ -54,16 +54,7 @@ export default function SourceViewerHeaderSlim(props: Props) { | |||
onExpand, | |||
sourceViewerFile | |||
} = props; | |||
const { | |||
measures, | |||
path, | |||
project, | |||
projectName, | |||
q, | |||
subProject, | |||
subProjectName, | |||
uuid | |||
} = sourceViewerFile; | |||
const { measures, path, project, projectName, q, subProject, subProjectName } = sourceViewerFile; | |||
const projectNameLabel = ( | |||
<> | |||
@@ -113,7 +104,7 @@ export default function SourceViewerHeaderSlim(props: Props) { | |||
<Link | |||
to={getComponentIssuesUrl(project, { | |||
...getBranchLikeQuery(branchLike), | |||
fileUuids: uuid, | |||
files: path, | |||
resolved: 'false' | |||
})}> | |||
{translate('source_viewer.view_all_issues')} |
@@ -377,7 +377,7 @@ exports[`should render correctly if issue details are passed 1`] = ` | |||
Object { | |||
"pathname": "/project/issues", | |||
"query": Object { | |||
"fileUuids": "foo-bar", | |||
"files": "foo/bar.ts", | |||
"id": "my-project", | |||
"resolved": "false", | |||
"types": "BUG", | |||
@@ -408,7 +408,7 @@ exports[`should render correctly if issue details are passed 1`] = ` | |||
Object { | |||
"pathname": "/project/issues", | |||
"query": Object { | |||
"fileUuids": "foo-bar", | |||
"files": "foo/bar.ts", | |||
"id": "my-project", | |||
"resolved": "false", | |||
"types": "VULNERABILITY", | |||
@@ -439,7 +439,7 @@ exports[`should render correctly if issue details are passed 1`] = ` | |||
Object { | |||
"pathname": "/project/issues", | |||
"query": Object { | |||
"fileUuids": "foo-bar", | |||
"files": "foo/bar.ts", | |||
"id": "my-project", | |||
"resolved": "false", | |||
"types": "CODE_SMELL", | |||
@@ -470,7 +470,7 @@ exports[`should render correctly if issue details are passed 1`] = ` | |||
Object { | |||
"pathname": "/project/issues", | |||
"query": Object { | |||
"fileUuids": "foo-bar", | |||
"files": "foo/bar.ts", | |||
"id": "my-project", | |||
"resolved": "false", | |||
"types": "SECURITY_HOTSPOT", |
@@ -58,7 +58,7 @@ exports[`should render correctly 1`] = ` | |||
Object { | |||
"pathname": "/project/issues", | |||
"query": Object { | |||
"fileUuids": "foo-bar", | |||
"files": "foo/bar.ts", | |||
"id": "my-project", | |||
"resolved": "false", | |||
}, | |||
@@ -152,7 +152,7 @@ exports[`should render correctly for subproject 1`] = ` | |||
Object { | |||
"pathname": "/project/issues", | |||
"query": Object { | |||
"fileUuids": "foo-bar", | |||
"files": "foo/bar.ts", | |||
"id": "my-project", | |||
"resolved": "false", | |||
}, | |||
@@ -232,7 +232,7 @@ exports[`should render correctly: no link to project 1`] = ` | |||
Object { | |||
"pathname": "/project/issues", | |||
"query": Object { | |||
"fileUuids": "foo-bar", | |||
"files": "foo/bar.ts", | |||
"id": "my-project", | |||
"resolved": "false", | |||
}, | |||
@@ -301,7 +301,7 @@ exports[`should render correctly: no project name 1`] = ` | |||
Object { | |||
"pathname": "/project/issues", | |||
"query": Object { | |||
"fileUuids": "foo-bar", | |||
"files": "foo/bar.ts", | |||
"id": "my-project", | |||
"resolved": "false", | |||
}, |