Files
SCM-Manager/scm-ui/src/config/containers/Config.js

132 lines
3.6 KiB
JavaScript
Raw Normal View History

2019-01-18 10:10:03 +01:00
// @flow
import React from "react";
import { translate } from "react-i18next";
2019-05-16 10:01:33 +02:00
import { Route, Switch } from "react-router-dom";
2019-01-18 10:10:03 +01:00
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-05-15 14:48:12 +02:00
import CreateRepositoryRole from "../roles/containers/CreateRepositoryRole";
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">
2019-05-16 10:01:33 +02:00
<Switch>
2019-05-16 10:04:57 +02:00
<Route path={url} exact component={GlobalConfig} />
<Route
path={`${url}/role/:role`}
render={() => (
<SingleRepositoryRole
baseUrl={`${url}/roles`}
history={this.props.history}
/>
)}
/>
<Route
path={`${url}/roles`}
exact
render={() => <RepositoryRoles baseUrl={`${url}/roles`} />}
/>
<Route
path={`${url}/roles/create`}
render={() => (
<CreateRepositoryRole
history={this.props.history}
/>
)}
/>
<Route
path={`${url}/roles/:page`}
exact
render={() => (
<RepositoryRoles baseUrl={`${url}/roles`} />
)}
/>
<ExtensionPoint
name="config.route"
props={extensionProps}
renderAll={true}
/>
2019-05-16 10:01:33 +02:00
</Switch>
2019-01-18 10:10:03 +01:00
</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
2019-05-16 10:01:33 +02:00
to={`${url}/roles/`}
label={t("repositoryRole.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);