Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds published histories to grid list #17449

Merged
merged 7 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 29 additions & 28 deletions client/src/components/Grid/GridList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import GridLink from "./GridElements/GridLink.vue";
import GridOperations from "./GridElements/GridOperations.vue";
import GridText from "./GridElements/GridText.vue";
import FilterMenu from "@/components/Common/FilterMenu.vue";
import Heading from "@/components/Common/Heading.vue";
import SharingIndicators from "@/components/Indices/SharingIndicators.vue";
import LoadingSpan from "@/components/LoadingSpan.vue";
import StatelessTags from "@/components/TagsMultiselect/StatelessTags.vue";
Expand Down Expand Up @@ -235,35 +236,35 @@ watch(operationMessage, () => {
<div :id="gridConfig.id" class="d-flex flex-column overflow-auto">
<BAlert v-if="!!errorMessage" variant="danger" show>{{ errorMessage }}</BAlert>
<BAlert v-if="!!operationMessage" :variant="operationStatus" fade show>{{ operationMessage }}</BAlert>
<div class="grid-header d-flex justify-content-between pb-2">
<div>
<h1 class="m-0" data-description="grid title">
{{ gridConfig.title }}
</h1>
<FilterMenu
class="py-2"
:name="gridConfig.plural"
:placeholder="`search ${gridConfig.plural.toLowerCase()}`"
:filter-class="gridConfig.filtering"
:filter-text.sync="filterText"
:loading="loading"
:show-advanced.sync="showAdvanced"
@on-backend-filter="onSearch" />
<hr v-if="showAdvanced" />
</div>
<div v-if="!showAdvanced" class="py-3">
<BButton
v-for="(action, actionIndex) in gridConfig.actions"
:key="actionIndex"
class="m-1"
size="sm"
variant="primary"
:data-description="`grid action ${action.title.toLowerCase()}`"
@click="action.handler()">
<Icon :icon="action.icon" class="mr-1" />
<span v-localize>{{ action.title }}</span>
</BButton>
<div class="grid-header d-flex justify-content-between pb-2 flex-column">
<div class="d-flex">
<Heading h1 separator inline size="xl" class="flex-grow-1 m-0" data-description="grid title">
<span v-localize>{{ gridConfig.title }}</span>
</Heading>
<div class="d-flex justify-content-between">
<BButton
v-for="(action, actionIndex) in gridConfig.actions"
:key="actionIndex"
class="m-1"
size="sm"
variant="primary"
:data-description="`grid action ${action.title.toLowerCase()}`"
@click="action.handler()">
<Icon :icon="action.icon" class="mr-1" />
<span v-localize>{{ action.title }}</span>
</BButton>
</div>
</div>
<FilterMenu
class="py-2"
:name="gridConfig.plural"
:placeholder="`search ${gridConfig.plural.toLowerCase()}`"
:filter-class="gridConfig.filtering"
:filter-text.sync="filterText"
:loading="loading"
:show-advanced.sync="showAdvanced"
@on-backend-filter="onSearch" />
<hr v-if="showAdvanced" />
</div>
<LoadingSpan v-if="loading" />
<BAlert v-else-if="!isAvailable" variant="info" show>
Expand Down
112 changes: 112 additions & 0 deletions client/src/components/Grid/configs/historiesPublished.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import { faEye } from "@fortawesome/free-solid-svg-icons";
import { useEventBus } from "@vueuse/core";

import { historiesFetcher } from "@/api/histories";
import Filtering, { contains, expandNameTag, type ValidFilter } from "@/utils/filtering";
import _l from "@/utils/localization";

import type { FieldArray, GridConfig } from "./types";

const { emit } = useEventBus<string>("grid-router-push");

/**
* Local types
*/
type HistoryEntry = Record<string, unknown>;
type SortKeyLiteral = "name" | "update_time" | undefined;

/**
* Request and return data from server
*/
async function getData(offset: number, limit: number, search: string, sort_by: string, sort_desc: boolean) {
const { data, headers } = await historiesFetcher({
limit,
offset,
search,
sort_by: sort_by as SortKeyLiteral,
sort_desc,
show_own: false,
show_published: true,
show_shared: false,
});
const totalMatches = parseInt(headers.get("total_matches") ?? "0");
return [data, totalMatches];
}

/**
* Declare columns to be displayed
*/
const fields: FieldArray = [
{
key: "name",
title: "Name",
type: "operations",
operations: [
{
title: "View",
icon: faEye,
condition: (data: HistoryEntry) => !data.deleted,
handler: (data: HistoryEntry) => {
emit(`/histories/view?id=${data.id}`);
},
},
],
},
{
key: "annotation",
title: "Annotation",
type: "text",
},
{
key: "id",
title: "Size",
type: "datasets",
},
{
key: "tags",
title: "Tags",
type: "tags",
disabled: true,
},
{
key: "update_time",
title: "Updated",
type: "date",
},
{
key: "username",
title: "Username",
type: "text",
},
];

/**
* Declare filter options
*/
const validFilters: Record<string, ValidFilter<string | boolean | undefined>> = {
name: { placeholder: "name", type: String, handler: contains("name"), menuItem: true },
user: { placeholder: "user", type: String, handler: contains("username"), menuItem: true },
tag: {
placeholder: "tag(s)",
type: "MultiTags",
handler: contains("tag", "tag", expandNameTag),
menuItem: true,
},
};

/**
* Grid configuration
*/
const gridConfig: GridConfig = {
id: "histories-published-grid",
fields: fields,
filtering: new Filtering(validFilters, undefined, false, false),
getData: getData,
plural: "Histories",
sortBy: "update_time",
sortDesc: true,
sortKeys: ["name", "update_time", "username"],
title: "Published Histories",
};

export default gridConfig;
10 changes: 4 additions & 6 deletions client/src/entry/analysis/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import DatasetDetails from "components/DatasetInformation/DatasetDetails";
import DatasetError from "components/DatasetInformation/DatasetError";
import FormGeneric from "components/Form/FormGeneric";
import historiesGridConfig from "components/Grid/configs/histories";
import historiesPublishedGridConfig from "components/Grid/configs/historiesPublished";
import historiesSharedGridConfig from "components/Grid/configs/historiesShared";
import visualizationsGridConfig from "components/Grid/configs/visualizations";
import visualizationsPublishedGridConfig from "components/Grid/configs/visualizationsPublished";
import GridList from "components/Grid/GridList";
import HistoryExportTasks from "components/History/Export/HistoryExport";
import HistoryPublished from "components/History/HistoryPublished";
import HistoryPublishedList from "components/History/HistoryPublishedList";
import HistoryView from "components/History/HistoryView";
import HistoryMultipleView from "components/History/Multiple/MultipleView";
import { HistoryExport } from "components/HistoryExport/index";
Expand Down Expand Up @@ -282,11 +282,9 @@ export function getRouter(Galaxy) {
},
{
path: "histories/list_published",
component: HistoryPublishedList,
props: (route) => {
return {
...route.query,
};
component: GridList,
props: {
gridConfig: historiesPublishedGridConfig,
},
},
{
Expand Down
15 changes: 7 additions & 8 deletions client/src/utils/navigation/navigation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -397,14 +397,13 @@ multi_history_panel:

published_histories:
selectors:
histories: '#published-histories-table tbody tr'
search_input: '#published-histories input.search-query[data-description="filter text input"]'
advanced_search_toggle: '#published-histories [data-description="toggle advanced search"]'
advanced_search_name_input: '#published-histories-advanced-filter-name'
advanced_search_tag_input: '#published-histories-advanced-filter-tag'
advanced_search_submit: '#published-histories-advanced-filter-submit'
tag_content: '#published-histories-table tbody tr .tag span'
column_header: '#published-histories-table thead tr th:nth-child(${column_number})'
histories: '#grid-histories-published tbody tr'
advanced_search_name_input: '#histories-advanced-filter-name'
advanced_search_tag_area: '#histories-advanced-filter-tag .stateless-tags button'
advanced_search_tag_input: '#histories-advanced-filter-tag .stateless-tags input'
advanced_search_toggle: '#histories-published-grid [data-description="toggle advanced search"]'
advanced_search_submit: '#histories-advanced-filter-submit'
search_input: '#histories-published-grid input.search-query[data-description="filter text input"]'

shared_histories:
selectors:
Expand Down
2 changes: 2 additions & 0 deletions lib/galaxy/managers/histories.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ def p_tag_filter(term_text: str, quoted: bool):
self.model_class.deleted == (true() if show_deleted else false())
)

stmt = stmt.distinct()

if include_total_count:
total_matches = get_count(trans.sa_session, stmt)
else:
Expand Down
8 changes: 5 additions & 3 deletions lib/galaxy/selenium/navigates_galaxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,9 +564,11 @@ def select_grid_operation(self, item_name, option_label):

def select_grid_cell(self, grid_name, item_name, column_index=3):
cell = None
grid = self.wait_for_selector(grid_name)
grid = self.wait_for_selector(f"{grid_name} table")
for row in grid.find_elements(By.TAG_NAME, "tr"):
td = row.find_elements(By.TAG_NAME, "td")
print(td[0].text)
print(td[1].text)
if item_name in [td[0].text, td[1].text]:
cell = td[column_index]
break
Expand Down Expand Up @@ -1733,10 +1735,10 @@ def histories_click_advanced_search(self):
self.wait_for_and_click_selector(search_selector)

@retry_during_transitions
def histories_get_history_names(self):
def histories_get_history_names(self, selector="#histories-grid"):
self.sleep_for(self.wait_types.UX_RENDER)
names = []
grid = self.wait_for_selector("#histories-grid")
grid = self.wait_for_selector(selector)
for row in grid.find_elements(By.TAG_NAME, "tr"):
td = row.find_elements(By.TAG_NAME, "td")
name = td[1].text if td[0].text == "" else td[0].text
Expand Down
69 changes: 27 additions & 42 deletions lib/galaxy_test/selenium/test_histories_published.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,94 +19,79 @@ def test_published_histories(self):
def test_published_histories_sort_by_name(self):
self._login()
self.navigate_to_published_histories()
self.sleep_for(self.wait_types.UX_RENDER)
self.components.published_histories.column_header(column_number=1).wait_for_and_click()

self.wait_for_and_click_selector('[data-description="grid sort key name"]')

sorted_histories = self.get_published_history_names_from_server(sort_by="name")
self.assert_histories_present(sorted_histories, sort_by_matters=True)

@selenium_test
def test_published_histories_sort_by_last_update(self):
self._login()
self.navigate_to_published_histories()
self.sleep_for(self.wait_types.UX_RENDER)
self.components.published_histories.column_header(column_number=5).wait_for_and_click()

self.wait_for_and_click_selector('[data-description="grid sort key update_time"]')

expected_history_names = self.get_published_history_names_from_server(sort_by="update_time")
self.assert_histories_present(expected_history_names, sort_by_matters=True)

@selenium_test
def test_published_histories_tag_click(self):
self._login()
self.navigate_to_published_histories()
self.sleep_for(self.wait_types.UX_RENDER)
present_histories = self.get_present_histories()
clicked = False
for row in present_histories:
his = row.find_elements(By.TAG_NAME, "td")[0]
if self.history3_name in his.text:
row.find_elements(By.TAG_NAME, "td")[3].find_elements(By.CSS_SELECTOR, ".tag")[0].click()
clicked = True
break

assert clicked

# Search by tag
tags_cell = self.select_grid_cell("#histories-published-grid", self.history3_name)
tag = tags_cell.find_element(By.CSS_SELECTOR, ".tag")
tag.click()

text = self.components.published_histories.search_input.wait_for_value()
if text == "":
raise AssertionError("Failed to update search filter on tag click")

self.assert_histories_present([self.history3_name, self.history1_name])

@selenium_test
def test_published_histories_username_click(self):
def test_published_histories_username_filter(self):
self._login()
self.navigate_to_published_histories()
self.sleep_for(self.wait_types.UX_RENDER)
present_histories = self.get_present_histories()
clicked = False
for row in present_histories:
his = row.find_elements(By.TAG_NAME, "td")[0]
if self.history2_name in his.text:
row.find_elements(By.TAG_NAME, "td")[2].find_elements(
By.CSS_SELECTOR, ".published-histories-username-link"
)[0].click()
clicked = True
break

assert clicked
text = self.components.published_histories.search_input.wait_for_value()
if "test2" not in text:
raise AssertionError("Failed to update search filter with username on username click")

username = self.user2_email.split("@")[0]
self.components.published_histories.search_input.wait_for_and_send_keys(f"user:{username}")
self.assert_histories_present([self.history2_name])

@selenium_test
def test_published_histories_search_standard(self):
self._login()
self.navigate_to_published_histories()
self.sleep_for(self.wait_types.UX_RENDER)
self.components.published_histories.search_input.wait_for_and_send_keys(self.history1_name)
self.assert_histories_present([self.history1_name])

@selenium_test
def test_published_histories_search_advanced(self):
self._login()
self.navigate_to_published_histories()
self.sleep_for(self.wait_types.UX_RENDER)
self.components.published_histories.advanced_search_toggle.wait_for_and_click()
# search by tag and name
self.components.published_histories.advanced_search_tag_input.wait_for_and_send_keys(self.history3_tags)
self.components.published_histories.advanced_search_name_input.wait_for_and_send_keys(self.history3_name)

self.components.published_histories.advanced_search_tag_area.wait_for_and_click()
input_element = self.components.published_histories.advanced_search_tag_input.wait_for_visible()
input_element.send_keys(self.history3_tags[0])
self.send_enter(input_element)
self.send_escape(input_element)
self.sleep_for(self.wait_types.UX_RENDER)

self.components.published_histories.advanced_search_submit.wait_for_and_click()
self.assert_histories_present([self.history3_name])

@retry_assertion_during_transitions
def assert_histories_present(self, expected_histories, sort_by_matters=False):
present_histories = self.get_present_histories()
present_histories = self.histories_get_history_names(selector="#histories-published-grid")
assert len(present_histories) == len(expected_histories)
for index, row in enumerate(present_histories):
cell = row.find_elements(By.TAG_NAME, "td")[0]
for index, history_name in enumerate(present_histories):
if not sort_by_matters:
assert cell.text in expected_histories
assert history_name in expected_histories
else:
assert cell.text == expected_histories[index]
assert history_name == expected_histories[index]

def get_published_history_names_from_server(self, sort_by=None):
published_histories = self.dataset_populator._get("histories/published").json()
Expand Down
Loading