mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix(site): Fix update when missing parameters (#7221)
This commit is contained in:
@@ -173,7 +173,12 @@ describe("api.ts", () => {
|
||||
expect(api.postWorkspaceBuild).toHaveBeenCalledWith(MockWorkspace.id, {
|
||||
transition: "start",
|
||||
template_version_id: MockTemplate.active_version_id,
|
||||
rich_parameter_values: [],
|
||||
rich_parameter_values: [
|
||||
{
|
||||
name: "first_parameter",
|
||||
value: "mock-abc",
|
||||
},
|
||||
],
|
||||
})
|
||||
})
|
||||
|
||||
@@ -222,7 +227,12 @@ describe("api.ts", () => {
|
||||
expect(api.postWorkspaceBuild).toHaveBeenCalledWith(MockWorkspace.id, {
|
||||
transition: "start",
|
||||
template_version_id: MockTemplate.active_version_id,
|
||||
rich_parameter_values: [],
|
||||
rich_parameter_values: [
|
||||
{
|
||||
name: "first_parameter",
|
||||
value: "mock-abc",
|
||||
},
|
||||
],
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
+10
-1
@@ -1041,10 +1041,19 @@ export const updateWorkspace = async (
|
||||
throw new MissingBuildParameters(missingParameters)
|
||||
}
|
||||
|
||||
// Merge parameters using name as key
|
||||
const richParameterValues = newBuildParameters
|
||||
oldBuildParameters.forEach((oldParam) => {
|
||||
const newParam = richParameterValues.find((p) => p.name === oldParam.name)
|
||||
if (newParam === undefined) {
|
||||
richParameterValues.push(oldParam)
|
||||
}
|
||||
})
|
||||
|
||||
return postWorkspaceBuild(workspace.id, {
|
||||
transition: "start",
|
||||
template_version_id: activeVersionId,
|
||||
rich_parameter_values: newBuildParameters,
|
||||
rich_parameter_values: richParameterValues,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -117,31 +117,32 @@ export const checks = {
|
||||
const permissionsToCheck = (
|
||||
workspace: TypesGen.Workspace,
|
||||
template: TypesGen.Template,
|
||||
) => ({
|
||||
[checks.readWorkspace]: {
|
||||
object: {
|
||||
resource_type: "workspace",
|
||||
resource_id: workspace.id,
|
||||
owner_id: workspace.owner_id,
|
||||
) =>
|
||||
({
|
||||
[checks.readWorkspace]: {
|
||||
object: {
|
||||
resource_type: "workspace",
|
||||
resource_id: workspace.id,
|
||||
owner_id: workspace.owner_id,
|
||||
},
|
||||
action: "read",
|
||||
},
|
||||
action: "read",
|
||||
},
|
||||
[checks.updateWorkspace]: {
|
||||
object: {
|
||||
resource_type: "workspace",
|
||||
resource_id: workspace.id,
|
||||
owner_id: workspace.owner_id,
|
||||
[checks.updateWorkspace]: {
|
||||
object: {
|
||||
resource_type: "workspace",
|
||||
resource_id: workspace.id,
|
||||
owner_id: workspace.owner_id,
|
||||
},
|
||||
action: "update",
|
||||
},
|
||||
action: "update",
|
||||
},
|
||||
[checks.updateTemplate]: {
|
||||
object: {
|
||||
resource_type: "template",
|
||||
resource_id: template.id,
|
||||
[checks.updateTemplate]: {
|
||||
object: {
|
||||
resource_type: "template",
|
||||
resource_id: template.id,
|
||||
},
|
||||
action: "update",
|
||||
},
|
||||
action: "update",
|
||||
},
|
||||
})
|
||||
} as const)
|
||||
|
||||
export const workspaceMachine = createMachine(
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user