Skip to content

Commit 8d524e2

Browse files
committed
cherry-pick(#32996): chore: allow minimal height for trace attachments
1 parent 0cdbb11 commit 8d524e2

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

packages/trace-viewer/src/ui/attachmentsTab.tsx

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { ImageDiffView } from '@web/shared/imageDiffView';
2020
import type { MultiTraceModel } from './modelUtil';
2121
import { PlaceholderPanel } from './placeholderPanel';
2222
import type { AfterActionTraceEventAttachment } from '@trace/trace';
23-
import { CodeMirrorWrapper } from '@web/components/codeMirrorWrapper';
23+
import { CodeMirrorWrapper, lineHeight } from '@web/components/codeMirrorWrapper';
2424
import { isTextualMimeType } from '@isomorphic/mimeType';
2525
import { Expandable } from '@web/components/expandable';
2626
import { linkifyText } from '@web/renderUtils';
@@ -51,6 +51,11 @@ const ExpandableAttachment: React.FunctionComponent<ExpandableAttachmentProps> =
5151
}
5252
}, [expanded, attachmentText, placeholder, attachment]);
5353

54+
const snippetHeight = React.useMemo(() => {
55+
const lineCount = attachmentText ? attachmentText.split('\n').length : 0;
56+
return Math.min(Math.max(5, lineCount), 20) * lineHeight;
57+
}, [attachmentText]);
58+
5459
const title = <span style={{ marginLeft: 5 }}>
5560
{linkifyText(attachment.name)} {hasContent && <a style={{ marginLeft: 5 }} href={downloadURL(attachment)}>download</a>}
5661
</span>;
@@ -62,14 +67,16 @@ const ExpandableAttachment: React.FunctionComponent<ExpandableAttachmentProps> =
6267
<Expandable title={title} expanded={expanded} setExpanded={setExpanded} expandOnTitleClick={true}>
6368
{placeholder && <i>{placeholder}</i>}
6469
</Expandable>
65-
{expanded && attachmentText !== null && <CodeMirrorWrapper
66-
text={attachmentText}
67-
readOnly
68-
mimeType={attachment.contentType}
69-
linkify={true}
70-
lineNumbers={true}
71-
wrapLines={false}>
72-
</CodeMirrorWrapper>}
70+
{expanded && attachmentText !== null && <div className='vbox' style={{ height: snippetHeight }}>
71+
<CodeMirrorWrapper
72+
text={attachmentText}
73+
readOnly
74+
mimeType={attachment.contentType}
75+
linkify={true}
76+
lineNumbers={true}
77+
wrapLines={false}>
78+
</CodeMirrorWrapper>
79+
</div>}
7380
</>;
7481
};
7582

packages/web/src/components/codeMirrorWrapper.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ export type SourceHighlight = {
2828

2929
export type Language = 'javascript' | 'python' | 'java' | 'csharp' | 'jsonl' | 'html' | 'css' | 'markdown';
3030

31+
export const lineHeight = 20;
32+
3133
export interface SourceProps {
3234
text: string;
3335
language?: Language;

0 commit comments

Comments
 (0)