/* 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, { PureComponent } from "react";
import PropTypes from "prop-types";
import { connect } from "../../../utils/connect";
import actions from "../../../actions";
import {
getTruncatedFileName,
getDisplayPath,
getSourceQueryString,
getFileURL,
} from "../../../utils/source";
import { createLocation } from "../../../utils/location";
import {
getBreakpointsForSource,
getContext,
getFirstSourceActorForGeneratedSource,
} from "../../../selectors";
import SourceIcon from "../../shared/SourceIcon";
import showContextMenu from "./BreakpointHeadingsContextMenu";
class BreakpointHeading extends PureComponent {
static get propTypes() {
return {
cx: PropTypes.object.isRequired,
sources: PropTypes.array.isRequired,
source: PropTypes.object.isRequired,
firstSourceActor: PropTypes.object,
selectSource: PropTypes.func.isRequired,
};
}
onContextMenu = e => {
showContextMenu({ ...this.props, contextMenuEvent: e });
};
render() {
const { cx, sources, source, selectSource } = this.props;
const path = getDisplayPath(source, sources);
const query = getSourceQueryString(source);
return (
selectSource(cx, source)}
onContextMenu={this.onContextMenu}
>
["file", "javascript"].includes(icon) ? null : icon
}
/>
{getTruncatedFileName(source, query)}
{path && {`../${path}/..`}}
);
}
}
const mapStateToProps = (state, { source }) => ({
cx: getContext(state),
breakpointsForSource: getBreakpointsForSource(state, source.id),
firstSourceActor: getFirstSourceActorForGeneratedSource(state, source.id),
});
export default connect(mapStateToProps, {
selectSource: actions.selectSource,
enableBreakpointsInSource: actions.enableBreakpointsInSource,
disableBreakpointsInSource: actions.disableBreakpointsInSource,
removeBreakpointsInSource: actions.removeBreakpointsInSource,
})(BreakpointHeading);