Skip to content

Commit 38a3818

Browse files
fix live update on table
1 parent f5e0b11 commit 38a3818

9 files changed

Lines changed: 14 additions & 45 deletions

File tree

apps/realtime/src/rooms/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ export interface IRoomManager {
177177
export interface TableRowUpdatedPayload {
178178
rowId: string
179179
data: Record<string, unknown>
180+
/** Per-workflow-group execution state. Keyed by `WorkflowGroup.id`. */
181+
executions?: Record<string, unknown>
180182
position: number
181183
updatedAt: string | number
182184
}

apps/realtime/src/routes/http.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,14 @@ export function createHttpHandler(roomManager: IRoomManager, logger: Logger) {
154154
if (req.method === 'POST' && req.url === '/api/table-row-updated') {
155155
try {
156156
const body = await readRequestBody(req)
157-
const { tableId, rowId, data, position, updatedAt } = JSON.parse(body)
158-
await roomManager.handleTableRowUpdated(tableId, { rowId, data, position, updatedAt })
157+
const { tableId, rowId, data, executions, position, updatedAt } = JSON.parse(body)
158+
await roomManager.handleTableRowUpdated(tableId, {
159+
rowId,
160+
data,
161+
executions,
162+
position,
163+
updatedAt,
164+
})
159165
sendSuccess(res)
160166
} catch (error) {
161167
logger.error('Error handling table row update notification:', error)

apps/sim/app/api/table/utils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import { createLogger } from '@sim/logger'
22
import { NextResponse } from 'next/server'
3+
import { z } from 'zod'
34
import {
45
createTableColumnBodySchema,
56
deleteTableColumnBodySchema,
67
updateTableColumnBodySchema,
78
} from '@/lib/api/contracts/tables'
89
import type { ColumnDefinition, TableDefinition } from '@/lib/table'
9-
import { getTableById } from '@/lib/table'
10+
import { COLUMN_TYPES, getTableById } from '@/lib/table'
1011
import { getUserEntityPermissions } from '@/lib/workspaces/permissions/utils'
1112

13+
const columnTypeEnum = z.enum(COLUMN_TYPES)
14+
1215
const logger = createLogger('TableUtils')
1316

1417
export interface TableAccessResult {

apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/table/table.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3429,10 +3429,6 @@ function CellContent({
34293429
</span>
34303430
)
34313431
} else {
3432-
// eslint-disable-next-line no-console
3433-
console.log(
3434-
`[FLASH-DEBUG] render dash col=${column.name} groupId=${column.workflowGroupId} status=${exec?.status ?? 'undefined'} value=${value === null ? 'null' : value === undefined ? 'undefined' : typeof value} runningBlockIds=${JSON.stringify(exec?.runningBlockIds ?? [])} blockErrors=${JSON.stringify(Object.keys(exec?.blockErrors ?? {}))}`
3435-
)
34363432
displayContent = <span className='text-[var(--text-tertiary)]'></span>
34373433
}
34383434
return displayContent

apps/sim/app/workspace/[workspaceId]/tables/[tableId]/hooks/use-row-execution.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@ export function useRowExecution(): UseRowExecutionReturn {
5959
return res.json()
6060
},
6161
onMutate: async (params) => {
62-
logger.info(
63-
`[FLASH-DEBUG] useRowExecution onMutate row=${params.rowId} group=${params.groupId} clearedCols=${JSON.stringify(params.outputColumnNames)}`
64-
)
6562
const snapshots = await snapshotAndMutateRows(queryClient, params.tableId, (r) => {
6663
if (r.id !== params.rowId) return null
6764
const exec = (r.executions ?? {})[params.groupId] as RowExecutionMetadata | undefined
@@ -89,7 +86,6 @@ export function useRowExecution(): UseRowExecutionReturn {
8986
toast.error(`Failed to run workflow: ${message}`)
9087
},
9188
onSettled: (_data, _err, params) => {
92-
logger.info(`[FLASH-DEBUG] useRowExecution onSettled → invalidate row=${params.rowId}`)
9389
queryClient.invalidateQueries({ queryKey: tableKeys.rowsRoot(params.tableId) })
9490
},
9591
})

apps/sim/background/workflow-column-execution.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,6 @@ export async function executeWorkflowGroupCellJob(
150150
const dataSnapshot: RowData = { ...accumulatedData }
151151
const blockErrorsSnapshot = { ...blockErrors }
152152
const runningSnapshot = Array.from(runningBlockIds)
153-
logger.info(
154-
`[FLASH-DEBUG] partial write scheduled row=${rowId} group=${groupId} dataKeys=${JSON.stringify(Object.keys(dataSnapshot))} running=${JSON.stringify(runningSnapshot)} errors=${JSON.stringify(Object.keys(blockErrorsSnapshot))}`
155-
)
156153
writeChain = writeChain
157154
.then(async () => {
158155
if (signal?.aborted) return
@@ -250,9 +247,6 @@ export async function executeWorkflowGroupCellJob(
250247
// Drain queued partial writes before the terminal write so a late
251248
// `running` partial doesn't clobber it.
252249
await writeChain.catch(() => {})
253-
logger.info(
254-
`[FLASH-DEBUG] terminal write row=${rowId} group=${groupId} status=${result.success ? 'completed' : 'error'} dataKeys=${JSON.stringify(Object.keys(accumulatedData))}`
255-
)
256250

257251
await writeState(
258252
{

apps/sim/hooks/queries/tables.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -258,17 +258,9 @@ export function useTableRows({
258258

259259
onTableRowUpdated((event) => {
260260
if (event.tableId !== tableId) return
261-
const incomingExec = Object.fromEntries(
262-
Object.entries(
263-
(event.executions as Record<string, { status?: string }> | undefined) ?? {}
264-
).map(([gid, e]) => [gid, e?.status ?? null])
265-
)
266261
// While an optimistic mutation is in flight, applying the socket delta
267262
// could clobber the optimistic state — defer to onSettled invalidate.
268263
if (queryClient.isMutating() > 0) {
269-
logger.info(
270-
`[FLASH-DEBUG] socket row=${event.rowId} (mutation in flight → invalidate) incomingExec=${JSON.stringify(incomingExec)}`
271-
)
272264
queryClient.invalidateQueries({ queryKey: tableKeys.rowsRoot(tableId) })
273265
return
274266
}
@@ -294,15 +286,6 @@ export function useTableRows({
294286
totalCount: current.totalCount === null ? null : current.totalCount + 1,
295287
}
296288
}
297-
const prevExec = Object.fromEntries(
298-
Object.entries(current.rows[idx].executions ?? {}).map(([gid, e]) => [
299-
gid,
300-
e?.status ?? null,
301-
])
302-
)
303-
logger.info(
304-
`[FLASH-DEBUG] socket merge row=${event.rowId} prevExec=${JSON.stringify(prevExec)} incomingExec=${JSON.stringify(incomingExec)}`
305-
)
306289
const merged = {
307290
...current.rows[idx],
308291
data: incoming.data,

apps/sim/lib/table/service.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,6 @@ const logger = createLogger('TableService')
7878
* server can broadcast to subscribed clients in the table room.
7979
*/
8080
function notifyTableRowUpdated(tableId: string, row: TableRow): void {
81-
const execStates = Object.fromEntries(
82-
Object.entries(row.executions ?? {}).map(([gid, e]) => [gid, e?.status ?? null])
83-
)
84-
logger.info(
85-
`[FLASH-DEBUG] notify row=${row.id} table=${tableId} exec=${JSON.stringify(execStates)}`
86-
)
8781
void fetch(`${getSocketServerUrl()}/api/table-row-updated`, {
8882
method: 'POST',
8983
headers: {
@@ -1578,11 +1572,9 @@ export async function updateRow(
15781572
// `running` execution state — those land last, so the cached executions
15791573
// end on the live state instead of being clobbered by a stale envelope.
15801574
notifyTableRowUpdated(data.tableId, updatedRow)
1581-
logger.info(`[FLASH-DEBUG] updateRow → scheduler START row=${data.rowId}`)
15821575
// Awaited (not `void`) so cell tasks dispatch their cascade before the
15831576
// trigger.dev worker tears down on `run()` resolve.
15841577
await scheduleWorkflowGroupRuns(table, [updatedRow])
1585-
logger.info(`[FLASH-DEBUG] updateRow → scheduler END row=${data.rowId}`)
15861578

15871579
return updatedRow
15881580
}

apps/sim/lib/table/workflow-columns.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ interface RunGroupCellOptions {
125125
*/
126126
export async function runWorkflowGroupCell(opts: RunGroupCellOptions): Promise<void> {
127127
const { tableId, tableName, rowId, groupId, workflowId, workspaceId, executionId } = opts
128-
logger.info(`[FLASH-DEBUG] runWorkflowGroupCell START row=${rowId} group=${groupId}`)
129128

130129
const { getJobQueue, shouldExecuteInline } = await import('@/lib/core/async-jobs/config')
131130
const cellCtx = { tableId, rowId, workspaceId, groupId, executionId }
@@ -143,7 +142,6 @@ export async function runWorkflowGroupCell(opts: RunGroupCellOptions): Promise<v
143142
let queue: Awaited<ReturnType<typeof getJobQueue>>
144143
try {
145144
queue = await getJobQueue()
146-
logger.info(`[FLASH-DEBUG] enqueue START row=${rowId} group=${groupId}`)
147145
jobId = await queue.enqueue('workflow-group-cell', taskPayload, {
148146
metadata: {
149147
workflowId,
@@ -183,7 +181,6 @@ export async function runWorkflowGroupCell(opts: RunGroupCellOptions): Promise<v
183181
// we abort the just-enqueued job.
184182
let stampResult: 'wrote' | 'skipped' = 'wrote'
185183
try {
186-
logger.info(`[FLASH-DEBUG] write running+jobId row=${rowId} group=${groupId} jobId=${jobId}`)
187184
stampResult = await writeWorkflowGroupState(cellCtx, {
188185
executionState: {
189186
status: 'running',

0 commit comments

Comments
 (0)