Skip to content

Commit

Permalink
Merge pull request galaxyproject#17924 from davelopez/fix_client_types
Browse files Browse the repository at this point in the history
Fix client types around history items
  • Loading branch information
mvdbeek authored Apr 6, 2024
2 parents bab7a6a + a8e88d5 commit 9a28c6a
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 55 deletions.
8 changes: 3 additions & 5 deletions client/src/api/datasets.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import type { FetchArgType } from "openapi-typescript-fetch";

import { DatasetDetails } from "@/api";
import { HDADetailed } from "@/api";
import { components, fetcher } from "@/api/schema";
import { withPrefix } from "@/utils/redirect";

export const datasetsFetcher = fetcher.path("/api/datasets").method("get").create();

export type HDASummary = components["schemas"]["HDASummary"];

type GetDatasetsApiOptions = FetchArgType<typeof datasetsFetcher>;
type GetDatasetsQuery = Pick<GetDatasetsApiOptions, "limit" | "offset">;
// custom interface for how we use getDatasets
Expand Down Expand Up @@ -42,11 +40,11 @@ export const fetchDataset = fetcher.path("/api/datasets/{dataset_id}").method("g

export const fetchDatasetStorage = fetcher.path("/api/datasets/{dataset_id}/storage").method("get").create();

export async function fetchDatasetDetails(params: { id: string }): Promise<DatasetDetails> {
export async function fetchDatasetDetails(params: { id: string }): Promise<HDADetailed> {
const { data } = await fetchDataset({ dataset_id: params.id, view: "detailed" });
// We know that the server will return a DatasetDetails object because of the view parameter
// but the type system doesn't, so we have to cast it.
return data as unknown as DatasetDetails;
return data as unknown as HDADetailed;
}

const updateDataset = fetcher.path("/api/datasets/{dataset_id}").method("put").create();
Expand Down
13 changes: 9 additions & 4 deletions client/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,17 @@ export type HistoryContentItemBase = components["schemas"]["EncodedHistoryConten
/**
* Contains summary information about a HistoryDatasetAssociation.
*/
export type DatasetSummary = components["schemas"]["HDASummary"];
export type HDASummary = components["schemas"]["HDASummary"];

/**
* Contains additional details about a HistoryDatasetAssociation.
*/
export type DatasetDetails = components["schemas"]["HDADetailed"];
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 All @@ -97,7 +102,7 @@ export type DatasetStorageDetails = components["schemas"]["DatasetStorageDetails
/**
* Represents a HistoryDatasetAssociation with either summary or detailed information.
*/
export type DatasetEntry = DatasetSummary | DatasetDetails;
export type DatasetEntry = HDASummary | HDADetailed;

/**
* Contains summary information about a DCE (DatasetCollectionElement).
Expand Down Expand Up @@ -179,7 +184,7 @@ export function isCollectionElement(element: DCESummary): element is DCECollecti
/**
* Returns true if the given dataset entry is an instance of DatasetDetails.
*/
export function hasDetails(entry: DatasetEntry): entry is DatasetDetails {
export function hasDetails(entry: DatasetEntry): entry is HDADetailed {
return "peek" in entry;
}

Expand Down
6 changes: 3 additions & 3 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 HDCADetailed } from "@/api";
import type { HDCADetailed, HistoryItemSummary } from "@/api";
import STATES from "@/mvc/dataset/states";
import localize from "@/utils/localization";
Expand Down Expand Up @@ -93,7 +93,7 @@ function _elementsSetUp() {
function _ensureElementIds() {
workingElements.value.forEach((element) => {
if (!Object.prototype.hasOwnProperty.call(element, "id")) {
element.id = element._uid as string;
console.warn("Element missing id", element);
}
});
Expand All @@ -116,7 +116,7 @@ function _validateElements() {
}
/** describe what is wrong with a particular element if anything */
function _isElementInvalid(element: HDCADetailed) {
function _isElementInvalid(element: HistoryItemSummary) {
if (element.history_content_type === "dataset_collection") {
return localize("is a collection, this is not allowed");
}
Expand Down
6 changes: 3 additions & 3 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 HDCADetailed } from "@/api";
import type { HDCADetailed, HistoryItemSummary } from "@/api";
import STATES from "@/mvc/dataset/states";
import localize from "@/utils/localization";
Expand Down Expand Up @@ -58,7 +58,7 @@ function _elementsSetUp() {
function _ensureElementIds() {
workingElements.value.forEach((element) => {
if (!Object.prototype.hasOwnProperty.call(element, "id")) {
element.id = element._uid as string;
console.warn("Element missing id", element);
}
});
Expand All @@ -81,7 +81,7 @@ function _validateElements() {
}
/** describe what is wrong with a particular element if anything */
function _isElementInvalid(element: HDCADetailed) {
function _isElementInvalid(element: HistoryItemSummary) {
if (element.history_content_type === "dataset_collection") {
return localize("is a collection, this is not allowed");
}
Expand Down
3 changes: 2 additions & 1 deletion client/src/components/Dataset/DatasetList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { BAlert, BTable } from "bootstrap-vue";
import { storeToRefs } from "pinia";
import { computed, onMounted, ref } from "vue";
import { copyDataset, getDatasets, HDASummary } from "@/api/datasets";
import { HDASummary } from "@/api";
import { copyDataset, getDatasets } from "@/api/datasets";
import { updateTags } from "@/api/tags";
import { useHistoryStore } from "@/stores/historyStore";
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/Dataset/DatasetName.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
import { BLink } from "bootstrap-vue";
import { computed } from "vue";
import { HDASummary } from "@/api/datasets";
import { HDASummary } from "@/api";
library.add(faCaretDown, faCopy, faEye, faTimesCircle, faPause);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { BButton } from "bootstrap-vue";
import { computed } from "vue";
import { useRouter } from "vue-router/composables";
import { type DatasetDetails } from "@/api";
import { type HDADetailed } from "@/api";
import { copy as sendToClipboard } from "@/utils/clipboard";
import localize from "@/utils/localization";
import { absPath, prependPath } from "@/utils/redirect";
Expand All @@ -26,7 +26,7 @@ import DatasetDownload from "@/components/History/Content/Dataset/DatasetDownloa
library.add(faBug, faChartBar, faInfoCircle, faLink, faQuestion, faRedo, faSitemap);
interface Props {
item: DatasetDetails;
item: HDADetailed;
writable: boolean;
showHighlight: boolean;
itemUrls: ItemUrls;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
import { BButton, BDropdown, BDropdownItem } from "bootstrap-vue";
import { computed } from "vue";
import { type DatasetDetails } from "@/api";
import { type HDADetailed } from "@/api";
import { prependPath } from "@/utils/redirect";
library.add(faSave);
interface Props {
item: DatasetDetails;
item: HDADetailed;
}
const props = defineProps<Props>();
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
6 changes: 3 additions & 3 deletions client/src/stores/datasetStore.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { defineStore } from "pinia";
import { computed, set } from "vue";

import type { DatasetDetails, DatasetEntry, HistoryContentItemBase } from "@/api";
import type { DatasetEntry, HDADetailed, HistoryContentItemBase } from "@/api";
import { fetchDataset } from "@/api/datasets";
import { ApiResponse } from "@/api/schema";
import { useKeyedCache } from "@/composables/keyedCache";

async function fetchDatasetDetails(params: { id: string }): Promise<ApiResponse<DatasetDetails>> {
async function fetchDatasetDetails(params: { id: string }): Promise<ApiResponse<HDADetailed>> {
const response = await fetchDataset({ dataset_id: params.id, view: "detailed" });
return response as unknown as ApiResponse<DatasetDetails>;
return response as unknown as ApiResponse<HDADetailed>;
}

export const useDatasetStore = defineStore("datasetStore", () => {
Expand Down
Loading

0 comments on commit 9a28c6a

Please sign in to comment.