fix: empty workspace deleting connections in some conditions

This commit is contained in:
Fabio Di Stasio 2023-09-11 18:02:19 +02:00
parent 785bc40ad0
commit 0de5ef8a98
3 changed files with 10 additions and 5 deletions

View File

@ -55,7 +55,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { uidGen } from 'common/libs/uidGen'; import { uidGen } from 'common/libs/uidGen';
import { storeToRefs } from 'pinia';
import { computed, Prop, ref } from 'vue'; import { computed, Prop, ref } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
@ -78,10 +77,8 @@ const {
} = connectionsStore; } = connectionsStore;
const workspacesStore = useWorkspacesStore(); const workspacesStore = useWorkspacesStore();
const { getSelected: selectedWorkspace } = storeToRefs(workspacesStore);
const { const {
selectWorkspace,
removeConnected: disconnectWorkspace, removeConnected: disconnectWorkspace,
getWorkspace getWorkspace
} = workspacesStore; } = workspacesStore;
@ -101,8 +98,8 @@ const connectionName = computed(() => props.contextConnection.name || getConnect
const isConnected = computed(() => getWorkspace(props.contextConnection.uid)?.connectionStatus === 'connected'); const isConnected = computed(() => getWorkspace(props.contextConnection.uid)?.connectionStatus === 'connected');
const confirmDeleteConnection = () => { const confirmDeleteConnection = () => {
if (selectedWorkspace.value === props.contextConnection.uid) if (isConnected.value)
selectWorkspace(null); disconnectWorkspace(props.contextConnection.uid);
deleteConnection(props.contextConnection); deleteConnection(props.contextConnection);
closeContext(); closeContext();
}; };

View File

@ -3,6 +3,8 @@ import { uidGen } from 'common/libs/uidGen';
import * as crypto from 'crypto'; import * as crypto from 'crypto';
import * as Store from 'electron-store'; import * as Store from 'electron-store';
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
import { useWorkspacesStore } from '@/stores/workspaces';
const key = localStorage.getItem('key'); const key = localStorage.getItem('key');
export interface SidebarElement { export interface SidebarElement {
@ -105,10 +107,12 @@ export const useConnectionsStore = defineStore('connections', {
return el; return el;
}); });
this.connectionsOrder = (this.connectionsOrder as SidebarElement[]).filter(el => el.uid !== connection.uid); this.connectionsOrder = (this.connectionsOrder as SidebarElement[]).filter(el => el.uid !== connection.uid);
this.lastConnections = (this.lastConnections as SidebarElement[]).filter(el => el.uid !== connection.uid);
this.connections = (this.connections as SidebarElement[]).filter(el => el.uid !== connection.uid); this.connections = (this.connections as SidebarElement[]).filter(el => el.uid !== connection.uid);
persistentStore.set('connections', this.connections); persistentStore.set('connections', this.connections);
this.clearEmptyFolders(); this.clearEmptyFolders();
useWorkspacesStore().removeWorkspace(connection.uid);
}, },
editConnection (connection: ConnectionParams) { editConnection (connection: ConnectionParams) {
const editedConnections = (this.connections as ConnectionParams[]).map(conn => { const editedConnections = (this.connections as ConnectionParams[]).map(conn => {

View File

@ -424,6 +424,10 @@ export const useWorkspacesStore = defineStore('workspaces', {
this.workspaces.push(workspace); this.workspaces.push(workspace);
}, },
removeWorkspace (uid: string) {
this.workspaces = this.workspaces.filter((w: Workspace) => w.uid !== uid);
if (uid === this.selectedWorkspace) this.selectedWorkspace = 'NEW';
},
changeBreadcrumbs (payload: Breadcrumb) { changeBreadcrumbs (payload: Breadcrumb) {
const breadcrumbsObj: Breadcrumb = { const breadcrumbsObj: Breadcrumb = {
schema: null, schema: null,