Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
BrunoQuaresma merged 8 commits intomainfrombq/3516
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
View file
Open in desktop
Original file line numberDiff line numberDiff 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,
}
131 changes: 131 additions & 0 deletionssite/src/components/PortForwardButton/PortForwardButton.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff 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>>=({
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"
Copy link
Member

Choose a reason for hiding this comment

The 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)
}

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],
},
},
}))
6 changes: 6 additions & 0 deletionssite/src/components/Resources/Resources.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,6 +10,7 @@ import { Skeleton } from "@material-ui/lab"
import useTheme from "@material-ui/styles/useTheme"
import { CloseDropdown, OpenDropdown } from "components/DropdownArrows/DropdownArrows"
import { ErrorSummary } from "components/ErrorSummary/ErrorSummary"
import { PortForwardButton } from "components/PortForwardButton/PortForwardButton"
import { TableCellDataPrimary } from "components/TableCellData/TableCellData"
import { FC, useState } from "react"
import { getDisplayAgentStatus, getDisplayVersionStatus } from "util/workspace"
Expand DownExpand Up@@ -150,6 +151,11 @@ export const Resources: FC<React.PropsWithChildren<ResourcesProps>> = ({
{canUpdateWorkspace && agent.status === "connected" && (
<>
<SSHButton workspaceName={workspace.name} agentName={agent.name} />
<PortForwardButton
username={workspace.owner_name}
workspaceName={workspace.name}
agentName={agent.name}
/>
<TerminalLink
workspaceName={workspace.name}
agentName={agent.name}
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -226,8 +226,9 @@ const useStyles = makeStyles((theme) => ({
},

link:{
display:"flex",
display:"inline-flex",
alignItems:"center",
width:"fit-content",
},

linkIcon:{
Expand Down
4 changes: 4 additions & 0 deletionssite/webpack.common.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,9 +14,13 @@ import { Configuration, EnvironmentPlugin } from "webpack"
constenvironmentPlugin=newEnvironmentPlugin({
INSPECT_XSTATE:"",
CODER_VERSION:"main",
CODER_ENABLE_WILDCARD_APPS:"",
})
console.info(`--- Setting INSPECT_XSTATE to '${process.env.INSPECT_XSTATE||""}'`)
console.info(`--- Setting CODER_VERSION to '${process.env.CODER_VERSION||"main"}'`)
console.info(
`--- Setting CODER_ENABLE_WILDCARD_APPS to '${process.env.CODER_ENABLE_WILDCARD_APPS??""}'`,
)
console.info(`--- Setting NODE_ENV to '${process.env.NODE_ENV||""}'`)

/**
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp