Skip to content

Commit 7983d56

Browse files
committed
fix: cache update
1 parent 1613388 commit 7983d56

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

static/app/views/detectors/components/connectAutomationsDrawer.tsx

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -80,26 +80,24 @@ export function ConnectAutomationsDrawer({
8080
const [localWorkflowIds, setLocalWorkflowIds] = useState(initialWorkflowIds);
8181

8282
const toggleConnected = ({automation}: {automation: Automation}) => {
83-
const newAutomations =
84-
queryClient.setQueryData(
85-
automationsApiOptions(organization, {
86-
ids: localWorkflowIds,
87-
}).queryKey,
88-
oldAutomations => {
89-
if (!oldAutomations) {
90-
return oldAutomations;
91-
}
92-
return {
93-
...oldAutomations,
94-
json: (oldAutomations.json.some(a => a.id === automation.id)
95-
? oldAutomations.json.filter(a => a.id !== automation.id)
96-
: [...oldAutomations.json, automation]
97-
).sort((a, b) => a.id.localeCompare(b.id)),
98-
};
99-
}
100-
)?.json ?? [];
83+
const queryKey = automationsApiOptions(organization, {
84+
ids: localWorkflowIds,
85+
}).queryKey;
86+
87+
const oldAutomationsData = queryClient.getQueryData(queryKey)?.json ?? [];
88+
89+
const newAutomations = (
90+
oldAutomationsData.some(a => a.id === automation.id)
91+
? oldAutomationsData.filter(a => a.id !== automation.id)
92+
: [...oldAutomationsData, automation]
93+
).sort((a, b) => a.id.localeCompare(b.id));
10194
const newWorkflowIds = newAutomations.map(a => a.id);
10295

96+
queryClient.setQueryData(
97+
automationsApiOptions(organization, {ids: newWorkflowIds}).queryKey,
98+
old => (old ? {...old, json: newAutomations} : old)
99+
);
100+
103101
setLocalWorkflowIds(newWorkflowIds);
104102
setWorkflowIds(newWorkflowIds);
105103
};

0 commit comments

Comments
 (0)