| 
									
										
										
										
											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-11-05 13:52:46 +01:00
										 |  |  |   fetchRepoByName, | 
					
						
							| 
									
										
										
										
											2018-08-03 09:34:39 +02:00
										 |  |  |   getFetchRepoFailure, | 
					
						
							|  |  |  |   getRepository, | 
					
						
							|  |  |  |   isFetchRepoPending | 
					
						
							|  |  |  | } from "../modules/repos"; | 
					
						
							| 
									
										
										
										
											2018-10-18 10:52:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-01 18:23:16 +02:00
										 |  |  | import { connect } from "react-redux"; | 
					
						
							| 
									
										
										
										
											2018-10-17 10:06:26 +02:00
										 |  |  | import { Route, Switch } from "react-router-dom"; | 
					
						
							| 
									
										
										
										
											2018-09-05 14:32:49 +02:00
										 |  |  | import type { Repository } from "@scm-manager/ui-types"; | 
					
						
							| 
									
										
										
										
											2018-10-18 10:52:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-05 14:32:49 +02:00
										 |  |  | import { | 
					
						
							|  |  |  |   ErrorPage, | 
					
						
							| 
									
										
										
										
											2018-10-17 10:06:26 +02:00
										 |  |  |   Loading, | 
					
						
							| 
									
										
										
										
											2018-09-05 14:32:49 +02:00
										 |  |  |   Navigation, | 
					
						
							|  |  |  |   NavLink, | 
					
						
							| 
									
										
										
										
											2018-10-17 10:06:26 +02:00
										 |  |  |   Page, | 
					
						
							| 
									
										
										
										
											2018-09-05 14:32:49 +02:00
										 |  |  |   Section | 
					
						
							|  |  |  | } from "@scm-manager/ui-components"; | 
					
						
							| 
									
										
										
										
											2018-08-01 18:23:16 +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-09-11 16:00:15 +02:00
										 |  |  | import Permissions from "../permissions/containers/Permissions"; | 
					
						
							| 
									
										
										
										
											2018-08-06 10:08:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | import type { History } from "history"; | 
					
						
							| 
									
										
										
										
											2018-08-06 15:41:20 +02:00
										 |  |  | import EditNavLink from "../components/EditNavLink"; | 
					
						
							| 
									
										
										
										
											2018-10-18 10:52:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-23 13:17:49 +02:00
										 |  |  | import BranchRoot from "./ChangesetsRoot"; | 
					
						
							| 
									
										
										
										
											2018-09-20 10:06:38 +02:00
										 |  |  | import ChangesetView from "./ChangesetView"; | 
					
						
							| 
									
										
										
										
											2018-08-23 09:10:38 +02:00
										 |  |  | import PermissionsNavLink from "../components/PermissionsNavLink"; | 
					
						
							| 
									
										
										
										
											2018-09-27 16:32:37 +02:00
										 |  |  | import Sources from "../sources/containers/Sources"; | 
					
						
							|  |  |  | import RepositoryNavLink from "../components/RepositoryNavLink"; | 
					
						
							| 
									
										
										
										
											2018-10-11 08:19:50 +02:00
										 |  |  | import { getRepositoriesLink } from "../../modules/indexResource"; | 
					
						
							| 
									
										
										
										
											2018-11-09 14:04:47 +01:00
										 |  |  | import {ExtensionPoint} from '@scm-manager/ui-extensions'; | 
					
						
							| 
									
										
										
										
											2018-08-01 18:23:16 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | type Props = { | 
					
						
							|  |  |  |   namespace: string, | 
					
						
							|  |  |  |   name: string, | 
					
						
							|  |  |  |   repository: Repository, | 
					
						
							|  |  |  |   loading: boolean, | 
					
						
							|  |  |  |   error: Error, | 
					
						
							| 
									
										
										
										
											2018-10-11 08:19:50 +02:00
										 |  |  |   repoLink: string, | 
					
						
							| 
									
										
										
										
											2018-08-01 18:23:16 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // dispatch functions
 | 
					
						
							| 
									
										
										
										
											2018-11-05 13:52:46 +01:00
										 |  |  |   fetchRepoByName: (link: string, 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-11-05 13:52:46 +01:00
										 |  |  |     const { fetchRepoByName, namespace, name, repoLink } = this.props; | 
					
						
							| 
									
										
										
										
											2018-08-01 18:23:16 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-05 13:52:46 +01:00
										 |  |  |     fetchRepoByName(repoLink, namespace, name); | 
					
						
							| 
									
										
										
										
											2018-08-01 18:23:16 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   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-10-09 11:53:06 +02:00
										 |  |  |   matches = (route: any) => { | 
					
						
							|  |  |  |     const url = this.matchedUrl(); | 
					
						
							| 
									
										
										
										
											2018-10-17 11:39:41 +02:00
										 |  |  |     const regex = new RegExp(`${url}(/branches)?/?[^/]*/changesets?.*`); | 
					
						
							| 
									
										
										
										
											2018-10-09 11:53:06 +02:00
										 |  |  |     return route.location.pathname.match(regex); | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-01 18:23:16 +02:00
										 |  |  |   render() { | 
					
						
							|  |  |  |     const { loading, error, repository, t } = this.props; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (error) { | 
					
						
							|  |  |  |       return ( | 
					
						
							|  |  |  |         <ErrorPage | 
					
						
							|  |  |  |           title={t("repository-root.error-title")} | 
					
						
							|  |  |  |           subtitle={t("repository-root.error-subtitle")} | 
					
						
							|  |  |  |           error={error} | 
					
						
							|  |  |  |         /> | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!repository || loading) { | 
					
						
							| 
									
										
										
										
											2018-08-03 09:34:39 +02:00
										 |  |  |       return <Loading />; | 
					
						
							| 
									
										
										
										
											2018-08-01 18:23:16 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const url = this.matchedUrl(); | 
					
						
							| 
									
										
										
										
											2018-11-09 14:04:47 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     const extensionProps = { | 
					
						
							|  |  |  |       repository, | 
					
						
							|  |  |  |       url | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-03 09:34:39 +02:00
										 |  |  |     return ( | 
					
						
							|  |  |  |       <Page title={repository.namespace + "/" + repository.name}> | 
					
						
							|  |  |  |         <div className="columns"> | 
					
						
							|  |  |  |           <div className="column is-three-quarters"> | 
					
						
							| 
									
										
										
										
											2018-10-16 17:04:28 +02:00
										 |  |  |             <Switch> | 
					
						
							|  |  |  |               <Route | 
					
						
							|  |  |  |                 path={url} | 
					
						
							|  |  |  |                 exact | 
					
						
							|  |  |  |                 component={() => <RepositoryDetails repository={repository} />} | 
					
						
							|  |  |  |               /> | 
					
						
							|  |  |  |               <Route | 
					
						
							|  |  |  |                 path={`${url}/edit`} | 
					
						
							|  |  |  |                 component={() => <Edit repository={repository} />} | 
					
						
							|  |  |  |               /> | 
					
						
							| 
									
										
										
										
											2018-10-17 15:54:25 +02:00
										 |  |  |               <Route | 
					
						
							|  |  |  |                 path={`${url}/permissions`} | 
					
						
							| 
									
										
										
										
											2018-10-18 15:56:51 +02:00
										 |  |  |                 render={() => ( | 
					
						
							| 
									
										
										
										
											2018-10-17 15:54:25 +02:00
										 |  |  |                   <Permissions | 
					
						
							|  |  |  |                     namespace={this.props.repository.namespace} | 
					
						
							|  |  |  |                     repoName={this.props.repository.name} | 
					
						
							|  |  |  |                   /> | 
					
						
							|  |  |  |                 )} | 
					
						
							|  |  |  |               /> | 
					
						
							| 
									
										
										
										
											2018-10-18 10:52:48 +02:00
										 |  |  |               <Route | 
					
						
							|  |  |  |                 exact | 
					
						
							|  |  |  |                 path={`${url}/changeset/:id`} | 
					
						
							|  |  |  |                 render={() => <ChangesetView repository={repository} />} | 
					
						
							|  |  |  |               /> | 
					
						
							| 
									
										
										
										
											2018-10-18 08:50:49 +02:00
										 |  |  |               <Route | 
					
						
							|  |  |  |                 path={`${url}/sources`} | 
					
						
							|  |  |  |                 exact={true} | 
					
						
							| 
									
										
										
										
											2018-10-23 10:41:10 +02:00
										 |  |  |                 render={() => ( | 
					
						
							|  |  |  |                   <Sources repository={repository} baseUrl={`${url}/sources`} /> | 
					
						
							| 
									
										
										
										
											2018-10-18 08:50:49 +02:00
										 |  |  |                 )} | 
					
						
							|  |  |  |               /> | 
					
						
							|  |  |  |               <Route | 
					
						
							|  |  |  |                 path={`${url}/sources/:revision/:path*`} | 
					
						
							| 
									
										
										
										
											2018-10-23 10:41:10 +02:00
										 |  |  |                 render={() => ( | 
					
						
							|  |  |  |                   <Sources repository={repository} baseUrl={`${url}/sources`} /> | 
					
						
							| 
									
										
										
										
											2018-10-18 08:50:49 +02:00
										 |  |  |                 )} | 
					
						
							|  |  |  |               /> | 
					
						
							| 
									
										
										
										
											2018-10-17 11:33:40 +02:00
										 |  |  |               <Route | 
					
						
							|  |  |  |                 path={`${url}/changesets`} | 
					
						
							|  |  |  |                 render={() => ( | 
					
						
							|  |  |  |                   <BranchRoot | 
					
						
							|  |  |  |                     repository={repository} | 
					
						
							|  |  |  |                     baseUrlWithBranch={`${url}/branches`} | 
					
						
							|  |  |  |                     baseUrlWithoutBranch={`${url}/changesets`} | 
					
						
							|  |  |  |                   /> | 
					
						
							|  |  |  |                 )} | 
					
						
							|  |  |  |               /> | 
					
						
							| 
									
										
										
										
											2018-10-16 17:04:28 +02:00
										 |  |  |               <Route | 
					
						
							| 
									
										
										
										
											2018-10-17 10:06:26 +02:00
										 |  |  |                 path={`${url}/branches/:branch/changesets`} | 
					
						
							| 
									
										
										
										
											2018-10-16 17:04:28 +02:00
										 |  |  |                 render={() => ( | 
					
						
							|  |  |  |                   <BranchRoot | 
					
						
							|  |  |  |                     repository={repository} | 
					
						
							| 
									
										
										
										
											2018-10-17 11:33:40 +02:00
										 |  |  |                     baseUrlWithBranch={`${url}/branches`} | 
					
						
							|  |  |  |                     baseUrlWithoutBranch={`${url}/changesets`} | 
					
						
							| 
									
										
										
										
											2018-10-16 17:04:28 +02:00
										 |  |  |                   /> | 
					
						
							|  |  |  |                 )} | 
					
						
							|  |  |  |               /> | 
					
						
							| 
									
										
										
										
											2018-11-09 14:04:47 +01:00
										 |  |  |               <ExtensionPoint name="repository.route" | 
					
						
							|  |  |  |                               props={extensionProps} | 
					
						
							|  |  |  |                               renderAll={true} | 
					
						
							|  |  |  |               /> | 
					
						
							| 
									
										
										
										
											2018-10-16 17:04:28 +02:00
										 |  |  |             </Switch> | 
					
						
							| 
									
										
										
										
											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")}> | 
					
						
							|  |  |  |                 <NavLink to={url} label={t("repository-root.information")} /> | 
					
						
							| 
									
										
										
										
											2018-10-24 10:11:42 +02:00
										 |  |  |                 <RepositoryNavLink | 
					
						
							|  |  |  |                   repository={repository} | 
					
						
							|  |  |  |                   linkName="changesets" | 
					
						
							| 
									
										
										
										
											2018-10-17 11:33:40 +02:00
										 |  |  |                   to={`${url}/changesets/`} | 
					
						
							| 
									
										
										
										
											2018-09-20 16:28:41 +02:00
										 |  |  |                   label={t("repository-root.history")} | 
					
						
							| 
									
										
										
										
											2018-10-09 11:53:06 +02:00
										 |  |  |                   activeWhenMatch={this.matches} | 
					
						
							| 
									
										
										
										
											2018-10-24 10:11:42 +02:00
										 |  |  |                   activeOnlyWhenExact={false} | 
					
						
							| 
									
										
										
										
											2018-08-23 09:10:38 +02:00
										 |  |  |                 /> | 
					
						
							| 
									
										
										
										
											2018-09-27 16:32:37 +02:00
										 |  |  |                 <RepositoryNavLink | 
					
						
							|  |  |  |                   repository={repository} | 
					
						
							|  |  |  |                   linkName="sources" | 
					
						
							|  |  |  |                   to={`${url}/sources`} | 
					
						
							|  |  |  |                   label={t("repository-root.sources")} | 
					
						
							| 
									
										
										
										
											2018-09-28 11:31:38 +02:00
										 |  |  |                   activeOnlyWhenExact={false} | 
					
						
							| 
									
										
										
										
											2018-09-20 16:28:41 +02:00
										 |  |  |                 /> | 
					
						
							| 
									
										
										
										
											2018-11-09 14:04:47 +01:00
										 |  |  |                 <ExtensionPoint name="repository.navigation" | 
					
						
							|  |  |  |                                 props={extensionProps} | 
					
						
							|  |  |  |                                 renderAll={true} | 
					
						
							|  |  |  |                 /> | 
					
						
							| 
									
										
										
										
											2018-08-23 09:10:38 +02:00
										 |  |  |                 <PermissionsNavLink | 
					
						
							|  |  |  |                   permissionUrl={`${url}/permissions`} | 
					
						
							|  |  |  |                   repository={repository} | 
					
						
							|  |  |  |                 /> | 
					
						
							| 
									
										
										
										
											2018-11-09 14:04:47 +01:00
										 |  |  |                 <EditNavLink repository={repository} editUrl={`${url}/edit`} /> | 
					
						
							| 
									
										
										
										
											2018-08-07 15:08:44 +02:00
										 |  |  |               </Section> | 
					
						
							|  |  |  |               <Section label={t("repository-root.actions-label")}> | 
					
						
							| 
									
										
										
										
											2018-08-06 10:08:28 +02:00
										 |  |  |                 <DeleteNavAction repository={repository} delete={this.delete} /> | 
					
						
							| 
									
										
										
										
											2018-08-03 09:34:39 +02:00
										 |  |  |                 <NavLink to="/repos" label={t("repository-root.back-label")} /> | 
					
						
							|  |  |  |               </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) => { | 
					
						
							|  |  |  |   const { namespace, name } = ownProps.match.params; | 
					
						
							|  |  |  |   const repository = getRepository(state, namespace, name); | 
					
						
							|  |  |  |   const loading = isFetchRepoPending(state, namespace, name); | 
					
						
							|  |  |  |   const error = getFetchRepoFailure(state, namespace, name); | 
					
						
							| 
									
										
										
										
											2018-10-11 08:19:50 +02:00
										 |  |  |   const repoLink = getRepositoriesLink(state); | 
					
						
							| 
									
										
										
										
											2018-08-01 18:23:16 +02:00
										 |  |  |   return { | 
					
						
							|  |  |  |     namespace, | 
					
						
							|  |  |  |     name, | 
					
						
							|  |  |  |     repository, | 
					
						
							|  |  |  |     loading, | 
					
						
							| 
									
										
										
										
											2018-10-11 08:19:50 +02:00
										 |  |  |     error, | 
					
						
							|  |  |  |     repoLink | 
					
						
							| 
									
										
										
										
											2018-08-01 18:23:16 +02:00
										 |  |  |   }; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const mapDispatchToProps = dispatch => { | 
					
						
							|  |  |  |   return { | 
					
						
							| 
									
										
										
										
											2018-11-05 13:52:46 +01:00
										 |  |  |     fetchRepoByName: (link: string, namespace: string, name: string) => { | 
					
						
							|  |  |  |       dispatch(fetchRepoByName(link, 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)); |