Allow configuring whether notification is automatically dismissed or not

This commit is contained in:
Andrew Kingston 2022-08-22 11:08:52 +01:00
parent 8a2f35b3f0
commit 19c99f4390
3 changed files with 18 additions and 9 deletions

View File

@ -1,5 +1,5 @@
<script> <script>
import { Select, Label } from "@budibase/bbui" import { Select, Label, Checkbox } from "@budibase/bbui"
import { onMount } from "svelte" import { onMount } from "svelte"
import DrawerBindableInput from "components/common/bindings/DrawerBindableInput.svelte" import DrawerBindableInput from "components/common/bindings/DrawerBindableInput.svelte"
@ -28,17 +28,22 @@
if (!parameters.type) { if (!parameters.type) {
parameters.type = "success" parameters.type = "success"
} }
if (parameters.autoDismiss == null) {
parameters.autoDismiss = true
}
}) })
</script> </script>
<div class="root"> <div class="root">
<Label small>Type</Label> <Label>Type</Label>
<Select bind:value={parameters.type} options={types} placeholder={null} /> <Select bind:value={parameters.type} options={types} placeholder={null} />
<Label small>Message</Label> <Label>Message</Label>
<DrawerBindableInput <DrawerBindableInput
value={parameters.message} value={parameters.message}
on:change={e => (parameters.message = e.detail)} on:change={e => (parameters.message = e.detail)}
/> />
<Label />
<Checkbox text="Auto dismiss" bind:value={parameters.autoDismiss} />
</div> </div>
<style> <style>

View File

@ -62,10 +62,14 @@ const createNotificationStore = () => {
subscribe: store.subscribe, subscribe: store.subscribe,
actions: { actions: {
send, send,
info: msg => send(msg, "info", "Info"), info: (msg, autoDismiss) =>
success: msg => send(msg, "success", "CheckmarkCircle"), send(msg, "info", "Info", autoDismiss ?? true),
warning: msg => send(msg, "warning", "Alert"), success: (msg, autoDismiss) =>
error: msg => send(msg, "error", "Alert", false), send(msg, "success", "CheckmarkCircle", autoDismiss ?? true),
warning: (msg, autoDismiss) =>
send(msg, "warning", "Alert", autoDismiss ?? true),
error: (msg, autoDismiss) =>
send(msg, "error", "Alert", autoDismiss ?? false),
blockNotifications, blockNotifications,
dismiss, dismiss,
}, },

View File

@ -301,11 +301,11 @@ const continueIfHandler = action => {
} }
const showNotificationHandler = action => { const showNotificationHandler = action => {
const { message, type } = action.parameters const { message, type, autoDismiss } = action.parameters
if (!message || !type) { if (!message || !type) {
return return
} }
notificationStore.actions[type]?.(message) notificationStore.actions[type]?.(message, autoDismiss)
} }
const handlerMap = { const handlerMap = {