Skip to content

Commit

Permalink
feat: Less indentation for deep trees with single child
Browse files Browse the repository at this point in the history
  • Loading branch information
BYK committed Feb 3, 2025
1 parent 63f2403 commit 9c0b936
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
8 changes: 8 additions & 0 deletions .changeset/plenty-foxes-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@spotlightjs/spotlight': minor
'@spotlightjs/electron': minor
'@spotlightjs/overlay': minor
'@spotlightjs/astro': minor
---

Flatter tree view for deeply nested traces with 1 child at each level
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"TEAMID",
"treeshake",
"ttfb",
"txns",
"unsign",
"uuidv",
"VITE",
Expand Down
9 changes: 5 additions & 4 deletions packages/overlay/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ ul.tree ul {
margin: 0;
padding: 0;
}
ul.tree ul {
ul.tree.deep > li > ul {
margin-left: 8px;
}
ul.tree li {
ul.tree.deep > li {
@apply border-primary-400 border-l;
padding-left: 1rem;
margin-left: 1rem;
}

ul.tree li:last-child {
Expand All @@ -59,11 +61,10 @@ ul.tree > li:first-child:before {
display: none;
}

ul.tree > li:before,
ul.tree.deep > li:before,
ul.tree ul.tree > li:before {
@apply border-primary-400 border-b;
position: absolute;
margin-top: -2px;
height: 15px;
width: 12px;
content: '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ const SpanItem = ({
}) => {
const { spanId } = useParams();
const containerRef = useRef<HTMLLIElement>(null);
const childrenCount = span.children ? span.children.length : 0;

Check warning on line 34 in packages/overlay/src/integrations/sentry/components/explore/traces/spans/SpanItem.tsx

View check run for this annotation

Codecov / codecov/patch

packages/overlay/src/integrations/sentry/components/explore/traces/spans/SpanItem.tsx#L34

Added line #L34 was not covered by tests
const [isItemCollapsed, setIsItemCollapsed] = useState(
(span.transaction && totalTransactions > 1 && depth !== 1) || depth >= 15,
(span.transaction && totalTransactions > 1 && depth !== 1) || depth >= 15 || childrenCount > 10,

Check warning on line 36 in packages/overlay/src/integrations/sentry/components/explore/traces/spans/SpanItem.tsx

View check run for this annotation

Codecov / codecov/patch

packages/overlay/src/integrations/sentry/components/explore/traces/spans/SpanItem.tsx#L36

Added line #L36 was not covered by tests
);
const [isResizing, setIsResizing] = useState(false);

Expand All @@ -51,7 +52,7 @@ const SpanItem = ({
: false;

return (
<li key={span.span_id} className="pl-4" ref={containerRef}>
<li key={span.span_id} ref={containerRef}>

Check warning on line 55 in packages/overlay/src/integrations/sentry/components/explore/traces/spans/SpanItem.tsx

View check run for this annotation

Codecov / codecov/patch

packages/overlay/src/integrations/sentry/components/explore/traces/spans/SpanItem.tsx#L55

Added line #L55 was not covered by tests
<Link
className={classNames(
'hover:bg-primary-900 group flex text-sm',
Expand All @@ -74,15 +75,15 @@ const SpanItem = ({
width: `${spanNodeWidth}%`,
}}
>
{(span.children || []).length > 0 && (
{childrenCount > 0 && (

Check warning on line 78 in packages/overlay/src/integrations/sentry/components/explore/traces/spans/SpanItem.tsx

View check run for this annotation

Codecov / codecov/patch

packages/overlay/src/integrations/sentry/components/explore/traces/spans/SpanItem.tsx#L78

Added line #L78 was not covered by tests
<div
className="bg-primary-600 z-10 mr-1 flex items-center gap-1 rounded-lg px-1 text-xs font-bold text-white"
onClick={e => {
e.preventDefault();
setIsItemCollapsed(prev => !prev);
}}
>
{(span.children || []).length}
{childrenCount}

Check warning on line 86 in packages/overlay/src/integrations/sentry/components/explore/traces/spans/SpanItem.tsx

View check run for this annotation

Codecov / codecov/patch

packages/overlay/src/integrations/sentry/components/explore/traces/spans/SpanItem.tsx#L86

Added line #L86 was not covered by tests
<ChevronIcon
width={12}
height={12}
Expand Down Expand Up @@ -128,7 +129,7 @@ const SpanItem = ({
tree={span.children || []}
startTimestamp={startTimestamp}
totalDuration={totalDuration}
depth={depth + 1}
depth={childrenCount > 1 ? depth + 1 : depth}

Check warning on line 132 in packages/overlay/src/integrations/sentry/components/explore/traces/spans/SpanItem.tsx

View check run for this annotation

Codecov / codecov/patch

packages/overlay/src/integrations/sentry/components/explore/traces/spans/SpanItem.tsx#L132

Added line #L132 was not covered by tests
totalTransactions={totalTransactions}
spanNodeWidth={spanNodeWidth}
setSpanNodeWidth={setSpanNodeWidth}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import classNames from '../../../../../../lib/classNames';
import { Span, TraceContext } from '../../../../types';
import SpanItem from './SpanItem';

Expand Down Expand Up @@ -25,7 +26,7 @@ export default function SpanTree({
if (!tree || !tree.length) return null;

return (
<ul className="tree">
<ul className={classNames(tree.length > 1 && 'deep', 'tree')}>

Check warning on line 29 in packages/overlay/src/integrations/sentry/components/explore/traces/spans/SpanTree.tsx

View check run for this annotation

Codecov / codecov/patch

packages/overlay/src/integrations/sentry/components/explore/traces/spans/SpanTree.tsx#L29

Added line #L29 was not covered by tests
{tree.map(span => {
return (
<SpanItem
Expand Down

0 comments on commit 9c0b936

Please sign in to comment.