mirror of
https://github.com/lana-k/sqliteviz.git
synced 2025-12-07 02:28:54 +08:00
use actions, add store tests
This commit is contained in:
@@ -42,5 +42,40 @@ export default {
|
||||
}
|
||||
|
||||
return value
|
||||
},
|
||||
addInquiry ({ state }, newInquiry) {
|
||||
state.inquiries.push(newInquiry)
|
||||
},
|
||||
deleteInquiries ({ state, commit }, inquiryIdSet) {
|
||||
state.inquiries = state.inquiries.filter(
|
||||
inquiry => !inquiryIdSet.has(inquiry.id)
|
||||
)
|
||||
|
||||
// Close deleted inquiries if it was opened
|
||||
const tabs = state.tabs
|
||||
let i = tabs.length - 1
|
||||
while (i > -1) {
|
||||
if (inquiryIdSet.has(tabs[i].id)) {
|
||||
commit('deleteTab', tabs[i])
|
||||
}
|
||||
i--
|
||||
}
|
||||
},
|
||||
renameInquiry ({ state, commit }, {inquiryId, newName}) {
|
||||
const renamingInquiry = state.inquiries
|
||||
.find(inquiry => inquiry.id === inquiryId)
|
||||
|
||||
renamingInquiry.name = newName
|
||||
|
||||
// update tab, if renamed inquiry is opened
|
||||
const tab = state.tabs.find(tab => tab.id === renamingInquiry.id)
|
||||
if (tab) {
|
||||
commit('updateTab', {
|
||||
tab,
|
||||
newValues: {
|
||||
name: newName
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,40 +63,5 @@ export default {
|
||||
},
|
||||
setInquiries (state, value) {
|
||||
state.inquiries = value
|
||||
},
|
||||
addInquiry (state, newInquiry) {
|
||||
state.inquiries.push(newInquiry)
|
||||
},
|
||||
deleteInquiries (state, inquiryIdSet) {
|
||||
state.inquiries = state.inquiries.filter(
|
||||
inquiry => !inquiryIdSet.has(inquiry.id)
|
||||
)
|
||||
|
||||
// Close deleted inquiries if it was opened
|
||||
const tabs = state.tabs
|
||||
let i = tabs.length - 1
|
||||
while (i > -1) {
|
||||
if (inquiryIdSet.has(tabs[i].id)) {
|
||||
this.commit('deleteTab', tabs[i])
|
||||
}
|
||||
i--
|
||||
}
|
||||
},
|
||||
renameInquiry (state, {inquiryId, newName}) {
|
||||
const renamingInquiry = state.inquiries
|
||||
.find(inquiry => inquiry.id === inquiryId)
|
||||
|
||||
renamingInquiry.name = newName
|
||||
|
||||
// update tab, if renamed inquiry is opened
|
||||
const tab = state.tabs.find(tab => tab.id === renamingInquiry.id)
|
||||
if (tab) {
|
||||
this.commit('updateTab', {
|
||||
tab,
|
||||
newValues: {
|
||||
name: newName
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -331,7 +331,7 @@ export default {
|
||||
this.errorMsg = "Inquiry name can't be empty"
|
||||
return
|
||||
}
|
||||
this.$store.commit('renameInquiry', {
|
||||
this.$store.dispatch('renameInquiry', {
|
||||
inquiryId: this.processedInquiryId,
|
||||
newName: this.newName
|
||||
})
|
||||
@@ -341,7 +341,7 @@ export default {
|
||||
},
|
||||
duplicateInquiry (index) {
|
||||
const newInquiry = storedInquiries.duplicateInquiry(this.showedInquiries[index])
|
||||
this.$store.commit('addInquiry', newInquiry)
|
||||
this.$store.dispatch('addInquiry', newInquiry)
|
||||
},
|
||||
showDeleteDialog (idsSet) {
|
||||
this.deleteGroup = idsSet.size > 1
|
||||
@@ -353,14 +353,14 @@ export default {
|
||||
deleteInquiry () {
|
||||
this.$modal.hide('delete')
|
||||
if (!this.deleteGroup) {
|
||||
this.$store.commit('deleteInquiries', new Set().add(this.processedInquiryId))
|
||||
this.$store.dispatch('deleteInquiries', new Set().add(this.processedInquiryId))
|
||||
|
||||
// Clear checkbox
|
||||
if (this.selectedInquiriesIds.has(this.processedInquiryId)) {
|
||||
this.selectedInquiriesIds.delete(this.processedInquiryId)
|
||||
}
|
||||
} else {
|
||||
this.$store.commit('deleteInquiries', this.selectedInquiriesIds)
|
||||
this.$store.dispatch('deleteInquiries', this.selectedInquiriesIds)
|
||||
|
||||
// Clear checkboxes
|
||||
this.selectedInquiriesIds.clear()
|
||||
|
||||
Reference in New Issue
Block a user