Skip to content

Commit

Permalink
fix(ui): use the proper URL to request the repository entry (#2127)
Browse files Browse the repository at this point in the history
* fix(ui): use the proper URL to request the repository entry

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and wsxiaoys committed May 15, 2024
1 parent cef168a commit c515c7d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 15 deletions.
10 changes: 8 additions & 2 deletions ee/tabby-ui/app/files/components/file-tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ import {
import { Skeleton } from '@/components/ui/skeleton'

import { SourceCodeBrowserContext, TFileMap } from './source-code-browser'
import { resolveFileNameFromPath, resolveRepositoryInfoFromPath } from './utils'
import {
encodeURIComponentIgnoringSlash,
resolveFileNameFromPath,
resolveRepositoryInfoFromPath
} from './utils'

type TFileTreeNode = {
name: string
Expand Down Expand Up @@ -241,7 +245,9 @@ const DirectoryTreeNode: React.FC<DirectoryTreeNodeProps> = ({
const { data, isLoading }: SWRResponse<ResolveEntriesResponse> =
useSWRImmutable(
shouldFetchChildren
? `/repositories/${activeRepoIdentity}/resolve/${basename}`
? encodeURIComponentIgnoringSlash(
`/repositories/${activeRepoIdentity}/resolve/${basename}`
)
: null,
fetcher,
{
Expand Down
9 changes: 7 additions & 2 deletions ee/tabby-ui/app/files/components/source-code-browser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { FileTreePanel } from './file-tree-panel'
import { RawFileView } from './raw-file-view'
import { TextFileView } from './text-file-view'
import {
encodeURIComponentIgnoringSlash,
fetchEntriesFromPath,
getDirectoriesFromBasename,
repositoryList2Map,
Expand Down Expand Up @@ -267,7 +268,9 @@ const SourceCodeBrowserRenderer: React.FC<SourceCodeBrowserProps> = ({
contentLength?: number
}>(
isFileSelected
? `/repositories/${activeRepoIdentity}/resolve/${activeBasename}`
? encodeURIComponentIgnoringSlash(
`/repositories/${activeRepoIdentity}/resolve/${activeBasename}`
)
: null,
(url: string) =>
fetcher(url, {
Expand Down Expand Up @@ -301,7 +304,9 @@ const SourceCodeBrowserRenderer: React.FC<SourceCodeBrowserProps> = ({
isLoading: fetchingSubTree
}: SWRResponse<ResolveEntriesResponse> = useSWRImmutable(
shouldFetchSubDir
? `/repositories/${activeRepoIdentity}/resolve/${activeBasename}`
? encodeURIComponentIgnoringSlash(
`/repositories/${activeRepoIdentity}/resolve/${activeBasename}`
)
: null,
fetcher
)
Expand Down
18 changes: 14 additions & 4 deletions ee/tabby-ui/app/files/components/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,11 @@ async function fetchEntriesFromPath(
directoryPaths.map(
dir => () =>
fetcher(
`/repositories/${repository.kind.toLowerCase()}/${
repository.id
}/resolve/${dir}`
encodeURIComponentIgnoringSlash(
`/repositories/${repository.kind.toLowerCase()}/${
repository.id
}/resolve/${dir}`
)
).catch(e => [])
)
const entries = await Promise.all(requests.map(fn => fn()))
Expand Down Expand Up @@ -117,11 +119,19 @@ function repositoryList2Map(repos: RepositoryListQuery['repositoryList']) {
return keyBy(repos, o => `${o.kind.toLowerCase()}/${o.name}`)
}

function encodeURIComponentIgnoringSlash(str: string) {
return str
.split('/')
.map(part => encodeURIComponent(part))
.join('/')
}

export {
resolveRepoSpecifierFromRepoInfo,
resolveFileNameFromPath,
getDirectoriesFromBasename,
fetchEntriesFromPath,
resolveRepositoryInfoFromPath,
repositoryList2Map
repositoryList2Map,
encodeURIComponentIgnoringSlash
}
21 changes: 14 additions & 7 deletions ee/tabby-ui/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1846,6 +1846,18 @@
tslib "^2.5.0"
webcrypto-core "^1.7.7"

"@quilted/events@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@quilted/events/-/events-2.0.0.tgz#7470ec92e94be1e4628e97f1a1e7726c15cf4e2f"
integrity sha512-0Q5w7jgHPj3nD8sTh1o7oa7LFxATK+dH0i4p8Y6BgKBLDOkr9/m01IDUXsbZdZ98XvxQaVkxBF/HUNAFfg/KfA==

"@quilted/threads@^2.1.2":
version "2.1.2"
resolved "https://registry.yarnpkg.com/@quilted/threads/-/threads-2.1.2.tgz#3c91d557e24cfe1edda1cd512dc0b85c3b9cf6e7"
integrity sha512-jkeh2K+Lbj9MkNXKsLab7Zu+kS16XcoGqBUOFXQNQerfJxMWSpVBliS4tG4chgte0YS6Ot4+fFRf19147gI0aQ==
dependencies:
"@quilted/events" "^2.0.0"

"@radix-ui/[email protected]":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@radix-ui/number/-/number-1.0.1.tgz#644161a3557f46ed38a042acf4a770e826021674"
Expand Down Expand Up @@ -2437,11 +2449,6 @@
dependencies:
"@babel/runtime" "^7.13.10"

"@remote-ui/rpc@^1.4.5":
version "1.4.5"
resolved "https://registry.yarnpkg.com/@remote-ui/rpc/-/rpc-1.4.5.tgz#20328970c314374d96fdaae1cf93aca4b47fefee"
integrity sha512-Cr+06niG/vmE4A9YsmaKngRuuVSWKMY42NMwtZfy+gctRWGu6Wj9BWuMJg5CEp+JTkRBPToqT5rqnrg1G/Wvow==

"@repeaterjs/repeater@^3.0.4":
version "3.0.5"
resolved "https://registry.yarnpkg.com/@repeaterjs/repeater/-/repeater-3.0.5.tgz#b77571685410217a548a9c753aa3cdfc215bfc78"
Expand Down Expand Up @@ -8032,9 +8039,9 @@ tabbable@^6.2.0:
integrity sha512-Cat63mxsVJlzYvN51JmVXIgNoUokrIaT2zLclCXjRd8boZ0004U4KCs/sToJ75C6sdlByWxpYnb5Boif1VSFew==

tabby-chat-panel@../../clients/tabby-chat-panel:
version "0.0.0"
version "0.0.0-dev.3"
dependencies:
"@remote-ui/rpc" "^1.4.5"
"@quilted/threads" "^2.1.2"
react "^18.3.1"

tailwind-merge@^1.12.0:
Expand Down

0 comments on commit c515c7d

Please sign in to comment.