Skip to content

Commit f61ffe9

Browse files
committed
fix(logs): key cancel optimistic detail by route workspaceId (not the log row)
1 parent be1083a commit f61ffe9

2 files changed

Lines changed: 9 additions & 14 deletions

File tree

apps/sim/app/workspace/[workspaceId]/logs/logs.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ export default function Logs() {
505505
}
506506
}, [contextMenuLog])
507507

508-
const cancelExecution = useCancelExecution()
508+
const cancelExecution = useCancelExecution(workspaceId)
509509
const retryExecution = useRetryExecution()
510510

511511
const handleCancelExecution = useCallback(() => {

apps/sim/hooks/queries/logs.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ export function useExecutionSnapshot(executionId: string | undefined) {
292292
})
293293
}
294294

295-
export function useCancelExecution() {
295+
export function useCancelExecution(workspaceId: string) {
296296
const queryClient = useQueryClient()
297297
return useMutation({
298298
mutationFn: async ({
@@ -316,7 +316,6 @@ export function useCancelExecution() {
316316
})
317317

318318
let affectedLogId: string | null = null
319-
let affectedWorkspaceId: string | undefined
320319
queryClient.setQueriesData<InfiniteData<LogsPage>>({ queryKey: logKeys.lists() }, (old) => {
321320
if (!old) return old
322321
return {
@@ -326,7 +325,6 @@ export function useCancelExecution() {
326325
logs: page.logs.map((log) => {
327326
if (log.executionId !== executionId) return log
328327
affectedLogId = log.id
329-
affectedWorkspaceId = log.workflow?.workspaceId ?? undefined
330328
return { ...log, status: 'cancelling' }
331329
}),
332330
})),
@@ -336,28 +334,25 @@ export function useCancelExecution() {
336334
let previousDetail: WorkflowLogDetail | undefined
337335
if (affectedLogId) {
338336
previousDetail = queryClient.getQueryData<WorkflowLogDetail>(
339-
logKeys.detail(affectedWorkspaceId, affectedLogId)
337+
logKeys.detail(workspaceId, affectedLogId)
340338
)
341339
if (previousDetail) {
342-
queryClient.setQueryData<WorkflowLogDetail>(
343-
logKeys.detail(affectedWorkspaceId, affectedLogId),
344-
{
345-
...previousDetail,
346-
status: 'cancelling',
347-
}
348-
)
340+
queryClient.setQueryData<WorkflowLogDetail>(logKeys.detail(workspaceId, affectedLogId), {
341+
...previousDetail,
342+
status: 'cancelling',
343+
})
349344
}
350345
}
351346

352-
return { previousQueries, affectedLogId, affectedWorkspaceId, previousDetail }
347+
return { previousQueries, affectedLogId, previousDetail }
353348
},
354349
onError: (_err, _variables, context) => {
355350
for (const [queryKey, data] of context?.previousQueries ?? []) {
356351
queryClient.setQueryData(queryKey, data)
357352
}
358353
if (context?.affectedLogId && context.previousDetail !== undefined) {
359354
queryClient.setQueryData(
360-
logKeys.detail(context.affectedWorkspaceId, context.affectedLogId),
355+
logKeys.detail(workspaceId, context.affectedLogId),
361356
context.previousDetail
362357
)
363358
}

0 commit comments

Comments
 (0)