]> source.dussan.org Git - sonarqube.git/commitdiff
SONARCLOUD-643 Fix select all repositories for import (#1617)
authorSiegfried Ehret <49895321+siegfried-ehret-sonarsource@users.noreply.github.com>
Tue, 14 May 2019 15:04:45 +0000 (17:04 +0200)
committerSonarTech <sonartech@sonarsource.com>
Tue, 14 May 2019 18:21:12 +0000 (20:21 +0200)
server/sonar-web/src/main/js/apps/create/project/RemoteRepositories.tsx
server/sonar-web/src/main/js/apps/create/project/__tests__/RemoteRepositories-test.tsx
server/sonar-web/src/main/js/apps/create/project/__tests__/__snapshots__/RemoteRepositories-test.tsx.snap
sonar-core/src/main/resources/org/sonar/l10n/core.properties

index 22692ba9f7a9e52d4552353c05994d4c6be20dc0..646cee5b1723fdb6c776f7afe69a98512d372dce 100644 (file)
@@ -95,8 +95,9 @@ export default class RemoteRepositories extends React.PureComponent<Props, State
     );
   };
 
-  filterBySearch = (repo: T.AlmRepository) =>
-    repo.label.toLowerCase().includes(this.state.search.toLowerCase());
+  filterBySearch = (search: String) => (repo: T.AlmRepository) => {
+    return repo.label.toLowerCase().includes(search.toLowerCase());
+  };
 
   handleHighlightUpgradeBox = (highlight: boolean) => {
     this.setState({ highlight });
@@ -136,6 +137,7 @@ export default class RemoteRepositories extends React.PureComponent<Props, State
 
       const isPaidOrg = isPaidOrganization(organization);
       const filterByPlan = (repo: T.AlmRepository) => (isPaidOrg ? true : !repo.private);
+      const filterByImportable = (repo: T.AlmRepository) => !repo.linkedProjectKey;
 
       const nextState = {
         selectedRepositories: {},
@@ -143,10 +145,10 @@ export default class RemoteRepositories extends React.PureComponent<Props, State
       };
 
       if (nextState.checkAllRepositories) {
-        const validRepositories = (search
-          ? repositories.filter(this.filterBySearch)
-          : repositories
-        ).filter(filterByPlan);
+        const validRepositories = repositories.filter(
+          repo =>
+            this.filterBySearch(search)(repo) && filterByPlan(repo) && filterByImportable(repo)
+        );
         nextState.selectedRepositories = keyBy(validRepositories, 'installationKey');
       }
 
@@ -174,7 +176,7 @@ export default class RemoteRepositories extends React.PureComponent<Props, State
     const showCheckAll = repositories.length > 1;
     const showUpgradebox =
       !isPaidOrg && hasPrivateRepositories && organization.actions && organization.actions.admin;
-    const filteredRepositories = search ? repositories.filter(this.filterBySearch) : repositories;
+    const filteredRepositories = repositories.filter(this.filterBySearch(search));
 
     return (
       <div className="create-project">
index a4e7c3d0455ab221fd93f59827f311ec8e37fafd..113d220bfbaef459851fa7a9c4ba227a5ff625b9 100644 (file)
@@ -115,7 +115,10 @@ it('should allow to select all repositories', async () => {
 
 it('should select all repositories', async () => {
   (getRepositories as jest.Mock<any>).mockResolvedValueOnce({
-    repositories: times(6, i => ({ label: `Project ${i}`, installationKey: `key-${i}` }))
+    repositories: [
+      { label: 'Project 1', installationKey: 'key-1' },
+      { label: 'Project 2', installationKey: 'key-2', linkedProjectKey: 'key-2' }
+    ]
   });
 
   const wrapper = shallowRender();
index cc41eb68a891b1fec7b206c6309ed6bcb2065dfb..d5f81a64131f9a56bfa85623dcb8791d093da60c 100644 (file)
@@ -178,29 +178,9 @@ exports[`should display the organization upgrade box 1`] = `
 
 exports[`should select all repositories 1`] = `
 Object {
-  "key-0": Object {
-    "installationKey": "key-0",
-    "label": "Project 0",
-  },
   "key-1": Object {
     "installationKey": "key-1",
     "label": "Project 1",
   },
-  "key-2": Object {
-    "installationKey": "key-2",
-    "label": "Project 2",
-  },
-  "key-3": Object {
-    "installationKey": "key-3",
-    "label": "Project 3",
-  },
-  "key-4": Object {
-    "installationKey": "key-4",
-    "label": "Project 4",
-  },
-  "key-5": Object {
-    "installationKey": "key-5",
-    "label": "Project 5",
-  },
 }
 `;
index 7c99cfb09774e3e89d0816139006c7304fd972a8..65990566c98536c309e59cabf4c71a569ef4b781 100644 (file)
@@ -2812,7 +2812,7 @@ onboarding.create_project.display_name.help=Some scanners might override the val
 onboarding.create_project.repository_imported=Already imported: {link}
 onboarding.create_project.see_project=See the project
 onboarding.create_project.select_repositories=Select repositories
-onboarding.create_project.select_all_repositories=Select all repositories
+onboarding.create_project.select_all_repositories=Select all available repositories
 onboarding.create_project.subscribe_to_import_private_repositories=You need to subscribe your organization to a paid plan to import private projects
 onboarding.create_project.encourage_to_subscribe=Subscribe your organization to our paid plan to get unlimited private projects.
 onboarding.create_project.subscribtion_success_x={0} has been successfully upgraded to paid plan. You can now import and analyze private projects.