Skip to content

Commit

Permalink
Capture ignored field changes for use in onComplete method.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrichar1 committed May 15, 2024
1 parent 74ef029 commit 1174a0d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
21 changes: 15 additions & 6 deletions src/components/TRDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
}
"
:configuration="configuration"
:ignored="ignored"
:item="item"
:new-item="newItem"
v-bind="field"
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) => {
Expand Down
4 changes: 4 additions & 0 deletions src/components/fieldBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export default () => {
type: String,
default: '',
},
ignored: {
type: Object,
default: () => ({}),
},
item: {
type: Object,
default: () => ({}),
Expand Down

0 comments on commit 1174a0d

Please sign in to comment.