Path: blob/main/components/dashboard/src/teams/policies/MaxParallelWorkspaces.tsx
2501 views
/**1* Copyright (c) 2024 Gitpod GmbH. All rights reserved.2* Licensed under the GNU Affero General Public License (AGPL).3* See License.AGPL.txt in the project root for license information.4*/56import { OrganizationSettings } from "@gitpod/public-api/lib/gitpod/v1/organization_pb";7import { FormEvent, useEffect, useState } from "react";8import { ConfigurationSettingsField } from "../../repositories/detail/ConfigurationSettingsField";9import { Heading3, Subheading } from "@podkit/typography/Headings";10import { InputField } from "../../components/forms/InputField";11import { NumberInput } from "../../components/forms/TextInputField";12import { LoadingButton } from "@podkit/buttons/LoadingButton";13import { MAX_PARALLEL_WORKSPACES_FREE, MAX_PARALLEL_WORKSPACES_PAID } from "@gitpod/gitpod-protocol";14import { PlainMessage } from "@bufbuild/protobuf";15import { useInstallationConfiguration } from "../../data/installation/installation-config-query";1617type Props = {18isOwner: boolean;19isLoading: boolean;20isPaidOrDedicated: boolean;21settings?: OrganizationSettings;22handleUpdateTeamSettings: (23newSettings: Partial<PlainMessage<OrganizationSettings>>,24options?: {25throwMutateError?: boolean;26},27) => Promise<void>;28};2930export const MaxParallelWorkspaces = ({31isOwner,32isLoading,33settings,34isPaidOrDedicated,35handleUpdateTeamSettings,36}: Props) => {37const [error, setError] = useState<string | undefined>(undefined);38const [maxParallelWorkspaces, setMaxParallelWorkspaces] = useState<number>(39settings?.maxParallelRunningWorkspaces ?? 0,40);4142const organizationDefault = isPaidOrDedicated ? MAX_PARALLEL_WORKSPACES_PAID : MAX_PARALLEL_WORKSPACES_FREE;43const { data: installationConfig } = useInstallationConfiguration();44const isDedicatedInstallation = !!installationConfig?.isDedicatedInstallation;4546const handleSubmit = async (e: FormEvent) => {47e.preventDefault();48if (maxParallelWorkspaces < 0) {49setError("The maximum parallel running workspaces must be a positive number.");50return;51}52await handleUpdateTeamSettings({53maxParallelRunningWorkspaces: maxParallelWorkspaces,54});55};5657useEffect(() => {58setMaxParallelWorkspaces(settings?.maxParallelRunningWorkspaces ?? 0);59}, [settings?.maxParallelRunningWorkspaces]);6061return (62<ConfigurationSettingsField>63<Heading3>Maximum parallel running workspaces</Heading3>64<Subheading>65By default, every user in your organization can have <strong>{organizationDefault}</strong> workspaces66running at the same time. You can change this limit below or revert to this default by specifying{" "}67<strong>0</strong> as the limit.68</Subheading>69<form onSubmit={handleSubmit}>70<InputField label="Maximum parallel running workspaces" error={error} className="mb-4">71<NumberInput72value={maxParallelWorkspaces ?? ""}73onChange={(newValue) => {74setMaxParallelWorkspaces(newValue);75setError(undefined);76}}77disabled={isLoading || !isOwner}78min={0}79max={isDedicatedInstallation ? undefined : organizationDefault}80/>81</InputField>82<LoadingButton type="submit" loading={isLoading} disabled={!isOwner}>83Save84</LoadingButton>85</form>86</ConfigurationSettingsField>87);88};899091