Pulse/frontend-modern/src/api/alerts.ts
rcourtman 6eb1a10d9b Refactor: Code cleanup and localStorage consolidation
This commit includes comprehensive codebase cleanup and refactoring:

## Code Cleanup
- Remove dead TypeScript code (types/monitoring.ts - 194 lines duplicate)
- Remove unused Go functions (GetClusterNodes, MigratePassword, GetClusterHealthInfo)
- Clean up commented-out code blocks across multiple files
- Remove unused TypeScript exports (helpTextClass, private tag color helpers)
- Delete obsolete test files and components

## localStorage Consolidation
- Centralize all storage keys into STORAGE_KEYS constant
- Update 5 files to use centralized keys:
  * utils/apiClient.ts (AUTH, LEGACY_TOKEN)
  * components/Dashboard/Dashboard.tsx (GUEST_METADATA)
  * components/Docker/DockerHosts.tsx (DOCKER_METADATA)
  * App.tsx (PLATFORMS_SEEN)
  * stores/updates.ts (UPDATES)
- Benefits: Single source of truth, prevents typos, better maintainability

## Previous Work Committed
- Docker monitoring improvements and disk metrics
- Security enhancements and setup fixes
- API refactoring and cleanup
- Documentation updates
- Build system improvements

## Testing
- All frontend tests pass (29 tests)
- All Go tests pass (15 packages)
- Production build successful
- Zero breaking changes

Total: 186 files changed, 5825 insertions(+), 11602 deletions(-)
2025-11-04 21:50:46 +00:00

79 lines
2.2 KiB
TypeScript

import type { Alert } from '@/types/api';
import type { AlertConfig } from '@/types/alerts';
import { apiFetchJSON } from '@/utils/apiClient';
export class AlertsAPI {
private static baseUrl = '/api/alerts';
static async getActive(): Promise<Alert[]> {
return apiFetchJSON(`${this.baseUrl}/active`);
}
static async getHistory(params?: {
limit?: number;
offset?: number;
startTime?: string;
endTime?: string;
severity?: 'warning' | 'critical' | 'all';
resourceId?: string;
}): Promise<Alert[]> {
const queryParams = new URLSearchParams();
if (params) {
Object.entries(params).forEach(([key, value]) => {
if (value !== undefined) {
queryParams.append(key, value.toString());
}
});
}
return apiFetchJSON(`${this.baseUrl}/history?${queryParams}`);
}
static async acknowledge(alertId: string, user?: string): Promise<{ success: boolean }> {
return apiFetchJSON(`${this.baseUrl}/${encodeURIComponent(alertId)}/acknowledge`, {
method: 'POST',
body: JSON.stringify({ user }),
});
}
static async unacknowledge(alertId: string): Promise<{ success: boolean }> {
return apiFetchJSON(`${this.baseUrl}/${encodeURIComponent(alertId)}/unacknowledge`, {
method: 'POST',
});
}
// Alert configuration methods
static async getConfig(): Promise<AlertConfig> {
return apiFetchJSON(`${this.baseUrl}/config`);
}
static async updateConfig(config: AlertConfig): Promise<{ success: boolean }> {
return apiFetchJSON(`${this.baseUrl}/config`, {
method: 'PUT',
body: JSON.stringify(config),
});
}
static async activate(): Promise<{ success: boolean; state: string; activationTime?: string }> {
return apiFetchJSON(`${this.baseUrl}/activate`, {
method: 'POST',
});
}
static async clearHistory(): Promise<{ success: boolean }> {
return apiFetchJSON(`${this.baseUrl}/history`, {
method: 'DELETE',
});
}
static async bulkAcknowledge(
alertIds: string[],
user?: string,
): Promise<{ results: Array<{ alertId: string; success: boolean; error?: string }> }> {
return apiFetchJSON(`${this.baseUrl}/bulk/acknowledge`, {
method: 'POST',
body: JSON.stringify({ alertIds, user }),
});
}
}