Merge pull request #4951 from Budibase/fix/query-schema-error
Don't attempt to invalidate related datasources when invalidating queries
This commit is contained in:
commit
0a22bb9034
|
@ -20,8 +20,8 @@
|
|||
let listenersAttached = false
|
||||
|
||||
const proxyInvalidation = event => {
|
||||
const { dataSourceId } = event.detail
|
||||
dataSourceStore.actions.invalidateDataSource(dataSourceId)
|
||||
const { dataSourceId, options } = event.detail
|
||||
dataSourceStore.actions.invalidateDataSource(dataSourceId, options)
|
||||
}
|
||||
|
||||
const proxyNotification = event => {
|
||||
|
|
|
@ -54,18 +54,24 @@ export const createDataSourceStore = () => {
|
|||
|
||||
// Invalidates a specific dataSource ID by refreshing all instances
|
||||
// which depend on data from that dataSource
|
||||
const invalidateDataSource = async dataSourceId => {
|
||||
const invalidateDataSource = async (dataSourceId, options) => {
|
||||
if (!dataSourceId) {
|
||||
return
|
||||
}
|
||||
|
||||
// Merge default options
|
||||
options = {
|
||||
invalidateRelationships: false,
|
||||
...options,
|
||||
}
|
||||
|
||||
// Emit this as a window event, so parent screens which are iframing us in
|
||||
// can also invalidate the same datasource
|
||||
const inModal = get(routeStore).queryParams?.peek
|
||||
if (inModal) {
|
||||
window.parent.postMessage({
|
||||
type: "invalidate-datasource",
|
||||
detail: { dataSourceId },
|
||||
detail: { dataSourceId, options },
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -73,13 +79,14 @@ export const createDataSourceStore = () => {
|
|||
|
||||
// Fetch related table IDs from table schema
|
||||
let schema
|
||||
if (options.invalidateRelationships) {
|
||||
try {
|
||||
const definition = await API.fetchTableDefinition(dataSourceId)
|
||||
schema = definition?.schema
|
||||
} catch (error) {
|
||||
schema = null
|
||||
}
|
||||
|
||||
}
|
||||
if (schema) {
|
||||
Object.values(schema).forEach(fieldSchema => {
|
||||
if (
|
||||
|
|
|
@ -37,7 +37,9 @@ const saveRowHandler = async (action, context) => {
|
|||
notificationStore.actions.success("Row saved")
|
||||
|
||||
// Refresh related datasources
|
||||
await dataSourceStore.actions.invalidateDataSource(row.tableId)
|
||||
await dataSourceStore.actions.invalidateDataSource(row.tableId, {
|
||||
invalidateRelationships: true,
|
||||
})
|
||||
|
||||
return { row }
|
||||
} catch (error) {
|
||||
|
@ -65,7 +67,9 @@ const duplicateRowHandler = async (action, context) => {
|
|||
notificationStore.actions.success("Row saved")
|
||||
|
||||
// Refresh related datasources
|
||||
await dataSourceStore.actions.invalidateDataSource(row.tableId)
|
||||
await dataSourceStore.actions.invalidateDataSource(row.tableId, {
|
||||
invalidateRelationships: true,
|
||||
})
|
||||
|
||||
return { row }
|
||||
} catch (error) {
|
||||
|
@ -83,7 +87,9 @@ const deleteRowHandler = async action => {
|
|||
notificationStore.actions.success("Row deleted")
|
||||
|
||||
// Refresh related datasources
|
||||
await dataSourceStore.actions.invalidateDataSource(tableId)
|
||||
await dataSourceStore.actions.invalidateDataSource(tableId, {
|
||||
invalidateRelationships: true,
|
||||
})
|
||||
} catch (error) {
|
||||
// Abort next actions
|
||||
return false
|
||||
|
|
Loading…
Reference in New Issue