StatusBar.js (5459B)
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/. */ 4 5 "use strict"; 6 7 const { 8 createFactory, 9 Component, 10 } = require("resource://devtools/client/shared/vendor/react.mjs"); 11 const PropTypes = require("resource://devtools/client/shared/vendor/react-prop-types.mjs"); 12 const dom = require("resource://devtools/client/shared/vendor/react-dom-factories.js"); 13 const { 14 connect, 15 } = require("resource://devtools/client/shared/vendor/react-redux.js"); 16 const FluentReact = require("resource://devtools/client/shared/vendor/fluent-react.js"); 17 const Localized = createFactory(FluentReact.Localized); 18 const Actions = require("resource://devtools/client/netmonitor/src/actions/index.js"); 19 const { 20 getDisplayedRequestsSummary, 21 getDisplayedTimingMarker, 22 } = require("resource://devtools/client/netmonitor/src/selectors/index.js"); 23 const { 24 getFormattedSize, 25 getFormattedTime, 26 } = require("resource://devtools/client/netmonitor/src/utils/format-utils.js"); 27 const { 28 propertiesEqual, 29 } = require("resource://devtools/client/netmonitor/src/utils/request-utils.js"); 30 31 const { button, div } = dom; 32 33 const UPDATED_SUMMARY_PROPS = ["count", "contentSize", "transferredSize", "ms"]; 34 35 const UPDATED_TIMING_PROPS = ["DOMContentLoaded", "load"]; 36 37 /** 38 * Status Bar component 39 * Displays the summary of total size and transferred size by all requests 40 * Also displays different timing markers 41 */ 42 class StatusBar extends Component { 43 static get propTypes() { 44 return { 45 connector: PropTypes.object.isRequired, 46 openStatistics: PropTypes.func.isRequired, 47 summary: PropTypes.object.isRequired, 48 timingMarkers: PropTypes.object.isRequired, 49 }; 50 } 51 52 shouldComponentUpdate(nextProps) { 53 const { summary, timingMarkers } = this.props; 54 return ( 55 !propertiesEqual(UPDATED_SUMMARY_PROPS, summary, nextProps.summary) || 56 !propertiesEqual( 57 UPDATED_TIMING_PROPS, 58 timingMarkers, 59 nextProps.timingMarkers 60 ) 61 ); 62 } 63 64 render() { 65 const { openStatistics, summary, timingMarkers, connector } = this.props; 66 const { count, contentSize, transferredSize, ms } = summary; 67 const { DOMContentLoaded, load } = timingMarkers; 68 const toolbox = connector.getToolbox(); 69 70 return div( 71 { className: "devtools-toolbar devtools-toolbar-bottom" }, 72 !toolbox.isBrowserToolbox && 73 !toolbox.commands.descriptorFront.isWebExtensionDescriptor 74 ? Localized( 75 { 76 id: "network-menu-summary-tooltip-perf", 77 attrs: { title: true }, 78 }, 79 button({ 80 className: "devtools-button requests-list-network-summary-button", 81 onClick: openStatistics, 82 }) 83 ) 84 : null, 85 Localized( 86 { 87 id: "network-menu-summary-tooltip-requests-count", 88 attrs: { title: true }, 89 }, 90 div( 91 { 92 className: "status-bar-label requests-list-network-summary-count", 93 }, 94 Localized({ 95 id: "network-menu-summary-requests-count", 96 $requestCount: count, 97 }) 98 ) 99 ), 100 count !== 0 && 101 Localized( 102 { 103 id: "network-menu-summary-tooltip-transferred", 104 attrs: { title: true }, 105 }, 106 div( 107 { 108 className: 109 "status-bar-label requests-list-network-summary-transfer", 110 }, 111 Localized({ 112 id: "network-menu-summary-transferred", 113 $formattedContentSize: getFormattedSize(contentSize), 114 $formattedTransferredSize: getFormattedSize(transferredSize), 115 }) 116 ) 117 ), 118 count !== 0 && 119 Localized( 120 { 121 id: "network-menu-summary-tooltip-finish", 122 attrs: { title: true }, 123 }, 124 div( 125 { 126 className: 127 "status-bar-label requests-list-network-summary-finish", 128 }, 129 Localized({ 130 id: "network-menu-summary-finish", 131 $formattedTime: getFormattedTime(ms), 132 }) 133 ) 134 ), 135 DOMContentLoaded > -1 && 136 Localized( 137 { 138 id: "network-menu-summary-tooltip-domcontentloaded", 139 attrs: { title: true }, 140 }, 141 div( 142 { 143 className: "status-bar-label dom-content-loaded", 144 }, 145 `DOMContentLoaded: ${getFormattedTime(DOMContentLoaded)}` 146 ) 147 ), 148 load > -1 && 149 Localized( 150 { 151 id: "network-menu-summary-tooltip-load", 152 attrs: { title: true }, 153 }, 154 div( 155 { 156 className: "status-bar-label load", 157 }, 158 `load: ${getFormattedTime(load)}` 159 ) 160 ) 161 ); 162 } 163 } 164 165 module.exports = connect( 166 state => ({ 167 summary: getDisplayedRequestsSummary(state), 168 timingMarkers: { 169 DOMContentLoaded: getDisplayedTimingMarker( 170 state, 171 "firstDocumentDOMContentLoadedTimestamp" 172 ), 173 load: getDisplayedTimingMarker(state, "firstDocumentLoadTimestamp"), 174 }, 175 }), 176 (dispatch, props) => ({ 177 openStatistics: () => 178 dispatch(Actions.openStatistics(props.connector, true)), 179 }) 180 )(StatusBar);