Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alexander Matyushentsev
authored and
Alexander Matyushentsev
committed
Jun 4, 2018
1 parent
2ba7eb8
commit 929f30c
Showing
13 changed files
with
290 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
@import 'node_modules/argo-ui/bundle/app/shared/styles/config'; | ||
|
||
.repos-list { | ||
&__top-panel { | ||
padding: 1em; | ||
|
||
& > .columns:first-child { | ||
font-size: 8em; | ||
text-align: center; | ||
} | ||
|
||
& > .columns:last-child { | ||
text-align: center; | ||
border-left: 2px solid $argo-color-gray-4; | ||
|
||
& > p { | ||
margin-bottom: 0; | ||
margin-top: 24px; | ||
&:first-of-type { | ||
font-size: 1.25em; | ||
} | ||
} | ||
|
||
& > button { | ||
width: 15em; | ||
} | ||
} | ||
} | ||
|
||
.argo-table-list { | ||
.argo-dropdown { | ||
float: right; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
import { DropDownMenu, MockupList, NotificationType, SlidingPanel } from 'argo-ui'; | ||
import * as PropTypes from 'prop-types'; | ||
import * as React from 'react'; | ||
import { Form, FormApi, Text } from 'react-form'; | ||
import { RouteComponentProps } from 'react-router'; | ||
|
||
import { ConnectionStateIcon, FormField, Page } from '../../../shared/components'; | ||
import { AppContext } from '../../../shared/context'; | ||
import * as models from '../../../shared/models'; | ||
import { services } from '../../../shared/services'; | ||
|
||
require('./repos-list.scss'); | ||
|
||
interface NewRepoParams { | ||
url: string; | ||
username: string; | ||
password: string; | ||
} | ||
|
||
export class ReposList extends React.Component<RouteComponentProps<any>, { repos: models.Repository[] }> { | ||
public static contextTypes = { | ||
router: PropTypes.object, | ||
apis: PropTypes.object, | ||
}; | ||
|
||
private formApi: FormApi; | ||
|
||
constructor(props: RouteComponentProps<any>) { | ||
super(props); | ||
this.state = { repos: null }; | ||
} | ||
|
||
public componentDidMount() { | ||
this.reloadRepos(); | ||
} | ||
|
||
public render() { | ||
return ( | ||
<Page title='Repositories' toolbar={{ breadcrumbs: [{title: 'Repositories'}] }}> | ||
<div className='repos-list'> | ||
<div className='row repos-list__top-panel argo-container'> | ||
|
||
<div className='columns small-7'> | ||
<i className='argo-icon-axcluster'/> | ||
</div> | ||
|
||
<div className='columns small-5'> | ||
<p>Connect your repo to deploy apps.</p> | ||
<button className='argo-button argo-button--base' onClick={() => this.showConnectRepo = true} >Connect Repo</button> | ||
<p>Successfully connected your repo?</p> | ||
<button className='argo-button argo-button--base'>Create Apps</button> | ||
</div> | ||
</div> | ||
<div className='argo-container'> | ||
{this.state.repos ? ( | ||
this.state.repos.length > 0 && ( | ||
<div className='argo-table-list'> | ||
<div className='argo-table-list__head'> | ||
<div className='row'> | ||
<div className='columns small-9'>REPOSITORY</div> | ||
<div className='columns small-3'>CONNECTION STATUS</div> | ||
</div> | ||
</div> | ||
{this.state.repos.map((repo) => ( | ||
<div className='argo-table-list__row' key={repo.repo}> | ||
<div className='row'> | ||
<div className='columns small-9'> | ||
<i className='icon argo-icon-git'/> {repo.repo} | ||
</div> | ||
<div className='columns small-3'> | ||
<ConnectionStateIcon state={repo.connectionState}/> {repo.connectionState.status} | ||
<DropDownMenu anchor={() => <button className='argo-button argo-button--light argo-button--lg argo-button--short'> | ||
<i className='fa fa-ellipsis-v'/> | ||
</button>} items={[{ | ||
title: 'Disconnect', | ||
action: () => this.disconnectRepo(repo.repo), | ||
}]}/> | ||
</div> | ||
</div> | ||
</div> | ||
))} | ||
</div> ) | ||
) : <MockupList height={50} marginTop={30}/>} | ||
</div> | ||
</div> | ||
<SlidingPanel isShown={this.showConnectRepo} onClose={() => this.showConnectRepo = false} header={( | ||
<div> | ||
<button className='argo-button argo-button--base' onClick={() => this.formApi.submitForm(null)}> | ||
Create | ||
</button> <button onClick={() => this.showConnectRepo = false} className='argo-button argo-button--base-o'> | ||
Cancel | ||
</button> | ||
</div> | ||
)}> | ||
<h4>Connect Git repo</h4> | ||
<Form onSubmit={(params) => this.connectRepo(params as NewRepoParams)} | ||
getApi={(api) => this.formApi = api} | ||
validateError={(params: NewRepoParams) => ({ | ||
url: !params.url && 'Repo URL is required', | ||
})}> | ||
{(formApi) => ( | ||
<form onSubmit={formApi.submitForm} role='form' className='width-control'> | ||
<div className='argo-form-row'> | ||
<FormField formApi={formApi} label='Repository URL' field='url' component={Text}/> | ||
</div> | ||
<div className='argo-form-row'> | ||
<FormField formApi={formApi} label='Username' field='username' component={Text}/> | ||
</div> | ||
<div className='argo-form-row'> | ||
<FormField formApi={formApi} label='Password' field='password' component={Text}/> | ||
</div> | ||
</form> | ||
)} | ||
</Form> | ||
</SlidingPanel> | ||
</Page> | ||
); | ||
} | ||
|
||
private async connectRepo(params: NewRepoParams) { | ||
try { | ||
await services.reposService.create(params); | ||
this.showConnectRepo = false; | ||
this.reloadRepos(); | ||
} catch (e) { | ||
this.appContext.apis.notifications.show({ | ||
content: e.response && e.response.text || 'Internal error', | ||
type: NotificationType.Error, | ||
}); | ||
} | ||
} | ||
|
||
private async reloadRepos() { | ||
this.setState({ repos: await services.reposService.list() }); | ||
} | ||
|
||
private async disconnectRepo(repo: string) { | ||
const confirmed = await this.appContext.apis.popup.confirm( | ||
'Disconnect repository', `Are you sure you want to disconnect '${repo}'?`); | ||
if (confirmed) { | ||
await services.reposService.delete(repo); | ||
this.reloadRepos(); | ||
} | ||
} | ||
|
||
private get showConnectRepo() { | ||
return new URLSearchParams(this.props.location.search).get('addRepo') === 'true'; | ||
} | ||
|
||
private set showConnectRepo(val: boolean) { | ||
this.appContext.router.history.push(`${this.props.match.url}?addRepo=${val}`); | ||
} | ||
|
||
private get appContext(): AppContext { | ||
return this.context as AppContext; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { ReposList } from './components/repos-list/repos-list'; | ||
|
||
export default { | ||
component: ReposList, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const ARGO_SUCCESS_COLOR = '#18BE94'; | ||
export const ARGO_FAILED_COLOR = '#E96D76'; | ||
export const ARGO_RUNNING_COLOR = '#0DADEA'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import * as React from 'react'; | ||
import * as models from '../models'; | ||
|
||
import { ARGO_FAILED_COLOR, ARGO_RUNNING_COLOR, ARGO_SUCCESS_COLOR } from './colors'; | ||
|
||
export const ConnectionStateIcon = (props: { state: models.ConnectionState }) => { | ||
let className = ''; | ||
let color = ''; | ||
|
||
switch (props.state.status) { | ||
case models.ConnectionStatuses.Successful: | ||
className = 'fa fa-check-circle'; | ||
color = ARGO_SUCCESS_COLOR; | ||
break; | ||
case models.ConnectionStatuses.Failed: | ||
className = 'fa fa-times'; | ||
color = ARGO_FAILED_COLOR; | ||
break; | ||
case models.ConnectionStatuses.Unknown: | ||
className = 'fa fa-exclamation-circle'; | ||
color = ARGO_RUNNING_COLOR; | ||
break; | ||
} | ||
return <i title={props.state.message || props.state.status} className={className} style={{ color }} />; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export * from './page'; | ||
export * from './form-field'; | ||
export * from './colors'; | ||
export * from './connection-state-icon'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
import { ApplicationsService } from './applications-service'; | ||
import { AuthService } from './auth-service'; | ||
import { RepositoriesService } from './repo-service'; | ||
import { UserService } from './user-service'; | ||
|
||
export interface Services { | ||
applications: ApplicationsService; | ||
userService: UserService; | ||
authService: AuthService; | ||
reposService: RepositoriesService; | ||
} | ||
|
||
export const services: Services = { | ||
applications: new ApplicationsService(), | ||
userService: new UserService(), | ||
authService: new AuthService(), | ||
reposService: new RepositoriesService(), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import * as models from '../models'; | ||
import requests from './requests'; | ||
|
||
export class RepositoriesService { | ||
public list(): Promise<models.Repository[]> { | ||
return requests.get('/repositories').then((res) => res.body as models.RepositoryList).then((list) => list.items || []); | ||
} | ||
|
||
public create({url, username, password}: {url: string, username: string, password: string}): Promise<models.Repository> { | ||
return requests.post('/repositories').send({ repo: url, username, password }).then((res) => res.body as models.Repository); | ||
} | ||
|
||
public delete(url: string): Promise<models.Repository> { | ||
return requests.delete(`/repositories/${encodeURIComponent(url)}`).send().then((res) => res.body as models.Repository); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters