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

Commit 3e20a35

Browse files
loganfsmythjasonLaster
authored andcommitted
Render a toggle for original/generated scopes when available. (#5702)
1 parent 497eae4 commit 3e20a35

File tree

4 files changed

+113
-22
lines changed

4 files changed

+113
-22
lines changed

assets/panel/debugger.properties

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,14 @@ scopes.notAvailable=Scopes unavailable
548548
# for when the debugger is not paused.
549549
scopes.notPaused=Not paused
550550

551+
# LOCALIZATION NOTE (scopes.toggleToGenerated): Link displayed in the right
552+
# sidebar scope pane to update the view to show generated scope data.
553+
scopes.toggleToGenerated=Show generated scope
554+
555+
# LOCALIZATION NOTE (scopes.toggleToOriginal): Link displayed in the right
556+
# sidebar scope pane to update the view to show original scope data.
557+
scopes.toggleToOriginal=Show original scope
558+
551559
# LOCALIZATION NOTE (scopes.block): Refers to a block of code in
552560
# the scopes pane when the debugger is paused.
553561
scopes.block=Block

src/components/SecondaryPanes/Scopes.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,14 @@
4040
.scopes-list .function-signature {
4141
display: inline-block;
4242
}
43+
44+
.scopes-list .scope-type-toggle {
45+
text-align: center;
46+
padding-top: 10px;
47+
padding-bottom: 10px;
48+
}
49+
50+
.scopes-list .scope-type-toggle a {
51+
/* Override color so that the link doesn't turn purple */
52+
color: var(--theme-body-color);
53+
}

src/components/SecondaryPanes/Scopes.js

Lines changed: 74 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import { createObjectClient } from "../../client/firefox";
1212
import {
1313
getSelectedSource,
1414
getSelectedFrame,
15-
getFrameScope,
15+
getGeneratedFrameScope,
16+
getOriginalFrameScope,
1617
isPaused as getIsPaused,
1718
getPauseReason
1819
} from "../../selectors";
@@ -27,48 +28,78 @@ import "./Scopes.css";
2728
type Props = {
2829
isPaused: Pause,
2930
selectedFrame: Object,
30-
frameScopes: Object | null,
31+
generatedFrameScopes: Object,
32+
originalFrameScopes: Object | null,
3133
isLoading: boolean,
3234
why: Why
3335
};
3436

3537
type State = {
36-
scopes: ?(NamedValue[])
38+
originalScopes: ?(NamedValue[]),
39+
generatedScopes: ?(NamedValue[]),
40+
showOriginal: boolean
3741
};
3842

3943
class Scopes extends PureComponent<Props, State> {
4044
constructor(props: Props, ...args) {
41-
const { why, selectedFrame, frameScopes } = props;
45+
const {
46+
why,
47+
selectedFrame,
48+
originalFrameScopes,
49+
generatedFrameScopes
50+
} = props;
4251

4352
super(props, ...args);
4453

4554
this.state = {
46-
scopes: getScopes(why, selectedFrame, frameScopes)
55+
originalScopes: getScopes(why, selectedFrame, originalFrameScopes),
56+
generatedScopes: getScopes(why, selectedFrame, generatedFrameScopes),
57+
showOriginal: true
4758
};
4859
}
4960

5061
componentWillReceiveProps(nextProps) {
51-
const { isPaused, selectedFrame, frameScopes } = this.props;
62+
const {
63+
isPaused,
64+
selectedFrame,
65+
originalFrameScopes,
66+
generatedFrameScopes
67+
} = this.props;
5268
const isPausedChanged = isPaused !== nextProps.isPaused;
5369
const selectedFrameChanged = selectedFrame !== nextProps.selectedFrame;
54-
const frameScopesChanged = frameScopes !== nextProps.frameScopes;
55-
56-
if (isPausedChanged || selectedFrameChanged || frameScopesChanged) {
70+
const originalFrameScopesChanged =
71+
originalFrameScopes !== nextProps.originalFrameScopes;
72+
const generatedFrameScopesChanged =
73+
generatedFrameScopes !== nextProps.generatedFrameScopes;
74+
75+
if (
76+
isPausedChanged ||
77+
selectedFrameChanged ||
78+
originalFrameScopesChanged ||
79+
generatedFrameScopesChanged
80+
) {
5781
this.setState({
58-
scopes: getScopes(
82+
originalScopes: getScopes(
83+
nextProps.why,
84+
nextProps.selectedFrame,
85+
nextProps.originalFrameScopes
86+
),
87+
generatedScopes: getScopes(
5988
nextProps.why,
6089
nextProps.selectedFrame,
61-
nextProps.frameScopes
90+
nextProps.generatedFrameScopes
6291
)
6392
});
6493
}
6594
}
6695

6796
render() {
6897
const { isPaused, isLoading } = this.props;
69-
const { scopes } = this.state;
98+
const { originalScopes, generatedScopes, showOriginal } = this.state;
99+
100+
const scopes = (showOriginal && originalScopes) || generatedScopes;
70101

71-
if (scopes) {
102+
if (scopes && !isLoading) {
72103
return (
73104
<div className="pane scopes-list">
74105
<ObjectInspector
@@ -80,6 +111,21 @@ class Scopes extends PureComponent<Props, State> {
80111
dimTopLevelWindow={true}
81112
createObjectClient={grip => createObjectClient(grip)}
82113
/>
114+
{originalScopes ? (
115+
<div className="scope-type-toggle">
116+
<a
117+
href=""
118+
onClick={e => {
119+
e.preventDefault();
120+
this.setState({ showOriginal: !showOriginal });
121+
}}
122+
>
123+
{showOriginal
124+
? L10N.getStr("scopes.toggleToGenerated")
125+
: L10N.getStr("scopes.toggleToOriginal")}
126+
</a>
127+
</div>
128+
) : null}
83129
</div>
84130
);
85131
}
@@ -106,18 +152,30 @@ export default connect(
106152
const selectedFrame = getSelectedFrame(state);
107153
const selectedSource = getSelectedSource(state);
108154

109-
const { scope: frameScopes, pending } = getFrameScope(
155+
const {
156+
scope: originalFrameScopes,
157+
pending: originalPending
158+
} = getOriginalFrameScope(
110159
state,
111160
selectedSource && selectedSource.get("id"),
112161
selectedFrame && selectedFrame.id
113162
) || { scope: null, pending: false };
114163

164+
const {
165+
scope: generatedFrameScopes,
166+
pending: generatedPending
167+
} = getGeneratedFrameScope(state, selectedFrame && selectedFrame.id) || {
168+
scope: null,
169+
pending: false
170+
};
171+
115172
return {
116173
selectedFrame,
117174
isPaused: getIsPaused(state),
118-
isLoading: pending,
175+
isLoading: generatedPending || originalPending,
119176
why: getPauseReason(state),
120-
frameScopes: frameScopes
177+
originalFrameScopes,
178+
generatedFrameScopes
121179
};
122180
},
123181
dispatch => bindActionCreators(actions, dispatch)

src/reducers/pause.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -326,11 +326,7 @@ export function getGeneratedFrameScope(state: OuterState, frameId: ?string) {
326326
return getFrameScopes(state).generated[frameId];
327327
}
328328

329-
export function getFrameScopes(state: OuterState) {
330-
return state.pause.frameScopes;
331-
}
332-
333-
export function getFrameScope(
329+
export function getOriginalFrameScope(
334330
state: OuterState,
335331
sourceId: ?SourceId,
336332
frameId: ?string
@@ -349,7 +345,25 @@ export function getFrameScope(
349345
return original;
350346
}
351347

352-
return getFrameScopes(state).generated[frameId];
348+
return null;
349+
}
350+
351+
export function getFrameScopes(state: OuterState) {
352+
return state.pause.frameScopes;
353+
}
354+
355+
export function getFrameScope(
356+
state: OuterState,
357+
sourceId: ?SourceId,
358+
frameId: ?string
359+
): ?{
360+
pending: boolean,
361+
+scope: OriginalScope | Scope
362+
} {
363+
return (
364+
getOriginalFrameScope(state, sourceId, frameId) ||
365+
getGeneratedFrameScope(state, frameId)
366+
);
353367
}
354368

355369
export function getSelectedScope(state: OuterState) {

0 commit comments

Comments
 (0)