mirror of
https://github.com/fosrl/pangolin.git
synced 2026-10-30 15:39:06 +01:00
♻️ handle priority field
This commit is contained in:
@@ -54,6 +54,7 @@ export default async function RedirectIndexPage(props: RedirectIndexPageProps) {
|
||||
matchPath: redirect.matchPath,
|
||||
rewritePath: redirect.rewritePath,
|
||||
rewritePathType: redirect.rewritePathType,
|
||||
priority: redirect.priority,
|
||||
permanent: redirect.permanent,
|
||||
enabled: redirect.enabled,
|
||||
resourceId: redirect.resourceId,
|
||||
|
||||
@@ -67,6 +67,7 @@ import DomainPicker from "@app/components/DomainPicker";
|
||||
import Link from "next/link";
|
||||
|
||||
const DEFAULT_PATH_MATCH_TYPE = "regex" as const;
|
||||
const DEFAULT_PRIORITY = 100;
|
||||
|
||||
export type ExistingRedirect = GetRedirectResponse["redirect"];
|
||||
|
||||
@@ -132,6 +133,11 @@ export default function RedirectForm({
|
||||
rewritePathType: z
|
||||
.enum(["exact", "prefix", "regex", "stripPrefix"])
|
||||
.nullable(),
|
||||
priority: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1, { message: t("redirectPriorityInvalid") })
|
||||
.max(1000, { message: t("redirectPriorityInvalid") }),
|
||||
permanent: z.boolean(),
|
||||
enabled: z.boolean()
|
||||
})
|
||||
@@ -193,6 +199,7 @@ export default function RedirectForm({
|
||||
matchPath: redirect?.matchPath ?? null,
|
||||
rewritePath: redirect?.rewritePath ?? null,
|
||||
rewritePathType: redirect?.rewritePathType ?? null,
|
||||
priority: redirect?.priority ?? DEFAULT_PRIORITY,
|
||||
permanent: redirect?.permanent ?? false,
|
||||
enabled: redirect?.enabled ?? true
|
||||
}
|
||||
@@ -248,6 +255,7 @@ export default function RedirectForm({
|
||||
matchPath: values.matchPath?.trim() || null,
|
||||
rewritePath: values.rewritePath?.trim() || null,
|
||||
rewritePathType: values.rewritePathType,
|
||||
priority: values.priority,
|
||||
permanent: values.permanent,
|
||||
enabled: values.enabled
|
||||
};
|
||||
@@ -792,6 +800,40 @@ export default function RedirectForm({
|
||||
/>
|
||||
</SettingsFormCell>
|
||||
|
||||
<SettingsFormCell span="half">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="priority"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>
|
||||
{t("priority")}
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
type="number"
|
||||
min={1}
|
||||
max={1000}
|
||||
{...field}
|
||||
onChange={(e) =>
|
||||
field.onChange(
|
||||
e.target
|
||||
.valueAsNumber
|
||||
)
|
||||
}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormDescription>
|
||||
{t(
|
||||
"priorityDescription"
|
||||
)}
|
||||
</FormDescription>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</SettingsFormCell>
|
||||
|
||||
<SettingsFormCell span="full">
|
||||
<FormField
|
||||
control={form.control}
|
||||
|
||||
@@ -22,9 +22,12 @@ import { createApiClient, formatAxiosError } from "@app/lib/api";
|
||||
import type { GetBatchedCertificateResponse } from "@server/routers/certificates/types";
|
||||
import type { PaginationState } from "@tanstack/react-table";
|
||||
import {
|
||||
ArrowDown,
|
||||
ArrowRight,
|
||||
ArrowUp,
|
||||
ArrowUpRight,
|
||||
GlobeIcon,
|
||||
MinusIcon,
|
||||
MoreHorizontal,
|
||||
WaypointsIcon
|
||||
} from "lucide-react";
|
||||
@@ -52,6 +55,7 @@ export type RedirectRow = {
|
||||
matchPath: string | null;
|
||||
rewritePath: string | null;
|
||||
rewritePathType: "exact" | "prefix" | "regex" | "stripPrefix" | null;
|
||||
priority: number | null;
|
||||
permanent: boolean;
|
||||
enabled: boolean;
|
||||
resourceId: number | null;
|
||||
@@ -286,9 +290,7 @@ export default function RedirectsTable({
|
||||
{redirect.matchPath && (
|
||||
<span className="text-muted-foreground">
|
||||
{redirect.pathMatchType === "prefix"
|
||||
? withPrefixGlob(
|
||||
redirect.matchPath
|
||||
)
|
||||
? withPrefixGlob(redirect.matchPath)
|
||||
: redirect.matchPath}
|
||||
</span>
|
||||
)}
|
||||
@@ -320,6 +322,28 @@ export default function RedirectsTable({
|
||||
);
|
||||
}
|
||||
},
|
||||
{
|
||||
accessorKey: "priority",
|
||||
friendlyName: t("priority"),
|
||||
header: () => <span className="p-3">{t("priority")}</span>,
|
||||
cell: ({ row }) => {
|
||||
// 100 is the automatic default; anything else was set
|
||||
// deliberately, so flag which way it deviates.
|
||||
const priority = row.original.priority ?? 100;
|
||||
return (
|
||||
<span className="inline-flex items-center gap-1">
|
||||
{priority}
|
||||
{priority > 100 ? (
|
||||
<ArrowUp className="size-3 text-green-500" />
|
||||
) : priority < 100 ? (
|
||||
<ArrowDown className="size-3 text-red-500" />
|
||||
) : (
|
||||
<MinusIcon className="size-3 text-muted-foreground" />
|
||||
)}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
},
|
||||
{
|
||||
accessorKey: "permanent",
|
||||
friendlyName: t("redirectType"),
|
||||
@@ -439,7 +463,8 @@ export default function RedirectsTable({
|
||||
columnVisibility={{
|
||||
attachedTo: false,
|
||||
niceId: false,
|
||||
permanent: false
|
||||
permanent: false,
|
||||
priority: false
|
||||
}}
|
||||
enableColumnVisibility
|
||||
stickyLeftColumn="name"
|
||||
|
||||
Reference in New Issue
Block a user