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

Lines changed: 6 additions & 6 deletions
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

Lines changed: 4 additions & 1 deletion
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy