发布

  • [NA] [FE] Maintain state of annotation view when moving between traces (#3703)

    frostbyte_neo 发布于 2025-10-21 14:13:28 +00:00

    • Add persistent tree state and scroll position for annotation queue JSON viewer

    Implement full state persistence across trace navigation in annotation queues.
    When users expand/collapse nodes and scroll to specific positions in the JSON
    tree viewer, these states now persist when navigating to the next/previous trace.

    Key changes:

    • Created AnnotationTreeStateContext to manage tree expansion and scroll state
      across trace navigation
    • Modified JsonKeyValueTable to support controlled mode where parent component
      manages expansion state
    • Updated SyntaxHighlighter and MarkdownHighlighter to pass through controlled
      state props
    • Enhanced TraceDataViewer with scroll position tracking and restoration
    • Wrapped AnnotationView with AnnotationTreeStateProvider to enable state
      sharing across input/output/metadata sections

    Benefits:

    • Improved annotation workflow efficiency by maintaining visual context
    • Separate state management for input, output, and metadata sections
    • Scroll position restoration ensures users see the same part of the tree
    • Only applies to annotation queues, does not affect other parts of the app

    🤖 Generated with Claude Code

    Co-Authored-By: Claude noreply@anthropic.com

    • Add key-based tree expansion matching for robust state persistence

    Enhance the JSON tree viewer to use key-based paths instead of index-based
    paths for tracking expansion state. This makes the expansion state robust
    across different tree structures when navigating between traces.

    How it works:

    • Each node in the tree now has a keyPath (e.g., "metadata.user.name")
    • When user expands/collapses nodes, we track which key paths are expanded
    • When data changes (new trace), we map stored key paths to new structure
    • If a key exists in the new trace, it stays expanded at its new position

    Benefits:

    • Expansion state persists even if keys appear in different order
    • Works across traces with slightly different structures
    • Example: If "metadata.session" is expanded in trace 1, it stays expanded
      in trace 2 even if other keys are added/removed

    Technical details:

    • Added keyPath tracking to JsonRowData interface
    • Created buildPathMaps() to build bidirectional index↔key mappings
    • Added useEffect hooks to track and restore expansion state in controlled mode
    • Only applies to controlled mode (annotation queues)

    🤖 Generated with Claude Code

    Co-Authored-By: Claude noreply@anthropic.com

    • Update .gitignore to exclude Python venv and test scripts

    • Revision 3: Remove unnecessary metadata tree state tracking

    Metadata does not have prettifyConfig and only displays as flat text (YAML/JSON)
    via CodeMirrorHighlighter. It never uses JsonKeyValueTable or expandable tree
    components, so tree expansion state tracking is unnecessary and has been removed.

    Changes:

    • Removed metadata from AnnotationTreeState interface
    • Removed metadata scroll position tracking
    • Removed metadata tree expansion handlers
    • Added explanatory comments about why metadata is excluded
    • Refactor TraceDataViewer to streamline scroll position management
    • Removed unnecessary scroll refs and handlers, simplifying the component.
    • Introduced new scroll position handlers for input and output sections.
    • Updated SyntaxHighlighter components to support scroll position tracking and restoration.
    • Enhanced overall code readability and maintainability.

    This refactor improves the user experience by ensuring scroll positions are accurately managed and restored during trace navigation.

    • fix scroll restoration for codemirror view

    Co-authored-by: Gideon Mendels gideonmendels@ip-192-168-68-52.ec2.internal
    Co-authored-by: Claude noreply@anthropic.com
    Co-authored-by: andrii.dudar fanat.web@gmail.com

    下载附件