Skip to content

Commit 45160d4

Browse files
committed
Hoist shared call-tree column helpers into columns.ts.
1 parent 6a05d1d commit 45160d4

5 files changed

Lines changed: 78 additions & 162 deletions

File tree

src/components/calltree/CallTree.tsx

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44
import { PureComponent } from 'react';
5-
import memoize from 'memoize-immutable';
65
import explicitConnect from 'firefox-profiler/utils/connect';
76
import { TreeView } from 'firefox-profiler/components/shared/TreeView';
87
import { CallTreeEmptyReasons } from './CallTreeEmptyReasons';
@@ -28,7 +27,6 @@ import {
2827
changeTableViewOptions,
2928
updateBottomBoxContentsAndMaybeOpen,
3029
} from 'firefox-profiler/actions/profile-view';
31-
import { assertExhaustiveCheck } from 'firefox-profiler/utils/types';
3230

3331
import type {
3432
State,
@@ -43,17 +41,13 @@ import type {
4341
import type { CallTree as CallTreeType } from 'firefox-profiler/profile-logic/call-tree';
4442
import type { CallNodeInfo } from 'firefox-profiler/profile-logic/call-node-info';
4543

46-
import type {
47-
Column,
48-
MaybeResizableColumn,
49-
} from 'firefox-profiler/components/shared/TreeView';
5044
import type { ConnectedProps } from 'firefox-profiler/utils/connect';
5145

5246
import './CallTree.css';
5347
import {
54-
treeColumnsForBytes,
55-
treeColumnsForSamples,
56-
treeColumnsForTracingMs,
48+
mainColumn,
49+
appendageColumn,
50+
treeColumnsForWeightType,
5751
} from './columns';
5852

5953
type StateProps = {
@@ -87,40 +81,11 @@ type DispatchProps = {
8781
type Props = ConnectedProps<{}, StateProps, DispatchProps>;
8882

8983
class CallTreeImpl extends PureComponent<Props> {
90-
_mainColumn: Column<CallNodeDisplayData> = {
91-
propName: 'name',
92-
titleL10nId: '',
93-
};
94-
_appendageColumn: Column<CallNodeDisplayData> = {
95-
propName: 'lib',
96-
titleL10nId: '',
97-
};
9884
_treeView: TreeView<CallNodeDisplayData> | null = null;
9985
_takeTreeViewRef = (treeView: TreeView<CallNodeDisplayData> | null) => {
10086
this._treeView = treeView;
10187
};
10288

103-
/**
104-
* Call Trees can have different types of "weights" for the data. Choose the
105-
* appropriate labels for the call tree based on this weight.
106-
*/
107-
_weightTypeToColumns = memoize(
108-
(weightType: WeightType): MaybeResizableColumn<CallNodeDisplayData>[] => {
109-
switch (weightType) {
110-
case 'tracing-ms':
111-
return treeColumnsForTracingMs;
112-
case 'samples':
113-
return treeColumnsForSamples;
114-
case 'bytes':
115-
return treeColumnsForBytes;
116-
default:
117-
throw assertExhaustiveCheck(weightType, 'Unhandled WeightType.');
118-
}
119-
},
120-
// Use a Map cache, as the function only takes one argument, which is a simple string.
121-
{ cache: new Map() }
122-
);
123-
12489
override componentDidMount() {
12590
this.focus();
12691
this.maybeProcureInterestingInitialSelection();
@@ -284,9 +249,9 @@ class CallTreeImpl extends PureComponent<Props> {
284249
return (
285250
<TreeView
286251
tree={tree}
287-
fixedColumns={this._weightTypeToColumns(weightType)}
288-
mainColumn={this._mainColumn}
289-
appendageColumn={this._appendageColumn}
252+
fixedColumns={treeColumnsForWeightType(weightType)}
253+
mainColumn={mainColumn}
254+
appendageColumn={appendageColumn}
290255
onSelectionChange={this._onSelectedCallNodeChange}
291256
onRightClickSelection={this._onRightClickSelection}
292257
onExpandedNodesChange={this._onExpandedCallNodesChange}

src/components/calltree/FunctionList.tsx

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,10 @@ import {
3232
changeFunctionListSort,
3333
handleFunctionTransformShortcut,
3434
} from 'firefox-profiler/actions/profile-view';
35-
import { assertExhaustiveCheck } from 'firefox-profiler/utils/types';
3635
import {
37-
functionListColumnsForTracingMs,
38-
functionListColumnsForSamples,
39-
functionListColumnsForBytes,
36+
mainColumn,
37+
appendageColumn,
38+
functionListColumnsForWeightType,
4039
} from './columns';
4140

4241
import type {
@@ -50,11 +49,7 @@ import type {
5049
} from 'firefox-profiler/types';
5150
import type { CallTree } from 'firefox-profiler/profile-logic/call-tree';
5251

53-
import type {
54-
Column,
55-
MaybeResizableColumn,
56-
SingleColumnSortState,
57-
} from 'firefox-profiler/components/shared/TreeView';
52+
import type { SingleColumnSortState } from 'firefox-profiler/components/shared/TreeView';
5853
import type { ConnectedProps } from 'firefox-profiler/utils/connect';
5954

6055
import './CallTree.css';
@@ -90,14 +85,6 @@ type DispatchProps = {
9085
type Props = ConnectedProps<{}, StateProps, DispatchProps>;
9186

9287
class FunctionListImpl extends PureComponent<Props> {
93-
_mainColumn: Column<CallNodeDisplayData> = {
94-
propName: 'name',
95-
titleL10nId: '',
96-
};
97-
_appendageColumn: Column<CallNodeDisplayData> = {
98-
propName: 'lib',
99-
titleL10nId: '',
100-
};
10188
_treeView: TreeView<CallNodeDisplayData> | null = null;
10289
_takeTreeViewRef = (treeView: TreeView<CallNodeDisplayData> | null) => {
10390
this._treeView = treeView;
@@ -114,27 +101,6 @@ class FunctionListImpl extends PureComponent<Props> {
114101
this.props.changeFunctionListSort(sortedColumns.sortedColumns);
115102
};
116103

117-
/**
118-
* Call Trees can have different types of "weights" for the data. Choose the
119-
* appropriate labels for the call tree based on this weight.
120-
*/
121-
_weightTypeToColumns = memoize(
122-
(weightType: WeightType): MaybeResizableColumn<CallNodeDisplayData>[] => {
123-
switch (weightType) {
124-
case 'tracing-ms':
125-
return functionListColumnsForTracingMs;
126-
case 'samples':
127-
return functionListColumnsForSamples;
128-
case 'bytes':
129-
return functionListColumnsForBytes;
130-
default:
131-
throw assertExhaustiveCheck(weightType, 'Unhandled WeightType.');
132-
}
133-
},
134-
// Use a Map cache, as the function only takes one argument, which is a simple string.
135-
{ cache: new Map() }
136-
);
137-
138104
override componentDidMount() {
139105
this.focus();
140106
this.maybeProcureInitialSelection();
@@ -236,9 +202,9 @@ class FunctionListImpl extends PureComponent<Props> {
236202
return (
237203
<TreeView
238204
tree={tree}
239-
fixedColumns={this._weightTypeToColumns(weightType)}
240-
mainColumn={this._mainColumn}
241-
appendageColumn={this._appendageColumn}
205+
fixedColumns={functionListColumnsForWeightType(weightType)}
206+
mainColumn={mainColumn}
207+
appendageColumn={appendageColumn}
242208
onSelectionChange={this._onSelectionChange}
243209
onRightClickSelection={this._onRightClickSelection}
244210
onExpandedNodesChange={this._onExpandedCallNodesChange}

src/components/calltree/SelfWing.tsx

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@
44
// @flow
55

66
import * as React from 'react';
7-
import memoize from 'memoize-immutable';
87

98
import explicitConnect from 'firefox-profiler/utils/connect';
109
import { FlameGraph } from 'firefox-profiler/components/flame-graph/FlameGraph';
1110
import { TreeView } from 'firefox-profiler/components/shared/TreeView';
1211
import { CallTreeEmptyReasons } from './CallTreeEmptyReasons';
1312
import {
14-
treeColumnsForTracingMs,
15-
treeColumnsForSamples,
16-
treeColumnsForBytes,
13+
mainColumn,
14+
appendageColumn,
15+
treeColumnsForWeightType,
1716
} from './columns';
1817

1918
import {
@@ -39,7 +38,6 @@ import {
3938
changeRightClickedFunctionIndex,
4039
changeTableViewOptions,
4140
} from 'firefox-profiler/actions/profile-view';
42-
import { assertExhaustiveCheck } from 'firefox-profiler/utils/types';
4341

4442
import type {
4543
Thread,
@@ -64,10 +62,6 @@ import type { FlameGraphTiming } from 'firefox-profiler/profile-logic/flame-grap
6462
import type { CallNodeInfo } from 'firefox-profiler/profile-logic/call-node-info';
6563
import type { CallTree } from 'firefox-profiler/profile-logic/call-tree';
6664

67-
import type {
68-
Column,
69-
MaybeResizableColumn,
70-
} from 'firefox-profiler/components/shared/TreeView';
7165
import type { ConnectedProps } from 'firefox-profiler/utils/connect';
7266

7367
type StateProps = {
@@ -116,35 +110,11 @@ class SelfWingImpl extends React.PureComponent<Props, LocalState> {
116110
expandedCallNodeIndexes: [],
117111
};
118112

119-
_mainColumn: Column<CallNodeDisplayData> = {
120-
propName: 'name',
121-
titleL10nId: '',
122-
};
123-
_appendageColumn: Column<CallNodeDisplayData> = {
124-
propName: 'lib',
125-
titleL10nId: '',
126-
};
127113
_treeView: TreeView<CallNodeDisplayData> | null = null;
128114
_takeTreeViewRef = (treeView: TreeView<CallNodeDisplayData> | null) => {
129115
this._treeView = treeView;
130116
};
131117

132-
_weightTypeToColumns = memoize(
133-
(weightType: WeightType): MaybeResizableColumn<CallNodeDisplayData>[] => {
134-
switch (weightType) {
135-
case 'tracing-ms':
136-
return treeColumnsForTracingMs;
137-
case 'samples':
138-
return treeColumnsForSamples;
139-
case 'bytes':
140-
return treeColumnsForBytes;
141-
default:
142-
throw assertExhaustiveCheck(weightType, 'Unhandled WeightType.');
143-
}
144-
},
145-
{ cache: new Map() }
146-
);
147-
148118
override componentDidUpdate(prevProps: Props, _prevState: LocalState) {
149119
// Reset local selection when the call node info changes (e.g. different
150120
// function selected) since old call node indices are no longer valid.
@@ -298,9 +268,9 @@ class SelfWingImpl extends React.PureComponent<Props, LocalState> {
298268
return (
299269
<TreeView
300270
tree={callTree}
301-
fixedColumns={this._weightTypeToColumns(weightType)}
302-
mainColumn={this._mainColumn}
303-
appendageColumn={this._appendageColumn}
271+
fixedColumns={treeColumnsForWeightType(weightType)}
272+
mainColumn={mainColumn}
273+
appendageColumn={appendageColumn}
304274
onSelectionChange={this._onTreeViewSelectionChange}
305275
onRightClickSelection={this._onTreeViewRightClickSelection}
306276
onExpandedNodesChange={this._onTreeViewExpandedNodesChange}

src/components/calltree/WingTreeView.tsx

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import * as React from 'react';
66
import { PureComponent } from 'react';
7-
import memoize from 'memoize-immutable';
87
import explicitConnect from 'firefox-profiler/utils/connect';
98
import { TreeView } from 'firefox-profiler/components/shared/TreeView';
109
import { CallTreeEmptyReasons } from './CallTreeEmptyReasons';
@@ -17,9 +16,9 @@ import {
1716
type LowerWingFlameGraphHandle,
1817
} from './LowerWingFlameGraph';
1918
import {
20-
treeColumnsForTracingMs,
21-
treeColumnsForSamples,
22-
treeColumnsForBytes,
19+
mainColumn,
20+
appendageColumn,
21+
treeColumnsForWeightType,
2322
} from './columns';
2423
import {
2524
getSearchStringsAsRegExp,
@@ -43,8 +42,6 @@ import {
4342
changeTableViewOptions,
4443
updateBottomBoxContentsAndMaybeOpen,
4544
} from 'firefox-profiler/actions/profile-view';
46-
import { assertExhaustiveCheck } from 'firefox-profiler/utils/types';
47-
4845
import type {
4946
State,
5047
ThreadsKey,
@@ -61,10 +58,6 @@ import type {
6158
import type { CallTree as CallTreeType } from 'firefox-profiler/profile-logic/call-tree';
6259
import type { CallNodeInfo } from 'firefox-profiler/profile-logic/call-node-info';
6360

64-
import type {
65-
Column,
66-
MaybeResizableColumn,
67-
} from 'firefox-profiler/components/shared/TreeView';
6861
import type { ConnectedProps } from 'firefox-profiler/utils/connect';
6962

7063
import './CallTree.css';
@@ -122,42 +115,13 @@ type WingConfigProps = {
122115
type Props = ConnectedProps<{}, StateProps, DispatchProps> & WingConfigProps;
123116

124117
class WingTreeViewImpl extends PureComponent<Props> {
125-
_mainColumn: Column<CallNodeDisplayData> = {
126-
propName: 'name',
127-
titleL10nId: '',
128-
};
129-
_appendageColumn: Column<CallNodeDisplayData> = {
130-
propName: 'lib',
131-
titleL10nId: '',
132-
};
133118
_treeView: TreeView<CallNodeDisplayData> | null = null;
134119
_takeTreeViewRef = (treeView: TreeView<CallNodeDisplayData> | null) => {
135120
this._treeView = treeView;
136121
};
137122
_flameGraphRef: React.RefObject<WingFlameGraphHandle | null> =
138123
React.createRef();
139124

140-
/**
141-
* Call Trees can have different types of "weights" for the data. Choose the
142-
* appropriate labels for the call tree based on this weight.
143-
*/
144-
_weightTypeToColumns = memoize(
145-
(weightType: WeightType): MaybeResizableColumn<CallNodeDisplayData>[] => {
146-
switch (weightType) {
147-
case 'tracing-ms':
148-
return treeColumnsForTracingMs;
149-
case 'samples':
150-
return treeColumnsForSamples;
151-
case 'bytes':
152-
return treeColumnsForBytes;
153-
default:
154-
throw assertExhaustiveCheck(weightType, 'Unhandled WeightType.');
155-
}
156-
},
157-
// Use a Map cache, as the function only takes one argument, which is a simple string.
158-
{ cache: new Map() }
159-
);
160-
161125
override componentDidMount() {
162126
this.focus();
163127
this.maybeProcureInterestingInitialSelection();
@@ -324,9 +288,9 @@ class WingTreeViewImpl extends PureComponent<Props> {
324288
return (
325289
<TreeView
326290
tree={tree}
327-
fixedColumns={this._weightTypeToColumns(weightType)}
328-
mainColumn={this._mainColumn}
329-
appendageColumn={this._appendageColumn}
291+
fixedColumns={treeColumnsForWeightType(weightType)}
292+
mainColumn={mainColumn}
293+
appendageColumn={appendageColumn}
330294
onSelectionChange={this._onSelectedCallNodeChange}
331295
onRightClickSelection={this._onRightClickSelection}
332296
onExpandedNodesChange={this._onExpandedCallNodesChange}

0 commit comments

Comments
 (0)