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