fix(site): Only patch version name if name is changed (#6878)

This commit is contained in:
Bruno Quaresma 2023-03-30 09:22:55 -03:00 committed by GitHub
parent d8762c676f
commit 7d7aa789b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 7 deletions

View File

@ -133,7 +133,7 @@ test("Do not mark as active if promote is not checked", async () => {
expect(updateActiveTemplateVersion).toBeCalledTimes(0) expect(updateActiveTemplateVersion).toBeCalledTimes(0)
}) })
test("The default version name is used when a new one is not used", async () => { test("Patch request is not send when the name is not updated", async () => {
const user = userEvent.setup() const user = userEvent.setup()
renderWithAuth(<TemplateVersionEditorPage />, { renderWithAuth(<TemplateVersionEditorPage />, {
extraRoutes: [ extraRoutes: [
@ -172,12 +172,12 @@ test("The default version name is used when a new one is not used", async () =>
}) })
await user.click(publishButton) await user.click(publishButton)
const publishDialog = await screen.findByTestId("dialog") const publishDialog = await screen.findByTestId("dialog")
// It is using the name from the template version
const nameField = within(publishDialog).getByLabelText("Version name")
expect(nameField).toHaveValue(MockTemplateVersion.name)
// Publish
await user.click( await user.click(
within(publishDialog).getByRole("button", { name: "Publish" }), within(publishDialog).getByRole("button", { name: "Publish" }),
) )
await waitFor(() => { expect(patchTemplateVersion).toBeCalledTimes(0)
expect(patchTemplateVersion).toBeCalledWith("new-version-id", {
name: MockTemplateVersion.name,
})
})
}) })

View File

@ -341,7 +341,10 @@ export const templateVersionEditorMachine = createMachine(
throw new Error("Template is not set") throw new Error("Template is not set")
} }
await Promise.all([ await Promise.all([
API.patchTemplateVersion(version.id, { name }), // Only do a patch if the name is different
name !== version.name
? API.patchTemplateVersion(version.id, { name })
: Promise.resolve(),
isActiveVersion isActiveVersion
? API.updateActiveTemplateVersion(templateId, { ? API.updateActiveTemplateVersion(templateId, {
id: version.id, id: version.id,