// SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 /** * MetadataSection Component - Comprehensive Alert Metadata Display * * This file contains the MetadataSection component which provides a detailed, structured * display of alert metadata and analytics information within expandable table rows. The * component renders complex nested data structures in an organized, readable format with * proper formatting, syntax highlighting, and responsive design considerations. * * **Key Features:** * - Structured metadata display with hierarchical organization and proper indentation * - JSON syntax highlighting and formatting for complex data structures * - Responsive design adapting to various screen sizes and container widths * - Comprehensive theme support with proper contrast and readability in both modes * - Intelligent data type detection and appropriate rendering for different value types * - Expandable/collapsible sections for managing large metadata objects * - Copy-to-clipboard for metadata; optional send-to-chat for configured report prompts * - Search and filter capabilities within metadata for quick information location * */ import React, { useState, useMemo } from 'react'; import { Button } from '@nvidia/foundations-react-core'; import { IconChevronDown, IconChevronUp, IconCopy, IconCheck, IconSend } from '@tabler/icons-react'; import {copyToClipboard} from 'common'; interface MetadataSectionProps { alertId: string; sensor: string; title: string; data: Record; isDark: boolean; alertReportPromptTemplate?: string; vlmVerifiedAlertReportPromptTemplate?: string; /** When true, use the VLM verified report prompt template. */ vlmVerified?: boolean; /** When set, "Generate Report" sends the resolved template to the app chat (e.g. VSS sidebar). */ submitChatMessage?: (message: string) => void; } export const MetadataSection: React.FC = ({ alertId, sensor, title, data, isDark, alertReportPromptTemplate, vlmVerifiedAlertReportPromptTemplate, vlmVerified = false, submitChatMessage, }) => { const [isCollapsed, setIsCollapsed] = useState(false); const [isCopied, setIsCopied] = useState(false); const [isReportSent, setIsReportSent] = useState(false); const [showTooltip, setShowTooltip] = useState(false); const isEmpty = !data || Object.keys(data).length === 0; const activeReportPromptTemplate = vlmVerified ? vlmVerifiedAlertReportPromptTemplate || alertReportPromptTemplate : alertReportPromptTemplate; const shouldShowGenerateReport = Boolean(submitChatMessage) && activeReportPromptTemplate && activeReportPromptTemplate.trim() !== '' && alertId && sensor && !alertId.startsWith('alert-'); const formattedPrompt = useMemo(() => { if (!shouldShowGenerateReport) return ''; return (activeReportPromptTemplate || '') .replace(/{incidentId}/g, alertId) .replace(/{sensorId}/g, sensor); }, [shouldShowGenerateReport, activeReportPromptTemplate, alertId, sensor]); const handleGenerateReport = () => { if (!submitChatMessage || !formattedPrompt.trim()) return; submitChatMessage(formattedPrompt); setIsReportSent(true); setTimeout(() => setIsReportSent(false), 2000); }; const handleCopy = async () => { try { await copyToClipboard(JSON.stringify(data, null, 2)); setIsCopied(true); setTimeout(() => setIsCopied(false), 2000); } catch (error) { console.error('Failed to copy metadata:', error); } }; return (
{!isEmpty && !isCollapsed && (
{shouldShowGenerateReport && (
{showTooltip && !isReportSent && (
{formattedPrompt}
)}
)}
)}
{!isEmpty && !isCollapsed && (
{JSON.stringify(data, null, 2)}
)}
); };