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

110 lines
2.9 KiB
JavaScript
Raw Normal View History

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";
import GlobalPermissionRoles from "./GlobalPermissionRoles";
import GlobalPermissionRoleForm from "./GlobalPermissionRoleForm";
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();
const regex = new RegExp(`${url}/role/.+/edit`);
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-08 09:32:51 +02:00
<Route
path={`${url}/roles`}
exact
2019-05-09 15:11:55 +02:00
render={() => (
<GlobalPermissionRoles
2019-05-09 16:57:13 +02:00
baseUrl={`${url}/role`}
2019-05-09 15:11:55 +02:00
/>
)}
2019-05-08 09:32:51 +02:00
/>
2019-05-09 16:57:13 +02:00
<Route path={`${url}/role`} component={GlobalPermissionRoleForm} />
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);