Skip to content

Commit

Permalink
integrate api
Browse files Browse the repository at this point in the history
  • Loading branch information
liangfung committed Jun 12, 2024
1 parent 8682b8f commit b8a6952
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import React, { useEffect, useState } from 'react'
import Link from 'next/link'
import { useRouter, useSearchParams } from 'next/navigation'
import { isNil } from 'lodash-es'
import { toast } from 'sonner'
import { useQuery } from 'urql'

Expand Down Expand Up @@ -34,7 +35,6 @@ import {
import {
IconChevronLeft,
IconChevronRight,
IconLink,
IconPlay,
IconPlus,
IconSpinner,
Expand Down Expand Up @@ -334,41 +334,44 @@ const ActiveRepoTable: React.FC<{
)
})}
{activeRepos?.map((x, index) => {
const lastJobRun = x.node.jobInfo.lastJobRun
const hasRunningJob =
!!lastJobRun?.id && isNil(lastJobRun.exitCode)

return (
<TableRow key={x.node.id}>
<TableCell>{x.node.displayName}</TableCell>
<TableCell>{x.node.gitUrl}</TableCell>
<TableCell>
<div className="flex items-center gap-1.5">
{index !== 0 && (
<Tooltip>
<TooltipTrigger asChild>
<Button size="icon" variant="ghost">
<IconPlay />
</Button>
</TooltipTrigger>
<TooltipContent>
<p>Run</p>
</TooltipContent>
</Tooltip>
)}
{index === 0 && (
{hasRunningJob ? (
<Tooltip>
<TooltipTrigger asChild>
<Link
href=""
href={`/jobs/detail?id=${lastJobRun.id}`}
className={buttonVariants({
variant: 'ghost',
size: 'icon'
})}
>
<IconLink />
<IconSpinner />
</Link>
</TooltipTrigger>
<TooltipContent>
Navigate to job detail
</TooltipContent>
</Tooltip>
) : (
<Tooltip>
<TooltipTrigger asChild>
<Button size="icon" variant="ghost">
<IconPlay />
</Button>
</TooltipTrigger>
<TooltipContent>
<p>Run</p>
</TooltipContent>
</Tooltip>
)}
</div>
</TableCell>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import React from 'react'
import Link from 'next/link'
import { isNil } from 'lodash-es'
import { toast } from 'sonner'
import { useClient, useQuery } from 'urql'

Expand All @@ -11,7 +12,7 @@ import { GitRepositoriesQueryVariables } from '@/lib/gql/generates/graphql'
import { useMutation } from '@/lib/tabby/gql'
import { listRepositories } from '@/lib/tabby/query'
import { Button, buttonVariants } from '@/components/ui/button'
import { IconLink, IconPlay, IconTrash } from '@/components/ui/icons'
import { IconPlay, IconSpinner, IconTrash } from '@/components/ui/icons'
import {
Pagination,
PaginationContent,
Expand Down Expand Up @@ -137,42 +138,44 @@ export default function RepositoryTable() {
</TableRow>
) : (
<>
{currentPageRepos?.map((x, index) => {
{currentPageRepos?.map(x => {
const lastJobRun = x.node.jobInfo.lastJobRun
const hasRunningJob =
!!lastJobRun?.id && isNil(lastJobRun.exitCode)
return (
<TableRow key={x.node.id}>
<TableCell className="truncate">{x.node.name}</TableCell>
<TableCell className="truncate">{x.node.gitUrl}</TableCell>
<TableCell className="truncate">
<div className="flex items-center gap-1.5">
{index !== 0 && (
<Tooltip>
<TooltipTrigger asChild>
<Button size="icon" variant="ghost">
<IconPlay />
</Button>
</TooltipTrigger>
<TooltipContent>
<p>Run</p>
</TooltipContent>
</Tooltip>
)}
{index === 0 && (
{hasRunningJob ? (
<Tooltip>
<TooltipTrigger asChild>
<Link
href=""
href={`/jobs/detail?id=${lastJobRun.id}`}
className={buttonVariants({
variant: 'ghost',
size: 'icon'
})}
>
<IconLink />
<IconSpinner />
</Link>
</TooltipTrigger>
<TooltipContent>
Navigate to job detail
</TooltipContent>
</Tooltip>
) : (
<Tooltip>
<TooltipTrigger asChild>
<Button size="icon" variant="ghost">
<IconPlay />
</Button>
</TooltipTrigger>
<TooltipContent>
<p>Run</p>
</TooltipContent>
</Tooltip>
)}
</div>
</TableCell>
Expand Down
10 changes: 4 additions & 6 deletions ee/tabby-ui/components/ui/icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import {
Blocks,
BookOpenText,
ChevronsDownUp,
CircleStop,
GitFork,
Layers2,
Mail,
Play,
Search,
Sparkles,
Star,
Play
Star
} from 'lucide-react'

import { cn } from '@/lib/utils'
Expand Down Expand Up @@ -1482,10 +1483,7 @@ function IconSearch({
return <Search className={cn('h4 w-4', className)} {...props} />
}

function IconPlay({
className,
...props
}: React.ComponentProps<typeof Play>) {
function IconPlay({ className, ...props }: React.ComponentProps<typeof Play>) {
return <Play className={cn('h4 w-4', className)} {...props} />
}

Expand Down
20 changes: 20 additions & 0 deletions ee/tabby-ui/lib/tabby/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ export const listRepositories = graphql(/* GraphQL */ `
id
name
gitUrl
jobInfo {
lastJobRun {
id
job
createdAt
finishedAt
exitCode
}
command
}
}
cursor
}
Expand Down Expand Up @@ -228,6 +238,16 @@ export const listIntegratedRepositories = graphql(/* GraphQL */ `
displayName
gitUrl
active
jobInfo {
lastJobRun {
id
job
createdAt
finishedAt
exitCode
}
command
}
}
cursor
}
Expand Down

0 comments on commit b8a6952

Please sign in to comment.