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

Function AddPolicyForm

packages/react/src/pages/policies.tsx:110–201  ·  view source on GitHub ↗
(props: {
  onSubmit: (input: { owner: Owner; pattern: string; action: ToolPolicyAction }) => void;
  owner: Owner;
  onOwnerChange: (owner: Owner) => void;
  busy: boolean;
})

Source from the content-addressed store, hash-verified

108// ---------------------------------------------------------------------------
109
110function AddPolicyForm(props: {
111 onSubmit: (input: { owner: Owner; pattern: string; action: ToolPolicyAction }) => void;
112 owner: Owner;
113 onOwnerChange: (owner: Owner) => void;
114 busy: boolean;
115}) {
116 const [pattern, setPattern] = useState("");
117 const [action, setAction] = useState<ToolPolicyAction>("require_approval");
118 const valid = isValidPattern(pattern);
119 // Non-org hosts (local/desktop) have one local workspace. New local policies
120 // are org-owned internally to match the v1->v2 migration.
121 const ownerDisplay = useOwnerDisplay();
122 const ownerChoices = ownerDisplay.isSinglePlayerHost
123 ? POLICY_OWNERS.filter((option) => option.owner === "org").map((option) => ({
124 ...option,
125 label: "Local",
126 }))
127 : POLICY_OWNERS;
128
129 return (
130 <form
131 className="flex flex-col gap-3 rounded-xl border border-border bg-card px-5 py-4"
132 onSubmit={(e) => {
133 e.preventDefault();
134 if (!valid) return;
135 props.onSubmit({ owner: props.owner, pattern, action });
136 setPattern("");
137 setAction("require_approval");
138 }}
139 >
140 <div className="flex flex-col gap-1">
141 <Label htmlFor="policy-pattern" className="text-xs font-medium text-foreground/80">
142 Pattern
143 </Label>
144 <Input
145 id="policy-pattern"
146 placeholder="vercel.dns.* or *"
147 value={pattern}
148 onChange={(e) => setPattern(e.target.value)}
149 className="font-mono text-sm"
150 />
151 <p className="text-xs text-muted-foreground">
152 Exact tool id, trailing wildcard, or <code className="font-mono">*</code> for every tool.
153 Examples: <code className="font-mono">*</code>,{" "}
154 <code className="font-mono">vercel.*</code>,{" "}
155 <code className="font-mono">vercel.dns.*</code>,{" "}
156 <code className="font-mono">vercel.dns.create</code>.
157 </p>
158 </div>
159 <div className="flex flex-col gap-1">
160 <Label className="text-xs font-medium text-foreground/80">Action</Label>
161 <Select value={action} onValueChange={(v) => setAction(v as ToolPolicyAction)}>
162 <SelectTrigger className="w-full">
163 <SelectValue />
164 </SelectTrigger>
165 <SelectContent>
166 {POLICY_ACTIONS_IN_ORDER.map((a) => (
167 <SelectItem key={a} value={a}>

Callers

nothing calls this directly

Calls 2

useOwnerDisplayFunction · 0.90
isValidPatternFunction · 0.85

Tested by

no test coverage detected