@@ -16,7 +16,7 @@ import Stack from "@mui/material/Stack";
16
16
import TextField from "@mui/material/TextField" ;
17
17
import Tooltip from "@mui/material/Tooltip" ;
18
18
import { type FormikContextType , useFormik } from "formik" ;
19
- import type { FC } from "react" ;
19
+ import { useState , type FC } from "react" ;
20
20
import { useQuery , useMutation } from "react-query" ;
21
21
import * as Yup from "yup" ;
22
22
import { getAgentListeningPorts } from "api/api" ;
@@ -48,7 +48,7 @@ import { type ClassName, useClassName } from "hooks/useClassName";
48
48
import { useDashboard } from "modules/dashboard/useDashboard" ;
49
49
import { docs } from "utils/docs" ;
50
50
import { getFormHelpers } from "utils/formUtils" ;
51
- import { portForwardURL } from "utils/portForward" ;
51
+ import { getWorkspaceListeningPortsProtocol , portForwardURL , saveWorkspaceListeningPortsProtocol } from "utils/portForward" ;
52
52
53
53
export interface PortForwardButtonProps {
54
54
host : string ;
@@ -135,6 +135,7 @@ export const PortForwardPopoverView: FC<PortForwardPopoverViewProps> = ({
135
135
portSharingControlsEnabled,
136
136
} ) => {
137
137
const theme = useTheme ( ) ;
138
+ const [ listeningPortProtocol , setListeningPortProtocol ] = useState ( getWorkspaceListeningPortsProtocol ( workspaceID ) ) ;
138
139
139
140
const sharedPortsQuery = useQuery ( {
140
141
...workspacePortShares ( workspaceID ) ,
@@ -253,52 +254,68 @@ export const PortForwardPopoverView: FC<PortForwardPopoverViewProps> = ({
253
254
? "No open ports were detected."
254
255
: "The listening ports are exclusively accessible to you." }
255
256
</ HelpTooltipText >
256
- < form
257
- css = { styles . newPortForm }
258
- onSubmit = { ( e ) => {
259
- e . preventDefault ( ) ;
260
- const formData = new FormData ( e . currentTarget ) ;
261
- const port = Number ( formData . get ( "portNumber" ) ) ;
262
- const url = portForwardURL (
263
- host ,
264
- port ,
265
- agent . name ,
266
- workspaceName ,
267
- username ,
268
- ) ;
269
- window . open ( url , "_blank" ) ;
270
- } }
271
- >
272
- < input
273
- aria-label = "Port number"
274
- name = "portNumber"
275
- type = "number"
276
- placeholder = "Connect to port..."
277
- min = { 9 }
278
- max = { 65535 }
279
- required
280
- css = { styles . newPortInput }
281
- />
282
- < Button
283
- type = "submit"
284
- size = "small"
285
- variant = "text"
286
- css = { {
287
- paddingLeft : 12 ,
288
- paddingRight : 12 ,
289
- minWidth : 0 ,
257
+ < Stack direction = "row" gap = { 1 } alignItems = "flex-end" justifyContent = "flex-end" >
258
+ < form
259
+ css = { styles . newPortForm }
260
+ onSubmit = { ( e ) => {
261
+ e . preventDefault ( ) ;
262
+ const formData = new FormData ( e . currentTarget ) ;
263
+ const port = Number ( formData . get ( "portNumber" ) ) ;
264
+ const url = portForwardURL (
265
+ host ,
266
+ port ,
267
+ agent . name ,
268
+ workspaceName ,
269
+ username ,
270
+ ) ;
271
+ window . open ( url , "_blank" ) ;
290
272
} }
291
273
>
292
- < OpenInNewOutlined
274
+ < input
275
+ aria-label = "Port number"
276
+ name = "portNumber"
277
+ type = "number"
278
+ placeholder = "Connect to port..."
279
+ min = { 9 }
280
+ max = { 65535 }
281
+ required
282
+ css = { styles . newPortInput }
283
+ />
284
+ < Button
285
+ type = "submit"
286
+ size = "small"
287
+ variant = "text"
293
288
css = { {
294
- flexShrink : 0 ,
295
- width : 14 ,
296
- height : 14 ,
297
- color : theme . palette . text . primary ,
289
+ paddingLeft : 12 ,
290
+ paddingRight : 12 ,
291
+ minWidth : 0 ,
298
292
} }
299
- />
300
- </ Button >
301
- </ form >
293
+ >
294
+ < OpenInNewOutlined
295
+ css = { {
296
+ flexShrink : 0 ,
297
+ width : 14 ,
298
+ height : 14 ,
299
+ color : theme . palette . text . primary ,
300
+ } }
301
+ />
302
+ </ Button >
303
+ </ form >
304
+ < FormControl size = "small" css = { styles . protocolFormControl } >
305
+ < Select
306
+ css = { styles . listeningPortProtocol }
307
+ value = { listeningPortProtocol }
308
+ onChange = { async ( event ) => {
309
+ const selectedProtocol = event . target . value as "http" | "https" ;
310
+ setListeningPortProtocol ( selectedProtocol ) ;
311
+ saveWorkspaceListeningPortsProtocol ( workspaceID , selectedProtocol ) ;
312
+ } }
313
+ >
314
+ < MenuItem value = "http" > HTTP</ MenuItem >
315
+ < MenuItem value = "https" > HTTPS</ MenuItem >
316
+ </ Select >
317
+ </ FormControl >
318
+ </ Stack >
302
319
</ header >
303
320
< div
304
321
css = { {
@@ -619,6 +636,22 @@ const styles = {
619
636
"&:focus-within" : {
620
637
borderColor : theme . palette . primary . main ,
621
638
} ,
639
+ width : "100%" ,
640
+ } ) ,
641
+
642
+ listeningPortProtocol : ( theme ) => ( {
643
+ boxShadow : "none" ,
644
+ ".MuiOutlinedInput-notchedOutline" : { border : 0 } ,
645
+ "&.MuiOutlinedInput-root:hover .MuiOutlinedInput-notchedOutline" : {
646
+ border : 0 ,
647
+ } ,
648
+ "&.MuiOutlinedInput-root.Mui-focused .MuiOutlinedInput-notchedOutline" : {
649
+ border : 0 ,
650
+ } ,
651
+ border : `1px solid ${ theme . palette . divider } ` ,
652
+ borderRadius : "4px" ,
653
+ marginTop : 8 ,
654
+ minWidth : "100px" ,
622
655
} ) ,
623
656
624
657
newPortInput : ( theme ) => ( {
0 commit comments