]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-14125 Fix BBS Onboarding search results
authorWouter Admiraal <wouter.admiraal@sonarsource.com>
Fri, 27 Nov 2020 10:12:19 +0000 (11:12 +0100)
committersonartech <sonartech@sonarsource.com>
Wed, 2 Dec 2020 20:06:58 +0000 (20:06 +0000)
server/sonar-web/src/main/js/apps/create/project/BitbucketSearchResults.tsx
server/sonar-web/src/main/js/apps/create/project/__tests__/BitbucketSearchResults-test.tsx
server/sonar-web/src/main/js/apps/create/project/__tests__/__snapshots__/BitbucketSearchResults-test.tsx.snap

index c8f6f122e3a47adeac5f7af6f249e48b15cefb15..6ef4c2617f863b24075ea4a2e0e6916af2da5632 100644 (file)
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
-import { uniq } 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';
 import { translate } from 'sonar-ui-common/helpers/l10n';
-import { isDefined } from 'sonar-ui-common/helpers/types';
 import { BitbucketProject, BitbucketRepository } from '../../../types/alm-integration';
 import BitbucketProjectAccordion from './BitbucketProjectAccordion';
 
@@ -52,19 +50,21 @@ export default function BitbucketSearchResults(props: BitbucketSearchResultsProp
     );
   }
 
-  const filteredProjects = uniq(
-    searchResults.map(r => projects.find(p => p.key === r.projectKey)).filter(isDefined)
+  const filteredProjects = projects.filter(p => searchResults.some(r => r.projectKey === p.key));
+  const filteredProjectKeys = filteredProjects.map(p => p.key);
+  const filteredSearchResults = searchResults.filter(
+    r => !filteredProjectKeys.includes(r.projectKey)
   );
 
   return (
     <div className="big-spacer-top">
       <DeferredSpinner loading={searching}>
-        {filteredProjects.length === 0 && searchResults.length > 0 && (
+        {filteredSearchResults.length > 0 && (
           <BitbucketProjectAccordion
             disableRepositories={disableRepositories}
             onSelectRepository={props.onSelectRepository}
             open={true}
-            repositories={searchResults}
+            repositories={filteredSearchResults}
             selectedRepository={selectedRepository}
             showingAllRepositories={true}
           />
index 3db815e30a4958cffc3d4efc195c3753a0e0db43..3b8f3fb0ad7dce33eab06837136c691688f0a1da 100644 (file)
@@ -29,11 +29,13 @@ import BitbucketSearchResults, { BitbucketSearchResultsProps } from '../Bitbucke
 it('should render correctly', () => {
   expect(shallowRender()).toMatchSnapshot('default');
   expect(
-    shallowRender({ searching: true, projects: undefined, searchResults: undefined })
+    shallowRender({ searching: true, projects: [], searchResults: undefined })
   ).toMatchSnapshot('searching');
   expect(shallowRender({ searchResults: undefined })).toMatchSnapshot('no results');
   expect(
-    shallowRender({ searchResults: [mockBitbucketRepository({ projectKey: 'unknown' })] })
+    shallowRender({
+      searchResults: [mockBitbucketRepository(), mockBitbucketRepository({ projectKey: 'unknown' })]
+    })
   ).toMatchSnapshot('unknown project in search results');
 });
 
index 87539e11b6b33cf04d5a104244f2264c7715d137..b9f80fb1ed666af9400d4cfc48d448d811238a32 100644 (file)
@@ -77,6 +77,30 @@ exports[`should render correctly: unknown project in search results 1`] = `
       }
       showingAllRepositories={true}
     />
+    <BitbucketProjectAccordion
+      disableRepositories={false}
+      key="project"
+      onSelectRepository={[MockFunction]}
+      open={true}
+      project={
+        Object {
+          "id": 1,
+          "key": "project",
+          "name": "Project",
+        }
+      }
+      repositories={
+        Array [
+          Object {
+            "id": 1,
+            "name": "Repo",
+            "projectKey": "project",
+            "slug": "project__repo",
+          },
+        ]
+      }
+      showingAllRepositories={true}
+    />
   </DeferredSpinner>
 </div>
 `;