Skip to content

Commit

Permalink
update: rename
Browse files Browse the repository at this point in the history
  • Loading branch information
liangfung committed Dec 27, 2024
1 parent bdbd825 commit 12427ae
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 52 deletions.
18 changes: 10 additions & 8 deletions ee/tabby-ui/app/(home)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import { useStore } from 'zustand'
import { SESSION_STORAGE_KEY } from '@/lib/constants'
import { useMe } from '@/lib/hooks/use-me'
import { useSelectedModel } from '@/lib/hooks/use-models'
import { useSelectedRepository } from '@/lib/hooks/use-repositories'
import {
useIsChatEnabled,
useIsFetchingServerInfo
} from '@/lib/hooks/use-server-info'
import { setThreadsPageNo } from '@/lib/stores/answer-engine-store'
import {
updateSelectedModel,
updateSelectedRepo
updateSelectedCodeSourceId,
updateSelectedModel
} from '@/lib/stores/chat-actions'
import { useChatStore } from '@/lib/stores/chat-store'
import {
clearHomeScrollPosition,
setHomeScrollPosition,
Expand Down Expand Up @@ -59,8 +59,8 @@ function MainPanel() {
})
const scrollY = useStore(useScrollStore, state => state.homePage)

const { selectedModel, isModelLoading, models } = useSelectedModel()
const selectedRepoId = useChatStore(state => state.selectedRepo)
const { selectedModel, isFetchingModels, models } = useSelectedModel()
const { selectedRepository, isFetchingRepositories } = useSelectedRepository()

const showMainSection = !!data?.me || !isFetchingServerInfo

Expand Down Expand Up @@ -91,7 +91,7 @@ function MainPanel() {
}

const onSelectedRepo = (sourceId: string | undefined) => {
updateSelectedRepo(sourceId)
updateSelectedCodeSourceId(sourceId)
}

const onSearch = (question: string, ctx?: ThreadRunContexts) => {
Expand Down Expand Up @@ -167,9 +167,11 @@ function MainPanel() {
fetchingContextInfo={fetchingContextInfo}
modelName={selectedModel}
onSelectModel={handleSelectModel}
repoSourceId={selectedRepoId}
repoSourceId={selectedRepository?.sourceId}
onSelectRepo={onSelectedRepo}
isModelLoading={isModelLoading}
isInitializingResources={
isFetchingModels || isFetchingRepositories
}
models={models}
/>
</AnimationWrapper>
Expand Down
30 changes: 14 additions & 16 deletions ee/tabby-ui/app/search/components/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,20 @@ import { useDebounceValue } from '@/lib/hooks/use-debounce'
import { useLatest } from '@/lib/hooks/use-latest'
import { useMe } from '@/lib/hooks/use-me'
import { useSelectedModel } from '@/lib/hooks/use-models'
import { useSelectedRepository } from '@/lib/hooks/use-repositories'
import useRouterStuff from '@/lib/hooks/use-router-stuff'
import { useIsChatEnabled } from '@/lib/hooks/use-server-info'
import { useThreadRun } from '@/lib/hooks/use-thread-run'
import {
updateSelectedModel,
updateSelectedRepo
updateSelectedCodeSourceId,
updateSelectedModel
} from '@/lib/stores/chat-actions'
import { useChatStore } from '@/lib/stores/chat-store'
import { clearHomeScrollPosition } from '@/lib/stores/scroll-store'
import { useMutation } from '@/lib/tabby/gql'
import {
contextInfoQuery,
listThreadMessages,
listThreads,
repositorySourceListQuery,
setThreadPersistedMutation
} from '@/lib/tabby/query'
import { ExtendedCombinedError, ThreadRunContexts } from '@/lib/types'
Expand Down Expand Up @@ -175,10 +174,6 @@ export function Search() {
const [{ data: contextInfoData, fetching: fetchingContextInfo }] = useQuery({
query: contextInfoQuery
})
const [{ data: repositorySourceListData, fetching: fetchingRepos }] =
useQuery({
query: repositorySourceListQuery
})

const [afterCursor, setAfterCursor] = useState<string | undefined>()

Expand Down Expand Up @@ -295,8 +290,9 @@ export function Search() {

const isLoadingRef = useLatest(isLoading)

const { selectedModel, isModelLoading, models } = useSelectedModel()
const selectedRepoId = useChatStore(state => state.selectedRepo)
const { selectedModel, isFetchingModels, models } = useSelectedModel()
const { selectedRepository, isFetchingRepositories, repos } =
useSelectedRepository()
const currentMessageForDev = useMemo(() => {
return messages.find(item => item.id === messageIdForDev)
}, [messageIdForDev, messages])
Expand Down Expand Up @@ -535,7 +531,7 @@ export function Search() {
}

const { sourceIdForCodeQuery, sourceIdsForDocQuery, searchPublic } =
getSourceInputs(selectedRepoId, ctx)
getSourceInputs(selectedRepository?.sourceId, ctx)

const codeQuery: InputMaybe<CodeQueryInput> = sourceIdForCodeQuery
? { sourceId: sourceIdForCodeQuery, content: question }
Expand Down Expand Up @@ -602,7 +598,7 @@ export function Search() {

const { sourceIdForCodeQuery, sourceIdsForDocQuery, searchPublic } =
getSourceInputs(
selectedRepoId,
selectedRepository?.sourceId,
getThreadRunContextsFromMentions(mentions)
)

Expand Down Expand Up @@ -694,7 +690,7 @@ export function Search() {
}

const onSelectedRepo = (sourceId: string | undefined) => {
updateSelectedRepo(sourceId)
updateSelectedCodeSourceId(sourceId)
}

const formatedThreadError: ExtendedCombinedError | undefined = useMemo(() => {
Expand Down Expand Up @@ -774,7 +770,7 @@ export function Search() {
onDeleteMessage,
isThreadOwner,
onUpdateMessage,
repositories: repositorySourceListData?.repositoryList
repositories: repos
}}
>
<div className="transition-all" style={style}>
Expand Down Expand Up @@ -913,9 +909,11 @@ export function Search() {
fetchingContextInfo={fetchingContextInfo}
modelName={selectedModel}
onSelectModel={onSelectModel}
repoSourceId={selectedRepoId}
repoSourceId={selectedRepository?.sourceId}
onSelectRepo={onSelectedRepo}
isModelLoading={isModelLoading}
isInitializingResources={
isFetchingModels || isFetchingRepositories
}
models={models}
/>
</div>
Expand Down
12 changes: 6 additions & 6 deletions ee/tabby-ui/components/textarea-search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ export default function TextAreaSearch({
isFollowup,
contextInfo,
fetchingContextInfo,
isModelLoading,
isInitializingResources,
models
}: {
onSearch: (value: string, ctx: ThreadRunContexts) => void
onSelectModel: (v: string) => void
isModelLoading: boolean
isInitializingResources: boolean
// selected model
modelName: string | undefined
// selected repo
Expand Down Expand Up @@ -97,7 +97,7 @@ export default function TextAreaSearch({
}

const handleSubmit = (editor: Editor | undefined | null) => {
if (!editor || isLoading || isModelLoading) {
if (!editor || isLoading || isInitializingResources) {
return
}

Expand Down Expand Up @@ -226,7 +226,7 @@ export default function TextAreaSearch({
<Separator orientation="vertical" className="h-5" />
{showModelSelect && (
<ModelSelect
isInitializing={isModelLoading}
isInitializing={isInitializingResources}
models={models}
value={modelName}
onChange={handleSelectModel}
Expand All @@ -243,7 +243,7 @@ export default function TextAreaSearch({
'bg-primary text-primary-foreground cursor-pointer':
value.length > 0,
'!bg-muted !text-primary !cursor-default':
isLoading || value.length === 0 || isModelLoading,
isLoading || value.length === 0 || isInitializingResources,
'mr-1.5': !showBetaBadge
}
)}
Expand All @@ -268,7 +268,7 @@ export default function TextAreaSearch({
onClick={e => e.stopPropagation()}
>
<LoadingWrapper
loading={isModelLoading || fetchingContextInfo}
loading={isInitializingResources || fetchingContextInfo}
delay={0}
fallback={
<div className="flex h-8 w-[40%] items-center">
Expand Down
8 changes: 4 additions & 4 deletions ee/tabby-ui/lib/hooks/use-models.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@ export function useModels(): SWRResponse<ModelInfo> {
}

export function useSelectedModel() {
const { data: modelData, isLoading: isFetchingModel } = useModels()
const { data: modelData, isLoading } = useModels()

const selectedModel = useStore(useChatStore, state => state.selectedModel)

useEffect(() => {
if (!isFetchingModel) {
if (!isLoading) {
// init model
const validModel = getModelFromModelInfo(selectedModel, modelData?.chat)
updateSelectedModel(validModel)
}
}, [isFetchingModel])
}, [isLoading])

return {
// fetching model data or trying to get selected model from localstorage
isModelLoading: isFetchingModel,
isFetchingModels: isLoading,
selectedModel,
models: modelData?.chat
}
Expand Down
46 changes: 46 additions & 0 deletions ee/tabby-ui/lib/hooks/use-repositories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
'use client'

import { useMemo } from 'react'
import { useQuery } from 'urql'

import { graphql } from '@/lib/gql/generates'

import { useChatStore } from '../stores/chat-store'

const repositorySourceListQuery = graphql(/* GraphQL */ `
query RepositorySourceList {
repositoryList {
id
name
kind
gitUrl
sourceId
sourceName
sourceKind
}
}
`)

export function useRepositorySources() {
return useQuery({
query: repositorySourceListQuery
})
}

export function useSelectedRepository() {
const [{ data, fetching }] = useRepositorySources()
const repos = data?.repositoryList
const repoId = useChatStore(state => state.selectedCodeSourceId)

const selectedRepository = useMemo(() => {
if (!repos?.length || !repoId) return undefined

return repos.find(repo => repo.sourceId === repoId)
}, [repos, repoId])

return {
repos,
isFetchingRepositories: fetching,
selectedRepository
}
}
4 changes: 2 additions & 2 deletions ee/tabby-ui/lib/stores/chat-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export const updateSelectedModel = (model: string | undefined) => {
set(() => ({ selectedModel: model }))
}

export const updateSelectedRepo = (sourceId: string | undefined) => {
set(() => ({ selectedRepo: sourceId }))
export const updateSelectedCodeSourceId = (sourceId: string | undefined) => {
set(() => ({ selectedCodeSourceId: sourceId }))
}

export const updateEnableActiveSelection = (enable: boolean) => {
Expand Down
4 changes: 2 additions & 2 deletions ee/tabby-ui/lib/stores/chat-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ const excludeFromState = ['activeChatId']
export interface ChatState {
activeChatId: string | undefined
selectedModel: string | undefined
selectedRepo: string | undefined
selectedCodeSourceId: string | undefined
enableActiveSelection: boolean
}

const initialState: ChatState = {
activeChatId: nanoid(),
selectedModel: undefined,
selectedRepo: undefined,
selectedCodeSourceId: undefined,
enableActiveSelection: true
}

Expand Down
14 changes: 0 additions & 14 deletions ee/tabby-ui/lib/tabby/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,17 +473,3 @@ export const notificationsQuery = graphql(/* GraphQL */ `
}
}
`)

export const repositorySourceListQuery = graphql(/* GraphQL */ `
query RepositorySourceList {
repositoryList {
id
name
kind
gitUrl
sourceId
sourceName
sourceKind
}
}
`)

0 comments on commit 12427ae

Please sign in to comment.