Skip to content

Commit

Permalink
Consolidate HistoryItemSummary type and imports
Browse files Browse the repository at this point in the history
  • Loading branch information
davelopez committed Apr 6, 2024
1 parent 61c3dc6 commit 2b1e796
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 35 deletions.
5 changes: 5 additions & 0 deletions client/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ export type HDASummary = components["schemas"]["HDASummary"];
*/
export type HDADetailed = components["schemas"]["HDADetailed"];

/**
* Represents either an HDA or an HDCA with minimal information.
*/
export type HistoryItemSummary = HDASummary | HDCASummary;

/**
* Contains storage (object store, quota, etc..) details for a dataset.
*/
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/Collections/ListCollectionCreator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { BAlert, BButton } from "bootstrap-vue";
import { computed, onMounted, ref } from "vue";
import draggable from "vuedraggable";
import type { HDASummary, HDCADetailed, HDCASummary } from "@/api";
import type { HDCADetailed, HistoryItemSummary } from "@/api";
import STATES from "@/mvc/dataset/states";
import localize from "@/utils/localization";
Expand Down Expand Up @@ -116,7 +116,7 @@ function _validateElements() {
}
/** describe what is wrong with a particular element if anything */
function _isElementInvalid(element: HDASummary | HDCASummary) {
function _isElementInvalid(element: HistoryItemSummary) {
if (element.history_content_type === "dataset_collection") {
return localize("is a collection, this is not allowed");
}
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/Collections/PairCollectionCreator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { BAlert } from "bootstrap-vue";
import { computed, onMounted, ref } from "vue";
import type { HDASummary, HDCADetailed, HDCASummary } from "@/api";
import type { HDCADetailed, HistoryItemSummary } from "@/api";
import STATES from "@/mvc/dataset/states";
import localize from "@/utils/localization";
Expand Down Expand Up @@ -81,7 +81,7 @@ function _validateElements() {
}
/** describe what is wrong with a particular element if anything */
function _isElementInvalid(element: HDASummary | HDCASummary) {
function _isElementInvalid(element: HistoryItemSummary) {
if (element.history_content_type === "dataset_collection") {
return localize("is a collection, this is not allowed");
}
Expand Down
38 changes: 19 additions & 19 deletions client/src/components/History/CurrentHistory/HistoryPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BAlert } from "bootstrap-vue";
import { storeToRefs } from "pinia";
import { computed, onMounted, type Ref, ref, set as VueSet, unref, watch } from "vue";
import type { HistorySummaryExtended } from "@/api";
import type { HistoryItemSummary, HistorySummaryExtended } from "@/api";
import { copyDataset } from "@/api/datasets";
import ExpandedItems from "@/components/History/Content/ExpandedItems";
import SelectedItems from "@/components/History/Content/SelectedItems";
Expand All @@ -13,7 +13,7 @@ import { Toast } from "@/composables/toast";
import { useActiveElement } from "@/composables/useActiveElement";
import { startWatchingHistory } from "@/store/historyStore/model/watchHistory";
import { useEventStore } from "@/stores/eventStore";
import { type HistoryItem, useHistoryItemsStore } from "@/stores/historyItemsStore";
import { useHistoryItemsStore } from "@/stores/historyItemsStore";
import { useHistoryStore } from "@/stores/historyStore";
import { type Alias, getOperatorForAlias } from "@/utils/filtering";
import { setDrag } from "@/utils/setDrag";
Expand Down Expand Up @@ -219,19 +219,19 @@ function dragSameHistory() {
function getDragData() {
const eventStore = useEventStore();
const multiple = eventStore.multipleDragData;
let data: HistoryItem[] | undefined;
let data: HistoryItemSummary[] | undefined;
let historyId: string | undefined;
try {
if (multiple) {
const dragData = eventStore.getDragData() as Record<string, HistoryItem>;
const dragData = eventStore.getDragData() as Record<string, HistoryItemSummary>;
// set historyId to the first history_id in the multiple drag data
const firstItem = Object.values(dragData)[0];
if (firstItem) {
historyId = firstItem.history_id;
}
data = Object.values(dragData);
} else {
data = [eventStore.getDragData() as HistoryItem];
data = [eventStore.getDragData() as HistoryItemSummary];
if (data[0]) {
historyId = data[0].history_id;
}
Expand All @@ -242,7 +242,7 @@ function getDragData() {
return { data, sameHistory: historyId === props.history.id, multiple };
}
function getHighlight(item: HistoryItem) {
function getHighlight(item: HistoryItemSummary) {
if (unref(isLoading)) {
return undefined;
}
Expand All @@ -263,11 +263,11 @@ function getHighlight(item: HistoryItem) {
return "input";
}
function hasMatches(items: HistoryItem[]) {
function hasMatches(items: HistoryItemSummary[]) {
return !!items && items.length > 0;
}
function isDataset(item: HistoryItem) {
function isDataset(item: HistoryItemSummary) {
return item.history_content_type === "dataset";
}
Expand All @@ -288,7 +288,7 @@ async function loadHistoryItems() {
}
}
async function onDelete(item: HistoryItem, recursive = false) {
async function onDelete(item: HistoryItemSummary, recursive = false) {
isLoading.value = true;
setInvisible(item);
Expand All @@ -300,7 +300,7 @@ async function onDelete(item: HistoryItem, recursive = false) {
}
}
function onHideSelection(selectedItems: HistoryItem[]) {
function onHideSelection(selectedItems: HistoryItemSummary[]) {
for (const item of selectedItems) {
setInvisible(item);
}
Expand All @@ -310,7 +310,7 @@ function onScroll(newOffset: number) {
offsetQueryParam.value = newOffset;
}
async function onUndelete(item: HistoryItem) {
async function onUndelete(item: HistoryItemSummary) {
setInvisible(item);
isLoading.value = true;
Expand All @@ -322,7 +322,7 @@ async function onUndelete(item: HistoryItem) {
}
}
async function onUnhide(item: HistoryItem) {
async function onUnhide(item: HistoryItemSummary) {
setInvisible(item);
isLoading.value = true;
Expand All @@ -342,11 +342,11 @@ function reloadContents() {
startWatchingHistory();
}
function setInvisible(item: HistoryItem) {
function setInvisible(item: HistoryItemSummary) {
VueSet(unref(invisibleHistoryItems), item.hid, true);
}
function onTagChange(item: HistoryItem, newTags: string[]) {
function onTagChange(item: HistoryItemSummary, newTags: string[]) {
item.tags = newTags;
}
Expand Down Expand Up @@ -424,11 +424,11 @@ function updateFilterValue(filterKey: string, newValue: any) {
filterText.value = filterClass.setFilterValue(currentFilterText, filterKey, newValue);
}
function getItemKey(item: HistoryItem) {
function getItemKey(item: HistoryItemSummary) {
return item.type_id;
}
function itemUniqueKey(item: HistoryItem) {
function itemUniqueKey(item: HistoryItemSummary) {
return `${item.history_content_type}-${item.id}`;
}
Expand All @@ -448,7 +448,7 @@ onMounted(async () => {
}
});
function arrowNavigate(item: HistoryItem, eventKey: string) {
function arrowNavigate(item: HistoryItemSummary, eventKey: string) {
let nextItem = null;
if (eventKey === "ArrowDown") {
nextItem = historyItems.value[historyItems.value.indexOf(item) + 1];
Expand All @@ -463,9 +463,9 @@ function arrowNavigate(item: HistoryItem, eventKey: string) {
}
function setItemDragstart(
item: HistoryItem,
item: HistoryItemSummary,
itemIsSelected: boolean,
selectedItems: Map<string, HistoryItem>,
selectedItems: Map<string, HistoryItemSummary>,
selectionSize: number,
event: DragEvent
) {
Expand Down
8 changes: 4 additions & 4 deletions client/src/components/History/Multiple/MultipleViewList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import { computed, type Ref, ref } from "vue";
//@ts-ignore missing typedefs
import VirtualList from "vue-virtual-scroll-list";
import { HistoryItemSummary } from "@/api";
import { copyDataset } from "@/api/datasets";
import { useAnimationFrameResizeObserver } from "@/composables/sensors/animationFrameResizeObserver";
import { useAnimationFrameScroll } from "@/composables/sensors/animationFrameScroll";
import { Toast } from "@/composables/toast";
import { useEventStore } from "@/stores/eventStore";
import type { HistoryItem } from "@/stores/historyItemsStore";
import { useHistoryStore } from "@/stores/historyStore";
import localize from "@/utils/localization";
import { errorMessageAsString } from "@/utils/simple-error";
Expand Down Expand Up @@ -75,20 +75,20 @@ async function onDrop(evt: any) {
}
processingDrop.value = true;
showDropZone.value = false;
let data: HistoryItem[] | undefined;
let data: HistoryItemSummary[] | undefined;
let originalHistoryId: string | undefined;
const multiple = eventStore.multipleDragData;
try {
if (multiple) {
const dragData = eventStore.getDragData() as Record<string, HistoryItem>;
const dragData = eventStore.getDragData() as Record<string, HistoryItemSummary>;
// set originalHistoryId to the first history_id in the multiple drag data
const firstItem = Object.values(dragData)[0];
if (firstItem) {
originalHistoryId = firstItem.history_id;
}
data = Object.values(dragData);
} else {
data = [eventStore.getDragData() as HistoryItem];
data = [eventStore.getDragData() as HistoryItemSummary];
if (data[0]) {
originalHistoryId = data[0].history_id;
}
Expand Down
14 changes: 6 additions & 8 deletions client/src/stores/historyItemsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,19 @@ import { reverse } from "lodash";
import { defineStore } from "pinia";
import { computed, ref, set } from "vue";

import type { HDASummary, HDCASummary } from "@/api";
import type { HistoryItemSummary } from "@/api";
import { HistoryFilters } from "@/components/History/HistoryFilters";
import { mergeArray } from "@/store/historyStore/model/utilities";
import { ActionSkippedError, LastQueue } from "@/utils/lastQueue";
import { urlData } from "@/utils/url";

export type HistoryItem = HDASummary | HDCASummary;

const limit = 100;

type ExpectedReturn = { stats: { total_matches: number }; contents: HistoryItem[] };
type ExpectedReturn = { stats: { total_matches: number }; contents: HistoryItemSummary[] };
const queue = new LastQueue<typeof urlData>(1000, true);

export const useHistoryItemsStore = defineStore("historyItemsStore", () => {
const items = ref<Record<string, HistoryItem[]>>({});
const items = ref<Record<string, HistoryItemSummary[]>>({});
const itemKey = ref("hid");
const totalMatchesCount = ref<number | undefined>(undefined);
const lastCheckedTime = ref(new Date());
Expand All @@ -37,7 +35,7 @@ export const useHistoryItemsStore = defineStore("historyItemsStore", () => {
(filter: [string, string]) => !filter[0].includes("related")
);
const relatedHid = HistoryFilters.getFilterValue(filterText, "related");
const filtered = itemArray.filter((item: HistoryItem) => {
const filtered = itemArray.filter((item: HistoryItemSummary) => {
if (!item) {
return false;
}
Expand Down Expand Up @@ -74,12 +72,12 @@ export const useHistoryItemsStore = defineStore("historyItemsStore", () => {
}
}

function saveHistoryItems(historyId: string, payload: HistoryItem[], relatedHid = null) {
function saveHistoryItems(historyId: string, payload: HistoryItemSummary[], relatedHid = null) {
// merges incoming payload into existing state
mergeArray(historyId, payload, items.value, itemKey.value);
// if related filter is included, set keys in state
if (relatedHid) {
payload.forEach((item: HistoryItem) => {
payload.forEach((item: HistoryItemSummary) => {
// current `item.hid` is related to item with hid = `relatedHid`
const relationKey = `${historyId}-${relatedHid}-${item.hid}`;
set(relatedItems.value, relationKey, true);
Expand Down

0 comments on commit 2b1e796

Please sign in to comment.