MessageListHeaderContextMenu.js (1777B)
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 showMenu, 9 } = require("resource://devtools/client/shared/components/menu/utils.js"); 10 const { 11 MESSAGE_HEADERS, 12 } = require("resource://devtools/client/netmonitor/src/constants.js"); 13 const { 14 L10N, 15 } = require("resource://devtools/client/netmonitor/src/utils/l10n.js"); 16 17 class MessageListHeaderContextMenu { 18 constructor(props) { 19 this.props = props; 20 } 21 22 /** 23 * Handle the context menu opening. 24 */ 25 open(event = {}, columns) { 26 const visibleColumns = Object.values(columns).filter(state => state); 27 const onlyOneColumn = visibleColumns.length === 1; 28 29 const columnsToShow = Object.keys(columns); 30 const menuItems = MESSAGE_HEADERS.filter(({ name }) => 31 columnsToShow.includes(name) 32 ).map(({ name: column }) => { 33 const shown = columns[column]; 34 const label = L10N.getStr(`netmonitor.ws.toolbar.${column}`); 35 return { 36 id: `message-list-header-${column}-toggle`, 37 label, 38 type: "checkbox", 39 checked: shown, 40 click: () => this.props.toggleColumn(column), 41 // We don't want to allow hiding the last visible column 42 disabled: onlyOneColumn && shown, 43 }; 44 }); 45 menuItems.push( 46 { type: "separator" }, 47 { 48 id: "message-list-header-reset-columns", 49 label: L10N.getStr("netmonitor.ws.toolbar.resetColumns"), 50 click: () => this.props.resetColumns(), 51 } 52 ); 53 54 showMenu(menuItems, { 55 screenX: event.screenX, 56 screenY: event.screenY, 57 }); 58 } 59 } 60 61 module.exports = MessageListHeaderContextMenu;