-
Notifications
You must be signed in to change notification settings - Fork 928
feat: Add portforward to the UI #3812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a6f976e
feat: Add portforward to the UI
BrunoQuaresma 8556bc9
Update site/src/components/PortForwardButton/PortForwardButton.tsx
BrunoQuaresma 8e7f8bd
Merge branch 'main' of github.com:coder/coder into bq/3516
BrunoQuaresma ba52fed
Add CODER_ENABLE_WILDCARD_APPS env var
BrunoQuaresma 1072f96
Merge branch 'bq/3516' of github.com:coder/coder into bq/3516
BrunoQuaresma f0f7156
Fix portforward link
BrunoQuaresma e965305
Remove t file
BrunoQuaresma 38a0f7b
Merge branch 'main' of github.com:coder/coder into bq/3516
BrunoQuaresma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
site/src/components/PortForwardButton/PortForwardButton.stories.tsx
This file contains hidden or 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,25 @@ | ||
import { Story } from "@storybook/react" | ||
import { MockWorkspace, MockWorkspaceAgent } from "../../testHelpers/renderHelpers" | ||
import { PortForwardButton, PortForwardButtonProps } from "./PortForwardButton" | ||
|
||
export default { | ||
title: "components/PortForwardButton", | ||
component: PortForwardButton, | ||
} | ||
|
||
const Template: Story<PortForwardButtonProps> = (args) => <PortForwardButton {...args} /> | ||
|
||
export const Closed = Template.bind({}) | ||
Closed.args = { | ||
username: MockWorkspace.owner_name, | ||
workspaceName: MockWorkspace.name, | ||
agentName: MockWorkspaceAgent.name, | ||
} | ||
|
||
export const Opened = Template.bind({}) | ||
Opened.args = { | ||
username: MockWorkspace.owner_name, | ||
workspaceName: MockWorkspace.name, | ||
agentName: MockWorkspaceAgent.name, | ||
defaultIsOpen: true, | ||
} |
131 changes: 131 additions & 0 deletions
131
site/src/components/PortForwardButton/PortForwardButton.tsx
This file contains hidden or 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,131 @@ | ||
import Button from "@material-ui/core/Button" | ||
import Link from "@material-ui/core/Link" | ||
import Popover from "@material-ui/core/Popover" | ||
import { makeStyles } from "@material-ui/core/styles" | ||
import TextField from "@material-ui/core/TextField" | ||
import OpenInNewOutlined from "@material-ui/icons/OpenInNewOutlined" | ||
import { Stack } from "components/Stack/Stack" | ||
import { useRef, useState } from "react" | ||
import { colors } from "theme/colors" | ||
import { CodeExample } from "../CodeExample/CodeExample" | ||
import { HelpTooltipLink, HelpTooltipLinksGroup, HelpTooltipText } from "../Tooltips/HelpTooltip" | ||
|
||
export interface PortForwardButtonProps { | ||
username: string | ||
workspaceName: string | ||
agentName: string | ||
defaultIsOpen?: boolean | ||
} | ||
|
||
export const PortForwardButton: React.FC<React.PropsWithChildren<PortForwardButtonProps>> = ({ | ||
workspaceName, | ||
agentName, | ||
username, | ||
defaultIsOpen = false, | ||
}) => { | ||
const anchorRef = useRef<HTMLButtonElement>(null) | ||
const [isOpen, setIsOpen] = useState(defaultIsOpen) | ||
const id = isOpen ? "schedule-popover" : undefined | ||
const styles = useStyles() | ||
const [port, setPort] = useState("3000") | ||
const { location } = window | ||
const urlExample = | ||
process.env.CODER_ENABLE_WILDCARD_APPS === "true" | ||
BrunoQuaresma marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will be compiled by webpack, and isn't a dynamic environment variable at runtime. If we want to have a proper environment variable passed through, it'll have to come via the backend. |
||
? `${location.protocol}//${port}--${agentName}--${workspaceName}--${username}.${location.host}` | ||
: `${location.protocol}//${location.host}/@${username}/${workspaceName}.${agentName}/apps/${port}` | ||
|
||
const onClose = () => { | ||
setIsOpen(false) | ||
} | ||
BrunoQuaresma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return ( | ||
<> | ||
<Button | ||
startIcon={<OpenInNewOutlined />} | ||
size="small" | ||
ref={anchorRef} | ||
onClick={() => { | ||
setIsOpen(true) | ||
}} | ||
> | ||
Port forward | ||
</Button> | ||
<Popover | ||
classes={{ paper: styles.popoverPaper }} | ||
id={id} | ||
open={isOpen} | ||
anchorEl={anchorRef.current} | ||
onClose={onClose} | ||
anchorOrigin={{ | ||
vertical: "bottom", | ||
horizontal: "left", | ||
}} | ||
transformOrigin={{ | ||
vertical: "top", | ||
horizontal: "left", | ||
}} | ||
> | ||
<Stack direction="column" spacing={1}> | ||
<HelpTooltipText> | ||
You can port forward this resource by typing the{" "} | ||
<strong>port, workspace name, agent name</strong> and <strong>your username</strong> in | ||
the URL like the example below | ||
</HelpTooltipText> | ||
|
||
<CodeExample code={urlExample} /> | ||
|
||
<HelpTooltipText> | ||
Or you can use the following form to open it in a new tab. | ||
</HelpTooltipText> | ||
|
||
<Stack direction="row" spacing={1} alignItems="center"> | ||
<TextField | ||
label="Port" | ||
type="number" | ||
value={port} | ||
className={styles.portField} | ||
onChange={(e) => { | ||
setPort(e.currentTarget.value) | ||
}} | ||
/> | ||
<Link | ||
underline="none" | ||
href={urlExample} | ||
target="_blank" | ||
rel="noreferrer" | ||
className={styles.openUrlButton} | ||
> | ||
<Button>Open URL</Button> | ||
</Link> | ||
</Stack> | ||
|
||
<HelpTooltipLinksGroup> | ||
<HelpTooltipLink href="https://coder.com/docs/coder-oss/latest/port-forward"> | ||
Port forward | ||
</HelpTooltipLink> | ||
</HelpTooltipLinksGroup> | ||
</Stack> | ||
</Popover> | ||
</> | ||
) | ||
} | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
popoverPaper: { | ||
padding: `${theme.spacing(2.5)}px ${theme.spacing(3.5)}px ${theme.spacing(3.5)}px`, | ||
width: theme.spacing(46), | ||
color: theme.palette.text.secondary, | ||
marginTop: theme.spacing(0.25), | ||
}, | ||
|
||
openUrlButton: { | ||
flexShrink: 0, | ||
}, | ||
|
||
portField: { | ||
// The default border don't contrast well with the popover | ||
"& .MuiOutlinedInput-root .MuiOutlinedInput-notchedOutline": { | ||
borderColor: colors.gray[10], | ||
}, | ||
}, | ||
})) |
This file contains hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.