BranchStatusBadge.tsx 1.8 KB

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