2024-02-09 04:17:47 -05:00
|
|
|
import { useCallback, useState } from 'react'
|
2023-02-06 09:17:22 -05:00
|
|
|
import { useResizeObserver } from '../../../shared/hooks/use-resize-observer'
|
2021-10-15 05:45:06 -04:00
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import classNames from 'classnames'
|
2024-10-23 03:32:40 -04:00
|
|
|
import OLButton from '@/features/ui/components/ol/ol-button'
|
2021-10-15 05:45:06 -04:00
|
|
|
import Icon from '../../../shared/components/icon'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
|
|
|
|
export default function PdfLogEntryRawContent({
|
|
|
|
rawContent,
|
|
|
|
collapsedSize = 0,
|
|
|
|
}) {
|
|
|
|
const [expanded, setExpanded] = useState(false)
|
2024-04-16 04:36:45 -04:00
|
|
|
const [needsExpander, setNeedsExpander] = useState(true)
|
2021-10-15 05:45:06 -04:00
|
|
|
|
2024-02-09 04:17:47 -05:00
|
|
|
const { elementRef } = useResizeObserver(
|
|
|
|
useCallback(
|
|
|
|
element => {
|
2024-04-16 04:36:45 -04:00
|
|
|
if (element.scrollHeight === 0) return // skip update when logs-pane is closed
|
2024-02-09 04:17:47 -05:00
|
|
|
setNeedsExpander(element.scrollHeight > collapsedSize)
|
|
|
|
},
|
|
|
|
[collapsedSize]
|
|
|
|
)
|
|
|
|
)
|
2021-10-15 05:45:06 -04:00
|
|
|
|
|
|
|
const { t } = useTranslation()
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="log-entry-content-raw-container">
|
|
|
|
<div
|
|
|
|
className="expand-collapse-container"
|
|
|
|
style={{
|
2021-10-21 04:09:33 -04:00
|
|
|
height: expanded || !needsExpander ? 'auto' : collapsedSize,
|
2021-10-15 05:45:06 -04:00
|
|
|
}}
|
|
|
|
>
|
2023-07-18 06:21:56 -04:00
|
|
|
<pre className="log-entry-content-raw" ref={elementRef}>
|
2021-10-15 05:45:06 -04:00
|
|
|
{rawContent.trim()}
|
|
|
|
</pre>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{needsExpander && (
|
|
|
|
<div
|
|
|
|
className={classNames('log-entry-content-button-container', {
|
|
|
|
'log-entry-content-button-container-collapsed': !expanded,
|
|
|
|
})}
|
|
|
|
>
|
2024-10-23 03:32:40 -04:00
|
|
|
<OLButton
|
|
|
|
variant="secondary"
|
|
|
|
size="sm"
|
|
|
|
bs3Props={{
|
|
|
|
bsSize: 'xsmall',
|
|
|
|
className: 'log-entry-btn-expand-collapse',
|
|
|
|
}}
|
2021-10-15 05:45:06 -04:00
|
|
|
onClick={() => setExpanded(value => !value)}
|
|
|
|
>
|
|
|
|
{expanded ? (
|
|
|
|
<>
|
|
|
|
<Icon type="angle-up" /> {t('collapse')}
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<Icon type="angle-down" /> {t('expand')}
|
|
|
|
</>
|
|
|
|
)}
|
2024-10-23 03:32:40 -04:00
|
|
|
</OLButton>
|
2021-10-15 05:45:06 -04:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
PdfLogEntryRawContent.propTypes = {
|
|
|
|
rawContent: PropTypes.string.isRequired,
|
|
|
|
collapsedSize: PropTypes.number,
|
|
|
|
}
|