vmui/vmanomaly: fix default server url (#6178)

This PR for ui vmanomaly eliminates URL parameters to automatically use
the default server URL, simplifying URLs like:

From http://localhost:3000/#/?g0.expr=vm_blocks... to
http://localhost:3000
From http://localhost:3000/select/0/vmui/#/?g0.expr=vm_blocks... to
http://localhost:3000/select/0/vmui/ etc.

(cherry picked from commit 29bd120126)
This commit is contained in:
Yury Molodov 2024-05-13 12:24:50 +02:00 committed by hagen1778
parent 3c645c4a79
commit e430ab1999
No known key found for this signature in database
GPG Key ID: 3BF75F3741CA9640

View File

@ -8,7 +8,7 @@ export const getDefaultServer = (tenantId?: string): string => {
const { serverURL } = getAppModeParams(); const { serverURL } = getAppModeParams();
const storageURL = getFromStorage("SERVER_URL") as string; const storageURL = getFromStorage("SERVER_URL") as string;
const logsURL = window.location.href.replace(/\/(select\/)?(vmui)\/.*/, ""); const logsURL = window.location.href.replace(/\/(select\/)?(vmui)\/.*/, "");
const anomalyURL = window.location.href.replace(/(?:graph|vmui)\/.*/, ""); const anomalyURL = `${window.location.origin}${window.location.pathname}`;
const defaultURL = window.location.href.replace(/\/(?:prometheus\/)?(?:graph|vmui)\/.*/, "/prometheus"); const defaultURL = window.location.href.replace(/\/(?:prometheus\/)?(?:graph|vmui)\/.*/, "/prometheus");
const url = serverURL || storageURL || defaultURL; const url = serverURL || storageURL || defaultURL;
@ -16,7 +16,7 @@ export const getDefaultServer = (tenantId?: string): string => {
case AppType.logs: case AppType.logs:
return logsURL; return logsURL;
case AppType.anomaly: case AppType.anomaly:
return serverURL || storageURL || anomalyURL; return storageURL || anomalyURL;
default: default:
return tenantId ? replaceTenantId(url, tenantId) : url; return tenantId ? replaceTenantId(url, tenantId) : url;
} }