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:
parent
a3ebf0bffd
commit
7b2880fbe2
|
@ -1,14 +1,19 @@
|
||||||
<script>
|
<script>
|
||||||
import { ActionButton, notifications } from "@budibase/bbui"
|
import { ActionButton, notifications } from "@budibase/bbui"
|
||||||
import CreateEditRelationshipModal from "../../Datasources/CreateEditRelationshipModal.svelte"
|
import CreateEditRelationshipModal from "../../Datasources/CreateEditRelationshipModal.svelte"
|
||||||
import { datasources } from "../../../../stores/backend"
|
import {
|
||||||
|
datasources,
|
||||||
|
tables as tablesStore,
|
||||||
|
} from "../../../../stores/backend"
|
||||||
import { createEventDispatcher } from "svelte"
|
import { createEventDispatcher } from "svelte"
|
||||||
|
|
||||||
export let table
|
export let table
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
|
|
||||||
$: datasource = findDatasource(table?._id)
|
$: datasource = findDatasource(table?._id)
|
||||||
$: tables = datasource?.plus ? Object.values(datasource?.entities || {}) : []
|
$: tables = datasource?.plus
|
||||||
|
? $tablesStore.list.filter(tbl => tbl.sourceId === datasource._id)
|
||||||
|
: []
|
||||||
|
|
||||||
let modal
|
let modal
|
||||||
|
|
||||||
|
@ -22,13 +27,18 @@
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const afterSave = ({ action }) => {
|
const afterSave = async ({ action }) => {
|
||||||
notifications.success(`Relationship ${action} successfully`)
|
notifications.success(`Relationship ${action} successfully`)
|
||||||
dispatch("updatecolumns")
|
dispatch("updatecolumns")
|
||||||
}
|
}
|
||||||
|
|
||||||
const onError = err => {
|
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>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -85,6 +85,7 @@
|
||||||
let relationshipTableIdSecondary = null
|
let relationshipTableIdSecondary = null
|
||||||
|
|
||||||
let table = $tables.selected
|
let table = $tables.selected
|
||||||
|
|
||||||
let confirmDeleteDialog
|
let confirmDeleteDialog
|
||||||
let savingColumn
|
let savingColumn
|
||||||
let deleteColName
|
let deleteColName
|
||||||
|
|
|
@ -2,7 +2,13 @@
|
||||||
import { getContext } from "svelte"
|
import { getContext } from "svelte"
|
||||||
import CreateEditColumn from "components/backend/DataTable/modals/CreateEditColumn.svelte"
|
import CreateEditColumn from "components/backend/DataTable/modals/CreateEditColumn.svelte"
|
||||||
|
|
||||||
const { datasource } = getContext("grid")
|
const { datasource, rows } = getContext("grid")
|
||||||
</script>
|
</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()
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
|
@ -15,7 +15,8 @@
|
||||||
|
|
||||||
let modal
|
let modal
|
||||||
|
|
||||||
$: tables = Object.values(datasource.entities)
|
$: tables =
|
||||||
|
$tablesStore.list.filter(tbl => tbl.sourceId === datasource._id) || []
|
||||||
$: relationships = getRelationships(tables)
|
$: relationships = getRelationships(tables)
|
||||||
|
|
||||||
function getRelationships(tables) {
|
function getRelationships(tables) {
|
||||||
|
|
|
@ -26,6 +26,7 @@ import {
|
||||||
import sdk from "../../sdk"
|
import sdk from "../../sdk"
|
||||||
import { builderSocket } from "../../websockets"
|
import { builderSocket } from "../../websockets"
|
||||||
import { setupCreationAuth as googleSetupCreationAuth } from "../../integrations/googlesheets"
|
import { setupCreationAuth as googleSetupCreationAuth } from "../../integrations/googlesheets"
|
||||||
|
import { isEqual } from "lodash"
|
||||||
|
|
||||||
async function getConnector(
|
async function getConnector(
|
||||||
datasource: Datasource
|
datasource: Datasource
|
||||||
|
@ -198,19 +199,20 @@ async function invalidateVariables(
|
||||||
export async function update(ctx: UserCtx<any, UpdateDatasourceResponse>) {
|
export async function update(ctx: UserCtx<any, UpdateDatasourceResponse>) {
|
||||||
const db = context.getAppDB()
|
const db = context.getAppDB()
|
||||||
const datasourceId = ctx.params.datasourceId
|
const datasourceId = ctx.params.datasourceId
|
||||||
let datasource = await sdk.datasources.get(datasourceId)
|
const baseDatasource = await sdk.datasources.get(datasourceId)
|
||||||
const auth = datasource.config?.auth
|
const auth = baseDatasource.config?.auth
|
||||||
await invalidateVariables(datasource, ctx.request.body)
|
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
|
const dataSourceBody = isBudibaseSource
|
||||||
? { name: ctx.request.body?.name }
|
? { name: ctx.request.body?.name }
|
||||||
: ctx.request.body
|
: ctx.request.body
|
||||||
|
|
||||||
datasource = {
|
let datasource: Datasource = {
|
||||||
...datasource,
|
...baseDatasource,
|
||||||
...sdk.datasources.mergeConfigs(dataSourceBody, datasource),
|
...sdk.datasources.mergeConfigs(dataSourceBody, baseDatasource),
|
||||||
}
|
}
|
||||||
if (auth && !ctx.request.body.auth) {
|
if (auth && !ctx.request.body.auth) {
|
||||||
// don't strip auth config from DB
|
// 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),
|
datasource: await sdk.datasources.removeSecretSingle(datasource),
|
||||||
}
|
}
|
||||||
builderSocket?.emitDatasourceUpdate(ctx, 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>> = {
|
const preSaveAction: Partial<Record<SourceName, any>> = {
|
||||||
|
|
Loading…
Reference in New Issue