fix(zookeeper): open new queries in key browser
This commit is contained in:
parent
badb3b61b9
commit
efe883f0d8
|
|
@ -1131,6 +1131,28 @@ async function newQuery() {
|
|||
const conn = connectionStore.getConfig(target.connectionId);
|
||||
if (!conn) return;
|
||||
connectionStore.activeConnectionId = target.connectionId;
|
||||
const connectionTarget = quickConnectionOpenTarget(conn);
|
||||
if (connectionTarget.kind !== "query") {
|
||||
try {
|
||||
await connectionStore.ensureConnected(target.connectionId);
|
||||
if (connectionTarget.kind === "mq-admin") {
|
||||
queryStore.openMqAdmin(target.connectionId);
|
||||
} else if (connectionTarget.kind === "nacos-admin") {
|
||||
await connectionStore.loadNacosNamespaces(target.connectionId);
|
||||
queryStore.openNacosAdmin(target.connectionId);
|
||||
} else {
|
||||
queryStore.createTab(target.connectionId, "", `${conn.name}:keys`, connectionTarget.kind);
|
||||
}
|
||||
} catch (e: any) {
|
||||
toast(
|
||||
t("connection.connectFailed", {
|
||||
message: translateBackendError(t, e?.message || String(e)),
|
||||
}),
|
||||
5000,
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Prefill the editor with `SELECT * FROM <focused table>` when enabled and a
|
||||
// table context (active data/structure tab or selected table node) is available.
|
||||
// Built before createTab so the tab opens with the content directly (no flash).
|
||||
|
|
@ -1183,6 +1205,20 @@ async function openConnectionQuery(connectionId: string) {
|
|||
}
|
||||
return;
|
||||
}
|
||||
if (initialTarget.kind === "etcd" || initialTarget.kind === "zookeeper") {
|
||||
try {
|
||||
await connectionStore.ensureConnected(connectionId);
|
||||
queryStore.createTab(connectionId, "", `${connection.name}:keys`, initialTarget.kind);
|
||||
} catch (e: any) {
|
||||
toast(
|
||||
t("connection.connectFailed", {
|
||||
message: translateBackendError(t, e?.message || String(e)),
|
||||
}),
|
||||
5000,
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
const tabId = queryStore.createTab(connectionId, initialTarget.database);
|
||||
try {
|
||||
await connectionStore.ensureConnected(connectionId);
|
||||
|
|
|
|||
|
|
@ -28,6 +28,14 @@ describe("quickConnectionOpenTarget", () => {
|
|||
expect(quickConnectionOpenTarget(connection("nacos"))).toEqual({ kind: "nacos-admin" });
|
||||
});
|
||||
|
||||
it("opens Etcd connections in the key browser", () => {
|
||||
expect(quickConnectionOpenTarget(connection("etcd"))).toEqual({ kind: "etcd" });
|
||||
});
|
||||
|
||||
it("opens ZooKeeper connections in the key browser", () => {
|
||||
expect(quickConnectionOpenTarget(connection("zookeeper"))).toEqual({ kind: "zookeeper" });
|
||||
});
|
||||
|
||||
it("opens regular connections in a query tab", () => {
|
||||
expect(quickConnectionOpenTarget({ ...connection("postgresql"), database: "app" })).toEqual({
|
||||
kind: "query",
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import type { ConnectionConfig } from "@/types/database";
|
||||
import { resolveDefaultDatabase } from "@/lib/database/defaultDatabase";
|
||||
|
||||
export type QuickConnectionOpenTarget = { kind: "mq-admin" } | { kind: "nacos-admin" } | { kind: "query"; database: string };
|
||||
export type QuickConnectionOpenTarget = { kind: "mq-admin" } | { kind: "nacos-admin" } | { kind: "etcd" } | { kind: "zookeeper" } | { kind: "query"; database: string };
|
||||
|
||||
export function quickConnectionOpenTarget(connection: Pick<ConnectionConfig, "db_type" | "database">, databaseOptions: string[] = []): QuickConnectionOpenTarget {
|
||||
if (connection.db_type === "mq") {
|
||||
|
|
@ -10,5 +10,11 @@ export function quickConnectionOpenTarget(connection: Pick<ConnectionConfig, "db
|
|||
if (connection.db_type === "nacos") {
|
||||
return { kind: "nacos-admin" };
|
||||
}
|
||||
if (connection.db_type === "etcd") {
|
||||
return { kind: "etcd" };
|
||||
}
|
||||
if (connection.db_type === "zookeeper") {
|
||||
return { kind: "zookeeper" };
|
||||
}
|
||||
return { kind: "query", database: resolveDefaultDatabase(connection, databaseOptions) };
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue