diff --git a/src/ui/src/dashboard/CallFlow.css b/src/ui/src/dashboard/CallFlow.css index 51ef562e..11318be8 100644 --- a/src/ui/src/dashboard/CallFlow.css +++ b/src/ui/src/dashboard/CallFlow.css @@ -441,8 +441,6 @@ position: relative; overflow: inherit; opacity: 1; - margin-left: var(--flow-left-px, 12px); - margin-right: var(--flow-right-px, 12px); min-width: 0; min-height: 64px; } @@ -459,10 +457,7 @@ .item-flow-packet-container .bg-color-polygon { position: absolute; z-index: 0; - top: 0; - bottom: 0; - left: calc(-1 * var(--flow-left-px, 12px)); - right: calc(-1 * var(--flow-right-px, 12px)); + inset: 0; opacity: 0.28; filter: saturate(120%); pointer-events: none; @@ -470,7 +465,7 @@ .item-flow-packet-container .bg-color-tab { position: absolute; - left: calc(-1 * var(--flow-left-px, 12px)); + left: 0; top: 0; bottom: 0; width: 5px; @@ -478,13 +473,24 @@ pointer-events: none; } +/* One host: the message is only the loop, so keep the tint, tab, border and + hover on it. The container stays full width; FlowItem sets --loop-left and + --loop-width from the measured host centre. */ .item-flow-packet-container.single-host .bg-color-polygon { - left: 0; - right: 0; + left: var(--loop-left); + right: auto; + width: var(--loop-width); } .item-flow-packet-container.single-host .bg-color-tab { - left: 0; + left: var(--loop-left); +} + +.item-flow-packet-container.single-host .item-flow-packet { + margin-left: var(--loop-left); + width: var(--loop-width); + /* No arrow has to end on a lifeline here, so keep the text clear of the tab. */ + padding-inline: 6px; } .item-flow-packet { @@ -492,7 +498,8 @@ z-index: 1; width: 100%; min-width: 0; - padding: 8px 6px 10px; + /* No horizontal padding: the track's x origin must match the host centres' origin. */ + padding: 8px 0 10px; border-bottom: 1px solid color-mix(in oklch, var(--color-border) 55%, transparent); cursor: pointer; transition: background-color 0.15s ease, box-shadow 0.15s ease; @@ -601,18 +608,20 @@ .item-flow-packet .arrow::after { content: ''; position: absolute; - right: -1px; + right: 0; bottom: -6px; - border: 5px solid transparent; - border-left: 12px solid; + /* No trailing border, so the tip lands exactly on the line end (the host lifeline). */ + border-style: solid; + border-color: transparent; + border-width: 5px 0 5px 12px; border-left-color: currentColor; } .item-flow-packet .arrow.left::after { right: initial; - left: -1px; - border: 5px solid transparent; - border-right: 12px solid; + left: 0; + border-color: transparent; + border-width: 5px 12px 5px 0; border-right-color: currentColor; } @@ -716,6 +725,14 @@ margin-top: 2px; } +/* Last-host loop sits at the segment's right edge, so the badges must too. + A block with width:auto would take the free space and zero margin-left:auto. */ +.radial-port-labels.end { + width: max-content; + margin-left: auto; + gap: 4px; +} + .radial-port-labels .radial-port-src, .radial-port-labels .radial-port-dst { padding: 1px 6px; diff --git a/src/ui/src/dashboard/CallFlow.tsx b/src/ui/src/dashboard/CallFlow.tsx index 712830cf..312597fe 100644 --- a/src/ui/src/dashboard/CallFlow.tsx +++ b/src/ui/src/dashboard/CallFlow.tsx @@ -70,7 +70,9 @@ export default function CallFlow({ items, timeZone, onClickMessage, onShowOtlpEv const innerWidth = Math.max(hosts.length * 220, 560) const innerRef = useRef(null) - const [gridLines, setGridLines] = useState([]) + // Host lifeline x-positions (px from the left of .callflow-inner). Both the + // grid lines and every arrow are positioned from these, so they cannot drift apart. + const [hostCenters, setHostCenters] = useState([]) useLayoutEffect(() => { const el = innerRef.current @@ -87,18 +89,9 @@ export default function CallFlow({ items, timeZone, onClickMessage, onShowOtlpEv const rect = wrapper.getBoundingClientRect() positions.push(rect.left + rect.width / 2 - innerRect.left) }) - setGridLines(positions) - - if (positions.length >= 2) { - el.style.setProperty('--flow-left-px', `${positions[0]}px`) - el.style.setProperty('--flow-right-px', `${innerRect.width - positions[positions.length - 1]}px`) - } else if (positions.length === 1) { - el.style.setProperty('--flow-left-px', `${positions[0]}px`) - el.style.setProperty('--flow-right-px', `${innerRect.width - positions[0] - 280}px`) - } else { - el.style.removeProperty('--flow-left-px') - el.style.removeProperty('--flow-right-px') - } + setHostCenters((prev) => + prev.length === positions.length && prev.every((p, i) => p === positions[i]) ? prev : positions, + ) } measure() @@ -136,7 +129,7 @@ export default function CallFlow({ items, timeZone, onClickMessage, onShowOtlpEv style={{ width: `max(100%, ${innerWidth}px)` }} >
- {gridLines.map((px, i) => ( + {hostCenters.map((px, i) => (
= {}): Fl payloadType: 'SIP', start: 0, middle: 1, - rightEnd: 0, direction, isRadial: false, isLastHost: false, @@ -115,3 +114,62 @@ describe('FlowItem consolidation', () => { expect(onClickItem).not.toHaveBeenCalled() }) }) + +describe('FlowItem geometry', () => { + it('places the arrow segment at the measured host centres', () => { + const { container } = render( + , + ) + const spacer = container.querySelector('.item-flow-track > div:first-child')! + const segment = container.querySelector('.item-flow-segment')! + expect(spacer.style.flex).toBe('0 0 509px') + expect(segment.style.flex).toBe('0 0 401px') + }) +}) + +describe('FlowItem self-message loops', () => { + const radial = (o: Partial) => makeItem(false, { isRadial: true, middle: 1, ...o }) + + it('pins the port badges to the loop on the last host', () => { + const { container } = render( + , + ) + expect(container.querySelector('.radial-port-labels')?.classList.contains('end')).toBe(true) + }) + + it('keeps the badges left-aligned on other hosts', () => { + const { container } = render( + , + ) + expect(container.querySelector('.radial-port-labels')?.classList.contains('end')).toBe(false) + }) +}) + +describe('FlowItem single host', () => { + const loop = makeItem(false, { isRadial: true, start: 0, middle: 1 }) + + it('sizes the row to the loop so tint, tab, border and hover stay on it', () => { + const { container } = render( + , + ) + const row = container.querySelector('.item-flow-packet-container')! + expect(row.classList.contains('single-host')).toBe(true) + expect(row.style.getPropertyValue('--loop-left')).toBe('300px') + expect(row.style.getPropertyValue('--loop-width')).toBe('280px') + // The row itself is offset, so the track fills it instead of re-applying the offset. + expect(container.querySelector('.item-flow-track > div:first-child')!.style.flex).toBe('0 0 0px') + expect(container.querySelector('.item-flow-segment')!.style.flex).toBe('1 1 0%') + }) + + it('does not apply to calls with several hosts', () => { + const { container } = render( + , + ) + const row = container.querySelector('.item-flow-packet-container')! + expect(row.classList.contains('single-host')).toBe(false) + expect(row.style.getPropertyValue('--loop-left')).toBe('') + }) +}) diff --git a/src/ui/src/dashboard/flow/FlowItem.tsx b/src/ui/src/dashboard/flow/FlowItem.tsx index 31b7f0a3..f3a5342b 100644 --- a/src/ui/src/dashboard/flow/FlowItem.tsx +++ b/src/ui/src/dashboard/flow/FlowItem.tsx @@ -1,10 +1,13 @@ +import type { CSSProperties } from 'react' import type { FlowItemData } from './flow-data' +import { flowSegmentPx } from './flow-data' interface FlowItemProps { item: FlowItemData isSimplify: boolean isAbsoluteTime: boolean - singleHost?: boolean + /** Measured host centres (px from the left edge of the flow), one per host. */ + hostCenters?: readonly number[] onClickItem?: (item: FlowItemData) => void expandedKey?: string | null setExpandedKey?: (key: string | null) => void @@ -15,7 +18,7 @@ export function FlowItem({ item, isSimplify, isAbsoluteTime, - singleHost, + hostCenters, onClickItem, expandedKey, setExpandedKey, @@ -26,21 +29,27 @@ export function FlowItem({ const canToggleSubItems = hasSubItems && typeof setExpandedKey === 'function' const showSubItems = canToggleSubItems && expandedKey === itemKey - const flexStart = item.start || 0.0000001 - const flexMiddle = item.middle || 0.0000001 - const flexRight = item.isRadial - ? Math.max(0.0000001, item.rightEnd - (item.isLastHost ? 0 : 1)) - : item.rightEnd || 0.0000001 + // Until host centres are measured the segment just fills the row; the + // layout effect in CallFlow measures before the first paint. + const segment = hostCenters ? flowSegmentPx(item, hostCenters) : null + // With one host the message is only the loop, so the row's tint, tab, border + // and hover sit on the loop (.single-host) while the container stays full width. + const loop = hostCenters?.length === 1 ? segment : null + // A single-host row is itself sized to the loop, so its track just fills it. + const trackSegment = loop ? null : segment + const loopStyle = loop + ? ({ '--loop-left': `${loop.left}px`, '--loop-width': `${loop.width}px` } as CSSProperties) + : undefined const arrowColor = item.callidColors.arrowColor const radialDottedClass = item.arrowStyleSolid ? '' : ' dotted' - const containerClass = `item-flow-packet-container${singleHost ? ' single-host' : ''}${ + const containerClass = `item-flow-packet-container${loop ? ' single-host' : ''}${ hasSubItems ? ' consolidated-parent' : '' }${isSubItem ? ' consolidated-subitem' : ''}` return ( <> -
+
onClickItem?.(item)} >
-
+
@@ -97,7 +106,7 @@ export function FlowItem({ )} {item.isRadial ? ( -
+
{item.srcPort || ''} {item.dstPort || ''}
@@ -117,7 +126,6 @@ export function FlowItem({ )} {isSimplify &&
{item.diffStr}
}
-
@@ -128,7 +136,7 @@ export function FlowItem({ item={subItem} isSimplify={isSimplify} isAbsoluteTime={isAbsoluteTime} - singleHost={singleHost} + hostCenters={hostCenters} onClickItem={onClickItem} expandedKey={expandedKey} setExpandedKey={setExpandedKey} diff --git a/src/ui/src/dashboard/flow/flow-data.test.ts b/src/ui/src/dashboard/flow/flow-data.test.ts index f2cff4dc..c8a8cc32 100644 --- a/src/ui/src/dashboard/flow/flow-data.test.ts +++ b/src/ui/src/dashboard/flow/flow-data.test.ts @@ -2,7 +2,7 @@ import { describe, expect, it } from 'vitest' import { buildFlow, buildHosts, endpointAlias, hostKey, hostKeyFromMessage, runtimeFingerprintOf, captureIdOf, consolidateFlowItems, canConsolidateFlowItems, - payloadTypeOf, + payloadTypeOf, flowSegmentPx, } from './flow-data' import type { FlowItemData, RawMessage } from './flow-data' @@ -101,7 +101,7 @@ function makeFlowItem(overrides: Partial & { ts?: number } = {}): dstIp: '10.0.0.2', srcPort: 5060, dstPort: 5060, callid: 'c1', callidColors: { color: '#000', tabColor: '#000', arrowColor: '#000' }, methodColor: '#000', timeStr: '', fullDateStr: '', diffStr: '', - protoLabel: '', payloadType: 'SIP', start: 0, middle: 1, rightEnd: 0, + protoLabel: '', payloadType: 'SIP', start: 0, middle: 1, direction: false, isRadial: false, isLastHost: false, arrowStyleSolid: true, raw: { timestamp: ts ?? new Date('2026-01-01T00:00:00Z').getTime() }, runtimeFingerprint: 'fp1', @@ -282,3 +282,30 @@ describe('buildFlow RTCP rows', () => { expect(flowItems[0].arrowStyleSolid).toBe(false) }) }) + +describe('flowSegmentPx', () => { + // Unevenly spaced lifelines, as produced by host cards of different widths. + const centers = [85, 509, 910, 1314, 1755] + const seg = (o: Partial) => + flowSegmentPx({ start: 0, middle: 1, isRadial: false, isLastHost: false, ...o }, centers) + + it('spans exactly between the measured centres of the two hosts', () => { + expect(seg({ start: 1, middle: 1 })).toEqual({ left: 509, width: 401 }) + expect(seg({ start: 2, middle: 2 })).toEqual({ left: 910, width: 845 }) + }) + + it('loops a self-message towards the next host, or the previous one for the last host', () => { + expect(seg({ start: 2, isRadial: true })).toEqual({ left: 910, width: 404 }) + expect(seg({ start: 4, isRadial: true, isLastHost: true })).toEqual({ left: 1314, width: 441 }) + }) + + it('uses a fixed loop width when there is a single host', () => { + expect(flowSegmentPx({ start: 0, middle: 1, isRadial: true, isLastHost: false }, [300])) + .toEqual({ left: 300, width: 280 }) + }) + + it('returns null until the needed centres are measured', () => { + expect(flowSegmentPx({ start: 0, middle: 1, isRadial: false, isLastHost: false }, [])).toBeNull() + expect(flowSegmentPx({ start: 0, middle: 2, isRadial: false, isLastHost: false }, [10, 20])).toBeNull() + }) +}) diff --git a/src/ui/src/dashboard/flow/flow-data.ts b/src/ui/src/dashboard/flow/flow-data.ts index 2aceb40b..3f7a7dab 100644 --- a/src/ui/src/dashboard/flow/flow-data.ts +++ b/src/ui/src/dashboard/flow/flow-data.ts @@ -63,7 +63,6 @@ export interface FlowItemData { payloadType: string start: number middle: number - rightEnd: number direction: boolean isRadial: boolean isLastHost: boolean @@ -266,7 +265,6 @@ function adoptParentGeometry(parent: FlowItemData, child: FlowItemData): FlowIte ...child, start: parent.start, middle: parent.middle, - rightEnd: parent.rightEnd, direction: parent.direction, isRadial: parent.isRadial, isLastHost: parent.isLastHost, @@ -578,7 +576,6 @@ export function buildFlow(items: RawMessage[] | null | undefined, opts: BuildOpt const start = singleHost ? 0 : Math.min(a, b) const middle = Math.abs(a - b) || 1 const direction = isLastHost || a > b - const rightEnd = singleHost ? 0 : hosts.length - 1 - Math.max(a, b) const arrowStyleSolid = payloadType === 'SIP' @@ -629,7 +626,6 @@ export function buildFlow(items: RawMessage[] | null | undefined, opts: BuildOpt payloadType, start, middle, - rightEnd, direction, isRadial, isLastHost, @@ -648,3 +644,30 @@ export function buildFlow(items: RawMessage[] | null | undefined, opts: BuildOpt return { hosts, flowItems, callIds } } + +/** Loop width (px) for a self-message when there is no neighbouring host to span to. */ +const RADIAL_FALLBACK_PX = 280 + +/** + * Pixel span of a message's arrow segment, derived from the measured host + * centres (the same positions the lifelines are drawn at), so arrows always + * end on the lifelines whatever the host card widths. Returns null until the + * centres needed for this item have been measured. + */ +export function flowSegmentPx( + item: Pick, + hostCenters: readonly number[], +): { left: number; width: number } | null { + let from = item.start + let to = item.start + item.middle + if (item.isRadial) { + // Self-messages loop towards the next host, or the previous one for the last host. + from = item.isLastHost ? item.start - 1 : item.start + to = from + 1 + } + const left = hostCenters[from] + if (left === undefined) return null + const right = hostCenters[to] ?? (item.isRadial ? left + RADIAL_FALLBACK_PX : undefined) + if (right === undefined) return null + return { left, width: right - left } +}