Skip to content

Commit ce51dae

Browse files
committed
[dashboard] add custom global timeout user preference
1 parent cca07f1 commit ce51dae

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

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

Lines changed: 59 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,37 @@ export default function Preferences() {
142170
</p>
143171
</div>
144172
</div>
173+
174+
<h3 className="mt-12">Timeout </h3>
175+
<p className="text-base text-gray-500 dark:text-gray-400">Customize timeout setting for workspace.</p>
176+
<div className="mt-4 max-w-xl">
177+
<h4>Workspace timeout</h4>
178+
<span className="flex">
179+
<input
180+
type="text"
181+
className="w-96 h-9"
182+
value={workspaceTimeout}
183+
placeholder="timeout time, such as 30m, 1h, max 24h"
184+
onChange={(e) => setWorkspaceTimeout(e.target.value)}
185+
/>
186+
<button
187+
className="secondary ml-2"
188+
onClick={() => actuallySetWorkspaceTimeout(workspaceTimeout)}
189+
>
190+
Save Changes
191+
</button>
192+
</span>
193+
<div className="mt-1">
194+
<p className="text-gray-500 dark:text-gray-400">some description</p>
195+
</div>
196+
197+
<CheckBox
198+
title="Disabled Close Timeout"
199+
desc={<span></span>}
200+
checked={disabledClosedTimeout}
201+
onChange={(e) => actuallySetDisabledClosedTimeout(e.target.checked)}
202+
/>
203+
</div>
145204
</PageWithSettingsSubMenu>
146205
</div>
147206
);

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)