Skip to content

Commit

Permalink
add enum type support to pr automation configs (#1090)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsladerman authored Jun 19, 2024
1 parent 3b5f2ce commit 9f543ec
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 18 deletions.
2 changes: 1 addition & 1 deletion assets/src/components/pr/automations/CreatePrModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ function CreatePrModalBase({
<Body1P>Provide some basic configuration for this PR:</Body1P>
<PrConfigurationFields
{...{
configuration: prAutomation.configuration,
configuration,
configVals,
setConfigVals,
}}
Expand Down
54 changes: 37 additions & 17 deletions assets/src/components/pr/automations/PrConfigurationInput.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Input, Switch } from '@pluralsh/design-system'
import { Input, ListBoxItem, Select, Switch } from '@pluralsh/design-system'
import { ConfigurationType, PrConfiguration } from 'generated/graphql'

import { parseToBool } from 'utils/parseToBool'
Expand All @@ -21,20 +21,40 @@ export function PrConfigurationInput({
configBoolVal = parseToBool(value)
}

return type === ConfigurationType.Bool ? (
<Switch
checked={!!configBoolVal}
onChange={(isChecked) => {
setValue(isChecked.toString())
}}
/>
) : (
<Input
value={value}
placeContent={config.placeholder}
onChange={(e) => {
setValue(e.currentTarget.value)
}}
/>
)
switch (type) {
case ConfigurationType.Bool:
return (
<Switch
checked={!!configBoolVal}
onChange={(isChecked) => {
setValue(isChecked.toString())
}}
/>
)
case ConfigurationType.Enum:
return (
<Select
selectedKey={value}
onSelectionChange={(key) => setValue(key as string)}
>
{(config?.values || [])?.map((val, index) => (
<ListBoxItem
key={`${index}`}
label={val}
textValue={val ?? ''}
/>
))}
</Select>
)
default:
return (
<Input
value={value}
placeContent={config.placeholder}
onChange={(e) => {
setValue(e.currentTarget.value)
}}
/>
)
}
}

0 comments on commit 9f543ec

Please sign in to comment.