Alter logic for field config checks causing test issues
This commit is contained in:
parent
ca44220bd3
commit
d10ef7b795
1 changed files with 8 additions and 6 deletions
|
@ -85,16 +85,18 @@ export async function run({ inputs, appId, emitter }: AutomationStepInput) {
|
||||||
// Base update
|
// Base update
|
||||||
let rowUpdate: Record<string, any>
|
let rowUpdate: Record<string, any>
|
||||||
|
|
||||||
// Legacy - find any empty values in the row that need to be cleared
|
// Legacy
|
||||||
|
// Find previously set values and add them to the update. Ensure empty relationships
|
||||||
|
// are added to the update is clearRelationships is true
|
||||||
const legacyUpdated = Object.keys(inputs.row || {}).reduce(
|
const legacyUpdated = Object.keys(inputs.row || {}).reduce(
|
||||||
(acc: Record<string, any>, key: string) => {
|
(acc: Record<string, any>, key: string) => {
|
||||||
const isEmpty = inputs.row[key] == null || inputs.row[key]?.length === 0
|
const isEmpty = inputs.row[key] == null || inputs.row[key]?.length === 0
|
||||||
const fieldConfig = inputs.meta?.fields?.[key]
|
const fieldConfig = inputs.meta?.fields || {}
|
||||||
|
|
||||||
if (isEmpty) {
|
if (isEmpty) {
|
||||||
if (
|
if (
|
||||||
Object.hasOwn(inputs.meta?.fields, key) &&
|
Object.hasOwn(fieldConfig, key) &&
|
||||||
fieldConfig?.clearRelationships === true
|
fieldConfig[key].clearRelationships === true
|
||||||
) {
|
) {
|
||||||
// Explicitly clear the field on update
|
// Explicitly clear the field on update
|
||||||
acc[key] = []
|
acc[key] = []
|
||||||
|
@ -111,13 +113,13 @@ export async function run({ inputs, appId, emitter }: AutomationStepInput) {
|
||||||
// The source of truth for inclusion in the update is: inputs.meta?.fields
|
// The source of truth for inclusion in the update is: inputs.meta?.fields
|
||||||
const parsedUpdate = Object.keys(inputs.meta?.fields || {}).reduce(
|
const parsedUpdate = Object.keys(inputs.meta?.fields || {}).reduce(
|
||||||
(acc: Record<string, any>, key: string) => {
|
(acc: Record<string, any>, key: string) => {
|
||||||
const fieldConfig = inputs.meta?.fields?.[key]
|
const fieldConfig = inputs.meta?.fields?.[key] || {}
|
||||||
// Ignore legacy config.
|
// Ignore legacy config.
|
||||||
if (Object.hasOwn(fieldConfig, "clearRelationships")) {
|
if (Object.hasOwn(fieldConfig, "clearRelationships")) {
|
||||||
return acc
|
return acc
|
||||||
}
|
}
|
||||||
acc[key] =
|
acc[key] =
|
||||||
Object.hasOwn(inputs.row, key) &&
|
Object.hasOwn(inputs.row || {}, key) &&
|
||||||
(!inputs.row[key] || inputs.row[key]?.length === 0)
|
(!inputs.row[key] || inputs.row[key]?.length === 0)
|
||||||
? null
|
? null
|
||||||
: inputs.row[key]
|
: inputs.row[key]
|
||||||
|
|
Loading…
Reference in a new issue