Skip to content

Commit 03f6e74

Browse files
committed
feat(logs): optimistic cancelling status on cancel execution
1 parent b6ab71d commit 03f6e74

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

apps/sim/app/workspace/[workspaceId]/logs/utils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const LOG_COLUMN_ORDER: readonly LogColumnKey[] = [
2929
export const DELETED_WORKFLOW_LABEL = 'Deleted Workflow'
3030
export const DELETED_WORKFLOW_COLOR = 'var(--text-tertiary)'
3131

32-
export type LogStatus = 'error' | 'pending' | 'running' | 'info' | 'cancelled'
32+
export type LogStatus = 'error' | 'pending' | 'running' | 'info' | 'cancelled' | 'cancelling'
3333

3434
/**
3535
* Maps raw status string to LogStatus for display.
@@ -42,6 +42,8 @@ export function getDisplayStatus(status: string | null | undefined): LogStatus {
4242
return 'running'
4343
case 'pending':
4444
return 'pending'
45+
case 'cancelling':
46+
return 'cancelling'
4547
case 'cancelled':
4648
return 'cancelled'
4749
case 'failed':
@@ -58,6 +60,7 @@ export const STATUS_CONFIG: Record<
5860
error: { variant: 'red', label: 'Error', color: 'var(--text-error)' },
5961
pending: { variant: 'amber', label: 'Pending', color: '#f59e0b' },
6062
running: { variant: 'amber', label: 'Running', color: '#f59e0b' },
63+
cancelling: { variant: 'amber', label: 'Cancelling...', color: '#f59e0b' },
6164
cancelled: { variant: 'orange', label: 'Cancelled', color: '#f97316' },
6265
info: { variant: 'gray', label: 'Info', color: 'var(--terminal-status-info-color)' },
6366
}

apps/sim/hooks/queries/logs.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
type InfiniteData,
23
keepPreviousData,
34
type QueryClient,
45
useInfiniteQuery,
@@ -276,6 +277,8 @@ export function useExecutionSnapshot(executionId: string | undefined) {
276277
})
277278
}
278279

280+
type LogsPage = { logs: WorkflowLog[]; hasMore: boolean; nextPage: number | undefined }
281+
279282
export function useCancelExecution() {
280283
const queryClient = useQueryClient()
281284
return useMutation({
@@ -294,6 +297,33 @@ export function useCancelExecution() {
294297
if (!data.success) throw new Error('Failed to cancel execution')
295298
return data
296299
},
300+
onMutate: async ({ executionId }) => {
301+
await queryClient.cancelQueries({ queryKey: logKeys.lists() })
302+
303+
const previousQueries = queryClient.getQueriesData<InfiniteData<LogsPage>>({
304+
queryKey: logKeys.lists(),
305+
})
306+
307+
queryClient.setQueriesData<InfiniteData<LogsPage>>({ queryKey: logKeys.lists() }, (old) => {
308+
if (!old) return old
309+
return {
310+
...old,
311+
pages: old.pages.map((page) => ({
312+
...page,
313+
logs: page.logs.map((log) =>
314+
log.executionId === executionId ? { ...log, status: 'cancelling' } : log
315+
),
316+
})),
317+
}
318+
})
319+
320+
return { previousQueries }
321+
},
322+
onError: (_err, _variables, context) => {
323+
for (const [queryKey, data] of context?.previousQueries ?? []) {
324+
queryClient.setQueryData(queryKey, data)
325+
}
326+
},
297327
onSettled: () => {
298328
queryClient.invalidateQueries({ queryKey: logKeys.lists() })
299329
queryClient.invalidateQueries({ queryKey: logKeys.details() })

0 commit comments

Comments
 (0)