fix(web): Dismiss button on refine agent ChangeSetBanner now works
The dismiss mutation only invalidated `listAgents` but the hook reads from `getActiveRefineAgent`, so the banner stayed visible after dismiss. Added optimistic cache clearing and invalidation for `getActiveRefineAgent`.
This commit is contained in:
@@ -170,26 +170,34 @@ export function useRefineAgent(initiativeId: string): UseRefineAgentResult {
|
||||
onMutate: async ({ id }) => {
|
||||
// Cancel outgoing refetches
|
||||
await utils.listAgents.cancel();
|
||||
await utils.getActiveRefineAgent.cancel({ initiativeId });
|
||||
|
||||
// Snapshot previous value
|
||||
// Snapshot previous values
|
||||
const previousAgents = utils.listAgents.getData();
|
||||
const previousRefineAgent = utils.getActiveRefineAgent.getData({ initiativeId });
|
||||
|
||||
// Optimistically remove the agent from the list
|
||||
utils.listAgents.setData(undefined, (old = []) =>
|
||||
old.filter(a => a.id !== id)
|
||||
);
|
||||
// Optimistically clear the active refine agent so the banner disappears immediately
|
||||
utils.getActiveRefineAgent.setData({ initiativeId }, null);
|
||||
|
||||
return { previousAgents };
|
||||
return { previousAgents, previousRefineAgent };
|
||||
},
|
||||
onSuccess: () => {},
|
||||
onError: (err, variables, context) => {
|
||||
// Revert optimistic update
|
||||
// Revert optimistic updates
|
||||
if (context?.previousAgents) {
|
||||
utils.listAgents.setData(undefined, context.previousAgents);
|
||||
}
|
||||
if (context?.previousRefineAgent !== undefined) {
|
||||
utils.getActiveRefineAgent.setData({ initiativeId }, context.previousRefineAgent);
|
||||
}
|
||||
},
|
||||
onSettled: () => {
|
||||
void utils.listAgents.invalidate();
|
||||
void utils.getActiveRefineAgent.invalidate({ initiativeId });
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user