Files
firefox/devtools/client/aboutdebugging/components/Aboutdebugging.js
T
Michael Ratcliffe 81596860ae Bug 1491879 - Fix telemetry support for multiple tabs / windows r=nchevobbe
- Various telemetry methods now need an object to be passed in in order to keep them seperate e.g. if the inspector is opened in tab 1 a timer is started. If an inspector is opened in tab 2 the same timer is restarted. Closing tab 2 would then erase the timing event invalidating the timer in tab 1.
- We no longer need to preface telemetry calls with category "devtools.main" because this is the only category we will be using.
- There are some changes to `devtools/client/debugger/new/dist/vendors.js` and `devtools/client/debugger/new/src/utils/telemetry.js` that need to be ported to the debugger at the same time as landing this.

Differential Revision: https://phabricator.services.mozilla.com/D6137
2018-09-25 12:57:13 +00:00

126 lines
3.7 KiB
JavaScript

/* 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/. */
/* eslint-env browser */
"use strict";
const { createFactory, Component } = require("devtools/client/shared/vendor/react");
const PropTypes = require("devtools/client/shared/vendor/react-prop-types");
const dom = require("devtools/client/shared/vendor/react-dom-factories");
const Services = require("Services");
const PanelMenu = createFactory(require("./PanelMenu"));
loader.lazyGetter(this, "AddonsPanel",
() => createFactory(require("./addons/Panel")));
loader.lazyGetter(this, "TabsPanel",
() => createFactory(require("./tabs/Panel")));
loader.lazyGetter(this, "WorkersPanel",
() => createFactory(require("./workers/Panel")));
loader.lazyRequireGetter(this, "DebuggerClient",
"devtools/shared/client/debugger-client", true);
loader.lazyRequireGetter(this, "Telemetry",
"devtools/client/shared/telemetry");
const Strings = Services.strings.createBundle(
"chrome://devtools/locale/aboutdebugging.properties");
const panels = [{
id: "addons",
name: Strings.GetStringFromName("addons"),
icon: "chrome://devtools/skin/images/debugging-addons.svg",
component: AddonsPanel
}, {
id: "tabs",
name: Strings.GetStringFromName("tabs"),
icon: "chrome://devtools/skin/images/debugging-tabs.svg",
component: TabsPanel
}, {
id: "workers",
name: Strings.GetStringFromName("workers"),
icon: "chrome://devtools/skin/images/debugging-workers.svg",
component: WorkersPanel
}];
const defaultPanelId = "addons";
class AboutDebuggingApp extends Component {
static get propTypes() {
return {
client: PropTypes.instanceOf(DebuggerClient).isRequired,
connect: PropTypes.object.isRequired,
telemetry: PropTypes.instanceOf(Telemetry).isRequired
};
}
constructor(props) {
super(props);
this.state = {
selectedPanelId: defaultPanelId
};
this.onHashChange = this.onHashChange.bind(this);
this.selectPanel = this.selectPanel.bind(this);
}
componentDidMount() {
window.addEventListener("hashchange", this.onHashChange);
this.onHashChange();
// aboutdebugging is not connected with a toolbox so we pass -1 as the
// toolbox session id.
this.props.telemetry.toolOpened("aboutdebugging", -1, this);
}
componentWillUnmount() {
window.removeEventListener("hashchange", this.onHashChange);
// aboutdebugging is not connected with a toolbox so we pass -1 as the
// toolbox session id.
this.props.telemetry.toolClosed("aboutdebugging", -1, this);
}
onHashChange() {
this.setState({
selectedPanelId: window.location.hash.substr(1) || defaultPanelId
});
}
selectPanel(panelId) {
window.location.hash = "#" + panelId;
}
render() {
const { client, connect } = this.props;
const { selectedPanelId } = this.state;
const selectPanel = this.selectPanel;
const selectedPanel = panels.find(p => p.id == selectedPanelId);
let panel;
if (selectedPanel) {
panel = selectedPanel.component({ client, connect, id: selectedPanel.id });
} else {
panel = (
dom.div({ className: "error-page" },
dom.h1({ className: "header-name" },
Strings.GetStringFromName("pageNotFound")
),
dom.h4({ className: "error-page-details" },
Strings.formatStringFromName("doesNotExist", [selectedPanelId], 1))
)
);
}
return dom.div({ className: "app" },
PanelMenu({ panels, selectedPanelId, selectPanel }),
dom.div({ className: "main-content" }, panel)
);
}
}
module.exports = AboutDebuggingApp;