2019-01-18 10:10:03 +01:00
|
|
|
// @flow
|
|
|
|
|
import React from "react";
|
|
|
|
|
import { translate } from "react-i18next";
|
|
|
|
|
import { Route } from "react-router";
|
|
|
|
|
import { ExtensionPoint } from "@scm-manager/ui-extensions";
|
|
|
|
|
import type { History } from "history";
|
|
|
|
|
import { connect } from "react-redux";
|
|
|
|
|
import { compose } from "redux";
|
2019-05-09 16:57:13 +02:00
|
|
|
import type { Links } from "@scm-manager/ui-types";
|
|
|
|
|
import { Page, Navigation, NavLink, Section } from "@scm-manager/ui-components";
|
2019-01-18 10:10:03 +01:00
|
|
|
import { getLinks } from "../../modules/indexResource";
|
2019-05-09 16:57:13 +02:00
|
|
|
import GlobalConfig from "./GlobalConfig";
|
2019-05-15 14:06:40 +02:00
|
|
|
import RepositoryRoles from "../roles/containers/RepositoryRoles";
|
|
|
|
|
import SingleRepositoryRole from "../roles/containers/SingleRepositoryRole";
|
2019-01-18 10:10:03 +01:00
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
links: Links,
|
|
|
|
|
|
|
|
|
|
// context objects
|
|
|
|
|
t: string => string,
|
|
|
|
|
match: any,
|
|
|
|
|
history: History
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class Config extends React.Component<Props> {
|
|
|
|
|
stripEndingSlash = (url: string) => {
|
|
|
|
|
if (url.endsWith("/")) {
|
|
|
|
|
return url.substring(0, url.length - 2);
|
|
|
|
|
}
|
|
|
|
|
return url;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
matchedUrl = () => {
|
|
|
|
|
return this.stripEndingSlash(this.props.match.url);
|
|
|
|
|
};
|
|
|
|
|
|
2019-05-09 16:57:13 +02:00
|
|
|
matchesRoles = (route: any) => {
|
|
|
|
|
const url = this.matchedUrl();
|
2019-05-15 14:06:40 +02:00
|
|
|
const regex = new RegExp(`${url}/role/`);
|
2019-05-09 16:57:13 +02:00
|
|
|
return route.location.pathname.match(regex);
|
|
|
|
|
};
|
|
|
|
|
|
2019-01-18 10:10:03 +01:00
|
|
|
render() {
|
|
|
|
|
const { links, t } = this.props;
|
|
|
|
|
|
|
|
|
|
const url = this.matchedUrl();
|
|
|
|
|
const extensionProps = {
|
|
|
|
|
links,
|
|
|
|
|
url
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Page>
|
|
|
|
|
<div className="columns">
|
|
|
|
|
<div className="column is-three-quarters">
|
|
|
|
|
<Route path={url} exact component={GlobalConfig} />
|
2019-05-15 12:19:47 +02:00
|
|
|
<Route
|
|
|
|
|
path={`${url}/role/:role`}
|
2019-05-15 14:06:40 +02:00
|
|
|
render={() => <SingleRepositoryRole baseUrl={`${url}/roles`} />}
|
2019-05-15 12:19:47 +02:00
|
|
|
/>
|
2019-05-08 09:32:51 +02:00
|
|
|
<Route
|
|
|
|
|
path={`${url}/roles`}
|
|
|
|
|
exact
|
2019-05-15 13:13:48 +02:00
|
|
|
render={() => <RepositoryRoles baseUrl={`${url}/roles`} />}
|
2019-05-08 09:32:51 +02:00
|
|
|
/>
|
2019-05-15 12:19:47 +02:00
|
|
|
<Route
|
|
|
|
|
path={`${url}/roles/create`}
|
|
|
|
|
render={() => <CreatePermissionRole />}
|
2019-05-08 09:32:51 +02:00
|
|
|
/>
|
2019-01-18 10:10:03 +01:00
|
|
|
<ExtensionPoint
|
|
|
|
|
name="config.route"
|
|
|
|
|
props={extensionProps}
|
|
|
|
|
renderAll={true}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="column is-one-quarter">
|
|
|
|
|
<Navigation>
|
|
|
|
|
<Section label={t("config.navigationLabel")}>
|
|
|
|
|
<NavLink
|
|
|
|
|
to={`${url}`}
|
|
|
|
|
label={t("config.globalConfigurationNavLink")}
|
|
|
|
|
/>
|
2019-05-08 09:32:51 +02:00
|
|
|
<NavLink
|
|
|
|
|
to={`${url}/roles`}
|
2019-05-08 13:13:50 +02:00
|
|
|
label={t("roles.navLink")}
|
2019-05-09 16:57:13 +02:00
|
|
|
activeWhenMatch={this.matchesRoles}
|
2019-05-08 09:32:51 +02:00
|
|
|
/>
|
2019-01-18 10:10:03 +01:00
|
|
|
<ExtensionPoint
|
|
|
|
|
name="config.navigation"
|
|
|
|
|
props={extensionProps}
|
|
|
|
|
renderAll={true}
|
|
|
|
|
/>
|
|
|
|
|
</Section>
|
|
|
|
|
</Navigation>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</Page>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state: any) => {
|
|
|
|
|
const links = getLinks(state);
|
|
|
|
|
return {
|
|
|
|
|
links
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default compose(
|
|
|
|
|
connect(mapStateToProps),
|
|
|
|
|
translate("config")
|
|
|
|
|
)(Config);
|