Add action for showing a custom notification

This commit is contained in:
Andrew Kingston 2022-08-22 11:00:51 +01:00
parent fe3d9f40f6
commit ab0d6bd6ed
6 changed files with 73 additions and 1 deletions

View File

@ -40,6 +40,7 @@ const INITIAL_FRONTEND_STATE = {
devicePreview: false,
messagePassing: false,
continueIfAction: false,
showNotificationAction: false,
},
errors: [],
hasAppPackage: false,

View File

@ -0,0 +1,54 @@
<script>
import { Select, Label } from "@budibase/bbui"
import { onMount } from "svelte"
import DrawerBindableInput from "components/common/bindings/DrawerBindableInput.svelte"
export let parameters
const types = [
{
label: "Success",
value: "success",
},
{
label: "Warning",
value: "warning",
},
{
label: "Error",
value: "error",
},
{
label: "Info",
value: "info",
},
]
onMount(() => {
if (!parameters.type) {
parameters.type = "success"
}
})
</script>
<div class="root">
<Label small>Type</Label>
<Select bind:value={parameters.type} options={types} placeholder={null} />
<Label small>Message</Label>
<DrawerBindableInput
value={parameters.message}
on:change={e => (parameters.message = e.detail)}
/>
</div>
<style>
.root {
display: grid;
column-gap: var(--spacing-l);
row-gap: var(--spacing-s);
grid-template-columns: 60px 1fr;
align-items: center;
max-width: 400px;
margin: 0 auto;
}
</style>

View File

@ -15,3 +15,4 @@ export { default as S3Upload } from "./S3Upload.svelte"
export { default as ExportData } from "./ExportData.svelte"
export { default as ContinueIf } from "./ContinueIf.svelte"
export { default as UpdateFieldValue } from "./UpdateFieldValue.svelte"
export { default as ShowNotification } from "./ShowNotification.svelte"

View File

@ -110,6 +110,12 @@
"type": "logic",
"component": "ContinueIf",
"dependsOnFeature": "continueIfAction"
},
{
"name": "Show Notification",
"type": "application",
"component": "ShowNotification",
"dependsOnFeature": "showNotificationAction"
}
]
}

View File

@ -8,7 +8,8 @@
"devicePreview": true,
"messagePassing": true,
"rowSelection": true,
"continueIfAction": true
"continueIfAction": true,
"showNotificationAction": true
},
"layout": {
"name": "Layout",

View File

@ -300,6 +300,14 @@ const continueIfHandler = action => {
}
}
const showNotificationHandler = action => {
const { message, type } = action.parameters
if (!message || !type) {
return
}
notificationStore.actions[type]?.(message)
}
const handlerMap = {
["Save Row"]: saveRowHandler,
["Duplicate Row"]: duplicateRowHandler,
@ -318,6 +326,7 @@ const handlerMap = {
["Upload File to S3"]: s3UploadHandler,
["Export Data"]: exportDataHandler,
["Continue if / Stop if"]: continueIfHandler,
["Show Notification"]: showNotificationHandler,
}
const confirmTextMap = {