"use client";
import { useCallback } from "react";
import { IconPlus, IconTrash } from "@tabler/icons-react";
import { Badge } from "@kandev/ui/badge";
import { Button } from "@kandev/ui/button";
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@kandev/ui/card";
import { Input } from "@kandev/ui/input";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@kandev/ui/select";
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@kandev/ui/table";
import type { NetworkPolicyRule } from "@/lib/api/domains/settings-api";
function PolicyRuleRow({
rule,
index,
onUpdate,
onRemove,
}: {
rule: NetworkPolicyRule;
index: number;
onUpdate: (index: number, field: keyof NetworkPolicyRule, val: string) => void;
onRemove: (index: number) => void;
}) {
return (
onUpdate(index, "domain", e.target.value)}
placeholder="*.example.com"
className="text-sm"
/>
onUpdate(index, "include", e.target.value)}
placeholder="Optional pattern"
className="text-sm"
/>
);
}
function PolicyRulesTable({
rules,
onUpdate,
onRemove,
}: {
rules: NetworkPolicyRule[];
onUpdate: (index: number, field: keyof NetworkPolicyRule, val: string) => void;
onRemove: (index: number) => void;
}) {
return (
Domain
Action
Include
{rules.map((rule, idx) => (
))}
);
}
type NetworkPoliciesCardProps = {
rules: NetworkPolicyRule[];
onRulesChange: (rules: NetworkPolicyRule[]) => void;
};
export function NetworkPoliciesCard({ rules, onRulesChange }: NetworkPoliciesCardProps) {
const addRule = useCallback(() => {
onRulesChange([...rules, { domain: "", action: "allow" }]);
}, [rules, onRulesChange]);
const removeRule = useCallback(
(index: number) => {
onRulesChange(rules.filter((_, i) => i !== index));
},
[rules, onRulesChange],
);
const updateRule = useCallback(
(index: number, field: keyof NetworkPolicyRule, val: string) => {
onRulesChange(rules.map((rule, i) => (i === index ? { ...rule, [field]: val } : rule)));
},
[rules, onRulesChange],
);
return (
Network Policies
Define network access rules applied when a sprite is created for this profile.
{rules.length === 0 ? (
No network policy rules configured.
) : (
)}
);
}