1
0
Fork 0
mirror of synced 2024-06-02 02:25:17 +12:00

Add 'continue if' button action

This commit is contained in:
Andrew Kingston 2022-03-25 09:26:15 +00:00
parent 8887b67ecc
commit ff327423e1
6 changed files with 109 additions and 2 deletions

View file

@ -45,6 +45,7 @@ const INITIAL_FRONTEND_STATE = {
customThemes: false,
devicePreview: false,
messagePassing: false,
continueIfAction: false,
},
currentFrontEndType: "none",
selectedScreenId: "",

View file

@ -0,0 +1,78 @@
<script>
import { Select, Body } from "@budibase/bbui"
import { onMount } from "svelte"
import DrawerBindableInput from "components/common/bindings/DrawerBindableInput.svelte"
export let parameters
export let bindings
const typeOptions = [
{
label: "Continue if",
value: "continue",
},
{
label: "Stop if",
value: "stop",
},
]
const operatorOptions = [
{
label: "Equals",
value: "equal",
},
{
label: "Not equals",
value: "notEqual",
},
]
onMount(() => {
if (!parameters.type) {
parameters.type = "continue"
}
if (!parameters.operator) {
parameters.operator = "equal"
}
})
</script>
<div class="root">
<Body size="S">
Configure a condition to be evaluated which can stop further actions from
being executed.
</Body>
<Select
bind:value={parameters.type}
options={typeOptions}
placeholder={null}
/>
<DrawerBindableInput
placeholder="Value"
value={parameters.value}
on:change={e => (parameters.value = e.detail)}
{bindings}
/>
<Select
bind:value={parameters.operator}
options={operatorOptions}
placeholder={null}
/>
<DrawerBindableInput
placeholder="Reference value"
bind:value={parameters.referenceValue}
on:change={e => (parameters.referenceValue = e.detail)}
{bindings}
/>
</div>
<style>
.root {
display: flex;
flex-direction: column;
gap: var(--spacing-l);
justify-content: flex-start;
align-items: stretch;
max-width: 400px;
margin: 0 auto;
}
</style>

View file

@ -13,3 +13,4 @@ export { default as RefreshDataProvider } from "./RefreshDataProvider.svelte"
export { default as DuplicateRow } from "./DuplicateRow.svelte"
export { default as S3Upload } from "./S3Upload.svelte"
export { default as ExportData } from "./ExportData.svelte"
export { default as ContinueIf } from "./ContinueIf.svelte"

View file

@ -84,6 +84,11 @@
{
"name": "Export Data",
"component": "ExportData"
},
{
"name": "Continue if / Stop if",
"component": "ContinueIf",
"dependsOnFeature": "continueIfAction"
}
]
}
}

View file

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

View file

@ -261,6 +261,26 @@ const exportDataHandler = async action => {
}
}
const continueIfHandler = action => {
const { type, value, operator, referenceValue } = action.parameters
if (!type || !operator) {
return
}
let match = false
if (value == null && referenceValue == null) {
match = true
} else if (value === referenceValue) {
match = true
} else {
match = JSON.stringify(value) === JSON.stringify(referenceValue)
}
if (type === "continue") {
return operator === "equal" ? match : !match
} else {
return operator === "equal" ? !match : match
}
}
const handlerMap = {
["Save Row"]: saveRowHandler,
["Duplicate Row"]: duplicateRowHandler,
@ -277,6 +297,7 @@ const handlerMap = {
["Update State"]: updateStateHandler,
["Upload File to S3"]: s3UploadHandler,
["Export Data"]: exportDataHandler,
["Continue if / Stop if"]: continueIfHandler,
}
const confirmTextMap = {