| 613 | "relative flex h-auto w-full items-center justify-start gap-2 rounded-none py-2 text-xs font-normal transition-[background-color] duration-150"; |
| 614 | |
| 615 | function PolicyActionMenu(props: { |
| 616 | pattern: string; |
| 617 | /** Action of an existing user rule with this exact pattern, if any. |
| 618 | * When set, the menu shows a "Clear" option and marks the active |
| 619 | * action with a check. */ |
| 620 | current?: ToolPolicyAction; |
| 621 | onSet: (pattern: string, action: ToolPolicyAction) => void; |
| 622 | onClear?: (pattern: string) => void; |
| 623 | align?: "start" | "end"; |
| 624 | /** When true, the trigger is rendered. Otherwise children are not |
| 625 | * emitted at all and the row falls back to its plain layout. */ |
| 626 | triggerLabel: string; |
| 627 | triggerClassName?: string; |
| 628 | }) { |
| 629 | return ( |
| 630 | <DropdownMenu> |
| 631 | <DropdownMenuTrigger asChild> |
| 632 | <Button |
| 633 | variant="ghost" |
| 634 | size="icon-xs" |
| 635 | aria-label={props.triggerLabel} |
| 636 | onClick={(e) => e.stopPropagation()} |
| 637 | className={cn( |
| 638 | "size-5 shrink-0 text-muted-foreground hover:text-foreground", |
| 639 | props.triggerClassName, |
| 640 | )} |
| 641 | > |
| 642 | <MoreHorizontalIcon className="size-3.5" /> |
| 643 | </Button> |
| 644 | </DropdownMenuTrigger> |
| 645 | <DropdownMenuContent align={props.align ?? "end"} onClick={(e) => e.stopPropagation()}> |
| 646 | <DropdownMenuLabel className="font-mono text-xs">{props.pattern}</DropdownMenuLabel> |
| 647 | <DropdownMenuSeparator /> |
| 648 | {POLICY_ACTIONS_IN_ORDER.map((action) => ( |
| 649 | <DropdownMenuItem key={action} onSelect={() => props.onSet(props.pattern, action)}> |
| 650 | <span className="flex-1">{POLICY_ACTION_LABEL[action]}</span> |
| 651 | {props.current === action && ( |
| 652 | <span aria-hidden className="text-muted-foreground"> |
| 653 | ✓ |
| 654 | </span> |
| 655 | )} |
| 656 | </DropdownMenuItem> |
| 657 | ))} |
| 658 | {props.current && props.onClear && ( |
| 659 | <> |
| 660 | <DropdownMenuSeparator /> |
| 661 | <DropdownMenuItem |
| 662 | onSelect={() => props.onClear?.(props.pattern)} |
| 663 | className="text-muted-foreground" |
| 664 | > |
| 665 | Clear |
| 666 | </DropdownMenuItem> |
| 667 | </> |
| 668 | )} |
| 669 | </DropdownMenuContent> |
| 670 | </DropdownMenu> |
| 671 | ); |
| 672 | } |