Skip to content

Commit

Permalink
use {history_content_type}-{id} to key unique items is 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 1998694
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 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 @@ -212,6 +212,10 @@ watch(
}
);
function itemUniqueKey(item: HistoryItem) {
return `${item.history_content_type}-${item.id}`;
}
function getHighlight(item: HistoryItem) {
if (unref(isLoading)) {
return undefined;
Expand Down Expand Up @@ -400,7 +404,7 @@ function updateFilterValue(newFilterText: string, newValue: any) {
}
function getItemKey(item: HistoryItem) {
return item.type_id;
return `${item.history_content_type}-${item.id}`;
}
onMounted(async () => {
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 1998694

Please sign in to comment.