feat(connection): update saved connections by ID through deep links
This commit is contained in:
1 parent
221683950d
commit
d66242508e
10 files changed
+818
-13
No files matched your search
@@ -72,7 +72,8 @@ import { applyMeilisearchBasePathToExternalConfig, applyParsedConnectionUrl, nor
|
||||
import { hasXuguConnectionDatabase } from "@/lib/connection/xuguDatabase";
|
||||
import { DEFAULT_QUERY_TIMEOUT_SECS, MAX_CONNECT_TIMEOUT_SECS, MAX_QUERY_TIMEOUT_SECS } from "@/lib/connection/timeoutLimits";
|
||||
import { buildOracleTnsConnectionString, normalizeOracleTnsAdminPath, parseOracleTnsConnectionString } from "@/lib/connection/oracleTnsConnection";
|
||||
import { connectionDeepLinkServiceHydrationValue, parseConnectionDeepLink, parseServiceConnectionUrl, type ConnectionDeepLinkDraft } from "@/lib/connection/connectionDeepLink";
|
||||
import { applyConnectionDeepLinkUpdate, resolveConnectionDeepLinkUpdate } from "@/lib/connection/connectionDeepLinkUpdate";
|
||||
import { connectionDeepLinkServiceHydrationValue, parseConnectionDeepLink, parseConnectionDeepLinkUpdate, parseServiceConnectionUrl, type ConnectionDeepLinkDraft, type ConnectionDeepLinkUpdate } from "@/lib/connection/connectionDeepLink";
|
||||
import { connectionUrlPlaceholder as getUrlPlaceholder } from "@/lib/connection/connectionPresentation";
|
||||
import { parseGaussdbHosts, serializeGaussdbHosts, type GaussdbHostEntry } from "@/lib/connection/gaussdbHosts";
|
||||
import { h2ConnectionModeForConfig, h2FileJdbcUrlWithPath, h2FilePathFromJdbcUrl, isH2SplitJdbcUrl, type H2ConnectionMode } from "@/lib/database/h2Connection";
|
||||
@@ -288,6 +289,7 @@ const isDesktop = isTauriRuntime();
|
||||
const props = defineProps<{
|
||||
editConfig?: ConnectionConfig;
|
||||
prefillConfig?: ConnectionDeepLinkDraft | null;
|
||||
updatePrefill?: ConnectionDeepLinkUpdate | null;
|
||||
pluginProvider?: PluginCenterFocus | null;
|
||||
initialTab?: ConfigTab;
|
||||
}>();
|
||||
@@ -2626,15 +2628,42 @@ function switchGbaseProfile(profile: "gbase8a" | "gbase8s") {
|
||||
resetTestState();
|
||||
}
|
||||
|
||||
let applyingConnectionUpdate = false;
|
||||
let appliedConnectionUpdate: ConnectionDeepLinkUpdate | null = null;
|
||||
|
||||
function finishApplyingConnectionUpdate() {
|
||||
void nextTick(() => {
|
||||
applyingConnectionUpdate = false;
|
||||
});
|
||||
}
|
||||
|
||||
// The external_config shaped by an update link must survive submit verbatim
|
||||
// only while the submitted values are still the ones the link patched: once
|
||||
// the user edits the port away from the patched value, or the patch targeted
|
||||
// another connection, the flag is re-derived from the form like any edit.
|
||||
function connectionUpdateExternalConfigPreserved(config: Pick<ConnectionConfig, "id" | "port">): boolean {
|
||||
if (!appliedConnectionUpdate || appliedConnectionUpdate.connectionId !== config.id) return false;
|
||||
const patchedPort = appliedConnectionUpdate.patch.port;
|
||||
return patchedPort === undefined || patchedPort === config.port;
|
||||
}
|
||||
|
||||
watch(
|
||||
[() => props.editConfig, open],
|
||||
([config, isOpen]) => {
|
||||
const syncAction = connectionEditDraftSyncAction(config?.id ?? null, isOpen, editingId.value);
|
||||
([savedConfig, isOpen]) => {
|
||||
const syncAction = connectionEditDraftSyncAction(savedConfig?.id ?? null, isOpen, editingId.value);
|
||||
if (syncAction === "preserve") return;
|
||||
// Hydrate a detached edit draft before form watchers observe it. Do not
|
||||
// mutate the saved record or apply create defaults to an ID update. Only
|
||||
// flag the update as applied when the prefill really targeted this
|
||||
// connection, so an ID mismatch cannot freeze port-flag recomputation.
|
||||
const connectionUpdate = savedConfig && props.updatePrefill?.connectionId === savedConfig.id ? props.updatePrefill : null;
|
||||
const config = connectionUpdate && savedConfig ? applyConnectionDeepLinkUpdate(savedConfig, connectionUpdate) : savedConfig;
|
||||
resetConnectionNoteVisibilityDraft(connectionNoteVisibilityDraft, settingsStore.editorSettings.sidebarShowConnectionNotes);
|
||||
editGlobalConnectTimeoutSecs.value = settingsStore.editorSettings.globalConnectTimeoutSecs;
|
||||
editGlobalQueryTimeoutSecs.value = settingsStore.editorSettings.globalQueryTimeoutSecs;
|
||||
if (syncAction === "hydrate" && config) {
|
||||
appliedConnectionUpdate = connectionUpdate;
|
||||
if (connectionUpdate) applyingConnectionUpdate = true;
|
||||
clearSavedDatabaseInfo();
|
||||
const legacyConfig = config as LegacyConnectionConfig;
|
||||
const profile = profileForConfig(config);
|
||||
@@ -2777,13 +2806,15 @@ watch(
|
||||
customDriverName.value = isCustomCompatibleProfile() ? config.driver_label || "" : "";
|
||||
dialogStep.value = "config";
|
||||
configTab.value = initialConfigTab();
|
||||
if (props.updatePrefill) finishApplyingConnectionUpdate();
|
||||
// Form/profile watchers normalize derived fields in this flush. Capture
|
||||
// the saved baseline afterwards so those initial changes are not treated
|
||||
// as user edits that invalidate persisted database metadata.
|
||||
void nextTick(() => {
|
||||
if (open.value && props.editConfig?.id === config.id) applySavedDatabaseInfo(config);
|
||||
if (open.value && props.editConfig?.id === config.id && !props.updatePrefill) applySavedDatabaseInfo(config);
|
||||
});
|
||||
} else {
|
||||
appliedConnectionUpdate = null;
|
||||
clearSavedDatabaseInfo();
|
||||
editingId.value = null;
|
||||
selectedConnectionGroupId.value = initialConnectionGroupId();
|
||||
@@ -3930,6 +3961,18 @@ function clearEditedConnectionErrorAfterSuccessfulTest() {
|
||||
|
||||
function applyConnectionUrlToForm(input: string): boolean {
|
||||
try {
|
||||
const update = parseConnectionDeepLinkUpdate(input);
|
||||
if (update) {
|
||||
if (update.connectionId !== editingId.value || props.editConfig?.one_time) throw new Error("Open the saved connection specified by this update link before applying it.");
|
||||
const draft = applyConnectionDeepLinkUpdate(form.value, update);
|
||||
applyingConnectionUpdate = true;
|
||||
appliedConnectionUpdate = update;
|
||||
form.value = draft;
|
||||
finishApplyingConnectionUpdate();
|
||||
resetTestState();
|
||||
appliedConnectionUrlInput.value = input.trim();
|
||||
return true;
|
||||
}
|
||||
const draft = parseConnectionDeepLink(input) ?? parseServiceConnectionUrl(input);
|
||||
if (draft) {
|
||||
applyConnectionDraftToForm({ ...draft, oneTime: undefined });
|
||||
@@ -4009,6 +4052,11 @@ function ensureConnectionHostResolvedFromUrl(): boolean {
|
||||
function formValueForSubmit(): Omit<ConnectionConfig, "id"> {
|
||||
const url = connectionUrlInput.value.trim();
|
||||
if (url && url !== appliedConnectionUrlInput.value) {
|
||||
const update = parseConnectionDeepLinkUpdate(url);
|
||||
if (update) {
|
||||
if (update.connectionId !== editingId.value || props.editConfig?.one_time) throw new Error("Open the saved connection specified by this update link before applying it.");
|
||||
return applyConnectionDeepLinkUpdate(form.value, update);
|
||||
}
|
||||
const draft = parseConnectionDeepLink(url);
|
||||
if (draft) {
|
||||
return applyConnectionDraftToConfig(form.value, { ...draft, oneTime: undefined });
|
||||
@@ -4384,7 +4432,7 @@ function connectionConfigForSubmit(id: string, generatedName = "", validatePlugi
|
||||
config.password = config.password.trim();
|
||||
config.database = undefined;
|
||||
} else if (config.db_type === "sqlserver") {
|
||||
config.external_config = sqlServerPortExplicitFromConfig(config) ? { portExplicit: true } : undefined;
|
||||
if (!connectionUpdateExternalConfigPreserved(config)) config.external_config = sqlServerPortExplicitFromConfig(config) ? { portExplicit: true } : undefined;
|
||||
} else if (supportsGaussdbIdentifierQuoteStyle(config)) {
|
||||
const style = gaussdbIdentifierQuoteStyle(config);
|
||||
const targetServerType = gaussdbTargetServerType(config);
|
||||
@@ -4397,7 +4445,7 @@ function connectionConfigForSubmit(id: string, generatedName = "", validatePlugi
|
||||
// Plugin connections keep `external_config`: the manifest-driven form
|
||||
// fields land there via buildPluginConnectionConfig. Only the built-in
|
||||
// drivers without an external-config payload get wiped here.
|
||||
config.external_config = undefined;
|
||||
if (!connectionUpdateExternalConfigPreserved(config)) config.external_config = undefined;
|
||||
}
|
||||
if (config.db_type === "mongodb" && !mongoUseUrl.value) {
|
||||
config.connection_string = undefined;
|
||||
@@ -5581,7 +5629,9 @@ watch(
|
||||
});
|
||||
// Preload database names so the summary count is accurate right away.
|
||||
void nextTick(() => {
|
||||
if (canChooseVisibleDatabases.value && hasVisibleDatabaseFilter.value) {
|
||||
// An external update may change the endpoint while retaining its saved
|
||||
// password. Do not send credentials until the user tests or saves it.
|
||||
if (!props.updatePrefill && canChooseVisibleDatabases.value && hasVisibleDatabaseFilter.value) {
|
||||
void preloadVisibleDatabaseNames();
|
||||
}
|
||||
});
|
||||
@@ -5618,7 +5668,7 @@ watch([() => form.value.db_type, () => form.value.username], () => {
|
||||
watch(
|
||||
() => connectionConfigSnapshotForVisibleDatabases(),
|
||||
(current, previous) => {
|
||||
if (!previous || !visibleObjectFiltersNeedReset(previous, current)) return;
|
||||
if (applyingConnectionUpdate || !previous || !visibleObjectFiltersNeedReset(previous, current)) return;
|
||||
form.value.visible_databases = undefined;
|
||||
form.value.visible_schemas = undefined;
|
||||
resetVisibleDatabaseDraftState();
|
||||
@@ -5865,6 +5915,14 @@ function startSavedConnection(config: ConnectionConfig) {
|
||||
});
|
||||
}
|
||||
|
||||
function validateConnectionUpdateTarget() {
|
||||
const update = props.updatePrefill ?? appliedConnectionUpdate;
|
||||
if (!update) return;
|
||||
const target = store.getConfig(update.connectionId);
|
||||
resolveConnectionDeepLinkUpdate(update, target ? [target] : [], false);
|
||||
if (editingId.value !== update.connectionId) throw new Error("The connection specified by the update link is no longer being edited.");
|
||||
}
|
||||
|
||||
async function save(options: SaveConnectionOptions = {}): Promise<boolean> {
|
||||
if (!ensureConnectionHostResolvedFromUrl()) return false;
|
||||
if (isSaving.value) return false;
|
||||
@@ -5881,10 +5939,12 @@ async function save(options: SaveConnectionOptions = {}): Promise<boolean> {
|
||||
let connectionSaved = false;
|
||||
try {
|
||||
let savedConfig: ConnectionConfig;
|
||||
validateConnectionUpdateTarget();
|
||||
if (editingId.value) {
|
||||
const updated = withSavedDatabaseInfo(connectionConfigForSubmit(editingId.value), databaseInfoForSave);
|
||||
await ensureRequiredAgentDriverInstalled(updated);
|
||||
await ensureRequiredGaussdbMJdbcRuntime(updated);
|
||||
validateConnectionUpdateTarget();
|
||||
await persistGlobalTimeoutDrafts();
|
||||
await store.updateConnection(updated);
|
||||
savedConfig = updated;
|
||||
|
||||
Reference in new issue
Block a user