feat(connection): add visible schema filtering
This commit is contained in:
@@ -36,7 +36,9 @@ import { prestoSqlBuiltinDriverPaths } from "@/lib/prestoSqlBuiltinDriver";
|
||||
import { SQLITE_DATABASE_FILE_EXTENSIONS } from "@/lib/databaseFileDetection";
|
||||
import { ArrowLeft, ArrowDown, ArrowUp, CheckSquare, ChevronRight, CircleHelp, Copy, ExternalLink, FilePlus2, FolderOpen, GripVertical, Grid3X3, KeyRound, Link2, List, ListFilter, Loader2, Pipette, Plus, Search, ShieldCheck, Square, Trash2 } from "@lucide/vue";
|
||||
import { buildDraftVisibleDatabasesConnectionId, connectionCanChooseVisibleDatabases, initialVisibleDatabaseSelection, visibleDatabaseSelectionIsStale } from "@/lib/connectionVisibleDatabases";
|
||||
import { canSaveVisibleDatabaseSelection, filterDatabaseNamesForConnection, isSystemDatabaseName, normalizeVisibleDatabaseSelection } from "@/lib/visibleDatabases";
|
||||
import { canSaveVisibleDatabaseSelection, filterDatabaseNamesForConnection, isSystemDatabaseName, normalizeVisibleDatabaseSelection, buildDraftVisibleSchemasConnectionId } from "@/lib/visibleDatabases";
|
||||
import { isSchemaAware } from "@/lib/databaseFeatureSupport";
|
||||
import VisibleSchemasDialog from "@/components/sidebar/VisibleSchemasDialog.vue";
|
||||
|
||||
type DbOption = { value: string; label: string };
|
||||
type DbCategory = { key: string; title: string; options: DbOption[] };
|
||||
@@ -106,6 +108,11 @@ const visibleDatabaseSelection = ref<Set<string>>(new Set());
|
||||
const visibleDatabaseSearchText = ref("");
|
||||
const visibleDatabaseError = ref("");
|
||||
const visibleDatabaseShowSystem = ref(false);
|
||||
const showVisibleSchemasDialog = ref(false);
|
||||
const isLoadingVisibleSchemas = ref(false);
|
||||
const visibleSchemaNames = ref<string[]>([]);
|
||||
const visibleSchemaInitialSelection = ref<string[]>([]);
|
||||
const visibleSchemaError = ref("");
|
||||
let testRunId = 0;
|
||||
|
||||
const defaultForm = (): ConnectionForm => ({
|
||||
@@ -980,6 +987,7 @@ function onDbTypeChange(val: string) {
|
||||
customDriverName.value = "";
|
||||
applyProfile(val, !!editingId.value);
|
||||
resetTestState();
|
||||
resetVisibleSchemasState();
|
||||
}
|
||||
|
||||
function switchH2ConnectionMode(mode: H2ConnectionMode) {
|
||||
@@ -1296,6 +1304,18 @@ const visibleDatabaseHasSystemDatabases = computed(() => {
|
||||
const connection = connectionConfigSnapshotForVisibleDatabases();
|
||||
return visibleDatabaseNames.value.some((database) => isSystemDatabaseName(connection.db_type, database));
|
||||
});
|
||||
const canChooseVisibleSchemas = computed(() => isSchemaAware(form.value.db_type));
|
||||
const visibleSchemasDatabaseKey = computed(() => form.value.database || "");
|
||||
const hasVisibleSchemaFilter = computed(() => {
|
||||
const key = visibleSchemasDatabaseKey.value;
|
||||
return Array.isArray(form.value.visible_schemas?.[key]);
|
||||
});
|
||||
const visibleSchemaSummary = computed(() => {
|
||||
const key = visibleSchemasDatabaseKey.value;
|
||||
const configured = form.value.visible_schemas?.[key];
|
||||
if (!configured?.length) return t("visibleSchemas.showAll");
|
||||
return t("visibleSchemas.selectedCount", { selected: configured.length, total: visibleSchemaNames.value.length });
|
||||
});
|
||||
const testResultMessage = computed(() => {
|
||||
if (!testResult.value) return "";
|
||||
return testResult.value.ok ? t("connection.testSuccess") : testResult.value.message;
|
||||
@@ -1607,6 +1627,7 @@ function connectionConfigForSubmit(id: string): ConnectionConfig {
|
||||
delete legacy.proxy_username;
|
||||
delete legacy.proxy_password;
|
||||
config.visible_databases = Array.isArray(config.visible_databases) && config.visible_databases.length > 0 ? config.visible_databases : undefined;
|
||||
if (config.visible_schemas && Object.keys(config.visible_schemas).length === 0) config.visible_schemas = undefined;
|
||||
return config as ConnectionConfig;
|
||||
}
|
||||
|
||||
@@ -1929,6 +1950,57 @@ function saveVisibleDatabaseSelection() {
|
||||
showVisibleDatabasesDialog.value = false;
|
||||
}
|
||||
|
||||
function resetVisibleSchemasState() {
|
||||
showVisibleSchemasDialog.value = false;
|
||||
isLoadingVisibleSchemas.value = false;
|
||||
visibleSchemaNames.value = [];
|
||||
visibleSchemaInitialSelection.value = [];
|
||||
visibleSchemaError.value = "";
|
||||
}
|
||||
|
||||
async function openVisibleSchemasPicker() {
|
||||
if (!ensureConnectionHostResolvedFromUrl()) return;
|
||||
if (!canChooseVisibleSchemas.value || isLoadingVisibleSchemas.value) return;
|
||||
isLoadingVisibleSchemas.value = true;
|
||||
visibleSchemaError.value = "";
|
||||
const draftId = buildDraftVisibleSchemasConnectionId(uuid());
|
||||
try {
|
||||
const draftConfig: ConnectionConfig = {
|
||||
...connectionConfigForSubmit(draftId),
|
||||
id: draftId,
|
||||
};
|
||||
await store.addEphemeralConnection(draftConfig);
|
||||
await store.ensureConnected(draftId);
|
||||
const names = await api.listSchemas(draftId, visibleSchemasDatabaseKey.value);
|
||||
visibleSchemaNames.value = names;
|
||||
const key = visibleSchemasDatabaseKey.value;
|
||||
const configured = form.value.visible_schemas?.[key];
|
||||
visibleSchemaInitialSelection.value = Array.isArray(configured) ? configured : [];
|
||||
showVisibleSchemasDialog.value = true;
|
||||
} catch (e: any) {
|
||||
visibleSchemaNames.value = [];
|
||||
visibleSchemaInitialSelection.value = [];
|
||||
visibleSchemaError.value = String(e?.message || e);
|
||||
} finally {
|
||||
isLoadingVisibleSchemas.value = false;
|
||||
store.removeConnection(draftId).catch(() => {});
|
||||
}
|
||||
}
|
||||
|
||||
function handleDraftSchemasSave(selectedNames: string[]) {
|
||||
const key = visibleSchemasDatabaseKey.value;
|
||||
form.value.visible_schemas = { ...(form.value.visible_schemas || {}), [key]: selectedNames };
|
||||
}
|
||||
|
||||
function handleDraftSchemasShowAll() {
|
||||
const key = visibleSchemasDatabaseKey.value;
|
||||
if (form.value.visible_schemas) {
|
||||
const next = { ...form.value.visible_schemas };
|
||||
delete next[key];
|
||||
form.value.visible_schemas = Object.keys(next).length > 0 ? next : undefined;
|
||||
}
|
||||
}
|
||||
|
||||
function applyConnectionUrl() {
|
||||
if (applyConnectionUrlToForm(connectionUrlInput.value)) {
|
||||
toast(t("connection.parseConnectionUrlApplied"), 2000);
|
||||
@@ -1963,6 +2035,7 @@ function resetForm() {
|
||||
dbSearchQuery.value = "";
|
||||
configTab.value = "connection";
|
||||
resetVisibleDatabaseDraftState();
|
||||
resetVisibleSchemasState();
|
||||
resetTestState();
|
||||
}
|
||||
|
||||
@@ -3896,6 +3969,11 @@ function openExternalUrl(url: string) {
|
||||
<ListFilter v-else class="mr-1.5 h-4 w-4" />
|
||||
{{ hasVisibleDatabaseFilter ? visibleDatabaseSummary : t("contextMenu.selectVisibleDatabases") }}
|
||||
</Button>
|
||||
<Button v-if="canChooseVisibleSchemas" variant="outline" class="shrink-0" :disabled="isTesting || isSaving || isLoadingVisibleSchemas || !hasRequiredConnectionTarget" @click="openVisibleSchemasPicker">
|
||||
<Loader2 v-if="isLoadingVisibleSchemas" class="mr-1.5 h-4 w-4 animate-spin" />
|
||||
<ListFilter v-else class="mr-1.5 h-4 w-4" />
|
||||
{{ hasVisibleSchemaFilter ? visibleSchemaSummary : t("visibleSchemas.showAll") }}
|
||||
</Button>
|
||||
<Button variant="outline" class="shrink-0" :disabled="isTesting || isSaving" @click="testConnection">
|
||||
{{ isTesting ? t("connection.testing") : t("connection.test") }}
|
||||
</Button>
|
||||
@@ -3985,4 +4063,18 @@ function openExternalUrl(url: string) {
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
<VisibleSchemasDialog
|
||||
v-model:open="showVisibleSchemasDialog"
|
||||
draft-mode
|
||||
:connection-id="''"
|
||||
:connection-name="form.name || selectedProfile().label"
|
||||
:database="visibleSchemasDatabaseKey"
|
||||
:draft-schema-names="visibleSchemaNames"
|
||||
:draft-initial-selection="visibleSchemaInitialSelection"
|
||||
:draft-loading="isLoadingVisibleSchemas"
|
||||
:draft-error="visibleSchemaError"
|
||||
@draft:save="handleDraftSchemasSave"
|
||||
@draft:show-all="handleDraftSchemasShowAll"
|
||||
/>
|
||||
</template>
|
||||
|
||||
@@ -121,7 +121,9 @@ import { rankSavedSqlHistory, type SavedSqlHistoryScope } from "@/lib/savedSqlHi
|
||||
import { isSqlServerLinkedNode } from "@/lib/sqlServerLinkedServers";
|
||||
import DatabaseIcon from "@/components/icons/DatabaseIcon.vue";
|
||||
import ConnectionErrorIndicator from "@/components/connection/ConnectionErrorIndicator.vue";
|
||||
import { isSchemaAware } from "@/lib/databaseFeatureSupport";
|
||||
import VisibleDatabasesDialog from "@/components/sidebar/VisibleDatabasesDialog.vue";
|
||||
import SchemaFilterDialog from "@/components/sidebar/VisibleSchemasDialog.vue";
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from "@/components/ui/dialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
@@ -153,6 +155,7 @@ type DuplicateStructureSource = TreeNode & { connectionId: string; database: str
|
||||
const DATA_TAB_METADATA_TTL_MS = 30_000;
|
||||
const { getDatabaseOptions } = useDatabaseOptions();
|
||||
const showVisibleDatabasesDialog = ref(false);
|
||||
const showVisibleSchemasDialog = ref(false);
|
||||
const { addTask: addExportTask } = useExportTracker();
|
||||
|
||||
const props = defineProps<{
|
||||
@@ -3065,11 +3068,25 @@ const nodeIconClass = computed(() => {
|
||||
if (props.node.type !== "database") return infoClass;
|
||||
return canCloseDatabaseConnection.value ? infoClass : "text-muted-foreground/65";
|
||||
});
|
||||
|
||||
const canConfigureVisibleDatabases = computed(() => {
|
||||
if (props.node.type !== "connection" || !props.node.connectionId) return false;
|
||||
const dbType = connectionStore.getConfig(props.node.connectionId)?.db_type;
|
||||
return dbType !== "elasticsearch" && dbType !== "qdrant" && dbType !== "milvus" && dbType !== "weaviate" && dbType !== "etcd" && dbType !== "mq" && dbType !== "nacos";
|
||||
});
|
||||
|
||||
const canConfigureVisibleSchemas = computed(() => {
|
||||
if (props.node.type === "database" && props.node.connectionId && props.node.database != null) {
|
||||
const dbType = connectionStore.getConfig(props.node.connectionId)?.db_type;
|
||||
return isSchemaAware(dbType);
|
||||
}
|
||||
if (props.node.type === "connection" && props.node.connectionId) {
|
||||
const dbType = connectionStore.getConfig(props.node.connectionId)?.db_type;
|
||||
return isSchemaAware(dbType) && !usesTreeSchemaMode(dbType);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
const canCopyFinalProxyPort = computed(() => {
|
||||
if (props.node.type !== "connection" || !props.node.connectionId) return false;
|
||||
return hasEnabledTransportLayers(connectionStore.getConfig(props.node.connectionId));
|
||||
@@ -3107,6 +3124,10 @@ function openVisibleDatabasesDialog() {
|
||||
showVisibleDatabasesDialog.value = true;
|
||||
}
|
||||
|
||||
function openVisibleSchemasDialog() {
|
||||
showVisibleSchemasDialog.value = true;
|
||||
}
|
||||
|
||||
// --- Connection Group Management ---
|
||||
const isRenamingGroup = ref(false);
|
||||
const renameInput = ref("");
|
||||
@@ -3521,6 +3542,13 @@ function treeItemMenuItems(): ContextMenuItem[] {
|
||||
icon: ListFilter,
|
||||
});
|
||||
}
|
||||
if (canConfigureVisibleSchemas.value) {
|
||||
items.push({
|
||||
label: t("visibleSchemas.title"),
|
||||
action: openVisibleSchemasDialog,
|
||||
icon: ListFilter,
|
||||
});
|
||||
}
|
||||
items.push({ label: t("contextMenu.editConnection"), action: editConnection, icon: Pencil });
|
||||
if (revealConnectionFilePath.value) {
|
||||
items.push({
|
||||
@@ -3613,6 +3641,13 @@ function treeItemMenuItems(): ContextMenuItem[] {
|
||||
icon: RefreshCw,
|
||||
shortcut: shortcutRefresh,
|
||||
});
|
||||
if (canConfigureVisibleSchemas.value) {
|
||||
items.push({
|
||||
label: t("visibleSchemas.title"),
|
||||
action: openVisibleSchemasDialog,
|
||||
icon: ListFilter,
|
||||
});
|
||||
}
|
||||
items.push({ label: "", separator: true });
|
||||
items.push({ label: t("transfer.dataTransfer"), action: openTransfer, icon: ArrowRightLeft });
|
||||
items.push({ label: t("diff.title"), action: openSchemaDiff, icon: ArrowRightLeft });
|
||||
@@ -4021,8 +4056,13 @@ function treeItemMenuItems(): ContextMenuItem[] {
|
||||
</LightTooltip>
|
||||
</div>
|
||||
</CustomContextMenu>
|
||||
|
||||
<VisibleDatabasesDialog v-if="node.type === 'connection' && node.connectionId" v-model:open="showVisibleDatabasesDialog" :connection-id="node.connectionId" :connection-name="node.label" />
|
||||
|
||||
<SchemaFilterDialog v-if="node.type === 'database' && node.connectionId && node.database != null" v-model:open="showVisibleSchemasDialog" :connection-id="node.connectionId" :connection-name="node.label" :database="node.database ?? ''" />
|
||||
|
||||
<SchemaFilterDialog v-else-if="node.type === 'connection' && node.connectionId && canConfigureVisibleSchemas" v-model:open="showVisibleSchemasDialog" :connection-id="node.connectionId" :connection-name="node.label" :database="connectionStore.getConfig(node.connectionId)?.database || ''" />
|
||||
|
||||
<Dialog v-model:open="showDeleteConfirm">
|
||||
<DialogContent class="sm:max-w-[400px]">
|
||||
<DialogHeader>
|
||||
|
||||
@@ -0,0 +1,235 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { CheckSquare, Loader2, Search, Square } from "@lucide/vue";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { useConnectionStore } from "@/stores/connectionStore";
|
||||
import { normalizeVisibleSchemaSelection } from "@/lib/visibleDatabases";
|
||||
import * as api from "@/lib/api";
|
||||
|
||||
const props = defineProps<{
|
||||
open: boolean;
|
||||
connectionId: string;
|
||||
connectionName: string;
|
||||
database: string;
|
||||
/** Draft mode: parent provides schemas/loading/error externally. Component emits events instead of calling store. */
|
||||
draftMode?: boolean;
|
||||
draftSchemaNames?: string[];
|
||||
draftInitialSelection?: string[];
|
||||
draftLoading?: boolean;
|
||||
draftError?: string;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
"update:open": [value: boolean];
|
||||
"draft:save": [selectedNames: string[]];
|
||||
"draft:showAll": [];
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
const connectionStore = useConnectionStore();
|
||||
|
||||
const schemaNames = ref<string[]>([]);
|
||||
const selectedNames = ref<Set<string>>(new Set());
|
||||
const searchText = ref("");
|
||||
const isLoading = ref(false);
|
||||
const errorMessage = ref("");
|
||||
|
||||
const isDraftMode = computed(() => props.draftMode);
|
||||
const isLoadingState = computed(() => (isDraftMode.value ? props.draftLoading : isLoading.value));
|
||||
const errorMessageState = computed(() => (isDraftMode.value ? props.draftError || "" : errorMessage.value));
|
||||
|
||||
const filteredSchemaNames = computed(() => {
|
||||
const query = searchText.value.trim().toLowerCase();
|
||||
const names = isDraftMode.value ? props.draftSchemaNames || [] : schemaNames.value;
|
||||
if (!query) return names;
|
||||
return names.filter((name) => name.toLowerCase().includes(query));
|
||||
});
|
||||
const selectedCount = computed(() => selectedNames.value.size);
|
||||
const totalCount = computed(() => {
|
||||
const names = isDraftMode.value ? props.draftSchemaNames || [] : schemaNames.value;
|
||||
return names.length;
|
||||
});
|
||||
const canSaveSelection = computed(() => selectedNames.value.size > 0);
|
||||
|
||||
watch(
|
||||
() => props.open,
|
||||
(open) => {
|
||||
if (!open) return;
|
||||
if (isDraftMode.value) {
|
||||
initDraftMode();
|
||||
} else {
|
||||
loadSchemas().catch(() => {});
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
function initDraftMode() {
|
||||
searchText.value = "";
|
||||
const names = props.draftSchemaNames || [];
|
||||
const configured = props.draftInitialSelection;
|
||||
if (configured && configured.length > 0) {
|
||||
const visibleSet = new Set(normalizeVisibleSchemaSelection(configured, names));
|
||||
selectedNames.value = new Set(names.filter((name) => visibleSet.has(name)));
|
||||
} else {
|
||||
selectedNames.value = new Set(names);
|
||||
}
|
||||
}
|
||||
|
||||
async function loadSchemas() {
|
||||
isLoading.value = true;
|
||||
errorMessage.value = "";
|
||||
searchText.value = "";
|
||||
try {
|
||||
const config = connectionStore.getConfig(props.connectionId);
|
||||
const database = props.database || config?.database || "";
|
||||
await connectionStore.ensureConnected(props.connectionId);
|
||||
const names = await api.listSchemas(props.connectionId, database);
|
||||
schemaNames.value = names;
|
||||
const configured = config?.visible_schemas?.[database || ""];
|
||||
if (Array.isArray(configured)) {
|
||||
const visibleSet = new Set(normalizeVisibleSchemaSelection(configured, names));
|
||||
selectedNames.value = new Set(names.filter((name) => visibleSet.has(name)));
|
||||
} else {
|
||||
selectedNames.value = new Set(names);
|
||||
}
|
||||
} catch (e: any) {
|
||||
schemaNames.value = [];
|
||||
selectedNames.value = new Set();
|
||||
errorMessage.value = String(e?.message || e);
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function toggleSchema(schema: string) {
|
||||
const next = new Set(selectedNames.value);
|
||||
if (next.has(schema)) next.delete(schema);
|
||||
else next.add(schema);
|
||||
selectedNames.value = next;
|
||||
}
|
||||
|
||||
const isSearching = computed(() => searchText.value.trim().length > 0);
|
||||
|
||||
function selectAll() {
|
||||
const names = isDraftMode.value ? props.draftSchemaNames || [] : schemaNames.value;
|
||||
selectedNames.value = new Set(names);
|
||||
}
|
||||
|
||||
function selectFiltered() {
|
||||
const next = new Set(selectedNames.value);
|
||||
for (const name of filteredSchemaNames.value) {
|
||||
next.add(name);
|
||||
}
|
||||
selectedNames.value = next;
|
||||
}
|
||||
|
||||
function clearSelection() {
|
||||
selectedNames.value = new Set();
|
||||
}
|
||||
|
||||
async function showAllSchemas() {
|
||||
if (isDraftMode.value) {
|
||||
selectedNames.value = new Set(props.draftSchemaNames || []);
|
||||
emit("draft:showAll");
|
||||
emit("update:open", false);
|
||||
return;
|
||||
}
|
||||
const config = connectionStore.getConfig(props.connectionId);
|
||||
const database = props.database || config?.database || "";
|
||||
if (config?.visible_schemas?.[database || ""]) {
|
||||
await connectionStore.clearVisibleSchemas(props.connectionId, database);
|
||||
}
|
||||
selectedNames.value = new Set(schemaNames.value);
|
||||
emit("update:open", false);
|
||||
}
|
||||
|
||||
async function saveSelection() {
|
||||
if (!canSaveSelection.value) return;
|
||||
const names = isDraftMode.value ? props.draftSchemaNames || [] : schemaNames.value;
|
||||
const normalized = normalizeVisibleSchemaSelection([...selectedNames.value], names);
|
||||
if (isDraftMode.value) {
|
||||
emit("draft:save", normalized);
|
||||
emit("update:open", false);
|
||||
return;
|
||||
}
|
||||
const config = connectionStore.getConfig(props.connectionId);
|
||||
const database = props.database || config?.database || "";
|
||||
await connectionStore.setVisibleSchemas(props.connectionId, database, normalized);
|
||||
emit("update:open", false);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Dialog :open="open" @update:open="(value: boolean) => emit('update:open', value)">
|
||||
<DialogContent class="sm:max-w-[460px]">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{{ t("visibleSchemas.title") }}</DialogTitle>
|
||||
<p class="text-sm text-muted-foreground">
|
||||
{{ t("visibleSchemas.description", { connection: connectionName }) }}
|
||||
</p>
|
||||
</DialogHeader>
|
||||
|
||||
<div class="flex items-center gap-2 rounded-md border bg-background px-2">
|
||||
<Search class="h-4 w-4 shrink-0 text-muted-foreground" />
|
||||
<Input v-model="searchText" :placeholder="t('visibleSchemas.searchPlaceholder')" class="h-8 border-0 px-0 shadow-none focus-visible:ring-0" :disabled="isLoadingState || !!errorMessageState" />
|
||||
</div>
|
||||
|
||||
<div class="flex items-center justify-between text-xs text-muted-foreground">
|
||||
<span>{{ t("visibleSchemas.selectedCount", { selected: selectedCount, total: totalCount }) }}</span>
|
||||
<div class="flex items-center gap-2">
|
||||
<button class="hover:text-foreground disabled:opacity-50" :disabled="isLoadingState" @click="selectAll">
|
||||
{{ t("visibleSchemas.selectAll") }}
|
||||
</button>
|
||||
<button v-if="isSearching" class="hover:text-foreground disabled:opacity-50" :disabled="isLoadingState" @click="selectFiltered">
|
||||
{{ t("visibleSchemas.selectFiltered") }}
|
||||
</button>
|
||||
<button class="hover:text-foreground disabled:opacity-50" :disabled="isLoadingState" @click="clearSelection">
|
||||
{{ t("visibleSchemas.clear") }}
|
||||
</button>
|
||||
<button class="hover:text-foreground disabled:opacity-50" :disabled="isLoadingState" @click="showAllSchemas">
|
||||
{{ t("visibleSchemas.showAll") }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<p v-if="!isLoadingState && !errorMessageState && !canSaveSelection" class="text-xs text-destructive">
|
||||
{{ t("visibleSchemas.emptySelection") }}
|
||||
</p>
|
||||
|
||||
<div class="h-72 overflow-y-auto rounded-md border bg-background/50 p-1">
|
||||
<div v-if="isLoadingState" class="flex h-full items-center justify-center gap-2 text-sm text-muted-foreground">
|
||||
<Loader2 class="h-4 w-4 animate-spin" />
|
||||
{{ t("common.loading") }}
|
||||
</div>
|
||||
<div v-else-if="errorMessageState" class="p-3 text-sm text-destructive">
|
||||
{{ t("visibleSchemas.loadFailed", { message: errorMessageState }) }}
|
||||
</div>
|
||||
<div v-else-if="!filteredSchemaNames.length" class="p-3 text-sm text-muted-foreground">
|
||||
{{ t("grid.noSearchResults") }}
|
||||
</div>
|
||||
<template v-else>
|
||||
<button
|
||||
v-for="schema in filteredSchemaNames"
|
||||
:key="schema"
|
||||
type="button"
|
||||
class="flex h-8 w-full min-w-0 items-center gap-2 rounded-sm px-2 text-left text-sm hover:bg-accent hover:text-accent-foreground focus-visible:bg-accent focus-visible:text-accent-foreground focus-visible:outline-none"
|
||||
@click="toggleSchema(schema)"
|
||||
>
|
||||
<CheckSquare v-if="selectedNames.has(schema)" class="h-4 w-4 shrink-0 text-primary" />
|
||||
<Square v-else class="h-4 w-4 shrink-0 text-muted-foreground" />
|
||||
<span class="truncate">{{ schema }}</span>
|
||||
</button>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<DialogFooter>
|
||||
<Button variant="outline" @click="emit('update:open', false)">{{ t("dangerDialog.cancel") }}</Button>
|
||||
<Button :disabled="isLoadingState || !!errorMessageState || !canSaveSelection" @click="saveSelection">
|
||||
{{ t("visibleSchemas.save") }}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</template>
|
||||
@@ -1334,6 +1334,19 @@ export default {
|
||||
emptySelection: "Select at least one database, or use Show all to clear the filter.",
|
||||
loadFailed: "Failed to load databases: {message}",
|
||||
},
|
||||
visibleSchemas: {
|
||||
title: "Schema Filter",
|
||||
description: 'Choose which schemas are shown under "{connection}".',
|
||||
searchPlaceholder: "Search schemas...",
|
||||
selectedCount: "{selected}/{total} selected",
|
||||
selectAll: "Select all",
|
||||
selectFiltered: "Select search results",
|
||||
clear: "Clear",
|
||||
showAll: "Show all",
|
||||
save: "Save",
|
||||
emptySelection: "Select at least one schema, or use Show all to clear the filter.",
|
||||
loadFailed: "Failed to load schemas: {message}",
|
||||
},
|
||||
tree: {
|
||||
savedSql: "SQL Library",
|
||||
userAdmin: "Users & Privileges",
|
||||
|
||||
@@ -1131,6 +1131,7 @@ export default {
|
||||
searchPlaceholder: "Buscar bases de datos...",
|
||||
selectedCount: "{selected}/{total} seleccionadas",
|
||||
selectAll: "Seleccionar todo",
|
||||
selectFiltered: "Seleccionar resultados de búsqueda",
|
||||
clear: "Limpiar",
|
||||
showAll: "Mostrar todo",
|
||||
showSystemDatabases: "Mostrar bases de datos del sistema",
|
||||
@@ -1138,6 +1139,19 @@ export default {
|
||||
emptySelection: "Selecciona al menos una base de datos, o usa Mostrar todo para quitar el filtro.",
|
||||
loadFailed: "No se pudieron cargar las bases de datos: {message}",
|
||||
},
|
||||
visibleSchemas: {
|
||||
title: "Filtro de Schema",
|
||||
description: 'Elige qué schemas se muestran bajo "{connection}".',
|
||||
searchPlaceholder: "Buscar schemas...",
|
||||
selectedCount: "{selected}/{total} seleccionados",
|
||||
selectAll: "Seleccionar todo",
|
||||
selectFiltered: "Seleccionar resultados de búsqueda",
|
||||
clear: "Limpiar",
|
||||
showAll: "Mostrar todo",
|
||||
save: "Guardar",
|
||||
emptySelection: "Selecciona al menos un schema, o usa Mostrar todo para quitar el filtro.",
|
||||
loadFailed: "No se pudieron cargar los schemas: {message}",
|
||||
},
|
||||
tree: {
|
||||
savedSql: "Biblioteca SQL",
|
||||
defaultDatabase: "Base predeterminada",
|
||||
|
||||
@@ -1255,6 +1255,7 @@ export default {
|
||||
searchPlaceholder: "Cerca database...",
|
||||
selectedCount: "{selected}/{total} selezionati",
|
||||
selectAll: "Seleziona tutto",
|
||||
selectFiltered: "Seleziona risultati ricerca",
|
||||
clear: "Cancella",
|
||||
showAll: "Mostra tutto",
|
||||
showSystemDatabases: "Mostra database di sistema",
|
||||
@@ -1262,6 +1263,19 @@ export default {
|
||||
emptySelection: "Seleziona almeno un database, oppure usa Mostra tutto per rimuovere il filtro.",
|
||||
loadFailed: "Impossibile caricare i database: {message}",
|
||||
},
|
||||
visibleSchemas: {
|
||||
title: "Filtro Schema",
|
||||
description: 'Scegli quali schema mostrare sotto "{connection}".',
|
||||
searchPlaceholder: "Cerca schema...",
|
||||
selectedCount: "{selected}/{total} selezionati",
|
||||
selectAll: "Seleziona tutto",
|
||||
selectFiltered: "Seleziona risultati ricerca",
|
||||
clear: "Cancella",
|
||||
showAll: "Mostra tutto",
|
||||
save: "Salva",
|
||||
emptySelection: "Seleziona almeno uno schema, oppure usa Mostra tutto per rimuovere il filtro.",
|
||||
loadFailed: "Impossibile caricare gli schema: {message}",
|
||||
},
|
||||
tree: {
|
||||
savedSql: "Libreria SQL",
|
||||
defaultDatabase: "DB Predefinito",
|
||||
|
||||
@@ -1315,6 +1315,19 @@ export default {
|
||||
emptySelection: "少なくとも1つのデータベースを選択するか、すべて表示でフィルターをクリアしてください。",
|
||||
loadFailed: "データベースの読み込みに失敗しました: {message}",
|
||||
},
|
||||
visibleSchemas: {
|
||||
title: "スキーマフィルター",
|
||||
description: "「{connection}」の下に表示するスキーマを選択してください。",
|
||||
searchPlaceholder: "スキーマを検索...",
|
||||
selectedCount: "{selected}/{total}件選択中",
|
||||
selectAll: "すべて選択",
|
||||
selectFiltered: "検索結果を選択",
|
||||
clear: "クリア",
|
||||
showAll: "すべて表示",
|
||||
save: "保存",
|
||||
emptySelection: "少なくとも1つのスキーマを選択するか、すべて表示でフィルターをクリアしてください。",
|
||||
loadFailed: "スキーマの読み込みに失敗しました: {message}",
|
||||
},
|
||||
tree: {
|
||||
savedSql: "SQLライブラリ",
|
||||
userAdmin: "ユーザーと権限",
|
||||
|
||||
@@ -1255,6 +1255,7 @@ export default {
|
||||
searchPlaceholder: "Pesquisar bancos de dados...",
|
||||
selectedCount: "{selected}/{total} selecionados",
|
||||
selectAll: "Selecionar todos",
|
||||
selectFiltered: "Selecionar resultados da pesquisa",
|
||||
clear: "Limpar",
|
||||
showAll: "Mostrar todos",
|
||||
showSystemDatabases: "Mostrar bancos de dados do sistema",
|
||||
@@ -1262,6 +1263,19 @@ export default {
|
||||
emptySelection: "Selecione pelo menos um banco de dados, ou use Mostrar todos para limpar o filtro.",
|
||||
loadFailed: "Falha ao carregar bancos de dados: {message}",
|
||||
},
|
||||
visibleSchemas: {
|
||||
title: "Filtro de Schema",
|
||||
description: 'Escolha quais schemas são exibidos em "{connection}".',
|
||||
searchPlaceholder: "Pesquisar schemas...",
|
||||
selectedCount: "{selected}/{total} selecionados",
|
||||
selectAll: "Selecionar todos",
|
||||
selectFiltered: "Selecionar resultados da pesquisa",
|
||||
clear: "Limpar",
|
||||
showAll: "Mostrar todos",
|
||||
save: "Salvar",
|
||||
emptySelection: "Selecione pelo menos um schema, ou use Mostrar todos para limpar o filtro.",
|
||||
loadFailed: "Falha ao carregar schemas: {message}",
|
||||
},
|
||||
tree: {
|
||||
savedSql: "Biblioteca SQL",
|
||||
defaultDatabase: "Banco padrão",
|
||||
|
||||
@@ -1330,9 +1330,22 @@ export default {
|
||||
showAll: "显示全部",
|
||||
showSystemDatabases: "显示系统库",
|
||||
save: "保存",
|
||||
emptySelection: "至少选择一个数据库,或使用“显示全部”清除过滤。",
|
||||
emptySelection: "至少选择一个数据库,或使用「显示全部」清除过滤。",
|
||||
loadFailed: "加载数据库失败:{message}",
|
||||
},
|
||||
visibleSchemas: {
|
||||
title: "Schema 过滤器",
|
||||
description: "选择「{connection}」下要在侧边栏显示的 Schema。",
|
||||
searchPlaceholder: "搜索 Schema...",
|
||||
selectedCount: "已选择 {selected}/{total}",
|
||||
selectAll: "全选",
|
||||
selectFiltered: "选中搜索结果",
|
||||
clear: "清空",
|
||||
showAll: "显示全部",
|
||||
save: "保存",
|
||||
emptySelection: "至少选择一个 Schema,或使用「显示全部」清除过滤。",
|
||||
loadFailed: "加载 Schema 失败:{message}",
|
||||
},
|
||||
tree: {
|
||||
savedSql: "SQL 库",
|
||||
userAdmin: "用户与权限",
|
||||
|
||||
@@ -1235,6 +1235,7 @@ export default {
|
||||
searchPlaceholder: "搜尋資料庫……",
|
||||
selectedCount: "已選擇 {selected}/{total}",
|
||||
selectAll: "全選",
|
||||
selectFiltered: "選取搜尋結果",
|
||||
clear: "清空",
|
||||
showAll: "顯示全部",
|
||||
showSystemDatabases: "顯示系統庫",
|
||||
@@ -1242,6 +1243,19 @@ export default {
|
||||
emptySelection: "至少選擇一個資料庫,或使用「顯示全部」清除篩選。",
|
||||
loadFailed: "載入資料庫失敗:{message}",
|
||||
},
|
||||
visibleSchemas: {
|
||||
title: "Schema 過濾器",
|
||||
description: "選擇「{connection}」下要在側邊欄顯示的 Schema。",
|
||||
searchPlaceholder: "搜尋 Schema……",
|
||||
selectedCount: "已選擇 {selected}/{total}",
|
||||
selectAll: "全選",
|
||||
selectFiltered: "選取搜尋結果",
|
||||
clear: "清空",
|
||||
showAll: "顯示全部",
|
||||
save: "儲存",
|
||||
emptySelection: "至少選擇一個 Schema,或使用「顯示全部」清除篩選。",
|
||||
loadFailed: "載入 Schema 失敗:{message}",
|
||||
},
|
||||
tree: {
|
||||
savedSql: "SQL 庫",
|
||||
defaultDatabase: "預設庫",
|
||||
|
||||
@@ -97,3 +97,32 @@ export function filterDatabaseNamesForConnection(databaseNames: string[], connec
|
||||
}
|
||||
return databaseNames.filter((name) => !isSystemDatabaseName(connection?.db_type, name));
|
||||
}
|
||||
|
||||
export function visibleSchemaFilterIsEnabled(visibleSchemas: Record<string, string[]> | undefined, database: string): boolean {
|
||||
return Array.isArray(visibleSchemas?.[database]);
|
||||
}
|
||||
|
||||
export function filterSchemaNamesForConnection(schemaNames: string[], connection: Pick<ConnectionConfig, "db_type" | "visible_schemas"> | undefined, database: string): string[] {
|
||||
const visibleSchemas = connection?.visible_schemas;
|
||||
if (!visibleSchemaFilterIsEnabled(visibleSchemas, database)) {
|
||||
return schemaNames.filter((name) => !isSystemDatabaseName(connection?.db_type, name));
|
||||
}
|
||||
const visible = new Set(visibleSchemas![database]);
|
||||
return schemaNames.filter((name) => visible.has(name));
|
||||
}
|
||||
|
||||
export function normalizeVisibleSchemaSelection(selectedNames: string[], schemaNames: string[]): string[] {
|
||||
const available = new Set(schemaNames);
|
||||
const seen = new Set<string>();
|
||||
return selectedNames.filter((name) => {
|
||||
if (!available.has(name) || seen.has(name)) return false;
|
||||
seen.add(name);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
const DRAFT_VISIBLE_SCHEMAS_PREFIX = "__visible_schema_draft_";
|
||||
|
||||
export function buildDraftVisibleSchemasConnectionId(seed: string): string {
|
||||
return `${DRAFT_VISIBLE_SCHEMAS_PREFIX}${seed}`;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ import { buildSqlServerDatabaseTreeNodes, SQLSERVER_DEFAULT_SCHEMA } from "@/lib
|
||||
import { findDatabaseTreeNode } from "@/lib/treeRefreshTarget";
|
||||
import { shouldMarkDisconnected } from "@/lib/connectionHealth";
|
||||
import { connectionAttemptOriginalErrorMessage, connectionAttemptTimeoutMessage, connectionAttemptTimeoutMs } from "@/lib/connectionAttemptTimeout";
|
||||
import { filterDatabaseNamesForConnection, filterVisibleDatabaseNames, normalizeVisibleDatabaseSelection } from "@/lib/visibleDatabases";
|
||||
import { filterDatabaseNamesForConnection, filterSchemaNamesForConnection, filterVisibleDatabaseNames, normalizeVisibleDatabaseSelection } from "@/lib/visibleDatabases";
|
||||
import {
|
||||
buildObjectGroupPlaceholderNodes,
|
||||
buildGroupedObjectTreeNodes,
|
||||
@@ -941,6 +941,61 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
rebuildTreeNodes();
|
||||
}
|
||||
|
||||
async function setVisibleSchemas(connectionId: string, database: string, schemaNames: string[]) {
|
||||
const config = getConfig(connectionId);
|
||||
if (!config) return;
|
||||
const key = database || "";
|
||||
await updateVisibleSchemasConfig(connectionId, key, schemaNames);
|
||||
await reloadSchemaChildren(connectionId, database);
|
||||
}
|
||||
|
||||
async function clearVisibleSchemas(connectionId: string, database: string) {
|
||||
const config = getConfig(connectionId);
|
||||
if (!config || !config.visible_schemas) return;
|
||||
const key = database || "";
|
||||
await updateVisibleSchemasConfig(connectionId, key, undefined);
|
||||
await reloadSchemaChildren(connectionId, database);
|
||||
}
|
||||
|
||||
async function updateVisibleSchemasConfig(connectionId: string, database: string, schemaNames: string[] | undefined) {
|
||||
const idx = connections.value.findIndex((connection) => connection.id === connectionId);
|
||||
if (idx < 0) return;
|
||||
const existing = connections.value[idx].visible_schemas;
|
||||
let nextSchemas: Record<string, string[]> | undefined;
|
||||
if (schemaNames) {
|
||||
nextSchemas = { ...(existing || {}), [database]: schemaNames };
|
||||
} else if (existing) {
|
||||
nextSchemas = { ...existing };
|
||||
delete nextSchemas[database];
|
||||
if (Object.keys(nextSchemas).length === 0) nextSchemas = undefined;
|
||||
}
|
||||
const nextConnections = [...connections.value];
|
||||
nextConnections[idx] = {
|
||||
...nextConnections[idx],
|
||||
visible_schemas: nextSchemas,
|
||||
};
|
||||
await persistConnections(nextConnections);
|
||||
connections.value = nextConnections;
|
||||
rebuildTreeNodes();
|
||||
}
|
||||
|
||||
async function reloadSchemaChildren(connectionId: string, database?: string) {
|
||||
const config = getConfig(connectionId);
|
||||
if (!config) return;
|
||||
const db = database || config.database || "";
|
||||
clearLoadedChildrenCache(connectionId);
|
||||
clearLoadedChildrenCache(`${connectionId}:${db}`);
|
||||
await loadDatabases(connectionId, { force: true });
|
||||
// After saving schema filter, force-refresh database node's schema children
|
||||
// to avoid stale children from previously expanded nodes
|
||||
if (db) {
|
||||
const dbNode = findNode(treeNodes.value, `${connectionId}:${db}`);
|
||||
if (dbNode) {
|
||||
await loadTreeNodeChildren(dbNode, { force: true });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function reloadConnectionDatabaseChildren(connectionId: string) {
|
||||
const config = getConfig(connectionId);
|
||||
if (!config) return;
|
||||
@@ -1139,7 +1194,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
}
|
||||
}
|
||||
const schemas = await withMetadataLoadTimeout(connectionId, api.listSchemas(connectionId, effectiveDb), "schemas");
|
||||
const visibleSchemas = filterDatabaseNamesForConnection(schemas, config);
|
||||
const visibleSchemas = filterSchemaNamesForConnection(schemas, config, effectiveDb || "");
|
||||
const schemaNodes: TreeNode[] = sortSidebarNames(visibleSchemas).map((s) => ({
|
||||
id: `${connectionId}:${s}:${s}`,
|
||||
label: s,
|
||||
@@ -1560,20 +1615,29 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
}
|
||||
|
||||
const schemas = sortSidebarSchemaInfos(await api.listSchemaInfos(connectionId, database));
|
||||
const children = schemas.map((schema) => {
|
||||
const s = schema.name;
|
||||
return {
|
||||
id: `${connectionId}:${database}:${s}`,
|
||||
label: s,
|
||||
type: "schema" as const,
|
||||
connectionId,
|
||||
const visibleSchemaNames = new Set(
|
||||
filterSchemaNamesForConnection(
|
||||
schemas.map((schema) => schema.name),
|
||||
getConfig(connectionId),
|
||||
database,
|
||||
schema: s,
|
||||
comment: schema.comment,
|
||||
isExpanded: false,
|
||||
children: [],
|
||||
};
|
||||
});
|
||||
),
|
||||
);
|
||||
const children = schemas
|
||||
.filter((schema) => visibleSchemaNames.has(schema.name))
|
||||
.map((schema) => {
|
||||
const s = schema.name;
|
||||
return {
|
||||
id: `${connectionId}:${database}:${s}`,
|
||||
label: s,
|
||||
type: "schema" as const,
|
||||
connectionId,
|
||||
database,
|
||||
schema: s,
|
||||
comment: schema.comment,
|
||||
isExpanded: false,
|
||||
children: [],
|
||||
};
|
||||
});
|
||||
setChildren(node, children);
|
||||
await savePersistedTreeChildren(cacheKey, children);
|
||||
node.isExpanded = true;
|
||||
@@ -1604,7 +1668,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
}
|
||||
|
||||
const config = getConfig(connectionId);
|
||||
const schemas = await api.listSchemas(connectionId, database);
|
||||
const schemas = filterSchemaNamesForConnection(await api.listSchemas(connectionId, database), config, database);
|
||||
const defaultSchemaObjects = simpleObjectDisplay ? await api.listObjects(connectionId, database, SQLSERVER_DEFAULT_SCHEMA) : [];
|
||||
const children = buildSqlServerDatabaseTreeNodes(connectionId, database, schemas, defaultSchemaObjects, {
|
||||
lazyObjectTypes: simpleObjectDisplay ? undefined : supportedSidebarObjectTypes(config),
|
||||
@@ -3412,6 +3476,8 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
isDefaultDatabase,
|
||||
setVisibleDatabases,
|
||||
clearVisibleDatabases,
|
||||
setVisibleSchemas,
|
||||
clearVisibleSchemas,
|
||||
removeConnection,
|
||||
removeConnections,
|
||||
editingConnectionId,
|
||||
|
||||
@@ -120,6 +120,7 @@ export interface ConnectionConfig {
|
||||
password: string;
|
||||
database?: string;
|
||||
visible_databases?: string[];
|
||||
visible_schemas?: Record<string, string[]>;
|
||||
attached_databases?: AttachedDatabaseConfig[];
|
||||
color?: string;
|
||||
transport_layers?: TransportLayerConfig[];
|
||||
|
||||
@@ -583,6 +583,7 @@ mod tests {
|
||||
password: "secret".to_string(),
|
||||
database: database.map(str::to_string),
|
||||
visible_databases: None,
|
||||
visible_schemas: None,
|
||||
attached_databases: Vec::new(),
|
||||
color: None,
|
||||
transport_layers: Vec::new(),
|
||||
|
||||
@@ -602,6 +602,7 @@ mod tests {
|
||||
password: "secret".to_string(),
|
||||
database: None,
|
||||
visible_databases: None,
|
||||
visible_schemas: None,
|
||||
attached_databases: Vec::new(),
|
||||
color: None,
|
||||
transport_layers: vec![TransportLayerConfig::Ssh(crate::models::connection::SshTunnelConfig {
|
||||
|
||||
@@ -2388,6 +2388,7 @@ mod tests {
|
||||
password: "secret".to_string(),
|
||||
database: database.map(str::to_string),
|
||||
visible_databases: None,
|
||||
visible_schemas: None,
|
||||
attached_databases: Vec::new(),
|
||||
color: None,
|
||||
transport_layers: Vec::new(),
|
||||
|
||||
@@ -705,6 +705,7 @@ mod tests {
|
||||
password: password.to_string(),
|
||||
database: Some("postgres".to_string()),
|
||||
visible_databases: None,
|
||||
visible_schemas: None,
|
||||
attached_databases: Vec::new(),
|
||||
color: None,
|
||||
transport_layers: Vec::new(),
|
||||
|
||||
@@ -2592,6 +2592,7 @@ mod tests {
|
||||
password: String::new(),
|
||||
database: Some("4".to_string()),
|
||||
visible_databases: None,
|
||||
visible_schemas: None,
|
||||
attached_databases: Vec::new(),
|
||||
color: None,
|
||||
transport_layers: Vec::new(),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use percent_encoding::{percent_decode_str, utf8_percent_encode, NON_ALPHANUMERIC};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, PartialEq)]
|
||||
pub struct ConnectionConfig {
|
||||
@@ -20,6 +21,8 @@ pub struct ConnectionConfig {
|
||||
pub database: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub visible_databases: Option<Vec<String>>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub visible_schemas: Option<HashMap<String, Vec<String>>>,
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub attached_databases: Vec<AttachedDatabaseConfig>,
|
||||
#[serde(default)]
|
||||
@@ -346,6 +349,8 @@ struct ConnectionConfigData {
|
||||
#[serde(default)]
|
||||
pub visible_databases: Option<Vec<String>>,
|
||||
#[serde(default)]
|
||||
pub visible_schemas: Option<HashMap<String, Vec<String>>>,
|
||||
#[serde(default)]
|
||||
pub attached_databases: Vec<AttachedDatabaseConfig>,
|
||||
#[serde(default)]
|
||||
pub color: Option<String>,
|
||||
@@ -422,6 +427,7 @@ impl From<ConnectionConfigData> for ConnectionConfig {
|
||||
password: data.password,
|
||||
database: data.database,
|
||||
visible_databases: data.visible_databases,
|
||||
visible_schemas: data.visible_schemas,
|
||||
attached_databases: data.attached_databases,
|
||||
color: data.color,
|
||||
transport_layers: data.transport_layers,
|
||||
@@ -1543,6 +1549,7 @@ mod tests {
|
||||
password: password.to_string(),
|
||||
database: database.map(str::to_string),
|
||||
visible_databases: None,
|
||||
visible_schemas: None,
|
||||
attached_databases: Vec::new(),
|
||||
color: None,
|
||||
transport_layers: Vec::new(),
|
||||
|
||||
@@ -109,6 +109,7 @@ mod tests {
|
||||
password: String::new(),
|
||||
database: None,
|
||||
visible_databases: None,
|
||||
visible_schemas: None,
|
||||
attached_databases: Vec::new(),
|
||||
color: None,
|
||||
transport_layers: Vec::new(),
|
||||
|
||||
@@ -503,6 +503,7 @@ mod tests {
|
||||
password: String::new(),
|
||||
database: None,
|
||||
visible_databases: None,
|
||||
visible_schemas: None,
|
||||
attached_databases: Vec::new(),
|
||||
color: None,
|
||||
transport_layers: Vec::new(),
|
||||
|
||||
@@ -2444,6 +2444,7 @@ mod tests {
|
||||
password: String::new(),
|
||||
database: None,
|
||||
visible_databases: None,
|
||||
visible_schemas: None,
|
||||
attached_databases: Vec::new(),
|
||||
color: None,
|
||||
transport_layers: Vec::new(),
|
||||
|
||||
@@ -1209,6 +1209,7 @@ mod tests {
|
||||
password: "secret".to_string(),
|
||||
database: Some("demo".to_string()),
|
||||
visible_databases: None,
|
||||
visible_schemas: None,
|
||||
attached_databases: Vec::new(),
|
||||
color: None,
|
||||
transport_layers: Vec::new(),
|
||||
|
||||
@@ -157,6 +157,7 @@ mod tests {
|
||||
password: "secret".to_string(),
|
||||
database: Some("demo".to_string()),
|
||||
visible_databases: None,
|
||||
visible_schemas: None,
|
||||
attached_databases: Vec::new(),
|
||||
color: None,
|
||||
transport_layers: Vec::new(),
|
||||
|
||||
@@ -1887,6 +1887,7 @@ mod tests {
|
||||
password: String::new(),
|
||||
database: None,
|
||||
visible_databases: None,
|
||||
visible_schemas: None,
|
||||
attached_databases: Vec::new(),
|
||||
color: None,
|
||||
transport_layers: Vec::new(),
|
||||
|
||||
@@ -3551,6 +3551,7 @@ mod tests {
|
||||
password: String::new(),
|
||||
database: None,
|
||||
visible_databases: None,
|
||||
visible_schemas: None,
|
||||
attached_databases: Vec::new(),
|
||||
color: None,
|
||||
transport_layers: Vec::new(),
|
||||
|
||||
@@ -22,6 +22,7 @@ fn postgres_test_config(id: &str, database: &str) -> ConnectionConfig {
|
||||
password: String::new(),
|
||||
database: Some(database.to_string()),
|
||||
visible_databases: None,
|
||||
visible_schemas: None,
|
||||
attached_databases: Vec::new(),
|
||||
color: None,
|
||||
transport_layers: Vec::new(),
|
||||
|
||||
@@ -108,7 +108,7 @@ pub async fn disconnect_db(
|
||||
#[cfg(feature = "mq-admin")]
|
||||
app.mq_registry.drop_connection(&body.connection_id).await;
|
||||
app.reset_connection_transport(&body.connection_id).await;
|
||||
if body.connection_id.starts_with("__visible_draft_") {
|
||||
if body.connection_id.starts_with("__visible_draft_") || body.connection_id.starts_with("__visible_schema_draft_") {
|
||||
app.configs.write().await.remove(&body.connection_id);
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ async fn sync_connection_configs(state: &WebState, configs: &[ConnectionConfig])
|
||||
}
|
||||
|
||||
fn is_transient_runtime_config_id(id: &str) -> bool {
|
||||
id.starts_with("__test_") || id.starts_with("__visible_draft_")
|
||||
id.starts_with("__test_") || id.starts_with("__visible_draft_") || id.starts_with("__visible_schema_draft_")
|
||||
}
|
||||
|
||||
async fn drop_nacos_adapters_for_connection_ids(state: &WebState, connection_ids: &[String]) {
|
||||
@@ -263,6 +263,7 @@ mod tests {
|
||||
password: String::new(),
|
||||
database: None,
|
||||
visible_databases: None,
|
||||
visible_schemas: None,
|
||||
attached_databases: Vec::new(),
|
||||
color: None,
|
||||
transport_layers: Vec::new(),
|
||||
|
||||
@@ -223,6 +223,7 @@ mod tests {
|
||||
password: "secret".to_string(),
|
||||
database: Some("RestCloud_V45PUB_Gateway".to_string()),
|
||||
visible_databases: None,
|
||||
visible_schemas: None,
|
||||
attached_databases: Vec::new(),
|
||||
color: None,
|
||||
transport_layers: Vec::new(),
|
||||
@@ -491,7 +492,7 @@ async fn sync_connection_configs(state: &AppState, configs: &[ConnectionConfig])
|
||||
}
|
||||
|
||||
fn is_transient_runtime_config_id(id: &str) -> bool {
|
||||
id.starts_with("__test_") || id.starts_with("__visible_draft_")
|
||||
id.starts_with("__test_") || id.starts_with("__visible_draft_") || id.starts_with("__visible_schema_draft_")
|
||||
}
|
||||
|
||||
async fn drop_nacos_adapters_for_connection_ids(state: &AppState, connection_ids: &[String]) {
|
||||
@@ -1127,7 +1128,7 @@ pub async fn disconnect_db(state: State<'_, Arc<AppState>>, connection_id: Strin
|
||||
drop_nacos_adapters_for_connection_ids(state.inner(), std::slice::from_ref(&connection_id)).await;
|
||||
drop_mq_adapters_for_connection_ids(state.inner(), std::slice::from_ref(&connection_id)).await;
|
||||
state.reset_connection_transport(&connection_id).await;
|
||||
if connection_id.starts_with("__visible_draft_") {
|
||||
if connection_id.starts_with("__visible_draft_") || connection_id.starts_with("__visible_schema_draft_") {
|
||||
state.configs.write().await.remove(&connection_id);
|
||||
}
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user