Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+17
@@ -0,0 +1,17 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { redirectLegacyAdminRoute } from "./legacyAdminRouteRedirect.server";
|
||||
|
||||
describe("redirectLegacyAdminRoute", () => {
|
||||
it("uses a permanent redirect and preserves the query string", () => {
|
||||
const response = redirectLegacyAdminRoute(
|
||||
new Request("https://admin.hivegrid.de/jobs?status=failed"),
|
||||
"system/jobs"
|
||||
);
|
||||
|
||||
expect(response.status).toBe(308);
|
||||
expect(response.headers.get("Location")).toBe(
|
||||
"https://admin.hivegrid.de/system/jobs?status=failed"
|
||||
);
|
||||
});
|
||||
});
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
import { redirect } from "react-router";
|
||||
|
||||
import { adminPath } from "~/utils/app/CanonicalUrlUtils";
|
||||
|
||||
export function redirectLegacyAdminRoute(request: Request, canonicalPath: string): Response {
|
||||
const source = new URL(request.url);
|
||||
const target = new URL(adminPath(canonicalPath, { mode: "host-aware" }), source);
|
||||
target.search = source.search;
|
||||
return redirect(target.toString(), 308);
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { redirectLegacyAdminSettingsRoute } from "./legacyAdminSettingsRedirect.server";
|
||||
|
||||
describe("redirectLegacyAdminSettingsRoute", () => {
|
||||
it("preserves query parameters while redirecting to the canonical settings route", () => {
|
||||
const response = redirectLegacyAdminSettingsRoute(
|
||||
new Request("https://admin.hivegrid.de/sales/settings/leads?source=sidebar"),
|
||||
"settings/leads"
|
||||
);
|
||||
|
||||
expect(response.status).toBe(308);
|
||||
expect(response.headers.get("Location")).toBe(
|
||||
"https://admin.hivegrid.de/settings/leads?source=sidebar"
|
||||
);
|
||||
});
|
||||
});
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
import { redirect } from "react-router";
|
||||
|
||||
import { adminPath } from "~/utils/app/CanonicalUrlUtils";
|
||||
|
||||
export function redirectLegacyAdminSettingsRoute(request: Request, canonicalPath: string): Response {
|
||||
const source = new URL(request.url);
|
||||
const target = new URL(adminPath(canonicalPath, { mode: "host-aware" }), source);
|
||||
target.search = source.search;
|
||||
return redirect(target.toString(), 308);
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
import UrlUtils from "~/utils/app/UrlUtils";
|
||||
|
||||
function pathnameOnly(value: string) {
|
||||
const [path] = value.split(/[?#]/);
|
||||
return UrlUtils.stripTrailingSlash(path || "/") || "/";
|
||||
}
|
||||
|
||||
export function isRouteActive(currentPathname: string, targetHref: string, options?: { exact?: boolean }) {
|
||||
const current = pathnameOnly(currentPathname);
|
||||
const target = pathnameOnly(targetHref);
|
||||
|
||||
if (options?.exact) {
|
||||
return current === target;
|
||||
}
|
||||
|
||||
return current === target || current.startsWith(`${target}/`);
|
||||
}
|
||||
|
||||
export function getBestActiveRouteIndex<T extends { routePath?: string; exact?: boolean }>(items: T[], currentPathname: string) {
|
||||
let bestIndex = -1;
|
||||
let bestLength = -1;
|
||||
|
||||
items.forEach((item, index) => {
|
||||
if (!item.routePath || !isRouteActive(currentPathname, item.routePath, { exact: item.exact })) return;
|
||||
|
||||
const length = pathnameOnly(item.routePath).length;
|
||||
if (length > bestLength) {
|
||||
bestIndex = index;
|
||||
bestLength = length;
|
||||
}
|
||||
});
|
||||
|
||||
return bestIndex;
|
||||
}
|
||||
Reference in new issue
Block a user