Skip to content

Commit cca994c

Browse files
author
Brian Vaughn
authored
DevTools Profiler commit selector wraps around (#17760)
I used to disable the <- and -> buttons when you reached the beginning or end of the profiler data. This can be kind of annoying though when you just want to get to the last commit, and I don't think there's a good reason to enforce it anyway, so I backed that change out. The buttons now wrap around at the beginning or end of the list.
1 parent b05cd61 commit cca994c

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

packages/react-devtools-shared/src/devtools/views/Profiler/SnapshotSelector.js

+10-13
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,20 @@ export default function SnapshotSelector(_: Props) {
9595

9696
const viewNextCommit = useCallback(
9797
() => {
98-
const nextCommitIndex = Math.min(
99-
((selectedFilteredCommitIndex: any): number) + 1,
100-
filteredCommitIndices.length - 1,
101-
);
98+
let nextCommitIndex = ((selectedFilteredCommitIndex: any): number) + 1;
99+
if (nextCommitIndex === filteredCommitIndices.length) {
100+
nextCommitIndex = 0;
101+
}
102102
selectCommitIndex(filteredCommitIndices[nextCommitIndex]);
103103
},
104104
[selectedFilteredCommitIndex, filteredCommitIndices, selectCommitIndex],
105105
);
106106
const viewPrevCommit = useCallback(
107107
() => {
108-
const nextCommitIndex = Math.max(
109-
((selectedFilteredCommitIndex: any): number) - 1,
110-
0,
111-
);
108+
let nextCommitIndex = ((selectedFilteredCommitIndex: any): number) - 1;
109+
if (nextCommitIndex < 0) {
110+
nextCommitIndex = filteredCommitIndices.length - 1;
111+
}
112112
selectCommitIndex(filteredCommitIndices[nextCommitIndex]);
113113
},
114114
[selectedFilteredCommitIndex, filteredCommitIndices, selectCommitIndex],
@@ -141,7 +141,7 @@ export default function SnapshotSelector(_: Props) {
141141
<span className={styles.IndexLabel}>{label}</span>
142142
<Button
143143
className={styles.Button}
144-
disabled={selectedFilteredCommitIndex === 0 || numFilteredCommits === 0}
144+
disabled={numFilteredCommits === 0}
145145
onClick={viewPrevCommit}
146146
title="Select previous commit">
147147
<ButtonIcon type="previous" />
@@ -173,10 +173,7 @@ export default function SnapshotSelector(_: Props) {
173173
</div>
174174
<Button
175175
className={styles.Button}
176-
disabled={
177-
selectedFilteredCommitIndex === null ||
178-
selectedFilteredCommitIndex >= numFilteredCommits - 1
179-
}
176+
disabled={numFilteredCommits === 0}
180177
onClick={viewNextCommit}
181178
title="Select next commit">
182179
<ButtonIcon type="next" />

0 commit comments

Comments
 (0)