1
0
mirror of https://github.com/lana-k/sqliteviz.git synced 2025-12-08 02:58:54 +08:00

add store tests

This commit is contained in:
lana-k
2021-01-01 18:47:16 +01:00
parent 4c2da33d01
commit ef461be3e5
5 changed files with 601 additions and 70 deletions

View File

@@ -3,59 +3,55 @@ import Vuex from 'vuex'
Vue.use(Vuex)
export default new Vuex.Store({
state: {
schema: null,
dbFile: null,
dbName: null,
tabs: [],
currentTab: null,
currentTabId: null,
untitledLastIndex: 0,
predefinedQueries: []
export const state = {
schema: null,
dbFile: null,
dbName: null,
tabs: [],
currentTab: null,
currentTabId: null,
untitledLastIndex: 0,
predefinedQueries: []
}
export const mutations = {
saveSchema (state, { dbName, schema }) {
state.dbName = dbName
state.schema = schema
},
mutations: {
saveSchema (state, { dbName, schema }) {
state.dbName = dbName
state.schema = schema
},
saveDbFile (state, file) {
state.dbFile = file
},
addTab (state, tab) {
// add new tab only if was not already opened
if (!state.tabs.some(openedTab => openedTab.id === tab.id)) {
state.tabs.push(tab)
if (!tab.name) {
state.untitledLastIndex += 1
}
addTab (state, tab) {
// add new tab only if was not already opened
if (!state.tabs.some(openedTab => openedTab.id === tab.id)) {
state.tabs.push(tab)
if (!tab.name) {
state.untitledLastIndex += 1
}
},
updateTab (state, { index, name, id, query, chart, isUnsaved }) {
const tab = state.tabs[index]
const oldId = tab.id
}
},
updateTab (state, { index, name, id, query, chart, isUnsaved }) {
const tab = state.tabs[index]
const oldId = tab.id
if (state.currentTabId === oldId) {
state.currentTabId = id
}
if (id && state.currentTabId === oldId) {
state.currentTabId = id
}
tab.id = id
if (name) { tab.name = name }
if (query) { tab.query = query }
if (chart) { tab.chart = chart }
if (isUnsaved !== undefined) { tab.isUnsaved = isUnsaved }
if (id) { tab.id = id }
if (name) { tab.name = name }
if (query) { tab.query = query }
if (chart) { tab.chart = chart }
if (isUnsaved !== undefined) { tab.isUnsaved = isUnsaved }
if (!isUnsaved) {
// Saved query is not predefined
delete tab.isPredefined
}
Vue.set(state.tabs, index, tab)
},
updateTabState (state, { index, isUnsaved }) {
const tab = state.tabs[index]
tab.isUnsaved = isUnsaved
Vue.set(state.tabs, index, tab)
},
deleteTab (state, index) {
if (state.tabs[index].id !== state.currentTabId) {
} else if (index < state.tabs.length - 1) {
Vue.set(state.tabs, index, tab)
},
deleteTab (state, index) {
// If closing tab is the current opened
if (state.tabs[index].id === state.currentTabId) {
if (index < state.tabs.length - 1) {
state.currentTabId = state.tabs[index + 1].id
} else if (index > 0) {
state.currentTabId = state.tabs[index - 1].id
@@ -64,22 +60,25 @@ export default new Vuex.Store({
state.currentTab = null
state.untitledLastIndex = 0
}
state.tabs.splice(index, 1)
},
setCurrentTabId (state, id) {
state.currentTabId = id
},
setCurrentTab (state, tab) {
state.currentTab = tab
},
updatePredefinedQueries (state, queries) {
if (Array.isArray(queries)) {
state.predefinedQueries = queries
} else {
state.predefinedQueries = [queries]
}
}
state.tabs.splice(index, 1)
},
actions: {
setCurrentTabId (state, id) {
state.currentTabId = id
},
setCurrentTab (state, tab) {
state.currentTab = tab
},
updatePredefinedQueries (state, queries) {
if (Array.isArray(queries)) {
state.predefinedQueries = queries
} else {
state.predefinedQueries = [queries]
}
}
}
export default new Vuex.Store({
state,
mutations
})