4
4
* See License.AGPL.txt in the project root for license information.
5
5
*/
6
6
7
- import { useContext , useState } from "react" ;
7
+ import { useContext , useEffect , useState } from "react" ;
8
8
import { getGitpodService } from "../service/service" ;
9
9
import { UserContext } from "../user-context" ;
10
10
import { trackEvent } from "../Analytics" ;
11
11
import SelectIDE from "./SelectIDE" ;
12
12
import { PageWithSettingsSubMenu } from "./PageWithSettingsSubMenu" ;
13
13
import { ThemeSelector } from "../components/ThemeSelector" ;
14
- import CheckBox from "../components/CheckBox" ;
15
- import { WorkspaceTimeoutDuration } from "@gitpod/gitpod-protocol" ;
16
14
17
15
export default function Preferences ( ) {
18
16
const { user } = useContext ( UserContext ) ;
@@ -31,32 +29,22 @@ export default function Preferences() {
31
29
}
32
30
} ;
33
31
34
- const [ disabledClosedTimeout , setDisabledClosedTimeout ] = useState < boolean > (
35
- user ?. additionalData ?. disabledClosedTimeout ?? false ,
36
- ) ;
37
- const actuallySetDisabledClosedTimeout = async ( value : boolean ) => {
38
- try {
39
- const additionalData = user ?. additionalData || { } ;
40
- additionalData . disabledClosedTimeout = value ;
41
- await getGitpodService ( ) . server . updateLoggedInUser ( { additionalData } ) ;
42
- setDisabledClosedTimeout ( value ) ;
43
- } catch ( e ) {
44
- alert ( "Cannot set custom workspace timeout: " + e . message ) ;
45
- }
46
- } ;
47
-
48
32
const [ workspaceTimeout , setWorkspaceTimeout ] = useState < string > ( user ?. additionalData ?. workspaceTimeout ?? "" ) ;
49
33
const actuallySetWorkspaceTimeout = async ( value : string ) => {
50
34
try {
51
- const timeout = WorkspaceTimeoutDuration . validate ( value ) ;
52
- const additionalData = user ?. additionalData || { } ;
53
- additionalData . workspaceTimeout = timeout ;
54
- await getGitpodService ( ) . server . updateLoggedInUser ( { additionalData } ) ;
35
+ await getGitpodService ( ) . server . updateWorkspaceTimeoutSetting ( { workspaceTimeout : value } ) ;
55
36
} catch ( e ) {
56
37
alert ( "Cannot set custom workspace timeout: " + e . message ) ;
57
38
}
58
39
} ;
59
40
41
+ const [ allowConfigureWorkspaceTimeout , setAllowConfigureWorkspaceTimeout ] = useState < boolean > ( false ) ;
42
+ useEffect ( ( ) => {
43
+ getGitpodService ( )
44
+ . server . supportConfigureWorkspaceTimeout ( )
45
+ . then ( ( r ) => setAllowConfigureWorkspaceTimeout ( r ) ) ;
46
+ } , [ ] ) ;
47
+
60
48
return (
61
49
< div >
62
50
< PageWithSettingsSubMenu >
@@ -107,17 +95,19 @@ export default function Preferences() {
107
95
input commands). You can increase the workspace timeout up to a maximum of 24 hours.
108
96
</ p >
109
97
< div className = "mt-4 max-w-xl" >
110
- < h4 > Default Inactivity Timeout</ h4 >
98
+ < h4 > Default Workspace Inactivity Timeout</ h4 >
111
99
< span className = "flex" >
112
100
< input
113
101
type = "text"
114
102
className = "w-96 h-9"
115
103
value = { workspaceTimeout }
104
+ disabled = { ! allowConfigureWorkspaceTimeout }
116
105
placeholder = "timeout time, such as 30m, 1h, max 24h"
117
106
onChange = { ( e ) => setWorkspaceTimeout ( e . target . value ) }
118
107
/>
119
108
< button
120
109
className = "secondary ml-2"
110
+ disabled = { ! allowConfigureWorkspaceTimeout }
121
111
onClick = { ( ) => actuallySetWorkspaceTimeout ( workspaceTimeout ) }
122
112
>
123
113
Save Changes
@@ -128,13 +118,6 @@ export default function Preferences() {
128
118
Use minutes or hours, like < strong > 30m</ strong > or < strong > 2h</ strong > .
129
119
</ p >
130
120
</ div >
131
-
132
- < CheckBox
133
- title = "Stop workspace when no active editor connection"
134
- desc = { < span > Don't change workspace inactivity timeout when closing the editor.</ span > }
135
- checked = { disabledClosedTimeout }
136
- onChange = { ( e ) => actuallySetDisabledClosedTimeout ( e . target . checked ) }
137
- />
138
121
</ div >
139
122
</ PageWithSettingsSubMenu >
140
123
</ div >
0 commit comments