Skip to content

Commit 418567f

Browse files
authored
feat: trace panel inline split detail (#2402)
1 parent 9119de5 commit 418567f

17 files changed

Lines changed: 494 additions & 236 deletions

‎.changeset/tough-ads-pay.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hyperdx/app": minor
3+
---
4+
5+
feat: trace panel inline split detail

‎packages/app/src/LogSidePanelElements.tsx‎

Lines changed: 52 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,16 @@ import * as React from 'react';
33
import Link from 'next/link';
44
import cx from 'classnames';
55
import { JSONTree } from 'react-json-tree';
6-
import { Alert, Button, CloseButton, Kbd, Text, Tooltip } from '@mantine/core';
6+
import {
7+
Alert,
8+
Button,
9+
Group,
10+
Kbd,
11+
Modal,
12+
Stack,
13+
Text,
14+
Tooltip,
15+
} from '@mantine/core';
716
import {
817
IconChevronDown,
918
IconChevronRight,
@@ -485,37 +494,49 @@ export const NetworkBody = ({
485494
/**
486495
* Keyboard shortcuts
487496
*/
488-
export const LogSidePanelKbdShortcuts = () => {
489-
const [isDismissed, setDismissed] = useLocalStorage<boolean>(
490-
'kbd-shortcuts-dismissed',
491-
false,
492-
);
493-
494-
const handleDismiss = React.useCallback(() => {
495-
setDismissed(true);
496-
}, [setDismissed]);
497-
498-
if (isDismissed) {
499-
return null;
500-
}
501-
497+
const SHORTCUTS = [
498+
{ keys: ['esc'], label: 'Close panel' },
499+
{ keys: ['←', '→'], label: 'Navigate between events' },
500+
{ keys: ['↑', '↓'], label: 'Navigate between events' },
501+
{ keys: ['k', 'j'], label: 'Navigate between events' },
502+
{ keys: ['⌘/Ctrl', 'scroll'], label: 'Zoom trace timeline' },
503+
] as const;
504+
505+
export const KeyboardShortcutsModal = ({
506+
opened,
507+
onClose,
508+
}: {
509+
opened: boolean;
510+
onClose: () => void;
511+
}) => {
502512
return (
503-
<div className={styles.kbdShortcuts}>
504-
<div className="d-flex justify-content-between align-items-center ">
505-
<div className="d-flex align-items-center gap-3">
506-
<div>
507-
Use <Kbd className="me-1">←</Kbd>
508-
<Kbd>→</Kbd> arrow keys or <Kbd className="me-1">k</Kbd>
509-
<Kbd>j</Kbd> to move through events
510-
</div>
511-
<div className={styles.kbdDivider} />
512-
<div>
513-
<Kbd>ESC</Kbd> to close
514-
</div>
515-
</div>
516-
<CloseButton aria-label="Hide" onClick={handleDismiss} />
517-
</div>
518-
</div>
513+
<Modal
514+
opened={opened}
515+
onClose={onClose}
516+
title="Keyboard Shortcuts"
517+
size="sm"
518+
centered
519+
>
520+
<Stack gap="sm">
521+
{SHORTCUTS.map(({ keys, label }) => (
522+
<Group key={label} justify="space-between">
523+
<Group gap={4}>
524+
{keys.map((key, i) => (
525+
<React.Fragment key={key}>
526+
{i > 0 && (
527+
<Text span size="xs" c="dimmed">
528+
+
529+
</Text>
530+
)}
531+
<Kbd size="xs">{key}</Kbd>
532+
</React.Fragment>
533+
))}
534+
</Group>
535+
<Text size="sm">{label}</Text>
536+
</Group>
537+
))}
538+
</Stack>
539+
</Modal>
519540
);
520541
};
521542

‎packages/app/src/SessionSidePanel.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { IconLink, IconX } from '@tabler/icons-react';
1313

1414
import {
1515
DrawerFullWidthToggle,
16-
getInitialDrawerWidthPercent,
16+
INITIAL_DRAWER_WIDTH_PERCENT,
1717
} from '@/components/DrawerUtils';
1818
import useResizable from '@/hooks/useResizable';
1919
import {
@@ -54,11 +54,11 @@ export default function SessionSidePanel({
5454
const [subDrawerOpen, setSubDrawerOpen] = useState(false);
5555

5656
const { size, setSize, startResize } = useResizable(
57-
getInitialDrawerWidthPercent(),
57+
INITIAL_DRAWER_WIDTH_PERCENT,
5858
);
5959
const isFullWidth = size >= 99;
6060
const toggleFullWidth = useCallback(() => {
61-
setSize(isFullWidth ? getInitialDrawerWidthPercent() : 100);
61+
setSize(isFullWidth ? INITIAL_DRAWER_WIDTH_PERCENT : 100);
6262
}, [isFullWidth, setSize]);
6363

6464
useHotkeys(

‎packages/app/src/components/DBRowDataPanel.tsx‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,34 @@ export function useRowData({
190190
};
191191
}
192192

193+
// Detects whether a normalized row carries Kubernetes resource attributes, used
194+
// to conditionally surface the Infrastructure tab/panel. Requires the source to
195+
// expose resource attributes; returns false (rather than throwing) on any gap.
196+
export function rowHasK8sContext(
197+
source: TSource | null | undefined,
198+
normalizedRow: Record<string, any> | null | undefined,
199+
): boolean {
200+
try {
201+
if (
202+
source == null ||
203+
!('resourceAttributesExpression' in source) ||
204+
!source.resourceAttributesExpression ||
205+
!normalizedRow
206+
) {
207+
return false;
208+
}
209+
210+
const resourceAttrs = normalizedRow[ROW_DATA_ALIASES.RESOURCE_ATTRIBUTES];
211+
return (
212+
resourceAttrs?.['k8s.pod.uid'] != null ||
213+
resourceAttrs?.['k8s.node.name'] != null
214+
);
215+
} catch (e) {
216+
console.error(e);
217+
return false;
218+
}
219+
}
220+
193221
export function getJSONColumnNames(meta: ResponseJSON['meta'] | undefined) {
194222
return (
195223
meta

‎packages/app/src/components/DBRowJsonViewer.test.tsx‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,28 @@ describe('DBRowJsonViewer', () => {
6161
);
6262
};
6363

64+
// Line action buttons are now icon-only; locate them by their `title`
65+
// tooltip. Maps the friendly action name to a unique title substring.
66+
const ACTION_TITLE: Record<string, string> = {
67+
Search: 'search for this value only',
68+
'Add to Filters': 'add to filters',
69+
Column: 'column to results table',
70+
'Copy Object': 'copy object',
71+
'Copy Value': 'copy value',
72+
};
73+
74+
const findActionButton = (line: HTMLElement, buttonText: string) => {
75+
const needle = (ACTION_TITLE[buttonText] ?? buttonText).toLowerCase();
76+
return within(line).getByTitle((content: string) =>
77+
(content ?? '').toLowerCase().includes(needle),
78+
);
79+
};
80+
6481
// Helper to click a button on a line
6582
const clickLineButton = (fieldText: string, buttonText: string) => {
6683
const line = screen.getByText(fieldText).closest('.line')! as HTMLElement;
6784
fireEvent.mouseEnter(line);
68-
const button = within(line).getByText(buttonText);
85+
const button = findActionButton(line, buttonText);
6986
fireEvent.click(button);
7087
};
7188

@@ -84,7 +101,7 @@ describe('DBRowJsonViewer', () => {
84101
.getByText(childField)
85102
.closest('.line')! as HTMLElement;
86103
fireEvent.mouseEnter(childLine);
87-
const button = within(childLine).getByText(buttonText);
104+
const button = findActionButton(childLine, buttonText);
88105
fireEvent.click(button);
89106
};
90107

‎packages/app/src/components/DBRowJsonViewer.tsx‎

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -384,12 +384,7 @@ export function DBRowJsonViewer({
384384
) {
385385
actions.push({
386386
key: 'add-to-search',
387-
label: (
388-
<Group gap={2}>
389-
<IconFilter size={14} />
390-
Add to Filters
391-
</Group>
392-
),
387+
label: <IconFilter size={14} />,
393388
title: 'Add to Filters',
394389
onClick: () => {
395390
let filterFieldPath = fieldPath;
@@ -428,12 +423,7 @@ export function DBRowJsonViewer({
428423
if (generateSearchUrl && typeof value !== 'object') {
429424
actions.push({
430425
key: 'search',
431-
label: (
432-
<Group gap={2}>
433-
<IconSearch size={14} />
434-
Search
435-
</Group>
436-
),
426+
label: <IconSearch size={14} />,
437427
title: 'Search for this value only',
438428
onClick: () => {
439429
let searchFieldPath = fieldPath;
@@ -532,17 +522,7 @@ export function DBRowJsonViewer({
532522
const isIncluded = displayedColumns?.includes(columnFieldPath);
533523
actions.push({
534524
key: 'toggle-column',
535-
label: isIncluded ? (
536-
<Group gap={2}>
537-
<IconMinus size={14} />
538-
Column
539-
</Group>
540-
) : (
541-
<Group gap={2}>
542-
<IconPlus size={14} />
543-
Column
544-
</Group>
545-
),
525+
label: isIncluded ? <IconMinus size={14} /> : <IconPlus size={14} />,
546526
title: isIncluded
547527
? `Remove ${fieldPath} column from results table`
548528
: `Add ${fieldPath} column to results table`,
@@ -589,18 +569,15 @@ export function DBRowJsonViewer({
589569
if (typeof value === 'object') {
590570
actions.push({
591571
key: 'copy-object',
592-
label: 'Copy Object',
572+
label: <IconCopy size={14} />,
573+
title: 'Copy object',
593574
onClick: handleCopyObject,
594575
});
595576
} else {
596577
actions.push({
597578
key: 'copy-value',
598-
label: (
599-
<Group gap={2}>
600-
<IconCopy size={14} />
601-
Copy Value
602-
</Group>
603-
),
579+
label: <IconCopy size={14} />,
580+
title: 'Copy value',
604581
onClick: async () => {
605582
const copied = await copyTextToClipboard(
606583
typeof value === 'string'

‎packages/app/src/components/DBRowSidePanel.tsx‎

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import DBRowSidePanelHeader, {
3131
import useResizable from '@/hooks/useResizable';
3232
import { WithClause } from '@/hooks/useRowWhere';
3333
import useWaterfallSearchState from '@/hooks/useWaterfallSearchState';
34-
import { LogSidePanelKbdShortcuts } from '@/LogSidePanelElements';
3534
import { getEventBody } from '@/source';
3635
import TabBar from '@/TabBar';
3736
import { SearchConfig } from '@/types';
@@ -41,11 +40,11 @@ import { useZIndex, ZIndexContext } from '@/zIndex';
4140
import ServiceMapSidePanel from './ServiceMap/ServiceMapSidePanel';
4241
import ContextSubpanel from './ContextSidePanel';
4342
import DBInfraPanel from './DBInfraPanel';
44-
import { RowDataPanel, useRowData } from './DBRowDataPanel';
43+
import { RowDataPanel, rowHasK8sContext, useRowData } from './DBRowDataPanel';
4544
import { RowOverviewPanel } from './DBRowOverviewPanel';
4645
import { DBSessionPanel, useSessionId } from './DBSessionPanel';
4746
import DBTracePanel from './DBTracePanel';
48-
import { getInitialDrawerWidthPercent } from './DrawerUtils';
47+
import { INITIAL_DRAWER_WIDTH_PERCENT } from './DrawerUtils';
4948

5049
import styles from '@/../styles/LogSidePanel.module.scss';
5150

@@ -289,26 +288,10 @@ const DBRowSidePanel = ({
289288
enabled: rowId != null,
290289
});
291290

292-
const hasK8sContext = useMemo(() => {
293-
try {
294-
if (
295-
!('resourceAttributesExpression' in source) ||
296-
!source?.resourceAttributesExpression ||
297-
!normalizedRow
298-
) {
299-
return false;
300-
}
301-
302-
const resourceAttrs = normalizedRow['__hdx_resource_attributes'];
303-
return (
304-
resourceAttrs?.['k8s.pod.uid'] != null ||
305-
resourceAttrs?.['k8s.node.name'] != null
306-
);
307-
} catch (e) {
308-
console.error(e);
309-
return false;
310-
}
311-
}, [source, normalizedRow]);
291+
const hasK8sContext = useMemo(
292+
() => rowHasK8sContext(source, normalizedRow),
293+
[source, normalizedRow],
294+
);
312295

313296
const initialRowHighlightHint = useMemo(() => {
314297
if (normalizedRow) {
@@ -554,7 +537,6 @@ const DBRowSidePanel = ({
554537
</Box>
555538
</ErrorBoundary>
556539
)}
557-
<LogSidePanelKbdShortcuts />
558540
</>
559541
);
560542
};
@@ -572,12 +554,12 @@ export default function DBRowSidePanelErrorBoundary({
572554
const drawerZIndex = contextZIndex + 10;
573555

574556
const { size, setSize, startResize } = useResizable(
575-
getInitialDrawerWidthPercent(),
557+
INITIAL_DRAWER_WIDTH_PERCENT,
576558
);
577559

578560
const isFullWidth = size >= 99;
579561
const toggleFullWidth = useCallback(() => {
580-
setSize(isFullWidth ? getInitialDrawerWidthPercent() : 100);
562+
setSize(isFullWidth ? INITIAL_DRAWER_WIDTH_PERCENT : 100);
581563
}, [isFullWidth, setSize]);
582564

583565
// Keep track of sub-drawers so we can disable closing this root drawer

0 commit comments

Comments
 (0)