mirror of
https://github.com/lana-k/sqliteviz.git
synced 2025-12-06 18:18:53 +08:00
#121 save inquiries in store
This commit is contained in:
@@ -13,5 +13,34 @@ export default {
|
||||
}
|
||||
|
||||
return inquiry.id
|
||||
},
|
||||
async saveInquiry ({ state }, { inquiryTab, newName }) {
|
||||
const value = {
|
||||
id: inquiryTab.isPredefined ? nanoid() : inquiryTab.id,
|
||||
query: inquiryTab.query,
|
||||
viewType: inquiryTab.dataView.mode,
|
||||
viewOptions: inquiryTab.dataView.getOptionsForSave(),
|
||||
name: newName || inquiryTab.name
|
||||
}
|
||||
|
||||
// Get inquiries from local storage
|
||||
const myInquiries = state.inquiries
|
||||
|
||||
// Set createdAt
|
||||
if (newName) {
|
||||
value.createdAt = new Date()
|
||||
} else {
|
||||
var inquiryIndex = myInquiries.findIndex(oldInquiry => oldInquiry.id === inquiryTab.id)
|
||||
value.createdAt = myInquiries[inquiryIndex].createdAt
|
||||
}
|
||||
|
||||
// Insert in inquiries list
|
||||
if (newName) {
|
||||
myInquiries.push(value)
|
||||
} else {
|
||||
myInquiries.splice(inquiryIndex, 1, value)
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user