Skip to content

Commit 02fa0e2

Browse files
committed
[dashboard] use new api to configure workspace timeout setting
1 parent 00c7986 commit 02fa0e2

File tree

1 file changed

+12
-29
lines changed

1 file changed

+12
-29
lines changed

components/dashboard/src/user-settings/Preferences.tsx

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44
* See License.AGPL.txt in the project root for license information.
55
*/
66

7-
import { useContext, useState } from "react";
7+
import { useContext, useEffect, useState } from "react";
88
import { getGitpodService } from "../service/service";
99
import { UserContext } from "../user-context";
1010
import { trackEvent } from "../Analytics";
1111
import SelectIDE from "./SelectIDE";
1212
import { PageWithSettingsSubMenu } from "./PageWithSettingsSubMenu";
1313
import { ThemeSelector } from "../components/ThemeSelector";
14-
import CheckBox from "../components/CheckBox";
15-
import { WorkspaceTimeoutDuration } from "@gitpod/gitpod-protocol";
1614

1715
export default function Preferences() {
1816
const { user } = useContext(UserContext);
@@ -31,32 +29,22 @@ export default function Preferences() {
3129
}
3230
};
3331

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-
4832
const [workspaceTimeout, setWorkspaceTimeout] = useState<string>(user?.additionalData?.workspaceTimeout ?? "");
4933
const actuallySetWorkspaceTimeout = async (value: string) => {
5034
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 });
5536
} catch (e) {
5637
alert("Cannot set custom workspace timeout: " + e.message);
5738
}
5839
};
5940

41+
const [allowConfigureWorkspaceTimeout, setAllowConfigureWorkspaceTimeout] = useState<boolean>(false);
42+
useEffect(() => {
43+
getGitpodService()
44+
.server.supportConfigureWorkspaceTimeout()
45+
.then((r) => setAllowConfigureWorkspaceTimeout(r));
46+
}, []);
47+
6048
return (
6149
<div>
6250
<PageWithSettingsSubMenu>
@@ -107,17 +95,19 @@ export default function Preferences() {
10795
input commands). You can increase the workspace timeout up to a maximum of 24 hours.
10896
</p>
10997
<div className="mt-4 max-w-xl">
110-
<h4>Default Inactivity Timeout</h4>
98+
<h4>Default Workspace Inactivity Timeout</h4>
11199
<span className="flex">
112100
<input
113101
type="text"
114102
className="w-96 h-9"
115103
value={workspaceTimeout}
104+
disabled={!allowConfigureWorkspaceTimeout}
116105
placeholder="timeout time, such as 30m, 1h, max 24h"
117106
onChange={(e) => setWorkspaceTimeout(e.target.value)}
118107
/>
119108
<button
120109
className="secondary ml-2"
110+
disabled={!allowConfigureWorkspaceTimeout}
121111
onClick={() => actuallySetWorkspaceTimeout(workspaceTimeout)}
122112
>
123113
Save Changes
@@ -128,13 +118,6 @@ export default function Preferences() {
128118
Use minutes or hours, like <strong>30m</strong> or <strong>2h</strong>.
129119
</p>
130120
</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-
/>
138121
</div>
139122
</PageWithSettingsSubMenu>
140123
</div>

0 commit comments

Comments
 (0)