1
0
mirror of https://github.com/lana-k/sqliteviz.git synced 2026-03-24 23:16:18 +08:00

#121 save inquiries in store

This commit is contained in:
lana-k
2025-01-05 21:06:06 +01:00
parent 378b9fb580
commit d6408bdd85
7 changed files with 107 additions and 79 deletions

View File

@@ -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
}
}

View File

@@ -60,5 +60,43 @@ export default {
},
setPredefinedInquiriesLoaded (state, value) {
state.predefinedInquiriesLoaded = value
},
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
}
})
}
}
}

View File

@@ -3,6 +3,7 @@ export default {
currentTab: null,
currentTabId: null,
untitledLastIndex: 0,
inquiries: [],
predefinedInquiries: [],
loadingPredefinedInquiries: false,
predefinedInquiriesLoaded: false,