| 
									
										
										
										
											2018-08-01 18:23:16 +02:00
										 |  |  | //@flow
 | 
					
						
							|  |  |  | import React from "react"; | 
					
						
							| 
									
										
										
										
											2018-08-03 09:34:39 +02:00
										 |  |  | import { | 
					
						
							| 
									
										
										
										
											2018-08-06 10:08:28 +02:00
										 |  |  |   deleteRepo, | 
					
						
							| 
									
										
										
										
											2018-08-03 09:34:39 +02:00
										 |  |  |   fetchRepo, | 
					
						
							|  |  |  |   getFetchRepoFailure, | 
					
						
							|  |  |  |   getRepository, | 
					
						
							|  |  |  |   isFetchRepoPending | 
					
						
							|  |  |  | } from "../modules/repos"; | 
					
						
							| 
									
										
										
										
											2018-09-17 14:03:13 +02:00
										 |  |  | import {connect} from "react-redux"; | 
					
						
							|  |  |  | import {Route} from "react-router-dom"; | 
					
						
							|  |  |  | import type {Repository} from "@scm-manager/ui-types"; | 
					
						
							| 
									
										
										
										
											2018-09-05 14:32:49 +02:00
										 |  |  | import { | 
					
						
							|  |  |  |   Page, | 
					
						
							|  |  |  |   Loading, | 
					
						
							|  |  |  |   ErrorPage, | 
					
						
							|  |  |  |   Navigation, | 
					
						
							|  |  |  |   NavLink, | 
					
						
							|  |  |  |   Section | 
					
						
							|  |  |  | } from "@scm-manager/ui-components"; | 
					
						
							| 
									
										
										
										
											2018-09-17 14:03:13 +02:00
										 |  |  | import {translate} from "react-i18next"; | 
					
						
							| 
									
										
										
										
											2018-08-03 09:34:39 +02:00
										 |  |  | import RepositoryDetails from "../components/RepositoryDetails"; | 
					
						
							| 
									
										
										
										
											2018-08-06 10:08:28 +02:00
										 |  |  | import DeleteNavAction from "../components/DeleteNavAction"; | 
					
						
							| 
									
										
										
										
											2018-08-06 15:41:20 +02:00
										 |  |  | import Edit from "../containers/Edit"; | 
					
						
							| 
									
										
										
										
											2018-08-06 10:08:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-17 14:03:13 +02:00
										 |  |  | import type {History} from "history"; | 
					
						
							| 
									
										
										
										
											2018-08-06 15:41:20 +02:00
										 |  |  | import EditNavLink from "../components/EditNavLink"; | 
					
						
							| 
									
										
										
										
											2018-09-17 14:03:13 +02:00
										 |  |  | import Changesets from "../../changesets/containers/Changesets"; | 
					
						
							| 
									
										
										
										
											2018-08-01 18:23:16 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | type Props = { | 
					
						
							|  |  |  |   namespace: string, | 
					
						
							|  |  |  |   name: string, | 
					
						
							|  |  |  |   repository: Repository, | 
					
						
							|  |  |  |   loading: boolean, | 
					
						
							|  |  |  |   error: Error, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // dispatch functions
 | 
					
						
							|  |  |  |   fetchRepo: (namespace: string, name: string) => void, | 
					
						
							| 
									
										
										
										
											2018-08-06 10:08:28 +02:00
										 |  |  |   deleteRepo: (repository: Repository, () => void) => void, | 
					
						
							| 
									
										
										
										
											2018-08-01 18:23:16 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // context props
 | 
					
						
							|  |  |  |   t: string => string, | 
					
						
							| 
									
										
										
										
											2018-08-06 10:08:28 +02:00
										 |  |  |   history: History, | 
					
						
							| 
									
										
										
										
											2018-08-01 18:23:16 +02:00
										 |  |  |   match: any | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class RepositoryRoot extends React.Component<Props> { | 
					
						
							|  |  |  |   componentDidMount() { | 
					
						
							| 
									
										
										
										
											2018-09-17 14:03:13 +02:00
										 |  |  |     const {fetchRepo, namespace, name} = this.props; | 
					
						
							| 
									
										
										
										
											2018-08-01 18:23:16 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     fetchRepo(namespace, name); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   stripEndingSlash = (url: string) => { | 
					
						
							|  |  |  |     if (url.endsWith("/")) { | 
					
						
							|  |  |  |       return url.substring(0, url.length - 2); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return url; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   matchedUrl = () => { | 
					
						
							|  |  |  |     return this.stripEndingSlash(this.props.match.url); | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-06 10:08:28 +02:00
										 |  |  |   deleted = () => { | 
					
						
							|  |  |  |     this.props.history.push("/repos"); | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   delete = (repository: Repository) => { | 
					
						
							|  |  |  |     this.props.deleteRepo(repository, this.deleted); | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-01 18:23:16 +02:00
										 |  |  |   render() { | 
					
						
							| 
									
										
										
										
											2018-09-17 14:03:13 +02:00
										 |  |  |     const {loading, error, repository, t} = this.props; | 
					
						
							| 
									
										
										
										
											2018-08-01 18:23:16 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (error) { | 
					
						
							|  |  |  |       return ( | 
					
						
							|  |  |  |         <ErrorPage | 
					
						
							|  |  |  |           title={t("repository-root.error-title")} | 
					
						
							|  |  |  |           subtitle={t("repository-root.error-subtitle")} | 
					
						
							|  |  |  |           error={error} | 
					
						
							|  |  |  |         /> | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!repository || loading) { | 
					
						
							| 
									
										
										
										
											2018-09-17 14:03:13 +02:00
										 |  |  |       return <Loading/>; | 
					
						
							| 
									
										
										
										
											2018-08-01 18:23:16 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const url = this.matchedUrl(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-03 09:34:39 +02:00
										 |  |  |     return ( | 
					
						
							|  |  |  |       <Page title={repository.namespace + "/" + repository.name}> | 
					
						
							|  |  |  |         <div className="columns"> | 
					
						
							|  |  |  |           <div className="column is-three-quarters"> | 
					
						
							|  |  |  |             <Route | 
					
						
							|  |  |  |               path={url} | 
					
						
							|  |  |  |               exact | 
					
						
							| 
									
										
										
										
											2018-09-17 14:03:13 +02:00
										 |  |  |               component={() => <RepositoryDetails repository={repository}/>} | 
					
						
							| 
									
										
										
										
											2018-08-03 09:34:39 +02:00
										 |  |  |             /> | 
					
						
							| 
									
										
										
										
											2018-08-06 15:41:20 +02:00
										 |  |  |             <Route | 
					
						
							|  |  |  |               path={`${url}/edit`} | 
					
						
							| 
									
										
										
										
											2018-09-17 14:03:13 +02:00
										 |  |  |               component={() => <Edit repository={repository}/>} | 
					
						
							|  |  |  |             /> | 
					
						
							|  |  |  |             <Route | 
					
						
							| 
									
										
										
										
											2018-09-17 16:51:09 +02:00
										 |  |  |               exact | 
					
						
							|  |  |  |               path={`${url}/history`} | 
					
						
							|  |  |  |               component={() => <Changesets repository={repository}/>} | 
					
						
							|  |  |  |             /> | 
					
						
							|  |  |  |             <Route | 
					
						
							|  |  |  |               exact | 
					
						
							| 
									
										
										
										
											2018-09-17 16:31:19 +02:00
										 |  |  |               path={`${url}/history/:branch`} | 
					
						
							|  |  |  |               component={() => <Changesets repository={repository}/>} | 
					
						
							| 
									
										
										
										
											2018-08-06 15:41:20 +02:00
										 |  |  |             /> | 
					
						
							| 
									
										
										
										
											2018-08-03 09:34:39 +02:00
										 |  |  |           </div> | 
					
						
							|  |  |  |           <div className="column"> | 
					
						
							|  |  |  |             <Navigation> | 
					
						
							| 
									
										
										
										
											2018-08-07 15:08:44 +02:00
										 |  |  |               <Section label={t("repository-root.navigation-label")}> | 
					
						
							| 
									
										
										
										
											2018-09-17 14:03:13 +02:00
										 |  |  |                 <NavLink to={url} label={t("repository-root.information")}/> | 
					
						
							| 
									
										
										
										
											2018-09-17 16:51:09 +02:00
										 |  |  |                 <NavLink activeOnlyWhenExact={false} to={`${url}/history`} label={t("repository-root.history")}/> | 
					
						
							| 
									
										
										
										
											2018-09-17 14:03:13 +02:00
										 |  |  |                 <EditNavLink repository={repository} editUrl={`${url}/edit`}/> | 
					
						
							| 
									
										
										
										
											2018-08-07 15:08:44 +02:00
										 |  |  |               </Section> | 
					
						
							|  |  |  |               <Section label={t("repository-root.actions-label")}> | 
					
						
							| 
									
										
										
										
											2018-09-17 14:03:13 +02:00
										 |  |  |                 <DeleteNavAction repository={repository} delete={this.delete}/> | 
					
						
							|  |  |  |                 <NavLink to="/repos" label={t("repository-root.back-label")}/> | 
					
						
							| 
									
										
										
										
											2018-08-03 09:34:39 +02:00
										 |  |  |               </Section> | 
					
						
							|  |  |  |             </Navigation> | 
					
						
							|  |  |  |           </div> | 
					
						
							| 
									
										
										
										
											2018-08-01 18:23:16 +02:00
										 |  |  |         </div> | 
					
						
							| 
									
										
										
										
											2018-08-03 09:34:39 +02:00
										 |  |  |       </Page> | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2018-08-01 18:23:16 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const mapStateToProps = (state, ownProps) => { | 
					
						
							| 
									
										
										
										
											2018-09-17 14:03:13 +02:00
										 |  |  |   const {namespace, name} = ownProps.match.params; | 
					
						
							| 
									
										
										
										
											2018-08-01 18:23:16 +02:00
										 |  |  |   const repository = getRepository(state, namespace, name); | 
					
						
							|  |  |  |   const loading = isFetchRepoPending(state, namespace, name); | 
					
						
							|  |  |  |   const error = getFetchRepoFailure(state, namespace, name); | 
					
						
							|  |  |  |   return { | 
					
						
							|  |  |  |     namespace, | 
					
						
							|  |  |  |     name, | 
					
						
							|  |  |  |     repository, | 
					
						
							|  |  |  |     loading, | 
					
						
							|  |  |  |     error | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const mapDispatchToProps = dispatch => { | 
					
						
							|  |  |  |   return { | 
					
						
							| 
									
										
										
										
											2018-08-03 09:34:39 +02:00
										 |  |  |     fetchRepo: (namespace: string, name: string) => { | 
					
						
							|  |  |  |       dispatch(fetchRepo(namespace, name)); | 
					
						
							| 
									
										
										
										
											2018-08-06 10:08:28 +02:00
										 |  |  |     }, | 
					
						
							|  |  |  |     deleteRepo: (repository: Repository, callback: () => void) => { | 
					
						
							|  |  |  |       dispatch(deleteRepo(repository, callback)); | 
					
						
							| 
									
										
										
										
											2018-08-01 18:23:16 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default connect( | 
					
						
							|  |  |  |   mapStateToProps, | 
					
						
							|  |  |  |   mapDispatchToProps | 
					
						
							|  |  |  | )(translate("repos")(RepositoryRoot)); |