Don't attempt to invalidate related datasources when invalidating query datasources

This commit is contained in:
Andrew Kingston 2022-03-18 15:21:24 +00:00
parent ac32c2ee5f
commit 80adf9be14
3 changed files with 26 additions and 13 deletions

View File

@ -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 => {

View File

@ -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 (

View File

@ -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