1
0
Fork 0
mirror of synced 2024-09-20 19:33:10 +12:00

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:
Dean 2024-07-01 12:59:43 +01:00
parent c91767ad1f
commit c2b54f118f
3 changed files with 82 additions and 16 deletions

View file

@ -15,8 +15,55 @@
let trigger = {}
let schemaProperties = {}
const memoTestData = memo($selectedAutomation.testData)
$: memoTestData.set($selectedAutomation.testData)
const rowTriggers = [
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
@ -32,18 +79,33 @@
}
// Check the schema to see if required fields have been entered
$: isError = !trigger.schema.outputs.required.every(
required => $memoTestData?.[required] || required !== "row"
)
$: isError =
!isTriggerValid(trigger) ||
!trigger.schema.outputs.required.every(
required => $memoTestData?.[required] || required !== "row"
)
function parseTestJSON(e) {
let jsonUpdate
try {
const obj = JSON.parse(e.detail)
jsonUpdate = JSON.parse(e.detail)
failedParse = null
automationStore.actions.addTestDataToAutomation(obj)
} catch (e) {
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 () => {

View file

@ -5,6 +5,7 @@
import ModalBindableInput from "../../common/bindings/ModalBindableInput.svelte"
import AutomationBindingPanel from "../../common/bindings/ServerBindingPanel.svelte"
import { DatePicker, Select } from "@budibase/bbui"
import { FieldType } from "@budibase/types"
const dispatch = createEventDispatcher()
@ -13,7 +14,9 @@
export let block
export let isTestModal
let schemaFields
const { STRING, NUMBER, ARRAY } = FieldType
let schemaFields = []
let editableValue
$: editableValue = { ...value }
@ -55,11 +58,11 @@
}
</script>
{#if schemaFields.length && isTestModal}
{#if schemaFields?.length && isTestModal}
<div class="fields">
{#each schemaFields as [field, schema]}
<PropField label={field}>
{#if ["string", "number", "array"].includes(schema.type)}
{#if [STRING, NUMBER, ARRAY].includes(schema.type)}
<svelte:component
this={isTestModal ? ModalBindableInput : DrawerBindableInput}
panel={AutomationBindingPanel}

View file

@ -26,13 +26,18 @@
export let bindings
export let isTestModal
const typeToField = Object.values(FIELDS).reduce((acc, field) => {
acc[field.type] = field
return acc
}, {})
const memoStore = memo({
row,
meta,
})
let table
// Row Schema Field
// Row Schema Fields
let schemaFields
let attachmentTypes = [
FieldType.ATTACHMENTS,
@ -62,6 +67,7 @@
})
$: tableId = $memoStore?.row?.tableId
$: if (tableId) {
// Refresh all the row data
editableRow = cloneDeep($memoStore?.row)
@ -147,11 +153,6 @@
}
}
$: typeToField = Object.values(FIELDS).reduce((acc, field) => {
acc[field.type] = field
return acc
}, {})
// Row coerce
const coerce = (value, type) => {
const re = new RegExp(/{{([^{].*?)}}/g)