|
17 | 17 | import type { TestAttachment, TestCase, TestCaseSummary, TestResult, TestResultSummary } from './types'; |
18 | 18 | import * as React from 'react'; |
19 | 19 | import * as icons from './icons'; |
20 | | -import { TreeItem } from './treeItem'; |
21 | 20 | import { CopyToClipboard } from './copyToClipboard'; |
22 | 21 | import './links.css'; |
23 | 22 | import { linkifyText } from '@web/renderUtils'; |
@@ -78,30 +77,61 @@ export const AttachmentLink: React.FunctionComponent<{ |
78 | 77 | openInNewTab?: boolean, |
79 | 78 | }> = ({ attachment, result, href, linkName, openInNewTab }) => { |
80 | 79 | const [flash, triggerFlash] = useFlash(); |
| 80 | + const [expanded, setExpanded] = React.useState(false); |
81 | 81 | useAnchor('attachment-' + result.attachments.indexOf(attachment), triggerFlash); |
82 | | - return <TreeItem title={<span> |
83 | | - {attachment.contentType === kMissingContentType ? icons.warning() : icons.attachment()} |
84 | | - {attachment.path && ( |
85 | | - openInNewTab |
86 | | - ? <a href={href || attachment.path} target='_blank' rel='noreferrer'>{linkName || attachment.name}</a> |
87 | | - : <a href={href || attachment.path} download={downloadFileNameForAttachment(attachment)}>{linkName || attachment.name}</a> |
88 | | - )} |
89 | | - {!attachment.path && ( |
90 | | - openInNewTab |
91 | | - ? ( |
92 | | - <a |
93 | | - href={URL.createObjectURL(new Blob([attachment.body!], { type: attachment.contentType }))} |
94 | | - target='_blank' rel='noreferrer' |
95 | | - onClick={e => e.stopPropagation() /* dont expand the tree item */} |
96 | | - > |
97 | | - {attachment.name} |
98 | | - </a> |
99 | | - ) |
100 | | - : <span>{linkifyText(attachment.name)}</span> |
101 | | - )} |
102 | | - </span>} loadChildren={attachment.body ? () => { |
103 | | - return [<div key={1} className='attachment-body'><CopyToClipboard value={attachment.body!}/>{linkifyText(attachment.body!)}</div>]; |
104 | | - } : undefined} depth={0} style={{ lineHeight: '32px' }} flash={flash}></TreeItem>; |
| 82 | + |
| 83 | + const summaryContent = ( |
| 84 | + <span> |
| 85 | + {attachment.contentType === kMissingContentType ? icons.warning() : icons.attachment()} |
| 86 | + {attachment.path && ( |
| 87 | + openInNewTab |
| 88 | + ? <a href={href || attachment.path} target='_blank' rel='noreferrer'>{linkName || attachment.name}</a> |
| 89 | + : <a href={href || attachment.path} download={downloadFileNameForAttachment(attachment)}>{linkName || attachment.name}</a> |
| 90 | + )} |
| 91 | + {!attachment.path && ( |
| 92 | + openInNewTab |
| 93 | + ? ( |
| 94 | + <a |
| 95 | + href={URL.createObjectURL(new Blob([attachment.body!], { type: attachment.contentType }))} |
| 96 | + target='_blank' rel='noreferrer' |
| 97 | + onClick={e => e.stopPropagation() /* dont expand the details */} |
| 98 | + > |
| 99 | + {attachment.name} |
| 100 | + </a> |
| 101 | + ) |
| 102 | + : <span>{linkifyText(attachment.name)}</span> |
| 103 | + )} |
| 104 | + </span> |
| 105 | + ); |
| 106 | + |
| 107 | + if (!attachment.body) { |
| 108 | + return ( |
| 109 | + <div |
| 110 | + style={{ lineHeight: '32px', whiteSpace: 'nowrap', paddingLeft: 4 }} |
| 111 | + className={clsx(flash && 'flash')} |
| 112 | + > |
| 113 | + <span style={{ visibility: 'hidden' }}>{icons.rightArrow()}</span> |
| 114 | + {summaryContent} |
| 115 | + </div> |
| 116 | + ); |
| 117 | + } |
| 118 | + |
| 119 | + return ( |
| 120 | + <details |
| 121 | + style={{ lineHeight: '32px' }} |
| 122 | + className={clsx(flash && 'flash')} |
| 123 | + onToggle={e => setExpanded(e.currentTarget.open)} |
| 124 | + > |
| 125 | + <summary style={{ cursor: 'pointer', listStyle: 'none', whiteSpace: 'nowrap', paddingLeft: 4 }}> |
| 126 | + {expanded ? icons.downArrow() : icons.rightArrow()} |
| 127 | + {summaryContent} |
| 128 | + </summary> |
| 129 | + <div className='attachment-body'> |
| 130 | + <CopyToClipboard value={attachment.body!}/> |
| 131 | + {linkifyText(attachment.body!)} |
| 132 | + </div> |
| 133 | + </details> |
| 134 | + ); |
105 | 135 | }; |
106 | 136 |
|
107 | 137 | export const TraceLink: React.FC<{ test: TestCaseSummary, trailingSeparator?: boolean, dim?: boolean }> = ({ test, trailingSeparator, dim }) => { |
|
0 commit comments