feat(nacos): add browser console open, zen mode and metadata view
This commit is contained in:
18 files changed
+335
-14
No files matched your search
@@ -59,12 +59,12 @@ describe("right sidebar panel entry points", () => {
|
||||
expect(functionSource("setRightSidebarPanelOpen", "toggleRightSidebarPanel")).toContain("isAiPanelMaximized.value = false;");
|
||||
});
|
||||
|
||||
it("keeps Zen mode as a temporary data-tab layout", () => {
|
||||
it("keeps Zen mode as a temporary data or Nacos-tab layout", () => {
|
||||
expect(appSource).toContain("const isZenMode = ref(false);");
|
||||
expect(appSource).toContain('if (mode !== "data") isZenMode.value = false;');
|
||||
expect(appSource).toContain('return mode === "data" || mode === "nacos";');
|
||||
expect(appSource).toContain("function toggleZenMode() {");
|
||||
expect(appSource).toContain('if (activeTab.value?.mode !== "data") return;');
|
||||
expect(appSource).toContain('isToggleZenModeShortcut(e, shortcuts) && activeTab.value?.mode === "data"');
|
||||
expect(appSource).toContain("if (!supportsZenMode(activeTab.value?.mode)) return;");
|
||||
expect(appSource).toContain("isToggleZenModeShortcut(e, shortcuts) && supportsZenMode(activeTab.value?.mode)");
|
||||
expect(appSource).toContain('@toggle-zen-mode="toggleZenMode"');
|
||||
expect(appSource).toContain('v-show="sidebarOpen && !isZenMode"');
|
||||
expect(appSource).toContain('v-show="!sidebarOpen && !isZenMode"');
|
||||
|
||||
@@ -31,6 +31,7 @@ describe("Nacos connection dialog layout", () => {
|
||||
expect(main).toContain('t("nacos.nacosAdvancedHint")');
|
||||
expect(main).toContain("@click=\"configTab = 'advanced'\"");
|
||||
expect(main).toContain('v-model="nacosServerAddr"');
|
||||
expect(main).not.toContain('v-model="nacosConsoleUrl"');
|
||||
expect(main).not.toContain('v-model="nacosManagedNamespacesText"');
|
||||
expect(main).not.toContain("data-nacos-namespace-access-scope");
|
||||
expect(main).not.toContain("data-nacos-ordinary-user-toggle");
|
||||
@@ -52,6 +53,9 @@ describe("Nacos connection dialog layout", () => {
|
||||
expect(advanced).toContain('v-model="nacosContextPath"');
|
||||
expect(advanced).toContain('t("nacos.nacosContextPathHint")');
|
||||
expect(advanced).toContain('v-model="nacosMetricsMode"');
|
||||
expect(advanced).toContain('v-model="nacosConsoleUrl"');
|
||||
expect(advanced).toContain('t("connection.nacosWebConsoleUrlHint")');
|
||||
expect(advanced).toContain('v-if="isNacosV3AdminPlane"');
|
||||
expect(advanced).toContain('v-model="nacosRNacosConsoleAddr"');
|
||||
expect(advanced).toContain('v-if="nacosRNacosConsoleAddr.trim()"');
|
||||
expect(advanced).toContain('v-model="nacosHistoryEnabled"');
|
||||
@@ -67,6 +71,7 @@ describe("Nacos connection dialog layout", () => {
|
||||
const mainEnd = source.indexOf("<!-- Redis: host, port, user, password, ssl -->", mainStart);
|
||||
expect(source.slice(mainStart, mainEnd)).not.toContain("data-nacos-managed-namespaces");
|
||||
expect(source.slice(mainStart, mainEnd)).not.toContain('placeholder="http://127.0.0.1:8080"');
|
||||
expect(source).toContain('return "http://127.0.0.1:8080";');
|
||||
expect(source).not.toContain("http://127.0.0.1:8010");
|
||||
expect(source).not.toContain("http://127.0.0.1:8818");
|
||||
});
|
||||
|
||||
@@ -20,8 +20,10 @@ import {
|
||||
isNacosConfigDeleteSnapshotInScope,
|
||||
mergeNacosNamespacePermissionAssignments,
|
||||
nacosConfigFileExtension,
|
||||
nacosMetadataTableRows,
|
||||
nacosMetricsCandidates,
|
||||
normalizeNacosMetricsUrl,
|
||||
normalizeNacosConsoleUrl,
|
||||
parseNacosManagedNamespaces,
|
||||
parseNacosRawBody,
|
||||
parseNacosRawQuery,
|
||||
@@ -29,6 +31,7 @@ import {
|
||||
resolveRNacosOpenApiFallback,
|
||||
resolveNacosConfigCopyText,
|
||||
resolveNacosConfigSaveCompletion,
|
||||
resolveNacosConsoleUrl,
|
||||
sanitizeNacosConfigFileNameSegment,
|
||||
splitNacosContentLiteralMatches,
|
||||
summarizeNacosConfigDiff,
|
||||
@@ -92,6 +95,26 @@ describe("nacosAdmin helpers", () => {
|
||||
expect(() => normalizeNacosMetricsUrl("http://localhost/metrics#")).toThrow(/fragment/);
|
||||
});
|
||||
|
||||
it("formats instance metadata for a readable table without flattening nested values", () => {
|
||||
expect(nacosMetadataTableRows({ role: "manual-test", source: "dbx-ui", ports: [8080, 8848], nested: { enabled: true } })).toEqual([
|
||||
{ key: "role", value: "manual-test" },
|
||||
{ key: "source", value: "dbx-ui" },
|
||||
{ key: "ports", value: "[8080,8848]" },
|
||||
{ key: "nested", value: '{"enabled":true}' },
|
||||
]);
|
||||
expect(nacosMetadataTableRows(["legacy-value"])).toEqual([{ key: "0", value: "legacy-value" }]);
|
||||
});
|
||||
|
||||
it("resolves browser console URLs without inferring Nacos 3 ports", () => {
|
||||
expect(resolveNacosConsoleUrl({ implementation: "nacos", versionMode: "v2", serverAddr: "https://nacos.example:8848", contextPath: "/gateway/nacos", consoleUrl: "https://stale.example" })).toBe("https://nacos.example:8848/gateway/nacos");
|
||||
expect(resolveNacosConsoleUrl({ implementation: "nacos", versionMode: "v3", serverAddr: "https://nacos.example:11003", contextPath: "/nacos" })).toBeUndefined();
|
||||
expect(resolveNacosConsoleUrl({ implementation: "nacos", versionMode: "v3", serverAddr: "https://nacos.example:11003", consoleUrl: "https://nacos.example:11004/next/" })).toBe("https://nacos.example:11004/next");
|
||||
expect(resolveNacosConsoleUrl({ implementation: "nacos", versionMode: "v3", apiPlane: "console", serverAddr: "https://nacos.example:11004", contextPath: "/next", consoleUrl: "https://stale.example" })).toBe("https://nacos.example:11004/next");
|
||||
expect(resolveNacosConsoleUrl({ implementation: "rnacos", serverAddr: "https://rnacos.example:8848", rnacosConsoleAddr: "https://rnacos.example:10848/" })).toBe("https://rnacos.example:10848");
|
||||
expect(resolveNacosConsoleUrl({ serverAddr: "https://rnacos.example:8848", rnacosConsoleAddr: "https://rnacos.example:10848/" })).toBe("https://rnacos.example:10848");
|
||||
expect(() => normalizeNacosConsoleUrl("https://user:secret@nacos.example")).toThrow(/credentials/i);
|
||||
});
|
||||
|
||||
it("parses raw query and body text", () => {
|
||||
expect(parseNacosRawQuery("?dataId=a&group=DEFAULT_GROUP")).toEqual({ dataId: "a", group: "DEFAULT_GROUP" });
|
||||
expect(parseNacosRawQuery("")).toBeUndefined();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { NacosApiPlane, NacosConfigHistoryItem, NacosConfigItem, NacosConfigKey, NacosContentMatch, NacosImplementation, NacosInstanceInfo, NacosPermissionInfo, NacosRawRequest, NacosServiceInfo, NacosVersionMode } from "@/types/nacos";
|
||||
import type { NacosAdminConfig, NacosApiPlane, NacosConfigHistoryItem, NacosConfigItem, NacosConfigKey, NacosContentMatch, NacosImplementation, NacosInstanceInfo, NacosPermissionInfo, NacosRawRequest, NacosServiceInfo, NacosVersionMode } from "@/types/nacos";
|
||||
import { diffArrays, diffChars } from "diff";
|
||||
|
||||
export type NacosRawTemplateKey = "serverState" | "namespaceList" | "configDetail" | "serviceList" | "instanceList";
|
||||
@@ -62,6 +62,65 @@ export interface NacosEndpointNormalizationOptions {
|
||||
contextPath?: string;
|
||||
}
|
||||
|
||||
export interface NacosMetadataTableRow {
|
||||
key: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
/** Makes a metadata object readable in a two-column view without losing nested values. */
|
||||
export function nacosMetadataTableRows(metadata: unknown): NacosMetadataTableRow[] {
|
||||
if (!metadata || typeof metadata !== "object") return [];
|
||||
return Object.entries(metadata as Record<string, unknown>).map(([key, value]) => ({
|
||||
key,
|
||||
value: typeof value === "string" ? value : (JSON.stringify(value) ?? String(value)),
|
||||
}));
|
||||
}
|
||||
|
||||
/** Validates a browser-only Nacos console URL without mixing credentials into a saved connection profile. */
|
||||
export function normalizeNacosConsoleUrl(input: string): string {
|
||||
let url: URL;
|
||||
try {
|
||||
url = new URL(input.trim());
|
||||
} catch {
|
||||
throw new Error("Nacos console URL must be a valid absolute URL");
|
||||
}
|
||||
if (!["http:", "https:"].includes(url.protocol)) throw new Error("Nacos console URL must use HTTP or HTTPS");
|
||||
if (url.username || url.password) throw new Error("Nacos console URL must not contain embedded credentials");
|
||||
return url.toString().replace(/\/$/, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the web-console address independently from DBX's API connection.
|
||||
* Nacos 3 must be configured explicitly because its Console port can differ
|
||||
* from its Admin API port. Nacos 2 keeps the historical same-endpoint fallback.
|
||||
*/
|
||||
function resolveNacosConsoleUrlFromServer(serverAddr: string, contextPath: string | undefined, fallbackPath: string): string {
|
||||
const endpoint = new URL(normalizeNacosConsoleUrl(serverAddr));
|
||||
const normalizedContextPath = contextPath?.trim().replace(/^\/+|\/+$/g, "");
|
||||
endpoint.pathname = normalizedContextPath ? `/${normalizedContextPath}` : fallbackPath || "/";
|
||||
endpoint.search = "";
|
||||
endpoint.hash = "";
|
||||
return endpoint.toString().replace(/\/$/, "");
|
||||
}
|
||||
|
||||
export function resolveNacosConsoleUrl(config: Pick<NacosAdminConfig, "implementation" | "versionMode" | "apiPlane" | "serverAddr" | "contextPath" | "consoleUrl" | "rnacosConsoleAddr">): string | undefined {
|
||||
// A Nacos 3 Console API connection already targets the browser console.
|
||||
// Prefer its primary endpoint even for legacy profiles that kept a stale
|
||||
// standalone console URL.
|
||||
if (config.versionMode === "v3" && config.apiPlane === "console") {
|
||||
const serverAddr = config.serverAddr?.trim();
|
||||
return serverAddr ? resolveNacosConsoleUrlFromServer(serverAddr, config.contextPath, "") : undefined;
|
||||
}
|
||||
if (config.implementation === "rnacos" || (!config.implementation && config.rnacosConsoleAddr?.trim())) {
|
||||
return config.rnacosConsoleAddr?.trim() ? normalizeNacosConsoleUrl(config.rnacosConsoleAddr) : undefined;
|
||||
}
|
||||
if (config.versionMode === "v3") return config.consoleUrl?.trim() ? normalizeNacosConsoleUrl(config.consoleUrl) : undefined;
|
||||
|
||||
const serverAddr = config.serverAddr?.trim();
|
||||
if (!serverAddr) return undefined;
|
||||
return resolveNacosConsoleUrlFromServer(serverAddr, config.contextPath, "/nacos");
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits a pasted browser/API URL into the persisted origin and API context.
|
||||
* We only strip documented Nacos 3 UI routes; every other prefix remains an
|
||||
|
||||
Reference in new issue
Block a user