Skip to content

Commit 831189f

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

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
@@ -12,6 +12,8 @@ import { UserContext } from "../user-context";
1212
import { trackEvent } from "../Analytics";
1313
import SelectIDE from "./SelectIDE";
1414
import { PageWithSettingsSubMenu } from "./PageWithSettingsSubMenu";
15+
import CheckBox from "../components/CheckBox";
16+
import { WorkspaceTimeoutDuration } from "@gitpod/gitpod-protocol";
1517

1618
type Theme = "light" | "dark" | "system";
1719

@@ -47,6 +49,32 @@ export default function Preferences() {
4749
}
4850
};
4951

52+
const [disabledClosedTimeout, setDisabledClosedTimeout] = useState<boolean>(
53+
user?.additionalData?.disabledClosedTimeout ?? false,
54+
);
55+
const actuallySetDisabledClosedTimeout = async (value: boolean) => {
56+
try {
57+
const additionalData = user?.additionalData || {};
58+
additionalData.disabledClosedTimeout = value;
59+
await getGitpodService().server.updateLoggedInUser({ additionalData });
60+
setDisabledClosedTimeout(value);
61+
} catch (e) {
62+
alert("Cannot set custom workspace timeout: " + e.message);
63+
}
64+
};
65+
66+
const [workspaceTimeout, setWorkspaceTimeout] = useState<string>(user?.additionalData?.workspaceTimeout ?? "");
67+
const actuallySetWorkspaceTimeout = async (value: string) => {
68+
try {
69+
const timeout = WorkspaceTimeoutDuration.validate(value);
70+
const additionalData = user?.additionalData || {};
71+
additionalData.workspaceTimeout = timeout;
72+
await getGitpodService().server.updateLoggedInUser({ additionalData });
73+
} catch (e) {
74+
alert("Cannot set custom workspace timeout: " + e.message);
75+
}
76+
};
77+
5078
return (
5179
<div>
5280
<PageWithSettingsSubMenu>
@@ -142,6 +170,42 @@ export default function Preferences() {
142170
</p>
143171
</div>
144172
</div>
173+
174+
<h3 className="mt-12">Inactivity Timeout </h3>
175+
<p className="text-base text-gray-500 dark:text-gray-400">
176+
By default, workspaces stop following 30 minutes without user input (e.g. keystrokes or terminal
177+
input commands). You can increase the workspace timeout up to a maximum of 24 hours.
178+
</p>
179+
<div className="mt-4 max-w-xl">
180+
<h4>Default Inactivity Timeout</h4>
181+
<span className="flex">
182+
<input
183+
type="text"
184+
className="w-96 h-9"
185+
value={workspaceTimeout}
186+
placeholder="timeout time, such as 30m, 1h, max 24h"
187+
onChange={(e) => setWorkspaceTimeout(e.target.value)}
188+
/>
189+
<button
190+
className="secondary ml-2"
191+
onClick={() => actuallySetWorkspaceTimeout(workspaceTimeout)}
192+
>
193+
Save Changes
194+
</button>
195+
</span>
196+
<div className="mt-1">
197+
<p className="text-gray-500 dark:text-gray-400">
198+
Use minutes or hours, like <strong>30m</strong> or <strong>2h</strong>.
199+
</p>
200+
</div>
201+
202+
<CheckBox
203+
title="Keep workspace running"
204+
desc={<span>Don't change workspace inactivity timeout when closing the editor.</span>}
205+
checked={disabledClosedTimeout}
206+
onChange={(e) => actuallySetDisabledClosedTimeout(e.target.checked)}
207+
/>
208+
</div>
145209
</PageWithSettingsSubMenu>
146210
</div>
147211
);

components/gitpod-protocol/src/protocol.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ export interface AdditionalUserData {
230230
// whether the user has been migrated to team attribution.
231231
// a corresponding feature flag (team_only_attribution) triggers the migration.
232232
isMigratedToTeamOnlyAttribution?: boolean;
233+
// user globol workspace timeout
234+
workspaceTimeout?: string;
235+
disabledClosedTimeout?: boolean;
233236
}
234237
export namespace AdditionalUserData {
235238
export function set(user: User, partialData: Partial<AdditionalUserData>): User {

0 commit comments

Comments
 (0)