;
onRemove: () => void;
canRemove: boolean;
}) {
const t = useTranslations();
const type = form.watch(`actions.${index}.type`);
return (
{canRemove && (
)}
(
{t("alertingActionType")}
)}
/>
{type === "notify" && (
)}
{type === "webhook" && (
)}
);
}
function NotifyActionFields({
orgId,
index,
control,
form
}: {
orgId: string;
index: number;
control: Control;
form: UseFormReturn;
}) {
const t = useTranslations();
const [emailActiveIdx, setEmailActiveIdx] = useState(null);
const [activeUsersTagIndex, setActiveUsersTagIndex] = useState<
number | null
>(null);
const [activeRolesTagIndex, setActiveRolesTagIndex] = useState<
number | null
>(null);
const { data: orgUsers = [] } = useQuery(orgQueries.users({ orgId }));
const { data: orgRoles = [] } = useQuery(orgQueries.roles({ orgId }));
const allUsers = useMemo(
() =>
orgUsers.map((u) => ({
id: String(u.id),
text: getUserDisplayName({
email: u.email,
name: u.name,
username: u.username
})
})),
[orgUsers]
);
const allRoles = useMemo(
() =>
orgRoles
.map((r) => ({ id: String(r.roleId), text: r.name }))
.filter((r) => r.text !== "Admin"),
[orgRoles]
);
const userTags = (form.watch(`actions.${index}.userTags`) ?? []) as Tag[];
const roleTags = (form.watch(`actions.${index}.roleTags`) ?? []) as Tag[];
const emailTags = (form.watch(`actions.${index}.emailTags`) ?? []) as Tag[];
return (
(
{t("alertingNotifyUsers")}
{
const next =
typeof newTags === "function"
? newTags(userTags)
: newTags;
form.setValue(
`actions.${index}.userTags`,
next as Tag[]
);
}}
enableAutocomplete={true}
autocompleteOptions={allUsers}
allowDuplicates={false}
restrictTagsToAutocompleteOptions={true}
sortTags={true}
/>
)}
/>
(
{t("alertingNotifyRoles")}
{
const next =
typeof newTags === "function"
? newTags(roleTags)
: newTags;
form.setValue(
`actions.${index}.roleTags`,
next as Tag[]
);
}}
enableAutocomplete={true}
autocompleteOptions={allRoles}
allowDuplicates={false}
restrictTagsToAutocompleteOptions={true}
sortTags={true}
/>
)}
/>
(
{t("alertingNotifyEmails")}
{
const next =
typeof updater === "function"
? updater(emailTags)
: updater;
form.setValue(
`actions.${index}.emailTags`,
next as Tag[]
);
}}
activeTagIndex={emailActiveIdx}
setActiveTagIndex={setEmailActiveIdx}
placeholder={t("alertingEmailPlaceholder")}
size="sm"
allowDuplicates={false}
sortTags={true}
validateTag={(tag) =>
/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(tag)
}
delimiterList={[",", "Enter"]}
/>
)}
/>
);
}
function WebhookActionFields({
index,
control,
form
}: {
index: number;
control: Control;
form: UseFormReturn;
}) {
const t = useTranslations();
return (
);
}
function WebhookHeadersField({
index,
control,
form
}: {
index: number;
control: Control;
form: UseFormReturn;
}) {
const t = useTranslations();
const headers =
form.watch(`actions.${index}.headers` as const) ?? [];
return (
);
}
export function AlertRuleSourceFields({
orgId,
control
}: {
orgId: string;
control: Control;
}) {
const t = useTranslations();
const { setValue, getValues } = useFormContext();
const sourceType = useWatch({ control, name: "sourceType" });
return (
(
{t("alertingSourceType")}
)}
/>
{sourceType === "site" ? (
(
{t("alertingPickSites")}
)}
/>
) : (
(
{t("alertingPickHealthChecks")}
)}
/>
)}
);
}
export function AlertRuleTriggerFields({
control
}: {
control: Control;
}) {
const t = useTranslations();
const sourceType = useWatch({ control, name: "sourceType" });
return (
(
{t("alertingTrigger")}
)}
/>
);
}