-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ba9826e
setting up settings
selfcontained a9c3197
preload ws classes
selfcontained 9d61cee
Merge branch 'main' into brad/new-prebuild-settings
filiptronicek 49e4e80
adding heading/description to prebuild ws class
selfcontained 366aa83
add some constants
selfcontained File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
components/dashboard/src/repositories/detail/prebuilds/PrebuildSettingsForm.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
/** | ||
* 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"; | ||
import { InputFieldHint } from "../../../components/forms/InputFieldHint"; | ||
import { DEFAULT_WS_CLASS } from "../../../data/workspaces/workspace-classes-query"; | ||
|
||
const DEFAULT_PREBUILD_COMMIT_INTERVAL = 20; | ||
|
||
type Props = { | ||
configuration: Configuration; | ||
}; | ||
|
||
export const PrebuildSettingsForm: FC<Props> = ({ configuration }) => { | ||
const { toast } = useToast(); | ||
const updateConfiguration = useConfigurationMutation(); | ||
|
||
const [interval, setInterval] = useState<string>( | ||
`${configuration.prebuildSettings?.prebuildInterval ?? DEFAULT_PREBUILD_COMMIT_INTERVAL}`, | ||
); | ||
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 || DEFAULT_WS_CLASS, | ||
); | ||
|
||
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> | ||
|
||
<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} | ||
/> | ||
)} | ||
|
||
<Heading3 className="mt-8">Machine type</Heading3> | ||
<Subheading>Choose the workspace machine type for your prebuilds.</Subheading> | ||
|
||
<WorkspaceClassOptions value={workspaceClass} onChange={setWorkspaceClass} /> | ||
filiptronicek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<InputFieldHint>Use a smaller machine type for cost optimization.</InputFieldHint> | ||
|
||
<LoadingButton className="mt-8" type="submit" loading={updateConfiguration.isLoading}> | ||
Save | ||
</LoadingButton> | ||
filiptronicek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</form> | ||
</ConfigurationSettingsField> | ||
); | ||
}; |
44 changes: 44 additions & 0 deletions
44
components/dashboard/src/repositories/detail/shared/WorkspaceClassOptions.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("my-4 gap-4", className)}> | ||
{classes.map((wsClass) => ( | ||
<Label className="flex items-start space-x-2" key={wsClass.id}> | ||
<RadioGroupItem value={wsClass.id} /> | ||
<div className="flex flex-col space-y-2"> | ||
<span className="font-semibold">{wsClass.displayName}</span> | ||
<span>{wsClass.description}</span> | ||
</div> | ||
</Label> | ||
))} | ||
</RadioGroup> | ||
); | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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 :)