-
Notifications
You must be signed in to change notification settings - Fork 930
feat: allow for default presets #18445
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 1 commit
89da41b
7e75433
0fb3743
e9a218c
a6e4d0a
1b737ff
f0f77fb
83192a7
0d9d751
590eb4e
737e1c6
ce92f1f
371ac5a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Signed-off-by: Danny Kopping <dannykopping@gmail.com>
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,13 +156,24 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({ | |
setPresetOptions([ | ||
{ label: "None", value: "" }, | ||
...presets.map((preset) => ({ | ||
label: preset.Name, | ||
label: preset.Default ? `${preset.Name} (Default)` : preset.Name, | ||
value: preset.ID, | ||
})), | ||
]); | ||
}, [presets]); | ||
|
||
const [selectedPresetIndex, setSelectedPresetIndex] = useState(0); | ||
|
||
// Set default preset when presets are loaded | ||
useEffect(() => { | ||
const defaultPreset = presets.find((preset) => preset.Default); | ||
if (defaultPreset) { | ||
// +1 because "None" is at index 0 | ||
const defaultIndex = | ||
presets.findIndex((preset) => preset.ID === defaultPreset.ID) + 1; | ||
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. It looks like this fine, but I've been caught by |
||
setSelectedPresetIndex(defaultIndex); | ||
} | ||
}, [presets]); | ||
const [presetParameterNames, setPresetParameterNames] = useState<string[]>( | ||
[], | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -190,13 +190,25 @@ export const CreateWorkspacePageViewExperimental: FC< | |
setPresetOptions([ | ||
{ label: "None", value: "None" }, | ||
...presets.map((preset) => ({ | ||
label: preset.Name, | ||
label: preset.Default ? `${preset.Name} (Default)` : preset.Name, | ||
value: preset.ID, | ||
})), | ||
]); | ||
}, [presets]); | ||
|
||
const [selectedPresetIndex, setSelectedPresetIndex] = useState(0); | ||
|
||
// Set default preset when presets are loaded | ||
useEffect(() => { | ||
const defaultPreset = presets.find((preset) => preset.Default); | ||
if (defaultPreset) { | ||
// +1 because "None" is at index 0 | ||
const defaultIndex = | ||
presets.findIndex((preset) => preset.ID === defaultPreset.ID) + 1; | ||
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. ...or I guess it's because everything is this 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. Agreed; I think we need a wider refactor of the implementation. For now though, I'm going to have to use what's present. @SasSwart WDYT? 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. Coping with the none preset in the FE has felt weird from the start. I'm considering the idea that "None" should be a preset returned like any other from the endpoint that lists presets. it would simplify the FE quite a bit and centralize how me manage it. |
||
setSelectedPresetIndex(defaultIndex); | ||
} | ||
}, [presets]); | ||
|
||
const [presetParameterNames, setPresetParameterNames] = useState<string[]>( | ||
[], | ||
); | ||
|
@@ -555,6 +567,7 @@ export const CreateWorkspacePageViewExperimental: FC< | |
<div className="flex flex-col gap-4"> | ||
<div className="max-w-lg"> | ||
<Select | ||
value={presetOptions[selectedPresetIndex]?.value} | ||
onValueChange={(option) => { | ||
const index = presetOptions.findIndex( | ||
(preset) => preset.value === option, | ||
|
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.
TODO: depends on coder/terraform-provider-coder#414.
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.
Might make sense to wait until that is merged + tagged first?