Initial work to get relationship column saving working as expecting, sending out events on datasource update for tables, trying to move more to table API where possible.

This commit is contained in:
mike12345567 2023-12-11 17:27:05 +00:00
parent a3ebf0bffd
commit 7b2880fbe2
6 changed files with 78 additions and 749 deletions

View File

@ -1,14 +1,19 @@
<script>
import { ActionButton, notifications } from "@budibase/bbui"
import CreateEditRelationshipModal from "../../Datasources/CreateEditRelationshipModal.svelte"
import { datasources } from "../../../../stores/backend"
import {
datasources,
tables as tablesStore,
} from "../../../../stores/backend"
import { createEventDispatcher } from "svelte"
export let table
const dispatch = createEventDispatcher()
$: datasource = findDatasource(table?._id)
$: tables = datasource?.plus ? Object.values(datasource?.entities || {}) : []
$: tables = datasource?.plus
? $tablesStore.list.filter(tbl => tbl.sourceId === datasource._id)
: []
let modal
@ -22,13 +27,18 @@
})
}
const afterSave = ({ action }) => {
const afterSave = async ({ action }) => {
notifications.success(`Relationship ${action} successfully`)
dispatch("updatecolumns")
}
const onError = err => {
notifications.error(`Error saving relationship info: ${err}`)
if (err.err) {
err = err.err
}
notifications.error(
`Error saving relationship info: ${err?.message || JSON.stringify(err)}`
)
}
</script>

View File

@ -85,6 +85,7 @@
let relationshipTableIdSecondary = null
let table = $tables.selected
let confirmDeleteDialog
let savingColumn
let deleteColName

View File

@ -2,7 +2,13 @@
import { getContext } from "svelte"
import CreateEditColumn from "components/backend/DataTable/modals/CreateEditColumn.svelte"
const { datasource } = getContext("grid")
const { datasource, rows } = getContext("grid")
</script>
<CreateEditColumn on:updatecolumns={datasource.actions.refreshDefinition} />
<CreateEditColumn
on:updatecolumns={async () => {
await datasource.actions.refreshDefinition()
// Need to find a better way to handle formula columns than just always refreshing
rows.actions.refreshData()
}}
/>

View File

@ -15,7 +15,8 @@
let modal
$: tables = Object.values(datasource.entities)
$: tables =
$tablesStore.list.filter(tbl => tbl.sourceId === datasource._id) || []
$: relationships = getRelationships(tables)
function getRelationships(tables) {

View File

@ -26,6 +26,7 @@ import {
import sdk from "../../sdk"
import { builderSocket } from "../../websockets"
import { setupCreationAuth as googleSetupCreationAuth } from "../../integrations/googlesheets"
import { isEqual } from "lodash"
async function getConnector(
datasource: Datasource
@ -198,19 +199,20 @@ async function invalidateVariables(
export async function update(ctx: UserCtx<any, UpdateDatasourceResponse>) {
const db = context.getAppDB()
const datasourceId = ctx.params.datasourceId
let datasource = await sdk.datasources.get(datasourceId)
const auth = datasource.config?.auth
await invalidateVariables(datasource, ctx.request.body)
const baseDatasource = await sdk.datasources.get(datasourceId)
const auth = baseDatasource.config?.auth
await invalidateVariables(baseDatasource, ctx.request.body)
const isBudibaseSource = datasource.type === dbCore.BUDIBASE_DATASOURCE_TYPE
const isBudibaseSource =
baseDatasource.type === dbCore.BUDIBASE_DATASOURCE_TYPE
const dataSourceBody = isBudibaseSource
? { name: ctx.request.body?.name }
: ctx.request.body
datasource = {
...datasource,
...sdk.datasources.mergeConfigs(dataSourceBody, datasource),
let datasource: Datasource = {
...baseDatasource,
...sdk.datasources.mergeConfigs(dataSourceBody, baseDatasource),
}
if (auth && !ctx.request.body.auth) {
// don't strip auth config from DB
@ -245,6 +247,15 @@ export async function update(ctx: UserCtx<any, UpdateDatasourceResponse>) {
datasource: await sdk.datasources.removeSecretSingle(datasource),
}
builderSocket?.emitDatasourceUpdate(ctx, datasource)
// send table updates if they have occurred
if (datasource.entities) {
for (let table of Object.values(datasource.entities)) {
const oldTable = baseDatasource.entities?.[table.name]
if (!oldTable || !isEqual(oldTable, table)) {
builderSocket?.emitTableUpdate(ctx, table, { includeOriginator: true })
}
}
}
}
const preSaveAction: Partial<Record<SourceName, any>> = {

770
yarn.lock

File diff suppressed because it is too large Load Diff