Skip to content

Commit

Permalink
feat(ui): support selecting repositories in answer engine (#2594)
Browse files Browse the repository at this point in the history
* feat(ui): support selecting repos in answer engine

* update textarea style

* [autofix.ci] apply automated fixes

* update: single choice

* [autofix.ci] apply automated fixes

* update: adjust style of 'clear' button

* [autofix.ci] apply automated fixes

* Update ee/tabby-ui/components/textarea-search.tsx

Co-authored-by: Meng Zhang <[email protected]>

* Update ee/tabby-ui/components/textarea-search.tsx

Co-authored-by: Meng Zhang <[email protected]>

* Update ee/tabby-ui/components/textarea-search.tsx

Co-authored-by: Meng Zhang <[email protected]>

* Update ee/tabby-ui/components/textarea-search.tsx

Co-authored-by: Meng Zhang <[email protected]>

* Update ee/tabby-ui/components/textarea-search.tsx

Co-authored-by: Meng Zhang <[email protected]>

* [autofix.ci] apply automated fixes

* update text

* [autofix.ci] apply automated fixes

* update style

* update: add code_query

* update: extraRequestPayload

* [autofix.ci] apply automated fixes

* update: request with code_query

* update: fix repo select

* update: process topbar

* update: use kind & id as key of commandItem

* update

* update: cache key

* update: rename storage key

* update: show repo select in search page

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Meng Zhang <[email protected]>
  • Loading branch information
3 people authored Jul 14, 2024
1 parent 0e0a882 commit 759206c
Show file tree
Hide file tree
Showing 12 changed files with 550 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ const ActiveRepoTable: React.FC<{
) : (
<TableRow>
<TableCell colSpan={4} className="h-[100px] text-center">
No repositories yet.
No repositories
</TableCell>
</TableRow>
)}
Expand Down
12 changes: 10 additions & 2 deletions ee/tabby-ui/app/(home)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Link from 'next/link'
import { useRouter } from 'next/navigation'
import tabbyUrl from '@/assets/logo-dark.png'
import AOS from 'aos'
import { noop } from 'lodash-es'
import { noop, omit } from 'lodash-es'

import { SESSION_STORAGE_KEY } from '@/lib/constants'
import { useEnableSearch } from '@/lib/experiment-flags'
Expand Down Expand Up @@ -41,6 +41,7 @@ import Stats from './components/stats'

import 'aos/dist/aos.css'

import { AnswerEngineExtraContext } from '@/lib/types'
import { Separator } from '@/components/ui/separator'

const resetUserAuthTokenDocument = graphql(/* GraphQL */ `
Expand Down Expand Up @@ -82,10 +83,17 @@ function MainPanel() {

if (!healthInfo || !data?.me) return <></>

const onSearch = (question: string) => {
const onSearch = (question: string, ctx?: AnswerEngineExtraContext) => {
setIsLoading(true)
sessionStorage.removeItem(SESSION_STORAGE_KEY.SEARCH_LATEST_MSG)
sessionStorage.removeItem(SESSION_STORAGE_KEY.SEARCH_LATEST_EXTRA_CONTEXT)
sessionStorage.setItem(SESSION_STORAGE_KEY.SEARCH_INITIAL_MSG, question)
sessionStorage.setItem(
SESSION_STORAGE_KEY.SEARCH_INITIAL_EXTRA_CONTEXT,
JSON.stringify({
repository: ctx?.repository ? omit(ctx.repository, 'refs') : undefined
})
)
router.push('/search')
}

Expand Down
2 changes: 1 addition & 1 deletion ee/tabby-ui/app/files/components/file-tree-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ const FileTreeHeader: React.FC<FileTreeHeaderProps> = ({
<SelectContent className="max-h-[50vh] overflow-y-auto">
{noIndexedRepo ? (
<SelectItem isPlaceHolder value="" disabled>
No indexed repository
No repositories
</SelectItem>
) : (
<>
Expand Down
8 changes: 0 additions & 8 deletions ee/tabby-ui/app/files/components/file-tree.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use client'

import React from 'react'
import { isEmpty } from 'lodash-es'
import { useInView } from 'react-intersection-observer'
import { SWRResponse } from 'swr'
import useSWRImmutable from 'swr/immutable'
Expand Down Expand Up @@ -352,13 +351,6 @@ const FileTreeRenderer: React.FC = () => {

if (!initialized) return <FileTreeSkeleton />

if (isEmpty(repoMap))
return (
<div className="flex h-full items-center justify-center">
No Indexed repository
</div>
)

if (!hasSelectedRepo) {
return null
}
Expand Down
20 changes: 5 additions & 15 deletions ee/tabby-ui/app/files/components/source-code-browser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { useIsChatEnabled } from '@/lib/hooks/use-server-info'
import { filename2prism } from '@/lib/language-utils'
import fetcher from '@/lib/tabby/fetcher'
import { client } from '@/lib/tabby/gql'
import { repositoryListQuery } from '@/lib/tabby/query'
import type { ResolveEntriesResponse, TFile } from '@/lib/types'
import { cn, formatLineHashForCodeBrowser } from '@/lib/utils'
import {
Expand Down Expand Up @@ -75,18 +76,6 @@ type TFileMapItem = {
type TFileMap = Record<string, TFileMapItem>
type RepositoryItem = RepositoryListQuery['repositoryList'][0]

const repositoryListQuery = graphql(/* GraphQL */ `
query RepositoryList {
repositoryList {
id
name
kind
gitUrl
refs
}
}
`)

const repositoryGrepQuery = graphql(/* GraphQL */ `
query RepositoryGrep($id: ID!, $kind: RepositoryKind!, $query: String!) {
repositoryGrep(kind: $kind, id: $id, query: $query) {
Expand Down Expand Up @@ -356,9 +345,10 @@ const SourceCodeBrowserRenderer: React.FC<SourceCodeBrowserProps> = ({
const isSearchMode = activeEntryInfo?.viewMode === 'search'

const shouldFetchTree =
!!isPathInitialized && !isEmpty(repoMap) && !!activePath && !isSearchMode
!!initialized && !isEmpty(repoMap) && !!activePath && !isSearchMode
const shouldFetchRepositoryGrep =
!!isPathInitialized && !isEmpty(repoMap) && !!activePath && isSearchMode
!!initialized && !isEmpty(repoMap) && !!activePath && isSearchMode
const shouldFetchRawFile = !!initialized && isBlobMode && activeRepo

// fetch tree
const {
Expand Down Expand Up @@ -393,7 +383,7 @@ const SourceCodeBrowserRenderer: React.FC<SourceCodeBrowserProps> = ({
contentLength?: number
fileDisplayType: FileDisplayType
}>(
isBlobMode && activeRepo
shouldFetchRawFile
? [
toEntryRequestUrl(activeRepo, activeRepoRef?.name, activeBasename),
activeBasename
Expand Down
24 changes: 21 additions & 3 deletions ee/tabby-ui/app/files/components/tree-mode-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import { find, isEmpty, omit } from 'lodash-es'

import { useDebounceValue } from '@/lib/hooks/use-debounce'
import { cn } from '@/lib/utils'
import { IconDirectorySolid, IconFile } from '@/components/ui/icons'
import { buttonVariants } from '@/components/ui/button'
import {
IconArrowRight,
IconDirectorySolid,
IconFile,
IconFileSearch
} from '@/components/ui/icons'
import { Skeleton } from '@/components/ui/skeleton'
import { Table, TableBody, TableCell, TableRow } from '@/components/ui/table'

Expand Down Expand Up @@ -150,8 +156,20 @@ const TreeModeView: React.FC<TreeModeViewProps> = ({
</TableBody>
</Table>
) : isEmpty(repoMap) ? (
<div className="flex justify-center py-8">
No indexed repository yet
<div className="flex min-h-[30vh] items-center justify-center">
<div className="flex flex-col items-center gap-4">
<div className="flex items-center gap-2">
<IconFileSearch className="h-6 w-6" />
<div className="text-xl font-semibold">No repositories</div>
</div>
<Link
href="/settings/providers/git"
className={cn(buttonVariants(), 'gap-2')}
>
<span>Connect</span>
<IconArrowRight />
</Link>
</div>
</div>
) : null}
</div>
Expand Down
Loading

0 comments on commit 759206c

Please sign in to comment.