Explorar o código

Refactor review panel position-items function (#22969)

GitOrigin-RevId: 929e7f2b90ac21cb68117d66ca599120cc765fab
Domagoj Kriskovic hai 1 ano
pai
achega
f2c6a7ddb4

+ 1 - 1
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
       )
 

+ 3 - 11
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]