|
| 1 | +'use client' |
| 2 | + |
| 3 | +import { useCallback, useMemo } from 'react' |
| 4 | +import { Button, cn } from '@sim/emcn' |
| 5 | +import { X } from '@sim/emcn/icons' |
| 6 | +import { LogView } from '@/components/resources/log-view' |
| 7 | +import type { WorkflowLogRow } from '@/lib/api/contracts/logs' |
| 8 | +import { useLogDetailsResize } from '@/hooks/use-log-details-resize' |
| 9 | +import { type ResourceGrants, type ResourceHost, workspaceSource } from '@/resources' |
| 10 | +import { useLogDetailsUIStore } from '@/stores/logs/store' |
| 11 | +import { MAX_LOG_DETAILS_WIDTH_RATIO, MIN_LOG_DETAILS_WIDTH } from '@/stores/logs/utils' |
| 12 | + |
| 13 | +interface ExecutionSlideoutProps { |
| 14 | + log: WorkflowLogRow | null |
| 15 | + isOpen: boolean |
| 16 | + onClose: () => void |
| 17 | + workspaceId: string |
| 18 | + grants: ResourceGrants |
| 19 | + host: ResourceHost |
| 20 | + /** |
| 21 | + * Whether this viewer may see trace internals. Required, not |
| 22 | + * optional-defaulting-to-true: forgetting it must fail to compile rather than |
| 23 | + * silently reveal payloads a permission group hid. Same contract, and the same |
| 24 | + * reason, as {@link LogView}'s own prop. |
| 25 | + */ |
| 26 | + showExecutionInternals: boolean |
| 27 | + onNavigate?: (path: string) => void |
| 28 | +} |
| 29 | + |
| 30 | +/** |
| 31 | + * A workflow run, slid in beside the table that triggered it. |
| 32 | + * |
| 33 | + * Mounts the canonical {@link LogView} directly rather than borrowing the logs |
| 34 | + * page's `LogDetails` shell. That shell reads `useParams`, `useRouter`, |
| 35 | + * `useQueryState` and the permission context — four route couplings a table has |
| 36 | + * no use for — and it deep-links its active tab, which meant opening a run from |
| 37 | + * the tables page wrote `?tab` onto the tables URL, and onto the host page's URL |
| 38 | + * from the chat panel. This slideout omits `tab`/`onTabChange` entirely, so the |
| 39 | + * view keeps the tab local, which is correct for a panel that was never |
| 40 | + * addressable. |
| 41 | + * |
| 42 | + * Only the chrome is reproduced: the frame, the resize handle, and a close |
| 43 | + * button. The logs page's prev/next and retry controls belong to a list this |
| 44 | + * surface does not have. |
| 45 | + */ |
| 46 | +export function ExecutionSlideout({ |
| 47 | + log, |
| 48 | + isOpen, |
| 49 | + onClose, |
| 50 | + workspaceId, |
| 51 | + grants, |
| 52 | + host, |
| 53 | + showExecutionInternals, |
| 54 | + onNavigate, |
| 55 | +}: ExecutionSlideoutProps) { |
| 56 | + const panelWidth = useLogDetailsUIStore((state) => state.panelWidth) |
| 57 | + const { handleMouseDown } = useLogDetailsResize() |
| 58 | + |
| 59 | + const source = useMemo( |
| 60 | + () => workspaceSource({ kind: 'log' as const, workspaceId, resourceId: log?.id ?? '' }), |
| 61 | + [workspaceId, log?.id] |
| 62 | + ) |
| 63 | + |
| 64 | + const handleNavigate = useCallback((path: string) => onNavigate?.(path), [onNavigate]) |
| 65 | + |
| 66 | + const maxVw = `${MAX_LOG_DETAILS_WIDTH_RATIO * 100}vw` |
| 67 | + const effectiveWidth = `clamp(min(${MIN_LOG_DETAILS_WIDTH}px, ${maxVw}), ${panelWidth}px, ${maxVw})` |
| 68 | + |
| 69 | + return ( |
| 70 | + <> |
| 71 | + {isOpen && ( |
| 72 | + <div |
| 73 | + className='absolute top-0 bottom-0 z-[var(--z-dropdown)] w-[8px] cursor-ew-resize' |
| 74 | + style={{ right: `calc(${effectiveWidth} - 4px)` }} |
| 75 | + onMouseDown={handleMouseDown} |
| 76 | + role='separator' |
| 77 | + aria-label='Resize execution details panel' |
| 78 | + aria-orientation='vertical' |
| 79 | + /> |
| 80 | + )} |
| 81 | + |
| 82 | + <div |
| 83 | + className={cn( |
| 84 | + 'absolute top-0 right-0 bottom-0 z-[var(--z-dropdown)] overflow-hidden border-l bg-[var(--bg)] shadow-md transition-transform duration-200 ease-out', |
| 85 | + isOpen ? 'translate-x-0' : 'translate-x-full' |
| 86 | + )} |
| 87 | + style={{ width: effectiveWidth }} |
| 88 | + aria-label='Execution details sidebar' |
| 89 | + > |
| 90 | + {log && ( |
| 91 | + <div className='flex h-full flex-col px-3.5 pt-3'> |
| 92 | + <div className='flex items-center justify-between'> |
| 93 | + <h2 className='font-medium text-[var(--text-primary)] text-sm'>Execution Details</h2> |
| 94 | + <Button variant='ghost' className='!p-1' onClick={onClose} aria-label='Close'> |
| 95 | + <X className='size-[14px]' /> |
| 96 | + </Button> |
| 97 | + </div> |
| 98 | + |
| 99 | + <LogView |
| 100 | + source={source} |
| 101 | + grants={grants} |
| 102 | + host={host} |
| 103 | + log={log} |
| 104 | + showExecutionInternals={showExecutionInternals} |
| 105 | + onNavigate={handleNavigate} |
| 106 | + /> |
| 107 | + </div> |
| 108 | + )} |
| 109 | + </div> |
| 110 | + </> |
| 111 | + ) |
| 112 | +} |
0 commit comments