Skip to content

Commit

Permalink
Fix/many bug fixes (#4095)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinlu1248 authored Jun 22, 2024
2 parents 5d80b91 + 8375536 commit b2ee376
Show file tree
Hide file tree
Showing 8 changed files with 829 additions and 726 deletions.
5 changes: 1 addition & 4 deletions sweep_chat/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,9 @@
h1 {
font-size: 2rem;
/* margin-bottom: 1.5rem; */
margin-top: 1rem;
}

h1 {
margin-top: 2rem;
}

h2 {
font-size: 1.5rem;
/* margin-bottom: 1.5rem; */
Expand Down
1,328 changes: 691 additions & 637 deletions sweep_chat/components/App.tsx

Large diffs are not rendered by default.

101 changes: 53 additions & 48 deletions sweep_chat/components/shared/ContextSideBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,70 +16,75 @@ import { PullRequest, Snippet } from '@/lib/types'
import { Dispatch, SetStateAction, useState } from 'react'
import { ScrollArea } from '../ui/scroll-area'
import { SnippetSearch } from './SnippetSearch'
import { HoverCard, HoverCardContent, HoverCardTrigger } from '../ui/hover-card'
import { FaInfoCircle } from 'react-icons/fa'
import PulsingLoader from './PulsingLoader'

const ContextSideBar = ({
snippets,
setSnippets,
repoName,
branch,
k,
searchMessage,
}: {
snippets: Snippet[]
setSnippets: Dispatch<SetStateAction<Snippet[]>>
repoName: string
branch: string
k: number
searchMessage: string
}) => {
const side = 'left'
return (
<>
<div className="grid grid-cols-4 gap-2">
<Sheet key={side}>
<SheetTrigger asChild>
<Button
variant="outline"
className="fixed left-10 top-1/2 px-6 text-white vertical-text text-lg bg-blue-900 hover:bg-blue-800"
>
Manage Context
</Button>
</SheetTrigger>
<SheetContent side={side} className="w-full flex flex-col">
<SheetHeader>
<SheetTitle>Current Context</SheetTitle>
<div className="flex justify-between align-middle">
<SheetDescription className="w-3/4 inline-block align-middle my-auto">
List of current snippets in context. Run a custom search query
to find new snippets.
</SheetDescription>
<SnippetSearch
snippets={snippets}
setSnippets={setSnippets}
repoName={repoName}
branch={branch}
k={k}
/>
</div>
</SheetHeader>
<ScrollArea className="h-3/4 w-full rounded-md border p-4 grow">
{snippets.map((snippet, index) => (
<>
<SnippetBadge
key={index}
snippet={snippet}
repoName={repoName}
branch={branch}
snippets={snippets}
setSnippets={setSnippets}
options={['remove']}
/>
<br />
</>
))}
</ScrollArea>
</SheetContent>
</Sheet>
<div className="h-full w-full flex flex-col">
<div className="pb-2 pl-2">
<h2 className="text-lg font-bold mb-2 flex items-center">
Context
<HoverCard>
<HoverCardTrigger>
<FaInfoCircle className="text-gray-400 hover:text-gray-200 hover:cursor-pointer ml-2" />
</HoverCardTrigger>
<HoverCardContent>
<p className="text-sm text-gray-300">
List of current snippets in context. Run a custom search query
to find new snippets.
</p>
</HoverCardContent>
</HoverCard>
</h2>
</div>
</>
<ScrollArea className="w-full rounded-md border p-4 grow mb-4 overflow-x-auto">
{searchMessage && (
<div className="flex flex-col justify-center items-center">
<p className="text-gray-500 center mb-4">{searchMessage}</p>
<div>
<PulsingLoader size={1} />
</div>
</div>
)}
{snippets.map((snippet, index) => (
<>
<SnippetBadge
key={index}
snippet={snippet}
repoName={repoName}
branch={branch}
snippets={snippets}
setSnippets={setSnippets}
options={['remove']}
/>
<br />
</>
))}
</ScrollArea>
<SnippetSearch
snippets={snippets}
setSnippets={setSnippets}
repoName={repoName}
branch={branch}
k={k}
/>
</div>
)
}

Expand Down
29 changes: 11 additions & 18 deletions sweep_chat/components/shared/SnippetBadge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const RenderPath = ({
)}
{options.includes('add') ? (
<FaPlus
className="ml-3 hover:drop-shadow-md hover:text-gray-300"
className="mr-2 hover:drop-shadow-md hover:text-gray-300"
onClick={() => {
let tempSnippets = [...snippets]
// if we are adding a snippet that means the score should be 1
Expand Down Expand Up @@ -106,31 +106,24 @@ const RenderPath = ({
)}
</span>
<span
className="text-gray-400 inline-block align-middle"
onClick={() => {
window.open(
`https://github.com/${repoName}/blob/${branch}/${snippet.file_path}`,
'_blank'
)
}}
>
{truncatedPath.substring(0, truncatedPath.lastIndexOf('/') + 1)}
<div className="text-white inline-block align-middle mr-2">
{truncatedPath.substring(truncatedPath.lastIndexOf('/') + 1)}
</div>
<div className="text-gray-400 inline-block align-middle">
{truncatedPath}
</div>
</span>
<span
className="text-white inline-block align-middle"
onClick={() => {
window.open(
`https://github.com/${repoName}/blob/${branch}/${snippet.file_path}`,
'_blank'
)
}}
>
{truncatedPath.substring(truncatedPath.lastIndexOf('/') + 1)}
</span>
{snippet.end > snippet.content.split('\n').length - 3 &&
snippet.start == 0 ? (
<></>
) : (
{!(
snippet.end > snippet.content.split('\n').length - 3 &&
snippet.start == 0
) && (
<span className="text-gray-400 inline-block align-middle">
:{snippet.start}-{snippet.end}
</span>
Expand Down
36 changes: 17 additions & 19 deletions sweep_chat/components/shared/SnippetSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { streamMessages } from '@/lib/streamingUtils'
import { useSession } from 'next-auth/react'
import { Session } from 'next-auth'
import PulsingLoader from './PulsingLoader'
import { FaSearchPlus } from 'react-icons/fa'

const SnippetSearch = ({
snippets,
Expand Down Expand Up @@ -105,7 +106,10 @@ const SnippetSearch = ({
return (
<Dialog>
<DialogTrigger asChild>
<Button variant="outline">Add Snippets</Button>
<Button variant="outline">
<FaSearchPlus className="mr-2" />
Add Snippets
</Button>
</DialogTrigger>
<DialogContent className="sm:max-w-9/10 p-8">
<DialogHeader>
Expand All @@ -116,30 +120,32 @@ const SnippetSearch = ({
</DialogDescription>
</DialogHeader>
<div className="grid gap-4 py-4">
<div className="grid grid-cols-4 items-center gap-4">
<Label htmlFor="username" className="text-right">
Search Query
</Label>
<div className="items-center gap-4 flex flex-row">
<Input
id="username"
placeholder="Custom Search Query"
className="col-span-3"
className="grow"
onInput={(event: React.ChangeEvent<HTMLInputElement>) => {
setSearchQuery(event.target.value)
}}
onKeyDown={handleKeyDown}
/>
<Button
className="text-white bg-blue-900 hover:bg-blue-800 w-fit"
disabled={searchQuery.length == 0 || searchIsLoading}
onClick={searchForSnippets}
>
{searchIsLoading ? 'Searching...' : 'Search'}
</Button>
</div>
</div>
{searchIsLoading ? (
{searchIsLoading && (
<div className="flex flex-col justify-center items-center">
<p className="text-gray-500 center mb-4">{progressMessage}</p>
<div>
<PulsingLoader size={2} />
<PulsingLoader size={1} />
</div>
</div>
) : (
<></>
)}
{newSnippets.length > 0 && (
<ScrollArea className="h-full w-full rounded-md border mb-6 p-4">
Expand All @@ -158,15 +164,7 @@ const SnippetSearch = ({
))}
</ScrollArea>
)}
<DialogFooter>
<Button
className="text-white bg-blue-900 hover:bg-blue-800"
disabled={searchQuery.length == 0 || searchIsLoading}
onClick={searchForSnippets}
>
{searchIsLoading ? 'Searching...' : 'Search'}
</Button>
</DialogFooter>
<DialogFooter></DialogFooter>
</DialogContent>
</Dialog>
)
Expand Down
45 changes: 45 additions & 0 deletions sweep_chat/components/ui/resizable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
'use client'

import { GripVertical } from 'lucide-react'
import * as ResizablePrimitive from 'react-resizable-panels'

import { cn } from '@/lib/utils'

const ResizablePanelGroup = ({
className,
...props
}: React.ComponentProps<typeof ResizablePrimitive.PanelGroup>) => (
<ResizablePrimitive.PanelGroup
className={cn(
'flex h-full w-full data-[panel-group-direction=vertical]:flex-col',
className
)}
{...props}
/>
)

const ResizablePanel = ResizablePrimitive.Panel

const ResizableHandle = ({
withHandle,
className,
...props
}: React.ComponentProps<typeof ResizablePrimitive.PanelResizeHandle> & {
withHandle?: boolean
}) => (
<ResizablePrimitive.PanelResizeHandle
className={cn(
'relative flex w-px items-center justify-center bg-border after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-1 data-[panel-group-direction=vertical]:h-px data-[panel-group-direction=vertical]:w-full data-[panel-group-direction=vertical]:after:left-0 data-[panel-group-direction=vertical]:after:h-1 data-[panel-group-direction=vertical]:after:w-full data-[panel-group-direction=vertical]:after:-translate-y-1/2 data-[panel-group-direction=vertical]:after:translate-x-0 [&[data-panel-group-direction=vertical]>div]:rotate-90',
className
)}
{...props}
>
{withHandle && (
<div className="z-10 flex h-4 w-3 items-center justify-center rounded-sm border bg-border">
<GripVertical className="h-2.5 w-2.5" />
</div>
)}
</ResizablePrimitive.PanelResizeHandle>
)

export { ResizablePanelGroup, ResizablePanel, ResizableHandle }
10 changes: 10 additions & 0 deletions sweep_chat/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions sweep_chat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"react-dom": "^18",
"react-icons": "^5.2.1",
"react-markdown": "^9.0.1",
"react-resizable-panels": "^2.0.19",
"react-syntax-highlighter": "^15.5.0",
"remark-gfm": "^4.0.0",
"skeleton": "^0.1.2",
Expand Down

0 comments on commit b2ee376

Please sign in to comment.