1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 * @typedef {import("react-redux").ResolveThunks<P>} ResolveThunks<P>
12 * @typedef {Object} StateProps
13 * @property {string} presetName
14 * @property {number} interval
15 * @property {string[]} threads
16 * @property {string[]} features
17 * @property {import("../../@types/perf").Presets} presets
21 * @typedef {Object} ThunkDispatchProps
22 * @property {typeof actions.changePreset} changePreset
26 * @typedef {Object} OwnProps
27 * @property {() => void} onEditSettingsLinkClicked
31 * @typedef {ResolveThunks<ThunkDispatchProps>} DispatchProps
32 * @typedef {StateProps & DispatchProps & OwnProps} Props
33 * @typedef {import("../../@types/perf").State} StoreState
34 * @typedef {import("../../@types/perf").FeatureDescription} FeatureDescription
42 } = require("resource://devtools/client/shared/vendor/react.js");
51 } = require("resource://devtools/client/shared/vendor/react-dom-factories.js");
54 } = require("resource://devtools/client/shared/vendor/react-redux.js");
55 const actions
= require("resource://devtools/client/performance-new/store/actions.js");
56 const selectors
= require("resource://devtools/client/performance-new/store/selectors.js");
59 } = require("resource://devtools/client/performance-new/shared/utils.js");
60 const Localized
= createFactory(
61 require("resource://devtools/client/shared/vendor/fluent-react.js").Localized
65 * This component displays the preset selection for the DevTools panel. It should be
66 * basically the same implementation as the popup, but done in React. The popup
67 * is written using vanilla JS and browser chrome elements in order to be more
70 * @extends {React.PureComponent<Props>}
72 class DevToolsPresetSelection
extends PureComponent
{
73 /** @param {Props} props */
78 * Create an object map to easily look up feature description.
79 * @type {{[key: string]: FeatureDescription}}
81 this.featureDescriptionMap
= {};
82 for (const feature
of featureDescriptions
) {
83 this.featureDescriptionMap
[feature
.value
] = feature
;
88 * Handle the select change.
89 * @param {React.ChangeEvent<HTMLSelectElement>} event
91 onPresetChange
= event
=> {
92 const { presets
} = this.props
;
93 this.props
.changePreset(presets
, event
.target
.value
);
97 const { presetName
, presets
, onEditSettingsLinkClicked
} = this.props
;
99 let presetDescription
;
100 const currentPreset
= presets
[presetName
];
102 // Display the current preset's description.
103 presetDescription
= Localized({
104 id
: currentPreset
.l10nIds
.devtools
.description
,
107 // Build up a display of the details of the custom preset.
108 const { interval
, threads
, features
} = this.props
;
109 presetDescription
= div(
112 { className
: "perf-presets-custom" },
116 { id
: "perftools-devtools-interval-label" },
117 span({ className
: "perf-presets-custom-bold" })
121 id
: "perftools-range-interval-milliseconds",
128 { id
: "perftools-devtools-threads-label" },
129 span({ className
: "perf-presets-custom-bold" })
134 features
.map(feature
=> {
135 const description
= this.featureDescriptionMap
[feature
];
138 "Could not find the feature description for " + feature
143 description
? description
.name
: feature
151 { className
: "perf-presets" },
153 { className
: "perf-presets-settings" },
154 Localized({ id
: "perftools-devtools-settings-label" })
157 { className
: "perf-presets-details" },
159 { className
: "perf-presets-details-row" },
162 className
: "perf-presets-select",
163 onChange
: this.onPresetChange
,
166 Object
.entries(presets
).map(([name
, preset
]) =>
168 { id
: preset
.l10nIds
.devtools
.label
},
169 option({ key
: name
, value
: name
})
173 { id
: "perftools-presets-custom-label" },
174 option({ value
: "custom" })
177 // The overhead component will go here.
180 { className
: "perf-presets-details-row perf-presets-description" },
185 className
: "perf-external-link",
186 onClick
: onEditSettingsLinkClicked
,
188 Localized({ id
: "perftools-button-edit-settings" })
196 * @param {StoreState} state
197 * @returns {StateProps}
199 function mapStateToProps(state
) {
201 presetName
: selectors
.getPresetName(state
),
202 presets
: selectors
.getPresets(state
),
203 interval
: selectors
.getInterval(state
),
204 threads
: selectors
.getThreads(state
),
205 features
: selectors
.getFeatures(state
),
210 * @type {ThunkDispatchProps}
212 const mapDispatchToProps
= {
213 changePreset
: actions
.changePreset
,
216 module
.exports
= connect(
219 )(DevToolsPresetSelection
);