-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): add debug mode of answer engine (#2705)
* feat(ui): add debug mode of answer engine * update: debug toggle * [autofix.ci] apply automated fixes * update: enableDebug * update: use ResizablePanel * [autofix.ci] apply automated fixes * update: scroll * update: toggle full screen * Update ee/tabby-ui/lib/experiment-flags.ts Co-authored-by: Meng Zhang <[email protected]> * rename * remove vaul * rename * update --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Meng Zhang <[email protected]>
- Loading branch information
1 parent
ac313f3
commit c60c817
Showing
7 changed files
with
522 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import React, { lazy, Suspense, useEffect, useRef } from 'react' | ||
|
||
import { useEnableDeveloperMode } from '@/lib/experiment-flags' | ||
import { useCurrentTheme } from '@/lib/hooks/use-current-theme' | ||
import { cn } from '@/lib/utils' | ||
import { Button } from '@/components/ui/button' | ||
import { IconChevronDown, IconClose } from '@/components/ui/icons' | ||
import { ScrollArea } from '@/components/ui/scroll-area' | ||
import { ListSkeleton } from '@/components/skeleton' | ||
|
||
const ReactJsonView = lazy(() => import('react-json-view')) | ||
|
||
interface DevPanelProps { | ||
isFullScreen: boolean | ||
onToggleFullScreen: (fullScreen: boolean) => void | ||
value: object | undefined | ||
onClose: () => void | ||
} | ||
|
||
export const DevPanel: React.FC<DevPanelProps> = ({ | ||
value, | ||
isFullScreen, | ||
onToggleFullScreen, | ||
onClose | ||
}) => { | ||
const [enableDeveloperMode] = useEnableDeveloperMode() | ||
const { theme } = useCurrentTheme() | ||
const scrollAreaRef = useRef<HTMLDivElement>(null) | ||
|
||
useEffect(() => { | ||
if (value) { | ||
scrollAreaRef.current?.children?.[1]?.scrollTo({ | ||
top: 0, | ||
behavior: 'smooth' | ||
}) | ||
} | ||
}, [value]) | ||
|
||
if (!enableDeveloperMode?.value) return null | ||
|
||
if (!open) return null | ||
|
||
return ( | ||
<div className="flex h-full flex-col px-3 pt-2"> | ||
<div className="flex items-center justify-end pb-2"> | ||
<div className="flex items-center gap-2"> | ||
<Button | ||
variant="ghost" | ||
size="icon" | ||
onClick={e => onToggleFullScreen(!isFullScreen)} | ||
> | ||
<IconChevronDown | ||
className={cn('transition-all', isFullScreen ? '' : 'rotate-180')} | ||
/> | ||
</Button> | ||
<Button variant="ghost" size="icon" onClick={onClose}> | ||
<IconClose /> | ||
</Button> | ||
</div> | ||
</div> | ||
<Suspense fallback={<ListSkeleton className="p-2" />}> | ||
{value ? ( | ||
<ScrollArea className="flex-1" ref={scrollAreaRef}> | ||
<ReactJsonView | ||
theme={theme === 'dark' ? 'tomorrow' : 'rjv-default'} | ||
src={value} | ||
style={{ fontSize: '0.75rem' }} | ||
collapseStringsAfterLength={120} | ||
/> | ||
</ScrollArea> | ||
) : null} | ||
</Suspense> | ||
</div> | ||
) | ||
} |
Oops, something went wrong.