Skip to content

Commit

Permalink
Update ACL port state to show correct value
Browse files Browse the repository at this point in the history
  • Loading branch information
heisbrot committed Aug 13, 2024
1 parent 7822c22 commit f30b8a4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
12 changes: 11 additions & 1 deletion src/modules/access-control/AccessControlModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,16 @@ export function AccessControlModalContent({
if (continuePostureChecksDisabled) return true;
}, [name, continuePostureChecksDisabled]);

const handleProtocolChange = (p: Protocol) => {
setProtocol(p);
if (p == "icmp") {
setPorts([]);
}
if (p == "all") {
setPorts([]);
}
};

return (
<ModalContent maxWidthClass={"max-w-2xl"}>
<ModalHeader
Expand Down Expand Up @@ -322,7 +332,7 @@ export function AccessControlModalContent({
</div>
<Select
value={protocol}
onValueChange={(v) => setProtocol(v as Protocol)}
onValueChange={(v) => handleProtocolChange(v as Protocol)}
>
<SelectTrigger className="w-[140px]">
<div className={"flex items-center gap-3"}>
Expand Down
10 changes: 5 additions & 5 deletions src/modules/access-control/table/AccessControlPortsCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
TooltipProvider,
TooltipTrigger,
} from "@components/Tooltip";
import React, { useMemo, useState } from "react";
import React, { useMemo } from "react";
import { Policy } from "@/interfaces/Policy";

type Props = {
Expand All @@ -19,15 +19,15 @@ export default function AccessControlPortsCell({ policy }: Props) {

const hasPorts = firstRule?.ports && firstRule?.ports.length > 0;

const [firstTwoPorts] = useState(() => {
const firstTwoPorts = useMemo(() => {
if (!hasPorts) return [];
return firstRule?.ports.slice(0, 2) ?? [];
});
}, [hasPorts, firstRule]);

const [otherPorts] = useState(() => {
const otherPorts = useMemo(() => {
if (!hasPorts) return [];
return firstRule?.ports.slice(2) ?? [];
});
}, [hasPorts, firstRule]);

return (
<div className={"flex-1"}>
Expand Down

0 comments on commit f30b8a4

Please sign in to comment.