From cca994c6a1f13dd0b64ad0a909b5209b10cc8609 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Thu, 2 Jan 2020 14:44:07 -0800 Subject: [PATCH] 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. --- .../views/Profiler/SnapshotSelector.js | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/packages/react-devtools-shared/src/devtools/views/Profiler/SnapshotSelector.js b/packages/react-devtools-shared/src/devtools/views/Profiler/SnapshotSelector.js index 5d9424211af8f..41979cee6b9f5 100644 --- a/packages/react-devtools-shared/src/devtools/views/Profiler/SnapshotSelector.js +++ b/packages/react-devtools-shared/src/devtools/views/Profiler/SnapshotSelector.js @@ -95,20 +95,20 @@ export default function SnapshotSelector(_: Props) { const viewNextCommit = useCallback( () => { - const nextCommitIndex = Math.min( - ((selectedFilteredCommitIndex: any): number) + 1, - filteredCommitIndices.length - 1, - ); + let nextCommitIndex = ((selectedFilteredCommitIndex: any): number) + 1; + if (nextCommitIndex === filteredCommitIndices.length) { + nextCommitIndex = 0; + } selectCommitIndex(filteredCommitIndices[nextCommitIndex]); }, [selectedFilteredCommitIndex, filteredCommitIndices, selectCommitIndex], ); const viewPrevCommit = useCallback( () => { - const nextCommitIndex = Math.max( - ((selectedFilteredCommitIndex: any): number) - 1, - 0, - ); + let nextCommitIndex = ((selectedFilteredCommitIndex: any): number) - 1; + if (nextCommitIndex < 0) { + nextCommitIndex = filteredCommitIndices.length - 1; + } selectCommitIndex(filteredCommitIndices[nextCommitIndex]); }, [selectedFilteredCommitIndex, filteredCommitIndices, selectCommitIndex], @@ -141,7 +141,7 @@ export default function SnapshotSelector(_: Props) { {label}