import { Settings } from "lucide-react"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { Badge } from "@app/components/ui/badge"; 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"; export function PathMatchModal({ value, onChange, trigger, }: { 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 || ""); useEffect(() => { if (open) { setMatchType(value?.pathMatchType || "prefix"); setPath(value?.path || ""); } }, [open, value]); const handleSave = () => { onChange({ pathMatchType: matchType as any, path: path.trim() }); setOpen(false); }; const handleClear = () => { onChange({ pathMatchType: null, path: null }); setOpen(false); }; const getPlaceholder = () => (matchType === "regex" ? "^/api/.*" : "/path"); 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 ""; } }; return ( {trigger} Configure Path Matching Set up how incoming requests should be matched based on their path. Match Type Prefix Exact Regex Path Value setPath(e.target.value)} /> {getHelpText()} {value?.path && ( Clear )} Save Changes ); } export function PathRewriteModal({ 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; }) { 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]); const handleSave = () => { onChange({ rewritePathType: rewriteType as any, rewritePath: rewritePath.trim() }); 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 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 ""; } }; return ( !disabled && setOpen(v)}> {trigger} Configure Path Rewriting Transform the matched path before forwarding to the target. Rewrite Type Prefix - Replace prefix Exact - Replace entire path Regex - Pattern replacement Strip Prefix - Remove prefix Rewrite Value setRewritePath(e.target.value)} /> {getHelpText()} {value?.rewritePath && ( Clear )} Save Changes ); } export function PathMatchDisplay({ value, }: { value: { path: string | null; pathMatchType: string | null }; }) { if (!value?.path) return null; const getTypeLabel = (type: string | null) => { const labels: Record = { prefix: "Prefix", exact: "Exact", regex: "Regex", }; return labels[type || ""] || type; }; return ( {getTypeLabel(value.pathMatchType)} {value.path} ); } export function PathRewriteDisplay({ value, }: { value: { rewritePath: string | null; rewritePathType: string | null }; }) { if (!value?.rewritePath && value?.rewritePathType !== "stripPrefix") return null; const getTypeLabel = (type: string | null) => { const labels: Record = { prefix: "Prefix", exact: "Exact", regex: "Regex", stripPrefix: "Strip", }; return labels[type || ""] || type; }; return ( {getTypeLabel(value.rewritePathType)} {value.rewritePath || (strip)} ); }
{getHelpText()}
{value.path}
{value.rewritePath || (strip)}