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

View File

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

View File

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