Skip to content

Commit

Permalink
focus on collection after returning from collection panel
Browse files Browse the repository at this point in the history
Also, add a couple types in `HistoryPanel`
  • Loading branch information
ahmedhamidawan committed Mar 7, 2024
1 parent 34792f2 commit 0501664
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions client/src/components/History/CurrentHistory/HistoryPanel.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { BAlert } from "bootstrap-vue";
import { storeToRefs } from "pinia";
import { computed, onMounted, ref, set as VueSet, unref, watch } from "vue";
import { computed, onMounted, type Ref, ref, set as VueSet, unref, watch } from "vue";
import type { HistorySummary } from "@/api";
import { copyDataset } from "@/api/datasets";
Expand Down Expand Up @@ -55,6 +55,8 @@ interface Props {
isMultiViewItem?: boolean;
}
type ContentItemRef = Record<string, Ref<InstanceType<typeof ContentItem> | null>>;
const props = withDefaults(defineProps<Props>(), {
listOffset: 0,
filter: "",
Expand All @@ -77,9 +79,8 @@ const operationError = ref(null);
const querySelectionBreak = ref(false);
const dragTarget = ref<EventTarget | null>(null);
const contentItemRefs = computed(() => {
return historyItems.value.reduce((acc: any, item) => {
// TODO: type `any` properly
acc[`item-${item.hid}`] = ref(null);
return historyItems.value.reduce((acc: ContentItemRef, item) => {
acc[`item-${item.id}`] = ref(null);
return acc;
}, {});
});
Expand Down Expand Up @@ -410,6 +411,12 @@ onMounted(async () => {
filterText.value = storeFilterText.value;
}
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 itemId = historyItems.value[props.listOffset]?.id;
const itemElement = contentItemRefs.value[`item-${itemId}`]?.value?.$el as HTMLElement;
itemElement?.focus();
}
});
function arrowNavigate(item: HistoryItem, eventKey: string) {
Expand All @@ -420,7 +427,8 @@ function arrowNavigate(item: HistoryItem, eventKey: string) {
nextItem = historyItems.value[historyItems.value.indexOf(item) - 1];
}
if (nextItem) {
contentItemRefs.value[`item-${nextItem.hid}`].value.$el.focus();
const itemElement = contentItemRefs.value[`item-${nextItem.id}`]?.value?.$el as HTMLElement;
itemElement?.focus();
}
return nextItem;
}
Expand Down Expand Up @@ -578,7 +586,7 @@ function setItemDragstart(
<template v-slot:item="{ item, currentOffset }">
<ContentItem
:id="item.hid"
:ref="contentItemRefs[`item-${item.hid}`]"
:ref="contentItemRefs[`item-${item.id}`]"
is-history-item
:item="item"
:name="item.name"
Expand Down

0 comments on commit 0501664

Please sign in to comment.