@@ -12,6 +12,8 @@ import { UserContext } from "../user-context";
12
12
import { trackEvent } from "../Analytics" ;
13
13
import SelectIDE from "./SelectIDE" ;
14
14
import { PageWithSettingsSubMenu } from "./PageWithSettingsSubMenu" ;
15
+ import CheckBox from "../components/CheckBox" ;
16
+ import { WorkspaceTimeoutDuration } from "@gitpod/gitpod-protocol" ;
15
17
16
18
type Theme = "light" | "dark" | "system" ;
17
19
@@ -47,6 +49,32 @@ export default function Preferences() {
47
49
}
48
50
} ;
49
51
52
+ const [ disabledClosedTimeout , setDisabledClosedTimeout ] = useState < boolean > (
53
+ user ?. additionalData ?. disabledClosedTimeout ?? false ,
54
+ ) ;
55
+ const actuallySetDisabledClosedTimeout = async ( value : boolean ) => {
56
+ try {
57
+ const additionalData = user ?. additionalData || { } ;
58
+ additionalData . disabledClosedTimeout = value ;
59
+ await getGitpodService ( ) . server . updateLoggedInUser ( { additionalData } ) ;
60
+ setDisabledClosedTimeout ( value ) ;
61
+ } catch ( e ) {
62
+ alert ( "Cannot set custom workspace timeout: " + e . message ) ;
63
+ }
64
+ } ;
65
+
66
+ const [ workspaceTimeout , setWorkspaceTimeout ] = useState < string > ( user ?. additionalData ?. workspaceTimeout ?? "" ) ;
67
+ const actuallySetWorkspaceTimeout = async ( value : string ) => {
68
+ try {
69
+ const timeout = WorkspaceTimeoutDuration . validate ( value ) ;
70
+ const additionalData = user ?. additionalData || { } ;
71
+ additionalData . workspaceTimeout = timeout ;
72
+ await getGitpodService ( ) . server . updateLoggedInUser ( { additionalData } ) ;
73
+ } catch ( e ) {
74
+ alert ( "Cannot set custom workspace timeout: " + e . message ) ;
75
+ }
76
+ } ;
77
+
50
78
return (
51
79
< div >
52
80
< PageWithSettingsSubMenu >
@@ -142,6 +170,37 @@ export default function Preferences() {
142
170
</ p >
143
171
</ div >
144
172
</ div >
173
+
174
+ < h3 className = "mt-12" > Timeout </ h3 >
175
+ < p className = "text-base text-gray-500 dark:text-gray-400" > Customize timeout setting for workspace.</ p >
176
+ < div className = "mt-4 max-w-xl" >
177
+ < h4 > Workspace timeout</ h4 >
178
+ < span className = "flex" >
179
+ < input
180
+ type = "text"
181
+ className = "w-96 h-9"
182
+ value = { workspaceTimeout }
183
+ placeholder = "timeout time, such as 30m, 1h, max 24h"
184
+ onChange = { ( e ) => setWorkspaceTimeout ( e . target . value ) }
185
+ />
186
+ < button
187
+ className = "secondary ml-2"
188
+ onClick = { ( ) => actuallySetWorkspaceTimeout ( workspaceTimeout ) }
189
+ >
190
+ Save Changes
191
+ </ button >
192
+ </ span >
193
+ < div className = "mt-1" >
194
+ < p className = "text-gray-500 dark:text-gray-400" > some description</ p >
195
+ </ div >
196
+
197
+ < CheckBox
198
+ title = "Disabled Close Timeout"
199
+ desc = { < span > </ span > }
200
+ checked = { disabledClosedTimeout }
201
+ onChange = { ( e ) => actuallySetDisabledClosedTimeout ( e . target . checked ) }
202
+ />
203
+ </ div >
145
204
</ PageWithSettingsSubMenu >
146
205
</ div >
147
206
) ;
0 commit comments