Refine the query for record bulk operations

This commit is contained in:
Mumbi Francis
2023-06-23 17:11:33 +03:00
committed by Mumbi Francis
parent b76458d20e
commit ba985be78e
4 changed files with 40 additions and 49 deletions
@@ -195,7 +195,7 @@
v-show="options.bulkRecordEditEnabled && canUpdateSelectedRecords && !showingDeletedRecords"
:module="recordListModule"
:namespace="namespace"
:selected-records="selectedAllRecords ? [] : selected"
:query="bulkQuery"
@save="onBulkUpdate()"
/>
@@ -636,12 +636,13 @@
v-if="options.inlineRecordEditEnabled"
:namespace="namespace"
:module="recordListModule"
:selected-records="inlineEdit.recordIDs"
:selected-fields="inlineEdit.fields"
:initial-record="inlineEdit.record"
:query="inlineEdit.query"
:modal-title="$t('recordList.inlineEdit.modal.title')"
open-on-select
@save="onInlineEdit()"
@close="onInlineEditClose()"
/>
<!-- Modal for naming custom filter -->
@@ -1046,6 +1047,14 @@ export default {
return this.$t(`recordList.${key}`, { count, total })
},
bulkQuery () {
if (this.selectedAllRecords) {
return this.filter.query
}
return this.selected.map(r => `recordID='${r}'`).join(' OR ')
},
},
watch: {
@@ -1515,18 +1524,10 @@ export default {
}
})
} else {
const { moduleID, namespaceID } = this.items[0].r
this.processing = true
let query = ''
if (!this.selectedAllRecords) {
// filter deletable records from the selected list
const recordIDs = this.items
.filter(({ id, r }) => r.canUndeleteRecord && selected.includes(id))
.map(({ id }) => id)
query = recordIDs.map(r => `recordID='${r}'`).join(' OR ')
}
const query = this.bulkQuery
const { moduleID, namespaceID } = this.filter
this.$ComposeAPI
.recordBulkUndelete({ moduleID, namespaceID, query })
@@ -1555,25 +1556,12 @@ export default {
}
}
} else {
// Pick module and namespace ID from the first record
//
// We are always showing list of records from the
// same module so this should be safe to do.
const { moduleID, namespaceID } = this.items[0].r
let query = ''
if (!this.selectedAllRecords) {
// filter deletable records from the selected list
const recordIDs = this.items
.filter(({ id, r }) => r.canDeleteRecord && selected.includes(id))
.map(({ id }) => id)
query = recordIDs.map(r => `recordID='${r}'`).join(' OR ')
}
this.processing = true
const query = this.bulkQuery
// Pick module and namespace ID from the filter
const { moduleID, namespaceID } = this.filter
this.$ComposeAPI
.recordBulkDelete({ moduleID, namespaceID, query })
.then(() => this.refresh(true))
@@ -1821,14 +1809,18 @@ export default {
editInlineField (record, field) {
this.inlineEdit.fields = [field]
this.inlineEdit.record = record.clone()
this.inlineEdit.recordIDs = [record.recordID]
this.inlineEdit.query = `recordID = ${record.recordID}`
},
onInlineEditClose () {
this.inlineEdit.fields = []
this.inlineEdit.record = {}
this.inlineEdit.query = ''
},
onInlineEdit () {
this.refresh(true)
this.inlineEdit.fields = []
this.inlineEdit.recordIDs = []
this.inlineEdit.record = {}
this.onInlineEditClose()
},
isFieldEditable (field) {
@@ -88,7 +88,7 @@
<b-button
variant="primary"
:disabled="!fields.length || processing"
@click="handleBulkUpdateSelectedRecords(selectedRecords)"
@click="handleBulkUpdateSelectedRecords(query)"
>
{{ $t('general.label.save') }}
</b-button>
@@ -132,11 +132,6 @@ export default {
required: true,
},
selectedRecords: {
type: Array,
required: true,
},
selectedFields: {
type: Array,
default: () => ([]),
@@ -156,6 +151,11 @@ export default {
type: String,
default: '',
},
query: {
type: String,
default: '',
},
},
data () {
@@ -182,9 +182,9 @@ export default {
},
watch: {
selectedRecords: {
handler (records) {
if (!this.openOnSelect || !records.length) return
query: {
handler (query) {
if (!this.openOnSelect || !query.length) return
this.record = new compose.Record(this.module, this.initialRecord)
this.showModal = true
@@ -215,6 +215,7 @@ export default {
this.fields = []
this.record = new compose.Record(this.module, {})
}
this.$emit('close')
},
getFieldLabel ({ kind, label, name }) {
+2 -4
View File
@@ -255,14 +255,14 @@ export default {
.then(() => this.dispatchUiEvent('afterUndelete'))
.then(() => this.updatePrompts())
.then(this.loadRecord)
.catch(this.toastErrorHandler(this.$t('notification:record.undeleteFailed')))
.catch(this.toastErrorHandler(this.$t('notification:record.restoreFailed')))
.finally(() => {
this.processingUndelete = false
this.processing = false
})
}, 500),
handleBulkUpdateSelectedRecords: throttle(function (records) {
handleBulkUpdateSelectedRecords: throttle(function (query) {
this.processing = true
const values = []
@@ -281,8 +281,6 @@ export default {
const { moduleID, namespaceID } = this.module
const query = records.map(r => `recordID='${r}'`).join(' OR ')
return this
.$ComposeAPI.recordPatch({ moduleID, namespaceID, values, query })
.catch(err => {
@@ -114,12 +114,12 @@ page:
record:
createFailed: Could not create record
deleteFailed: Could not delete record
undeleteFailed: Could not undelete record
restoreFailed: Could not restore record
deleteBulkFailed: Could not delete selected records
deleteBulkRecordUpdateFailed: Could not update selected records
deleteBulkSuccess: Successfully deleted selected records
bulkRecordUpdateSuccess: Successfully updated selected records
undeleteBulkFailed: Could not restore selected records
restoreBulkFailed: Could not restore selected records
restoreBulkSuccess: Successfully restored selected records
invalidOwnerVar: Can not use ${ownerID} variable in non-record pages
invalidRecordVar: Can not use ${record...} variable in non-record pages