Extract common function 'stripEndingSlash'

This commit is contained in:
René Pfeuffer
2020-09-18 17:20:54 +02:00
parent b1c0ec15a7
commit 4523e22feb
11 changed files with 27 additions and 83 deletions

View File

@@ -45,6 +45,7 @@ import GlobalConfig from "./GlobalConfig";
import RepositoryRoles from "../roles/containers/RepositoryRoles";
import SingleRepositoryRole from "../roles/containers/SingleRepositoryRole";
import CreateRepositoryRole from "../roles/containers/CreateRepositoryRole";
import { urls } from "@scm-manager/ui-components";
type Props = RouteComponentProps &
WithTranslation & {
@@ -54,18 +55,8 @@ type Props = RouteComponentProps &
};
class Admin extends React.Component<Props> {
stripEndingSlash = (url: string) => {
if (url.endsWith("/")) {
if (url.includes("role")) {
return url.substring(0, url.length - 2);
}
return url.substring(0, url.length - 1);
}
return url;
};
matchedUrl = () => {
return this.stripEndingSlash(this.props.match.url);
return urls.stripEndingSlash(this.props.match.url);
};
matchesRoles = (route: any) => {

View File

@@ -34,6 +34,7 @@ import { fetchRoleByName, getFetchRoleFailure, getRoleByName, isFetchRolePending
import PermissionRoleDetail from "../components/PermissionRoleDetails";
import EditRepositoryRole from "./EditRepositoryRole";
import { compose } from "redux";
import { urls } from "@scm-manager/ui-components";
type Props = WithTranslation & {
roleName: string;
@@ -56,15 +57,8 @@ class SingleRepositoryRole extends React.Component<Props> {
this.props.fetchRoleByName(this.props.repositoryRolesLink, this.props.roleName);
}
stripEndingSlash = (url: string) => {
if (url.endsWith("/")) {
return url.substring(0, url.length - 2);
}
return url;
};
matchedUrl = () => {
return this.stripEndingSlash(this.props.match.url);
return urls.stripEndingSlash(this.props.match.url);
};
render() {