import React, { useContext } from 'react'; import ErrorOccurrenceContext from '../../contexts/ErrorOccurrenceContext'; type Props = { path: string; lineNumber?: null | number; }; export default function RelaxedFilePath({ path: fullPath, lineNumber = null }: Props) { const { application_path } = useContext(ErrorOccurrenceContext); const path = fullPath.replace(application_path + '/', '').replace(/\/Users\/.*?\//, '~/'); const parts = path.split('/'); const fileParts = parts.pop()?.split('.') || []; const extension = fileParts.pop(); const fileName = fileParts.join('.'); const tightSpace = String.fromCharCode(8201); return ( {parts.map((part, index) => ( {part} {tightSpace}/{tightSpace} ))} {fileName} .{extension} {lineNumber && <> {tightSpace} :{tightSpace} {lineNumber} } ); }