From: Mathieu Suen Date: Fri, 18 Sep 2020 14:52:06 +0000 (+0200) Subject: SONAR-13592 Fix file facet search, result filter issue correctly. X-Git-Tag: 8.5.0.37579~39 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e21fbb25bc5a1b3a4658a78993d51404b6f8204e;p=sonarqube.git SONAR-13592 Fix file facet search, result filter issue correctly. --- diff --git a/server/sonar-web/src/main/js/apps/issues/sidebar/FileFacet.tsx b/server/sonar-web/src/main/js/apps/issues/sidebar/FileFacet.tsx index 451aef2dd6c..cd6a0f1dee3 100644 --- a/server/sonar-web/src/main/js/apps/issues/sidebar/FileFacet.tsx +++ b/server/sonar-web/src/main/js/apps/issues/sidebar/FileFacet.tsx @@ -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) => Promise; onChange: (changes: Partial) => void; onToggle: (property: string) => void; open: boolean; query: Query; - referencedComponents: T.Dict; stats: Facet | undefined; } export default class FileFacet extends React.PureComponent { - 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 { 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 { ); - 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 { renderSearchResult={this.renderSearchResult} searchPlaceholder={translate('search.search_for_files')} stats={this.props.stats} - values={this.props.fileUuids} + values={this.props.files} /> ); } diff --git a/server/sonar-web/src/main/js/apps/issues/sidebar/Sidebar.tsx b/server/sonar-web/src/main/js/apps/issues/sidebar/Sidebar.tsx index 878cac3cae8..a9f69fff513 100644 --- a/server/sonar-web/src/main/js/apps/issues/sidebar/Sidebar.tsx +++ b/server/sonar-web/src/main/js/apps/issues/sidebar/Sidebar.tsx @@ -88,9 +88,8 @@ export class Sidebar extends React.PureComponent { diff --git a/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/FileFacet-test.tsx b/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/FileFacet-test.tsx index cac5c92b52b..e2df44d6079 100644 --- a/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/FileFacet-test.tsx +++ b/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/FileFacet-test.tsx @@ -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 = {}) { 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} /> diff --git a/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/__snapshots__/FileFacet-test.tsx.snap b/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/__snapshots__/FileFacet-test.tsx.snap index e0c34a44074..0a5a99c9daf 100644 --- a/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/__snapshots__/FileFacet-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/__snapshots__/FileFacet-test.tsx.snap @@ -50,6 +50,6 @@ exports[`should render correctly 3`] = ` className="little-spacer-right" qualifier="FIL" /> - foo/bar.js + fooUuid `; diff --git a/server/sonar-web/src/main/js/apps/issues/utils.ts b/server/sonar-web/src/main/js/apps/issues/utils.ts index 5d25e6d22a0..8dc99ee6329 100644 --- a/server/sonar-web/src/main/js/apps/issues/utils.ts +++ b/server/sonar-web/src/main/js/apps/issues/utils.ts @@ -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 = { - files: 'fileUuids', modules: 'moduleUuids' }; return propertyMapping[facet] || facet; @@ -174,7 +173,6 @@ export function parseFacets(facets: RawFacet[]): T.Dict { // for readability purpose const propertyMapping: T.Dict = { - fileUuids: 'files', moduleUuids: 'modules' }; diff --git a/server/sonar-web/src/main/js/components/SourceViewer/SourceViewerHeader.tsx b/server/sonar-web/src/main/js/components/SourceViewer/SourceViewerHeader.tsx index 63f01ef746c..48b0b8d0b00 100644 --- a/server/sonar-web/src/main/js/components/SourceViewer/SourceViewerHeader.tsx +++ b/server/sonar-web/src/main/js/components/SourceViewer/SourceViewerHeader.tsx @@ -81,7 +81,7 @@ export default class SourceViewerHeader extends React.PureComponent { const params = { ...getBranchLikeQuery(branchLike), - fileUuids: sourceViewerFile.uuid, + files: sourceViewerFile.path, resolved: 'false', types: type }; diff --git a/server/sonar-web/src/main/js/components/SourceViewer/SourceViewerHeaderSlim.tsx b/server/sonar-web/src/main/js/components/SourceViewer/SourceViewerHeaderSlim.tsx index 5e7a12efbff..3306ca2dc3c 100644 --- a/server/sonar-web/src/main/js/components/SourceViewer/SourceViewerHeaderSlim.tsx +++ b/server/sonar-web/src/main/js/components/SourceViewer/SourceViewerHeaderSlim.tsx @@ -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) { {translate('source_viewer.view_all_issues')} diff --git a/server/sonar-web/src/main/js/components/SourceViewer/__tests__/__snapshots__/SourceViewerHeader-test.tsx.snap b/server/sonar-web/src/main/js/components/SourceViewer/__tests__/__snapshots__/SourceViewerHeader-test.tsx.snap index 92f4a5eb87f..6e53dad11aa 100644 --- a/server/sonar-web/src/main/js/components/SourceViewer/__tests__/__snapshots__/SourceViewerHeader-test.tsx.snap +++ b/server/sonar-web/src/main/js/components/SourceViewer/__tests__/__snapshots__/SourceViewerHeader-test.tsx.snap @@ -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", diff --git a/server/sonar-web/src/main/js/components/SourceViewer/__tests__/__snapshots__/SourceViewerHeaderSlim-test.tsx.snap b/server/sonar-web/src/main/js/components/SourceViewer/__tests__/__snapshots__/SourceViewerHeaderSlim-test.tsx.snap index 6d59238df6d..dc4035a4fae 100644 --- a/server/sonar-web/src/main/js/components/SourceViewer/__tests__/__snapshots__/SourceViewerHeaderSlim-test.tsx.snap +++ b/server/sonar-web/src/main/js/components/SourceViewer/__tests__/__snapshots__/SourceViewerHeaderSlim-test.tsx.snap @@ -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", },