From 1c1f439152c4c3660d23decd44ae946176ba908e Mon Sep 17 00:00:00 2001 From: Wouter Admiraal Date: Fri, 27 Nov 2020 11:12:19 +0100 Subject: [PATCH] SONAR-14125 Fix BBS Onboarding search results --- .../create/project/BitbucketSearchResults.tsx | 12 +++++----- .../__tests__/BitbucketSearchResults-test.tsx | 6 +++-- .../BitbucketSearchResults-test.tsx.snap | 24 +++++++++++++++++++ 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/create/project/BitbucketSearchResults.tsx b/server/sonar-web/src/main/js/apps/create/project/BitbucketSearchResults.tsx index c8f6f122e3a..6ef4c2617f8 100644 --- a/server/sonar-web/src/main/js/apps/create/project/BitbucketSearchResults.tsx +++ b/server/sonar-web/src/main/js/apps/create/project/BitbucketSearchResults.tsx @@ -17,12 +17,10 @@ * 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 (
- {filteredProjects.length === 0 && searchResults.length > 0 && ( + {filteredSearchResults.length > 0 && ( diff --git a/server/sonar-web/src/main/js/apps/create/project/__tests__/BitbucketSearchResults-test.tsx b/server/sonar-web/src/main/js/apps/create/project/__tests__/BitbucketSearchResults-test.tsx index 3db815e30a4..3b8f3fb0ad7 100644 --- a/server/sonar-web/src/main/js/apps/create/project/__tests__/BitbucketSearchResults-test.tsx +++ b/server/sonar-web/src/main/js/apps/create/project/__tests__/BitbucketSearchResults-test.tsx @@ -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'); }); diff --git a/server/sonar-web/src/main/js/apps/create/project/__tests__/__snapshots__/BitbucketSearchResults-test.tsx.snap b/server/sonar-web/src/main/js/apps/create/project/__tests__/__snapshots__/BitbucketSearchResults-test.tsx.snap index 87539e11b6b..b9f80fb1ed6 100644 --- a/server/sonar-web/src/main/js/apps/create/project/__tests__/__snapshots__/BitbucketSearchResults-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/create/project/__tests__/__snapshots__/BitbucketSearchResults-test.tsx.snap @@ -77,6 +77,30 @@ exports[`should render correctly: unknown project in search results 1`] = ` } showingAllRepositories={true} /> +
`; -- 2.39.5