+
{{ t('word.duplicate') }}
@@ -38,7 +28,7 @@
>
- {{ t('message.deleteConnection') }}
+ {{ t(contextConnection.isFolder ? 'message.deleteFolder' : 'message.deleteConnection') }}
@@ -55,26 +45,22 @@ import { computed, Prop, ref } from 'vue';
import { storeToRefs } from 'pinia';
import { uidGen } from 'common/libs/uidGen';
import { useI18n } from 'vue-i18n';
-import { useConnectionsStore } from '@/stores/connections';
+import { SidebarElement, useConnectionsStore } from '@/stores/connections';
import { useWorkspacesStore } from '@/stores/workspaces';
import BaseContextMenu from '@/components/BaseContextMenu.vue';
import ConfirmModal from '@/components/BaseConfirmModal.vue';
-import { ConnectionParams } from 'common/interfaces/antares';
const { t } = useI18n();
const connectionsStore = useConnectionsStore();
const {
+ getConnectionByUid,
getConnectionName,
addConnection,
- deleteConnection,
- pinConnection,
- unpinConnection
+ deleteConnection
} = connectionsStore;
-const { pinnedConnections } = storeToRefs(connectionsStore);
-
const workspacesStore = useWorkspacesStore();
const { getSelected: selectedWorkspace } = storeToRefs(workspacesStore);
@@ -86,16 +72,15 @@ const {
const props = defineProps({
contextEvent: MouseEvent,
- contextConnection: Object as Prop
+ contextConnection: Object as Prop
});
const emit = defineEmits(['close-context']);
const isConfirmModal = ref(false);
-const connectionName = computed(() => getConnectionName(props.contextConnection.uid));
-const isConnected = computed(() => getWorkspace(props.contextConnection.uid).connectionStatus === 'connected');
-const isPinned = computed(() => pinnedConnections.value.has(props.contextConnection.uid));
+const connectionName = computed(() => props.contextConnection.name || getConnectionName(props.contextConnection.uid) || t('word.folder', 1));
+const isConnected = computed(() => getWorkspace(props.contextConnection.uid)?.connectionStatus === 'connected');
const confirmDeleteConnection = () => {
if (selectedWorkspace.value === props.contextConnection.uid)
@@ -105,7 +90,7 @@ const confirmDeleteConnection = () => {
};
const duplicateConnection = () => {
- let connectionCopy = Object.assign({}, props.contextConnection);
+ let connectionCopy = getConnectionByUid(props.contextConnection.uid);
connectionCopy = {
...connectionCopy,
uid: uidGen('C'),
@@ -125,16 +110,6 @@ const hideConfirmModal = () => {
closeContext();
};
-const pin = () => {
- pinConnection(props.contextConnection.uid);
- closeContext();
-};
-
-const unpin = () => {
- unpinConnection(props.contextConnection.uid);
- closeContext();
-};
-
const disconnect = () => {
disconnectWorkspace(props.contextConnection.uid);
closeContext();
diff --git a/src/renderer/components/TheSettingBar.vue b/src/renderer/components/TheSettingBar.vue
index e4011d51..f9961f1e 100644
--- a/src/renderer/components/TheSettingBar.vue
+++ b/src/renderer/components/TheSettingBar.vue
@@ -8,47 +8,10 @@
@close-context="isContext = false"
/>
-
-
- -
-
- {{ getConnectionName(element.uid) }}
-
-
-
-
-
-
- -
-
- {{ getConnectionName(connection.uid) }}
-
+
@@ -102,12 +65,11 @@
import { ref, Ref, computed, watch } from 'vue';
import { storeToRefs } from 'pinia';
import { useApplicationStore } from '@/stores/application';
-import { useConnectionsStore } from '@/stores/connections';
+import { useConnectionsStore, SidebarElement } from '@/stores/connections';
import { useWorkspacesStore } from '@/stores/workspaces';
import { useSettingsStore } from '@/stores/settings';
-import * as Draggable from 'vuedraggable';
import SettingBarContext from '@/components/SettingBarContext.vue';
-import { ConnectionParams } from 'common/interfaces/antares';
+import SettingBarConnections from '@/components/SettingBarConnections.vue';
import { useElementBounding } from '@vueuse/core';
import { useI18n } from 'vue-i18n';
@@ -119,121 +81,42 @@ const workspacesStore = useWorkspacesStore();
const settingsStore = useSettingsStore();
const { updateStatus } = storeToRefs(applicationStore);
-const { connections: storedConnections, pinnedConnections, lastConnections } = storeToRefs(connectionsStore);
const { getSelected: selectedWorkspace } = storeToRefs(workspacesStore);
+const { getConnectionsOrder: connectionsOrder } = storeToRefs(connectionsStore);
const { disableScratchpad } = storeToRefs(settingsStore);
const { showSettingModal, showScratchpad } = applicationStore;
-const { getConnectionName, updatePinnedConnections } = connectionsStore;
-const { getWorkspace, selectWorkspace } = workspacesStore;
+const { updateConnectionsOrder } = connectionsStore;
+const { selectWorkspace } = workspacesStore;
const emit = defineEmits(['show-connections-modal']);
-const isLinux = process.platform === 'linux';
-
const sidebarConnections: Ref
= ref(null);
const isContext: Ref = ref(false);
-const isDragging: Ref = ref(false);
const isScrollable: Ref = ref(false);
const contextEvent: Ref = ref(null);
-const contextConnection: Ref = ref(null);
+const contextConnection: Ref = ref(null);
const sidebarConnectionsHeight = ref(useElementBounding(sidebarConnections)?.height);
-const pinnedConnectionsArr = computed({
- get: () => [...pinnedConnections.value].map(c => storedConnections.value.find(sc => sc.uid === c)).filter(Boolean),
- set: (value: ConnectionParams[]) => {
- const pinnedUid = value.reduce((acc, curr) => {
- acc.push(curr.uid);
- return acc;
- }, []);
-
- updatePinnedConnections(pinnedUid);
+const connectionsArr = computed({
+ get: () => connectionsOrder.value,
+ set: (value: SidebarElement[]) => {
+ updateConnectionsOrder(value);
}
});
-const unpinnedConnectionsArr = computed(() => {
- return storedConnections.value
- .filter(c => !pinnedConnections.value.has(c.uid))
- .map(c => {
- const connTime = lastConnections.value.find((lc) => lc.uid === c.uid)?.time || 0;
- return { ...c, time: connTime };
- })
- .sort((a, b) => {
- if (a.time < b.time) return 1;
- else if (a.time > b.time) return -1;
- return 0;
- });
-});
-
const hasUpdates = computed(() => ['available', 'downloading', 'downloaded', 'link'].includes(updateStatus.value));
-const contextMenu = (event: MouseEvent, connection: ConnectionParams) => {
+const contextMenu = (event: MouseEvent, connection: SidebarElement) => {
contextEvent.value = event;
contextConnection.value = connection;
isContext.value = true;
};
-const tooltipPosition = (e: Event) => {
- const el = (e.target ? e.target : e) as unknown as HTMLElement;
- const tooltip = el.querySelector('.ex-tooltip-content');
- if (tooltip) {
- const fromTop = isLinux
- ? window.scrollY + el.getBoundingClientRect().top + (el.offsetHeight / 4)
- : window.scrollY + el.getBoundingClientRect().top - (el.offsetHeight / 4);
- tooltip.style.top = `${fromTop}px`;
- }
-};
-
-const getStatusBadge = (uid: string) => {
- if (getWorkspace(uid)) {
- const status = getWorkspace(uid).connectionStatus;
-
- switch (status) {
- case 'connected':
- return 'badge badge-connected';
- case 'connecting':
- return 'badge badge-connecting';
- case 'failed':
- return 'badge badge-failed';
- default:
- return '';
- }
- }
-};
-
-// eslint-disable-next-line @typescript-eslint/no-explicit-any
-const dragStop = (e: any) => {
- isDragging.value = false;
-
- setTimeout(() => {
- tooltipPosition(e.originalEvent.target.parentNode);
- }, 200);
-};
-
watch(sidebarConnectionsHeight, (value) => {
isScrollable.value = value < sidebarConnections.value.scrollHeight;
});
-watch(unpinnedConnectionsArr, (newVal, oldVal) => {
- if (JSON.stringify(newVal) !== JSON.stringify(oldVal)) {
- setTimeout(() => {
- const element = document.querySelector('.settingbar-element.selected');
- if (element) {
- const rect = element.getBoundingClientRect();
- const elemTop = rect.top;
- const elemBottom = rect.bottom;
- const isVisible = (elemTop >= 0) && (elemBottom <= window.innerHeight);
-
- if (!isVisible) {
- element.setAttribute('tabindex', '-1');
- element.focus();
- element.removeAttribute('tabindex');
- }
- }
- }, 50);
- }
-});
-
watch(selectedWorkspace, (newVal, oldVal) => {
if (newVal !== oldVal) {
setTimeout(() => {
diff --git a/src/renderer/i18n/en-US.ts b/src/renderer/i18n/en-US.ts
index 3bac1565..e99747f1 100644
--- a/src/renderer/i18n/en-US.ts
+++ b/src/renderer/i18n/en-US.ts
@@ -143,7 +143,8 @@ export const enUS = {
pin: 'Pin',
unpin: 'Unpin',
console: 'Console',
- shortcuts: 'Shortcuts'
+ shortcuts: 'Shortcuts',
+ folder: 'Folder | Folders'
},
message: {
appWelcome: 'Welcome to Antares SQL Client!',
@@ -323,7 +324,8 @@ export const enUS = {
openFilter: 'Open filter',
nextResultsPage: 'Next results page',
previousResultsPage: 'Previous results page',
- fillCell: 'Fill cell'
+ fillCell: 'Fill cell',
+ deleteFolder: 'Delete folder'
},
faker: {
address: 'Address',
diff --git a/src/renderer/stores/connections.ts b/src/renderer/stores/connections.ts
index b520f597..2f595683 100644
--- a/src/renderer/stores/connections.ts
+++ b/src/renderer/stores/connections.ts
@@ -2,8 +2,18 @@ import { defineStore } from 'pinia';
import * as Store from 'electron-store';
import * as crypto from 'crypto';
import { ConnectionParams } from 'common/interfaces/antares';
+import { uidGen } from 'common/libs/uidGen';
const key = localStorage.getItem('key');
+export interface SidebarElement {
+ isFolder: boolean;
+ uid: string;
+ client?: string;
+ connections?: string[];
+ color?: string;
+ name?: string;
+}
+
if (!key)
localStorage.setItem('key', crypto.randomBytes(16).toString('hex'));
else
@@ -18,42 +28,80 @@ const persistentStore = new Store({
export const useConnectionsStore = defineStore('connections', {
state: () => ({
connections: persistentStore.get('connections', []) as ConnectionParams[],
- pinnedConnections: new Set([...persistentStore.get('pinnedConnections', []) as string[]]) as Set,
- lastConnections: persistentStore.get('lastConnections', []) as {uid: string; time: number}[]
+ lastConnections: persistentStore.get('lastConnections', []) as {uid: string; time: number}[],
+ connectionsOrder: persistentStore.get('connectionsOrder', []) as SidebarElement[]
}),
getters: {
+ getConnectionByUid: state => (uid:string) => state.connections.find(connection => connection.uid === uid),
getConnectionName: state => (uid: string) => {
- const connection = state.connections.filter(connection => connection.uid === uid)[0];
+ const connection = state.connections.find(connection => connection.uid === uid);
let connectionName = '';
+ if (connection) {
+ if (connection.name)
+ connectionName = connection.name;
+ else if (connection.ask)
+ connectionName = `${connection.host}:${connection.port}`;
+ else if (connection.databasePath) {
+ let string = connection.databasePath.split(/[/\\]+/).pop();
- if (connection.name)
- connectionName = connection.name;
- else if (connection.ask)
- connectionName = `${connection.host}:${connection.port}`;
- else if (connection.databasePath) {
- let string = connection.databasePath.split(/[/\\]+/).pop();
+ if (string.length >= 30)
+ string = `...${string.slice(-30)}`;
- if (string.length >= 30)
- string = `...${string.slice(-30)}`;
-
- connectionName = string;
+ connectionName = string;
+ }
+ else
+ connectionName = `${connection.user + '@'}${connection.host}:${connection.port}`;
}
- else
- connectionName = `${connection.user + '@'}${connection.host}:${connection.port}`;
return connectionName;
- }
+ },
+ getConnectionsOrder: state => {
+ if (state.connectionsOrder.length)
+ return state.connectionsOrder;
+ else {
+ const connectionsOrder = state.connections.map(conn => {
+ return {
+ isFolder: false,
+ uid: conn.uid,
+ client: conn.client
+ };
+ });
+ persistentStore.set('connectionsOrder', connectionsOrder);
+ return connectionsOrder;
+ }
+ },
+ getFolders: state => state.connectionsOrder.filter(conn => conn.isFolder)
},
actions: {
addConnection (connection: ConnectionParams) {
this.connections.push(connection);
persistentStore.set('connections', this.connections);
+
+ this.connectionsOrder.push({
+ isFolder: false,
+ uid: connection.uid,
+ client: connection.client
+ });
+ persistentStore.set('connectionsOrder', this.connectionsOrder);
},
- deleteConnection (connection: ConnectionParams) {
- this.connections = (this.connections as ConnectionParams[]).filter(el => el.uid !== connection.uid);
+ addFolder (params: {after: string; connections: [string, string]}) {
+ const index = this.connectionsOrder.findIndex((conn: SidebarElement) => conn.uid === params.after);
+ this.connectionsOrder.splice(index, 0, {
+ isFolder: true,
+ uid: uidGen('F'),
+ name: '',
+ color: 'orange',
+ connections: params.connections
+ });
+ persistentStore.set('connectionsOrder', this.connectionsOrder);
+ },
+ deleteConnection (connection: SidebarElement | ConnectionParams) {
+ this.connections = (this.connections as SidebarElement[]).filter(el => el.uid !== connection.uid);
persistentStore.set('connections', this.connections);
- (this.pinnedConnections as Set).delete(connection.uid);
- persistentStore.set('pinnedConnections', [...this.pinnedConnections]);
+
+ this.connectionsOrder = (this.connectionsOrder as SidebarElement[]).filter(el => el.uid !== connection.uid);
+ console.log(connection.uid, this.connectionsOrder);
+ persistentStore.set('connectionsOrder', this.connectionsOrder);
},
editConnection (connection: ConnectionParams) {
const editedConnections = (this.connections as ConnectionParams[]).map(conn => {
@@ -68,17 +116,9 @@ export const useConnectionsStore = defineStore('connections', {
this.connections = connections;
persistentStore.set('connections', this.connections);
},
- updatePinnedConnections (pinned: string[]) {
- this.pinnedConnections = new Set(pinned);
- persistentStore.set('pinnedConnections', [...this.pinnedConnections]);
- },
- pinConnection (uid: string) {
- (this.pinnedConnections as Set).add(uid);
- persistentStore.set('pinnedConnections', [...this.pinnedConnections]);
- },
- unpinConnection (uid: string) {
- (this.pinnedConnections as Set).delete(uid);
- persistentStore.set('pinnedConnections', [...this.pinnedConnections]);
+ updateConnectionsOrder (connections: SidebarElement[]) {
+ this.connectionsOrder = connections;
+ persistentStore.set('connectionsOrder', this.connectionsOrder);
},
updateLastConnection (uid: string) {
const cIndex = (this.lastConnections as {uid: string; time: number}[]).findIndex((c) => c.uid === uid);