From f2c6a7ddb4c4236e1809b4875dd928cda3cf6e8d Mon Sep 17 00:00:00 2001 From: Domagoj Kriskovic Date: Fri, 31 Jan 2025 11:06:15 +0100 Subject: [PATCH] Refactor review panel position-items function (#22969) GitOrigin-RevId: 929e7f2b90ac21cb68117d66ca599120cc765fab --- .../components/review-panel-current-file.tsx | 2 +- .../review-panel-new/utils/position-items.ts | 14 +++----------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/services/web/frontend/js/features/review-panel-new/components/review-panel-current-file.tsx b/services/web/frontend/js/features/review-panel-new/components/review-panel-current-file.tsx index 2b90305bc1..db9933d66b 100644 --- a/services/web/frontend/js/features/review-panel-new/components/review-panel-current-file.tsx +++ b/services/web/frontend/js/features/review-panel-new/components/review-panel-current-file.tsx @@ -241,7 +241,7 @@ const ReviewPanelCurrentFile: FC = () => { if (containerRef.current && docId) { const positioningRes = positionItems( containerRef.current, - previousFocusedItem.current.get(docId) || 0, + previousFocusedItem.current.get(docId), docId ) diff --git a/services/web/frontend/js/features/review-panel-new/utils/position-items.ts b/services/web/frontend/js/features/review-panel-new/utils/position-items.ts index 3db0244adf..26fecc19de 100644 --- a/services/web/frontend/js/features/review-panel-new/utils/position-items.ts +++ b/services/web/frontend/js/features/review-panel-new/utils/position-items.ts @@ -8,7 +8,7 @@ const GAP_BETWEEN_ENTRIES = 4 export const positionItems = debounce( ( element: HTMLDivElement, - previousFocusedItemIndex: number, + previousFocusedItemIndex: number | undefined, docId: string ) => { const items = Array.from( @@ -22,17 +22,9 @@ export const positionItems = debounce( } let activeItemIndex = items.findIndex(item => - item.classList.contains('review-panel-entry-action') + item.classList.contains('review-panel-entry-selected') ) - if (activeItemIndex === -1) { - // if there is no action available - // check if there is manually selected entry - activeItemIndex = items.findIndex(item => - item.classList.contains('review-panel-entry-selected') - ) - } - if (activeItemIndex === -1) { // if entry was not selected manually // check if there is an entry in selection and use that as the focused item @@ -42,7 +34,7 @@ export const positionItems = debounce( } if (activeItemIndex === -1) { - activeItemIndex = previousFocusedItemIndex + activeItemIndex = previousFocusedItemIndex || 0 } const activeItem = items[activeItemIndex]