Skip to content

Commit

Permalink
Manage columns support for All Hosts (#1421)
Browse files Browse the repository at this point in the history
  • Loading branch information
sambible authored Jun 18, 2024
1 parent 9b5b498 commit 75bc196
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
44 changes: 44 additions & 0 deletions airgun/entities/all_hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from airgun.navigation import NavigateStep, navigator
from airgun.utils import retry_navigation
from airgun.views.all_hosts import (
AllHostsManageColumnsView,
AllHostsTableView,
BulkHostDeleteDialog,
HostDeleteDialog,
Expand All @@ -20,6 +21,13 @@ def search(self, host_name):
view.wait_displayed()
return view.search(host_name)

def read_table(self):
"""Read All Hosts table"""
view = self.navigate_to(self, 'All')
self.browser.plugin.ensure_page_safe(timeout='5s')
view.wait_displayed()
return view.table.read()

def delete(self, host_name):
"""Delete host through table dropdown"""
view = self.navigate_to(self, 'All')
Expand Down Expand Up @@ -54,6 +62,28 @@ def bulk_delete_all(self):
view.wait_displayed()
return view.no_results

def manage_table_columns(self, values: dict):
"""
Select which columns should be displayed in the hosts table.
:param dict values: items of 'column name: value' pairs
Example: {'IPv4': True, 'Power': False, 'Model': True}
"""
view = self.navigate_to(self, 'ManageColumns')
view.fill(values)
view.submit()

def get_displayed_table_headers(self):
"""
Return displayed columns in the hosts table.
:return list: header names of the hosts table
"""
view = self.navigate_to(self, 'All')
self.browser.plugin.ensure_page_safe(timeout='5s')
view.wait_displayed()
return view.table.headers


@navigator.register(AllHostsEntity, 'All')
class ShowAllHostsScreen(NavigateStep):
Expand All @@ -64,3 +94,17 @@ class ShowAllHostsScreen(NavigateStep):
@retry_navigation
def step(self, *args, **kwargs):
self.view.menu.select('Hosts', 'All Hosts')


@navigator.register(AllHostsEntity, 'ManageColumns')
class HostsManageColumns(NavigateStep):
"""Navigate to the Manage columns dialog"""

VIEW = AllHostsManageColumnsView

def prerequisite(self, *args, **kwargs):
return self.navigate_to(self.obj, 'All')

def step(self, *args, **kwargs):
"""Open the Manage columns dialog"""
self.parent.manage_columns.click()
28 changes: 28 additions & 0 deletions airgun/views/all_hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
BaseLoggedInView,
SearchableViewMixinPF4,
)
from airgun.views.host_new import ManageColumnsView, PF4CheckboxTreeView


class AllHostsTableView(BaseLoggedInView, SearchableViewMixinPF4):
Expand All @@ -18,6 +19,7 @@ class AllHostsTableView(BaseLoggedInView, SearchableViewMixinPF4):
bulk_actions = Dropdown(locator='.//div[@data-ouia-component-id="action-buttons-dropdown"]')
table_loading = Text("//h5[normalize-space(.)='Loading']")
no_results = Text("//h5[normalize-space(.)='No Results']")
manage_columns = Button("Manage columns")
table = PatternflyTable(
component_id='table',
column_widgets={
Expand Down Expand Up @@ -64,3 +66,29 @@ class BulkHostDeleteDialog(View):
@property
def is_displayed(self):
return self.browser.wait_for_element(self.title, exception=False) is not None


class AllHostsCheckboxTreeView(PF4CheckboxTreeView):
"""Small tweaks to work with All Hosts"""

CHECKBOX_LOCATOR = './/*[self::span|self::label][contains(@class, "pf-c-tree-view__node-text")]/preceding-sibling::span/input[@type="checkbox"]'


class AllHostsManageColumnsView(ManageColumnsView):
"""Manage columns modal from Hosts page, small tweaks to work with All Hosts"""

ROOT = './/div[@data-ouia-component-id="manage-columns-modal"]'

def read(self):
"""
Get labels and values of all checkboxes in the dialog.
:return dict: mapping of `label: value` items
"""
return self.checkbox_group.read()

def fill(self, values):
"""
Overwritten to ignore the "Expand tree" functionality
"""
self.checkbox_group.fill(values)

0 comments on commit 75bc196

Please sign in to comment.