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