diff --git a/packages/server/src/api/controllers/table/index.ts b/packages/server/src/api/controllers/table/index.ts index f139313086..d2ad63c13e 100644 --- a/packages/server/src/api/controllers/table/index.ts +++ b/packages/server/src/api/controllers/table/index.ts @@ -169,8 +169,8 @@ export async function migrate(ctx: UserCtx) { let result = await sdk.tables.migrate(table, oldColumn, newColumn) for (let table of result.tablesUpdated) { - builderSocket?.emitTableUpdate(ctx, processInternalTable(table), { - includeSelf: true, + builderSocket?.emitTableUpdate(ctx, table, { + includeOriginator: true, }) } diff --git a/packages/server/src/integrations/utils.ts b/packages/server/src/integrations/utils.ts index 79b18e767c..b37fe9f0ed 100644 --- a/packages/server/src/integrations/utils.ts +++ b/packages/server/src/integrations/utils.ts @@ -87,6 +87,10 @@ export function isExternalTable(tableId: string) { return tableId.includes(DocumentType.DATASOURCE) } +export function isInternalTable(tableId: string) { + return !isExternalTable(tableId) +} + export function buildExternalTableId(datasourceId: string, tableName: string) { // encode spaces if (tableName.includes(" ")) { diff --git a/packages/server/src/websockets/builder.ts b/packages/server/src/websockets/builder.ts index b1ef473d6c..2cff24e635 100644 --- a/packages/server/src/websockets/builder.ts +++ b/packages/server/src/websockets/builder.ts @@ -16,6 +16,8 @@ import { gridSocket } from "./index" import { clearLock, updateLock } from "../utilities/redis" import { Socket } from "socket.io" import { BuilderSocketEvent } from "@budibase/shared-core" +import { processInternalTable } from "../sdk/app/tables/getters" +import { isExternalTable, isInternalTable } from "../integrations/utils" export default class BuilderSocket extends BaseSocket { constructor(app: Koa, server: http.Server) { @@ -101,6 +103,13 @@ export default class BuilderSocket extends BaseSocket { } emitTableUpdate(ctx: any, table: Table, options?: EmitOptions) { + // This was added to make sure that sourceId is always present when + // sending this message to clients. Without this, tables without a + // sourceId (e.g. ta_users) won't get correctly updated client-side. + if (isInternalTable(table._id!)) { + table = processInternalTable(table) + } + this.emitToRoom( ctx, ctx.appId, diff --git a/packages/server/src/websockets/websocket.ts b/packages/server/src/websockets/websocket.ts index a0dc388d4f..1dba108d24 100644 --- a/packages/server/src/websockets/websocket.ts +++ b/packages/server/src/websockets/websocket.ts @@ -13,8 +13,10 @@ import { createContext, runMiddlewares } from "./middleware" export interface EmitOptions { // Whether to include the originator of the request from the broadcast, - // defaults to false. - includeSelf?: boolean + // defaults to false because it is assumed that the user who triggered + // an action will already have the changes of that action reflected in their + // own UI, so there is no need to send them again. + includeOriginator?: boolean } const anonUser = () => ({ @@ -284,7 +286,7 @@ export class BaseSocket { options?: EmitOptions ) { let emitPayload = { ...payload } - if (!options?.includeSelf) { + if (!options?.includeOriginator) { emitPayload.apiSessionId = ctx.headers?.[Header.SESSION_ID] } this.io.in(room).emit(event, emitPayload)