mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: update template with noop returned undefined template (#11688)
* fix: doing a noop patch to templates resulted in 404 The patch response did not include the template. The UI required the template to be returned to form the new page path null is more explicit, and harder to make occur by mistake.
This commit is contained in:
+6
-1
@@ -414,11 +414,16 @@ export const unarchiveTemplateVersion = async (templateVersionId: string) => {
|
||||
export const updateTemplateMeta = async (
|
||||
templateId: string,
|
||||
data: TypesGen.UpdateTemplateMeta,
|
||||
): Promise<TypesGen.Template> => {
|
||||
): Promise<TypesGen.Template | null> => {
|
||||
const response = await axios.patch<TypesGen.Template>(
|
||||
`/api/v2/templates/${templateId}`,
|
||||
data,
|
||||
);
|
||||
// On 304 response there is no data payload.
|
||||
if (response.status === 304) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return response.data;
|
||||
};
|
||||
|
||||
|
||||
+13
-4
@@ -29,10 +29,19 @@ export const TemplateSettingsPage: FC = () => {
|
||||
(data: UpdateTemplateMeta) => updateTemplateMeta(template.id, data),
|
||||
{
|
||||
onSuccess: async (data) => {
|
||||
// we use data.name because an admin may have updated templateName to something new
|
||||
await queryClient.invalidateQueries(
|
||||
templateByNameKey(orgId, data.name),
|
||||
);
|
||||
// This update has a chance to return a 304 which means nothing was updated.
|
||||
// In this case, the return payload will be empty and we should use the
|
||||
// original template data.
|
||||
if (!data) {
|
||||
data = template;
|
||||
} else {
|
||||
// Only invalid the query if data is returned, indicating at least one field was updated.
|
||||
//
|
||||
// we use data.name because an admin may have updated templateName to something new
|
||||
await queryClient.invalidateQueries(
|
||||
templateByNameKey(orgId, data.name),
|
||||
);
|
||||
}
|
||||
displaySuccess("Template updated successfully");
|
||||
navigate(`/templates/${data.name}`);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user