3
0

Fix record selector, metric, chart values not refreshed when inline and bulk edit changes are applied to related records

This commit is contained in:
Kelani Tolulope 2023-09-12 12:59:54 +01:00
parent 79791dc8d2
commit 6284ac5af9
8 changed files with 97 additions and 9 deletions

View File

@ -48,6 +48,8 @@ export default {
recordValues: {}, recordValues: {},
relRecords: [], relRecords: [],
relatedModuleID: undefined,
} }
}, },
@ -84,6 +86,11 @@ export default {
beforeDestroy () { beforeDestroy () {
this.setDefaultValues() this.setDefaultValues()
this.destroyEvents()
},
mounted () {
this.$root.$on('module-records-updated', this.refreshOnRelatedModuleUpdate)
}, },
methods: { methods: {
@ -93,6 +100,12 @@ export default {
resolveRecords: 'record/resolveRecords', resolveRecords: 'record/resolveRecords',
}), }),
refreshOnRelatedModuleUpdate (module) {
if (this.relatedModuleID === module.moduleID) {
this.formatRecordValues(this.value)
}
},
linkToRecord (recordID) { linkToRecord (recordID) {
if (!this.recordPage || !recordID) { if (!this.recordPage || !recordID) {
return '' return ''
@ -127,6 +140,8 @@ export default {
const relatedModule = await this.findModuleByID({ namespaceID, moduleID: relatedField.options.moduleID }) const relatedModule = await this.findModuleByID({ namespaceID, moduleID: relatedField.options.moduleID })
const relatedRecordIDs = new Set() const relatedRecordIDs = new Set()
this.relatedModuleID = relatedModule.moduleID
records.forEach(r => { records.forEach(r => {
const recordValue = relatedField.isMulti ? r.values[relatedField.name] : [r.values[relatedField.name]] const recordValue = relatedField.isMulti ? r.values[relatedField.name] : [r.values[relatedField.name]]
recordValue.forEach(rID => relatedRecordIDs.add(rID)) recordValue.forEach(rID => relatedRecordIDs.add(rID))
@ -197,6 +212,11 @@ export default {
this.processing = false this.processing = false
this.recordValues = {} this.recordValues = {}
this.relRecords = [] this.relRecords = []
this.relatedModuleID = undefined
},
destroyEvents () {
this.$root.$off('module-records-updated', this.refreshOnRelatedModuleUpdate)
}, },
}, },
} }

View File

@ -55,6 +55,8 @@ export default {
this.refreshBlock(this.refresh) this.refreshBlock(this.refresh)
this.$root.$on('drill-down-chart', this.drillDown) this.$root.$on('drill-down-chart', this.drillDown)
this.$root.$on('module-records-updated', this.refreshOnRelatedRecordsUpdate)
}, },
beforeDestroy () { beforeDestroy () {
@ -67,6 +69,12 @@ export default {
findChartByID: 'chart/findByID', findChartByID: 'chart/findByID',
}), }),
refreshOnRelatedRecordsUpdate (module) {
if (this.filter.moduleID === module.moduleID) {
this.refresh()
}
},
async fetchChart (params = {}) { async fetchChart (params = {}) {
const { chartID } = this.options const { chartID } = this.options
@ -178,6 +186,7 @@ export default {
destroyEvents () { destroyEvents () {
this.$root.$off('drill-down-chart', this.drillDown) this.$root.$off('drill-down-chart', this.drillDown)
this.$root.$off('module-records-updated', this.refreshOnRelatedRecordsUpdate)
}, },
}, },
} }

View File

@ -224,9 +224,14 @@ export default {
this.refreshBlock(this.refresh) this.refreshBlock(this.refresh)
}, },
mounted () {
this.$root.$on('module-records-updated', this.refreshOnRelatedRecordsUpdate)
},
beforeDestroy () { beforeDestroy () {
this.abortRequests() this.abortRequests()
this.setDefaultValues() this.setDefaultValues()
this.destroyEvents()
}, },
methods: { methods: {
@ -239,6 +244,12 @@ export default {
return user.name || user.handle || user.email || '' return user.name || user.handle || user.email || ''
}, },
refreshOnRelatedRecordsUpdate (module) {
if (this.options.moduleID === module.moduleID) {
this.refresh()
}
},
refresh () { refresh () {
if (!this.options.moduleID) { if (!this.options.moduleID) {
// Make sure block is properly configured // Make sure block is properly configured
@ -369,6 +380,10 @@ export default {
cancel() cancel()
}) })
}, },
destroyEvents () {
this.$root.$off('module-records-updated', this.refreshOnRelatedRecordsUpdate)
},
}, },
} }
</script> </script>

View File

@ -95,6 +95,8 @@ export default {
this.$root.$on('metric.update', this.refresh) this.$root.$on('metric.update', this.refresh)
this.$root.$on(`refetch-non-record-blocks:${this.page.pageID}`, this.refresh) this.$root.$on(`refetch-non-record-blocks:${this.page.pageID}`, this.refresh)
this.$root.$on('drill-down-chart', this.drillDown) this.$root.$on('drill-down-chart', this.drillDown)
this.$root.$on('module-records-updated', this.refreshOnRelatedRecordsUpdate)
}, },
beforeDestroy () { beforeDestroy () {
@ -233,10 +235,23 @@ export default {
}) })
}, },
refreshOnRelatedRecordsUpdate (module) {
const metrics = this.options.metrics
const hasMatchingModule = metrics.some((m) => {
return m.moduleID === module.moduleID
})
if (hasMatchingModule) {
this.refresh()
}
},
destroyEvents () { destroyEvents () {
this.$root.$off('metric.update', this.refresh) this.$root.$off('metric.update', this.refresh)
this.$root.$off(`refetch-non-record-blocks:${this.page.pageID}`, this.refresh) this.$root.$off(`refetch-non-record-blocks:${this.page.pageID}`, this.refresh)
this.$root.$off('drill-down-chart', this.drillDown) this.$root.$off('drill-down-chart', this.drillDown)
this.$root.$off('module-records-updated', this.refreshOnRelatedRecordsUpdate)
}, },
}, },
} }

View File

@ -1099,6 +1099,23 @@ export default {
this.$root.$on(`page-block:validate:${this.uniqueID}`, this.validatePageBlock) this.$root.$on(`page-block:validate:${this.uniqueID}`, this.validatePageBlock)
this.$root.$on(`drill-down-recordList:${this.uniqueID}`, this.setDrillDownFilter) this.$root.$on(`drill-down-recordList:${this.uniqueID}`, this.setDrillDownFilter)
this.$root.$on(`refetch-non-record-blocks:${pageID}`, this.refreshAndResetPagination) this.$root.$on(`refetch-non-record-blocks:${pageID}`, this.refreshAndResetPagination)
this.$root.$on('module-records-updated', this.refreshOnRelatedRecordsUpdate)
},
refreshOnRelatedRecordsUpdate (module) {
if (this.recordListModule.moduleID === module.moduleID) {
this.refresh(true)
} else {
const recordFields = this.fields.filter((f) => f.moduleField.kind === 'Record')
const hasMatchingModule = recordFields.some((r) => {
return r.moduleField.options.moduleID === module.moduleID
})
if (hasMatchingModule) {
this.refresh(false)
}
}
}, },
onFilter (filter = []) { onFilter (filter = []) {
@ -1803,7 +1820,6 @@ export default {
onBulkUpdate () { onBulkUpdate () {
this.selectedAllRecords = false this.selectedAllRecords = false
this.refresh(true)
}, },
editInlineField (record, field) { editInlineField (record, field) {
@ -1819,7 +1835,6 @@ export default {
}, },
onInlineEdit () { onInlineEdit () {
this.refresh(true)
this.onInlineEditClose() this.onInlineEditClose()
}, },
@ -1918,6 +1933,7 @@ export default {
this.$root.$off(`page-block:validate:${this.uniqueID}`, this.validatePageBlock) this.$root.$off(`page-block:validate:${this.uniqueID}`, this.validatePageBlock)
this.$root.$off(`drill-down-recordList:${this.uniqueID}`, this.setDrillDownFilter) this.$root.$off(`drill-down-recordList:${this.uniqueID}`, this.setDrillDownFilter)
this.$root.$off(`refetch-non-record-blocks:${pageID}`, this.refreshAndResetPagination) this.$root.$off(`refetch-non-record-blocks:${pageID}`, this.refreshAndResetPagination)
this.$root.$off('module-records-updated', this.refreshOnRelatedRecordsUpdate)
}, },
handleAddRecord () { handleAddRecord () {

View File

@ -251,6 +251,7 @@ export default {
mounted () { mounted () {
this.$root.$on(`refetch-non-record-blocks:${this.page.pageID}`, this.refresh) this.$root.$on(`refetch-non-record-blocks:${this.page.pageID}`, this.refresh)
this.$root.$on('module-records-updated', this.refreshOnRelatedRecordsUpdate)
}, },
beforeDestroy () { beforeDestroy () {
@ -345,6 +346,12 @@ export default {
} }
}, },
refreshOnRelatedRecordsUpdate (module) {
if (this.options.moduleID === module.moduleID) {
this.refresh()
}
},
expandFilter () { expandFilter () {
const filter = [] const filter = []
@ -518,6 +525,7 @@ export default {
destroyEvents () { destroyEvents () {
this.$root.$off(`refetch-non-record-blocks:${this.page.pageID}`, this.refresh) this.$root.$off(`refetch-non-record-blocks:${this.page.pageID}`, this.refresh)
this.$root.$off('module-records-updated', this.refreshOnRelatedRecordsUpdate)
}, },
}, },
} }

View File

@ -185,6 +185,10 @@ export default {
} }
this.toastSuccess(this.$t(`notification:record.${isNew ? 'create' : 'update'}Success`)) this.toastSuccess(this.$t(`notification:record.${isNew ? 'create' : 'update'}Success`))
this.$root.$emit('module-records-updated', {
moduleID: this.module.moduleID,
})
}) })
.catch(this.toastErrorHandler(this.$t(`notification:record.${isNew ? 'create' : 'update'}Failed`))) .catch(this.toastErrorHandler(this.$t(`notification:record.${isNew ? 'create' : 'update'}Failed`)))
.finally(() => { .finally(() => {
@ -239,6 +243,10 @@ export default {
this.initialRecordState = this.record.clone() this.initialRecordState = this.record.clone()
this.$router.push({ name: route, params: { ...this.$route.params, recordID: record.recordID } }) this.$router.push({ name: route, params: { ...this.$route.params, recordID: record.recordID } })
this.$root.$emit('module-records-updated', {
moduleID: this.module.moduleID,
})
} }
}) })
.catch(this.toastErrorHandler(this.$t( .catch(this.toastErrorHandler(this.$t(
@ -335,6 +343,8 @@ export default {
this.record = new compose.Record(this.module, {}) this.record = new compose.Record(this.module, {})
this.initialRecordState = this.record.clone() this.initialRecordState = this.record.clone()
this.$emit('save') this.$emit('save')
this.$root.$emit('module-records-updated', { moduleID })
}) })
.catch(this.toastErrorHandler(this.$t('notification:record.deleteBulkRecordUpdateFailed'))) .catch(this.toastErrorHandler(this.$t('notification:record.deleteBulkRecordUpdateFailed')))
.finally(() => { .finally(() => {

View File

@ -38,16 +38,12 @@ export default function (ComposeAPI) {
/** /**
* Similar to fetchRecords but it only fetches unknown (not in set) ids * Similar to fetchRecords but it only fetches unknown (not in set) ids
*/ */
async resolveRecords ({ commit, getters }, { namespaceID, moduleID, recordIDs }) { async resolveRecords ({ commit }, { namespaceID, moduleID, recordIDs }) {
if (recordIDs.length === 0) { if (recordIDs.length === 0) {
// save ourselves some work // save ourselves some work
return return
} }
// exclude existing & make unique
const existing = new Set(getters.set.map(({ recordID }) => recordID))
recordIDs = [...new Set(recordIDs.filter(recordID => !existing.has(recordID)))]
if (recordIDs.length === 0) { if (recordIDs.length === 0) {
// Check for values again // Check for values again
return return
@ -59,7 +55,6 @@ export default function (ComposeAPI) {
commit(types.updateSet, set) commit(types.updateSet, set)
}).finally(() => { }).finally(() => {
commit(types.completed) commit(types.completed)
existing.clear()
recordIDs = [] recordIDs = []
}) })
}, },
@ -97,7 +92,7 @@ export default function (ComposeAPI) {
const existing = new Set(state.set.map(({ recordID }) => recordID)) const existing = new Set(state.set.map(({ recordID }) => recordID))
set.forEach(newItem => { set.forEach(newItem => {
const oldIndex = !existing.has(newItem.recordID) ? state.set.findIndex(({ recordID }) => recordID === newItem.recordID) : -1 const oldIndex = existing.has(newItem.recordID) ? state.set.findIndex(({ recordID }) => recordID === newItem.recordID) : -1
if (oldIndex > -1) { if (oldIndex > -1) {
state.set.splice(oldIndex, 1, newItem) state.set.splice(oldIndex, 1, newItem)
} else { } else {