import { toast, ToastContainer } from 'react-toastify'; import { useStudioStore } from './store.ts'; import { useEffect, useState } from 'react'; import { MonitorPlay, Play } from 'lucide-react'; export const AppProvider = () => { return } interface RouteItem { id: string; path?: string; key?: string; description?: string; metadata?: Record; } export const App = () => { const { routes, getRoutes, run } = useStudioStore(); const [expandedIds, setExpandedIds] = useState>(new Set()); const [visibleIds, setVisibleIds] = useState>(new Set()); useEffect(() => { getRoutes(); }, []); const toggleDescription = (id: string) => { const newExpanded = new Set(expandedIds); if (newExpanded.has(id)) { newExpanded.delete(id); } else { newExpanded.add(id); } setExpandedIds(newExpanded); }; const toggleIdVisibility = (e: React.MouseEvent, id: string) => { e.stopPropagation(); const newVisible = new Set(visibleIds); if (newVisible.has(id)) { newVisible.delete(id); } else { newVisible.add(id); } setVisibleIds(newVisible); }; return ( {routes.map((route: RouteItem) => { const isExpanded = expandedIds.has(route.id); const isIdVisible = visibleIds.has(route.id); const len = route.description?.length || 0; const isLongDescription = len > 20; return ( {/* ID and Path/Key in one line */} toggleIdVisibility(e, route.id)} className="inline-flex items-center px-2.5 py-1 rounded-md text-xs font-semibold bg-gray-900 text-white cursor-pointer hover:bg-gray-700 transition-all duration-200 shadow-sm" > {isIdVisible ? route.id : 'id'} {(route.path || route.key) && ( {route.path}{route.key && ` / ${route.key}`} )} run(route)} > run(route)}> {/* Description with expand/collapse */} {route.description && ( {isExpanded ? ( {route.description} ) : ( {route.description} )} {isLongDescription && ( toggleDescription(route.id)} > {isExpanded ? '点击收起' : '点击展开'} )} )} {/* Metadata */} {route.metadata && Object.keys(route.metadata).length > 0 && ( Metadata: {Object.entries(route.metadata).map(([k, v]) => ( {k}: {String(v)} ))} )} ); })} ); }
{route.description}
toggleDescription(route.id)} > {isExpanded ? '点击收起' : '点击展开'}