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 '../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 (
setForm({ ...form, name: e.target.value })} placeholder="Order API error rate" /> setForm({ ...form, description: e.target.value })} /> setForm({ ...form, scopeKind: e.target.value as FormState['scopeKind'] })} options={SCOPE_OPTIONS} /> {form.scopeKind !== 'env' && ( setForm({ ...form, routeId: e.target.value })} options={[{ value: '', label: '-- select --' }, ...routes.map((r) => ({ value: r.routeId, label: r.routeId }))]} /> )} {form.scopeKind === 'agent' && (