All files / features / repositories / hooks useRepoColumns.tsx

12.5% Statements 1/8
0% Branches 0/6
0% Functions 0/6
12.5% Lines 1/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66  69x                                                                                                                                
import type { Column } from '@/shared/components/DataTable'
import { formatRelativeTime } from '@/shared/utils/format'
import type { components } from '@/types/api'

type Repository = components['schemas']['Repository']
 
export function useRepoColumns(): Column<Repository>[] {
  return [
    {
      key: 'name',
      label: 'Name',
      sortable: true,
      render: (item) => (
        <a
          href={`#/repositories/${item.id}`}
          className="text-primary underline-offset-4 hover:underline"
        >
          {item.name}
        </a>
      ),
    },
    {
      key: 'description',
      label: 'Description',
      sortable: true,
      render: (item) => item.description || '\u2014',
    },
    {
      key: 'url',
      label: 'URL',
      sortable: true,
      render: (item) => (
        <span className="font-mono text-xs">{item.url}</span>
      ),
    },
    {
      key: 'status',
      label: 'Status',
      sortable: true,
      render: (item) => {
        const [emoji, text, color] =
          item.status === 'connected'
            ? ['\uD83D\uDFE2', 'Connected', 'text-green-600']
            : item.status === 'disconnected'
              ? ['\uD83D\uDD34', 'Disconnected', 'text-red-600']
              : ['\u26AA', 'Unknown', 'text-muted-foreground']
        return (
          <span className={color}>
            {emoji} {text}
          </span>
        )
      },
    },
    {
      key: 'last_checked_at',
      label: 'Last Checked',
      sortable: true,
      render: (item) => (
        <span className="text-sm text-muted-foreground">
          {formatRelativeTime(item.last_checked_at)}
        </span>
      ),
    },
  ]
}