-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: include issues and MRs in gitlab button (#2256)
- Loading branch information
Showing
2 changed files
with
67 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import React from "react"; | ||
import { DropdownItem } from "reactstrap"; | ||
|
||
import { ExternalLink } from "../../utils/components/ExternalLinks"; | ||
import { ButtonWithMenu } from "../../utils/components/buttons/Button"; | ||
|
||
function externalUrlToGitLabIdeUrl(externalUrl: string) { | ||
if (externalUrl.includes("/gitlab/")) return externalUrl.replace("/gitlab/", "/gitlab/-/ide/project/"); | ||
const url = new URL(externalUrl); | ||
const pathname = url.pathname; | ||
const newPathname = `/-/ide/project${pathname}`; | ||
url.pathname = newPathname; | ||
return url.toString(); | ||
} | ||
|
||
type GitLabLinkItemProps = { | ||
size: string; | ||
text: string; | ||
url: string; | ||
}; | ||
|
||
function GitLabLinkItem({ size, text, url }: GitLabLinkItemProps) { | ||
const onClick = () => window.open(url, "_blank"); | ||
return ( | ||
<DropdownItem onClick={onClick} size={size}> | ||
{text} | ||
</DropdownItem> | ||
); | ||
} | ||
|
||
type GitLabConnectButtonProps = { | ||
externalUrl?: string; | ||
size: string; | ||
userLogged: boolean; | ||
}; | ||
function GitLabConnectButton(props: GitLabConnectButtonProps) { | ||
const { externalUrl, userLogged } = props; | ||
if (!externalUrl) return null; | ||
const gitlabIdeUrl = externalUrlToGitLabIdeUrl(externalUrl); | ||
const size = props.size ? props.size : "md"; | ||
|
||
const gitLabIssuesUrl = `${props.externalUrl}/-/issues`; | ||
const gitLabMrUrl = `${props.externalUrl}/-/merge_requests`; | ||
|
||
const gitlabProjectButton = ( | ||
<ExternalLink className="btn-outline-rk-green" url={props.externalUrl} title="Open in GitLab" /> | ||
); | ||
|
||
const gitlabIDEButton = | ||
userLogged && gitlabIdeUrl ? <GitLabLinkItem size={size} text="Web IDE" url={gitlabIdeUrl} /> : null; | ||
|
||
return ( | ||
<div> | ||
<ButtonWithMenu color="rk-green" default={gitlabProjectButton} size={size}> | ||
<GitLabLinkItem size={size} text="Issues" url={gitLabIssuesUrl} /> | ||
<GitLabLinkItem size={size} text="Merge Requests" url={gitLabMrUrl} /> | ||
{gitlabIDEButton} | ||
</ButtonWithMenu> | ||
</div> | ||
); | ||
} | ||
|
||
export default GitLabConnectButton; | ||
export { externalUrlToGitLabIdeUrl }; |