Skip to content

feat(site): add auto mode on create workspace form #8651

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 24 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a82a189
Add one click workspace
BrunoQuaresma Jul 20, 2023
3a38c03
feat(site): add auto mode on the create workspace form
BrunoQuaresma Jul 21, 2023
f255f37
fix deps
BrunoQuaresma Jul 21, 2023
37e6dd3
fix git auth validation result and callback
BrunoQuaresma Jul 21, 2023
3b82a03
Merge branch 'main' into bq/one-click-workspace
matifali Jul 25, 2023
ed46ee7
Merge branch 'main' into bq/one-click-workspace
BrunoQuaresma Jul 25, 2023
b26b118
Merge branch 'bq/one-click-workspace' of https://github.com/coder/cod…
BrunoQuaresma Jul 25, 2023
3593e0a
Merge branch 'main' into bq/one-click-workspace
matifali Jul 25, 2023
6fcfa13
Merge branch 'main' into bq/one-click-workspace
matifali Jul 25, 2023
0d8b026
Merge branch 'main' into bq/one-click-workspace
matifali Jul 25, 2023
4f440c9
Merge branch 'main' into bq/one-click-workspace
matifali Jul 25, 2023
934c90c
Merge branch 'main' into bq/one-click-workspace
matifali Jul 25, 2023
34135f3
Merge branch 'main' into bq/one-click-workspace
matifali Jul 25, 2023
bfa73bf
Merge branch 'main' into bq/one-click-workspace
matifali Jul 25, 2023
417788b
Merge branch 'main' into bq/one-click-workspace
matifali Jul 26, 2023
2ce8166
Merge branch 'main' into bq/one-click-workspace
matifali Jul 26, 2023
9b87a20
Merge branch 'main' into bq/one-click-workspace
BrunoQuaresma Jul 26, 2023
fefcf2f
Fix invalid option as default parameter
BrunoQuaresma Jul 26, 2023
c785282
Display error when auto creation fails
BrunoQuaresma Jul 26, 2023
116cbe2
Merge branch 'main' into bq/one-click-workspace
BrunoQuaresma Jul 26, 2023
4d7a7c3
Add test to check auto create flow
BrunoQuaresma Jul 26, 2023
73dbc0f
Add option to the user choose auto or manual
BrunoQuaresma Jul 26, 2023
ce75ca0
Fix tests
BrunoQuaresma Jul 26, 2023
8504971
Better unique names
BrunoQuaresma Jul 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix invalid option as default parameter
  • Loading branch information
BrunoQuaresma committed Jul 26, 2023
commit fefcf2f819b0033bd8ccf8b8cc1e23ed2f22f144
53 changes: 53 additions & 0 deletions site/src/utils/richParameters.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { TemplateVersionParameter } from "api/typesGenerated"
import { selectInitialRichParametersValues } from "./richParameters"

test("selectInitialRichParametersValues return default value when default build parameter is not valid", () => {
const templateParameters: TemplateVersionParameter[] = [
{
name: "cpu",
display_name: "CPU",
description: "The number of CPU cores",
description_plaintext: "The number of CPU cores",
type: "string",
mutable: true,
default_value: "2",
icon: "/icon/memory.svg",
options: [
{
name: "2 Cores",
description: "",
value: "2",
icon: "",
},
{
name: "4 Cores",
description: "",
value: "4",
icon: "",
},
{
name: "6 Cores",
description: "",
value: "6",
icon: "",
},
{
name: "8 Cores",
description: "",
value: "8",
icon: "",
},
],
required: false,
ephemeral: false,
},
]

const cpuParameter = templateParameters[0]
const [cpuParameterInitialValue] = selectInitialRichParametersValues(
templateParameters,
[{ name: cpuParameter.name, value: "100" }],
)

expect(cpuParameterInitialValue.value).toBe(cpuParameter.default_value)
})
11 changes: 8 additions & 3 deletions site/src/utils/richParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@ export const selectInitialRichParametersValues = (

if (parameter.options.length > 0) {
parameterValue = parameterValue ?? parameter.options[0].value
const validValues = parameter.options.map((option) => option.value)

if (defaultBuildParameters) {
const buildParameter = defaultBuildParameters.find(
const defaultBuildParameter = defaultBuildParameters.find(
(p) => p.name === parameter.name,
)

if (buildParameter) {
parameterValue = buildParameter?.value
// We don't want invalid values from default parameters to be set
if (
defaultBuildParameter &&
validValues.includes(defaultBuildParameter.value)
) {
parameterValue = defaultBuildParameter?.value
}
}

Expand Down