@@ -4,14 +4,17 @@ import CircularProgress from "@mui/material/CircularProgress";
4
4
import OpenInNewOutlined from "@mui/icons-material/OpenInNewOutlined" ;
5
5
import { type Interpolation , type Theme , useTheme } from "@emotion/react" ;
6
6
import type { FC } from "react" ;
7
- import { useQuery } from "react-query" ;
7
+ import { useQuery , useMutation } from "react-query" ;
8
8
import { docs } from "utils/docs" ;
9
- import { getAgentListeningPorts , getWorkspaceAgentSharedPorts } from "api/api" ;
9
+ import { deleteWorkspaceAgentSharedPort , getAgentListeningPorts , getWorkspaceAgentSharedPorts , postWorkspaceAgentSharedPort } from "api/api" ;
10
10
import type {
11
+ DeleteWorkspaceAgentPortShareRequest ,
12
+ UpdateWorkspaceAgentPortShareRequest ,
11
13
WorkspaceAgent ,
12
14
WorkspaceAgentListeningPort ,
13
15
WorkspaceAgentListeningPortsResponse ,
14
16
WorkspaceAgentPortShare ,
17
+ WorkspaceAgentPortShareLevel ,
15
18
WorkspaceAgentPortShares ,
16
19
} from "api/typesGenerated" ;
17
20
import { portForwardURL } from "utils/portForward" ;
@@ -37,7 +40,6 @@ import LockIcon from "@mui/icons-material/Lock";
37
40
import LockOpenIcon from "@mui/icons-material/LockOpen" ;
38
41
import IconButton from "@mui/material/IconButton" ;
39
42
import CloseIcon from "@mui/icons-material/Close" ;
40
- import Grid from "@mui/material/Grid" ;
41
43
42
44
export interface PortForwardButtonProps {
43
45
host : string ;
@@ -68,7 +70,7 @@ export const PortForwardButton: FC<PortForwardButtonProps> = (props) => {
68
70
} ) ;
69
71
70
72
const sharedPortsQuery = useQuery ( {
71
- queryKey : [ "sharedPorts" , agent . id ] ,
73
+ queryKey : [ "sharedPorts" , workspaceID ] ,
72
74
queryFn : ( ) => getWorkspaceAgentSharedPorts ( workspaceID ) ,
73
75
enabled : ! storybook && agent . status === "connected" ,
74
76
} ) ;
@@ -123,13 +125,27 @@ interface PortForwardPopoverViewProps extends PortForwardButtonProps {
123
125
export const PortForwardPopoverView : FC < PortForwardPopoverViewProps > = ( {
124
126
host,
125
127
workspaceName,
128
+ workspaceID,
126
129
agent,
127
130
username,
128
131
listeningPorts,
129
132
sharedPorts,
130
133
} ) => {
131
134
const theme = useTheme ( ) ;
132
135
136
+
137
+ const createSharedPortMutation = useMutation ( {
138
+ mutationFn : async ( options : UpdateWorkspaceAgentPortShareRequest ) => {
139
+ await postWorkspaceAgentSharedPort ( workspaceID , options ) ;
140
+ } ,
141
+ } ) ;
142
+
143
+ const deleteSharedPortMutation = useMutation ( {
144
+ mutationFn : async ( options : DeleteWorkspaceAgentPortShareRequest ) => {
145
+ await deleteWorkspaceAgentSharedPort ( workspaceID , options ) ;
146
+ } ,
147
+ } ) ;
148
+
133
149
// we don't want to show listening ports if it's already a shared port
134
150
const filteredListeningPorts = listeningPorts ?. filter (
135
151
( port ) => {
@@ -258,7 +274,15 @@ export const PortForwardPopoverView: FC<PortForwardPopoverViewProps> = ({
258
274
>
259
275
< span css = { styles . portNumber } > { port . port } </ span >
260
276
</ Link >
261
- < Button size = "small" variant = "text" >
277
+ < Button size = "small" variant = "text" onClick = {
278
+ ( ) => {
279
+ createSharedPortMutation . mutate ( {
280
+ agent_name : agent . name ,
281
+ port : port . port ,
282
+ share_level : "authenticated" ,
283
+ } ) ;
284
+ }
285
+ } >
262
286
Share
263
287
</ Button >
264
288
</ Stack >
@@ -328,7 +352,12 @@ export const PortForwardPopoverView: FC<PortForwardPopoverViewProps> = ({
328
352
< MenuItem value = "public" > Public</ MenuItem >
329
353
</ Select >
330
354
</ FormControl >
331
- < IconButton >
355
+ < IconButton onClick = { ( ) => {
356
+ deleteSharedPortMutation . mutate ( {
357
+ agent_name : agent . name ,
358
+ port : share . port ,
359
+ } ) ;
360
+ } } >
332
361
< CloseIcon
333
362
css = { {
334
363
width : 14 ,
@@ -352,11 +381,12 @@ export const PortForwardPopoverView: FC<PortForwardPopoverViewProps> = ({
352
381
>
353
382
< TextField label = "Port" variant = "outlined" size = "small" />
354
383
< FormControl size = "small" >
355
- < Select value = "Authenticated " >
356
- < MenuItem value = "Authenticated " > Authenticated</ MenuItem >
357
- < MenuItem value = "Public " > Public</ MenuItem >
384
+ < Select value = "authenticated " >
385
+ < MenuItem value = "authenticated " > Authenticated</ MenuItem >
386
+ < MenuItem value = "public " > Public</ MenuItem >
358
387
</ Select >
359
388
</ FormControl >
389
+ { /* How do I use the value from the select in the mutation? */ }
360
390
< Button variant = "contained" > Share Port</ Button >
361
391
</ Stack >
362
392
</ div >
0 commit comments