MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / PolicyBadgeMenu

Function PolicyBadgeMenu

packages/react/src/components/tool-detail.tsx:409–503  ·  view source on GitHub ↗
(props: {
  toolName: string;
  /** Static (plugin-contributed) tools are policy-matched on their full
   *  address verbatim; dynamic tools on the connection-wildcarded form. */
  staticTool?: boolean;
  policy?: EffectivePolicy;
  onSetPolicy?: (pattern: string, action: ToolPolicyAction) => void;
  onClearPolicy?: (pattern: string, policyId?: string) => void;
  patternForDisplay?: (displayPattern: string) => string;
})

Source from the content-addressed store, hash-verified

407// ---------------------------------------------------------------------------
408
409function PolicyBadgeMenu(props: {
410 toolName: string;
411 /** Static (plugin-contributed) tools are policy-matched on their full
412 * address verbatim; dynamic tools on the connection-wildcarded form. */
413 staticTool?: boolean;
414 policy?: EffectivePolicy;
415 onSetPolicy?: (pattern: string, action: ToolPolicyAction) => void;
416 onClearPolicy?: (pattern: string, policyId?: string) => void;
417 patternForDisplay?: (displayPattern: string) => string;
418}) {
419 const interactive = !!props.onSetPolicy;
420 // The same pattern bridge the tree rows apply — the pattern WRITTEN and the
421 // pattern LOOKED UP must be the same string, or the menu authors rules that
422 // never match and can't see its own rule afterward.
423 const pattern = props.staticTool
424 ? props.toolName
425 : (props.patternForDisplay ?? toPolicyPattern)(props.toolName);
426 // The "Clear" affordance only makes sense when there's a user rule
427 // pinned to this exact tool id — clearing a wildcard rule from a
428 // single tool's detail header would silently affect siblings.
429 const hasExactUserRule = props.policy?.source === "user" && props.policy.pattern === pattern;
430 const currentAction = hasExactUserRule ? props.policy?.action : undefined;
431
432 if (!interactive) {
433 if (!props.policy) return null;
434 const badge = policyBadgeFor(props.policy);
435 if (!badge) return null;
436 return (
437 <Badge variant={badge.variant} title={badge.title} className={badge.className}>
438 {badge.text}
439 </Badge>
440 );
441 }
442
443 // Interactive trigger always renders, even when the effective policy
444 // would otherwise be "silent" (auto-approve plugin-default), so the
445 // user can click it to override.
446 const badge = props.policy ? policyBadgeFor(props.policy) : null;
447 const triggerLabel = badge?.text ?? "Set policy";
448 const triggerVariant = badge?.variant ?? "outline";
449 const triggerTitle = badge?.title ?? "Set policy";
450 const triggerClassName = badge?.className ?? "text-[10px] text-muted-foreground";
451
452 return (
453 <DropdownMenu>
454 <DropdownMenuTrigger asChild>
455 <Button
456 variant="ghost"
457 aria-label={triggerTitle}
458 className="h-auto rounded-none p-0 hover:bg-transparent"
459 >
460 <Badge
461 variant={triggerVariant}
462 title={triggerTitle}
463 className={cn(
464 triggerClassName,
465 "cursor-pointer gap-1 pr-1.5 transition-opacity hover:opacity-80",
466 )}

Callers

nothing calls this directly

Calls 2

cnFunction · 0.90
policyBadgeForFunction · 0.85

Tested by

no test coverage detected