Skip to content

Commit

Permalink
First work on updates rom child changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrichar1 committed May 28, 2024
1 parent 4f2c53a commit a7778dd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
21 changes: 14 additions & 7 deletions src/components/TRList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ let dialogVisible = ref(false)
let dirty = ref(false)
// Use ref, not reactive, as we replace the whole object, rather than modify its properties
let dtProps = ref({})
let selectedIndex = undefined
let selectedRow = ref({})
let rowIndex = ref()
let filters = ref({})
let sortField = undefined
let sortOrder = undefined
Expand Down Expand Up @@ -175,19 +175,21 @@ const onReload = () => {
}
const onRefresh = () => {
// Create a new object with a new reference, or it won't be reactive if underlying data is unchanged
selectedRow.value = Object.assign({}, collection.value[rowIndex.value])
// Reset detail card data to the selected row
selectedRow.value = collection.value[selectedIndex]
}
const onRowSelect = (event) => {
if (event.data) {
if ('index' in event) {
// Editing existing row
dialogConfig.value = props.configuration
dialogName.value = props.name
dialogHeader.value = `Edit: ${dialogName.value}`
selectedRow.value = event.data
// Preserve the rowIndex so we can access the item data in onRefresh
rowIndex.value = event.index
// Save the index of the selected row for later re-use in onRefresh
// FIXME: Array index is a 'poor' key since arrays can reorder, change length etc
// But we can't guarantee/mandate unique array entries to key off
selectedIndex = event.index
selectedRow.value = collection.value[selectedIndex]
} else {
// New button
selectedRow.value = newButton.value.value || {}
Expand Down Expand Up @@ -226,6 +228,11 @@ const newButton = computed(() => {
return true
})
watch(collection, () => {
// Update selectedRow if the collection changes (based on selected row index)
selectedRow.value = collection.value[selectedIndex]
})
watch(
confTRDetail,
(newDetail) => {
Expand Down
7 changes: 6 additions & 1 deletion src/components/fields/TextInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ export default {
watch(
[props.field, props.item],
() => {
fieldValue.value = fieldBaseValue(useProps)
// FIXME: fbv is the 'store' value, fieldValue is the current edits
// We should have logic here to handle the store changing while editing, and decide what to do
// This would then need replicating to all other fields, potentially with different behaviours.
let fbv = fieldBaseValue(useProps)
console.log('Vals', fieldValue.value, fbv)

Check failure on line 49 in src/components/fields/TextInput.vue

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement

Check failure on line 49 in src/components/fields/TextInput.vue

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement

Check failure on line 49 in src/components/fields/TextInput.vue

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
fieldValue.value = fbv
},
{ immediate: true }
)
Expand Down

0 comments on commit a7778dd

Please sign in to comment.