Fix type error

This commit is contained in:
Owen
2026-06-08 12:21:43 -07:00
parent 56c415ca05
commit b81bfcfcee
3 changed files with 14 additions and 3 deletions

View File

@@ -15,9 +15,11 @@ import { useTranslations } from "next-intl";
import { toast } from "@app/hooks/useToast";
import {
createPolicyRulesSectionSchema,
type PolicyRuleMatchType,
validatePolicyRulesForSave,
type PolicyFormValues
} from ".";
import { POLICY_RULE_MATCH_TYPES } from "./policy-access-rule-validation";
import { Button } from "@app/components/ui/button";
import { Plus } from "lucide-react";
@@ -69,6 +71,12 @@ export type PolicyAccessRulesSectionProps =
| PolicyAccessRulesSectionEditProps
| PolicyAccessRulesSectionCreateProps;
const POLICY_RULE_MATCH_SET = new Set<string>(POLICY_RULE_MATCH_TYPES);
function isPolicyRuleMatchType(value: string): value is PolicyRuleMatchType {
return POLICY_RULE_MATCH_SET.has(value);
}
export function PolicyAccessRulesSection(props: PolicyAccessRulesSectionProps) {
if (props.mode === "create") {
return <PolicyAccessRulesSectionCreate {...props} />;
@@ -270,7 +278,7 @@ function PolicyAccessRulesSectionEdit({
.map((r) => ({
ruleId: r.ruleId,
action: r.action as "ACCEPT" | "DROP" | "PASS",
match: r.match,
match: isPolicyRuleMatchType(r.match) ? r.match : "PATH",
value: r.value,
priority: r.priority,
enabled: r.enabled,

View File

@@ -2,6 +2,7 @@
import z from "zod";
import { POLICY_RULE_MATCH_TYPES } from "./policy-access-rule-validation";
import type { PolicyRuleMatchType } from "./policy-access-rule-validation";
export const createPolicySchema = z.object({
name: z.string().min(1).max(255),
@@ -50,7 +51,7 @@ export type PolicyFormValues = z.infer<typeof createPolicySchema>;
export type LocalRule = {
ruleId: number;
action: "ACCEPT" | "DROP" | "PASS";
match: string;
match: PolicyRuleMatchType;
value: string;
priority: number;
enabled: boolean;

View File

@@ -1,7 +1,9 @@
import type { PolicyRuleMatchType } from "./policy-access-rule-validation";
export type PolicyAccessRule = {
ruleId: number;
action: "ACCEPT" | "DROP" | "PASS";
match: string;
match: PolicyRuleMatchType;
value: string;
priority: number;
enabled: boolean;