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

Added an app trigger update parser that will clean the testdata for the automation on save. Old values were not cleaned out. Added some padding to the PropField labels. General fixes

This commit is contained in:
Dean 2024-06-26 11:10:15 +01:00
parent fd1570401c
commit ed0f60d5d7
6 changed files with 100 additions and 79 deletions

View file

@ -120,8 +120,6 @@
? [hbAutocomplete([...bindingsToCompletions(bindings, codeMode)])]
: []
let testDataRowVisibility = {}
const getInputData = (testData, blockInputs) => {
// Test data is not cloned for reactivity
let newInputData = testData || cloneDeep(blockInputs)
@ -275,7 +273,7 @@
const onRowTriggerUpdate = async update => {
if (
update.hasOwnProperty("tableId") &&
$selectedAutomation.testData.row.tableId !== update.tableId
$selectedAutomation.testData?.row?.tableId !== update.tableId
) {
try {
const reqSchema = getSchemaForDatasourcePlus(update.tableId, {
@ -309,6 +307,47 @@
}
}
/**
* Handler for App trigger automation updates.
* Ensure updates to the field list are reflected in testData
@param {object} update - An app trigger update object
@example
onAppTriggerUpdate({
"fields" : {"myField": "123", "myArray": "cat,dog,badger"}
})
*/
const onAppTriggerUpdate = async update => {
try {
// Parse the block inputs as usual
const updatedAutomation =
await automationStore.actions.processBlockInputs(block, {
schema: {},
...update,
})
// Exclude default or invalid data from the test data
let updatedFields = {}
for (const key of Object.keys(block?.inputs?.fields || {})) {
if (update.fields.hasOwnProperty(key)) {
if (key !== "") {
updatedFields[key] = updatedAutomation.testData?.fields?.[key]
}
}
}
// Save the entire automation and reset the testData
await automationStore.actions.save({
...updatedAutomation,
testData: {
fields: updatedFields,
},
})
} catch (e) {
console.error("Error saving automation", error)
notifications.error("Error saving automation")
}
}
/**
* Handler for automation block input updates.
@param {object} update - An automation inputs update object
@ -321,11 +360,19 @@
const onChange = Utils.sequential(async update => {
const request = cloneDeep(update)
// Process row trigger updates
// Process app trigger updates
if (isTrigger && !isTestModal) {
// Row trigger
if (rowEvents.includes(block.event)) {
await onRowTriggerUpdate(request)
return
}
// App trigger
if (block.event === AutomationEventType.APP_TRIGGER) {
await onAppTriggerUpdate(request)
return
}
}
// We need to cache the schema as part of the definition because it is
// used in the server to detect relationships. It would be far better to

View file

@ -16,19 +16,7 @@
let schemaFields
let editableValue
$: processValue(value)
const processValue = value => {
editableValue = { ...value }
// DEAN - review this
// const fieldKeys = Object.keys(block?.inputs?.fields)
// // Purge orphaned keys
// Object.keys(editableValue || {}).forEach(key => {
// if (!fieldKeys.includes(key)) {
// delete editableValue[key]
// }
// })
}
$: editableValue = { ...value }
$: {
let fields = {}
@ -60,7 +48,7 @@
ARRAY: "",
}
const onChange = (e, field, type) => {
const onChange = (e, field) => {
if (e.detail !== editableValue[field]) {
editableValue[field] = e.detail
dispatch("change", editableValue)

View file

@ -49,4 +49,12 @@
white-space: nowrap;
overflow: hidden;
}
.prop-control {
margin-left: var(--spacing-s);
}
.prop-field.fullWidth .prop-control {
margin-left: 0px;
}
</style>

View file

@ -33,6 +33,7 @@
})
let table
// Row Schema Field
let schemaFields
let attachmentTypes = [
FieldType.ATTACHMENTS,
@ -51,8 +52,6 @@
meta,
})
$: fields = $memoStore?.meta?.fields
$: if ($memoStore?.meta?.fields) {
editableFields = cloneDeep($memoStore?.meta?.fields)
}
@ -91,26 +90,16 @@
}
editableFields = editableFields
}
// Go through the table schema and build out the editable content
for (const entry of schemaFields) {
const [key, fieldSchema] = entry
if ($memoStore?.row?.[key]) {
// DEAN - review this
editableRow = {
...editableRow,
[key]: $memoStore?.row[key],
}
}
// Legacy
const emptyField =
!$memoStore?.row[key] || $memoStore?.row[key]?.length === 0
editableRow[key] == null || editableRow[key]?.length === 0
// Legacy
// Put non-empty elements into the update and add their key to the fields list.
if (!emptyField && !editableFields.hasOwnProperty(key)) {
//DEAN - review this - IF THEY ADDED A NEW ONE IT WOULD BE MISSING FROM editableFields + editableFields
console.log("EMPTY STATE DETECTED")
editableFields = {
...editableFields,
[key]: key,
@ -119,7 +108,8 @@
// Legacy - clearRelationships
// Init the field and add it to the update.
if (emptyField && editableFields[key]?.clearRelationships === true) {
if (emptyField) {
if (editableFields[key]?.clearRelationships === true) {
const emptyField = coerce(
!$memoStore?.row.hasOwnProperty(key) ? "" : $memoStore?.row[key],
fieldSchema.type
@ -133,25 +123,29 @@
...editableRow,
[key]: emptyField,
}
} else {
// Purge from the update as it's presence is not necessary.
delete editableRow[key]
}
}
}
// Possible to go through the automation fields schema?
console.log("ACTUAL ROW", row)
console.log("EDITABLE FIELDS", editableFields)
console.log("EDITABLE ROW", editableRow)
}
// Parse all known row schema keys
const schemaKeys = [
"tableId",
...schemaFields.map(entry => {
const [key] = entry
return key
}),
]
// Legacy - add explicitly cleared relationships to the request.
// DEAN - review this
$: if (schemaFields?.length && fields && false) {
// Meta fields processing.
Object.keys(fields).forEach(key => {
if (fields[key]?.clearRelationships) {
columns.add(key)
// Purge any row keys that are not present in the schema.
for (const rowKey of Object.keys(editableRow)) {
if (!schemaKeys.includes(rowKey)) {
delete editableRow[rowKey]
delete editableFields[rowKey]
}
}
})
columns = new Set(columns)
}
$: typeToField = Object.values(FIELDS).reduce((acc, field) => {
@ -209,7 +203,7 @@
}
const onChange = update => {
const customizer = (objValue, srcValue, key) => {
const customizer = (objValue, srcValue) => {
if (isPlainObject(objValue) && isPlainObject(srcValue)) {
const result = mergeWith({}, objValue, srcValue, customizer)
let outcome = Object.keys(result).reduce((acc, key) => {
@ -235,7 +229,6 @@
update,
customizer
)
console.log("Row Selector - MERGED", result)
dispatch("change", result)
}
</script>
@ -283,10 +276,7 @@
meta={{
fields: editableFields,
}}
onChange={change => {
console.log("RowSelectorTypes > RowSelector > ", change)
onChange(change)
}}
onChange={change => onChange(change)}
/>
</DrawerBindableSlot>
{/if}

View file

@ -122,7 +122,6 @@
<CodeEditor
value={fieldData}
on:change={e => {
console.log("JSON change", e.detail?.value, fieldData)
if (e.detail?.value !== fieldData) {
onChange({
row: {

View file

@ -29,17 +29,6 @@ export const definition: AutomationStepSchema = {
meta: {
type: AutomationIOType.OBJECT,
title: "Field settings",
// DEAN - REVIEW THIS - add in some record of these types
// properties: {
// fields: {
// properties: {
// useAttachmentBinding: {
// type: AutomationIOType.BOOLEAN,
// },
// },
// },
// },
},
row: {
type: AutomationIOType.OBJECT,
@ -129,8 +118,8 @@ export async function run({ inputs, appId, emitter }: AutomationStepInput) {
}
acc[key] =
inputs.row.hasOwnProperty(key) &&
(inputs.row[key] == null || inputs.row[key]?.length === 0)
? undefined
(!inputs.row[key] || inputs.row[key]?.length === 0)
? null
: inputs.row[key]
return acc
},