Skip to content

fix(site): Fix update when missing parameters #7221

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 1 commit into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 12 additions & 2 deletions site/src/api/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
],
})
})

Expand Down Expand Up @@ -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",
},
],
})
})
})
Expand Down
11 changes: 10 additions & 1 deletion site/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Basically, we were not passing the old values when there is new ones.


return postWorkspaceBuild(workspace.id, {
transition: "start",
template_version_id: activeVersionId,
rich_parameter_values: newBuildParameters,
rich_parameter_values: richParameterValues,
})
}

Expand Down
45 changes: 23 additions & 22 deletions site/src/xServices/workspace/workspaceXService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand Down