antares/src/renderer/store/modules/workspaces.store.js

723 lines
27 KiB
JavaScript
Raw Normal View History

'use strict';
import Store from 'electron-store';
2020-05-18 18:06:32 +02:00
import Connection from '@/ipc-api/Connection';
2021-03-17 11:15:14 +01:00
import Schema from '@/ipc-api/Schema';
import Users from '@/ipc-api/Users';
import { uidGen } from 'common/libs/uidGen';
const persistentStore = new Store({ name: 'tabs' });
const tabIndex = [];
2020-06-05 21:00:15 +02:00
export default {
namespaced: true,
strict: true,
state: {
workspaces: [],
2021-07-16 23:24:55 +02:00
selected_workspace: null
},
getters: {
getSelected: state => {
2020-05-18 18:06:32 +02:00
if (state.selected_workspace) return state.selected_workspace;
if (state.workspaces.length) return state.workspaces[0].uid;
2021-07-08 17:43:33 +02:00
return 'NEW';
},
2020-05-20 18:00:14 +02:00
getWorkspace: state => uid => {
return state.workspaces.find(workspace => workspace.uid === uid);
},
2020-09-25 12:39:58 +02:00
getDatabaseVariable: state => (uid, name) => {
return state.workspaces.find(workspace => workspace.uid === uid).variables.find(variable => variable.name === name);
},
getWorkspaceTab: (state, getters) => tUid => {
if (!getters.getSelected) return;
const workspace = state.workspaces.find(workspace => workspace.uid === getters.getSelected);
if ('tabs' in workspace)
return workspace.tabs.find(tab => tab.uid === tUid);
return {};
2020-05-20 18:00:14 +02:00
},
getConnected: state => {
return state.workspaces
.filter(workspace => workspace.connectionStatus === 'connected')
2020-05-20 18:00:14 +02:00
.map(workspace => workspace.uid);
2020-12-04 11:19:16 +01:00
},
getLoadedSchemas: state => uid => {
return state.workspaces.find(workspace => workspace.uid === uid).loadedSchemas;
},
2021-02-20 11:55:34 +01:00
getSearchTerm: state => uid => {
return state.workspaces.find(workspace => workspace.uid === uid).searchTerm;
2020-05-20 18:00:14 +02:00
}
},
mutations: {
SELECT_WORKSPACE (state, uid) {
2021-07-08 17:43:33 +02:00
if (!uid)
state.selected_workspace = state.workspaces.length ? state.workspaces[0].uid : 'NEW';
else
state.selected_workspace = uid;
},
SET_CONNECTED (state, payload) {
const { uid, client, dataTypes, indexTypes, customizations, structure, version } = payload;
2021-02-06 12:37:37 +01:00
const cachedTabs = payload.restoreTabs ? persistentStore.get(uid, []) : [];
if (cachedTabs.length) {
tabIndex[uid] = cachedTabs.reduce((acc, curr) => {
if (curr.index > acc) acc = curr.index;
return acc;
}, null);
}
2020-11-13 12:39:40 +01:00
state.workspaces = state.workspaces.map(workspace => workspace.uid === uid
? {
...workspace,
client,
dataTypes,
2020-12-01 16:48:20 +01:00
indexTypes,
customizations,
2020-11-13 12:39:40 +01:00
structure,
connectionStatus: 'connected',
tabs: cachedTabs,
selectedTab: cachedTabs.length ? cachedTabs[0].uid : null,
version
2020-11-13 12:39:40 +01:00
}
: workspace);
},
SET_CONNECTING (state, uid) {
2020-11-13 12:39:40 +01:00
state.workspaces = state.workspaces.map(workspace => workspace.uid === uid
? {
...workspace,
structure: {},
breadcrumbs: {},
loadedSchemas: new Set(),
connectionStatus: 'connecting'
}
: workspace);
},
SET_FAILED (state, uid) {
state.workspaces = state.workspaces.map(workspace => workspace.uid === uid
? {
...workspace,
structure: {},
breadcrumbs: {},
loadedSchemas: new Set(),
connectionStatus: 'failed'
}
: workspace);
},
SET_DISCONNECTED (state, uid) {
state.workspaces = state.workspaces.map(workspace => workspace.uid === uid
? {
...workspace,
structure: {},
breadcrumbs: {},
loadedSchemas: new Set(),
connectionStatus: 'disconnected'
2020-11-13 12:39:40 +01:00
}
: workspace);
2020-05-20 18:00:14 +02:00
},
2020-05-31 17:56:33 +02:00
REFRESH_STRUCTURE (state, { uid, structure }) {
2020-11-13 12:39:40 +01:00
state.workspaces = state.workspaces.map(workspace => workspace.uid === uid
? {
...workspace,
structure
}
: workspace);
2020-05-18 18:06:32 +02:00
},
REFRESH_SCHEMA (state, { uid, schema, schemaElements }) {
state.workspaces = state.workspaces.map(workspace => {
if (workspace.uid === uid) {
const schemaIndex = workspace.structure.findIndex(s => s.name === schema);
if (schemaIndex !== -1)
workspace.structure[schemaIndex] = schemaElements;
else
workspace.structure.push(schemaElements);
}
return workspace;
});
},
2020-09-25 12:39:58 +02:00
REFRESH_COLLATIONS (state, { uid, collations }) {
2020-11-13 12:39:40 +01:00
state.workspaces = state.workspaces.map(workspace => workspace.uid === uid
? {
...workspace,
collations
}
: workspace);
2020-09-25 12:39:58 +02:00
},
REFRESH_VARIABLES (state, { uid, variables }) {
2020-11-13 12:39:40 +01:00
state.workspaces = state.workspaces.map(workspace => workspace.uid === uid
? {
...workspace,
variables
}
: workspace);
},
2020-11-16 17:16:39 +01:00
REFRESH_ENGINES (state, { uid, engines }) {
state.workspaces = state.workspaces.map(workspace => workspace.uid === uid
? {
...workspace,
engines
}
: workspace);
},
REFRESH_USERS (state, { uid, users }) {
state.workspaces = state.workspaces.map(workspace => workspace.uid === uid
? {
...workspace,
users
}
: workspace);
},
2020-05-18 18:06:32 +02:00
ADD_WORKSPACE (state, workspace) {
state.workspaces.push(workspace);
2020-06-05 21:00:15 +02:00
},
CHANGE_BREADCRUMBS (state, { uid, breadcrumbs }) {
2020-11-13 12:39:40 +01:00
state.workspaces = state.workspaces.map(workspace => workspace.uid === uid
? {
...workspace,
breadcrumbs
}
: workspace);
2020-06-05 21:00:15 +02:00
},
2021-02-20 11:55:34 +01:00
SET_SEARCH_TERM (state, { uid, term }) {
state.workspaces = state.workspaces.map(workspace => workspace.uid === uid
? {
...workspace,
searchTerm: term
2021-02-20 11:55:34 +01:00
}
: workspace);
},
2021-07-16 18:52:18 +02:00
NEW_TAB (state, { uid, tab, content, type, autorun, schema, elementName, elementType }) {
2021-07-12 19:18:29 +02:00
if (type === 'query')
tabIndex[uid] = tabIndex[uid] ? ++tabIndex[uid] : 1;
2020-06-05 21:00:15 +02:00
const newTab = {
2020-12-11 15:55:18 +01:00
uid: tab,
2021-07-12 19:18:29 +02:00
index: type === 'query' ? tabIndex[uid] : null,
2020-06-12 18:10:45 +02:00
selected: false,
2021-07-12 19:18:29 +02:00
type,
schema,
2021-07-16 18:52:18 +02:00
elementName,
elementType,
fields: [],
keyUsage: [],
content: content || '',
autorun: !!autorun
2020-06-05 21:00:15 +02:00
};
2020-06-05 21:00:15 +02:00
state.workspaces = state.workspaces.map(workspace => {
if (workspace.uid === uid) {
return {
...workspace,
tabs: [...workspace.tabs, newTab]
};
}
else
return workspace;
});
persistentStore.set(uid, state.workspaces.find(workspace => workspace.uid === uid).tabs);
2020-06-12 18:10:45 +02:00
},
2020-08-19 18:20:57 +02:00
REMOVE_TAB (state, { uid, tab: tUid }) {
state.workspaces = state.workspaces.map(workspace => {
if (workspace.uid === uid) {
return {
...workspace,
tabs: workspace.tabs.filter(tab => tab.uid !== tUid)
};
}
else
return workspace;
});
persistentStore.set(uid, state.workspaces.find(workspace => workspace.uid === uid).tabs);
2020-08-19 18:20:57 +02:00
},
2021-07-17 10:46:24 +02:00
REMOVE_TABS (state, { uid, schema, elementName, elementType }) { // Multiple tabs based on schema and element name
if (elementType === 'procedure') elementType = 'routine'; // TODO: pass directly "routine"
2021-07-17 10:46:24 +02:00
state.workspaces = state.workspaces.map(workspace => {
if (workspace.uid === uid) {
return {
...workspace,
tabs: workspace.tabs.filter(tab =>
tab.schema !== schema ||
tab.elementName !== elementName ||
tab.elementType !== elementType
)
};
}
else
return workspace;
});
persistentStore.set(uid, state.workspaces.find(workspace => workspace.uid === uid).tabs);
2021-07-17 10:46:24 +02:00
},
REPLACE_TAB (state, { uid, tab: tUid, type, schema, content, elementName, elementType }) {
2021-07-13 16:53:47 +02:00
state.workspaces = state.workspaces.map(workspace => {
if (workspace.uid === uid) {
return {
...workspace,
tabs: workspace.tabs.map(tab => {
if (tab.uid === tUid)
return { ...tab, type, schema, content, elementName, elementType };
2021-07-13 16:53:47 +02:00
return tab;
})
};
}
else
return workspace;
});
persistentStore.set(uid, state.workspaces.find(workspace => workspace.uid === uid).tabs);
2021-07-13 16:53:47 +02:00
},
RENAME_TABS (state, { uid, schema, elementName, elementType, elementNewName }) {
state.workspaces = state.workspaces.map(workspace => {
if (workspace.uid === uid) {
return {
...workspace,
tabs: workspace.tabs.map(tab => {
2021-07-16 18:52:18 +02:00
if (tab.elementName === elementName && tab.schema === schema) {
return {
...tab,
2021-07-16 18:52:18 +02:00
elementName: elementNewName
};
}
return tab;
})
};
}
else
return workspace;
});
persistentStore.set(uid, state.workspaces.find(workspace => workspace.uid === uid).tabs);
},
2020-06-12 18:10:45 +02:00
SELECT_TAB (state, { uid, tab }) {
state.workspaces = state.workspaces.map(workspace => workspace.uid === uid ? { ...workspace, selectedTab: tab } : workspace);
},
2021-07-14 20:30:54 +02:00
UPDATE_TABS (state, { uid, tabs }) {
state.workspaces = state.workspaces.map(workspace => workspace.uid === uid ? { ...workspace, tabs } : workspace);
persistentStore.set(uid, state.workspaces.find(workspace => workspace.uid === uid).tabs);
2021-07-14 20:30:54 +02:00
},
SET_TAB_FIELDS (state, { cUid, tUid, fields }) {
state.workspaces = state.workspaces.map(workspace => {
if (workspace.uid === cUid) {
return {
...workspace,
tabs: workspace.tabs.map(tab => {
if (tab.uid === tUid)
return { ...tab, fields };
else
return tab;
})
};
}
else
return workspace;
});
persistentStore.set(uid, state.workspaces.find(workspace => workspace.uid === uid).tabs);
},
SET_TAB_KEY_USAGE (state, { cUid, tUid, keyUsage }) {
state.workspaces = state.workspaces.map(workspace => {
if (workspace.uid === cUid) {
return {
...workspace,
tabs: workspace.tabs.map(tab => {
if (tab.uid === tUid)
return { ...tab, keyUsage };
else
return tab;
})
};
}
else
return workspace;
});
persistentStore.set(uid, state.workspaces.find(workspace => workspace.uid === uid).tabs);
2020-12-04 11:19:16 +01:00
},
2021-07-16 23:24:55 +02:00
SET_UNSAVED_CHANGES (state, { uid, tUid, isChanged }) {
state.workspaces = state.workspaces.map(workspace => {
if (workspace.uid === uid) {
return {
...workspace,
tabs: workspace.tabs.map(tab => {
if (tab.uid === tUid)
return { ...tab, isChanged };
return tab;
})
};
}
else
return workspace;
});
2020-12-04 11:19:16 +01:00
},
ADD_LOADED_SCHEMA (state, payload) {
state.workspaces = state.workspaces.map(workspace => {
if (workspace.uid === payload.uid)
workspace.loadedSchemas.add(payload.schema);
return workspace;
});
},
ADD_LOADING_ELEMENT (state, payload) {
state.workspaces = state.workspaces.map(workspace => {
if (workspace.uid === payload.uid)
workspace.loadingElements.push(payload.element);
return workspace;
});
},
REMOVE_LOADING_ELEMENT (state, payload) {
state.workspaces = state.workspaces.map(workspace => {
if (workspace.uid === payload.uid) {
const loadingElements = workspace.loadingElements.filter(el =>
el.schema !== payload.element.schema &&
el.name !== payload.element.name &&
el.type !== payload.element.type
);
workspace = { ...workspace, loadingElements };
}
return workspace;
});
}
},
actions: {
2020-11-13 12:39:40 +01:00
selectWorkspace ({ commit }, uid) {
commit('SELECT_WORKSPACE', uid);
},
async connectWorkspace ({ dispatch, commit, getters, rootGetters }, connection) {
commit('SET_CONNECTING', connection.uid);
2020-05-19 18:06:05 +02:00
try {
const { status, response } = await Connection.connect(connection);
if (status === 'error') {
2020-05-19 18:06:05 +02:00
dispatch('notifications/addNotification', { status, message: response }, { root: true });
commit('SET_FAILED', connection.uid);
}
else {
2020-11-13 12:39:40 +01:00
let dataTypes = [];
2020-12-01 16:48:20 +01:00
let indexTypes = [];
let customizations = {};
2020-11-13 12:39:40 +01:00
switch (connection.client) {
case 'mysql':
case 'maria':
dataTypes = require('common/data-types/mysql');
2020-12-01 16:48:20 +01:00
indexTypes = require('common/index-types/mysql');
customizations = require('common/customizations/mysql');
break;
case 'pg':
dataTypes = require('common/data-types/postgresql');
indexTypes = require('common/index-types/postgresql');
customizations = require('common/customizations/postgresql');
2020-11-13 12:39:40 +01:00
break;
}
2021-03-17 11:15:14 +01:00
const { status, response: version } = await Schema.getVersion(connection.uid);
if (status === 'error')
dispatch('notifications/addNotification', { status, message: version }, { root: true });
2021-02-06 12:37:37 +01:00
// Check if Maria or MySQL
2021-02-06 12:37:37 +01:00
const isMySQL = version.name.includes('MySQL');
if (isMySQL && connection.client !== 'mysql') {
const connProxy = Object.assign({}, connection);
connProxy.client = 'mysql';
dispatch('connections/editConnection', connProxy, { root: true });
}
else if (!isMySQL && connection.client === 'mysql') {
const connProxy = Object.assign({}, connection);
connProxy.client = 'maria';
dispatch('connections/editConnection', connProxy, { root: true });
}
commit('SET_CONNECTED', {
2020-11-13 12:39:40 +01:00
uid: connection.uid,
client: connection.client,
dataTypes,
2020-12-01 16:48:20 +01:00
indexTypes,
customizations,
structure: response,
version,
restoreTabs: rootGetters['settings/getRestoreTabs']
2020-11-13 12:39:40 +01:00
});
dispatch('refreshCollations', connection.uid);
2020-09-25 12:39:58 +02:00
dispatch('refreshVariables', connection.uid);
2020-11-16 17:16:39 +01:00
dispatch('refreshEngines', connection.uid);
dispatch('refreshUsers', connection.uid);
}
2020-05-19 18:06:05 +02:00
}
catch (err) {
dispatch('notifications/addNotification', { status: 'error', message: err.stack }, { root: true });
}
},
async refreshStructure ({ dispatch, commit, getters }, uid) {
2020-05-20 18:00:14 +02:00
try {
2021-03-17 11:15:14 +01:00
const { status, response } = await Schema.getStructure({ uid, schemas: getters.getLoadedSchemas(uid) });
2020-05-20 18:00:14 +02:00
if (status === 'error')
dispatch('notifications/addNotification', { status, message: response }, { root: true });
else
commit('REFRESH_STRUCTURE', { uid, structure: response });
2020-05-20 18:00:14 +02:00
}
catch (err) {
dispatch('notifications/addNotification', { status: 'error', message: err.stack }, { root: true });
}
},
async refreshSchema ({ dispatch, commit }, { uid, schema }) {
try {
2021-03-17 11:15:14 +01:00
const { status, response } = await Schema.getStructure({ uid, schemas: new Set([schema]) });
if (status === 'error')
dispatch('notifications/addNotification', { status, message: response }, { root: true });
else
commit('REFRESH_SCHEMA', { uid, schema, schemaElements: response.find(_schema => _schema.name === schema) });
}
catch (err) {
dispatch('notifications/addNotification', { status: 'error', message: err.stack }, { root: true });
}
},
async refreshCollations ({ dispatch, commit }, uid) {
try {
2021-03-17 11:15:14 +01:00
const { status, response } = await Schema.getCollations(uid);
if (status === 'error')
dispatch('notifications/addNotification', { status, message: response }, { root: true });
else
commit('REFRESH_COLLATIONS', { uid, collations: response });
}
catch (err) {
dispatch('notifications/addNotification', { status: 'error', message: err.stack }, { root: true });
}
},
2020-09-25 12:39:58 +02:00
async refreshVariables ({ dispatch, commit }, uid) {
try {
2021-03-17 11:15:14 +01:00
const { status, response } = await Schema.getVariables(uid);
2020-09-25 12:39:58 +02:00
if (status === 'error')
dispatch('notifications/addNotification', { status, message: response }, { root: true });
else
commit('REFRESH_VARIABLES', { uid, variables: response });
}
catch (err) {
dispatch('notifications/addNotification', { status: 'error', message: err.stack }, { root: true });
}
},
2020-11-16 17:16:39 +01:00
async refreshEngines ({ dispatch, commit }, uid) {
try {
2021-03-17 11:15:14 +01:00
const { status, response } = await Schema.getEngines(uid);
2020-11-16 17:16:39 +01:00
if (status === 'error')
dispatch('notifications/addNotification', { status, message: response }, { root: true });
else
commit('REFRESH_ENGINES', { uid, engines: response });
}
catch (err) {
dispatch('notifications/addNotification', { status: 'error', message: err.stack }, { root: true });
}
},
async refreshUsers ({ dispatch, commit }, uid) {
try {
const { status, response } = await Users.getUsers(uid);
if (status === 'error')
dispatch('notifications/addNotification', { status, message: response }, { root: true });
else
commit('REFRESH_USERS', { uid, users: response });
}
catch (err) {
dispatch('notifications/addNotification', { status: 'error', message: err.stack }, { root: true });
}
},
2020-06-05 21:00:15 +02:00
removeConnected ({ commit }, uid) {
2020-05-18 18:06:32 +02:00
Connection.disconnect(uid);
commit('SET_DISCONNECTED', uid);
2020-06-13 18:14:32 +02:00
commit('SELECT_TAB', { uid, tab: 0 });
2020-05-18 18:06:32 +02:00
},
addWorkspace ({ commit }, uid) {
2020-05-18 18:06:32 +02:00
const workspace = {
uid,
connectionStatus: 'disconnected',
selectedTab: 0,
searchTerm: '',
tabs: [],
2020-06-05 21:00:15 +02:00
structure: {},
2020-09-25 12:39:58 +02:00
variables: [],
collations: [],
users: [],
breadcrumbs: {},
loadingElements: [],
loadedSchemas: new Set()
2020-05-18 18:06:32 +02:00
};
2020-06-05 21:00:15 +02:00
2020-05-18 18:06:32 +02:00
commit('ADD_WORKSPACE', workspace);
2020-06-05 21:00:15 +02:00
},
2021-07-17 10:46:24 +02:00
changeBreadcrumbs ({ commit, getters }, payload) {
2020-12-03 13:00:54 +01:00
const breadcrumbsObj = {
schema: null,
table: null,
trigger: null,
triggerFunction: null,
2020-12-03 13:00:54 +01:00
procedure: null,
2021-01-05 17:25:18 +01:00
function: null,
2020-12-26 14:47:15 +01:00
scheduler: null,
view: null,
query: null
2020-12-03 13:00:54 +01:00
};
commit('CHANGE_BREADCRUMBS', { uid: getters.getSelected, breadcrumbs: { ...breadcrumbsObj, ...payload } });
2021-07-21 17:56:55 +02:00
},
addLoadedSchema ({ commit, getters }, schema) {
commit('ADD_LOADED_SCHEMA', { uid: getters.getSelected, schema });
2020-06-05 21:00:15 +02:00
},
addLoadingElement ({ commit, getters }, element) {
commit('ADD_LOADING_ELEMENT', { uid: getters.getSelected, element });
},
removeLoadingElement ({ commit, getters }, element) {
commit('REMOVE_LOADING_ELEMENT', { uid: getters.getSelected, element });
},
2021-02-20 11:55:34 +01:00
setSearchTerm ({ commit, getters }, term) {
commit('SET_SEARCH_TERM', { uid: getters.getSelected, term });
},
2021-07-16 18:52:18 +02:00
newTab ({ state, commit }, { uid, content, type, autorun, schema, elementName, elementType }) {
2021-07-13 16:53:47 +02:00
let tabUid;
2021-07-13 19:23:02 +02:00
const workspaceTabs = state.workspaces.find(workspace => workspace.uid === uid);
2021-07-17 13:10:54 +02:00
switch (type) {
2021-08-13 16:50:59 +02:00
case 'new-table':
case 'new-trigger':
case 'new-trigger-function':
case 'new-function':
case 'new-routine':
case 'new-scheduler':
tabUid = uidGen('T');
commit('NEW_TAB', {
uid,
tab: tabUid,
content,
type,
autorun,
schema,
elementName,
elementType
});
break;
case 'temp-data':
2021-07-19 22:38:56 +02:00
case 'temp-trigger-props':
case 'temp-trigger-function-props':
case 'temp-function-props':
case 'temp-routine-props':
case 'temp-scheduler-props': {
2021-07-17 13:10:54 +02:00
const existentTab = workspaceTabs
? workspaceTabs.tabs.find(tab =>
tab.schema === schema &&
2021-07-17 16:09:57 +02:00
tab.elementName === elementName &&
tab.elementType === elementType &&
2021-07-19 22:38:56 +02:00
[type, type.replace('temp-', '')].includes(tab.type))
2021-07-17 13:10:54 +02:00
: false;
if (existentTab) { // if tab exists
tabUid = existentTab.uid;
}
else {
2021-07-19 22:38:56 +02:00
const tempTabs = workspaceTabs ? workspaceTabs.tabs.filter(tab => tab.type.includes('temp-')) : false;
2021-07-17 13:10:54 +02:00
if (tempTabs && tempTabs.length) { // if temp tab already opened
for (const tab of tempTabs) {
if (tab.isChanged) {
commit('REPLACE_TAB', { // make permanent a temp table with unsaved changes
uid,
tab: tab.uid,
2021-07-19 22:38:56 +02:00
type: tab.type.replace('temp-', ''),
schema: tab.schema,
elementName: tab.elementName,
elementType: tab.elementType
});
tabUid = uidGen('T');
commit('NEW_TAB', { uid, tab: tabUid, content, type, autorun, schema, elementName, elementType });
}
else {
commit('REPLACE_TAB', { uid, tab: tab.uid, type, schema, elementName, elementType });
tabUid = tab.uid;
}
2021-07-17 13:10:54 +02:00
}
}
else {
tabUid = uidGen('T');
commit('NEW_TAB', { uid, tab: tabUid, content, type, autorun, schema, elementName, elementType });
}
}
2021-07-12 19:18:29 +02:00
}
2021-07-17 13:10:54 +02:00
break;
case 'data':
case 'table-props':
2021-07-19 22:38:56 +02:00
case 'trigger-props':
case 'trigger-function-props':
case 'function-props':
case 'routine-props':
case 'scheduler-props': {
2021-07-17 13:10:54 +02:00
const existentTab = workspaceTabs
? workspaceTabs.tabs.find(tab =>
tab.schema === schema &&
tab.elementName === elementName &&
tab.elementType === elementType &&
2021-07-19 22:38:56 +02:00
[`temp-${type}`, type].includes(tab.type))
2021-07-17 13:10:54 +02:00
: false;
2021-07-15 19:51:18 +02:00
2021-07-17 13:10:54 +02:00
if (existentTab) {
commit('REPLACE_TAB', { uid, tab: existentTab.uid, type, schema, elementName, elementType });
tabUid = existentTab.uid;
}
else {
tabUid = uidGen('T');
commit('NEW_TAB', { uid, tab: tabUid, content, type, autorun, schema, elementName, elementType });
}
2021-07-15 19:51:18 +02:00
}
2021-07-17 13:10:54 +02:00
break;
default:
2021-07-15 19:51:18 +02:00
tabUid = uidGen('T');
2021-07-16 18:52:18 +02:00
commit('NEW_TAB', { uid, tab: tabUid, content, type, autorun, schema, elementName, elementType });
2021-07-17 13:10:54 +02:00
break;
2021-07-13 16:53:47 +02:00
}
2020-12-11 15:55:18 +01:00
2021-07-13 16:53:47 +02:00
commit('SELECT_TAB', { uid, tab: tabUid });
2020-06-12 18:10:45 +02:00
},
2021-07-17 10:46:24 +02:00
checkSelectedTabExists ({ state, commit }, uid) {
const workspace = state.workspaces.find(workspace => workspace.uid === uid);
const isSelectedExistent = workspace
? workspace.tabs.some(tab => tab.uid === workspace.selectedTab)
2021-07-17 10:46:24 +02:00
: false;
2021-07-18 16:10:36 +02:00
if (!isSelectedExistent && workspace.tabs.length)
2021-07-17 10:46:24 +02:00
commit('SELECT_TAB', { uid, tab: workspace.tabs[workspace.tabs.length - 1].uid });
},
updateTabContent ({ commit }, { uid, tab, type, schema, content }) {
commit('REPLACE_TAB', { uid, tab, type, schema, content });
},
renameTabs ({ commit }, payload) {
commit('RENAME_TABS', payload);
},
2021-07-17 10:46:24 +02:00
removeTab ({ commit, dispatch }, payload) {
2020-08-19 18:20:57 +02:00
commit('REMOVE_TAB', payload);
2021-07-17 10:46:24 +02:00
dispatch('checkSelectedTabExists', payload.uid);
},
removeTabs ({ commit, dispatch }, payload) {
commit('REMOVE_TABS', payload);
dispatch('checkSelectedTabExists', payload.uid);
2020-08-19 18:20:57 +02:00
},
2020-06-12 18:10:45 +02:00
selectTab ({ commit }, payload) {
commit('SELECT_TAB', payload);
},
2021-07-14 20:30:54 +02:00
updateTabs ({ commit }, payload) {
commit('UPDATE_TABS', payload);
},
setTabFields ({ commit }, payload) {
commit('SET_TAB_FIELDS', payload);
},
setTabKeyUsage ({ commit }, payload) {
commit('SET_TAB_KEY_USAGE', payload);
2020-12-04 11:19:16 +01:00
},
2021-07-16 23:24:55 +02:00
setUnsavedChanges ({ commit }, payload) {
commit('SET_UNSAVED_CHANGES', payload);
}
}
};