2019-10-19 16:38:07 +02:00
|
|
|
import React from 'react';
|
2019-08-28 13:34:55 +02:00
|
|
|
import {
|
|
|
|
|
fetchRepoByName,
|
|
|
|
|
getFetchRepoFailure,
|
|
|
|
|
getRepository,
|
2019-10-19 16:38:07 +02:00
|
|
|
isFetchRepoPending,
|
|
|
|
|
} from '../modules/repos';
|
2019-08-28 13:34:55 +02:00
|
|
|
|
2019-10-19 16:38:07 +02:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
import { Redirect, Route, Switch } from 'react-router-dom';
|
|
|
|
|
import { Repository } from '@scm-manager/ui-types';
|
2019-08-28 13:34:55 +02:00
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
ErrorPage,
|
|
|
|
|
Loading,
|
|
|
|
|
Navigation,
|
|
|
|
|
NavLink,
|
|
|
|
|
Page,
|
|
|
|
|
Section,
|
2019-10-19 16:38:07 +02:00
|
|
|
SubNavigation,
|
|
|
|
|
} from '@scm-manager/ui-components';
|
|
|
|
|
import { translate } from 'react-i18next';
|
|
|
|
|
import RepositoryDetails from '../components/RepositoryDetails';
|
|
|
|
|
import EditRepo from './EditRepo';
|
|
|
|
|
import BranchesOverview from '../branches/containers/BranchesOverview';
|
|
|
|
|
import CreateBranch from '../branches/containers/CreateBranch';
|
|
|
|
|
import Permissions from '../permissions/containers/Permissions';
|
2018-08-06 10:08:28 +02:00
|
|
|
|
2019-10-19 16:38:07 +02:00
|
|
|
import { History } from 'history';
|
|
|
|
|
import EditRepoNavLink from '../components/EditRepoNavLink';
|
|
|
|
|
import BranchRoot from '../branches/containers/BranchRoot';
|
|
|
|
|
import ChangesetsRoot from './ChangesetsRoot';
|
|
|
|
|
import ChangesetView from './ChangesetView';
|
|
|
|
|
import PermissionsNavLink from '../components/PermissionsNavLink';
|
|
|
|
|
import Sources from '../sources/containers/Sources';
|
|
|
|
|
import RepositoryNavLink from '../components/RepositoryNavLink';
|
|
|
|
|
import { getLinks, getRepositoriesLink } from '../../modules/indexResource';
|
|
|
|
|
import { binder, ExtensionPoint } from '@scm-manager/ui-extensions';
|
2018-08-01 18:23:16 +02:00
|
|
|
|
|
|
|
|
type Props = {
|
2019-10-19 16:38:07 +02:00
|
|
|
namespace: string;
|
|
|
|
|
name: string;
|
|
|
|
|
repository: Repository;
|
|
|
|
|
loading: boolean;
|
|
|
|
|
error: Error;
|
|
|
|
|
repoLink: string;
|
|
|
|
|
indexLinks: object;
|
2018-08-01 18:23:16 +02:00
|
|
|
|
|
|
|
|
// dispatch functions
|
2019-10-19 16:38:07 +02:00
|
|
|
fetchRepoByName: (link: string, namespace: string, name: string) => void;
|
2018-08-01 18:23:16 +02:00
|
|
|
|
|
|
|
|
// context props
|
2019-10-19 16:38:07 +02:00
|
|
|
t: (p: string) => string;
|
|
|
|
|
history: History;
|
|
|
|
|
match: any;
|
2018-08-01 18:23:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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) => {
|
2019-10-19 16:38:07 +02:00
|
|
|
if (url.endsWith('/')) {
|
2019-03-07 17:49:20 +01:00
|
|
|
return url.substring(0, url.length - 1);
|
2018-08-01 18:23:16 +02:00
|
|
|
}
|
|
|
|
|
return url;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
matchedUrl = () => {
|
|
|
|
|
return this.stripEndingSlash(this.props.match.url);
|
|
|
|
|
};
|
|
|
|
|
|
2019-03-29 10:22:54 +01:00
|
|
|
matchesBranches = (route: any) => {
|
|
|
|
|
const url = this.matchedUrl();
|
2019-03-29 13:52:19 +01:00
|
|
|
const regex = new RegExp(`${url}/branch/.+/info`);
|
2019-03-29 10:22:54 +01:00
|
|
|
return route.location.pathname.match(regex);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
matchesChangesets = (route: any) => {
|
2018-10-09 11:53:06 +02:00
|
|
|
const url = this.matchedUrl();
|
2019-03-28 10:16:19 +01:00
|
|
|
const regex = new RegExp(`${url}(/branch)?/?[^/]*/changesets?.*`);
|
2018-10-09 11:53:06 +02:00
|
|
|
return route.location.pathname.match(regex);
|
|
|
|
|
};
|
|
|
|
|
|
2018-08-01 18:23:16 +02:00
|
|
|
render() {
|
2019-02-01 10:04:37 +01:00
|
|
|
const { loading, error, indexLinks, repository, t } = this.props;
|
2018-08-01 18:23:16 +02:00
|
|
|
|
|
|
|
|
if (error) {
|
2019-03-28 14:47:57 +01:00
|
|
|
return (
|
|
|
|
|
<ErrorPage
|
2019-10-19 16:38:07 +02:00
|
|
|
title={t('repositoryRoot.errorTitle')}
|
|
|
|
|
subtitle={t('repositoryRoot.errorSubtitle')}
|
2019-03-28 14:47:57 +01:00
|
|
|
error={error}
|
|
|
|
|
/>
|
|
|
|
|
);
|
2018-08-01 18:23:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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,
|
2019-02-01 10:04:37 +01:00
|
|
|
url,
|
2019-10-19 16:38:07 +02:00
|
|
|
indexLinks,
|
2018-11-09 14:04:47 +01:00
|
|
|
};
|
|
|
|
|
|
2019-03-28 14:47:57 +01:00
|
|
|
const redirectUrlFactory = binder.getExtension(
|
2019-10-19 16:38:07 +02:00
|
|
|
'repository.redirect',
|
|
|
|
|
this.props,
|
2019-03-28 14:47:57 +01:00
|
|
|
);
|
2019-03-07 17:49:20 +01:00
|
|
|
let redirectedUrl;
|
2019-03-28 14:47:57 +01:00
|
|
|
if (redirectUrlFactory) {
|
2019-03-06 17:24:50 +01:00
|
|
|
redirectedUrl = url + redirectUrlFactory(this.props);
|
2019-03-28 14:47:57 +01:00
|
|
|
} else {
|
2019-10-19 16:38:07 +02:00
|
|
|
redirectedUrl = url + '/info';
|
2019-03-06 17:24:50 +01:00
|
|
|
}
|
|
|
|
|
|
2018-08-03 09:34:39 +02:00
|
|
|
return (
|
2019-10-19 16:38:07 +02:00
|
|
|
<Page title={repository.namespace + '/' + repository.name}>
|
2018-08-03 09:34:39 +02:00
|
|
|
<div className="columns">
|
2019-07-24 08:56:12 +02:00
|
|
|
<div className="column is-three-quarters">
|
2018-10-16 17:04:28 +02:00
|
|
|
<Switch>
|
2019-03-28 14:47:57 +01:00
|
|
|
<Redirect exact from={this.props.match.url} to={redirectedUrl} />
|
2018-10-16 17:04:28 +02:00
|
|
|
<Route
|
2019-03-06 17:24:50 +01:00
|
|
|
path={`${url}/info`}
|
2018-10-16 17:04:28 +02:00
|
|
|
exact
|
|
|
|
|
component={() => <RepositoryDetails repository={repository} />}
|
|
|
|
|
/>
|
|
|
|
|
<Route
|
2019-01-18 17:28:38 +01:00
|
|
|
path={`${url}/settings/general`}
|
2019-01-29 08:22:43 +01:00
|
|
|
component={() => <EditRepo repository={repository} />}
|
2018-10-16 17:04:28 +02:00
|
|
|
/>
|
2018-10-17 15:54:25 +02:00
|
|
|
<Route
|
2019-01-18 17:28:38 +01:00
|
|
|
path={`${url}/settings/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={() => (
|
2019-04-03 15:19:54 +02:00
|
|
|
<ChangesetsRoot
|
2018-10-17 11:33:40 +02:00
|
|
|
repository={repository}
|
2019-03-28 10:16:19 +01:00
|
|
|
baseUrlWithBranch={`${url}/branch`}
|
2018-10-17 11:33:40 +02:00
|
|
|
baseUrlWithoutBranch={`${url}/changesets`}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
/>
|
2019-03-28 17:09:59 +01:00
|
|
|
<Route
|
2019-04-04 11:15:34 +02:00
|
|
|
path={`${url}/branch/:branch/changesets`}
|
2019-03-28 17:09:59 +01:00
|
|
|
render={() => (
|
2019-04-04 11:15:34 +02:00
|
|
|
<ChangesetsRoot
|
2019-03-28 17:09:59 +01:00
|
|
|
repository={repository}
|
2019-04-04 11:15:34 +02:00
|
|
|
baseUrlWithBranch={`${url}/branch`}
|
|
|
|
|
baseUrlWithoutBranch={`${url}/changesets`}
|
2019-03-28 17:09:59 +01:00
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
/>
|
2018-10-16 17:04:28 +02:00
|
|
|
<Route
|
2019-04-04 11:15:34 +02:00
|
|
|
path={`${url}/branch/:branch`}
|
2018-10-16 17:04:28 +02:00
|
|
|
render={() => (
|
2019-04-04 11:15:34 +02:00
|
|
|
<BranchRoot
|
2018-10-16 17:04:28 +02:00
|
|
|
repository={repository}
|
2019-04-04 11:15:34 +02:00
|
|
|
baseUrl={`${url}/branch`}
|
2018-10-16 17:04:28 +02:00
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
/>
|
2019-03-28 11:51:00 +01:00
|
|
|
<Route
|
|
|
|
|
path={`${url}/branches`}
|
2019-03-28 14:47:57 +01:00
|
|
|
exact={true}
|
2019-03-28 17:09:59 +01:00
|
|
|
render={() => (
|
|
|
|
|
<BranchesOverview
|
|
|
|
|
repository={repository}
|
|
|
|
|
baseUrl={`${url}/branch`}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2019-03-28 11:51:00 +01:00
|
|
|
/>
|
2019-03-28 10:16:19 +01:00
|
|
|
<Route
|
|
|
|
|
path={`${url}/branches/create`}
|
2019-03-28 14:47:57 +01:00
|
|
|
render={() => <CreateBranch repository={repository} />}
|
2019-03-28 10:16:19 +01:00
|
|
|
/>
|
2018-11-22 10:26:13 +01:00
|
|
|
<ExtensionPoint
|
|
|
|
|
name="repository.route"
|
|
|
|
|
props={extensionProps}
|
|
|
|
|
renderAll={true}
|
2018-11-09 14:04:47 +01:00
|
|
|
/>
|
2018-10-16 17:04:28 +02:00
|
|
|
</Switch>
|
2018-08-03 09:34:39 +02:00
|
|
|
</div>
|
|
|
|
|
<div className="column">
|
|
|
|
|
<Navigation>
|
2019-10-19 16:38:07 +02:00
|
|
|
<Section label={t('repositoryRoot.menu.navigationLabel')}>
|
2019-03-06 17:24:50 +01:00
|
|
|
<ExtensionPoint
|
|
|
|
|
name="repository.navigation.topLevel"
|
|
|
|
|
props={extensionProps}
|
|
|
|
|
renderAll={true}
|
|
|
|
|
/>
|
2019-01-23 15:42:15 +01:00
|
|
|
<NavLink
|
2019-03-06 17:24:50 +01:00
|
|
|
to={`${url}/info`}
|
2019-01-23 17:01:12 +01:00
|
|
|
icon="fas fa-info-circle"
|
2019-10-19 16:38:07 +02:00
|
|
|
label={t('repositoryRoot.menu.informationNavLink')}
|
2019-01-23 15:42:15 +01:00
|
|
|
/>
|
2019-03-28 11:51:00 +01:00
|
|
|
<RepositoryNavLink
|
|
|
|
|
repository={repository}
|
|
|
|
|
linkName="branches"
|
|
|
|
|
to={`${url}/branches/`}
|
2019-03-28 13:40:12 +01:00
|
|
|
icon="fas fa-code-branch"
|
2019-10-19 16:38:07 +02:00
|
|
|
label={t('repositoryRoot.menu.branchesNavLink')}
|
2019-03-29 10:22:54 +01:00
|
|
|
activeWhenMatch={this.matchesBranches}
|
2019-03-28 11:51:00 +01:00
|
|
|
activeOnlyWhenExact={false}
|
|
|
|
|
/>
|
2018-10-24 10:11:42 +02:00
|
|
|
<RepositoryNavLink
|
|
|
|
|
repository={repository}
|
|
|
|
|
linkName="changesets"
|
2018-10-17 11:33:40 +02:00
|
|
|
to={`${url}/changesets/`}
|
2019-03-28 13:40:12 +01:00
|
|
|
icon="fas fa-exchange-alt"
|
2019-10-19 16:38:07 +02:00
|
|
|
label={t('repositoryRoot.menu.historyNavLink')}
|
2019-03-29 10:22:54 +01:00
|
|
|
activeWhenMatch={this.matchesChangesets}
|
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`}
|
2018-12-21 13:53:59 +01:00
|
|
|
icon="fas fa-code"
|
2019-10-19 16:38:07 +02:00
|
|
|
label={t('repositoryRoot.menu.sourcesNavLink')}
|
2018-09-28 11:31:38 +02:00
|
|
|
activeOnlyWhenExact={false}
|
2018-09-20 16:28:41 +02:00
|
|
|
/>
|
2019-01-23 11:14:30 +01:00
|
|
|
<ExtensionPoint
|
|
|
|
|
name="repository.navigation"
|
|
|
|
|
props={extensionProps}
|
|
|
|
|
renderAll={true}
|
|
|
|
|
/>
|
2019-01-18 17:28:38 +01:00
|
|
|
<SubNavigation
|
|
|
|
|
to={`${url}/settings/general`}
|
2019-10-19 16:38:07 +02:00
|
|
|
label={t('repositoryRoot.menu.settingsNavLink')}
|
2019-01-18 17:28:38 +01:00
|
|
|
>
|
2019-01-29 08:22:43 +01:00
|
|
|
<EditRepoNavLink
|
2019-01-23 15:42:15 +01:00
|
|
|
repository={repository}
|
|
|
|
|
editUrl={`${url}/settings/general`}
|
|
|
|
|
/>
|
2019-01-18 17:28:38 +01:00
|
|
|
<PermissionsNavLink
|
|
|
|
|
permissionUrl={`${url}/settings/permissions`}
|
|
|
|
|
repository={repository}
|
|
|
|
|
/>
|
2019-01-23 15:42:15 +01:00
|
|
|
<ExtensionPoint
|
2019-02-07 16:55:34 +01:00
|
|
|
name="repository.setting"
|
2019-01-23 15:42:15 +01:00
|
|
|
props={extensionProps}
|
|
|
|
|
renderAll={true}
|
|
|
|
|
/>
|
2019-01-18 17:28:38 +01:00
|
|
|
</SubNavigation>
|
2018-08-07 15:08:44 +02:00
|
|
|
</Section>
|
2018-08-03 09:34:39 +02:00
|
|
|
</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);
|
2019-02-01 10:04:37 +01:00
|
|
|
const indexLinks = getLinks(state);
|
2018-08-01 18:23:16 +02:00
|
|
|
return {
|
|
|
|
|
namespace,
|
|
|
|
|
name,
|
|
|
|
|
repository,
|
|
|
|
|
loading,
|
2018-10-11 08:19:50 +02:00
|
|
|
error,
|
2019-02-01 10:04:37 +01:00
|
|
|
repoLink,
|
2019-10-19 16:38:07 +02:00
|
|
|
indexLinks,
|
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));
|
2019-10-19 16:38:07 +02:00
|
|
|
},
|
2018-08-01 18:23:16 +02:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default connect(
|
|
|
|
|
mapStateToProps,
|
2019-10-19 16:38:07 +02:00
|
|
|
mapDispatchToProps,
|
|
|
|
|
)(translate('repos')(RepositoryRoot));
|