feat(editor): filter schema selector options
This commit is contained in:
1 parent
35af7ac721
commit
15546387db
2 files changed
+32
-2
No files matched your search
@@ -1,12 +1,18 @@
|
|||||||
import { ref } from "vue";
|
import { ref } from "vue";
|
||||||
import { useConnectionStore } from "@/stores/connectionStore";
|
import { useConnectionStore } from "@/stores/connectionStore";
|
||||||
import { isSchemaAware as isSchemaAwareType, isSingleDatabase, usesTreeSchemaMode } from "@/lib/databaseCapabilities";
|
import { isSchemaAware as isSchemaAwareType, isSingleDatabase, usesTreeSchemaMode } from "@/lib/databaseCapabilities";
|
||||||
|
import { filterDatabaseNamesForConnection } from "@/lib/visibleDatabases";
|
||||||
|
import type { ConnectionConfig } from "@/types/database";
|
||||||
import * as api from "@/lib/api";
|
import * as api from "@/lib/api";
|
||||||
|
|
||||||
export function hasSchemaOptionsCacheEntry(options: Record<string, string[]>, key: string): boolean {
|
export function hasSchemaOptionsCacheEntry(options: Record<string, string[]>, key: string): boolean {
|
||||||
return Object.prototype.hasOwnProperty.call(options, key);
|
return Object.prototype.hasOwnProperty.call(options, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function schemaOptionsForConnection(schemaNames: string[], connection: Pick<ConnectionConfig, "db_type" | "driver_profile" | "visible_databases"> | undefined): string[] {
|
||||||
|
return filterDatabaseNamesForConnection(schemaNames, connection);
|
||||||
|
}
|
||||||
|
|
||||||
export function useSchemaOptions() {
|
export function useSchemaOptions() {
|
||||||
const connectionStore = useConnectionStore();
|
const connectionStore = useConnectionStore();
|
||||||
|
|
||||||
@@ -23,7 +29,8 @@ export function useSchemaOptions() {
|
|||||||
|
|
||||||
async function loadSchemaOptions(connectionId: string, database: string) {
|
async function loadSchemaOptions(connectionId: string, database: string) {
|
||||||
if (!isSchemaAware(connectionId)) return;
|
if (!isSchemaAware(connectionId)) return;
|
||||||
const dbType = connectionStore.getConfig(connectionId)?.db_type;
|
const connection = connectionStore.getConfig(connectionId);
|
||||||
|
const dbType = connection?.db_type;
|
||||||
if (!database && !isSingleDatabase(dbType) && !usesTreeSchemaMode(dbType)) return;
|
if (!database && !isSingleDatabase(dbType) && !usesTreeSchemaMode(dbType)) return;
|
||||||
const key = cacheKey(connectionId, database);
|
const key = cacheKey(connectionId, database);
|
||||||
if (hasSchemaOptionsCacheEntry(schemaOptions.value, key)) return;
|
if (hasSchemaOptionsCacheEntry(schemaOptions.value, key)) return;
|
||||||
@@ -32,7 +39,7 @@ export function useSchemaOptions() {
|
|||||||
loadingSchemaOptions.value[key] = true;
|
loadingSchemaOptions.value[key] = true;
|
||||||
try {
|
try {
|
||||||
await connectionStore.ensureConnected(connectionId);
|
await connectionStore.ensureConnected(connectionId);
|
||||||
schemaOptions.value[key] = await api.listSchemas(connectionId, database);
|
schemaOptions.value[key] = schemaOptionsForConnection(await api.listSchemas(connectionId, database), connection);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
schemaOptions.value[key] = [];
|
schemaOptions.value[key] = [];
|
||||||
throw e;
|
throw e;
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
import assert from "node:assert/strict";
|
||||||
|
import { test } from "vitest";
|
||||||
|
import { schemaOptionsForConnection } from "../../apps/desktop/src/composables/useSchemaOptions.ts";
|
||||||
|
|
||||||
|
test("schema options respect Oracle visible database filters", () => {
|
||||||
|
assert.deepEqual(
|
||||||
|
schemaOptionsForConnection(["CAM", "00010", "00012", "SYS"], {
|
||||||
|
db_type: "oracle",
|
||||||
|
visible_databases: ["CAM", "00010"],
|
||||||
|
}),
|
||||||
|
["CAM", "00010"],
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("schema options keep default system-schema filtering without explicit filters", () => {
|
||||||
|
assert.deepEqual(
|
||||||
|
schemaOptionsForConnection(["CAM", "SYS", "SYSTEM"], {
|
||||||
|
db_type: "oracle",
|
||||||
|
visible_databases: undefined,
|
||||||
|
}),
|
||||||
|
["CAM"],
|
||||||
|
);
|
||||||
|
});
|
||||||
Reference in new issue
Block a user