Skip to content

Commit

Permalink
use {history_content_type}-{id} to key unique items in panel refs
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedhamidawan committed Mar 11, 2024
1 parent 8b778a5 commit 84b6272
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions client/src/components/History/CurrentHistory/HistoryPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const querySelectionBreak = ref(false);
const dragTarget = ref<EventTarget | null>(null);
const contentItemRefs = computed(() => {
return historyItems.value.reduce((acc: ContentItemRef, item) => {
acc[`item-${item.hid}`] = ref(null);
acc[itemUniqueKey(item)] = ref(null);
return acc;
}, {});
});
Expand Down Expand Up @@ -403,6 +403,10 @@ function getItemKey(item: HistoryItem) {
return item.type_id;
}
function itemUniqueKey(item: HistoryItem) {
return `${item.history_content_type}-${item.id}`;
}
onMounted(async () => {
// `filterable` here indicates if this is the current history panel
if (props.filterable && !props.filter) {
Expand All @@ -411,9 +415,11 @@ onMounted(async () => {
await loadHistoryItems();
// if there is a listOffset, we are coming from a collection view, so focus on item at that offset
if (props.listOffset) {
const itemHid = historyItems.value[props.listOffset]?.hid;
const itemElement = contentItemRefs.value[`item-${itemHid}`]?.value?.$el as HTMLElement;
itemElement?.focus();
const itemAtOffset = historyItems.value[props.listOffset];
if (itemAtOffset) {
const itemElement = contentItemRefs.value[itemUniqueKey(itemAtOffset)]?.value?.$el as HTMLElement;
itemElement?.focus();
}
}
});
Expand All @@ -425,7 +431,7 @@ function arrowNavigate(item: HistoryItem, eventKey: string) {
nextItem = historyItems.value[historyItems.value.indexOf(item) - 1];
}
if (nextItem) {
const itemElement = contentItemRefs.value[`item-${nextItem.hid}`]?.value?.$el as HTMLElement;
const itemElement = contentItemRefs.value[itemUniqueKey(nextItem)]?.value?.$el as HTMLElement;
itemElement?.focus();
}
return nextItem;
Expand Down Expand Up @@ -584,7 +590,7 @@ function setItemDragstart(
<template v-slot:item="{ item, currentOffset }">
<ContentItem
:id="item.hid"
:ref="contentItemRefs[`item-${item.hid}`]"
:ref="contentItemRefs[itemUniqueKey(item)]"
is-history-item
:item="item"
:name="item.name"
Expand Down

0 comments on commit 84b6272

Please sign in to comment.