Review fixes. Populated Row fields clearing, test data parsing to ensure tableId is present and correct. Also added some initial JSON test data parsing.
This commit is contained in:
parent
c91767ad1f
commit
c2b54f118f
|
@ -15,8 +15,55 @@
|
||||||
let trigger = {}
|
let trigger = {}
|
||||||
let schemaProperties = {}
|
let schemaProperties = {}
|
||||||
|
|
||||||
const memoTestData = memo($selectedAutomation.testData)
|
const rowTriggers = [
|
||||||
$: memoTestData.set($selectedAutomation.testData)
|
AutomationEventType.ROW_DELETE,
|
||||||
|
AutomationEventType.ROW_UPDATE,
|
||||||
|
AutomationEventType.ROW_SAVE,
|
||||||
|
]
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the automation test data and ensures it is valid
|
||||||
|
* @param {object} testData contains all config for the test
|
||||||
|
* @returns {object} valid testData
|
||||||
|
* @todo Parse *all* data for each trigger type and relay adequate feedback
|
||||||
|
*/
|
||||||
|
const parseTestData = testData => {
|
||||||
|
const autoTrigger = $selectedAutomation?.definition?.trigger
|
||||||
|
const { tableId } = autoTrigger?.inputs || {}
|
||||||
|
|
||||||
|
// Ensure the tableId matches the trigger table for row trigger automations
|
||||||
|
if (
|
||||||
|
rowTriggers.includes(autoTrigger?.event) &&
|
||||||
|
testData?.row?.tableId !== tableId
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
// Reset Core fields
|
||||||
|
row: { tableId },
|
||||||
|
meta: {},
|
||||||
|
id: "",
|
||||||
|
revision: "",
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Leave the core data as it is
|
||||||
|
return testData
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Before executing a test run, relay if an automation is in a valid state
|
||||||
|
* @param {object} trigger The automation trigger config
|
||||||
|
* @returns {boolean} validation status
|
||||||
|
* @todo Parse *all* trigger types relay adequate feedback
|
||||||
|
*/
|
||||||
|
const isTriggerValid = trigger => {
|
||||||
|
if (rowTriggers.includes(trigger?.event) && !trigger?.inputs?.tableId) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
const memoTestData = memo(parseTestData($selectedAutomation.testData))
|
||||||
|
$: memoTestData.set(parseTestData($selectedAutomation.testData))
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
// clone the trigger so we're not mutating the reference
|
// clone the trigger so we're not mutating the reference
|
||||||
|
@ -32,18 +79,33 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check the schema to see if required fields have been entered
|
// Check the schema to see if required fields have been entered
|
||||||
$: isError = !trigger.schema.outputs.required.every(
|
$: isError =
|
||||||
required => $memoTestData?.[required] || required !== "row"
|
!isTriggerValid(trigger) ||
|
||||||
)
|
!trigger.schema.outputs.required.every(
|
||||||
|
required => $memoTestData?.[required] || required !== "row"
|
||||||
|
)
|
||||||
|
|
||||||
function parseTestJSON(e) {
|
function parseTestJSON(e) {
|
||||||
|
let jsonUpdate
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const obj = JSON.parse(e.detail)
|
jsonUpdate = JSON.parse(e.detail)
|
||||||
failedParse = null
|
failedParse = null
|
||||||
automationStore.actions.addTestDataToAutomation(obj)
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
failedParse = "Invalid JSON"
|
failedParse = "Invalid JSON"
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (rowTriggers.includes(trigger?.event)) {
|
||||||
|
const tableId = trigger?.inputs?.tableId
|
||||||
|
|
||||||
|
// Reset the tableId as it must match the trigger
|
||||||
|
if (jsonUpdate?.row?.tableId !== tableId) {
|
||||||
|
jsonUpdate.row.tableId = tableId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
automationStore.actions.addTestDataToAutomation(jsonUpdate)
|
||||||
}
|
}
|
||||||
|
|
||||||
const testAutomation = async () => {
|
const testAutomation = async () => {
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
import ModalBindableInput from "../../common/bindings/ModalBindableInput.svelte"
|
import ModalBindableInput from "../../common/bindings/ModalBindableInput.svelte"
|
||||||
import AutomationBindingPanel from "../../common/bindings/ServerBindingPanel.svelte"
|
import AutomationBindingPanel from "../../common/bindings/ServerBindingPanel.svelte"
|
||||||
import { DatePicker, Select } from "@budibase/bbui"
|
import { DatePicker, Select } from "@budibase/bbui"
|
||||||
|
import { FieldType } from "@budibase/types"
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
|
|
||||||
|
@ -13,7 +14,9 @@
|
||||||
export let block
|
export let block
|
||||||
export let isTestModal
|
export let isTestModal
|
||||||
|
|
||||||
let schemaFields
|
const { STRING, NUMBER, ARRAY } = FieldType
|
||||||
|
|
||||||
|
let schemaFields = []
|
||||||
let editableValue
|
let editableValue
|
||||||
|
|
||||||
$: editableValue = { ...value }
|
$: editableValue = { ...value }
|
||||||
|
@ -55,11 +58,11 @@
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if schemaFields.length && isTestModal}
|
{#if schemaFields?.length && isTestModal}
|
||||||
<div class="fields">
|
<div class="fields">
|
||||||
{#each schemaFields as [field, schema]}
|
{#each schemaFields as [field, schema]}
|
||||||
<PropField label={field}>
|
<PropField label={field}>
|
||||||
{#if ["string", "number", "array"].includes(schema.type)}
|
{#if [STRING, NUMBER, ARRAY].includes(schema.type)}
|
||||||
<svelte:component
|
<svelte:component
|
||||||
this={isTestModal ? ModalBindableInput : DrawerBindableInput}
|
this={isTestModal ? ModalBindableInput : DrawerBindableInput}
|
||||||
panel={AutomationBindingPanel}
|
panel={AutomationBindingPanel}
|
||||||
|
|
|
@ -26,13 +26,18 @@
|
||||||
export let bindings
|
export let bindings
|
||||||
export let isTestModal
|
export let isTestModal
|
||||||
|
|
||||||
|
const typeToField = Object.values(FIELDS).reduce((acc, field) => {
|
||||||
|
acc[field.type] = field
|
||||||
|
return acc
|
||||||
|
}, {})
|
||||||
|
|
||||||
const memoStore = memo({
|
const memoStore = memo({
|
||||||
row,
|
row,
|
||||||
meta,
|
meta,
|
||||||
})
|
})
|
||||||
|
|
||||||
let table
|
let table
|
||||||
// Row Schema Field
|
// Row Schema Fields
|
||||||
let schemaFields
|
let schemaFields
|
||||||
let attachmentTypes = [
|
let attachmentTypes = [
|
||||||
FieldType.ATTACHMENTS,
|
FieldType.ATTACHMENTS,
|
||||||
|
@ -62,6 +67,7 @@
|
||||||
})
|
})
|
||||||
|
|
||||||
$: tableId = $memoStore?.row?.tableId
|
$: tableId = $memoStore?.row?.tableId
|
||||||
|
|
||||||
$: if (tableId) {
|
$: if (tableId) {
|
||||||
// Refresh all the row data
|
// Refresh all the row data
|
||||||
editableRow = cloneDeep($memoStore?.row)
|
editableRow = cloneDeep($memoStore?.row)
|
||||||
|
@ -147,11 +153,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$: typeToField = Object.values(FIELDS).reduce((acc, field) => {
|
|
||||||
acc[field.type] = field
|
|
||||||
return acc
|
|
||||||
}, {})
|
|
||||||
|
|
||||||
// Row coerce
|
// Row coerce
|
||||||
const coerce = (value, type) => {
|
const coerce = (value, type) => {
|
||||||
const re = new RegExp(/{{([^{].*?)}}/g)
|
const re = new RegExp(/{{([^{].*?)}}/g)
|
||||||
|
|
Loading…
Reference in New Issue