mirror of
https://github.com/fosrl/pangolin.git
synced 2026-06-10 17:43:15 +00:00
Fix type error
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user