Skip to content

Commit f242605

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

File tree

1 file changed

+23
-33
lines changed

1 file changed

+23
-33
lines changed

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

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
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";
14+
import Alert from "../components/Alert";
1615

1716
export default function Preferences() {
1817
const { user } = useContext(UserContext);
@@ -31,32 +30,22 @@ export default function Preferences() {
3130
}
3231
};
3332

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-
4833
const [workspaceTimeout, setWorkspaceTimeout] = useState<string>(user?.additionalData?.workspaceTimeout ?? "");
4934
const actuallySetWorkspaceTimeout = async (value: string) => {
5035
try {
51-
const timeout = WorkspaceTimeoutDuration.validate(value);
52-
const additionalData = user?.additionalData || {};
53-
additionalData.workspaceTimeout = timeout;
54-
await getGitpodService().server.updateLoggedInUser({ additionalData });
36+
await getGitpodService().server.updateWorkspaceTimeoutSetting({ workspaceTimeout: value });
5537
} catch (e) {
5638
alert("Cannot set custom workspace timeout: " + e.message);
5739
}
5840
};
5941

42+
const [allowConfigureWorkspaceTimeout, setAllowConfigureWorkspaceTimeout] = useState<boolean>(false);
43+
useEffect(() => {
44+
getGitpodService()
45+
.server.supportConfigureWorkspaceTimeout()
46+
.then((r) => setAllowConfigureWorkspaceTimeout(r));
47+
}, []);
48+
6049
return (
6150
<div>
6251
<PageWithSettingsSubMenu>
@@ -103,21 +92,29 @@ export default function Preferences() {
10392

10493
<h3 className="mt-12">Inactivity Timeout </h3>
10594
<p className="text-base text-gray-500 dark:text-gray-400">
106-
By default, workspaces stop following 30 minutes without user input (e.g. keystrokes or terminal
107-
input commands). You can increase the workspace timeout up to a maximum of 24 hours.
95+
Workspaces will stop after a period of inactivity without any user input.
10896
</p>
10997
<div className="mt-4 max-w-xl">
110-
<h4>Default Inactivity Timeout</h4>
111-
<span className="flex">
98+
<h4>Default Workspace Timeout</h4>
99+
100+
{!allowConfigureWorkspaceTimeout && (
101+
<Alert type="message">
102+
Upgrade organization <a href="/billing">billing</a> plan to use a custom inactivity timeout.
103+
</Alert>
104+
)}
105+
106+
<span className="flex mt-2">
112107
<input
113108
type="text"
114109
className="w-96 h-9"
115110
value={workspaceTimeout}
116-
placeholder="timeout time, such as 30m, 1h, max 24h"
111+
disabled={!allowConfigureWorkspaceTimeout}
112+
placeholder="e.g. 30m"
117113
onChange={(e) => setWorkspaceTimeout(e.target.value)}
118114
/>
119115
<button
120116
className="secondary ml-2"
117+
disabled={!allowConfigureWorkspaceTimeout}
121118
onClick={() => actuallySetWorkspaceTimeout(workspaceTimeout)}
122119
>
123120
Save Changes
@@ -128,13 +125,6 @@ export default function Preferences() {
128125
Use minutes or hours, like <strong>30m</strong> or <strong>2h</strong>.
129126
</p>
130127
</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-
/>
138128
</div>
139129
</PageWithSettingsSubMenu>
140130
</div>

0 commit comments

Comments
 (0)