From 80adf9be14241aed11272df317acca86bd90dfdb Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 18 Mar 2022 15:21:24 +0000 Subject: [PATCH] Don't attempt to invalidate related datasources when invalidating query datasources --- .../overlay/PeekScreenDisplay.svelte | 4 ++-- packages/client/src/stores/dataSource.js | 23 ++++++++++++------- packages/client/src/utils/buttonActions.js | 12 +++++++--- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/packages/client/src/components/overlay/PeekScreenDisplay.svelte b/packages/client/src/components/overlay/PeekScreenDisplay.svelte index 72ea58c194..d6da9ca3f0 100644 --- a/packages/client/src/components/overlay/PeekScreenDisplay.svelte +++ b/packages/client/src/components/overlay/PeekScreenDisplay.svelte @@ -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 => { diff --git a/packages/client/src/stores/dataSource.js b/packages/client/src/stores/dataSource.js index d5ad0cb594..6288cbc072 100644 --- a/packages/client/src/stores/dataSource.js +++ b/packages/client/src/stores/dataSource.js @@ -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 - try { - const definition = await API.fetchTableDefinition(dataSourceId) - schema = definition?.schema - } catch (error) { - schema = null + 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 ( diff --git a/packages/client/src/utils/buttonActions.js b/packages/client/src/utils/buttonActions.js index f44e7d7453..40e97be721 100644 --- a/packages/client/src/utils/buttonActions.js +++ b/packages/client/src/utils/buttonActions.js @@ -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