From e0fb6d68835e5c3f96365eb17107c28b8c2e91a6 Mon Sep 17 00:00:00 2001 From: miloschwartz Date: Fri, 2 Oct 2026 16:52:31 -0400 Subject: [PATCH] add descriptions to the rewrite modals --- messages/en-US.json | 3 +- src/components/PathMatchRenameModal.tsx | 204 +++++++++++++----------- 2 files changed, 117 insertions(+), 90 deletions(-) diff --git a/messages/en-US.json b/messages/en-US.json index 10b20c4fd..f74f72444 100644 --- a/messages/en-US.json +++ b/messages/en-US.json @@ -3540,7 +3540,7 @@ "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.", + "pathRewriteModalDescription": "Transform the matched path before forwarding to the destination.", "pathRewriteType": "Rewrite Type", "pathRewritePrefixOption": "Prefix - Replace prefix", "pathRewriteExactOption": "Exact - Replace entire path", @@ -3557,6 +3557,7 @@ "pathRewriteExact": "Exact", "pathRewriteRegex": "Regex", "pathRewriteStrip": "Strip", + "pathRewriteStripPrefix": "Strip Prefix", "pathRewriteStripLabel": "strip", "sidebarEnableEnterpriseLicense": "Enable Enterprise License", "cannotbeUndone": "This can not be undone.", diff --git a/src/components/PathMatchRenameModal.tsx b/src/components/PathMatchRenameModal.tsx index 6474da6b9..7f9b30de7 100644 --- a/src/components/PathMatchRenameModal.tsx +++ b/src/components/PathMatchRenameModal.tsx @@ -1,11 +1,8 @@ import { Settings } from "lucide-react"; import { - Select, - SelectContent, - SelectItem, - SelectTrigger, - SelectValue -} from "@/components/ui/select"; + DescribedSelect, + type DescribedSelectOption +} from "@app/components/DescribedSelect"; import { Badge } from "@app/components/ui/badge"; import { Label } from "@app/components/ui/label"; @@ -24,6 +21,30 @@ import { } from "./Credenza"; import { useTranslations } from "next-intl"; +type PathMatchType = "prefix" | "exact" | "regex"; +type RewritePathType = "prefix" | "exact" | "regex" | "stripPrefix"; + +const pathMatchTypes: PathMatchType[] = ["prefix", "exact", "regex"]; + +function isPathMatchType( + value: string | null | undefined +): value is PathMatchType { + return pathMatchTypes.includes(value as PathMatchType); +} + +const rewritePathTypes: RewritePathType[] = [ + "prefix", + "exact", + "regex", + "stripPrefix" +]; + +function isRewritePathType( + value: string | null | undefined +): value is RewritePathType { + return rewritePathTypes.includes(value as RewritePathType); +} + export function PathMatchModal({ value, onChange, @@ -39,20 +60,42 @@ export function PathMatchModal({ const t = useTranslations(); const [open, setOpen] = useState(false); - const [matchType, setMatchType] = useState( - value?.pathMatchType || "prefix" + const [matchType, setMatchType] = useState( + isPathMatchType(value?.pathMatchType) ? value.pathMatchType : "prefix" ); const [path, setPath] = useState(value?.path || ""); + const matchOptions: DescribedSelectOption[] = [ + { + value: "prefix", + title: t("pathMatchPrefix"), + description: t("pathMatchPrefixHelp") + }, + { + value: "exact", + title: t("pathMatchExact"), + description: t("pathMatchExactHelp") + }, + { + value: "regex", + title: t("pathMatchRegex"), + description: t("pathMatchRegexHelp") + } + ]; + useEffect(() => { if (open) { - setMatchType(value?.pathMatchType || "prefix"); + setMatchType( + isPathMatchType(value?.pathMatchType) + ? value.pathMatchType + : "prefix" + ); setPath(value?.path || ""); } }, [open, value]); const handleSave = () => { - onChange({ pathMatchType: matchType as any, path: path.trim() }); + onChange({ pathMatchType: matchType, path: path.trim() }); setOpen(false); }; @@ -66,19 +109,6 @@ export function PathMatchModal({ ? t("pathMatchRegexPlaceholder") : t("pathMatchDefaultPlaceholder"); - const getHelpText = () => { - switch (matchType) { - case "prefix": - return t("pathMatchPrefixHelp"); - case "exact": - return t("pathMatchExactHelp"); - case "regex": - return t("pathMatchRegexHelp"); - default: - return ""; - } - }; - return ( {trigger} @@ -91,23 +121,21 @@ export function PathMatchModal({
- - + + + options={matchOptions} + value={matchType} + onChange={setMatchType} + searchPlaceholder={t("search")} + emptyMessage={t("noResults")} + /> +

+ { + matchOptions.find( + (option) => option.value === matchType + )?.description + } +

@@ -155,21 +180,50 @@ export function PathRewriteModal({ }) { const t = useTranslations(); const [open, setOpen] = useState(false); - const [rewriteType, setRewriteType] = useState( - value?.rewritePathType || "prefix" + const [rewriteType, setRewriteType] = useState( + isRewritePathType(value?.rewritePathType) + ? value.rewritePathType + : "prefix" ); const [rewritePath, setRewritePath] = useState(value?.rewritePath || ""); + const rewriteOptions: DescribedSelectOption[] = [ + { + value: "prefix", + title: t("pathRewritePrefix"), + description: t("pathRewritePrefixHelp") + }, + { + value: "exact", + title: t("pathRewriteExact"), + description: t("pathRewriteExactHelp") + }, + { + value: "regex", + title: t("pathRewriteRegex"), + description: t("pathRewriteRegexHelp") + }, + { + value: "stripPrefix", + title: t("pathRewriteStripPrefix"), + description: t("pathRewriteStripPrefixHelp") + } + ]; + useEffect(() => { if (open) { - setRewriteType(value?.rewritePathType || "prefix"); + setRewriteType( + isRewritePathType(value?.rewritePathType) + ? value.rewritePathType + : "prefix" + ); setRewritePath(value?.rewritePath || ""); } }, [open, value]); const handleSave = () => { onChange({ - rewritePathType: rewriteType as any, + rewritePathType: rewriteType, rewritePath: rewritePath.trim() }); setOpen(false); @@ -191,21 +245,6 @@ export function PathRewriteModal({ } }; - 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 ( !disabled && setOpen(v)}> {trigger} @@ -218,31 +257,21 @@ export function PathRewriteModal({
- - + onChange={setRewriteType} + searchPlaceholder={t("search")} + emptyMessage={t("noResults")} + /> +

+ { + rewriteOptions.find( + (option) => option.value === rewriteType + )?.description + } +