Optimistically reflect a run on the "X running" badge + per-row gutter Stop * instantly (the optimistic stamp eats the dispatcher's `pending` SSE, so * `applyCell` never bumps the count, and the server's dispatch-scope count * isn't live until the first window). `stampedByRow` drives the per-r
( queryClient: ReturnType<typeof useQueryClient>, tableId: string, stampedByRow: Record<string, number>, cellCountDelta?: number )
| 349 | * scope (rows × groups) for Run-all so it matches the server, or omit to use |
| 350 | * the stamped total. Returns the prior snapshot for rollback. */ |
| 351 | function bumpRunState( |
| 352 | queryClient: ReturnType<typeof useQueryClient>, |
| 353 | tableId: string, |
| 354 | stampedByRow: Record<string, number>, |
| 355 | cellCountDelta?: number |
| 356 | ): { snapshot: TableRunState | undefined } | null { |
| 357 | const stampedTotal = Object.values(stampedByRow).reduce((s, n) => s + n, 0) |
| 358 | const countDelta = cellCountDelta ?? stampedTotal |
| 359 | if (countDelta === 0 && stampedTotal === 0) return null |
| 360 | const snapshot = queryClient.getQueryData<TableRunState>(tableKeys.activeDispatches(tableId)) |
| 361 | queryClient.setQueryData<TableRunState>(tableKeys.activeDispatches(tableId), (prev) => { |
| 362 | const base = prev ?? { dispatches: [], runningCellCount: 0, runningByRowId: {} } |
| 363 | const nextByRow = { ...base.runningByRowId } |
| 364 | for (const [rid, n] of Object.entries(stampedByRow)) { |
| 365 | nextByRow[rid] = (nextByRow[rid] ?? 0) + n |
| 366 | } |
| 367 | return { |
| 368 | ...base, |
| 369 | runningCellCount: base.runningCellCount + countDelta, |
| 370 | runningByRowId: nextByRow, |
| 371 | } |
| 372 | }) |
| 373 | return { snapshot } |
| 374 | } |
| 375 | |
| 376 | /** |
| 377 | * Aggregate live state for a table: active dispatches (drives the "about to |
no outgoing calls
no test coverage detected