Pulse/frontend-modern/src/utils/status.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

22 lines
707 B
TypeScript

import type { Node, VM, Container } from '@/types/api';
const ONLINE_STATUS = 'online';
const RUNNING_STATUS = 'running';
export function isNodeOnline(node: Partial<Node> | undefined | null): boolean {
if (!node) return false;
if (node.status !== ONLINE_STATUS) return false;
if ((node.uptime ?? 0) <= 0) return false;
const connection = (node as Node).connectionHealth;
if (connection === 'offline' || connection === 'error') return false;
return true;
}
export function isGuestRunning(
guest: Partial<VM | Container> | undefined | null,
parentNodeOnline = true,
): boolean {
if (!guest) return false;
if (!parentNodeOnline) return false;
return guest.status === RUNNING_STATUS;
}