-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathCallStackDisplay.tsx
More file actions
62 lines (56 loc) · 1.7 KB
/
CallStackDisplay.tsx
File metadata and controls
62 lines (56 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* Displays the current call stack as a breadcrumb trail.
*/
import React from "react";
import { useTraceContext } from "./TraceContext.js";
// CSS is expected to be imported by the consuming application
// import "./CallStackDisplay.css";
export interface CallStackDisplayProps {
/** Custom class name */
className?: string;
}
/**
* Renders the call stack as a breadcrumb.
*
* Shows function names separated by arrows, e.g.:
* main() -> transfer() -> _update()
*/
export function CallStackDisplay({
className = "",
}: CallStackDisplayProps): JSX.Element {
const { callStack, jumpToStep } = useTraceContext();
if (callStack.length === 0) {
return (
<div className={`call-stack call-stack-empty ${className}`.trim()}>
<span className="call-stack-empty-text">(top level)</span>
</div>
);
}
return (
<div className={`call-stack ${className}`.trim()}>
<div className="call-stack-breadcrumb">
{callStack.map((frame, index) => (
<React.Fragment key={index}>
{index > 0 && (
<span className="call-stack-separator">{" -> "}</span>
)}
<button
className="call-stack-frame"
onClick={() => jumpToStep(frame.stepIndex)}
title={
`Step ${frame.stepIndex + 1}` +
(frame.callType ? ` (${frame.callType})` : "")
}
type="button"
>
<span className="call-stack-name">
{frame.identifier || "(anonymous)"}
</span>
<span className="call-stack-parens">()</span>
</button>
</React.Fragment>
))}
</div>
</div>
);
}