From 2394644b98644f3a9a8cc2c3985af71259471b80 Mon Sep 17 00:00:00 2001 From: liangfung <1098486429@qq.com> Date: Tue, 28 May 2024 19:48:14 +0800 Subject: [PATCH] update: code browser --- .../app/files/components/file-tree.tsx | 3 +- .../files/components/repository-kind-icon.tsx | 2 + .../files/components/source-code-browser.tsx | 7 +++- ee/tabby-ui/app/files/components/utils.ts | 42 ++++++++++++++----- 4 files changed, 42 insertions(+), 12 deletions(-) diff --git a/ee/tabby-ui/app/files/components/file-tree.tsx b/ee/tabby-ui/app/files/components/file-tree.tsx index 6fb5962d708c..f4da75918538 100644 --- a/ee/tabby-ui/app/files/components/file-tree.tsx +++ b/ee/tabby-ui/app/files/components/file-tree.tsx @@ -23,6 +23,7 @@ import { Skeleton } from '@/components/ui/skeleton' import { SourceCodeBrowserContext, TFileMap } from './source-code-browser' import { encodeURIComponentIgnoringSlash, + getProviderVariantFromKind, resolveFileNameFromPath, resolveRepositoryInfoFromPath } from './utils' @@ -246,7 +247,7 @@ const DirectoryTreeNode: React.FC = ({ const repoId = activeRepo?.id if (!kind || !repoId) return '' - return `${kind.toLowerCase()}/${repoId}` + return `${getProviderVariantFromKind(kind)}/${repoId}` }, [activeRepo]) const { repositorySpecifier } = resolveRepositoryInfoFromPath(activePath) diff --git a/ee/tabby-ui/app/files/components/repository-kind-icon.tsx b/ee/tabby-ui/app/files/components/repository-kind-icon.tsx index f472ed8c9fbe..c08cd64e20f9 100644 --- a/ee/tabby-ui/app/files/components/repository-kind-icon.tsx +++ b/ee/tabby-ui/app/files/components/repository-kind-icon.tsx @@ -16,8 +16,10 @@ export function RepositoryKindIcon({ case RepositoryKind.Git: return case RepositoryKind.Github: + case RepositoryKind.GithubSelfHosted: return case RepositoryKind.Gitlab: + case RepositoryKind.GitlabSelfHosted: return default: return fallback ?? null diff --git a/ee/tabby-ui/app/files/components/source-code-browser.tsx b/ee/tabby-ui/app/files/components/source-code-browser.tsx index e512e3054c51..aa6fbdbcba2a 100644 --- a/ee/tabby-ui/app/files/components/source-code-browser.tsx +++ b/ee/tabby-ui/app/files/components/source-code-browser.tsx @@ -38,6 +38,7 @@ import { encodeURIComponentIgnoringSlash, fetchEntriesFromPath, getDirectoriesFromBasename, + getProviderVariantFromKind, repositoryList2Map, resolveFileNameFromPath, resolveRepositoryInfoFromPath, @@ -227,6 +228,8 @@ const SourceCodeBrowserRenderer: React.FC = ({ chatSideBarVisible, setChatSideBarVisible, setPendingEvent, + fileTreeData, + repoMap, setRepoMap, activeRepo } = React.useContext(SourceCodeBrowserContext) @@ -241,7 +244,7 @@ const SourceCodeBrowserRenderer: React.FC = ({ const repoId = activeRepo?.id const kind = activeRepo?.kind if (!repoId || !kind) return '' - return `${activeRepo.kind?.toLowerCase()}/${repoId}` + return `${getProviderVariantFromKind(kind)}/${repoId}` }, [activeRepo]) const activeBasename = React.useMemo(() => { @@ -434,6 +437,8 @@ const SourceCodeBrowserRenderer: React.FC = ({ } }, [chatSideBarVisible]) + console.log('repoMap', repoMap, fileTreeData) + return ( () => fetcher( encodeURIComponentIgnoringSlash( - `/repositories/${repository.kind.toLowerCase()}/${ + `/repositories/${getProviderVariantFromKind(repository.kind)}/${ repository.id }/resolve/${dir}` ) @@ -109,14 +130,14 @@ function resolveRepoSpecifierFromRepoInfo( | undefined ) { if (repo?.kind && repo?.name) { - return `${repo.kind.toLowerCase()}/${repo.name}` + return `${getProviderVariantFromKind(repo.kind)}/${repo.name}` } return undefined } function repositoryList2Map(repos: RepositoryListQuery['repositoryList']) { - return keyBy(repos, o => `${o.kind.toLowerCase()}/${o.name}`) + return keyBy(repos, o => `${getProviderVariantFromKind(o.kind)}/${o.name}`) } function encodeURIComponentIgnoringSlash(str: string) { @@ -133,5 +154,6 @@ export { fetchEntriesFromPath, resolveRepositoryInfoFromPath, repositoryList2Map, - encodeURIComponentIgnoringSlash + encodeURIComponentIgnoringSlash, + getProviderVariantFromKind }