feat(editor): filter schema selector options
This commit is contained in:
@@ -1,12 +1,18 @@
|
||||
import { ref } from "vue";
|
||||
import { useConnectionStore } from "@/stores/connectionStore";
|
||||
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";
|
||||
|
||||
export function hasSchemaOptionsCacheEntry(options: Record<string, string[]>, key: string): boolean {
|
||||
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() {
|
||||
const connectionStore = useConnectionStore();
|
||||
|
||||
@@ -23,7 +29,8 @@ export function useSchemaOptions() {
|
||||
|
||||
async function loadSchemaOptions(connectionId: string, database: string) {
|
||||
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;
|
||||
const key = cacheKey(connectionId, database);
|
||||
if (hasSchemaOptionsCacheEntry(schemaOptions.value, key)) return;
|
||||
@@ -32,7 +39,7 @@ export function useSchemaOptions() {
|
||||
loadingSchemaOptions.value[key] = true;
|
||||
try {
|
||||
await connectionStore.ensureConnected(connectionId);
|
||||
schemaOptions.value[key] = await api.listSchemas(connectionId, database);
|
||||
schemaOptions.value[key] = schemaOptionsForConnection(await api.listSchemas(connectionId, database), connection);
|
||||
} catch (e) {
|
||||
schemaOptions.value[key] = [];
|
||||
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