-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New Prebuild Settings UI for repo configs #19184
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
Changes from 3 commits
ba9826e
a9c3197
9d61cee
49e4e80
366aa83
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/** | ||
* Copyright (c) 2023 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 { BranchMatchingStrategy, Configuration } from "@gitpod/public-api/lib/gitpod/v1/configuration_pb"; | ||
import { FC, FormEvent, useCallback, useState } from "react"; | ||
import { ConfigurationSettingsField } from "../ConfigurationSettingsField"; | ||
import { Heading3, Subheading } from "@podkit/typography/Headings"; | ||
import { InputField } from "../../../components/forms/InputField"; | ||
import { PartialConfiguration, useConfigurationMutation } from "../../../data/configurations/configuration-queries"; | ||
import { useToast } from "../../../components/toasts/Toasts"; | ||
import { SelectInputField } from "../../../components/forms/SelectInputField"; | ||
import { TextInputField } from "../../../components/forms/TextInputField"; | ||
import { WorkspaceClassOptions } from "../shared/WorkspaceClassOptions"; | ||
import { LoadingButton } from "@podkit/buttons/LoadingButton"; | ||
|
||
type Props = { | ||
configuration: Configuration; | ||
}; | ||
|
||
export const PrebuildSettingsForm: FC<Props> = ({ configuration }) => { | ||
const { toast } = useToast(); | ||
const updateConfiguration = useConfigurationMutation(); | ||
|
||
const [interval, setInterval] = useState<string>(`${configuration.prebuildSettings?.prebuildInterval ?? 20}`); | ||
const [branchStrategy, setBranchStrategy] = useState<BranchMatchingStrategy>( | ||
configuration.prebuildSettings?.branchStrategy ?? BranchMatchingStrategy.DEFAULT_BRANCH, | ||
); | ||
const [branchMatchingPattern, setBranchMatchingPattern] = useState<string>( | ||
configuration.prebuildSettings?.branchMatchingPattern || "**", | ||
); | ||
const [workspaceClass, setWorkspaceClass] = useState<string>( | ||
configuration.prebuildSettings?.workspaceClass || "g1-standard", | ||
); | ||
|
||
const handleSubmit = useCallback( | ||
(e: FormEvent) => { | ||
e.preventDefault(); | ||
|
||
const newInterval = Math.abs(Math.min(Number.parseInt(interval), 100)) || 0; | ||
|
||
const updatedConfig: PartialConfiguration = { | ||
configurationId: configuration.id, | ||
prebuildSettings: { | ||
...configuration.prebuildSettings, | ||
prebuildInterval: newInterval, | ||
branchStrategy, | ||
branchMatchingPattern, | ||
workspaceClass, | ||
}, | ||
}; | ||
|
||
updateConfiguration.mutate(updatedConfig, { | ||
onSuccess: () => { | ||
toast("Your prebuild settings were updated."); | ||
}, | ||
}); | ||
}, | ||
[ | ||
branchMatchingPattern, | ||
branchStrategy, | ||
configuration.id, | ||
configuration.prebuildSettings, | ||
interval, | ||
toast, | ||
updateConfiguration, | ||
workspaceClass, | ||
], | ||
); | ||
|
||
// TODO: Figure out if there's a better way to deal with grpc enums in the UI | ||
const handleBranchStrategyChange = useCallback((val) => { | ||
// This is pretty hacky, trying to coerce value into a number and then cast it to the enum type | ||
// Would be better if we treated these as strings instead of special enums | ||
setBranchStrategy(parseInt(val, 10) as BranchMatchingStrategy); | ||
}, []); | ||
|
||
return ( | ||
<ConfigurationSettingsField> | ||
<form onSubmit={handleSubmit}> | ||
<Heading3>Prebuild Settings</Heading3> | ||
<Subheading className="max-w-lg">These settings will be applied on every Prebuild.</Subheading> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is more of an aside since it's relevant to all of the work we've been doing with Configs so far: do we or do we not capitalize feature names? I like the aesthetics of doing so, but am not convinced too hard. Either way, it would be great to settle this so that we can make it consistent. cc @loujaybee since you may have an opinion :) |
||
|
||
<InputField | ||
label="Commit interval" | ||
hint="The number of commits to be skipped between prebuild runs." | ||
id="prebuild-interval" | ||
> | ||
<input | ||
type="number" | ||
id="prebuild-interval" | ||
min="0" | ||
max="100" | ||
step="5" | ||
value={interval} | ||
onChange={({ target }) => setInterval(target.value)} | ||
/> | ||
</InputField> | ||
|
||
<SelectInputField | ||
label="Branch Filter" | ||
hint="Run prebuilds on the selected branches only." | ||
value={branchStrategy} | ||
onChange={handleBranchStrategyChange} | ||
> | ||
<option value={BranchMatchingStrategy.ALL_BRANCHES}>All branches</option> | ||
<option value={BranchMatchingStrategy.DEFAULT_BRANCH}>Default branch</option> | ||
<option value={BranchMatchingStrategy.MATCHED_BRANCHES}>Match branches by pattern</option> | ||
</SelectInputField> | ||
|
||
{branchStrategy === BranchMatchingStrategy.MATCHED_BRANCHES && ( | ||
<TextInputField | ||
label="Branch name pattern" | ||
hint="Glob patterns separated by commas are supported." | ||
value={branchMatchingPattern} | ||
onChange={setBranchMatchingPattern} | ||
/> | ||
)} | ||
|
||
<WorkspaceClassOptions value={workspaceClass} onChange={setWorkspaceClass} /> | ||
filiptronicek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
<LoadingButton className="mt-8" type="submit" loading={updateConfiguration.isLoading}> | ||
Save | ||
</LoadingButton> | ||
filiptronicek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</form> | ||
</ConfigurationSettingsField> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* Copyright (c) 2023 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 { FC } from "react"; | ||
import { useWorkspaceClasses } from "../../../data/workspaces/workspace-classes-query"; | ||
import { LoadingState } from "@podkit/loading/LoadingState"; | ||
import { cn } from "@podkit/lib/cn"; | ||
import Alert from "../../../components/Alert"; | ||
import { Label } from "@podkit/forms/Label"; | ||
import { RadioGroup, RadioGroupItem } from "@podkit/forms/RadioListField"; | ||
|
||
type Props = { | ||
value: string; | ||
className?: string; | ||
onChange: (newValue: string) => void; | ||
}; | ||
export const WorkspaceClassOptions: FC<Props> = ({ value, className, onChange }) => { | ||
const { data: classes, isLoading } = useWorkspaceClasses(); | ||
|
||
if (isLoading) { | ||
return <LoadingState />; | ||
} | ||
|
||
if (!classes) { | ||
return <Alert type="error">There was a problem loading workspace classes.</Alert>; | ||
} | ||
|
||
return ( | ||
<RadioGroup value={value} onValueChange={onChange} className={cn("mt-4", className)}> | ||
{classes.map((wsClass) => ( | ||
<Label className="flex items-start space-x-2 my-2" key={wsClass.id}> | ||
<RadioGroupItem value={wsClass.id} /> | ||
<div className="flex flex-col space-y-2"> | ||
<span className="font-bold">{wsClass.displayName}</span> | ||
<span>{wsClass.description}</span> | ||
</div> | ||
</Label> | ||
))} | ||
</RadioGroup> | ||
); | ||
}; |
Uh oh!
There was an error while loading. Please reload this page.