); | ); | ||||
}; | }; | ||||
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) => { | handleHighlightUpgradeBox = (highlight: boolean) => { | ||||
this.setState({ highlight }); | this.setState({ highlight }); | ||||
const isPaidOrg = isPaidOrganization(organization); | const isPaidOrg = isPaidOrganization(organization); | ||||
const filterByPlan = (repo: T.AlmRepository) => (isPaidOrg ? true : !repo.private); | const filterByPlan = (repo: T.AlmRepository) => (isPaidOrg ? true : !repo.private); | ||||
const filterByImportable = (repo: T.AlmRepository) => !repo.linkedProjectKey; | |||||
const nextState = { | const nextState = { | ||||
selectedRepositories: {}, | selectedRepositories: {}, | ||||
}; | }; | ||||
if (nextState.checkAllRepositories) { | 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'); | nextState.selectedRepositories = keyBy(validRepositories, 'installationKey'); | ||||
} | } | ||||
const showCheckAll = repositories.length > 1; | const showCheckAll = repositories.length > 1; | ||||
const showUpgradebox = | const showUpgradebox = | ||||
!isPaidOrg && hasPrivateRepositories && organization.actions && organization.actions.admin; | !isPaidOrg && hasPrivateRepositories && organization.actions && organization.actions.admin; | ||||
const filteredRepositories = search ? repositories.filter(this.filterBySearch) : repositories; | |||||
const filteredRepositories = repositories.filter(this.filterBySearch(search)); | |||||
return ( | return ( | ||||
<div className="create-project"> | <div className="create-project"> |
it('should select all repositories', async () => { | it('should select all repositories', async () => { | ||||
(getRepositories as jest.Mock<any>).mockResolvedValueOnce({ | (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(); | const wrapper = shallowRender(); |
exports[`should select all repositories 1`] = ` | exports[`should select all repositories 1`] = ` | ||||
Object { | Object { | ||||
"key-0": Object { | |||||
"installationKey": "key-0", | |||||
"label": "Project 0", | |||||
}, | |||||
"key-1": Object { | "key-1": Object { | ||||
"installationKey": "key-1", | "installationKey": "key-1", | ||||
"label": "Project 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", | |||||
}, | |||||
} | } | ||||
`; | `; |
onboarding.create_project.repository_imported=Already imported: {link} | onboarding.create_project.repository_imported=Already imported: {link} | ||||
onboarding.create_project.see_project=See the project | onboarding.create_project.see_project=See the project | ||||
onboarding.create_project.select_repositories=Select repositories | 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.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.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. | onboarding.create_project.subscribtion_success_x={0} has been successfully upgraded to paid plan. You can now import and analyze private projects. |