Skip to content

Commit

Permalink
Update TraceWaterfallList.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
ccschmitz committed Apr 30, 2024
1 parent e3c55f9 commit 230752c
Showing 1 changed file with 15 additions and 20 deletions.
35 changes: 15 additions & 20 deletions frontend/src/pages/Traces/TraceWaterfallList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
IconSolidXCircle,
Stack,
Table,
Tabs,
Text,
} from '@highlight-run/ui/components'
import useLocalStorage from '@rehooks/local-storage'
Expand All @@ -27,9 +28,13 @@ img.src =
'data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs='

export const TraceWaterfallList: React.FC = () => {
const { selectedSpan, spans, totalDuration, setSelectedSpan } = useTrace()
const { selectedSpan, spanCount, spans, totalDuration, setSelectedSpan } =
useTrace()
const bodyRef = useRef<HTMLDivElement>(null)
const tabsContext = Tabs.useContext()!
const activeTab = tabsContext.useState('activeId')
const [query, setQuery] = useState('')
const [bodyHeight, setBodyHeight] = useState('auto')
const [columns, setColumns] = useLocalStorage(
'highlight-trace-waterfall-list-column-sizes',
[
Expand All @@ -45,6 +50,14 @@ export const TraceWaterfallList: React.FC = () => {
[spans, query],
)

useEffect(() => {
const bodyHeight = bodyRef.current?.clientHeight ?? 0

if (bodyHeight > 0) {
setBodyHeight(`${Math.min(bodyHeight, 280)}px`)
}
}, [spanCount, activeTab])

const handleDrag = (e: React.DragEvent, name: string) => {
const headerRef = e.currentTarget.parentElement?.parentElement
const leftElementCoord = headerRef?.getBoundingClientRect()
Expand Down Expand Up @@ -83,24 +96,6 @@ export const TraceWaterfallList: React.FC = () => {
}
}

const initialHeightRef = useRef<number | null>(null)
useEffect(() => {
const observer = new ResizeObserver(() => {
if (bodyRef.current && initialHeightRef.current === null) {
initialHeightRef.current = bodyRef.current.offsetHeight
bodyRef.current.style.height = `${initialHeightRef.current}px`
}
})

if (bodyRef.current) {
observer.observe(bodyRef.current)
}

return () => {
observer.disconnect()
}
}, [])

return (
<Box border="dividerWeak" borderRadius="6" overflow="hidden">
<Form>
Expand Down Expand Up @@ -155,7 +150,7 @@ export const TraceWaterfallList: React.FC = () => {
<Table.Body
ref={bodyRef}
overflowY="auto"
style={{ maxHeight: initialHeightRef.current ?? 280 }}
style={{ height: bodyHeight }}
>
{canRenderSpans ? (
spans.map((span) => (
Expand Down

0 comments on commit 230752c

Please sign in to comment.