diff --git a/changes/43135-fix-stale-label-hosts b/changes/43135-fix-stale-label-hosts new file mode 100644 index 0000000000..7e683a6e30 --- /dev/null +++ b/changes/43135-fix-stale-label-hosts @@ -0,0 +1,2 @@ +* Fixed stale "Selected hosts" on the edit label page after a previous edit by invalidating the related query caches on success. +* Fixed stale "Selected hosts" on the edit label page when navigating between manual labels by scoping the hosts cache per label and keying the form on the actual host set. diff --git a/frontend/pages/labels/EditLabelPage/EditLabelPage.tsx b/frontend/pages/labels/EditLabelPage/EditLabelPage.tsx index b4a7d82168..fba27ba105 100644 --- a/frontend/pages/labels/EditLabelPage/EditLabelPage.tsx +++ b/frontend/pages/labels/EditLabelPage/EditLabelPage.tsx @@ -79,7 +79,7 @@ const EditLabelPage = ({ routeParams, router }: IEditLabelPageProps) => { isLoading: isLoadingHosts, isError: isErrorHosts, } = useQuery( - ["hosts"], + ["hosts", labelId], () => { return labelsAPI.getHostsInLabel(labelId); }, @@ -101,6 +101,8 @@ const EditLabelPage = ({ routeParams, router }: IEditLabelPageProps) => { await labelsAPI.update(labelId, formData); renderFlash("success", "Label updated successfully."); queryClient.invalidateQueries(["label", labelId, currentUser]); + queryClient.invalidateQueries(["hosts", labelId]); + queryClient.invalidateQueries(["labels"]); } catch (error) { const status = (error as { status: number }).status; let errorMessage = "Couldn't edit label. Please try again."; @@ -150,7 +152,10 @@ const EditLabelPage = ({ routeParams, router }: IEditLabelPageProps) => { /> ) : ( h.id) + .sort((a, b) => a - b) + .join(",")}`} defaultName={label.name} defaultDescription={label.description} defaultTargetedHosts={targetedHosts}