Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit 856d469

Browse files
darkwingjasonLaster
authored andcommitted
Move BreakPointItem elements to their own rendering functions (#5905)
* Move BreakPointItem elements to their own rendering functions * Rename the BreakpointItem component * Grr lint * Unify breakpoint text retrieval for conditional
1 parent a4e9946 commit 856d469

File tree

2 files changed

+65
-36
lines changed

2 files changed

+65
-36
lines changed

src/components/SecondaryPanes/BreakpointItem.js renamed to src/components/SecondaryPanes/Breakpoint.js

Lines changed: 55 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@ function getBreakpointLocation(source, line, column) {
3333
return bpLocation;
3434
}
3535

36-
class BreakpointItem extends Component<Props> {
36+
class Breakpoint extends Component<Props> {
3737
editor: SourceEditor;
3838

3939
componentDidMount() {
4040
this.setupEditor();
4141
}
42+
4243
componentDidUpdate() {
4344
this.setupEditor();
4445
}
@@ -63,13 +64,17 @@ class BreakpointItem extends Component<Props> {
6364
);
6465
}
6566

66-
setupEditor() {
67+
getBreakpointText() {
6768
const { breakpoint } = this.props;
69+
return breakpoint.condition || breakpoint.text;
70+
}
71+
72+
setupEditor() {
6873
if (this.editor) {
6974
return;
7075
}
7176

72-
this.editor = createEditor(breakpoint.text);
77+
this.editor = createEditor(this.getBreakpointText());
7378

7479
// disables the default search shortcuts
7580
// $FlowIgnore
@@ -87,18 +92,52 @@ class BreakpointItem extends Component<Props> {
8792
}
8893
}
8994

95+
renderCheckbox() {
96+
const { onChange, breakpoint } = this.props;
97+
const { disabled } = breakpoint;
98+
99+
return (
100+
<input
101+
type="checkbox"
102+
className="breakpoint-checkbox"
103+
checked={!disabled}
104+
onChange={onChange}
105+
onClick={ev => ev.stopPropagation()}
106+
/>
107+
);
108+
}
109+
110+
renderText() {
111+
const text = this.getBreakpointText();
112+
113+
return (
114+
<label className="breakpoint-label" title={text}>
115+
{text}
116+
</label>
117+
);
118+
}
119+
120+
renderLineClose() {
121+
const { breakpoint, onCloseClick } = this.props;
122+
const { line, column } = breakpoint.location;
123+
124+
return (
125+
<div className="breakpoint-line-close">
126+
<div className="breakpoint-line">
127+
{getBreakpointLocation(breakpoint.source, line, column)}
128+
</div>
129+
<CloseButton
130+
handleClick={onCloseClick}
131+
tooltip={L10N.getStr("breakpoints.removeBreakpointTooltip")}
132+
/>
133+
</div>
134+
);
135+
}
136+
90137
render() {
91-
const {
92-
breakpoint,
93-
onClick,
94-
onChange,
95-
onContextMenu,
96-
onCloseClick
97-
} = this.props;
138+
const { breakpoint, onClick, onContextMenu } = this.props;
98139

99140
const locationId = breakpoint.locationId;
100-
const line = breakpoint.location.line;
101-
const column = breakpoint.location.column;
102141
const isCurrentlyPaused = breakpoint.isCurrentlyPaused;
103142
const isDisabled = breakpoint.disabled;
104143
const isConditional = !!breakpoint.condition;
@@ -115,28 +154,12 @@ class BreakpointItem extends Component<Props> {
115154
onClick={onClick}
116155
onContextMenu={onContextMenu}
117156
>
118-
<input
119-
type="checkbox"
120-
className="breakpoint-checkbox"
121-
checked={!isDisabled}
122-
onChange={onChange}
123-
onClick={ev => ev.stopPropagation()}
124-
/>
125-
<label className="breakpoint-label" title={breakpoint.text}>
126-
{breakpoint.text}
127-
</label>
128-
<div className="breakpoint-line-close">
129-
<div className="breakpoint-line">
130-
{getBreakpointLocation(breakpoint.source, line, column)}
131-
</div>
132-
<CloseButton
133-
handleClick={onCloseClick}
134-
tooltip={L10N.getStr("breakpoints.removeBreakpointTooltip")}
135-
/>
136-
</div>
157+
{this.renderCheckbox()}
158+
{this.renderText()}
159+
{this.renderLineClose()}
137160
</div>
138161
);
139162
}
140163
}
141164

142-
export default BreakpointItem;
165+
export default Breakpoint;

src/components/SecondaryPanes/Breakpoints.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import * as I from "immutable";
1111
import { createSelector } from "reselect";
1212
import { groupBy, sortBy } from "lodash";
1313

14-
import BreakpointItem from "./BreakpointItem";
14+
import Breakpoint from "./Breakpoint";
1515

1616
import actions from "../../actions";
1717
import { getFilename } from "../../utils/source";
@@ -26,11 +26,17 @@ import { isInterrupted } from "../../utils/pause";
2626
import { makeLocationId } from "../../utils/breakpoint";
2727
import showContextMenu from "./BreakpointsContextMenu";
2828

29-
import type { Breakpoint, Location, Source, Frame, Why } from "../../types";
29+
import type {
30+
Breakpoint as BreakpointType,
31+
Location,
32+
Source,
33+
Frame,
34+
Why
35+
} from "../../types";
3036

3137
import "./Breakpoints.css";
3238

33-
export type LocalBreakpoint = Breakpoint & {
39+
export type LocalBreakpoint = BreakpointType & {
3440
location: Location,
3541
isCurrentlyPaused: boolean,
3642
locationId: string,
@@ -101,7 +107,7 @@ class Breakpoints extends Component<Props> {
101107

102108
renderBreakpoint(breakpoint) {
103109
return (
104-
<BreakpointItem
110+
<Breakpoint
105111
key={breakpoint.locationId}
106112
breakpoint={breakpoint}
107113
onClick={() => this.selectBreakpoint(breakpoint)}

0 commit comments

Comments
 (0)