Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 13 commits into from
Jun 24, 2025
Merged

feat: allow for default presets #18445

merged 13 commits into from
Jun 24, 2025

Conversation

dannykopping
Copy link
Contributor

@dannykopping dannykopping commented Jun 19, 2025

Disclaimer: mostly implemented by Claude Code.

Depends on: coder/terraform-provider-coder#414
Closes: #18110

I've tested this against both the classic and new (dynamic parameters) approaches.

...
data "coder_workspace_preset" "goland" {
  default = true													# <-----------------
  name = "I Like GoLand"
  parameters = {
    "jetbrains_ide" = "GO"
    "cpu"           = "2"
  }
}

data "coder_workspace_preset" "python" {
  name = "Some Like PyCharm"
  parameters = {
    "jetbrains_ide" = "PY"
  }
}
...

Default preset is autoselected on load:

image

image

@dannykopping dannykopping changed the title feat: default presets feat: allow for default presets Jun 19, 2025
@@ -103,5 +103,4 @@ Read [cursor rules](.cursorrules).

The frontend is contained in the site folder.

For building Frontend refer to [this document](docs/contributing/frontend.md)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drive-by: link is dead.

Copy link
Member

@aslilac aslilac Jun 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's in docs/about/contributing/ now. can you leave this as is and I'll do a quick pr to fix the link?

sorry, I just looked at the whole file and this diff makes more sense now. the line got duplicated, with one having the out of date path and one having the correct path. you're just removing the stale one.

@@ -72,6 +72,9 @@ replace github.com/aquasecurity/trivy => github.com/coder/trivy v0.0.0-202505271
// https://github.com/spf13/afero/pull/487
replace github.com/spf13/afero => github.com/aslilac/afero v0.0.0-20250403163713-f06e86036696

// TODO: replace once we cut release.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

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?

@dannykopping dannykopping marked this pull request as ready for review June 19, 2025 08:27
Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look OK to me, with the provisio that we should merge + pre-release the provider change first

}

for name, tc := range cases {
tc := tc
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tc := tc

t.Parallel()

// nolint:dogsled
_, filename, _, _ := runtime.Caller(0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, non-blocking: I understand that this is copied from other tests, but I wonder if we could use t.Name() instead?

@@ -72,6 +72,9 @@ replace github.com/aquasecurity/trivy => github.com/coder/trivy v0.0.0-202505271
// https://github.com/spf13/afero/pull/487
replace github.com/spf13/afero => github.com/aslilac/afero v0.0.0-20250403163713-f06e86036696

// TODO: replace once we cut release.
Copy link
Member

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Obligatory reminder to check migration number before merge

if (defaultPreset) {
// +1 because "None" is at index 0
const defaultIndex =
presets.findIndex((preset) => preset.ID === defaultPreset.ID) + 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this fine, but I've been caught by findIndex before while working on presets. Is there any way that findIndex might return -1 here?

Replace findIndex with find() to avoid -1 edge case and consolidate preset initialization into single useEffect for better maintainability.

Signed-off-by: Danny Kopping <[email protected]>
setPresetOptions(options);
const defaultPreset = presets.find((p) => p.Default);
if (defaultPreset) {
const idx = presets.indexOf(defaultPreset) + 1; // +1 for "None"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is really confusing. so 0 is "none", but we want to special case it to 1, which should be the default if defaultPreset is true? is the first "real" option actually guaranteed to be the default? if so, why are we searching the array for it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None is index 0, indexOf can return -1.

if (defaultPreset) {
// +1 because "None" is at index 0
const defaultIndex =
presets.findIndex((preset) => preset.ID === defaultPreset.ID) + 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...or I guess it's because everything is this presets array ends up getting offset by one for having "none" at the beginning? that feels really weird, it'd make a lot more sense to me if the numbers were preserved and "none" was represented by null or something

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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?

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

@dannykopping dannykopping merged commit 6cc4cfa into main Jun 24, 2025
39 checks passed
@dannykopping dannykopping deleted the dk/default-preset branch June 24, 2025 10:19
@github-actions github-actions bot locked and limited conversation to collaborators Jun 24, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Presets: Support a default preset
4 participants