Skip to content

Commit 7d7aa78

Browse files
fix(site): Only patch version name if name is changed (coder#6878)
1 parent d8762c6 commit 7d7aa78

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

site/src/pages/TemplateVersionPage/TemplateVersionEditorPage/TemplateVersionEditorPage.test.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ test("Do not mark as active if promote is not checked", async () => {
133133
expect(updateActiveTemplateVersion).toBeCalledTimes(0)
134134
})
135135

136-
test("The default version name is used when a new one is not used", async () => {
136+
test("Patch request is not send when the name is not updated", async () => {
137137
const user = userEvent.setup()
138138
renderWithAuth(<TemplateVersionEditorPage />, {
139139
extraRoutes: [
@@ -172,12 +172,12 @@ test("The default version name is used when a new one is not used", async () =>
172172
})
173173
await user.click(publishButton)
174174
const publishDialog = await screen.findByTestId("dialog")
175+
// It is using the name from the template version
176+
const nameField = within(publishDialog).getByLabelText("Version name")
177+
expect(nameField).toHaveValue(MockTemplateVersion.name)
178+
// Publish
175179
await user.click(
176180
within(publishDialog).getByRole("button", { name: "Publish" }),
177181
)
178-
await waitFor(() => {
179-
expect(patchTemplateVersion).toBeCalledWith("new-version-id", {
180-
name: MockTemplateVersion.name,
181-
})
182-
})
182+
expect(patchTemplateVersion).toBeCalledTimes(0)
183183
})

site/src/xServices/templateVersionEditor/templateVersionEditorXService.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,10 @@ export const templateVersionEditorMachine = createMachine(
341341
throw new Error("Template is not set")
342342
}
343343
await Promise.all([
344-
API.patchTemplateVersion(version.id, { name }),
344+
// Only do a patch if the name is different
345+
name !== version.name
346+
? API.patchTemplateVersion(version.id, { name })
347+
: Promise.resolve(),
345348
isActiveVersion
346349
? API.updateActiveTemplateVersion(templateId, {
347350
id: version.id,

0 commit comments

Comments
 (0)