diff --git a/ui/src/pages/Alerts/RuleEditor/ScopeStep.tsx b/ui/src/pages/Alerts/RuleEditor/ScopeStep.tsx index 649457f0..68955926 100644 --- a/ui/src/pages/Alerts/RuleEditor/ScopeStep.tsx +++ b/ui/src/pages/Alerts/RuleEditor/ScopeStep.tsx @@ -1,5 +1,103 @@ +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'; -export function ScopeStep({ form: _form, setForm: _setForm }: { form: FormState; setForm: (f: FormState) => void }) { - return
Scope step — TODO Task 20
; +const SEVERITY_OPTIONS = [ + { value: 'CRITICAL', label: 'Critical' }, + { value: 'WARNING', label: 'Warning' }, + { value: 'INFO', label: 'Info' }, +]; + +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' && ( + +