Spring cleaning before review.
This commit is contained in:
parent
70f39b6b6b
commit
007e919d0e
|
@ -169,8 +169,8 @@ export async function migrate(ctx: UserCtx<MigrateRequest, MigrateResponse>) {
|
||||||
let result = await sdk.tables.migrate(table, oldColumn, newColumn)
|
let result = await sdk.tables.migrate(table, oldColumn, newColumn)
|
||||||
|
|
||||||
for (let table of result.tablesUpdated) {
|
for (let table of result.tablesUpdated) {
|
||||||
builderSocket?.emitTableUpdate(ctx, processInternalTable(table), {
|
builderSocket?.emitTableUpdate(ctx, table, {
|
||||||
includeSelf: true,
|
includeOriginator: true,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -87,6 +87,10 @@ export function isExternalTable(tableId: string) {
|
||||||
return tableId.includes(DocumentType.DATASOURCE)
|
return tableId.includes(DocumentType.DATASOURCE)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isInternalTable(tableId: string) {
|
||||||
|
return !isExternalTable(tableId)
|
||||||
|
}
|
||||||
|
|
||||||
export function buildExternalTableId(datasourceId: string, tableName: string) {
|
export function buildExternalTableId(datasourceId: string, tableName: string) {
|
||||||
// encode spaces
|
// encode spaces
|
||||||
if (tableName.includes(" ")) {
|
if (tableName.includes(" ")) {
|
||||||
|
|
|
@ -16,6 +16,8 @@ import { gridSocket } from "./index"
|
||||||
import { clearLock, updateLock } from "../utilities/redis"
|
import { clearLock, updateLock } from "../utilities/redis"
|
||||||
import { Socket } from "socket.io"
|
import { Socket } from "socket.io"
|
||||||
import { BuilderSocketEvent } from "@budibase/shared-core"
|
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 {
|
export default class BuilderSocket extends BaseSocket {
|
||||||
constructor(app: Koa, server: http.Server) {
|
constructor(app: Koa, server: http.Server) {
|
||||||
|
@ -101,6 +103,13 @@ export default class BuilderSocket extends BaseSocket {
|
||||||
}
|
}
|
||||||
|
|
||||||
emitTableUpdate(ctx: any, table: Table, options?: EmitOptions) {
|
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(
|
this.emitToRoom(
|
||||||
ctx,
|
ctx,
|
||||||
ctx.appId,
|
ctx.appId,
|
||||||
|
|
|
@ -13,8 +13,10 @@ import { createContext, runMiddlewares } from "./middleware"
|
||||||
|
|
||||||
export interface EmitOptions {
|
export interface EmitOptions {
|
||||||
// Whether to include the originator of the request from the broadcast,
|
// Whether to include the originator of the request from the broadcast,
|
||||||
// defaults to false.
|
// defaults to false because it is assumed that the user who triggered
|
||||||
includeSelf?: boolean
|
// 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 = () => ({
|
const anonUser = () => ({
|
||||||
|
@ -284,7 +286,7 @@ export class BaseSocket {
|
||||||
options?: EmitOptions
|
options?: EmitOptions
|
||||||
) {
|
) {
|
||||||
let emitPayload = { ...payload }
|
let emitPayload = { ...payload }
|
||||||
if (!options?.includeSelf) {
|
if (!options?.includeOriginator) {
|
||||||
emitPayload.apiSessionId = ctx.headers?.[Header.SESSION_ID]
|
emitPayload.apiSessionId = ctx.headers?.[Header.SESSION_ID]
|
||||||
}
|
}
|
||||||
this.io.in(room).emit(event, emitPayload)
|
this.io.in(room).emit(event, emitPayload)
|
||||||
|
|
Loading…
Reference in New Issue