mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-02 08:09:10 +00:00
Path rewriting working?
This commit is contained in:
@@ -1860,5 +1860,38 @@
|
||||
},
|
||||
"priority": "Priority",
|
||||
"priorityDescription": "Higher priority routes are evaluated first. Priority = 100 means automatic ordering (system decides). Use another number to enforce manual priority.",
|
||||
"instanceName": "Instance Name"
|
||||
"instanceName": "Instance Name",
|
||||
"pathMatchModalTitle": "Configure Path Matching",
|
||||
"pathMatchModalDescription": "Set up how incoming requests should be matched based on their path.",
|
||||
"pathMatchType": "Match Type",
|
||||
"pathMatchPrefix": "Prefix",
|
||||
"pathMatchExact": "Exact",
|
||||
"pathMatchRegex": "Regex",
|
||||
"pathMatchValue": "Path Value",
|
||||
"clear": "Clear",
|
||||
"saveChanges": "Save Changes",
|
||||
"pathMatchRegexPlaceholder": "^/api/.*",
|
||||
"pathMatchDefaultPlaceholder": "/path",
|
||||
"pathMatchPrefixHelp": "Example: /api matches /api, /api/users, etc.",
|
||||
"pathMatchExactHelp": "Example: /api matches only /api",
|
||||
"pathMatchRegexHelp": "Example: ^/api/.* matches /api/anything",
|
||||
"pathRewriteModalTitle": "Configure Path Rewriting",
|
||||
"pathRewriteModalDescription": "Transform the matched path before forwarding to the target.",
|
||||
"pathRewriteType": "Rewrite Type",
|
||||
"pathRewritePrefixOption": "Prefix - Replace prefix",
|
||||
"pathRewriteExactOption": "Exact - Replace entire path",
|
||||
"pathRewriteRegexOption": "Regex - Pattern replacement",
|
||||
"pathRewriteStripPrefixOption": "Strip Prefix - Remove prefix",
|
||||
"pathRewriteValue": "Rewrite Value",
|
||||
"pathRewriteRegexPlaceholder": "/new/$1",
|
||||
"pathRewriteDefaultPlaceholder": "/new-path",
|
||||
"pathRewritePrefixHelp": "Replace the matched prefix with this value",
|
||||
"pathRewriteExactHelp": "Replace the entire path with this value when the path matches exactly",
|
||||
"pathRewriteRegexHelp": "Use capture groups like $1, $2 for replacement",
|
||||
"pathRewriteStripPrefixHelp": "Leave empty to strip prefix or provide new prefix",
|
||||
"pathRewritePrefix": "Prefix",
|
||||
"pathRewriteExact": "Exact",
|
||||
"pathRewriteRegex": "Regex",
|
||||
"pathRewriteStrip": "Strip",
|
||||
"pathRewriteStripLabel": "strip"
|
||||
}
|
||||
|
||||
@@ -164,9 +164,6 @@ export async function getTraefikConfig(
|
||||
port: row.port,
|
||||
internalPort: row.internalPort,
|
||||
enabled: row.targetEnabled,
|
||||
rewritePath: row.rewritePath,
|
||||
rewritePathType: row.rewritePathType,
|
||||
priority: row.priority,
|
||||
site: {
|
||||
siteId: row.siteId,
|
||||
type: row.siteType,
|
||||
@@ -268,8 +265,8 @@ export async function getTraefikConfig(
|
||||
|
||||
// Handle path rewriting middleware
|
||||
if (
|
||||
resource.rewritePath &&
|
||||
resource.path &&
|
||||
resource.rewritePath !== null &&
|
||||
resource.path !== null &&
|
||||
resource.pathMatchType &&
|
||||
resource.rewritePathType
|
||||
) {
|
||||
|
||||
@@ -203,9 +203,6 @@ export async function getTraefikConfig(
|
||||
port: row.port,
|
||||
internalPort: row.internalPort,
|
||||
enabled: row.targetEnabled,
|
||||
rewritePath: row.rewritePath,
|
||||
rewritePathType: row.rewritePathType,
|
||||
priority: row.priority,
|
||||
site: {
|
||||
siteId: row.siteId,
|
||||
type: row.siteType,
|
||||
@@ -330,8 +327,8 @@ export async function getTraefikConfig(
|
||||
|
||||
// Handle path rewriting middleware
|
||||
if (
|
||||
resource.rewritePath &&
|
||||
resource.path &&
|
||||
resource.rewritePath !== null &&
|
||||
resource.path !== null &&
|
||||
resource.pathMatchType &&
|
||||
resource.rewritePathType
|
||||
) {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { Settings } from "lucide-react";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue
|
||||
} from "@/components/ui/select";
|
||||
|
||||
import { Badge } from "@app/components/ui/badge";
|
||||
@@ -12,275 +12,324 @@ import { Label } from "@app/components/ui/label";
|
||||
import { useEffect, useState } from "react";
|
||||
import { Input } from "./ui/input";
|
||||
import { Button } from "./ui/button";
|
||||
import { Credenza, CredenzaContent, CredenzaDescription, CredenzaFooter, CredenzaHeader, CredenzaTitle, CredenzaTrigger } from "./Credenza";
|
||||
|
||||
import {
|
||||
Credenza,
|
||||
CredenzaContent,
|
||||
CredenzaDescription,
|
||||
CredenzaFooter,
|
||||
CredenzaHeader,
|
||||
CredenzaTitle,
|
||||
CredenzaTrigger
|
||||
} from "./Credenza";
|
||||
import { useTranslations } from "next-intl";
|
||||
|
||||
export function PathMatchModal({
|
||||
value,
|
||||
onChange,
|
||||
trigger,
|
||||
value,
|
||||
onChange,
|
||||
trigger
|
||||
}: {
|
||||
value: { path: string | null; pathMatchType: string | null };
|
||||
onChange: (config: { path: string | null; pathMatchType: string | null }) => void;
|
||||
trigger: React.ReactNode;
|
||||
value: { path: string | null; pathMatchType: string | null };
|
||||
onChange: (config: {
|
||||
path: string | null;
|
||||
pathMatchType: string | null;
|
||||
}) => void;
|
||||
trigger: React.ReactNode;
|
||||
}) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [matchType, setMatchType] = useState(value?.pathMatchType || "prefix");
|
||||
const [path, setPath] = useState(value?.path || "");
|
||||
const t = useTranslations();
|
||||
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
setMatchType(value?.pathMatchType || "prefix");
|
||||
setPath(value?.path || "");
|
||||
}
|
||||
}, [open, value]);
|
||||
const [open, setOpen] = useState(false);
|
||||
const [matchType, setMatchType] = useState(
|
||||
value?.pathMatchType || "prefix"
|
||||
);
|
||||
const [path, setPath] = useState(value?.path || "");
|
||||
|
||||
const handleSave = () => {
|
||||
onChange({ pathMatchType: matchType as any, path: path.trim() });
|
||||
setOpen(false);
|
||||
};
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
setMatchType(value?.pathMatchType || "prefix");
|
||||
setPath(value?.path || "");
|
||||
}
|
||||
}, [open, value]);
|
||||
|
||||
const handleClear = () => {
|
||||
onChange({ pathMatchType: null, path: null });
|
||||
setOpen(false);
|
||||
};
|
||||
const handleSave = () => {
|
||||
onChange({ pathMatchType: matchType as any, path: path.trim() });
|
||||
setOpen(false);
|
||||
};
|
||||
|
||||
const getPlaceholder = () => (matchType === "regex" ? "^/api/.*" : "/path");
|
||||
const handleClear = () => {
|
||||
onChange({ pathMatchType: null, path: null });
|
||||
setOpen(false);
|
||||
};
|
||||
|
||||
const getHelpText = () => {
|
||||
switch (matchType) {
|
||||
case "prefix":
|
||||
return "Example: /api matches /api, /api/users, etc.";
|
||||
case "exact":
|
||||
return "Example: /api matches only /api";
|
||||
case "regex":
|
||||
return "Example: ^/api/.* matches /api/anything";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
};
|
||||
const getPlaceholder = () => (matchType === "regex" ? t("pathMatchRegexPlaceholder") : t("pathMatchDefaultPlaceholder"));
|
||||
|
||||
return (
|
||||
<Credenza open={open} onOpenChange={setOpen}>
|
||||
<CredenzaTrigger asChild>{trigger}</CredenzaTrigger>
|
||||
<CredenzaContent className="sm:max-w-[500px]">
|
||||
<CredenzaHeader>
|
||||
<CredenzaTitle>Configure Path Matching</CredenzaTitle>
|
||||
<CredenzaDescription>
|
||||
Set up how incoming requests should be matched based on their path.
|
||||
</CredenzaDescription>
|
||||
</CredenzaHeader>
|
||||
<div className="grid gap-4">
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="match-type">Match Type</Label>
|
||||
<Select value={matchType} onValueChange={setMatchType}>
|
||||
<SelectTrigger id="match-type">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="prefix">Prefix</SelectItem>
|
||||
<SelectItem value="exact">Exact</SelectItem>
|
||||
<SelectItem value="regex">Regex</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="path-value">Path Value</Label>
|
||||
<Input
|
||||
id="path-value"
|
||||
placeholder={getPlaceholder()}
|
||||
value={path}
|
||||
onChange={(e) => setPath(e.target.value)}
|
||||
/>
|
||||
<p className="text-sm text-muted-foreground">{getHelpText()}</p>
|
||||
</div>
|
||||
</div>
|
||||
<CredenzaFooter className="gap-2">
|
||||
{value?.path && (
|
||||
<Button variant="outline" onClick={handleClear}>
|
||||
Clear
|
||||
</Button>
|
||||
)}
|
||||
<Button onClick={handleSave} disabled={!path.trim()}>
|
||||
Save Changes
|
||||
</Button>
|
||||
</CredenzaFooter>
|
||||
</CredenzaContent>
|
||||
</Credenza>
|
||||
);
|
||||
const getHelpText = () => {
|
||||
switch (matchType) {
|
||||
case "prefix":
|
||||
return t("pathMatchPrefixHelp");
|
||||
case "exact":
|
||||
return t("pathMatchExactHelp");
|
||||
case "regex":
|
||||
return t("pathMatchRegexHelp");
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Credenza open={open} onOpenChange={setOpen}>
|
||||
<CredenzaTrigger asChild>{trigger}</CredenzaTrigger>
|
||||
<CredenzaContent className="sm:max-w-[500px]">
|
||||
<CredenzaHeader>
|
||||
<CredenzaTitle>{t("pathMatchModalTitle")}</CredenzaTitle>
|
||||
<CredenzaDescription>
|
||||
{t("pathMatchModalDescription")}
|
||||
</CredenzaDescription>
|
||||
</CredenzaHeader>
|
||||
<div className="grid gap-4">
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="match-type">{t("pathMatchType")}</Label>
|
||||
<Select value={matchType} onValueChange={setMatchType}>
|
||||
<SelectTrigger id="match-type">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="prefix">{t("pathMatchPrefix")}</SelectItem>
|
||||
<SelectItem value="exact">{t("pathMatchExact")}</SelectItem>
|
||||
<SelectItem value="regex">{t("pathMatchRegex")}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="path-value">{t("pathMatchValue")}</Label>
|
||||
<Input
|
||||
id="path-value"
|
||||
placeholder={getPlaceholder()}
|
||||
value={path}
|
||||
onChange={(e) => setPath(e.target.value)}
|
||||
/>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{getHelpText()}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<CredenzaFooter className="gap-2">
|
||||
{value?.path && (
|
||||
<Button variant="outline" onClick={handleClear}>
|
||||
{t("clear")}
|
||||
</Button>
|
||||
)}
|
||||
<Button onClick={handleSave} disabled={!path.trim()}>
|
||||
{t("saveChanges")}
|
||||
</Button>
|
||||
</CredenzaFooter>
|
||||
</CredenzaContent>
|
||||
</Credenza>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
export function PathRewriteModal({
|
||||
value,
|
||||
onChange,
|
||||
trigger,
|
||||
disabled,
|
||||
value,
|
||||
onChange,
|
||||
trigger,
|
||||
disabled
|
||||
}: {
|
||||
value: { rewritePath: string | null; rewritePathType: string | null };
|
||||
onChange: (config: { rewritePath: string | null; rewritePathType: string | null }) => void;
|
||||
trigger: React.ReactNode;
|
||||
disabled?: boolean;
|
||||
value: { rewritePath: string | null; rewritePathType: string | null };
|
||||
onChange: (config: {
|
||||
rewritePath: string | null;
|
||||
rewritePathType: string | null;
|
||||
}) => void;
|
||||
trigger: React.ReactNode;
|
||||
disabled?: boolean;
|
||||
}) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [rewriteType, setRewriteType] = useState(value?.rewritePathType || "prefix");
|
||||
const [rewritePath, setRewritePath] = useState(value?.rewritePath || "");
|
||||
const t = useTranslations();
|
||||
const [open, setOpen] = useState(false);
|
||||
const [rewriteType, setRewriteType] = useState(
|
||||
value?.rewritePathType || "prefix"
|
||||
);
|
||||
const [rewritePath, setRewritePath] = useState(value?.rewritePath || "");
|
||||
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
setRewriteType(value?.rewritePathType || "prefix");
|
||||
setRewritePath(value?.rewritePath || "");
|
||||
}
|
||||
}, [open, value]);
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
setRewriteType(value?.rewritePathType || "prefix");
|
||||
setRewritePath(value?.rewritePath || "");
|
||||
}
|
||||
}, [open, value]);
|
||||
|
||||
const handleSave = () => {
|
||||
onChange({ rewritePathType: rewriteType as any, rewritePath: rewritePath.trim() });
|
||||
setOpen(false);
|
||||
};
|
||||
const handleSave = () => {
|
||||
onChange({
|
||||
rewritePathType: rewriteType as any,
|
||||
rewritePath: rewritePath.trim()
|
||||
});
|
||||
setOpen(false);
|
||||
};
|
||||
|
||||
const handleClear = () => {
|
||||
onChange({ rewritePathType: null, rewritePath: null });
|
||||
setOpen(false);
|
||||
};
|
||||
const handleClear = () => {
|
||||
onChange({ rewritePathType: null, rewritePath: null });
|
||||
setOpen(false);
|
||||
};
|
||||
|
||||
const getPlaceholder = () => {
|
||||
switch (rewriteType) {
|
||||
case "regex":
|
||||
return "/new/$1";
|
||||
case "stripPrefix":
|
||||
return "";
|
||||
default:
|
||||
return "/new-path";
|
||||
}
|
||||
};
|
||||
const getPlaceholder = () => {
|
||||
switch (rewriteType) {
|
||||
case "regex":
|
||||
return t("pathRewriteRegexPlaceholder");
|
||||
case "stripPrefix":
|
||||
return "";
|
||||
default:
|
||||
return t("pathRewriteDefaultPlaceholder");
|
||||
}
|
||||
};
|
||||
|
||||
const getHelpText = () => {
|
||||
switch (rewriteType) {
|
||||
case "prefix":
|
||||
return "Replace the matched prefix with this value";
|
||||
case "exact":
|
||||
return "Replace the entire path with this value";
|
||||
case "regex":
|
||||
return "Use capture groups like $1, $2 for replacement";
|
||||
case "stripPrefix":
|
||||
return "Leave empty to strip prefix or provide new prefix";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
};
|
||||
const getHelpText = () => {
|
||||
switch (rewriteType) {
|
||||
case "prefix":
|
||||
return t("pathRewritePrefixHelp");
|
||||
case "exact":
|
||||
return t("pathRewriteExactHelp");
|
||||
case "regex":
|
||||
return t("pathRewriteRegexHelp");
|
||||
case "stripPrefix":
|
||||
return t("pathRewriteStripPrefixHelp");
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Credenza open={open} onOpenChange={(v) => !disabled && setOpen(v)}>
|
||||
<CredenzaTrigger asChild>
|
||||
{trigger}
|
||||
</CredenzaTrigger>
|
||||
<CredenzaContent className="sm:max-w-[500px]">
|
||||
<CredenzaHeader>
|
||||
<CredenzaTitle>Configure Path Rewriting</CredenzaTitle>
|
||||
<CredenzaDescription>
|
||||
Transform the matched path before forwarding to the target.
|
||||
</CredenzaDescription>
|
||||
</CredenzaHeader>
|
||||
<div className="grid gap-4">
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="rewrite-type">Rewrite Type</Label>
|
||||
<Select value={rewriteType} onValueChange={setRewriteType}>
|
||||
<SelectTrigger id="rewrite-type">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="prefix">Prefix - Replace prefix</SelectItem>
|
||||
<SelectItem value="exact">Exact - Replace entire path</SelectItem>
|
||||
<SelectItem value="regex">Regex - Pattern replacement</SelectItem>
|
||||
<SelectItem value="stripPrefix">Strip Prefix - Remove prefix</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="rewrite-value">Rewrite Value</Label>
|
||||
<Input
|
||||
id="rewrite-value"
|
||||
placeholder={getPlaceholder()}
|
||||
value={rewritePath}
|
||||
onChange={(e) => setRewritePath(e.target.value)}
|
||||
/>
|
||||
<p className="text-sm text-muted-foreground">{getHelpText()}</p>
|
||||
</div>
|
||||
</div>
|
||||
<CredenzaFooter className="gap-2">
|
||||
{value?.rewritePath && (
|
||||
<Button variant="outline" onClick={handleClear}>
|
||||
Clear
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
onClick={handleSave}
|
||||
disabled={rewriteType !== "stripPrefix" && !rewritePath.trim()}
|
||||
>
|
||||
Save Changes
|
||||
</Button>
|
||||
</CredenzaFooter>
|
||||
</CredenzaContent>
|
||||
</Credenza>
|
||||
);
|
||||
return (
|
||||
<Credenza open={open} onOpenChange={(v) => !disabled && setOpen(v)}>
|
||||
<CredenzaTrigger asChild>{trigger}</CredenzaTrigger>
|
||||
<CredenzaContent className="sm:max-w-[500px]">
|
||||
<CredenzaHeader>
|
||||
<CredenzaTitle>{t("pathRewriteModalTitle")}</CredenzaTitle>
|
||||
<CredenzaDescription>
|
||||
{t("pathRewriteModalDescription")}
|
||||
</CredenzaDescription>
|
||||
</CredenzaHeader>
|
||||
<div className="grid gap-4">
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="rewrite-type">{t("pathRewriteType")}</Label>
|
||||
<Select
|
||||
value={rewriteType}
|
||||
onValueChange={setRewriteType}
|
||||
>
|
||||
<SelectTrigger id="rewrite-type">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="prefix">
|
||||
{t("pathRewritePrefixOption")}
|
||||
</SelectItem>
|
||||
<SelectItem value="exact">
|
||||
{t("pathRewriteExactOption")}
|
||||
</SelectItem>
|
||||
<SelectItem value="regex">
|
||||
{t("pathRewriteRegexOption")}
|
||||
</SelectItem>
|
||||
<SelectItem value="stripPrefix">
|
||||
{t("pathRewriteStripPrefixOption")}
|
||||
</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="rewrite-value">{t("pathRewriteValue")}</Label>
|
||||
<Input
|
||||
id="rewrite-value"
|
||||
placeholder={getPlaceholder()}
|
||||
value={rewritePath}
|
||||
onChange={(e) => setRewritePath(e.target.value)}
|
||||
/>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{getHelpText()}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<CredenzaFooter className="gap-2">
|
||||
{value?.rewritePath && (
|
||||
<Button variant="outline" onClick={handleClear}>
|
||||
{t("clear")}
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
onClick={handleSave}
|
||||
disabled={
|
||||
rewriteType !== "stripPrefix" && !rewritePath.trim()
|
||||
}
|
||||
>
|
||||
{t("saveChanges")}
|
||||
</Button>
|
||||
</CredenzaFooter>
|
||||
</CredenzaContent>
|
||||
</Credenza>
|
||||
);
|
||||
}
|
||||
|
||||
export function PathMatchDisplay({
|
||||
value,
|
||||
value
|
||||
}: {
|
||||
value: { path: string | null; pathMatchType: string | null };
|
||||
value: { path: string | null; pathMatchType: string | null };
|
||||
}) {
|
||||
if (!value?.path) return null;
|
||||
const t = useTranslations();
|
||||
|
||||
if (!value?.path) return null;
|
||||
|
||||
const getTypeLabel = (type: string | null) => {
|
||||
const labels: Record<string, string> = {
|
||||
prefix: "Prefix",
|
||||
exact: "Exact",
|
||||
regex: "Regex",
|
||||
const getTypeLabel = (type: string | null) => {
|
||||
const labels: Record<string, string> = {
|
||||
prefix: t("pathMatchPrefix"),
|
||||
exact: t("pathMatchExact"),
|
||||
regex: t("pathMatchRegex")
|
||||
};
|
||||
return labels[type || ""] || type;
|
||||
};
|
||||
return labels[type || ""] || type;
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex items-center gap-2 w-full text-left">
|
||||
<Badge variant="secondary" className="text-xs shrink-0">
|
||||
{getTypeLabel(value.pathMatchType)}
|
||||
</Badge>
|
||||
<code className="text-sm flex-1 truncate" title={value.path}>
|
||||
{value.path}
|
||||
</code>
|
||||
<Settings className="h-4 w-4" />
|
||||
</div>
|
||||
);
|
||||
return (
|
||||
<div className="flex items-center gap-2 w-full text-left">
|
||||
<Badge variant="secondary" className="text-xs shrink-0">
|
||||
{getTypeLabel(value.pathMatchType)}
|
||||
</Badge>
|
||||
<code className="text-sm flex-1 truncate" title={value.path}>
|
||||
{value.path}
|
||||
</code>
|
||||
<Settings className="h-4 w-4" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
export function PathRewriteDisplay({
|
||||
value,
|
||||
value
|
||||
}: {
|
||||
value: { rewritePath: string | null; rewritePathType: string | null };
|
||||
value: { rewritePath: string | null; rewritePathType: string | null };
|
||||
}) {
|
||||
if (!value?.rewritePath && value?.rewritePathType !== "stripPrefix") return null;
|
||||
const t = useTranslations();
|
||||
|
||||
if (!value?.rewritePath && value?.rewritePathType !== "stripPrefix")
|
||||
return null;
|
||||
|
||||
const getTypeLabel = (type: string | null) => {
|
||||
const labels: Record<string, string> = {
|
||||
prefix: "Prefix",
|
||||
exact: "Exact",
|
||||
regex: "Regex",
|
||||
stripPrefix: "Strip",
|
||||
const getTypeLabel = (type: string | null) => {
|
||||
const labels: Record<string, string> = {
|
||||
prefix: t("pathRewritePrefix"),
|
||||
exact: t("pathRewriteExact"),
|
||||
regex: t("pathRewriteRegex"),
|
||||
stripPrefix: t("pathRewriteStrip")
|
||||
};
|
||||
return labels[type || ""] || type;
|
||||
};
|
||||
return labels[type || ""] || type;
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex items-center gap-2 w-full text-left">
|
||||
<Badge variant="secondary" className="text-xs shrink-0">
|
||||
{getTypeLabel(value.rewritePathType)}
|
||||
</Badge>
|
||||
<code className="text-sm flex-1 truncate" title={value.rewritePath || ""}>
|
||||
{value.rewritePath || <span className="text-muted-foreground italic">(strip)</span>}
|
||||
</code>
|
||||
<Settings className="h-4 w-4" />
|
||||
</div>
|
||||
);
|
||||
return (
|
||||
<div className="flex items-center gap-2 w-full text-left">
|
||||
<Badge variant="secondary" className="text-xs shrink-0">
|
||||
{getTypeLabel(value.rewritePathType)}
|
||||
</Badge>
|
||||
<code
|
||||
className="text-sm flex-1 truncate"
|
||||
title={value.rewritePath || ""}
|
||||
>
|
||||
{value.rewritePath || (
|
||||
<span className="text-muted-foreground italic">
|
||||
({t("pathRewriteStripLabel")})
|
||||
</span>
|
||||
)}
|
||||
</code>
|
||||
<Settings className="h-4 w-4" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user