BranchStatusBadge.tsx70 lines · main
| 1 | import { Badge, StatusIcon } from 'ui' |
| 2 | |
| 3 | import type { BranchData } from '@/data/branches/branch-query' |
| 4 | import type { Branch } from '@/data/branches/branches-query' |
| 5 | |
| 6 | type Status = Branch['status'] | BranchData['status'] |
| 7 | |
| 8 | export interface BranchStatusBadgeProps { |
| 9 | status: Status |
| 10 | } |
| 11 | |
| 12 | const UNHEALTHY_STATUES: Status[] = [ |
| 13 | 'ACTIVE_UNHEALTHY', |
| 14 | 'INIT_FAILED', |
| 15 | 'UNKNOWN', |
| 16 | 'MIGRATIONS_FAILED', |
| 17 | 'FUNCTIONS_FAILED', |
| 18 | ] |
| 19 | const WAITING_STATUSES: Status[] = [ |
| 20 | 'COMING_UP', |
| 21 | 'GOING_DOWN', |
| 22 | 'PAUSING', |
| 23 | 'RESTORING', |
| 24 | 'UPGRADING', |
| 25 | 'RUNNING_MIGRATIONS', |
| 26 | ] |
| 27 | |
| 28 | const STATUS_TO_LABEL: Record<Status, string> = { |
| 29 | ACTIVE_HEALTHY: 'Healthy', |
| 30 | ACTIVE_UNHEALTHY: 'Unhealthy', |
| 31 | INIT_FAILED: 'Init failed', |
| 32 | UNKNOWN: 'Unknown', |
| 33 | COMING_UP: 'Coming up', |
| 34 | GOING_DOWN: 'Going down', |
| 35 | INACTIVE: 'Inactive', |
| 36 | PAUSING: 'Pausing', |
| 37 | REMOVED: 'Removed', |
| 38 | RESTORING: 'Restoring', |
| 39 | UPGRADING: 'Upgrading', |
| 40 | RESIZING: 'Resizing', |
| 41 | CREATING_PROJECT: 'Creating project', |
| 42 | RUNNING_MIGRATIONS: 'Running migrations', |
| 43 | MIGRATIONS_FAILED: 'Migrations failed', |
| 44 | MIGRATIONS_PASSED: 'Migrations applied successfully', |
| 45 | FUNCTIONS_DEPLOYED: 'Functions deployed', |
| 46 | FUNCTIONS_FAILED: 'Functions failed to deploy', |
| 47 | RESTARTING: 'Restarting', |
| 48 | RESTORE_FAILED: 'Failed to restore', |
| 49 | PAUSE_FAILED: 'Failed to pause', |
| 50 | } |
| 51 | |
| 52 | const BranchStatusBadge = ({ status }: BranchStatusBadgeProps) => { |
| 53 | if (status === 'ACTIVE_HEALTHY' || status === 'MIGRATIONS_PASSED') { |
| 54 | return null |
| 55 | } |
| 56 | |
| 57 | const isUnhealthy = UNHEALTHY_STATUES.includes(status) |
| 58 | const isWaiting = WAITING_STATUSES.includes(status) |
| 59 | |
| 60 | return ( |
| 61 | <Badge variant={isUnhealthy ? 'destructive' : 'default'} className="gap-1.5"> |
| 62 | {(isUnhealthy || isWaiting) && ( |
| 63 | <StatusIcon variant={isUnhealthy ? 'destructive' : 'default'} hideBackground /> |
| 64 | )} |
| 65 | {STATUS_TO_LABEL[status]} |
| 66 | </Badge> |
| 67 | ) |
| 68 | } |
| 69 | |
| 70 | export default BranchStatusBadge |