mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-07-04 19:21:51 +00:00
refactor(ui): share Lighthouse config redirect helper
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
type SearchParams = Promise<Record<string, string | string[] | undefined>>;
|
||||
|
||||
export async function redirectWithSearchParams(
|
||||
searchParams: SearchParams,
|
||||
pathname: string,
|
||||
) {
|
||||
const params = await searchParams;
|
||||
const query = new URLSearchParams();
|
||||
|
||||
Object.entries(params).forEach(([key, value]) => {
|
||||
if (Array.isArray(value)) {
|
||||
value.forEach((item) => query.append(key, item));
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof value === "string") {
|
||||
query.set(key, value);
|
||||
}
|
||||
});
|
||||
|
||||
const queryString = query.toString();
|
||||
redirect(queryString ? `${pathname}?${queryString}` : pathname);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { redirect } from "next/navigation";
|
||||
import { redirectWithSearchParams } from "@/app/(prowler)/lighthouse/_lib/redirect-with-search-params";
|
||||
|
||||
export default async function LighthouseConfigConnectRedirectPage({
|
||||
searchParams,
|
||||
@@ -7,25 +7,3 @@ export default async function LighthouseConfigConnectRedirectPage({
|
||||
}) {
|
||||
await redirectWithSearchParams(searchParams, "/lighthouse/settings/connect");
|
||||
}
|
||||
|
||||
async function redirectWithSearchParams(
|
||||
searchParams: Promise<Record<string, string | string[] | undefined>>,
|
||||
pathname: string,
|
||||
) {
|
||||
const params = await searchParams;
|
||||
const query = new URLSearchParams();
|
||||
|
||||
Object.entries(params).forEach(([key, value]) => {
|
||||
if (Array.isArray(value)) {
|
||||
value.forEach((item) => query.append(key, item));
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof value === "string") {
|
||||
query.set(key, value);
|
||||
}
|
||||
});
|
||||
|
||||
const queryString = query.toString();
|
||||
redirect(queryString ? `${pathname}?${queryString}` : pathname);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { redirect } from "next/navigation";
|
||||
import { redirectWithSearchParams } from "@/app/(prowler)/lighthouse/_lib/redirect-with-search-params";
|
||||
|
||||
export default async function LighthouseConfigSelectModelRedirectPage({
|
||||
searchParams,
|
||||
@@ -10,25 +10,3 @@ export default async function LighthouseConfigSelectModelRedirectPage({
|
||||
"/lighthouse/settings/select-model",
|
||||
);
|
||||
}
|
||||
|
||||
async function redirectWithSearchParams(
|
||||
searchParams: Promise<Record<string, string | string[] | undefined>>,
|
||||
pathname: string,
|
||||
) {
|
||||
const params = await searchParams;
|
||||
const query = new URLSearchParams();
|
||||
|
||||
Object.entries(params).forEach(([key, value]) => {
|
||||
if (Array.isArray(value)) {
|
||||
value.forEach((item) => query.append(key, item));
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof value === "string") {
|
||||
query.set(key, value);
|
||||
}
|
||||
});
|
||||
|
||||
const queryString = query.toString();
|
||||
redirect(queryString ? `${pathname}?${queryString}` : pathname);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user