import { FormField, Input, Select } from '@cameleer/design-system'; import { useCatalog } from '../../../api/queries/catalog'; import { useAgents } from '../../../api/queries/agents'; import { useSelectedEnv } from '../../../api/queries/alertMeta'; import type { FormState } from './form-state'; import { SEVERITY_OPTIONS } from '../../../api/alerting-enums'; const SCOPE_OPTIONS = [ { value: 'env', label: 'Environment-wide' }, { value: 'app', label: 'Single app' }, { value: 'route', label: 'Single route' }, { value: 'agent', label: 'Single agent' }, ]; type AgentSummary = { instanceId?: string; displayName?: string; applicationId?: string; }; export function ScopeStep({ form, setForm }: { form: FormState; setForm: (f: FormState) => void }) { const env = useSelectedEnv(); const { data: catalog } = useCatalog(env); const { data: agents } = useAgents(); const apps = (catalog ?? []).map((a) => ({ slug: a.slug, name: a.displayName ?? a.slug, routes: a.routes ?? [], })); const selectedApp = apps.find((a) => a.slug === form.appSlug); const routes = selectedApp?.routes ?? []; const appAgents: AgentSummary[] = Array.isArray(agents) ? (agents as AgentSummary[]).filter((a) => a.applicationId === form.appSlug) : []; return (