Skip to content

Commit 6ab9dc4

Browse files
iQQBotgtsiolis
andcommitted
[dashboard] add custom global timeout user preference
Co-authored-by: George Tsiolis <[email protected]>
1 parent ad26ca1 commit 6ab9dc4

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

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

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ 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";
1416

1517
export default function Preferences() {
1618
const { user } = useContext(UserContext);
@@ -29,6 +31,32 @@ export default function Preferences() {
2931
}
3032
};
3133

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+
const [workspaceTimeout, setWorkspaceTimeout] = useState<string>(user?.additionalData?.workspaceTimeout ?? "");
49+
const actuallySetWorkspaceTimeout = async (value: string) => {
50+
try {
51+
const timeout = WorkspaceTimeoutDuration.validate(value);
52+
const additionalData = user?.additionalData || {};
53+
additionalData.workspaceTimeout = timeout;
54+
await getGitpodService().server.updateLoggedInUser({ additionalData });
55+
} catch (e) {
56+
alert("Cannot set custom workspace timeout: " + e.message);
57+
}
58+
};
59+
3260
return (
3361
<div>
3462
<PageWithSettingsSubMenu>
@@ -72,6 +100,42 @@ export default function Preferences() {
72100
</p>
73101
</div>
74102
</div>
103+
104+
<h3 className="mt-12">Inactivity Timeout </h3>
105+
<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.
108+
</p>
109+
<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>
131+
132+
<CheckBox
133+
title="Keep workspace running"
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+
</div>
75139
</PageWithSettingsSubMenu>
76140
</div>
77141
);

components/gitpod-protocol/src/protocol.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,9 @@ export interface AdditionalUserData {
254254
// whether the user has been migrated to team attribution.
255255
// a corresponding feature flag (team_only_attribution) triggers the migration.
256256
isMigratedToTeamOnlyAttribution?: boolean;
257+
// user globol workspace timeout
258+
workspaceTimeout?: string;
259+
disabledClosedTimeout?: boolean;
257260
}
258261
export namespace AdditionalUserData {
259262
export function set(user: User, partialData: Partial<AdditionalUserData>): User {

0 commit comments

Comments
 (0)