Skip to content

[dashboard] Fix user preferences workspace timeouts alert #20619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Copyright (c) 2025 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License.AGPL.txt in the project root for license information.
*/

import { WORKSPACE_TIMEOUT_DEFAULT_LONG, WORKSPACE_TIMEOUT_DEFAULT_SHORT } from "@gitpod/gitpod-protocol";
import { useOrgBillingMode } from "../billing-mode/org-billing-mode-query";

/**
* Returns the default workspace timeout for an organization based on their billing mode (does not take into account the organization's own settings)
*/
export const useDefaultOrgTimeoutQuery = () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit sad that we have to replicate this logic here... 😕 Ideally, we'd have an API that emits this.

I'm ok with using this PR as short-term fix, though, given the overhead of introducing such an API. We can get back to it if we have the capacity. 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could totally put this in a OrganizationService.GetDefaultWorkspaceTimeout method. This feels ok for now, as the logic is so simple and since we're going to remove the billing stuff in a couple months, we'll be able to hardcode it instead.

const { data: billingMode } = useOrgBillingMode();

const isPaidOrDedicated =
billingMode?.mode === "none" || (billingMode?.mode === "usage-based" && billingMode?.paid);

return isPaidOrDedicated ? WORKSPACE_TIMEOUT_DEFAULT_LONG : WORKSPACE_TIMEOUT_DEFAULT_SHORT;
};
7 changes: 6 additions & 1 deletion components/dashboard/src/teams/TeamPolicies.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { WorkspaceClassesEnterpriseCallout } from "./policies/WorkspaceClassesEn
import { EditorOptions } from "./policies/EditorOptions";
import { RolePermissionsRestrictions } from "./policies/RoleRestrictions";
import { OrgWorkspaceClassesOptions } from "./policies/OrgWorkspaceClassesOptions";
import { useDefaultOrgTimeoutQuery } from "../data/organizations/default-org-timeout-query";

export default function TeamPoliciesPage() {
useDocumentTitle("Organization Settings - Policies");
Expand All @@ -46,6 +47,8 @@ export default function TeamPoliciesPage() {
const [allowTimeoutChangeByMembers, setAllowTimeoutChangeByMembers] = useState<boolean | undefined>(undefined);
const [workspaceTimeoutSettingError, setWorkspaceTimeoutSettingError] = useState<string | undefined>(undefined);

const defaultOrgTimeout = useDefaultOrgTimeoutQuery();

const handleUpdateTeamSettings = useCallback(
async (newSettings: Partial<PlainMessage<OrganizationSettings>>, options?: { throwMutateError?: boolean }) => {
if (!org?.id) {
Expand Down Expand Up @@ -156,7 +159,9 @@ export default function TeamPoliciesPage() {
hint={
<span>
Use minutes or hours, like <span className="font-semibold">30m</span> or{" "}
<span className="font-semibold">2h</span>
<span className="font-semibold">2h</span>. If not set, your organization's
default of <span className="font-semibold">{defaultOrgTimeout}</span> will be
used.
</span>
}
>
Expand Down
6 changes: 4 additions & 2 deletions components/dashboard/src/user-settings/Preferences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { converter, userClient } from "../service/public-api";
import { LoadingButton } from "@podkit/buttons/LoadingButton";
import { useOrgSettingsQuery } from "../data/organizations/org-settings-query";
import Alert from "../components/Alert";
import { useDefaultOrgTimeoutQuery } from "../data/organizations/default-org-timeout-query";

export type IDEChangedTrackLocation = "workspace_list" | "workspace_start" | "preferences";

Expand All @@ -35,7 +36,7 @@ export default function Preferences() {
const billingMode = useOrgBillingMode();
const updateDotfileRepo = useUpdateCurrentUserDotfileRepoMutation();
const { data: settings } = useOrgSettingsQuery();

const defaultOrgTimeout = useDefaultOrgTimeoutQuery();
const [dotfileRepo, setDotfileRepo] = useState<string>(user?.dotfileRepo || "");

const [workspaceTimeout, setWorkspaceTimeout] = useState<string>(
Expand Down Expand Up @@ -173,7 +174,8 @@ export default function Preferences() {
<Alert type="warning" className="mb-4">
The currently selected organization does not allow members to set custom workspace timeouts,
so for workspaces created in it, its default timeout of{" "}
{converter.toDurationStringOpt(settings?.timeoutSettings?.inactivity) || ""} will be used.
{converter.toDurationStringOpt(settings?.timeoutSettings?.inactivity) ?? defaultOrgTimeout}{" "}
will be used.
</Alert>
)}

Expand Down
Loading