From 2795b038bc579e2bde3dd4bf27e9e58ac95cc472 Mon Sep 17 00:00:00 2001 From: anastasiia Date: Tue, 12 Dec 2023 09:02:22 -0500 Subject: [PATCH] use /file and /folder endpoints instead of /q?open:true --- .../ChatTab/Message/LoadingStep.tsx | 43 ++++++++++++ .../ChatTab/Message/index.tsx | 31 +++------ .../src/Project/CurrentTabContent/FileTab.tsx | 67 +++++++++---------- .../CurrentTabContent/Header/TabButton.tsx | 34 ++++++++-- .../src/Project/CurrentTabContent/index.tsx | 1 - .../src/Project/LeftSidebar/NavPanel/Repo.tsx | 19 +++--- .../LeftSidebar/NavPanel/RepoEntry.tsx | 6 +- .../Project/LeftSidebar/NavPanel/index.tsx | 3 - .../RegexSearchPanel/AutocompleteMenuItem.tsx | 1 - .../RegexSearchPanel/Results/CodeLine.tsx | 5 +- .../RegexSearchPanel/Results/CodeResult.tsx | 9 +-- .../RegexSearchPanel/Results/FileResult.tsx | 8 +-- .../LeftSidebar/RegexSearchPanel/index.tsx | 33 ++++----- client/src/Project/LeftSidebar/index.tsx | 6 +- .../components/Breadcrumbs/PathContainer.tsx | 4 +- .../components/Code/CodeBlockSearch/index.tsx | 7 +- client/src/components/Code/CodeFull/index.tsx | 6 +- .../MarkdownWithCode/CodeRenderer.tsx | 39 ++++++----- .../MarkdownWithCode/CodeWithBreadcrumbs.tsx | 3 - .../components/MarkdownWithCode/DiffCode.tsx | 4 +- .../MarkdownWithCode/FolderChip.tsx | 22 +++--- .../MarkdownWithCode/LinkRenderer.tsx | 27 ++++---- .../src/components/MarkdownWithCode/index.tsx | 2 +- .../RefsDefsPopup/RefDefFileItem.tsx | 3 - client/src/components/RefsDefsPopup/index.tsx | 3 - .../context/providers/TabsContextProvider.tsx | 4 +- client/src/context/tabsContext.tsx | 1 - client/src/icons/Wrapper.tsx | 20 +++--- client/src/mappers/conversation.ts | 1 + client/src/services/api.ts | 40 ++++++++--- client/src/types/general.ts | 1 - 31 files changed, 250 insertions(+), 203 deletions(-) create mode 100644 client/src/Project/CurrentTabContent/ChatTab/Message/LoadingStep.tsx diff --git a/client/src/Project/CurrentTabContent/ChatTab/Message/LoadingStep.tsx b/client/src/Project/CurrentTabContent/ChatTab/Message/LoadingStep.tsx new file mode 100644 index 0000000000..67e2468a04 --- /dev/null +++ b/client/src/Project/CurrentTabContent/ChatTab/Message/LoadingStep.tsx @@ -0,0 +1,43 @@ +import { memo, useCallback, useContext } from 'react'; +import { useTranslation } from 'react-i18next'; +import FileChip from '../../../../components/Chips/FileChip'; +import { ChatLoadingStep, TabTypesEnum } from '../../../../types/general'; +import { TabsContext } from '../../../../context/tabsContext'; + +type Props = ChatLoadingStep & { + side: 'left' | 'right'; + repo?: string; +}; + +const LoadingStep = ({ type, path, displayText, side, repo }: Props) => { + const { t } = useTranslation(); + const { openNewTab } = useContext(TabsContext.Handlers); + + const handleClickFile = useCallback(() => { + if (type === 'proc' && repo && path) { + openNewTab( + { + type: TabTypesEnum.FILE, + repoRef: repo, + path, + }, + side === 'left' ? 'right' : 'left', + ); + } + }, [path, repo, side]); + + return ( +
+ {type === 'proc' ? t('Reading ') : displayText} + {type === 'proc' ? ( + + ) : null} +
+ ); +}; + +export default memo(LoadingStep); diff --git a/client/src/Project/CurrentTabContent/ChatTab/Message/index.tsx b/client/src/Project/CurrentTabContent/ChatTab/Message/index.tsx index a9f34026ce..0374fad887 100644 --- a/client/src/Project/CurrentTabContent/ChatTab/Message/index.tsx +++ b/client/src/Project/CurrentTabContent/ChatTab/Message/index.tsx @@ -1,4 +1,4 @@ -import { memo, useCallback, useContext, useState } from 'react'; +import { memo, useCallback, useContext, useEffect, useState } from 'react'; import { Trans, useTranslation } from 'react-i18next'; import { format } from 'date-fns'; import { @@ -22,11 +22,12 @@ import SpinLoaderContainer from '../../../../components/Loaders/SpinnerLoader'; import { getPlainFromStorage, LOADING_STEPS_SHOWN_KEY, + savePlainToStorage, } from '../../../../services/storage'; import { LocaleContext } from '../../../../context/localeContext'; -import FileChip from '../../../../components/Chips/FileChip'; import { upvoteAnswer } from '../../../../services/api'; import UserParsedQuery from './UserParsedQuery'; +import LoadingStep from './LoadingStep'; type Props = { author: ChatMessageAuthor; @@ -76,6 +77,13 @@ const ConversationMessage = ({ : true, ); + useEffect(() => { + savePlainToStorage( + LOADING_STEPS_SHOWN_KEY, + isLoadingStepsShown ? '1' : '0', + ); + }, [isLoadingStepsShown]); + const toggleStepsShown = useCallback(() => { setLoadingStepsShown((prev) => !prev); }, []); @@ -195,24 +203,7 @@ const ConversationMessage = ({ }} > {loadingSteps.map((s, i) => ( -
- - {s.type === 'proc' ? t('Reading ') : s.displayText} - - {s.type === 'proc' ? ( - - // navigateFullResult(s.path, undefined, i, threadId) - {} - } - fileName={s.path.split('/').pop() || ''} - filePath={s.path || ''} - /> - ) : null} -
+ ))} )} diff --git a/client/src/Project/CurrentTabContent/FileTab.tsx b/client/src/Project/CurrentTabContent/FileTab.tsx index 49de726cea..c5d5235073 100644 --- a/client/src/Project/CurrentTabContent/FileTab.tsx +++ b/client/src/Project/CurrentTabContent/FileTab.tsx @@ -5,18 +5,19 @@ import React, { useEffect, useRef, useState, + useTransition, } from 'react'; import { Trans, useTranslation } from 'react-i18next'; import { forceFileToBeIndexed, + getFileContent, getHoverables, - search, } from '../../services/api'; -import { buildRepoQuery, splitPath } from '../../utils'; +import { splitPath } from '../../utils'; import FileIcon from '../../components/FileIcon'; import Button from '../../components/Button'; import { EyeCutIcon, MoreHorizontalIcon } from '../../icons'; -import { File } from '../../types/api'; +import { FileResponse } from '../../types/api'; import { mapRanges } from '../../mappers/results'; import { Range } from '../../types/results'; import CodeFull from '../../components/Code/CodeFull'; @@ -27,7 +28,6 @@ import { DeviceContext } from '../../context/deviceContext'; import { ProjectContext } from '../../context/projectContext'; type Props = { - repoName: string; repoRef: string; path: string; scrollToLine?: string; @@ -37,7 +37,6 @@ type Props = { }; const FileTab = ({ - repoName, path, noBorder, repoRef, @@ -46,39 +45,40 @@ const FileTab = ({ tokenRange, }: Props) => { const { t } = useTranslation(); - const [file, setFile] = useState< - (File & { hoverableRanges?: Record }) | null - >(null); + const [file, setFile] = useState(null); + const [hoverableRanges, setHoverableRanges] = useState< + Record | undefined + >(undefined); const [indexRequested, setIndexRequested] = useState(false); + const [isFetched, setIsFetched] = useState(false); const { apiUrl } = useContext(DeviceContext); const { refreshCurrentProjectRepos } = useContext(ProjectContext.Current); const eventSourceRef = useRef(null); + const [isPending, startTransition] = useTransition(); useEffect(() => { setIndexRequested(false); - }, [repoName, path, repoRef]); + }, [path, repoRef]); const refetchFile = useCallback(() => { - search(buildRepoQuery(repoName, path, branch)).then((resp) => { - const item = resp?.data?.[0]?.data as File; - if (!item) { - return; - } - setFile(item); - if (item.indexed) { - getHoverables( - item.relative_path, - item.repo_ref, - // selectedBranch ? selectedBranch : undefined, - ).then((data) => { - setFile((prevState) => ({ - ...prevState!, - hoverableRanges: mapRanges(data.ranges), - })); + getFileContent(repoRef, path, branch) + .then((resp) => { + if (!resp) { + return; + } + startTransition(() => { + setFile(resp); }); - } - }); - }, [repoName, path, branch]); + // if (item.indexed) { + getHoverables(path, repoRef, branch).then((data) => { + setHoverableRanges(mapRanges(data.ranges)); + }); + // } + }) + .finally(() => { + setIsFetched(true); + }); + }, [repoRef, path, branch]); useEffect(() => { refetchFile(); @@ -153,19 +153,18 @@ const FileTab = ({
{file?.lang === 'jupyter notebook' ? ( - ) : file?.indexed ? ( + ) : file ? ( - ) : !!file && !file.indexed ? ( + ) : isFetched && !file ? (
diff --git a/client/src/Project/CurrentTabContent/Header/TabButton.tsx b/client/src/Project/CurrentTabContent/Header/TabButton.tsx index c2a183a83a..df92ec65dd 100644 --- a/client/src/Project/CurrentTabContent/Header/TabButton.tsx +++ b/client/src/Project/CurrentTabContent/Header/TabButton.tsx @@ -26,10 +26,12 @@ type Props = TabType & { moveTab: (i: number, j: number) => void; i: number; repoRef?: string; - repoName?: string; path?: string; threadId?: string; name?: string; + branch?: string | null; + scrollToLine?: string; + tokenRange?: string; }; const TabButton = ({ @@ -43,8 +45,10 @@ const TabButton = ({ side, moveTab, isOnlyTab, - repoName, i, + branch, + scrollToLine, + tokenRange, }: Props) => { const { t } = useTranslation(); const { closeTab, setActiveLeftTab, setActiveRightTab, setFocusedPanel } = @@ -105,7 +109,17 @@ const TabButton = ({ id: tabKey, index: i, // @ts-ignore - t: { key: tabKey, repoRef, repoName, path, type, threadId, name }, + t: { + key: tabKey, + repoRef: repoRef!, + path: path!, + type, + threadId, + name, + branch, + scrollToLine, + tokenRange, + }, side, }; }, @@ -126,9 +140,19 @@ const TabButton = ({ const handleClick = useCallback(() => { const setAction = side === 'left' ? setActiveLeftTab : setActiveRightTab; // @ts-ignore - setAction({ path, repoRef, repoName, key: tabKey, type, threadId, name }); + setAction({ + path, + repoRef, + key: tabKey, + type, + threadId, + name, + branch, + scrollToLine, + tokenRange, + }); setFocusedPanel(side); - }, [path, repoRef, tabKey, side, repoName]); + }, [path, repoRef, tabKey, side, branch, scrollToLine, tokenRange]); return ( { >; isExpanded: boolean; @@ -41,7 +40,6 @@ type Props = { const reactRoot = document.getElementById('root')!; const RepoNav = ({ - repoName, repoRef, i, isExpanded, @@ -59,11 +57,11 @@ const RepoNav = ({ const fetchFiles = useCallback( async (path?: string) => { - const resp = await search(buildRepoQuery(repoName, path, branch)); - if (!resp.data?.[0]?.data) { + const resp = await getFolderContent(repoRef, path, branch); + if (!resp.entries) { return []; } - return (resp.data[0].data as Directory)?.entries.sort((a, b) => { + return resp?.entries.sort((a, b) => { if ((a.entry_data === 'Directory') === (b.entry_data === 'Directory')) { return a.name.toLowerCase() < b.name.toLowerCase() ? -1 : 1; } else { @@ -71,7 +69,7 @@ const RepoNav = ({ } }); }, - [repoName, branch], + [repoRef, branch], ); const refetchParentFolder = useCallback(() => { @@ -124,7 +122,7 @@ const RepoNav = ({ )}

- {splitPath(repoName).pop()} + {splitPath(repoRef).pop()}

{isExpanded && ( <> @@ -174,7 +172,6 @@ const RepoNav = ({ fetchFiles={fetchFiles} fullPath={f.name} repoRef={repoRef} - repoName={repoName} currentPath={currentPath} lastIndex={lastIndex} branch={branch} diff --git a/client/src/Project/LeftSidebar/NavPanel/RepoEntry.tsx b/client/src/Project/LeftSidebar/NavPanel/RepoEntry.tsx index cd7dda8067..3016102665 100644 --- a/client/src/Project/LeftSidebar/NavPanel/RepoEntry.tsx +++ b/client/src/Project/LeftSidebar/NavPanel/RepoEntry.tsx @@ -21,7 +21,6 @@ type Props = { defaultOpen?: boolean; indexed: boolean; repoRef: string; - repoName: string; lastIndex: string; currentPath?: string; branch?: string | null; @@ -37,7 +36,6 @@ const RepoEntry = ({ defaultOpen, indexed, repoRef, - repoName, lastIndex, branch, }: Props) => { @@ -87,11 +85,10 @@ const RepoEntry = ({ type: TabTypesEnum.FILE, path: fullPath, repoRef, - repoName, branch, }); } - }, [isDirectory, fullPath, openNewTab, repoRef, repoName, branch]); + }, [isDirectory, fullPath, openNewTab, repoRef, branch]); return (
{ setExpanded={setExpanded} isExpanded={expanded === i} i={i} - repoName={ - r.repo.provider === RepoProvider.Local ? r.repo.name : r.repo.ref - } repoRef={r.repo.ref} branch={r.branch} lastIndex={r.repo.last_index} diff --git a/client/src/Project/LeftSidebar/RegexSearchPanel/AutocompleteMenuItem.tsx b/client/src/Project/LeftSidebar/RegexSearchPanel/AutocompleteMenuItem.tsx index 9b384815c8..45d35695ca 100644 --- a/client/src/Project/LeftSidebar/RegexSearchPanel/AutocompleteMenuItem.tsx +++ b/client/src/Project/LeftSidebar/RegexSearchPanel/AutocompleteMenuItem.tsx @@ -64,7 +64,6 @@ const AutocompleteMenuItem = ({ snippets={snippets} language={item.language} filePath={item.relativePath} - repoName={item.repoName} collapsed={false} repoRef={item.repoRef} /> diff --git a/client/src/Project/LeftSidebar/RegexSearchPanel/Results/CodeLine.tsx b/client/src/Project/LeftSidebar/RegexSearchPanel/Results/CodeLine.tsx index 1119ba0204..f0bc22c4bf 100644 --- a/client/src/Project/LeftSidebar/RegexSearchPanel/Results/CodeLine.tsx +++ b/client/src/Project/LeftSidebar/RegexSearchPanel/Results/CodeLine.tsx @@ -10,7 +10,6 @@ import CodeToken from '../../../../components/Code/CodeToken'; type Props = { path: string; repoRef: string; - repoName: string; lineStart: number; lineEnd: number; code: string; @@ -23,7 +22,6 @@ const noOp = () => {}; const CodeLine = ({ path, repoRef, - repoName, lineStart, lineEnd, code, @@ -37,10 +35,9 @@ const CodeLine = ({ type: TabTypesEnum.FILE, path, repoRef, - repoName, scrollToLine: `${lineStart}_${lineEnd}`, }); - }, [path, lineEnd, lineStart, repoName, repoRef, openNewTab]); + }, [path, lineEnd, lineStart, repoRef, openNewTab]); const lang = useMemo( () => getPrismLanguage(language) || 'plaintext', diff --git a/client/src/Project/LeftSidebar/RegexSearchPanel/Results/CodeResult.tsx b/client/src/Project/LeftSidebar/RegexSearchPanel/Results/CodeResult.tsx index c4749c7733..13cc4da8a8 100644 --- a/client/src/Project/LeftSidebar/RegexSearchPanel/Results/CodeResult.tsx +++ b/client/src/Project/LeftSidebar/RegexSearchPanel/Results/CodeResult.tsx @@ -16,7 +16,6 @@ import CodeLine from './CodeLine'; type Props = { relative_path: string; - repo_name: string; repo_ref: string; lang: string; snippets: SnippetItem[]; @@ -26,7 +25,6 @@ type Props = { const CodeResult = ({ relative_path, - repo_name, repo_ref, lang, snippets, @@ -54,13 +52,12 @@ const CodeResult = ({ openNewTab({ type: TabTypesEnum.FILE, path: relative_path, - repoName: repo_name, repoRef: repo_ref, scrollToLine: `${snippets[0].line_range.start}_${snippets[0].line_range.end}`, }); } }, - [repo_name, repo_ref, relative_path, openNewTab], + [repo_ref, relative_path, openNewTab], ); useKeyboardNavigation(handleKeyEvent, !isFocused); @@ -68,10 +65,9 @@ const CodeResult = ({ openNewTab({ type: TabTypesEnum.FILE, path: relative_path, - repoName: repo_name, repoRef: repo_ref, }); - }, [repo_name, repo_ref, relative_path, openNewTab]); + }, [repo_ref, relative_path, openNewTab]); return (
@@ -106,7 +102,6 @@ const CodeResult = ({ path={relative_path} language={lang} repoRef={repo_ref} - repoName={repo_name} lineStart={s.line_range.start} lineEnd={s.line_range.end} highlights={s.highlights} diff --git a/client/src/Project/LeftSidebar/RegexSearchPanel/Results/FileResult.tsx b/client/src/Project/LeftSidebar/RegexSearchPanel/Results/FileResult.tsx index 678085517f..0d14c1b91e 100644 --- a/client/src/Project/LeftSidebar/RegexSearchPanel/Results/FileResult.tsx +++ b/client/src/Project/LeftSidebar/RegexSearchPanel/Results/FileResult.tsx @@ -8,7 +8,6 @@ import useKeyboardNavigation from '../../../../hooks/useKeyboardNavigation'; type Props = { relative_path: RepoFileNameItem; - repo_name: string; repo_ref: string; is_dir: boolean; isFocused: boolean; @@ -18,7 +17,6 @@ type Props = { const FileResult = ({ relative_path, repo_ref, - repo_name, is_dir, isFocused, isFirst, @@ -41,13 +39,12 @@ const FileResult = ({ openNewTab({ type: TabTypesEnum.FILE, path: relative_path.text, - repoName: repo_name, repoRef: repo_ref, }); } } }, - [repo_name, repo_ref, relative_path, is_dir, openNewTab], + [repo_ref, relative_path, is_dir, openNewTab], ); useKeyboardNavigation(handleKeyEvent, !isFocused); @@ -58,10 +55,9 @@ const FileResult = ({ openNewTab({ type: TabTypesEnum.FILE, path: relative_path.text, - repoName: repo_name, repoRef: repo_ref, }); - }, [relative_path, repo_ref, repo_name, is_dir, openNewTab]); + }, [relative_path, repo_ref, is_dir, openNewTab]); return (
{ +const RegexSearchPanel = ({ projectId }: Props) => { const { t } = useTranslation(); const [inputValue, setInputValue] = useState(''); // const [options, setOptions] = useState([]); @@ -101,7 +103,6 @@ const RegexSearchPanel = ({}: Props) => { // openNewTab({ // type: TabTypesEnum.FILE, // branch: null, - // repoName: state.selectedItem.repoName, // repoRef: state.selectedItem.repoRef, // path: state.selectedItem.relativePath, // }); @@ -135,18 +136,20 @@ const RegexSearchPanel = ({}: Props) => { const onSubmit = useCallback( async (e: FormEvent) => { e.preventDefault(); - const data = await search(inputValue); - const newResults: Record = {}; - data.data.forEach((d) => { - if (!newResults[d.data.repo_ref]) { - newResults[d.data.repo_ref] = [d]; - } else { - newResults[d.data.repo_ref].push(d); - } - }); - setResults(newResults); - setResultsRaw(data.data); - // closeMenu(); + if (projectId) { + const data = await search(projectId, inputValue); + const newResults: Record = {}; + data.data.forEach((d) => { + if (!newResults[d.data.repo_ref]) { + newResults[d.data.repo_ref] = [d]; + } else { + newResults[d.data.repo_ref].push(d); + } + }); + setResults(newResults); + setResultsRaw(data.data); + // closeMenu(); + } }, [inputValue], ); diff --git a/client/src/Project/LeftSidebar/index.tsx b/client/src/Project/LeftSidebar/index.tsx index d9acb782c0..20c5ec0d8f 100644 --- a/client/src/Project/LeftSidebar/index.tsx +++ b/client/src/Project/LeftSidebar/index.tsx @@ -42,7 +42,11 @@ const LeftSidebar = ({}: Props) => {
- {isRegexSearchEnabled ? : } + {isRegexSearchEnabled ? ( + + ) : ( + + )}
; type Props = { path: string; - repo: string; onClick?: (path: string, fileType?: FileTreeFileType) => void; shouldGoToFile?: boolean; nonInteractive?: boolean; @@ -22,7 +21,6 @@ type Props = { const BreadcrumbsPathContainer = ({ path, onClick, - repo, shouldGoToFile, allowOverflow, scrollContainerRef, @@ -51,7 +49,7 @@ const BreadcrumbsPathContainer = ({ // navigateFullResult(path); } }); - }, [path, shouldGoToFile, onClick, repo]); + }, [path, shouldGoToFile, onClick]); return (
{ if (!document.getSelection()?.toString()) { onClick?.( - repoName, + repoRef, filePath, startLine !== undefined && endLine !== undefined ? [startLine, endLine] @@ -54,7 +52,7 @@ const CodeBlockSearch = ({ ); } }, - [onClick, repoName, filePath], + [onClick, repoRef, filePath], ); const totalMatches = useMemo(() => { @@ -136,7 +134,6 @@ const CodeBlockSearch = ({
diff --git a/client/src/components/Code/CodeFull/index.tsx b/client/src/components/Code/CodeFull/index.tsx index 5c85934cca..1e82e0f1d9 100644 --- a/client/src/components/Code/CodeFull/index.tsx +++ b/client/src/components/Code/CodeFull/index.tsx @@ -26,7 +26,6 @@ type Props = { hoverableRanges?: Record; relativePath: string; repoRef: string; - repoName: string; isDiff?: boolean; scrollToLine?: string; branch?: string | null; @@ -37,7 +36,6 @@ const CodeFull = ({ code, isDiff, hoverableRanges, - repoName, repoRef, relativePath, branch, @@ -167,13 +165,12 @@ const CodeFull = ({ type: TabTypesEnum.FILE, path: filePath, repoRef, - repoName, branch, scrollToLine: `${lineNum}_${lineNum}`, tokenRange, }); }, - [openNewTab], + [openNewTab, repoRef, branch], ); useEffect(() => { if (tokenInfo.tokenRange) { @@ -246,7 +243,6 @@ const CodeFull = ({ ; hideCode?: boolean; setFileHighlights: Dispatch>; @@ -36,13 +37,13 @@ const CodeRenderer = ({ fileChips, setFileHighlights, setHoveredLines, - repoName, propsJSON, recordId, threadId, isCodeStudio, side, }: Props) => { + const { openNewTab } = useContext(TabsContext.Handlers); const matchLang = useMemo( () => /lang:(\w+)/.exec(className || '') || @@ -94,9 +95,23 @@ const CodeRenderer = ({ [lines], ); - const handleChipClick = useCallback(() => { - // updateScrollToIndex(`${lines[0]}_${lines[1] ?? lines[0]}`); - }, [lines]); + const onClick = useCallback( + (path?: string, linesToGo?: string) => { + openNewTab( + { + type: TabTypesEnum.FILE, + path: path || filePath, + repoRef, + scrollToLine: + linesToGo || lines + ? `${lines[0]}_${lines[1] ?? lines[0]}` + : undefined, + }, + side === 'left' ? 'right' : 'left', + ); + }, + [openNewTab, filePath, repoRef, lines, side], + ); return ( <> @@ -109,7 +124,7 @@ const CodeRenderer = ({ fileName={filePath || ''} filePath={filePath || ''} skipIcon={false} - onClick={handleChipClick} + onClick={onClick} lines={linesToUse} fileChips={fileChips} setFileHighlights={setFileHighlights} @@ -120,16 +135,8 @@ const CodeRenderer = ({ code={code} language={matchLang?.[1] || ''} filePath={filePath || ''} - onResultClick={(path, lines) => { - // navigateFullResult( - // path, - // lines ? { scrollToLine: lines } : undefined, - // recordId, - // threadId, - // ); - }} + onResultClick={onClick} startLine={lines[0] ? lines[0] : null} - repoName={repoName} /> ) ) : ( diff --git a/client/src/components/MarkdownWithCode/CodeWithBreadcrumbs.tsx b/client/src/components/MarkdownWithCode/CodeWithBreadcrumbs.tsx index af55b1ec1f..3b0c0deb58 100644 --- a/client/src/components/MarkdownWithCode/CodeWithBreadcrumbs.tsx +++ b/client/src/components/MarkdownWithCode/CodeWithBreadcrumbs.tsx @@ -7,7 +7,6 @@ import CopyButton from './CopyButton'; type Props = { filePath: string; - repoName?: string; onResultClick: (path: string, lines?: string) => void; startLine: number | null; language: string; @@ -16,7 +15,6 @@ type Props = { const CodeWithBreadcrumbs = ({ filePath, - repoName, onResultClick, startLine, language, @@ -57,7 +55,6 @@ const CodeWithBreadcrumbs = ({ diff --git a/client/src/components/MarkdownWithCode/DiffCode.tsx b/client/src/components/MarkdownWithCode/DiffCode.tsx index a768065f61..07ce4bfd5f 100644 --- a/client/src/components/MarkdownWithCode/DiffCode.tsx +++ b/client/src/components/MarkdownWithCode/DiffCode.tsx @@ -10,10 +10,9 @@ import { MessageResultModify } from '../../types/general'; type Props = { data: MessageResultModify['Modify']; - repoName: string; }; -const DiffCode = ({ data, repoName }: Props) => { +const DiffCode = ({ data }: Props) => { const [showRaw, setShowRaw] = useState(false); // const { openFileModal } = useContext(FileModalContext); @@ -46,7 +45,6 @@ const DiffCode = ({ data, repoName }: Props) => {
diff --git a/client/src/components/MarkdownWithCode/FolderChip.tsx b/client/src/components/MarkdownWithCode/FolderChip.tsx index e0de547825..7f677cc68b 100644 --- a/client/src/components/MarkdownWithCode/FolderChip.tsx +++ b/client/src/components/MarkdownWithCode/FolderChip.tsx @@ -1,25 +1,26 @@ import React, { useCallback } from 'react'; import { ArrowOutIcon, FolderIcon } from '../../icons'; -import { search } from '../../services/api'; -import { buildRepoQuery } from '../../utils'; -import { Directory } from '../../types/api'; +import { getFolderContent } from '../../services/api'; import OverflowTracker from '../OverflowTracker'; import RepoEntry from '../../Project/LeftSidebar/NavPanel/RepoEntry'; type Props = { onClick: () => void; path: string; - repoName?: string; + repoRef?: string; }; -const FolderChip = ({ onClick, path, repoName }: Props) => { +const FolderChip = ({ onClick, path, repoRef }: Props) => { const fetchFiles = useCallback( async (path?: string) => { - const resp = await search(buildRepoQuery(repoName, path)); - if (!resp.data?.[0]?.data) { + if (!repoRef) { return []; } - return (resp.data[0].data as Directory)?.entries.sort((a, b) => { + const resp = await getFolderContent(repoRef, path); + if (!resp.entries?.length) { + return []; + } + return resp?.entries.sort((a, b) => { if ((a.entry_data === 'Directory') === (b.entry_data === 'Directory')) { return a.name.toLowerCase() < b.name.toLowerCase() ? -1 : 1; } else { @@ -27,7 +28,7 @@ const FolderChip = ({ onClick, path, repoName }: Props) => { } }); }, - [repoName], + [repoRef], ); return ( @@ -60,8 +61,7 @@ const FolderChip = ({ onClick, path, repoName }: Props) => { fullPath={path} defaultOpen indexed - repoRef={''} - repoName={''} + repoRef={repoRef || ''} lastIndex={''} /> diff --git a/client/src/components/MarkdownWithCode/LinkRenderer.tsx b/client/src/components/MarkdownWithCode/LinkRenderer.tsx index 3b4d28437d..3e6c35b3ba 100644 --- a/client/src/components/MarkdownWithCode/LinkRenderer.tsx +++ b/client/src/components/MarkdownWithCode/LinkRenderer.tsx @@ -39,7 +39,7 @@ const LinkRenderer = ({ }: Props) => { const { openNewTab } = useContext(TabsContext.Handlers); const [filePath, lines] = useMemo(() => href?.split('#') || [], [href]); - const [repo, path] = useMemo(() => href?.split(':') || [], [filePath]); + const [repo, path] = useMemo(() => filePath?.split(':') || [], [filePath]); const [start, end] = useMemo( () => lines?.split('-').map((l) => Number(l.slice(1))) || [], [lines], @@ -63,17 +63,18 @@ const LinkRenderer = ({ }, [hideCode, start, end]); const handleClickFile = useCallback(() => { - // openNewTab( - // { - // type: TabTypesEnum.FILE, - // repoName, - // repoRef, - // path: filePath, - // scrollToLine: `${start}_${end ?? start}`, - // }, - // side === 'left' ? 'right' : 'left', - // ); - }, [hideCode, start, end, path, recordId, threadId, side]); + if (repo && path) { + openNewTab( + { + type: TabTypesEnum.FILE, + repoRef: repo, + path, + scrollToLine: `${start}_${end ?? start}`, + }, + side === 'left' ? 'right' : 'left', + ); + } + }, [start, end, path, repo, side]); const handleClickFolder = useCallback(() => { // if (repoName) { @@ -84,7 +85,7 @@ const LinkRenderer = ({ return ( <> {filePath.endsWith('/') ? ( - + ) : ( diff --git a/client/src/components/RefsDefsPopup/index.tsx b/client/src/components/RefsDefsPopup/index.tsx index c4cef54782..5a58de1f57 100644 --- a/client/src/components/RefsDefsPopup/index.tsx +++ b/client/src/components/RefsDefsPopup/index.tsx @@ -45,7 +45,6 @@ const getTailPosition = ( type Props = { placement: TippyProps['placement']; data: TokenInfoWrapped; - repoName: string; onRefDefClick: ( lineNum: number, filePath: string, @@ -63,7 +62,6 @@ export const TypeMap = { const RefsDefsPopup = ({ placement, data, - repoName, onRefDefClick, language, relativePath, @@ -147,7 +145,6 @@ const RefsDefsPopup = ({ onRefDefClick={onRefDefClick} data={item.data} file={item.file} - repoName={repoName} language={language} key={item.file + i} relativePath={relativePath} diff --git a/client/src/context/providers/TabsContextProvider.tsx b/client/src/context/providers/TabsContextProvider.tsx index f17f8aabbc..97d57bb530 100644 --- a/client/src/context/providers/TabsContextProvider.tsx +++ b/client/src/context/providers/TabsContextProvider.tsx @@ -33,7 +33,6 @@ const TabsContextProvider = ({ children }: PropsWithChildren) => { type: TabTypesEnum.FILE; path: string; repoRef: string; - repoName: string; scrollToLine?: string; branch?: string | null; tokenRange?: string; @@ -51,11 +50,10 @@ const TabsContextProvider = ({ children }: PropsWithChildren) => { : setActiveRightTab; setTabsAction((prev) => { const newTab: FileTabType | ChatTabType = - data.type === TabTypesEnum.FILE && data.path && data.repoRef + data.type === TabTypesEnum.FILE ? { path: data.path, repoRef: data.repoRef, - repoName: data.repoName, key: `${data.repoRef}-${data.path}`, scrollToLine: data.scrollToLine, branch: data.branch, diff --git a/client/src/context/tabsContext.tsx b/client/src/context/tabsContext.tsx index 66e4080da6..699522d5c6 100644 --- a/client/src/context/tabsContext.tsx +++ b/client/src/context/tabsContext.tsx @@ -8,7 +8,6 @@ type HandlersContextType = { type: TabTypesEnum.FILE; path: string; repoRef: string; - repoName: string; branch?: string | null; scrollToLine?: string; tokenRange?: string; diff --git a/client/src/icons/Wrapper.tsx b/client/src/icons/Wrapper.tsx index fa25502730..ebbb460f91 100644 --- a/client/src/icons/Wrapper.tsx +++ b/client/src/icons/Wrapper.tsx @@ -4,14 +4,16 @@ const IconWrapper = (icon: ReactNode) => //eslint-disable-next-line ({ sizeClassName, className }: { raw?: boolean; sizeClassName?: string; className?: string }) => - ( - - {icon} - - ); + sizeClassName ? ( + + {icon} + + ) : ( + <>{icon} + ); export default IconWrapper; diff --git a/client/src/mappers/conversation.ts b/client/src/mappers/conversation.ts index 412e3bb567..1048a74ea7 100644 --- a/client/src/mappers/conversation.ts +++ b/client/src/mappers/conversation.ts @@ -15,6 +15,7 @@ export const mapLoadingSteps = ( return s.content.paths.map((pa) => ({ ...s, path: pa.path || '', + repo: pa.repo, displayText: t(`Reading`) + ' ' + diff --git a/client/src/services/api.ts b/client/src/services/api.ts index eec2114ca8..4dd369a7eb 100644 --- a/client/src/services/api.ts +++ b/client/src/services/api.ts @@ -3,6 +3,7 @@ import { AllConversationsResponse, CodeStudioType, ConversationType, + Directory, DocPageType, DocSectionType, DocShortType, @@ -68,13 +69,14 @@ export const initApi = (serverUrl = '', isSelfServe?: boolean) => { }; export const search = ( + projectId: string, q: string, page: number = 0, page_size: number = 5, global_regex: boolean = false, ): Promise => { return http - .get('/q', { + .get(`/projects/${projectId}/q`, { params: { q: `${q} global_regex:${global_regex}`, page_size, @@ -101,19 +103,33 @@ export const searchFiles = ( .then((r) => r.data); }; -export const getFileLines = ( +export const getFileContent = ( repo_ref: string, path: string, - line_start: number, - line_end: number, + branch?: string | null, ): Promise => { return http .get(`/file`, { params: { repo_ref, path, - line_start, - line_end, + ...(branch ? { branch } : {}), + }, + }) + .then((r) => r.data); +}; + +export const getFolderContent = ( + repo_ref: string, + path?: string, + branch?: string | null, +): Promise => { + return http + .get(`/folder`, { + params: { + repo_ref, + path: path || '', + ...(branch ? { branch } : {}), }, }) .then((r) => r.data); @@ -134,13 +150,17 @@ export const nlSearch = ( }; export const getHoverables = async ( - path: string, - repoId: string, - branch?: string, + relative_path: string, + repo_ref: string, + branch?: string | null, ): Promise => { try { const { data } = await http.get('/hoverable', { - params: { relative_path: path, repo_ref: repoId, branch }, + params: { + relative_path, + repo_ref, + ...(branch ? { branch } : {}), + }, }); return data; } catch (e) { diff --git a/client/src/types/general.ts b/client/src/types/general.ts index 12963b036c..3342886109 100644 --- a/client/src/types/general.ts +++ b/client/src/types/general.ts @@ -97,7 +97,6 @@ export type FileTabType = { type: TabTypesEnum.FILE; key: string; path: string; - repoName: string; repoRef: string; branch?: string | null; scrollToLine?: string;