Block notifications following a datasource invalidation so that unnecessary notification don't get shown
This commit is contained in:
parent
f5fe4c9bb7
commit
b0cf9d2544
|
@ -1,4 +1,5 @@
|
||||||
import { writable, get } from "svelte/store"
|
import { writable, get } from "svelte/store"
|
||||||
|
import { notificationStore } from "./notification"
|
||||||
|
|
||||||
export const createDatasourceStore = () => {
|
export const createDatasourceStore = () => {
|
||||||
const store = writable([])
|
const store = writable([])
|
||||||
|
@ -66,6 +67,9 @@ export const createDatasourceStore = () => {
|
||||||
const relatedInstances = get(store).filter(instance => {
|
const relatedInstances = get(store).filter(instance => {
|
||||||
return instance.datasourceId === datasourceId
|
return instance.datasourceId === datasourceId
|
||||||
})
|
})
|
||||||
|
if (relatedInstances?.length) {
|
||||||
|
notificationStore.blockNotifications(1000)
|
||||||
|
}
|
||||||
relatedInstances?.forEach(instance => {
|
relatedInstances?.forEach(instance => {
|
||||||
instance.refresh()
|
instance.refresh()
|
||||||
})
|
})
|
||||||
|
|
|
@ -5,13 +5,22 @@ const NOTIFICATION_TIMEOUT = 3000
|
||||||
|
|
||||||
const createNotificationStore = () => {
|
const createNotificationStore = () => {
|
||||||
const _notifications = writable([])
|
const _notifications = writable([])
|
||||||
|
let block = false
|
||||||
|
|
||||||
const send = (message, type = "default") => {
|
const send = (message, type = "default") => {
|
||||||
|
if (block) {
|
||||||
|
return
|
||||||
|
}
|
||||||
_notifications.update(state => {
|
_notifications.update(state => {
|
||||||
return [...state, { id: generate(), type, message }]
|
return [...state, { id: generate(), type, message }]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const blockNotifications = (timeout = 1000) => {
|
||||||
|
block = true
|
||||||
|
setTimeout(() => (block = false), timeout)
|
||||||
|
}
|
||||||
|
|
||||||
const notifications = derived(_notifications, ($_notifications, set) => {
|
const notifications = derived(_notifications, ($_notifications, set) => {
|
||||||
set($_notifications)
|
set($_notifications)
|
||||||
if ($_notifications.length > 0) {
|
if ($_notifications.length > 0) {
|
||||||
|
@ -36,6 +45,7 @@ const createNotificationStore = () => {
|
||||||
warning: msg => send(msg, "warning"),
|
warning: msg => send(msg, "warning"),
|
||||||
info: msg => send(msg, "info"),
|
info: msg => send(msg, "info"),
|
||||||
success: msg => send(msg, "success"),
|
success: msg => send(msg, "success"),
|
||||||
|
blockNotifications,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue