* 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';
);
}
- 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}
/>
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');
});
}
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>
`;