summaryrefslogtreecommitdiffstats
path: root/devtools/client/performance-new/components/panel/DevToolsPanel.js
blob: 8f1b8fb344e66c86effc766da61144479d082a4d (plain)
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
/* 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/. */
// @ts-check

/**
 * @template P
 * @typedef {import("react-redux").ResolveThunks<P>} ResolveThunks<P>
 */

/**
 * @typedef {Object} StateProps
 * @property {boolean?} isSupportedPlatform
 */

/**
 * @typedef {Object} OwnProps
 * @property {import("../../@types/perf").PerfFront} perfFront
 * @property {import("../../@types/perf").OnProfileReceived} onProfileReceived
 * @property {() => void} onEditSettingsLinkClicked
 */

/**
 * @typedef {StateProps & OwnProps} Props
 * @typedef {import("../../@types/perf").State} StoreState
 * @typedef {import("../../@types/perf").RecordingState} RecordingState
 * @typedef {import("../../@types/perf").PanelWindow} PanelWindow
 */

"use strict";

const {
  PureComponent,
  createFactory,
} = require("resource://devtools/client/shared/vendor/react.js");
const {
  connect,
} = require("resource://devtools/client/shared/vendor/react-redux.js");
const {
  div,
  hr,
} = require("resource://devtools/client/shared/vendor/react-dom-factories.js");
const RecordingButton = createFactory(
  require("resource://devtools/client/performance-new/components/panel/RecordingButton.js")
);
const Description = createFactory(
  require("resource://devtools/client/performance-new/components/panel/Description.js")
);
const DevToolsPresetSelection = createFactory(
  require("resource://devtools/client/performance-new/components/panel/DevToolsPresetSelection.js")
);
const OnboardingMessage = createFactory(
  require("resource://devtools/client/performance-new/components/panel/OnboardingMessage.js")
);
const ToolboxHighlightController = createFactory(
  require("resource://devtools/client/performance-new/components/panel/ToolboxHighlightController.js")
);

const selectors = require("resource://devtools/client/performance-new/store/selectors.js");
const anyWindow = /** @type {any} */ (window);
const panelWindow = /** @type {PanelWindow} */ (anyWindow);

/**
 * This is the top level component for the DevTools panel.
 *
 * @extends {React.PureComponent<Props>}
 */
class DevToolsPanel extends PureComponent {
  render() {
    const {
      isSupportedPlatform,
      perfFront,
      onProfileReceived,
      onEditSettingsLinkClicked,
    } = this.props;

    if (isSupportedPlatform === null) {
      // We don't know yet if this is a supported platform, wait for a response.
      return null;
    }

    return [
      OnboardingMessage(),
      div(
        { className: `perf perf-devtools` },
        RecordingButton({ perfFront, onProfileReceived }),
        panelWindow.gToolbox
          ? ToolboxHighlightController({ toolbox: panelWindow.gToolbox })
          : null,
        Description(),
        hr({ className: "perf-presets-hr" }),
        DevToolsPresetSelection({ onEditSettingsLinkClicked })
      ),
    ];
  }
}

/**
 * @param {StoreState} state
 * @returns {StateProps}
 */
function mapStateToProps(state) {
  return {
    isSupportedPlatform: selectors.getIsSupportedPlatform(state),
  };
}

module.exports = connect(mapStateToProps)(DevToolsPanel);