@@ -15,18 +15,25 @@ import ButtonIcon from '../ButtonIcon';
1515import ViewSourceContext from '../Components/ViewSourceContext' ;
1616import { useContext } from 'react' ;
1717import { TimelineContext } from 'react-devtools-timeline/src/TimelineContext' ;
18+ import {
19+ formatTimestamp ,
20+ getSchedulingEventLabel ,
21+ } from 'react-devtools-timeline/src/utils/formatting' ;
1822import { stackToComponentSources } from 'react-devtools-shared/src/devtools/utils' ;
23+ import { copy } from 'clipboard-js' ;
1924
2025import styles from './SidebarEventInfo.css' ;
2126
2227export type Props = { || } ;
2328
24- function SchedulingEventInfo ( { eventInfo} : { eventInfo : SchedulingEvent } ) {
25- const { viewUrlSourceFunction} = useContext ( ViewSourceContext ) ;
29+ type SchedulingEventProps = { |
30+ eventInfo : SchedulingEvent ,
31+ | } ;
2632
27- const componentStack = eventInfo . componentStack
28- ? stackToComponentSources ( eventInfo . componentStack )
29- : null ;
33+ function SchedulingEventInfo ( { eventInfo} : SchedulingEventProps ) {
34+ const { viewUrlSourceFunction} = useContext ( ViewSourceContext ) ;
35+ const { componentName, timestamp} = eventInfo ;
36+ const componentStack = eventInfo . componentStack || null ;
3037
3138 const viewSource = source => {
3239 if ( viewUrlSourceFunction != null && source != null ) {
@@ -35,45 +42,66 @@ function SchedulingEventInfo({eventInfo}: {eventInfo: SchedulingEvent}) {
3542 } ;
3643
3744 return (
38- < div className = { styles . Content } tabIndex = { 0 } >
39- { componentStack ? (
40- < ol className = { styles . List } >
41- { componentStack . map ( ( [ displayName , source ] , index ) => {
42- const hasSource = source != null ;
43-
44- return (
45- < li
46- key = { index }
47- className = { styles . ListItem }
48- data-source = { hasSource } >
49- < label className = { styles . Label } >
50- < Button
51- className = { styles . Button }
52- onClick = { ( ) => viewSource ( source ) } >
53- { displayName }
54- </ Button >
55- { hasSource && (
56- < ButtonIcon className = { styles . Source } type = "view-source" />
57- ) }
58- </ label >
59- </ li >
60- ) ;
61- } ) }
62- </ ol >
63- ) : null }
64- </ div >
45+ < >
46+ < div className = { styles . Toolbar } >
47+ { componentName } { getSchedulingEventLabel ( eventInfo ) }
48+ </ div >
49+ < div className = { styles . Content } tabIndex = { 0 } >
50+ < ul className = { styles . List } >
51+ < li className = { styles . ListItem } >
52+ < label className = { styles . Label } > Timestamp</ label > :{ ' ' }
53+ < span className = { styles . Value } > { formatTimestamp ( timestamp ) } </ span >
54+ </ li >
55+ { componentStack && (
56+ < li className = { styles . ListItem } >
57+ < div className = { styles . Row } >
58+ < label className = { styles . Label } > Rendered by</ label >
59+ < Button
60+ onClick = { ( ) => copy ( componentStack ) }
61+ title = "Copy component stack to clipboard" >
62+ < ButtonIcon type = "copy" />
63+ </ Button >
64+ </ div >
65+ < ul className = { styles . List } >
66+ { stackToComponentSources ( componentStack ) . map (
67+ ( [ displayName , source ] , index ) => {
68+ return (
69+ < li key = { index } >
70+ < Button
71+ className = {
72+ source
73+ ? styles . ClickableSource
74+ : styles . UnclickableSource
75+ }
76+ disabled = { ! source }
77+ onClick = { ( ) => viewSource ( source ) } >
78+ { displayName }
79+ </ Button >
80+ </ li >
81+ ) ;
82+ } ,
83+ ) }
84+ </ ul >
85+ </ li >
86+ ) }
87+ </ ul >
88+ </ div >
89+ </ >
6590 ) ;
6691}
6792
6893export default function SidebarEventInfo ( _ : Props ) {
6994 const { selectedEvent} = useContext ( TimelineContext ) ;
7095 // (TODO) Refactor in next PR so this supports multiple types of events
71- return selectedEvent ? (
72- < >
73- < div className = { styles . Toolbar } > Event Component Tree</ div >
74- { selectedEvent . schedulingEvent ? (
75- < SchedulingEventInfo eventInfo = { selectedEvent . schedulingEvent } />
76- ) : null }
77- </ >
78- ) : null ;
96+ if ( selectedEvent ) {
97+ return (
98+ < >
99+ { selectedEvent . schedulingEvent ? (
100+ < SchedulingEventInfo eventInfo = { selectedEvent . schedulingEvent } />
101+ ) : null }
102+ </ >
103+ ) ;
104+ }
105+
106+ return null ;
79107}
0 commit comments