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

Commit 8fc9fd3

Browse files
darkwingjasonLaster
authored andcommitted
Add + icon for adding watch expressions (#5916)
1 parent 93124c4 commit 8fc9fd3

File tree

6 files changed

+69
-62
lines changed

6 files changed

+69
-62
lines changed

src/components/SecondaryPanes/Expressions.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
}
3838

3939
.input-expression::placeholder {
40-
text-align: center;
4140
font-style: italic;
4241
color: var(--theme-comment);
4342
}
@@ -54,6 +53,7 @@
5453
}
5554
.expression-input-container {
5655
display: flex;
56+
border: 1px solid var(--theme-highlight-blue);
5757
}
5858

5959
.expression-container {

src/components/SecondaryPanes/Expressions.js

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ type Props = {
3434
evaluateExpressions: () => void,
3535
updateExpression: (input: string, expression: Expression) => void,
3636
deleteExpression: (expression: Expression) => void,
37-
openLink: (url: string) => void
37+
openLink: (url: string) => void,
38+
showInput: boolean,
39+
onExpressionAdded: () => void
3840
};
3941

4042
class Expressions extends Component<Props, State> {
@@ -46,7 +48,12 @@ class Expressions extends Component<Props, State> {
4648

4749
constructor(props: Props) {
4850
super(props);
49-
this.state = { editing: false, editIndex: -1, inputValue: "" };
51+
52+
this.state = {
53+
editing: false,
54+
editIndex: -1,
55+
inputValue: ""
56+
};
5057
}
5158

5259
componentDidMount() {
@@ -71,12 +78,14 @@ class Expressions extends Component<Props, State> {
7178

7279
shouldComponentUpdate(nextProps, nextState) {
7380
const { editing, inputValue } = this.state;
74-
const { expressions, expressionError } = this.props;
81+
const { expressions, expressionError, showInput } = this.props;
82+
7583
return (
7684
expressions !== nextProps.expressions ||
7785
expressionError !== nextProps.expressionError ||
7886
editing !== nextState.editing ||
79-
inputValue !== nextState.inputValue
87+
inputValue !== nextState.inputValue ||
88+
nextProps.showInput !== showInput
8089
);
8190
}
8291

@@ -115,6 +124,15 @@ class Expressions extends Component<Props, State> {
115124
}
116125
};
117126

127+
hideInput = () => {
128+
this.props.onExpressionAdded();
129+
};
130+
131+
onBlur() {
132+
this.clear();
133+
this.hideInput();
134+
}
135+
118136
handleExistingSubmit = async (
119137
e: SyntheticEvent<HTMLFormElement>,
120138
expression: Expression
@@ -123,6 +141,7 @@ class Expressions extends Component<Props, State> {
123141
e.stopPropagation();
124142

125143
this.props.updateExpression(this.state.inputValue, expression);
144+
this.hideInput();
126145
};
127146

128147
handleNewSubmit = async (e: SyntheticEvent<HTMLFormElement>) => {
@@ -137,6 +156,10 @@ class Expressions extends Component<Props, State> {
137156
editIndex: -1,
138157
inputValue: this.props.expressionError ? inputValue : ""
139158
});
159+
160+
if (!this.props.expressionError) {
161+
this.hideInput();
162+
}
140163
};
141164

142165
renderExpression = (expression: Expression, index: number) => {
@@ -202,8 +225,9 @@ class Expressions extends Component<Props, State> {
202225
type="text"
203226
placeholder={placeholder}
204227
onChange={this.handleChange}
205-
onBlur={this.clear}
228+
onBlur={this.hideInput}
206229
onKeyDown={this.handleKeyDown}
230+
autoFocus="true"
207231
value={!editing ? inputValue : ""}
208232
/>
209233
<input type="submit" style={{ display: "none" }} />
@@ -240,11 +264,12 @@ class Expressions extends Component<Props, State> {
240264
}
241265

242266
render() {
243-
const { expressions } = this.props;
267+
const { expressions, showInput } = this.props;
268+
244269
return (
245270
<ul className="pane expressions-list">
246271
{expressions.map(this.renderExpression)}
247-
{this.renderNewExpressionInput()}
272+
{showInput && this.renderNewExpressionInput()}
248273
</ul>
249274
);
250275
}

src/components/SecondaryPanes/index.js

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ function debugBtn(onClick, type, className, tooltip) {
6868
);
6969
}
7070

71+
type State = {
72+
showExpressionsInput: boolean
73+
};
74+
7175
type Props = {
7276
extra: Object,
7377
evaluateExpressions: Function,
@@ -86,7 +90,19 @@ type Props = {
8690
workers: WorkersList
8791
};
8892

89-
class SecondaryPanes extends Component<Props> {
93+
class SecondaryPanes extends Component<Props, State> {
94+
constructor(props: Props) {
95+
super(props);
96+
97+
this.state = {
98+
showExpressionsInput: false
99+
};
100+
}
101+
102+
onExpressionAdded = () => {
103+
this.setState({ showExpressionsInput: false });
104+
};
105+
90106
renderBreakpointsToggle() {
91107
const {
92108
toggleAllBreakpoints,
@@ -138,6 +154,15 @@ class SecondaryPanes extends Component<Props> {
138154
"refresh",
139155
"refresh",
140156
L10N.getStr("watchExpressions.refreshButton")
157+
),
158+
debugBtn(
159+
evt => {
160+
evt.stopPropagation();
161+
this.setState({ showExpressionsInput: true });
162+
},
163+
"plus",
164+
"plus",
165+
L10N.getStr("expressions.placeholder")
141166
)
142167
];
143168
}
@@ -173,7 +198,12 @@ class SecondaryPanes extends Component<Props> {
173198
header: L10N.getStr("watchExpressions.header"),
174199
className: "watch-expressions-pane",
175200
buttons: this.watchExpressionHeaderButtons(),
176-
component: <Expressions />,
201+
component: (
202+
<Expressions
203+
showInput={this.state.showExpressionsInput}
204+
onExpressionAdded={this.onExpressionAdded}
205+
/>
206+
),
177207
opened: prefs.expressionsVisible,
178208
onToggle: opened => {
179209
prefs.expressionsVisible = opened;

src/components/SecondaryPanes/tests/__snapshots__/Expressions.spec.js.snap

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -78,32 +78,6 @@ exports[`Expressions should always have unique keys 1`] = `
7878
</div>
7979
</div>
8080
</li>
81-
<li
82-
className="expression-input-container"
83-
>
84-
<form
85-
className="expression-input-form"
86-
onSubmit={[Function]}
87-
>
88-
<input
89-
className="input-expression"
90-
onBlur={[Function]}
91-
onChange={[Function]}
92-
onKeyDown={[Function]}
93-
placeholder="Add watch expression"
94-
type="text"
95-
value=""
96-
/>
97-
<input
98-
style={
99-
Object {
100-
"display": "none",
101-
}
102-
}
103-
type="submit"
104-
/>
105-
</form>
106-
</li>
10781
</ul>
10882
`;
10983

@@ -185,31 +159,5 @@ exports[`Expressions should render 1`] = `
185159
</div>
186160
</div>
187161
</li>
188-
<li
189-
className="expression-input-container"
190-
>
191-
<form
192-
className="expression-input-form"
193-
onSubmit={[Function]}
194-
>
195-
<input
196-
className="input-expression"
197-
onBlur={[Function]}
198-
onChange={[Function]}
199-
onKeyDown={[Function]}
200-
placeholder="Add watch expression"
201-
type="text"
202-
value=""
203-
/>
204-
<input
205-
style={
206-
Object {
207-
"display": "none",
208-
}
209-
}
210-
type="submit"
211-
/>
212-
</form>
213-
</li>
214162
</ul>
215163
`;

src/test/mochitest/browser_dbg-expressions-error.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111

1212
const expressionSelectors = {
13+
plusIcon: ".watch-expressions-pane button.plus",
1314
input: "input.input-expression"
1415
};
1516

@@ -22,6 +23,7 @@ function getValue(dbg, index) {
2223
}
2324

2425
async function addExpression(dbg, input) {
26+
findElementWithSelector(dbg, expressionSelectors.plusIcon).click();
2527
const evaluation = waitForDispatch(dbg, "EVALUATE_EXPRESSION");
2628
findElementWithSelector(dbg, expressionSelectors.input).focus();
2729
type(dbg, input);

src/test/mochitest/browser_dbg-expressions.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111

1212
const expressionSelectors = {
13+
plusIcon: ".watch-expressions-pane button.plus",
1314
input: "input.input-expression"
1415
};
1516

@@ -33,6 +34,7 @@ function assertEmptyValue(dbg, index) {
3334

3435
async function addExpression(dbg, input) {
3536
info("Adding an expression");
37+
findElementWithSelector(dbg, expressionSelectors.plusIcon).click();
3638
findElementWithSelector(dbg, expressionSelectors.input).focus();
3739
type(dbg, input);
3840
pressKey(dbg, "Enter");

0 commit comments

Comments
 (0)