- Notifications
You must be signed in to change notification settings - Fork928
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
a6f976e
8556bc9
8e7f8bd
ba52fed
1072f96
f0f7156
e965305
38a0f7b
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
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" | ||
exportdefault{ | ||
title:"components/PortForwardButton", | ||
component:PortForwardButton, | ||
} | ||
constTemplate:Story<PortForwardButtonProps>=(args)=><PortForwardButton{...args}/> | ||
exportconstClosed=Template.bind({}) | ||
Closed.args={ | ||
username:MockWorkspace.owner_name, | ||
workspaceName:MockWorkspace.name, | ||
agentName:MockWorkspaceAgent.name, | ||
} | ||
exportconstOpened=Template.bind({}) | ||
Opened.args={ | ||
username:MockWorkspace.owner_name, | ||
workspaceName:MockWorkspace.name, | ||
agentName:MockWorkspaceAgent.name, | ||
defaultIsOpen:true, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
importButtonfrom"@material-ui/core/Button" | ||
importLinkfrom"@material-ui/core/Link" | ||
importPopoverfrom"@material-ui/core/Popover" | ||
import{makeStyles}from"@material-ui/core/styles" | ||
importTextFieldfrom"@material-ui/core/TextField" | ||
importOpenInNewOutlinedfrom"@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" | ||
exportinterfacePortForwardButtonProps{ | ||
username:string | ||
workspaceName:string | ||
agentName:string | ||
defaultIsOpen?:boolean | ||
} | ||
exportconstPortForwardButton:React.FC<React.PropsWithChildren<PortForwardButtonProps>>=({ | ||
BrunoQuaresma marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
workspaceName, | ||
agentName, | ||
username, | ||
defaultIsOpen=false, | ||
})=>{ | ||
constanchorRef=useRef<HTMLButtonElement>(null) | ||
const[isOpen,setIsOpen]=useState(defaultIsOpen) | ||
constid=isOpen ?"schedule-popover" :undefined | ||
conststyles=useStyles() | ||
const[port,setPort]=useState("3000") | ||
const{ location}=window | ||
consturlExample= | ||
process.env.CODER_ENABLE_WILDCARD_APPS==="true" | ||
BrunoQuaresma marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. 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}` | ||
constonClose=()=>{ | ||
setIsOpen(false) | ||
} | ||
BrunoQuaresma marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
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", | ||
}} | ||
> | ||
<Stackdirection="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> | ||
<CodeExamplecode={urlExample}/> | ||
<HelpTooltipText> | ||
Or you can use the following form to open it in a new tab. | ||
</HelpTooltipText> | ||
<Stackdirection="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> | ||
<HelpTooltipLinkhref="https://coder.com/docs/coder-oss/latest/port-forward"> | ||
Port forward | ||
</HelpTooltipLink> | ||
</HelpTooltipLinksGroup> | ||
</Stack> | ||
</Popover> | ||
</> | ||
) | ||
} | ||
constuseStyles=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], | ||
}, | ||
}, | ||
})) |