Skip to content

Commit

Permalink
feat: filter files of dataset with search query
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiOnGitHub committed Dec 21, 2024
1 parent be3c779 commit 60e2055
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/galaxy/files/sources/_rdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def get_file_containers(
raise NotImplementedError()

def get_files_in_container(
self, container_id: str, writeable: bool, user_context: OptionalUserContext = None
self, container_id: str, writeable: bool, user_context: OptionalUserContext = None, query: Optional[str] = None,
) -> List[RemoteFile]:
"""Returns the list of files of a file container.
Expand Down
18 changes: 14 additions & 4 deletions lib/galaxy/files/sources/dataverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def _list(
)
return cast(List[AnyRemoteEntry], datasets), total_hits
dataset_id = self.get_container_id_from_path(path)
files = self.repository.get_files_in_container(dataset_id, writeable, user_context)
files = self.repository.get_files_in_container(dataset_id, writeable, user_context, query)
return cast(List[AnyRemoteEntry], files), len(files)

def _create_entry(
Expand Down Expand Up @@ -268,13 +268,23 @@ def get_file_containers(
return self._get_datasets_from_response(response_data["data"]), total_hits

def get_files_in_container(
self, dataset_id: str, writeable: bool, user_context: OptionalUserContext = None
self,
dataset_id: str,
writeable: bool,
user_context: OptionalUserContext = None,
query: Optional[str] = None,
) -> List[RemoteFile]:
"""This method lists the files in a dataverse dataset."""
request_url = self.files_of_dataset_url(dataset_id=dataset_id)
response_data = self._get_response(user_context, request_url)
total_hits = response_data["totalCount"]
return self._get_files_from_response(dataset_id, response_data["data"])
files = self._get_files_from_response(dataset_id, response_data["data"])
files = self._filter_files_by_name(files, query)
return files

def _filter_files_by_name(self, files: List[RemoteFile], query: Optional[str] = None) -> List[RemoteFile]:
if not query:
return files
return [file for file in files if query in file["name"]]

def create_draft_file_container(
self, title: str, public_name: str, user_context: OptionalUserContext = None
Expand Down

0 comments on commit 60e2055

Please sign in to comment.