1
0
Fork 0
mirror of synced 2024-09-20 11:27:56 +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)])] ? [hbAutocomplete([...bindingsToCompletions(bindings, codeMode)])]
: [] : []
let testDataRowVisibility = {}
const getInputData = (testData, blockInputs) => { const getInputData = (testData, blockInputs) => {
// Test data is not cloned for reactivity // Test data is not cloned for reactivity
let newInputData = testData || cloneDeep(blockInputs) let newInputData = testData || cloneDeep(blockInputs)
@ -275,7 +273,7 @@
const onRowTriggerUpdate = async update => { const onRowTriggerUpdate = async update => {
if ( if (
update.hasOwnProperty("tableId") && update.hasOwnProperty("tableId") &&
$selectedAutomation.testData.row.tableId !== update.tableId $selectedAutomation.testData?.row?.tableId !== update.tableId
) { ) {
try { try {
const reqSchema = getSchemaForDatasourcePlus(update.tableId, { 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. * Handler for automation block input updates.
@param {object} update - An automation inputs update object @param {object} update - An automation inputs update object
@ -321,10 +360,18 @@
const onChange = Utils.sequential(async update => { const onChange = Utils.sequential(async update => {
const request = cloneDeep(update) const request = cloneDeep(update)
// Process row trigger updates // Process app trigger updates
if (isTrigger && !isTestModal) { if (isTrigger && !isTestModal) {
await onRowTriggerUpdate(request) // Row trigger
return 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 // We need to cache the schema as part of the definition because it is

View file

@ -16,19 +16,7 @@
let schemaFields let schemaFields
let editableValue let editableValue
$: processValue(value) $: editableValue = { ...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]
// }
// })
}
$: { $: {
let fields = {} let fields = {}
@ -60,7 +48,7 @@
ARRAY: "", ARRAY: "",
} }
const onChange = (e, field, type) => { const onChange = (e, field) => {
if (e.detail !== editableValue[field]) { if (e.detail !== editableValue[field]) {
editableValue[field] = e.detail editableValue[field] = e.detail
dispatch("change", editableValue) dispatch("change", editableValue)

View file

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

View file

@ -33,6 +33,7 @@
}) })
let table let table
// Row Schema Field
let schemaFields let schemaFields
let attachmentTypes = [ let attachmentTypes = [
FieldType.ATTACHMENTS, FieldType.ATTACHMENTS,
@ -51,8 +52,6 @@
meta, meta,
}) })
$: fields = $memoStore?.meta?.fields
$: if ($memoStore?.meta?.fields) { $: if ($memoStore?.meta?.fields) {
editableFields = cloneDeep($memoStore?.meta?.fields) editableFields = cloneDeep($memoStore?.meta?.fields)
} }
@ -91,26 +90,16 @@
} }
editableFields = editableFields editableFields = editableFields
} }
// Go through the table schema and build out the editable content // Go through the table schema and build out the editable content
for (const entry of schemaFields) { for (const entry of schemaFields) {
const [key, fieldSchema] = entry const [key, fieldSchema] = entry
if ($memoStore?.row?.[key]) {
// DEAN - review this
editableRow = {
...editableRow,
[key]: $memoStore?.row[key],
}
}
// Legacy
const emptyField = 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. // Put non-empty elements into the update and add their key to the fields list.
if (!emptyField && !editableFields.hasOwnProperty(key)) { 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 = {
...editableFields, ...editableFields,
[key]: key, [key]: key,
@ -119,39 +108,44 @@
// Legacy - clearRelationships // Legacy - clearRelationships
// Init the field and add it to the update. // Init the field and add it to the update.
if (emptyField && editableFields[key]?.clearRelationships === true) { if (emptyField) {
const emptyField = coerce( if (editableFields[key]?.clearRelationships === true) {
!$memoStore?.row.hasOwnProperty(key) ? "" : $memoStore?.row[key], const emptyField = coerce(
fieldSchema.type !$memoStore?.row.hasOwnProperty(key) ? "" : $memoStore?.row[key],
) fieldSchema.type
)
// remove this and place the field in the editable row. // remove this and place the field in the editable row.
delete editableFields[key]?.clearRelationships delete editableFields[key]?.clearRelationships
// Default the field // Default the field
editableRow = { editableRow = {
...editableRow, ...editableRow,
[key]: emptyField, [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? // Parse all known row schema keys
console.log("ACTUAL ROW", row) const schemaKeys = [
console.log("EDITABLE FIELDS", editableFields) "tableId",
console.log("EDITABLE ROW", editableRow) ...schemaFields.map(entry => {
} const [key] = entry
return key
}),
]
// Legacy - add explicitly cleared relationships to the request. // Purge any row keys that are not present in the schema.
// DEAN - review this for (const rowKey of Object.keys(editableRow)) {
$: if (schemaFields?.length && fields && false) { if (!schemaKeys.includes(rowKey)) {
// Meta fields processing. delete editableRow[rowKey]
Object.keys(fields).forEach(key => { delete editableFields[rowKey]
if (fields[key]?.clearRelationships) {
columns.add(key)
} }
}) }
columns = new Set(columns)
} }
$: typeToField = Object.values(FIELDS).reduce((acc, field) => { $: typeToField = Object.values(FIELDS).reduce((acc, field) => {
@ -209,7 +203,7 @@
} }
const onChange = update => { const onChange = update => {
const customizer = (objValue, srcValue, key) => { const customizer = (objValue, srcValue) => {
if (isPlainObject(objValue) && isPlainObject(srcValue)) { if (isPlainObject(objValue) && isPlainObject(srcValue)) {
const result = mergeWith({}, objValue, srcValue, customizer) const result = mergeWith({}, objValue, srcValue, customizer)
let outcome = Object.keys(result).reduce((acc, key) => { let outcome = Object.keys(result).reduce((acc, key) => {
@ -235,7 +229,6 @@
update, update,
customizer customizer
) )
console.log("Row Selector - MERGED", result)
dispatch("change", result) dispatch("change", result)
} }
</script> </script>
@ -283,10 +276,7 @@
meta={{ meta={{
fields: editableFields, fields: editableFields,
}} }}
onChange={change => { onChange={change => onChange(change)}
console.log("RowSelectorTypes > RowSelector > ", change)
onChange(change)
}}
/> />
</DrawerBindableSlot> </DrawerBindableSlot>
{/if} {/if}

View file

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

View file

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