Skip to content

Commit

Permalink
Merge pull request #17145 from davelopez/migrate_dataset_ext_files_st…
Browse files Browse the repository at this point in the history
…ore_pinia

Migrate dataset extra files store to Pinia
  • Loading branch information
davelopez authored Dec 11, 2023
2 parents 6b88703 + 31809d5 commit 33acf3f
Show file tree
Hide file tree
Showing 9 changed files with 176 additions and 89 deletions.
5 changes: 4 additions & 1 deletion client/src/api/datasets.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { FetchArgType } from "openapi-typescript-fetch";

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

export const datasetsFetcher = fetcher.path("/api/datasets").method("get").create();
Expand Down Expand Up @@ -87,3 +87,6 @@ export async function copyDataset(
export function getCompositeDatasetLink(historyDatasetId: string, path: string) {
return withPrefix(`/api/datasets/${historyDatasetId}/display?filename=${path}`);
}

export type DatasetExtraFiles = components["schemas"]["DatasetExtraFiles"];
export const fetchDatasetExtraFiles = fetcher.path("/api/datasets/{dataset_id}/extra_files").method("get").create();
62 changes: 57 additions & 5 deletions client/src/api/schema/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ export interface paths {
*/
get: operations["converted_ext_api_datasets__dataset_id__converted__ext__get"];
};
"/api/datasets/{dataset_id}/extra_files": {
/** Get the list of extra files/directories associated with a dataset. */
get: operations["extra_files_api_datasets__dataset_id__extra_files_get"];
};
"/api/datasets/{dataset_id}/get_content_as_text": {
/** Returns dataset content as Text. */
get: operations["get_content_as_text_api_datasets__dataset_id__get_content_as_text_get"];
Expand Down Expand Up @@ -650,8 +654,8 @@ export interface paths {
head: operations["history_contents_display_api_histories__history_id__contents__history_content_id__display_head"];
};
"/api/histories/{history_id}/contents/{history_content_id}/extra_files": {
/** Generate list of extra files. */
get: operations["extra_files_api_histories__history_id__contents__history_content_id__extra_files_get"];
/** Get the list of extra files/directories associated with a dataset. */
get: operations["extra_files_history_api_histories__history_id__contents__history_content_id__extra_files_get"];
};
"/api/histories/{history_id}/contents/{history_content_id}/metadata_file": {
/** Returns the metadata file associated with this history item. */
Expand Down Expand Up @@ -3502,6 +3506,11 @@ export interface components {
*/
error_message: string;
};
/**
* DatasetExtraFiles
* @description A list of extra files associated with a dataset.
*/
DatasetExtraFiles: components["schemas"]["ExtraFileEntry"][];
/**
* DatasetInheritanceChain
* @default []
Expand Down Expand Up @@ -4370,6 +4379,16 @@ export interface components {
};
/** ExportTaskListResponse */
ExportTaskListResponse: components["schemas"]["ObjectExportTaskResponse"][];
/** ExtraFileEntry */
ExtraFileEntry: {
/** @description The class of this entry, either File or Directory. */
class: components["schemas"]["ExtraFilesEntryClass"];
/**
* Path
* @description Relative path to the file or directory.
*/
path: string;
};
/** ExtraFiles */
ExtraFiles: {
/**
Expand All @@ -4382,6 +4401,12 @@ export interface components {
items_from?: string;
src: components["schemas"]["Src"];
};
/**
* ExtraFilesEntryClass
* @description An enumeration.
* @enum {string}
*/
ExtraFilesEntryClass: "Directory" | "File";
/** FavoriteObject */
FavoriteObject: {
/**
Expand Down Expand Up @@ -10819,6 +10844,33 @@ export interface operations {
};
};
};
extra_files_api_datasets__dataset_id__extra_files_get: {
/** Get the list of extra files/directories associated with a dataset. */
parameters: {
/** @description The user ID that will be used to effectively make this API call. Only admins and designated users can make API calls on behalf of other users. */
header?: {
"run-as"?: string;
};
/** @description The encoded database identifier of the dataset. */
path: {
dataset_id: string;
};
};
responses: {
/** @description Successful Response */
200: {
content: {
"application/json": components["schemas"]["DatasetExtraFiles"];
};
};
/** @description Validation Error */
422: {
content: {
"application/json": components["schemas"]["HTTPValidationError"];
};
};
};
};
get_content_as_text_api_datasets__dataset_id__get_content_as_text_get: {
/** Returns dataset content as Text. */
parameters: {
Expand Down Expand Up @@ -13743,8 +13795,8 @@ export interface operations {
};
};
};
extra_files_api_histories__history_id__contents__history_content_id__extra_files_get: {
/** Generate list of extra files. */
extra_files_history_api_histories__history_id__contents__history_content_id__extra_files_get: {
/** Get the list of extra files/directories associated with a dataset. */
parameters: {
/** @description The user ID that will be used to effectively make this API call. Only admins and designated users can make API calls on behalf of other users. */
header?: {
Expand All @@ -13761,7 +13813,7 @@ export interface operations {
/** @description Successful Response */
200: {
content: {
"application/json": Record<string, never>;
"application/json": components["schemas"]["DatasetExtraFiles"];
};
};
/** @description Validation Error */
Expand Down
36 changes: 0 additions & 36 deletions client/src/components/Dataset/compositeDatasetUtils.js

This file was deleted.

45 changes: 45 additions & 0 deletions client/src/components/Dataset/compositeDatasetUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { DatasetExtraFiles, getCompositeDatasetLink } from "@/api/datasets";
import { useDatasetExtraFilesStore } from "@/stores/datasetExtraFilesStore";

interface PathDestination {
datasetContent: DatasetExtraFiles;
isDirectory: boolean;
filepath?: string;
fileLink?: string;
}

export async function getPathDestination(dataset_id: string, path?: string): Promise<PathDestination | null> {
const datasetExtraFilesStore = useDatasetExtraFilesStore();

let datasetExtraFiles = datasetExtraFilesStore.getDatasetExtraFiles(dataset_id);
if (!datasetExtraFiles) {
await datasetExtraFilesStore.fetchDatasetExtFilesByDatasetId({ id: dataset_id });
datasetExtraFiles = datasetExtraFilesStore.getDatasetExtraFiles(dataset_id);
}

if (datasetExtraFiles === null) {
return null;
}

const pathDestination: PathDestination = { datasetContent: datasetExtraFiles, isDirectory: false, filepath: path };

if (path === undefined || path === "undefined") {
return pathDestination;
}

const filepath = path;

const datasetEntry = datasetExtraFiles?.find((entry) => {
return filepath === entry.path;
});

if (datasetEntry) {
if (datasetEntry.class === "Directory") {
pathDestination.isDirectory = true;
pathDestination.filepath = filepath;
return pathDestination;
}
pathDestination.fileLink = getCompositeDatasetLink(dataset_id, datasetEntry.path);
}
return pathDestination;
}
35 changes: 0 additions & 35 deletions client/src/store/datasetExtFilesStore.js

This file was deleted.

2 changes: 0 additions & 2 deletions client/src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import Vuex from "vuex";
import createCache from "vuex-cache";
import VuexPersistence from "vuex-persist";

import { datasetExtFilesStore } from "./datasetExtFilesStore";
import { datasetPathDestinationStore } from "./datasetPathDestinationStore";
import { gridSearchStore } from "./gridSearchStore";
import { invocationStore } from "./invocationStore";
Expand Down Expand Up @@ -41,7 +40,6 @@ export function createStore() {
const storeConfig = {
plugins: [createCache(), panelsPersistence.plugin],
modules: {
datasetExtFiles: datasetExtFilesStore,
datasetPathDestination: datasetPathDestinationStore,
invocations: invocationStore,
gridSearch: gridSearchStore,
Expand Down
46 changes: 46 additions & 0 deletions client/src/stores/datasetExtraFilesStore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { defineStore } from "pinia";
import { computed, del, ref, set } from "vue";

import { DatasetExtraFiles, fetchDatasetExtraFiles } from "@/api/datasets";

export const useDatasetExtraFilesStore = defineStore("datasetExtraFilesStore", () => {
const storedDatasetExtraFiles = ref<{ [key: string]: DatasetExtraFiles }>({});
const loading = ref<{ [key: string]: boolean }>({});

const getDatasetExtraFiles = computed(() => {
return (datasetId: string) => {
const datasetExtFiles = storedDatasetExtraFiles.value[datasetId];
if (!datasetExtFiles && !loading.value[datasetId]) {
fetchDatasetExtFilesByDatasetId({ id: datasetId });
}
return datasetExtFiles ?? null;
};
});

const isLoadingDatasetExtraFiles = computed(() => {
return (datasetId: string) => {
return loading.value[datasetId] ?? false;
};
});

async function fetchDatasetExtFilesByDatasetId(params: { id: string }) {
const datasetId = params.id;
set(loading.value, datasetId, true);
try {
const { data: datasetExtFiles } = await fetchDatasetExtraFiles({
dataset_id: datasetId,
});
set(storedDatasetExtraFiles.value, datasetId, datasetExtFiles);
return datasetExtFiles;
} finally {
del(loading.value, datasetId);
}
}

return {
storedDatasetExtraFiles,
getDatasetExtraFiles,
isLoadingDatasetExtraFiles,
fetchDatasetExtFilesByDatasetId,
};
});
28 changes: 18 additions & 10 deletions lib/galaxy/webapps/galaxy/api/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
ComputeDatasetHashPayload,
ConvertedDatasetsMap,
DatasetContentType,
DatasetExtraFiles,
DatasetInheritanceChain,
DatasetsService,
DatasetStorageDetails,
Expand All @@ -72,7 +73,7 @@

DatasetIDPathParam: DecodedDatabaseIdField = Path(..., description="The encoded database identifier of the dataset.")

HistoryIDPathParam: DecodedDatabaseIdField = Path(..., description="The encoded database identifier of the History.")
HistoryIDPathParam = Path(description="The encoded database identifier of the History.")

DatasetSourceQueryParam: DatasetSourceType = Query(
default=DatasetSourceType.hda,
Expand Down Expand Up @@ -241,17 +242,28 @@ def update_permissions(

@router.get(
"/api/histories/{history_id}/contents/{history_content_id}/extra_files",
summary="Generate list of extra files.",
summary="Get the list of extra files/directories associated with a dataset.",
tags=["histories"],
)
def extra_files(
def extra_files_history(
self,
trans=DependsOnTrans,
history_id: DecodedDatabaseIdField = HistoryIDPathParam,
history_content_id: DecodedDatabaseIdField = DatasetIDPathParam,
):
) -> DatasetExtraFiles:
return self.service.extra_files(trans, history_content_id)

@router.get(
"/api/datasets/{dataset_id}/extra_files",
summary="Get the list of extra files/directories associated with a dataset.",
)
def extra_files(
self,
trans=DependsOnTrans,
dataset_id: DecodedDatabaseIdField = DatasetIDPathParam,
) -> DatasetExtraFiles:
return self.service.extra_files(trans, dataset_id)

@router.get(
"/api/histories/{history_id}/contents/{history_content_id}/display",
name="history_contents_display",
Expand All @@ -269,9 +281,7 @@ def display_history_content(
self,
request: Request,
trans=DependsOnTrans,
history_id: Optional[DecodedDatabaseIdField] = Path(
description="The encoded database identifier of the History.",
),
history_id: Optional[DecodedDatabaseIdField] = HistoryIDPathParam,
history_content_id: DecodedDatabaseIdField = DatasetIDPathParam,
preview: bool = PreviewQueryParam,
filename: Optional[str] = FilenameQueryParam,
Expand Down Expand Up @@ -356,9 +366,7 @@ def _display(
def get_metadata_file_history_content(
self,
trans=DependsOnTrans,
history_id: DecodedDatabaseIdField = Path(
description="The encoded database identifier of the History.",
),
history_id: DecodedDatabaseIdField = HistoryIDPathParam,
history_content_id: DecodedDatabaseIdField = DatasetIDPathParam,
metadata_file: str = Query(
...,
Expand Down
6 changes: 6 additions & 0 deletions lib/galaxy/webapps/galaxy/services/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ class ExtraFileEntry(Model):
)


class DatasetExtraFiles(Model):
"""A list of extra files associated with a dataset."""

__root__: List[ExtraFileEntry]


class DatasetTextContentDetails(Model):
item_data: Optional[str] = Field(
description="First chunk of text content (maximum 1MB) of the dataset.",
Expand Down

0 comments on commit 33acf3f

Please sign in to comment.