-
Notifications
You must be signed in to change notification settings - Fork 456
Expand file tree
/
Copy pathDetails.tsx
More file actions
153 lines (137 loc) · 5.34 KB
/
Details.tsx
File metadata and controls
153 lines (137 loc) · 5.34 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { PureComponent } from 'react';
import classNames from 'classnames';
import { Localized } from '@fluent/react';
import explicitConnect from 'firefox-profiler/utils/connect';
import { TabBar } from './TabBar';
import { LocalizedErrorBoundary } from './ErrorBoundary';
import { ProfileCallTreeView } from 'firefox-profiler/components/calltree/ProfileCallTreeView';
import { MarkerTable } from 'firefox-profiler/components/marker-table';
import { StackChart } from 'firefox-profiler/components/stack-chart/';
import { MarkerChartTab } from 'firefox-profiler/components/marker-chart-tab/';
import { NetworkChart } from 'firefox-profiler/components/network-chart/';
import { FlameGraph } from 'firefox-profiler/components/flame-graph/';
import { JsTracer } from 'firefox-profiler/components/js-tracer/';
import { selectSidebar } from 'firefox-profiler/components/sidebar';
import {
changeSelectedTab,
changeSidebarOpenState,
} from 'firefox-profiler/actions/app';
import { getSelectedTab } from 'firefox-profiler/selectors/url-state';
import { getIsSidebarOpen } from 'firefox-profiler/selectors/app';
import { selectedThreadSelectors } from 'firefox-profiler/selectors/per-thread';
import { CallNodeContextMenu } from 'firefox-profiler/components/shared/CallNodeContextMenu';
import { MaybeMarkerContextMenu } from 'firefox-profiler/components/shared/MarkerContextMenu';
import { toValidTabSlug } from 'firefox-profiler/utils/types';
import type { ConnectedProps } from 'firefox-profiler/utils/connect';
import type { TabSlug } from 'firefox-profiler/app-logic/tabs-handling';
import './Details.css';
type StateProps = {
readonly visibleTabs: ReadonlyArray<TabSlug>;
readonly selectedTab: TabSlug;
readonly isSidebarOpen: boolean;
};
type DispatchProps = {
readonly changeSelectedTab: typeof changeSelectedTab;
readonly changeSidebarOpenState: typeof changeSidebarOpenState;
};
type Props = ConnectedProps<{}, StateProps, DispatchProps>;
const SMALL_SCREEN_WIDTH = 768;
class ProfileViewerImpl extends PureComponent<Props> {
_onSelectTab = (selectedTab: string) => {
const { changeSelectedTab } = this.props;
const tabSlug = toValidTabSlug(selectedTab);
if (!tabSlug) {
throw new Error('Attempted to change to a tab that does not exist.');
}
changeSelectedTab(tabSlug);
};
_onClickSidebarButton = () => {
const { selectedTab, isSidebarOpen, changeSidebarOpenState } = this.props;
changeSidebarOpenState(selectedTab, !isSidebarOpen);
};
override componentDidMount() {
const width = window.innerWidth;
const { selectedTab, isSidebarOpen, changeSidebarOpenState } = this.props;
if (width <= SMALL_SCREEN_WIDTH && isSidebarOpen) {
changeSidebarOpenState(selectedTab, false);
}
}
override render() {
const { visibleTabs, selectedTab, isSidebarOpen } = this.props;
const hasSidebar = selectSidebar(selectedTab) !== null;
return (
<div className="Details">
<div className="Details-top-bar">
<TabBar
selectedTabSlug={selectedTab}
visibleTabs={visibleTabs}
onSelectTab={this._onSelectTab}
/>
<Localized
id={
isSidebarOpen
? 'Details--close-sidebar-button'
: 'Details--open-sidebar-button'
}
attrs={{ title: true }}
vars={{ isSidebarOpen: isSidebarOpen }}
>
<button
className={classNames(
'sidebar-open-close-button',
'photon-button',
'photon-button-ghost',
{
'sidebar-open-close-button-isopen': isSidebarOpen,
'sidebar-open-close-button-isclosed': !isSidebarOpen,
}
)}
title={isSidebarOpen ? 'Close the sidebar' : 'Open the sidebar'}
type="button"
disabled={!hasSidebar}
onClick={this._onClickSidebarButton}
/>
</Localized>
</div>
<Localized
id="Details--error-boundary-message"
attrs={{ message: true }}
>
<LocalizedErrorBoundary
key={selectedTab}
message="Uh oh, some unknown error happened in this panel"
>
{
{
calltree: <ProfileCallTreeView />,
'flame-graph': <FlameGraph />,
'stack-chart': <StackChart />,
'marker-chart': <MarkerChartTab />,
'marker-table': <MarkerTable />,
'network-chart': <NetworkChart />,
'js-tracer': <JsTracer />,
}[selectedTab]
}
</LocalizedErrorBoundary>
</Localized>
<CallNodeContextMenu />
<MaybeMarkerContextMenu />
</div>
);
}
}
export const Details = explicitConnect<{}, StateProps, DispatchProps>({
mapStateToProps: (state) => ({
visibleTabs: selectedThreadSelectors.getUsefulTabs(state),
selectedTab: getSelectedTab(state),
isSidebarOpen: getIsSidebarOpen(state),
}),
mapDispatchToProps: {
changeSelectedTab,
changeSidebarOpenState,
},
component: ProfileViewerImpl,
});