ui.js (2278B)
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 createSelector, 9 } = require("resource://devtools/client/shared/vendor/reselect.js"); 10 const { 11 REQUESTS_WATERFALL, 12 } = require("resource://devtools/client/netmonitor/src/constants.js"); 13 14 const EPSILON = 0.001; 15 16 const getWaterfallScale = createSelector( 17 state => state.requests.firstStartedMs, 18 state => state.requests.lastEndedMs, 19 state => state.timingMarkers.firstDocumentDOMContentLoadedTimestamp, 20 state => state.timingMarkers.firstDocumentLoadTimestamp, 21 state => state.ui.waterfallWidth, 22 ( 23 firstStartedMs, 24 lastEndedMs, 25 firstDocumentDOMContentLoadedTimestamp, 26 firstDocumentLoadTimestamp, 27 waterfallWidth 28 ) => { 29 if (firstStartedMs === +Infinity || waterfallWidth === null) { 30 return null; 31 } 32 33 const lastEventMs = Math.max( 34 lastEndedMs, 35 firstDocumentDOMContentLoadedTimestamp, 36 firstDocumentLoadTimestamp 37 ); 38 const longestWidth = lastEventMs - firstStartedMs; 39 40 // Reduce 20px for the last request's requests-list-timings-total 41 return Math.min( 42 Math.max( 43 (waterfallWidth - REQUESTS_WATERFALL.LABEL_WIDTH - 20) / longestWidth, 44 EPSILON 45 ), 46 1 47 ); 48 } 49 ); 50 51 function getVisibleColumns(columns) { 52 return Object.entries(columns).filter(([_, shown]) => shown); 53 } 54 55 const getColumns = createSelector( 56 state => state.ui.columns, 57 state => state.ui.networkDetailsOpen || state.search.panelOpen, 58 (_, hasOverride) => hasOverride, 59 (columns, isSidePanelOpen, hasOverride) => { 60 columns = { ...columns }; 61 const isWaterfallOnly = 62 getVisibleColumns(columns).length === 1 && columns.waterfall; 63 if (isSidePanelOpen && !isWaterfallOnly) { 64 // Remove the Waterfall column if it is not the only column and a side 65 // panel is open. 66 delete columns.waterfall; 67 } 68 69 // Automatically add the override column if any override is currently 70 // configured in the toolbox. 71 columns.override = hasOverride; 72 return columns; 73 } 74 ); 75 76 module.exports = { 77 getColumns, 78 getVisibleColumns, 79 getWaterfallScale, 80 };