/* 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 . */ import React, { Component } from "devtools/client/shared/vendor/react"; import { connect } from "devtools/client/shared/vendor/react-redux"; import PropTypes from "devtools/client/shared/vendor/react-prop-types"; import FrameComponent from "./Frame"; import Group from "./Group"; import actions from "../../../actions/index"; import { collapseFrames } from "../../../utils/pause/frames/index"; import { getFrameworkGroupingState, getSelectedFrame, getCurrentThreadFrames, getCurrentThread, getShouldSelectOriginalLocation, } from "../../../selectors/index"; const NUM_FRAMES_SHOWN = 7; class Frames extends Component { constructor(props) { super(props); this.state = { showAllFrames: !!props.disableFrameTruncate, }; } static get propTypes() { return { disableContextMenu: PropTypes.bool.isRequired, disableFrameTruncate: PropTypes.bool.isRequired, displayFullUrl: PropTypes.bool.isRequired, frames: PropTypes.array.isRequired, frameworkGroupingOn: PropTypes.bool.isRequired, getFrameTitle: PropTypes.func, panel: PropTypes.oneOf(["debugger", "webconsole"]).isRequired, selectFrame: PropTypes.func.isRequired, selectLocation: PropTypes.func, selectedFrame: PropTypes.object, showFrameContextMenu: PropTypes.func, shouldDisplayOriginalLocation: PropTypes.bool, }; } shouldComponentUpdate(nextProps, nextState) { const { frames, selectedFrame, frameworkGroupingOn, shouldDisplayOriginalLocation, } = this.props; const { showAllFrames } = this.state; return ( frames !== nextProps.frames || selectedFrame !== nextProps.selectedFrame || showAllFrames !== nextState.showAllFrames || frameworkGroupingOn !== nextProps.frameworkGroupingOn || shouldDisplayOriginalLocation !== nextProps.shouldDisplayOriginalLocation ); } toggleFramesDisplay = () => { this.setState(prevState => ({ showAllFrames: !prevState.showAllFrames, })); }; collapseFrames(frames) { const { frameworkGroupingOn } = this.props; if (!frameworkGroupingOn) { return frames; } return collapseFrames(frames); } truncateFrames(frames) { const numFramesToShow = this.state.showAllFrames ? frames.length : NUM_FRAMES_SHOWN; return frames.slice(0, numFramesToShow); } renderFrames(frames) { const { selectFrame, selectLocation, selectedFrame, displayFullUrl, getFrameTitle, disableContextMenu, panel, shouldDisplayOriginalLocation, showFrameContextMenu, } = this.props; const framesOrGroups = this.truncateFrames(this.collapseFrames(frames)); // We're not using a