Refactor review panel position-items function (#22969)

GitOrigin-RevId: 929e7f2b90ac21cb68117d66ca599120cc765fab
This commit is contained in:
Domagoj Kriskovic
2025-01-31 11:06:15 +01:00
committed by Copybot
parent 97562c0042
commit f2c6a7ddb4
2 changed files with 4 additions and 12 deletions
@@ -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
)
@@ -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]