TableReplicationRow.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import { useParams } from 'common'
  2. import { ExternalLink, RotateCcw } from 'lucide-react'
  3. import Link from 'next/link'
  4. import { Badge, Button, TableCell, TableRow, Tooltip, TooltipContent, TooltipTrigger } from 'ui'
  5. import { ErroredTableDetails } from '../ErroredTableDetails'
  6. import { TableState } from './ReplicationPipelineStatus.types'
  7. import { getStatusConfig } from './ReplicationPipelineStatus.utils'
  8. import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
  9. import { InlineLinkClassName } from '@/components/ui/InlineLink'
  10. import { ReplicationPipelineTableStatus } from '@/data/replication/pipeline-replication-status-query'
  11. interface TableReplicationRowProps {
  12. table: ReplicationPipelineTableStatus
  13. isRestarting: boolean
  14. showDisabledState: boolean
  15. disabledStateMessage: string
  16. isAnyRestartInProgress: boolean
  17. isPipelineStopped: boolean
  18. onSelectRestart: () => void
  19. onSelectShowError: () => void
  20. }
  21. export const TableReplicationRow = ({
  22. table,
  23. isRestarting,
  24. showDisabledState,
  25. disabledStateMessage,
  26. isAnyRestartInProgress,
  27. isPipelineStopped,
  28. onSelectRestart,
  29. onSelectShowError,
  30. }: TableReplicationRowProps) => {
  31. const { ref } = useParams()
  32. const isErrorState = table.state.name === 'error'
  33. const statusConfig = getStatusConfig(table.state as TableState['state'])
  34. return (
  35. <TableRow>
  36. <TableCell className="align-top">
  37. <div className="flex items-center gap-x-2">
  38. <p>{table.table_name}</p>
  39. <ButtonTooltip
  40. asChild
  41. type="text"
  42. className="px-1.5"
  43. icon={<ExternalLink />}
  44. tooltip={{
  45. content: { side: 'bottom', text: 'Open in Table Editor' },
  46. }}
  47. >
  48. <Link
  49. target="_blank"
  50. rel="noopener noreferrer"
  51. href={`/project/${ref}/editor/${table.table_id}`}
  52. />
  53. </ButtonTooltip>
  54. </div>
  55. </TableCell>
  56. <TableCell className="align-top">
  57. {isRestarting ? (
  58. <Badge variant="default">Restarting</Badge>
  59. ) : showDisabledState ? (
  60. <Badge variant="default">Not Available</Badge>
  61. ) : (
  62. statusConfig.badge
  63. )}
  64. </TableCell>
  65. <TableCell className="align-top">
  66. {isRestarting ? (
  67. <p className="text-sm text-foreground-lighter">
  68. Replication is being restarted for this table. The pipeline will restart automatically.
  69. </p>
  70. ) : showDisabledState ? (
  71. <p className="text-sm text-foreground-lighter">{disabledStateMessage}</p>
  72. ) : (
  73. <div className="flex flex-col gap-y-3">
  74. <div className="text-sm text-foreground">
  75. {statusConfig.description}{' '}
  76. {isErrorState && 'reason' in table.state && (
  77. <button className={InlineLinkClassName} onClick={() => onSelectShowError()}>
  78. View error.
  79. </button>
  80. )}
  81. </div>
  82. {table.state.name === 'error' && <ErroredTableDetails table={table} />}
  83. </div>
  84. )}
  85. </TableCell>
  86. <TableCell className="align-top">
  87. <div className="flex items-center justify-end">
  88. <Tooltip>
  89. <TooltipTrigger asChild>
  90. <Button
  91. type="default"
  92. className="w-7"
  93. icon={<RotateCcw />}
  94. disabled={showDisabledState || isRestarting || isAnyRestartInProgress}
  95. aria-label={`Restart replication for ${table.table_name}`}
  96. onClick={onSelectRestart}
  97. />
  98. </TooltipTrigger>
  99. <TooltipContent side="bottom" align="center">
  100. {isPipelineStopped ? 'Reset table and start pipeline' : 'Reset and restart pipeline'}
  101. </TooltipContent>
  102. </Tooltip>
  103. </div>
  104. </TableCell>
  105. </TableRow>
  106. )
  107. }