cherry-pick(#31939): chore(trace-viewer): copy only file name without line number

As discussed in the meeting, copy only file name which is shown in the
same line, do not include highlighted line number.
This commit is contained in:
Yury Semikhatsky 2024-07-31 15:40:13 -07:00
parent ca9ddff7ca
commit 13c6ed8941

View file

@ -100,7 +100,7 @@ export const SourceTab: React.FunctionComponent<{
<div className='vbox' data-testid='source-code'> <div className='vbox' data-testid='source-code'>
{ fileName && <Toolbar> { fileName && <Toolbar>
<span className='source-tab-file-name'>{fileName}</span> <span className='source-tab-file-name'>{fileName}</span>
<CopyToClipboard description='Copy filename' value={getFileName(fileName, targetLine)}/> <CopyToClipboard description='Copy filename' value={getFileName(fileName)}/>
{location && <ToolbarButton icon='link-external' title='Open in VS Code' onClick={openExternally}></ToolbarButton>} {location && <ToolbarButton icon='link-external' title='Open in VS Code' onClick={openExternally}></ToolbarButton>}
</Toolbar> } </Toolbar> }
<CodeMirrorWrapper text={source.content || ''} language='javascript' highlight={highlight} revealLine={targetLine} readOnly={true} lineNumbers={true} /> <CodeMirrorWrapper text={source.content || ''} language='javascript' highlight={highlight} revealLine={targetLine} readOnly={true} lineNumbers={true} />
@ -121,10 +121,9 @@ export async function calculateSha1(text: string): Promise<string> {
return hexCodes.join(''); return hexCodes.join('');
} }
function getFileName(fullPath?: string, lineNum?: number): string { function getFileName(fullPath?: string): string {
if (!fullPath) if (!fullPath)
return ''; return '';
const pathSep = fullPath?.includes('/') ? '/' : '\\'; const pathSep = fullPath?.includes('/') ? '/' : '\\';
const fileName = fullPath?.split(pathSep).pop() ?? ''; return fullPath?.split(pathSep).pop() ?? '';
return lineNum ? `${fileName}:${lineNum}` : fileName;
} }