2019-10-19 16:38:07 +02:00
|
|
|
import React from 'react';
|
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
import { Loading, ErrorPage, Title } from '@scm-manager/ui-components';
|
|
|
|
|
import { Route } from 'react-router-dom';
|
|
|
|
|
import { History } from 'history';
|
|
|
|
|
import { translate } from 'react-i18next';
|
|
|
|
|
import { RepositoryRole } from '@scm-manager/ui-types';
|
|
|
|
|
import { getRepositoryRolesLink } from '../../../modules/indexResource';
|
|
|
|
|
import { ExtensionPoint } from '@scm-manager/ui-extensions';
|
2019-05-15 16:41:14 +02:00
|
|
|
import {
|
|
|
|
|
fetchRoleByName,
|
|
|
|
|
getFetchRoleFailure,
|
|
|
|
|
getRoleByName,
|
2019-10-19 16:38:07 +02:00
|
|
|
isFetchRolePending,
|
|
|
|
|
} from '../modules/roles';
|
|
|
|
|
import { withRouter } from 'react-router-dom';
|
|
|
|
|
import PermissionRoleDetail from '../components/PermissionRoleDetails';
|
|
|
|
|
import EditRepositoryRole from './EditRepositoryRole';
|
2019-05-15 13:13:48 +02:00
|
|
|
|
|
|
|
|
type Props = {
|
2019-10-19 16:38:07 +02:00
|
|
|
roleName: string;
|
|
|
|
|
role: RepositoryRole;
|
|
|
|
|
loading: boolean;
|
|
|
|
|
error: Error;
|
|
|
|
|
repositoryRolesLink: string;
|
|
|
|
|
disabled: boolean;
|
2019-05-15 13:13:48 +02:00
|
|
|
|
|
|
|
|
// dispatcher function
|
2019-10-19 16:38:07 +02:00
|
|
|
fetchRoleByName: (p1: string, p2: string) => void;
|
2019-05-15 13:13:48 +02:00
|
|
|
|
|
|
|
|
// context objects
|
2019-10-19 16:38:07 +02:00
|
|
|
t: (p: string) => string;
|
|
|
|
|
match: any;
|
|
|
|
|
history: History;
|
2019-05-15 13:13:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class SingleRepositoryRole extends React.Component<Props> {
|
|
|
|
|
componentDidMount() {
|
2019-05-15 16:41:14 +02:00
|
|
|
this.props.fetchRoleByName(
|
|
|
|
|
this.props.repositoryRolesLink,
|
2019-10-19 16:38:07 +02:00
|
|
|
this.props.roleName,
|
2019-05-15 16:41:14 +02:00
|
|
|
);
|
2019-05-15 13:13:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stripEndingSlash = (url: string) => {
|
2019-10-19 16:38:07 +02:00
|
|
|
if (url.endsWith('/')) {
|
2019-05-15 13:13:48 +02:00
|
|
|
return url.substring(0, url.length - 2);
|
|
|
|
|
}
|
|
|
|
|
return url;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
matchedUrl = () => {
|
|
|
|
|
return this.stripEndingSlash(this.props.match.url);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
const { t, loading, error, role } = this.props;
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
return (
|
|
|
|
|
<ErrorPage
|
2019-10-19 16:38:07 +02:00
|
|
|
title={t('repositoryRole.errorTitle')}
|
|
|
|
|
subtitle={t('repositoryRole.errorSubtitle')}
|
2019-05-15 13:13:48 +02:00
|
|
|
error={error}
|
|
|
|
|
/>
|
2019-05-16 10:01:33 +02:00
|
|
|
);
|
2019-05-15 13:13:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!role || loading) {
|
|
|
|
|
return <Loading />;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const url = this.matchedUrl();
|
|
|
|
|
|
|
|
|
|
const extensionProps = {
|
|
|
|
|
role,
|
2019-10-19 16:38:07 +02:00
|
|
|
url,
|
2019-05-15 13:13:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
2019-05-15 16:41:14 +02:00
|
|
|
<>
|
2019-10-19 16:38:07 +02:00
|
|
|
<Title title={t('repositoryRole.title')} />
|
2019-05-17 15:51:55 +02:00
|
|
|
<Route
|
|
|
|
|
path={`${url}/info`}
|
|
|
|
|
component={() => <PermissionRoleDetail role={role} url={url} />}
|
|
|
|
|
/>
|
|
|
|
|
<Route
|
|
|
|
|
path={`${url}/edit`}
|
|
|
|
|
exact
|
|
|
|
|
component={() => (
|
|
|
|
|
<EditRepositoryRole role={role} history={this.props.history} />
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
<ExtensionPoint
|
|
|
|
|
name="roles.route"
|
|
|
|
|
props={extensionProps}
|
|
|
|
|
renderAll={true}
|
|
|
|
|
/>
|
2019-05-15 16:41:14 +02:00
|
|
|
</>
|
2019-05-15 13:13:48 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state, ownProps) => {
|
2019-05-15 15:21:43 +02:00
|
|
|
const roleName = ownProps.match.params.role;
|
|
|
|
|
const role = getRoleByName(state, roleName);
|
|
|
|
|
const loading = isFetchRolePending(state, roleName);
|
|
|
|
|
const error = getFetchRoleFailure(state, roleName);
|
2019-05-15 13:13:48 +02:00
|
|
|
const repositoryRolesLink = getRepositoryRolesLink(state);
|
|
|
|
|
return {
|
|
|
|
|
repositoryRolesLink,
|
2019-05-15 15:21:43 +02:00
|
|
|
roleName,
|
2019-05-15 13:13:48 +02:00
|
|
|
role,
|
|
|
|
|
loading,
|
2019-10-19 16:38:07 +02:00
|
|
|
error,
|
2019-05-15 13:13:48 +02:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => {
|
|
|
|
|
return {
|
|
|
|
|
fetchRoleByName: (link: string, name: string) => {
|
|
|
|
|
dispatch(fetchRoleByName(link, name));
|
2019-10-19 16:38:07 +02:00
|
|
|
},
|
2019-05-15 13:13:48 +02:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2019-05-15 16:41:14 +02:00
|
|
|
export default withRouter(
|
|
|
|
|
connect(
|
|
|
|
|
mapStateToProps,
|
2019-10-19 16:38:07 +02:00
|
|
|
mapDispatchToProps,
|
|
|
|
|
)(translate('admin')(SingleRepositoryRole)),
|
2019-05-15 16:41:14 +02:00
|
|
|
);
|