feat(connection): add connection attempt cancellation
This commit is contained in:
16 files changed
+681
-51
No files matched your search
@@ -16,7 +16,7 @@ import { Switch } from "@/components/ui/switch";
|
||||
import type { ConnectionConfig, DatabaseType, HttpTunnelConfig, JdbcDriverInfo, JdbcMavenBundleInfo, ProxyTunnelConfig, SshTunnelConfig, TransportLayerConfig } from "@/types/database";
|
||||
import type { MqAdminConfig, MqAuth, MqSystemKind } from "@/types/mq";
|
||||
import type { NacosAdminConfig, NacosAuthConfig } from "@/types/nacos";
|
||||
import { useConnectionStore } from "@/stores/connectionStore";
|
||||
import { CONNECTION_ATTEMPT_CANCELLED_MESSAGE, useConnectionStore } from "@/stores/connectionStore";
|
||||
import { REDIS_SCAN_PAGE_SIZE_DEFAULT, REDIS_SCAN_PAGE_SIZE_MIN, REDIS_SCAN_PAGE_SIZE_MAX, REDIS_SCAN_PAGE_SIZE_OPTIONS } from "@/lib/redis/redisKeyPattern";
|
||||
import { useSettingsStore } from "@/stores/settingsStore";
|
||||
import { useToast } from "@/composables/useToast";
|
||||
@@ -2991,8 +2991,10 @@ async function save() {
|
||||
emit("connectSucceeded", config.name);
|
||||
})
|
||||
.catch((e: any) => {
|
||||
const message = String(e?.message || e);
|
||||
if (message.includes(CONNECTION_ATTEMPT_CANCELLED_MESSAGE)) return;
|
||||
if (config.one_time) void store.removeConnection(config.id);
|
||||
emit("connectFailed", mongodbAuthFailureHint(String(e?.message || e)));
|
||||
emit("connectFailed", mongodbAuthFailureHint(message));
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -58,9 +58,10 @@ import {
|
||||
Info,
|
||||
Archive,
|
||||
Square,
|
||||
X,
|
||||
} from "@lucide/vue";
|
||||
import CustomContextMenu from "@/components/ui/CustomContextMenu.vue";
|
||||
import { useConnectionStore } from "@/stores/connectionStore";
|
||||
import { CONNECTION_ATTEMPT_CANCELLED_MESSAGE, useConnectionStore } from "@/stores/connectionStore";
|
||||
import { useQueryStore } from "@/stores/queryStore";
|
||||
import { useSettingsStore } from "@/stores/settingsStore";
|
||||
import { useSavedSqlStore } from "@/stores/savedSqlStore";
|
||||
@@ -512,8 +513,7 @@ function isTooltipDisabled(): boolean {
|
||||
async function toggle() {
|
||||
const node = props.node;
|
||||
if (node.isLoading) {
|
||||
if (node.type !== "connection") return;
|
||||
node.isLoading = false;
|
||||
return;
|
||||
}
|
||||
emit("search-toggle", node);
|
||||
const wasExpanded = !!node.isExpanded;
|
||||
@@ -651,6 +651,7 @@ async function toggle() {
|
||||
} catch (e: any) {
|
||||
if (!wasExpanded) node.isExpanded = false;
|
||||
const errMsg = e?.message || String(e);
|
||||
if (errMsg.includes(CONNECTION_ATTEMPT_CANCELLED_MESSAGE)) return;
|
||||
toast(t("connection.connectFailed", { message: translateBackendError(t, errMsg) }), 5000);
|
||||
if (errMsg.includes("driver is not installed") || errMsg.includes("is not installed")) {
|
||||
window.dispatchEvent(new Event("dbx-open-driver-store"));
|
||||
@@ -3469,6 +3470,16 @@ async function disconnectConnection() {
|
||||
}
|
||||
}
|
||||
|
||||
async function cancelConnectionAttempt() {
|
||||
if (!props.node.connectionId) return;
|
||||
try {
|
||||
const cancelled = await connectionStore.cancelConnecting(props.node.connectionId);
|
||||
if (cancelled) toast(t("connection.connectCancelled"), 2000);
|
||||
} catch (e: any) {
|
||||
toast(t("connection.saveFailed", { message: e?.message || String(e) }), 5000);
|
||||
}
|
||||
}
|
||||
|
||||
async function closeDatabaseConnection() {
|
||||
const node = props.node;
|
||||
if (node.type !== "database" || !node.connectionId || node.database == null) return;
|
||||
@@ -3640,6 +3651,7 @@ const tableComment = computed(() =>
|
||||
);
|
||||
const paddingLeft = computed(() => treeItemPaddingLeft(props.depth));
|
||||
const isConnected = computed(() => props.node.type === "connection" && !!props.node.connectionId && connectionStore.connectedIds.has(props.node.connectionId));
|
||||
const isConnecting = computed(() => props.node.type === "connection" && !!props.node.connectionId && connectionStore.connectingIds.has(props.node.connectionId));
|
||||
const isConnectionReadonly = computed(() => props.node.type === "connection" && !!props.node.connectionId && (connectionStore.getConfig(props.node.connectionId)?.read_only ?? false));
|
||||
const isOpenedDatabase = computed(() => isSidebarDatabaseOpened(props.node, connectionStore.isTreeNodeChildrenLoaded));
|
||||
const showsDatabaseOpenIndicator = computed(() => props.node.type === "database" && (isOpenedDatabase.value || (!!props.node.connectionId && props.node.database != null && queryStore.isDatabaseOpen(props.node.connectionId, props.node.database))));
|
||||
@@ -4095,7 +4107,9 @@ function treeItemMenuItems(): ContextMenuItem[] {
|
||||
|
||||
// 2. Connection
|
||||
if (node.type === "connection") {
|
||||
if (!isConnected.value) {
|
||||
if (isConnecting.value) {
|
||||
items.push({ label: t("connection.cancelConnecting"), action: cancelConnectionAttempt, icon: X });
|
||||
} else if (!isConnected.value) {
|
||||
items.push({ label: t("contextMenu.openConnection"), action: toggle, icon: Plug });
|
||||
} else {
|
||||
items.push({ label: t("contextMenu.closeConnection"), action: disconnectConnection, icon: Unplug });
|
||||
@@ -4712,11 +4726,22 @@ function treeItemMenuItems(): ContextMenuItem[] {
|
||||
<Badge v-if="isConnectionReadonly" variant="secondary" class="h-4 px-1.5 text-[10px] gap-0.5"><Lock class="w-2.5 h-2.5" />{{ t("connection.readOnlyBadge") }}</Badge>
|
||||
<ConnectionErrorIndicator v-if="node.type === 'connection'" :connection-id="node.connectionId" trigger-class="h-4 w-4" />
|
||||
<Pin v-if="isPinned" class="w-3 h-3 shrink-0 text-primary fill-current" aria-hidden="true" />
|
||||
<button
|
||||
v-if="isConnecting"
|
||||
type="button"
|
||||
class="ml-auto flex h-4 w-4 shrink-0 items-center justify-center rounded text-muted-foreground transition-colors hover:bg-secondary/45 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||
:aria-label="t('connection.cancelConnecting')"
|
||||
:title="t('connection.cancelConnecting')"
|
||||
@mousedown.stop
|
||||
@click.stop="cancelConnectionAttempt"
|
||||
>
|
||||
<X class="h-3 w-3" />
|
||||
</button>
|
||||
<button
|
||||
v-if="node.type === 'connection'"
|
||||
type="button"
|
||||
class="ml-auto flex h-4 w-4 shrink-0 items-center justify-center rounded text-muted-foreground/55 opacity-0 transition-colors transition-opacity hover:bg-secondary/45 hover:text-foreground focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring group-hover/sidebar-row:opacity-100"
|
||||
:class="{ 'opacity-100': isConnectionSelectionChecked || connectionStore.connectionMultiSelectActive }"
|
||||
class="flex h-4 w-4 shrink-0 items-center justify-center rounded text-muted-foreground/55 opacity-0 transition-colors transition-opacity hover:bg-secondary/45 hover:text-foreground focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring group-hover/sidebar-row:opacity-100"
|
||||
:class="[{ 'opacity-100': isConnectionSelectionChecked || connectionStore.connectionMultiSelectActive }, isConnecting ? '' : 'ml-auto']"
|
||||
:aria-label="isConnectionSelectionChecked ? t('connectionGroup.deselectConnection') : t('connectionGroup.selectConnection')"
|
||||
@mousedown.stop
|
||||
@click="toggleConnectionMultiSelection"
|
||||
|
||||
Reference in new issue
Block a user