Skip to content

Commit 9ee6e9d

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

File tree

1 file changed

+48
-52
lines changed

1 file changed

+48
-52
lines changed

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

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

7-
import { useContext, useState } from "react";
7+
import { useCallback, 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";
15+
import { Link } from "react-router-dom";
1616

1717
export default function Preferences() {
1818
const { user } = useContext(UserContext);
@@ -31,31 +31,21 @@ export default function Preferences() {
3131
}
3232
};
3333

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-
4834
const [workspaceTimeout, setWorkspaceTimeout] = useState<string>(user?.additionalData?.workspaceTimeout ?? "");
49-
const actuallySetWorkspaceTimeout = async (value: string) => {
35+
const actuallySetWorkspaceTimeout = useCallback(async (value: string) => {
5036
try {
51-
const timeout = WorkspaceTimeoutDuration.validate(value);
52-
const additionalData = user?.additionalData || {};
53-
additionalData.workspaceTimeout = timeout;
54-
await getGitpodService().server.updateLoggedInUser({ additionalData });
37+
await getGitpodService().server.updateWorkspaceTimeoutSetting({ workspaceTimeout: value });
5538
} catch (e) {
5639
alert("Cannot set custom workspace timeout: " + e.message);
5740
}
58-
};
41+
}, []);
42+
43+
const [allowConfigureWorkspaceTimeout, setAllowConfigureWorkspaceTimeout] = useState<boolean>(false);
44+
useEffect(() => {
45+
getGitpodService()
46+
.server.supportConfigureWorkspaceTimeout()
47+
.then((r) => setAllowConfigureWorkspaceTimeout(r));
48+
}, []);
5949

6050
return (
6151
<div>
@@ -103,38 +93,44 @@ export default function Preferences() {
10393

10494
<h3 className="mt-12">Inactivity Timeout </h3>
10595
<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.
96+
Workspaces will stop after a period of inactivity without any user input.
10897
</p>
10998
<div className="mt-4 max-w-xl">
110-
<h4>Default Inactivity Timeout</h4>
111-
<span className="flex">
112-
<input
113-
type="text"
114-
className="w-96 h-9"
115-
value={workspaceTimeout}
116-
placeholder="timeout time, such as 30m, 1h, max 24h"
117-
onChange={(e) => setWorkspaceTimeout(e.target.value)}
118-
/>
119-
<button
120-
className="secondary ml-2"
121-
onClick={() => actuallySetWorkspaceTimeout(workspaceTimeout)}
122-
>
123-
Save Changes
124-
</button>
125-
</span>
126-
<div className="mt-1">
127-
<p className="text-gray-500 dark:text-gray-400">
128-
Use minutes or hours, like <strong>30m</strong> or <strong>2h</strong>.
129-
</p>
130-
</div>
99+
<h4>Default Workspace Timeout</h4>
100+
101+
{!allowConfigureWorkspaceTimeout && (
102+
<Alert type="message">
103+
Upgrade organization <Link to="/billing">billing</Link> plan to use a custom inactivity
104+
timeout.
105+
</Alert>
106+
)}
131107

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-
/>
108+
{allowConfigureWorkspaceTimeout && (
109+
<>
110+
<span className="flex mt-2">
111+
<input
112+
type="text"
113+
className="w-96 h-9"
114+
value={workspaceTimeout}
115+
disabled={!allowConfigureWorkspaceTimeout}
116+
placeholder="e.g. 30m"
117+
onChange={(e) => setWorkspaceTimeout(e.target.value)}
118+
/>
119+
<button
120+
className="secondary ml-2"
121+
disabled={!allowConfigureWorkspaceTimeout}
122+
onClick={() => actuallySetWorkspaceTimeout(workspaceTimeout)}
123+
>
124+
Save Changes
125+
</button>
126+
</span>
127+
<div className="mt-1">
128+
<p className="text-gray-500 dark:text-gray-400">
129+
Use minutes or hours, like <strong>30m</strong> or <strong>2h</strong>.
130+
</p>
131+
</div>
132+
</>
133+
)}
138134
</div>
139135
</PageWithSettingsSubMenu>
140136
</div>

0 commit comments

Comments
 (0)