StatusBar.js (2920B)
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 Component, 9 } = require("resource://devtools/client/shared/vendor/react.mjs"); 10 const PropTypes = require("resource://devtools/client/shared/vendor/react-prop-types.mjs"); 11 const dom = require("resource://devtools/client/shared/vendor/react-dom-factories.js"); 12 const { 13 connect, 14 } = require("resource://devtools/client/shared/vendor/react-redux.js"); 15 const { 16 getSearchStatus, 17 getSearchResultCount, 18 getSearchResourceCount, 19 } = require("resource://devtools/client/netmonitor/src/selectors/index.js"); 20 const { PluralForm } = require("resource://devtools/shared/plural-form.js"); 21 const { 22 L10N, 23 } = require("resource://devtools/client/netmonitor/src/utils/l10n.js"); 24 const { div, span } = dom; 25 const { 26 SEARCH_STATUS, 27 } = require("resource://devtools/client/netmonitor/src/constants.js"); 28 29 /** 30 * Displays the number of lines found for results and resource count (files) 31 */ 32 class StatusBar extends Component { 33 static get propTypes() { 34 return { 35 status: PropTypes.string, 36 resultsCount: PropTypes.string, 37 resourceCount: PropTypes.string, 38 }; 39 } 40 41 getSearchStatusDoneLabel(lines, files) { 42 const matchingLines = PluralForm.get( 43 lines, 44 L10N.getStr("netmonitor.search.status.labels.matchingLines") 45 ).replace("#1", lines); 46 const matchingFiles = PluralForm.get( 47 files, 48 L10N.getStr("netmonitor.search.status.labels.fileCount") 49 ).replace("#1", files); 50 51 return L10N.getFormatStr( 52 "netmonitor.search.status.labels.done", 53 matchingLines, 54 matchingFiles 55 ); 56 } 57 58 renderStatus() { 59 const { status, resultsCount, resourceCount } = this.props; 60 61 switch (status) { 62 case SEARCH_STATUS.FETCHING: 63 return L10N.getStr("netmonitor.search.status.labels.fetching"); 64 case SEARCH_STATUS.DONE: 65 return this.getSearchStatusDoneLabel(resultsCount, resourceCount); 66 case SEARCH_STATUS.ERROR: 67 return L10N.getStr("netmonitor.search.status.labels.error"); 68 case SEARCH_STATUS.CANCELED: 69 return L10N.getStr("netmonitor.search.status.labels.canceled"); 70 default: 71 return ""; 72 } 73 } 74 75 render() { 76 const { status } = this.props; 77 return div( 78 { className: "devtools-toolbar devtools-toolbar-bottom" }, 79 div( 80 { 81 className: "status-bar-label", 82 title: this.renderStatus(), 83 }, 84 this.renderStatus(), 85 status === SEARCH_STATUS.FETCHING 86 ? span({ className: "img loader" }) 87 : "" 88 ) 89 ); 90 } 91 } 92 93 module.exports = connect(state => ({ 94 status: getSearchStatus(state), 95 resultsCount: getSearchResultCount(state), 96 resourceCount: getSearchResourceCount(state), 97 }))(StatusBar);