@@ -63,9 +63,9 @@ export function getAzureRepositories( | |||
export function searchAzureRepositories( | |||
almSetting: string, | |||
repositoryName: string | |||
searchQuery: string | |||
): Promise<{ repositories: AzureRepository[] }> { | |||
return getJSON('/api/alm_integrations/search_azure_repos', { almSetting, repositoryName }).catch( | |||
return getJSON('/api/alm_integrations/search_azure_repos', { almSetting, searchQuery }).catch( | |||
throwGlobalError | |||
); | |||
} |
@@ -52,7 +52,7 @@ export default function AzureProjectAccordion(props: AzureProjectAccordionProps) | |||
const [open, setOpen] = React.useState(startsOpen); | |||
const handleClick = () => { | |||
if (!open) { | |||
props.onOpen(project.key); | |||
props.onOpen(project.name); | |||
} | |||
setOpen(!open); | |||
}; | |||
@@ -61,7 +61,7 @@ export default function AzureProjectAccordion(props: AzureProjectAccordionProps) | |||
const limitedRepositories = repositories.slice(0, page * PAGE_SIZE); | |||
const isSelected = (repo: AzureRepository) => | |||
selectedRepository?.projectName === project.key && selectedRepository.name === repo.name; | |||
selectedRepository?.projectName === project.name && selectedRepository.name === repo.name; | |||
return ( | |||
<BoxedGroupAccordion | |||
@@ -70,7 +70,7 @@ export default function AzureProjectAccordion(props: AzureProjectAccordionProps) | |||
})} | |||
onClick={handleClick} | |||
open={open} | |||
title={<h3>{project.name}</h3>}> | |||
title={<h3 title={project.description}>{project.name}</h3>}> | |||
{open && ( | |||
<DeferredSpinner loading={loading}> | |||
{/* The extra loading guard is to prevent the flash of the Alert */} |
@@ -101,23 +101,23 @@ export default class AzureProjectCreate extends React.PureComponent<Props, State | |||
const { repositories } = this.state; | |||
let firstProjectKey: string; | |||
let firstProjectName: string; | |||
if (projects && projects.length > 0) { | |||
firstProjectKey = projects[0].key; | |||
firstProjectName = projects[0].name; | |||
this.setState(({ loadingRepositories }) => ({ | |||
loadingRepositories: { ...loadingRepositories, [firstProjectKey]: true } | |||
loadingRepositories: { ...loadingRepositories, [firstProjectName]: true } | |||
})); | |||
const repos = await this.fetchAzureRepositories(firstProjectKey); | |||
repositories[firstProjectKey] = repos; | |||
const repos = await this.fetchAzureRepositories(firstProjectName); | |||
repositories[firstProjectName] = repos; | |||
} | |||
if (this.mounted) { | |||
this.setState(({ loadingRepositories }) => { | |||
if (firstProjectKey) { | |||
loadingRepositories[firstProjectKey] = false; | |||
if (firstProjectName) { | |||
loadingRepositories[firstProjectName] = false; | |||
} | |||
return { | |||
@@ -141,14 +141,14 @@ export default class AzureProjectCreate extends React.PureComponent<Props, State | |||
return getAzureProjects(settings.key).then(({ projects }) => projects); | |||
}; | |||
fetchAzureRepositories = (projectKey: string): Promise<AzureRepository[]> => { | |||
fetchAzureRepositories = (projectName: string): Promise<AzureRepository[]> => { | |||
const { settings } = this.state; | |||
if (!settings) { | |||
return Promise.resolve([]); | |||
} | |||
return getAzureRepositories(settings.key, projectKey) | |||
return getAzureRepositories(settings.key, projectName) | |||
.then(({ repositories }) => repositories) | |||
.catch(() => []); | |||
}; |
@@ -53,7 +53,7 @@ export default function AzureProjectsList(props: AzureProjectsListProps) { | |||
const [page, setPage] = React.useState(1); | |||
const filteredProjects = searchResults | |||
? projects.filter(p => searchResults[p.key] !== undefined) | |||
? projects.filter(p => searchResults[p.name] !== undefined) | |||
: projects; | |||
if (filteredProjects.length === 0) { | |||
@@ -92,13 +92,13 @@ export default function AzureProjectsList(props: AzureProjectsListProps) { | |||
<div> | |||
{displayedProjects.map((p, i) => ( | |||
<AzureProjectAccordion | |||
key={`${p.key}${keySuffix}`} | |||
key={`${p.name}${keySuffix}`} | |||
importing={importing} | |||
loading={Boolean(loadingRepositories[p.key])} | |||
loading={Boolean(loadingRepositories[p.name])} | |||
onOpen={props.onOpenProject} | |||
onSelectRepository={props.onSelectRepository} | |||
project={p} | |||
repositories={searchResults ? searchResults[p.key] : repositories[p.key]} | |||
repositories={searchResults ? searchResults[p.name] : repositories[p.name]} | |||
selectedRepository={selectedRepository} | |||
startsOpen={searchResults !== undefined || i === 0} | |||
/> |
@@ -106,13 +106,13 @@ it('should correctly fetch projects and repositories on mount', async () => { | |||
await waitAndUpdate(wrapper); | |||
expect(getAzureProjects).toBeCalled(); | |||
expect(getAzureRepositories).toBeCalledTimes(1); | |||
expect(getAzureRepositories).toBeCalledWith('foo', project.key); | |||
expect(getAzureRepositories).toBeCalledWith('foo', project.name); | |||
}); | |||
it('should handle opening a project', async () => { | |||
const projects = [ | |||
mockAzureProject(), | |||
mockAzureProject({ key: 'project2', name: 'Project to open' }) | |||
mockAzureProject({ name: 'project2', description: 'Project to open' }) | |||
]; | |||
const firstProjectRepos = [mockAzureRepository()]; | |||
@@ -130,14 +130,14 @@ it('should handle opening a project', async () => { | |||
const wrapper = shallowRender(); | |||
await waitAndUpdate(wrapper); | |||
wrapper.instance().handleOpenProject(projects[1].key); | |||
wrapper.instance().handleOpenProject(projects[1].name); | |||
await waitAndUpdate(wrapper); | |||
expect(getAzureRepositories).toBeCalledWith('foo', projects[1].key); | |||
expect(getAzureRepositories).toBeCalledWith('foo', projects[1].name); | |||
expect(wrapper.state().repositories).toEqual({ | |||
[projects[0].key]: firstProjectRepos, | |||
[projects[1].key]: secondProjectRepos | |||
[projects[0].name]: firstProjectRepos, | |||
[projects[1].name]: secondProjectRepos | |||
}); | |||
}); | |||
@@ -49,7 +49,7 @@ function shallowRender(overrides: Partial<AzureProjectCreateRendererProps>) { | |||
onSearch={jest.fn()} | |||
onSelectRepository={jest.fn()} | |||
projects={[project]} | |||
repositories={{ [project.key]: [mockAzureRepository()] }} | |||
repositories={{ [project.name]: [mockAzureRepository()] }} | |||
tokenValidationFailed={false} | |||
settings={mockAlmSettingsInstance({ alm: AlmKeys.Azure })} | |||
showPersonalAccessTokenForm={false} |
@@ -32,9 +32,9 @@ it('should render correctly', () => { | |||
it('should render search results correctly', () => { | |||
const projects = [ | |||
mockAzureProject({ key: 'p1', name: 'p1' }), | |||
mockAzureProject({ key: 'p2', name: 'p2' }), | |||
mockAzureProject({ key: 'p3', name: 'p3' }) | |||
mockAzureProject({ name: 'p1', description: 'p1' }), | |||
mockAzureProject({ name: 'p2', description: 'p2' }), | |||
mockAzureProject({ name: 'p3', description: 'p3' }) | |||
]; | |||
const searchResults = { | |||
p2: [mockAzureRepository({ projectName: 'p2' })] | |||
@@ -46,7 +46,7 @@ it('should render search results correctly', () => { | |||
it('should handle pagination', () => { | |||
const projects = new Array(21) | |||
.fill(1) | |||
.map((_, i) => mockAzureProject({ key: `project-${i}`, name: `Project #${i}` })); | |||
.map((_, i) => mockAzureProject({ name: `project-${i}`, description: `Project #${i}` })); | |||
const wrapper = shallowRender({ projects }); | |||
@@ -67,7 +67,7 @@ function shallowRender(overrides: Partial<AzureProjectsListProps> = {}) { | |||
onOpenProject={jest.fn()} | |||
onSelectRepository={jest.fn()} | |||
projects={[project]} | |||
repositories={{ [project.key]: [] }} | |||
repositories={{ [project.name]: [] }} | |||
{...overrides} | |||
/> | |||
); |
@@ -6,8 +6,10 @@ exports[`should render correctly: closed 1`] = ` | |||
onClick={[Function]} | |||
open={false} | |||
title={ | |||
<h3> | |||
Azure Project | |||
<h3 | |||
title="Azure Project" | |||
> | |||
azure-project-1 | |||
</h3> | |||
} | |||
/> | |||
@@ -19,8 +21,10 @@ exports[`should render correctly: importing 1`] = ` | |||
onClick={[Function]} | |||
open={true} | |||
title={ | |||
<h3> | |||
Azure Project | |||
<h3 | |||
title="Azure Project" | |||
> | |||
azure-project-1 | |||
</h3> | |||
} | |||
> | |||
@@ -65,8 +69,10 @@ exports[`should render correctly: loading 1`] = ` | |||
onClick={[Function]} | |||
open={true} | |||
title={ | |||
<h3> | |||
Azure Project | |||
<h3 | |||
title="Azure Project" | |||
> | |||
azure-project-1 | |||
</h3> | |||
} | |||
> | |||
@@ -91,8 +97,10 @@ exports[`should render correctly: with repositories 1`] = ` | |||
onClick={[Function]} | |||
open={true} | |||
title={ | |||
<h3> | |||
Azure Project | |||
<h3 | |||
title="Azure Project" | |||
> | |||
azure-project-1 | |||
</h3> | |||
} | |||
> |
@@ -134,8 +134,8 @@ exports[`should render correctly: project list 1`] = ` | |||
projects={ | |||
Array [ | |||
Object { | |||
"key": "azure-project-1", | |||
"name": "Azure Project", | |||
"description": "Azure Project", | |||
"name": "azure-project-1", | |||
}, | |||
] | |||
} |
@@ -10,8 +10,8 @@ exports[`should render correctly: default 1`] = ` | |||
onSelectRepository={[MockFunction]} | |||
project={ | |||
Object { | |||
"key": "azure-project-1", | |||
"name": "Azure Project", | |||
"description": "Azure Project", | |||
"name": "azure-project-1", | |||
} | |||
} | |||
repositories={Array []} | |||
@@ -66,7 +66,7 @@ exports[`should render search results correctly: default 1`] = ` | |||
onSelectRepository={[MockFunction]} | |||
project={ | |||
Object { | |||
"key": "p2", | |||
"description": "p2", | |||
"name": "p2", | |||
} | |||
} |
@@ -28,8 +28,8 @@ import { | |||
export function mockAzureProject(overrides: Partial<AzureProject> = {}): AzureProject { | |||
return { | |||
key: 'azure-project-1', | |||
name: 'Azure Project', | |||
name: 'azure-project-1', | |||
description: 'Azure Project', | |||
...overrides | |||
}; | |||
} |
@@ -19,8 +19,8 @@ | |||
*/ | |||
export interface AzureProject { | |||
key: string; | |||
name: string; | |||
description: string; | |||
} | |||
export interface AzureRepository { |