diff --git a/scm-ui/ui-components/src/urls.ts b/scm-ui/ui-components/src/urls.ts index 98bdb7137b..6001dd4043 100644 --- a/scm-ui/ui-components/src/urls.ts +++ b/scm-ui/ui-components/src/urls.ts @@ -80,3 +80,10 @@ function parsePageNumber(pageAsString: string) { export function getQueryStringFromLocation(location: any) { return location.search ? queryString.parse(location.search).q : undefined; } + +export function stripEndingSlash(url: string) { + if (url.endsWith("/")) { + return url.substring(0, url.length - 1); + } + return url; +} diff --git a/scm-ui/ui-webapp/src/admin/containers/Admin.tsx b/scm-ui/ui-webapp/src/admin/containers/Admin.tsx index 505a2760a1..4701fade60 100644 --- a/scm-ui/ui-webapp/src/admin/containers/Admin.tsx +++ b/scm-ui/ui-webapp/src/admin/containers/Admin.tsx @@ -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 { - 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) => { diff --git a/scm-ui/ui-webapp/src/admin/roles/containers/SingleRepositoryRole.tsx b/scm-ui/ui-webapp/src/admin/roles/containers/SingleRepositoryRole.tsx index 9829e91157..92ff5af005 100644 --- a/scm-ui/ui-webapp/src/admin/roles/containers/SingleRepositoryRole.tsx +++ b/scm-ui/ui-webapp/src/admin/roles/containers/SingleRepositoryRole.tsx @@ -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 { 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() { diff --git a/scm-ui/ui-webapp/src/containers/Profile.tsx b/scm-ui/ui-webapp/src/containers/Profile.tsx index 4fe7bd4b61..28f69bef1a 100644 --- a/scm-ui/ui-webapp/src/containers/Profile.tsx +++ b/scm-ui/ui-webapp/src/containers/Profile.tsx @@ -44,6 +44,7 @@ import ProfileInfo from "./ProfileInfo"; import { ExtensionPoint } from "@scm-manager/ui-extensions"; import SetPublicKeys from "../users/components/publicKeys/SetPublicKeys"; import SetPublicKeyNavLink from "../users/components/navLinks/SetPublicKeysNavLink"; +import { urls } from "@scm-manager/ui-components"; type Props = RouteComponentProps & WithTranslation & { @@ -54,15 +55,8 @@ type Props = RouteComponentProps & }; class Profile extends React.Component { - 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); }; mayChangePassword = () => { diff --git a/scm-ui/ui-webapp/src/groups/containers/SingleGroup.tsx b/scm-ui/ui-webapp/src/groups/containers/SingleGroup.tsx index b38974cc0e..33492d2dc7 100644 --- a/scm-ui/ui-webapp/src/groups/containers/SingleGroup.tsx +++ b/scm-ui/ui-webapp/src/groups/containers/SingleGroup.tsx @@ -45,6 +45,7 @@ import { Details } from "./../components/table"; import { EditGroupNavLink, SetPermissionsNavLink } from "./../components/navLinks"; import EditGroup from "./EditGroup"; import SetPermissions from "../../permissions/components/SetPermissions"; +import { urls } from "@scm-manager/ui-components"; type Props = RouteComponentProps & WithTranslation & { @@ -63,15 +64,8 @@ class SingleGroup extends React.Component { this.props.fetchGroupByName(this.props.groupLink, this.props.name); } - 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() { diff --git a/scm-ui/ui-webapp/src/repos/branches/containers/BranchRoot.tsx b/scm-ui/ui-webapp/src/repos/branches/containers/BranchRoot.tsx index 713796cffa..c6671f3d93 100644 --- a/scm-ui/ui-webapp/src/repos/branches/containers/BranchRoot.tsx +++ b/scm-ui/ui-webapp/src/repos/branches/containers/BranchRoot.tsx @@ -31,6 +31,7 @@ import { fetchBranch, getBranch, getFetchBranchFailure, isFetchBranchPending } f import { ErrorNotification, Loading, NotFoundError } from "@scm-manager/ui-components"; import { History } from "history"; import queryString from "query-string"; +import { urls } from "@scm-manager/ui-components"; type Props = { repository: Repository; @@ -54,15 +55,8 @@ class BranchRoot extends React.Component { fetchBranch(repository, branchName); } - stripEndingSlash = (url: string) => { - if (url.endsWith("/")) { - return url.substring(0, url.length - 1); - } - return url; - }; - matchedUrl = () => { - return this.stripEndingSlash(this.props.match.url); + return urls.stripEndingSlash(this.props.match.url); }; render() { diff --git a/scm-ui/ui-webapp/src/repos/containers/ChangesetsRoot.tsx b/scm-ui/ui-webapp/src/repos/containers/ChangesetsRoot.tsx index 5bc0e0d6e7..62ecd0adb3 100644 --- a/scm-ui/ui-webapp/src/repos/containers/ChangesetsRoot.tsx +++ b/scm-ui/ui-webapp/src/repos/containers/ChangesetsRoot.tsx @@ -28,6 +28,7 @@ import { Repository, Branch } from "@scm-manager/ui-types"; import Changesets from "./Changesets"; import { compose } from "redux"; import CodeActionBar from "../codeSection/components/CodeActionBar"; +import { urls } from "@scm-manager/ui-components"; type Props = WithTranslation & RouteComponentProps & { @@ -38,13 +39,6 @@ type Props = WithTranslation & }; class ChangesetsRoot extends React.Component { - stripEndingSlash = (url: string) => { - if (url.endsWith("/")) { - return url.substring(0, url.length - 1); - } - return url; - }; - isBranchAvailable = () => { const { branches, selectedBranch } = this.props; return branches?.filter(b => b.name === selectedBranch).length === 0; @@ -75,7 +69,7 @@ class ChangesetsRoot extends React.Component { return null; } - const url = this.stripEndingSlash(match.url); + const url = urls.stripEndingSlash(match.url); return ( <> diff --git a/scm-ui/ui-webapp/src/repos/containers/EditRepo.tsx b/scm-ui/ui-webapp/src/repos/containers/EditRepo.tsx index e4d16dcfa8..f7b1697c71 100644 --- a/scm-ui/ui-webapp/src/repos/containers/EditRepo.tsx +++ b/scm-ui/ui-webapp/src/repos/containers/EditRepo.tsx @@ -33,6 +33,7 @@ import { ExtensionPoint } from "@scm-manager/ui-extensions"; import { compose } from "redux"; import DangerZone from "./DangerZone"; import { getLinks } from "../../modules/indexResource"; +import { urls } from "@scm-manager/ui-components"; type Props = { loading: boolean; @@ -59,15 +60,8 @@ class EditRepo extends React.Component { history.push(`/repo/${repository.namespace}/${repository.name}`); }; - 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() { diff --git a/scm-ui/ui-webapp/src/repos/containers/RepositoryRoot.tsx b/scm-ui/ui-webapp/src/repos/containers/RepositoryRoot.tsx index f3ef73bf36..2731a57b74 100644 --- a/scm-ui/ui-webapp/src/repos/containers/RepositoryRoot.tsx +++ b/scm-ui/ui-webapp/src/repos/containers/RepositoryRoot.tsx @@ -56,6 +56,7 @@ import SourceExtensions from "../sources/containers/SourceExtensions"; import { FileControlFactory, JumpToFileButton } from "@scm-manager/ui-components"; import TagsOverview from "../tags/container/TagsOverview"; import TagRoot from "../tags/container/TagRoot"; +import { urls } from "@scm-manager/ui-components"; type Props = RouteComponentProps & WithTranslation & { @@ -84,15 +85,8 @@ class RepositoryRoot extends React.Component { } } - stripEndingSlash = (url: string) => { - if (url.endsWith("/")) { - return url.substring(0, url.length - 1); - } - return url; - }; - matchedUrl = () => { - return this.stripEndingSlash(this.props.match.url); + return urls.stripEndingSlash(this.props.match.url); }; matchesBranches = (route: any) => { diff --git a/scm-ui/ui-webapp/src/repos/tags/container/TagRoot.tsx b/scm-ui/ui-webapp/src/repos/tags/container/TagRoot.tsx index 056ddd5b18..bbe8fb814b 100644 --- a/scm-ui/ui-webapp/src/repos/tags/container/TagRoot.tsx +++ b/scm-ui/ui-webapp/src/repos/tags/container/TagRoot.tsx @@ -28,6 +28,7 @@ import { Redirect, Switch, useLocation, useRouteMatch, Route } from "react-route import { apiClient, ErrorNotification, Loading } from "@scm-manager/ui-components"; import { useTranslation } from "react-i18next"; import TagView from "../components/TagView"; +import { urls } from "@scm-manager/ui-components"; type Props = { repository: Repository; @@ -65,15 +66,8 @@ const TagRoot: FC = ({ repository, baseUrl }) => { } }, [tags]); - const stripEndingSlash = (url: string) => { - if (url.endsWith("/")) { - return url.substring(0, url.length - 1); - } - return url; - }; - const matchedUrl = () => { - return stripEndingSlash(match.url); + return urls.stripEndingSlash(match.url); }; if (error) { diff --git a/scm-ui/ui-webapp/src/users/containers/SingleUser.tsx b/scm-ui/ui-webapp/src/users/containers/SingleUser.tsx index e7d0856545..0373d47b51 100644 --- a/scm-ui/ui-webapp/src/users/containers/SingleUser.tsx +++ b/scm-ui/ui-webapp/src/users/containers/SingleUser.tsx @@ -47,6 +47,7 @@ import { mustGetUsersLink } from "../../modules/indexResource"; import SetUserPassword from "../components/SetUserPassword"; import SetPermissions from "../../permissions/components/SetPermissions"; import SetPublicKeys from "../components/publicKeys/SetPublicKeys"; +import { urls } from "@scm-manager/ui-components"; type Props = RouteComponentProps & WithTranslation & { @@ -65,15 +66,8 @@ class SingleUser extends React.Component { this.props.fetchUserByName(this.props.usersLink, this.props.name); } - 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() {