]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13592 Fix file facet search, result filter issue correctly.
authorMathieu Suen <mathieu.suen@sonarsource.com>
Fri, 18 Sep 2020 14:52:06 +0000 (16:52 +0200)
committersonartech <sonartech@sonarsource.com>
Thu, 24 Sep 2020 20:07:22 +0000 (20:07 +0000)
server/sonar-web/src/main/js/apps/issues/sidebar/FileFacet.tsx
server/sonar-web/src/main/js/apps/issues/sidebar/Sidebar.tsx
server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/FileFacet-test.tsx
server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/__snapshots__/FileFacet-test.tsx.snap
server/sonar-web/src/main/js/apps/issues/utils.ts
server/sonar-web/src/main/js/components/SourceViewer/SourceViewerHeader.tsx
server/sonar-web/src/main/js/components/SourceViewer/SourceViewerHeaderSlim.tsx
server/sonar-web/src/main/js/components/SourceViewer/__tests__/__snapshots__/SourceViewerHeader-test.tsx.snap
server/sonar-web/src/main/js/components/SourceViewer/__tests__/__snapshots__/SourceViewerHeaderSlim-test.tsx.snap

index 451aef2dd6ce8ba1ffed170e46b40f3bf1725d10..cd6a0f1dee3d5025c0b4c4be0cdb281935038250 100644 (file)
@@ -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}
       />
     );
   }
index 878cac3cae837b018486f0766cfede6e39a3e165..a9f69fff513e79af430ced3317f2cdec16a68553 100644 (file)
@@ -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}
         />
index cac5c92b52bba15fb4dec003dc193bdc1a464fea..e2df44d607911c7c58b37087d48b2a6da5fce59d 100644 (file)
@@ -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}
     />
index e0c34a440745b4a2bb4d58469a3b7cda4ad8666d..0a5a99c9daf8928e5a6c0e492adbc36c6361a9f5 100644 (file)
@@ -50,6 +50,6 @@ exports[`should render correctly 3`] = `
     className="little-spacer-right"
     qualifier="FIL"
   />
-  foo/bar.js
+  fooUuid
 </React.Fragment>
 `;
index 5d25e6d22a011abb62232a63962316b734b91520..8dc99ee6329ebe63dfaebb32d53b62fbea33c4a9 100644 (file)
@@ -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'
   };
 
index 63f01ef746ce97acfc7e03a4a0fa2cfaa7cad70c..48b0b8d0b00949dd9a2d57c0207c88316b093da4 100644 (file)
@@ -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
             };
index 5e7a12efbffd14814429085151aa260c8c834cde..3306ca2dc3c862f717f78817fb1e396dd9863e67 100644 (file)
@@ -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')}
index 92f4a5eb87fc7410785a5638d0c252e407ce956e..6e53dad11aa6bf6b090dcc499cb68dc4740e55ca 100644 (file)
@@ -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",
index 6d59238df6d65f0bf8bc7764cda01acb655fa7f2..dc4035a4fae8157f8d5bf9b9d568fa3db12d3e27 100644 (file)
@@ -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",
           },