From 1174a0d3837ea6504cccc9099df034cec32be72b Mon Sep 17 00:00:00 2001 From: Matthew Richardson Date: Wed, 15 May 2024 10:31:59 +0100 Subject: [PATCH] Capture ignored field changes for use in onComplete method. --- package.json | 2 +- src/components/TRDetail.vue | 21 +++++++++++++++------ src/components/fieldBase.js | 4 ++++ 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index bf8541b..443695d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@uoe-eng/tabularasa", - "version": "1.32.2", + "version": "1.33.0", "scripts": { "serve": "vue-cli-service serve", "build": "vue-cli-service build --target lib --name tabularasa src/index.js", diff --git a/src/components/TRDetail.vue b/src/components/TRDetail.vue index dade355..d3fb4d4 100644 --- a/src/components/TRDetail.vue +++ b/src/components/TRDetail.vue @@ -10,6 +10,7 @@ } " :configuration="configuration" + :ignored="ignored" :item="item" :new-item="newItem" v-bind="field" @@ -47,6 +48,7 @@ import { computed, defineEmits, defineProps, onMounted, ref, toRefs, watch } from 'vue' import Button from 'primevue/button' import { trBus } from '@/index' +import merge from 'lodash/merge' import set from 'lodash/set' import { TYPERE } from '@/helpers' @@ -78,6 +80,9 @@ const emit = defineEmits(['close']) let fieldComponents = ref([]) // We start with an empty object and update it as fields change let newItem = ref({}) +// Store changed but ignored fields for e.g. onComplete methods +let ignored = ref({}) + // Fields to display in the card (from schema) let fields = configuration.value.fields // Update field validity on 'valid' events @@ -143,13 +148,17 @@ const onUpdate = (field, event) => { // Remove brackets to avoid creating empty arrays/objects let fld = field.field.replace(TYPERE, '') // Parse dot-notation field name into a nested object using _.set - let newObj = set({}, fld, event) - // Use spread notation to shallow copy - Object.assign causes side-effects in deep/recursive objects - newItem.value = { ...newItem.value, ...newObj } - if (!field.ignoreField) { - // Emit just the changed field - trBus.emit(`TRDetail:update:${props.name}`, [props.item, newObj]) + let parsed = set({}, fld, event) + if (field.ignoreField) { + // Save ignored field change, but don't emit update + // Use merge as ignored fields may be nested with shared 'root' property + merge(ignored.value, parsed) + return } + // Use spread notation to shallow copy - Object.assign causes side-effects in deep/recursive objects + newItem.value = { ...newItem.value, ...parsed } + // Emit just the changed field + trBus.emit(`TRDetail:update:${props.name}`, [props.item, parsed]) } const onValid = (field, event) => { diff --git a/src/components/fieldBase.js b/src/components/fieldBase.js index e7a19b3..18467f7 100644 --- a/src/components/fieldBase.js +++ b/src/components/fieldBase.js @@ -11,6 +11,10 @@ export default () => { type: String, default: '', }, + ignored: { + type: Object, + default: () => ({}), + }, item: { type: Object, default: () => ({}),