Skip to content

fix(site): fix ports update #9221

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 2 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 1 addition & 2 deletions site/src/components/Resources/AgentRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,7 @@ export const AgentRow: FC<AgentRowProps> = ({
<PortForwardButton
host={proxy.preferredWildcardHostname}
workspaceName={workspace.name}
agentId={agent.id}
agentName={agent.name}
agent={agent}
username={workspace.owner_name}
/>
)}
Expand Down
27 changes: 14 additions & 13 deletions site/src/components/Resources/PortForwardButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { docs } from "utils/docs"
import Box from "@mui/material/Box"
import { useQuery } from "@tanstack/react-query"
import { getAgentListeningPorts } from "api/api"
import { WorkspaceAgentListeningPort } from "api/typesGenerated"
import { WorkspaceAgent, WorkspaceAgentListeningPort } from "api/typesGenerated"
import CircularProgress from "@mui/material/CircularProgress"
import { portForwardURL } from "utils/portForward"
import OpenInNewOutlined from "@mui/icons-material/OpenInNewOutlined"
Expand All @@ -23,18 +23,19 @@ export interface PortForwardButtonProps {
host: string
username: string
workspaceName: string
agentName: string
agentId: string
agent: WorkspaceAgent
}

export const PortForwardButton: React.FC<PortForwardButtonProps> = (props) => {
const anchorRef = useRef<HTMLButtonElement>(null)
const [isOpen, setIsOpen] = useState(false)
const id = isOpen ? "schedule-popover" : undefined
const styles = useStyles()
const { data: listeningPorts } = useQuery({
queryKey: ["portForward", props.agentId],
queryFn: () => getAgentListeningPorts(props.agentId),
const portsQuery = useQuery({
queryKey: ["portForward", props.agent.id],
queryFn: () => getAgentListeningPorts(props.agent.id),
enabled: props.agent.status === "connected",
refetchInterval: 5_000,
})

const onClose = () => {
Expand All @@ -44,14 +45,14 @@ export const PortForwardButton: React.FC<PortForwardButtonProps> = (props) => {
return (
<>
<SecondaryAgentButton
disabled={!listeningPorts}
disabled={!portsQuery.data}
ref={anchorRef}
onClick={() => {
setIsOpen(true)
}}
>
Ports
{listeningPorts ? (
{portsQuery.data ? (
<Box
sx={{
fontSize: 12,
Expand All @@ -67,7 +68,7 @@ export const PortForwardButton: React.FC<PortForwardButtonProps> = (props) => {
ml: 1,
}}
>
{listeningPorts.ports.length}
{portsQuery.data.ports.length}
</Box>
) : (
<CircularProgress size={10} sx={{ ml: 1 }} />
Expand All @@ -88,7 +89,7 @@ export const PortForwardButton: React.FC<PortForwardButtonProps> = (props) => {
horizontal: "right",
}}
>
<PortForwardPopoverView {...props} ports={listeningPorts?.ports} />
<PortForwardPopoverView {...props} ports={portsQuery.data?.ports} />
</Popover>
</>
)
Expand All @@ -97,7 +98,7 @@ export const PortForwardButton: React.FC<PortForwardButtonProps> = (props) => {
export const PortForwardPopoverView: React.FC<
PortForwardButtonProps & { ports?: WorkspaceAgentListeningPort[] }
> = (props) => {
const { host, workspaceName, agentName, username, ports } = props
const { host, workspaceName, agent, username, ports } = props

return (
<>
Expand All @@ -120,7 +121,7 @@ export const PortForwardPopoverView: React.FC<
const url = portForwardURL(
host,
p.port,
agentName,
agent.name,
workspaceName,
username,
)
Expand Down Expand Up @@ -192,7 +193,7 @@ export const PortForwardPopoverView: React.FC<
const url = portForwardURL(
host,
port,
agentName,
agent.name,
workspaceName,
username,
)
Expand Down