diff --git a/packages/builder/src/components/backend/DataTable/DataTable.svelte b/packages/builder/src/components/backend/DataTable/DataTable.svelte index 1b0c92bde0..981a619ebd 100644 --- a/packages/builder/src/components/backend/DataTable/DataTable.svelte +++ b/packages/builder/src/components/backend/DataTable/DataTable.svelte @@ -1,5 +1,5 @@
@@ -37,7 +49,7 @@ allowDeleteRows={!isUsersTable} schemaOverrides={isUsersTable ? userSchemaOverrides : null} showAvatars={false} - on:updatetable={e => tables.replaceTable(id, e.detail)} + on:updatetable={handleGridTableUpdate} > {#if isInternal} diff --git a/packages/builder/src/components/backend/TableNavigator/modals/CreateTableModal.svelte b/packages/builder/src/components/backend/TableNavigator/modals/CreateTableModal.svelte index bd1761620d..bfca91afaa 100644 --- a/packages/builder/src/components/backend/TableNavigator/modals/CreateTableModal.svelte +++ b/packages/builder/src/components/backend/TableNavigator/modals/CreateTableModal.svelte @@ -93,6 +93,7 @@ try { await beforeSave() table = await tables.save(newTable) + await datasources.fetch() await afterSave(table) } catch (e) { notifications.error(e) diff --git a/packages/builder/src/components/backend/TableNavigator/popovers/EditTablePopover.svelte b/packages/builder/src/components/backend/TableNavigator/popovers/EditTablePopover.svelte index 01c62d56f7..11ef60480b 100644 --- a/packages/builder/src/components/backend/TableNavigator/popovers/EditTablePopover.svelte +++ b/packages/builder/src/components/backend/TableNavigator/popovers/EditTablePopover.svelte @@ -65,6 +65,7 @@ const updatedTable = cloneDeep(table) updatedTable.name = updatedName await tables.save(updatedTable) + await datasources.fetch() notifications.success("Table renamed successfully") } diff --git a/packages/builder/src/stores/backend/datasources.js b/packages/builder/src/stores/backend/datasources.js index 0815f9d766..af914cbee7 100644 --- a/packages/builder/src/stores/backend/datasources.js +++ b/packages/builder/src/stores/backend/datasources.js @@ -113,6 +113,10 @@ export function createDatasourcesStore() { ...state, list: [...state.list, datasource], })) + + // If this is a new datasource then we should refresh the tables list, + // because otherwise we'll never see the new tables + tables.fetch() } // Update existing datasource diff --git a/packages/builder/src/stores/backend/tables.js b/packages/builder/src/stores/backend/tables.js index f8796712a8..d79ed6f072 100644 --- a/packages/builder/src/stores/backend/tables.js +++ b/packages/builder/src/stores/backend/tables.js @@ -1,5 +1,4 @@ import { get, writable, derived } from "svelte/store" -import { datasources } from "./" import { cloneDeep } from "lodash/fp" import { API } from "api" import { SWITCHABLE_TYPES } from "constants/backend" @@ -63,7 +62,6 @@ export function createTablesStore() { const savedTable = await API.saveTable(updatedTable) replaceTable(savedTable._id, savedTable) - await datasources.fetch() select(savedTable._id) return savedTable } diff --git a/packages/frontend-core/src/components/grid/stores/columns.js b/packages/frontend-core/src/components/grid/stores/columns.js index 024fdc29bc..82a26d923c 100644 --- a/packages/frontend-core/src/components/grid/stores/columns.js +++ b/packages/frontend-core/src/components/grid/stores/columns.js @@ -90,12 +90,12 @@ export const deriveStores = context => { // Update local state table.set(newTable) + // Update server + await API.saveTable(newTable) + // Broadcast change to external state can be updated, as this change // will not be received by the builder websocket because we caused it ourselves dispatch("updatetable", newTable) - - // Update server - await API.saveTable(newTable) } return { diff --git a/packages/server/src/api/controllers/table/external.ts b/packages/server/src/api/controllers/table/external.ts index ee789ddd3a..24d4242478 100644 --- a/packages/server/src/api/controllers/table/external.ts +++ b/packages/server/src/api/controllers/table/external.ts @@ -26,6 +26,7 @@ import { RelationshipTypes, } from "@budibase/types" import sdk from "../../../sdk" +import { builderSocket } from "../../../websockets" const { cloneDeep } = require("lodash/fp") async function makeTableRequest( @@ -318,6 +319,11 @@ export async function save(ctx: UserCtx) { datasource.entities[tableToSave.name] = tableToSave await db.put(datasource) + // Since tables are stored inside datasources, we need to notify clients + // that the datasource definition changed + const updatedDatasource = await db.get(datasource._id) + builderSocket?.emitDatasourceUpdate(ctx, updatedDatasource) + return tableToSave } @@ -344,6 +350,11 @@ export async function destroy(ctx: UserCtx) { await db.put(datasource) + // Since tables are stored inside datasources, we need to notify clients + // that the datasource definition changed + const updatedDatasource = await db.get(datasource._id) + builderSocket?.emitDatasourceUpdate(ctx, updatedDatasource) + return tableToDelete }