From 9a73a16b0c9d7b0299769ceab3dd6ffa1c85e0f1 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 11 Feb 2021 09:39:35 +0000 Subject: [PATCH] Block notifications following a datasource invalidation so that unnecessary notification don't get shown --- packages/client/src/store/datasource.js | 4 ++++ packages/client/src/store/notification.js | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/packages/client/src/store/datasource.js b/packages/client/src/store/datasource.js index 58fa632c49..ac129efc10 100644 --- a/packages/client/src/store/datasource.js +++ b/packages/client/src/store/datasource.js @@ -1,4 +1,5 @@ import { writable, get } from "svelte/store" +import { notificationStore } from "./notification" export const createDatasourceStore = () => { const store = writable([]) @@ -66,6 +67,9 @@ export const createDatasourceStore = () => { const relatedInstances = get(store).filter(instance => { return instance.datasourceId === datasourceId }) + if (relatedInstances?.length) { + notificationStore.blockNotifications(1000) + } relatedInstances?.forEach(instance => { instance.refresh() }) diff --git a/packages/client/src/store/notification.js b/packages/client/src/store/notification.js index 8e8f465e07..64757569ed 100644 --- a/packages/client/src/store/notification.js +++ b/packages/client/src/store/notification.js @@ -5,13 +5,22 @@ const NOTIFICATION_TIMEOUT = 3000 const createNotificationStore = () => { const _notifications = writable([]) + let block = false const send = (message, type = "default") => { + if (block) { + return + } _notifications.update(state => { return [...state, { id: generate(), type, message }] }) } + const blockNotifications = (timeout = 1000) => { + block = true + setTimeout(() => (block = false), timeout) + } + const notifications = derived(_notifications, ($_notifications, set) => { set($_notifications) if ($_notifications.length > 0) { @@ -36,6 +45,7 @@ const createNotificationStore = () => { warning: msg => send(msg, "warning"), info: msg => send(msg, "info"), success: msg => send(msg, "success"), + blockNotifications, } }