From 20ce05fc6a6cecd85d06eaaabf3f4ca171dabefa Mon Sep 17 00:00:00 2001 From: skull8888888 Date: Sat, 26 Oct 2024 16:15:53 -0700 Subject: [PATCH 1/2] refactored code editor (#97) --- frontend/app/globals.css | 4 +- .../traces/chat-message-list-tab.tsx | 1 + frontend/components/traces/span-card.tsx | 4 +- frontend/components/traces/span-view-span.tsx | 2 + frontend/components/ui/code-editor.tsx | 20 ++--- frontend/components/ui/formatter.tsx | 76 ++++++++++++------- 6 files changed, 64 insertions(+), 43 deletions(-) diff --git a/frontend/app/globals.css b/frontend/app/globals.css index ad27ab99..5577d34f 100644 --- a/frontend/app/globals.css +++ b/frontend/app/globals.css @@ -41,13 +41,13 @@ --card: 240 8% 10%; --card-foreground: 240 8% 80%; - --popover: 240 8% 8%; + --popover: 240 0% 6%; --popover-foreground: 240 8% 80%; --primary: 16 83% 59%; --primary-foreground: 16 0% 91%; - --secondary: 232 9% 17%; + --secondary: 240 4% 11%; --secondary-foreground: 240 8% 70%; --muted: 240 6% 16%; diff --git a/frontend/components/traces/chat-message-list-tab.tsx b/frontend/components/traces/chat-message-list-tab.tsx index 4a3ae3e6..7ad88fbc 100644 --- a/frontend/components/traces/chat-message-list-tab.tsx +++ b/frontend/components/traces/chat-message-list-tab.tsx @@ -10,6 +10,7 @@ function ContentPartText({ text }: ContentPartTextProps) { return (
diff --git a/frontend/components/traces/span-card.tsx b/frontend/components/traces/span-card.tsx index b662f907..017a9b3b 100644 --- a/frontend/components/traces/span-card.tsx +++ b/frontend/components/traces/span-card.tsx @@ -46,7 +46,7 @@ export function SpanCard({ return (
{isSelected && (
)} @@ -36,6 +37,7 @@ export function SpanViewSpan({ span }: SpanViewSpanProps) { ? span.output : JSON.stringify(span.output) } + collapsible />
diff --git a/frontend/components/ui/code-editor.tsx b/frontend/components/ui/code-editor.tsx index 671b58eb..671b1534 100644 --- a/frontend/components/ui/code-editor.tsx +++ b/frontend/components/ui/code-editor.tsx @@ -1,15 +1,6 @@ -import { - Select, - SelectContent, - SelectItem, - SelectTrigger, - SelectValue -} from './select'; -import { useState } from 'react'; -import YAML from 'yaml'; import CodeMirror from '@uiw/react-codemirror'; import { createTheme } from '@uiw/codemirror-themes'; -import { githubDarkStyle, githubDark } from '@uiw/codemirror-theme-github'; +import { githubDarkStyle } from '@uiw/codemirror-theme-github'; import { json } from '@codemirror/lang-json'; import { yaml } from '@codemirror/lang-yaml'; import { python } from '@codemirror/lang-python'; @@ -33,7 +24,10 @@ const myTheme = createTheme({ lineHighlight: 'transparent', gutterBackground: 'transparent', gutterBorder: 'transparent', - gutterForeground: 'gray !important' + gutterForeground: 'gray !important', + selection: '#193860', + selectionMatch: 'transparent', + caret: '2px solid hsl(var(--primary) / 0.1)', }, styles: githubDarkStyle, }); @@ -67,10 +61,10 @@ export default function CodeEditor({ } return ( -
+
void; + collapsible?: boolean; } export default function Formatter({ @@ -28,10 +29,12 @@ export default function Formatter({ defaultMode = 'text', editable = false, onChange, - className + className, + collapsible = false }: OutputFormatterProps) { const [mode, setMode] = useState(defaultMode); const [expandedValue, setExpandedValue] = useState(value); + const [isCollapsed, setIsCollapsed] = useState(false); const renderText = (value: string) => { // if mode is YAML try to parse it as YAML @@ -62,14 +65,14 @@ export default function Formatter({
-
-
-
+
+
+
+ {collapsible && ( + + )}
-
+