From 48a6e92700bda32d0b1343b5fa141ca7e838c4fe Mon Sep 17 00:00:00 2001 From: David Matamoros Date: Thu, 20 Jan 2022 10:09:58 +0100 Subject: [PATCH] MDL-72061 reportbuilder: Report actions are shown in action menus --- reportbuilder/classes/local/report/action.php | 2 +- .../classes/table/system_report_table.php | 12 +++++--- .../tests/behat/behat_reportbuilder.php | 13 +++++++++ .../tests/behat/customreports.feature | 29 ++++++++++++------- reportbuilder/tests/behat/schedules.feature | 6 ++-- 5 files changed, 43 insertions(+), 19 deletions(-) diff --git a/reportbuilder/classes/local/report/action.php b/reportbuilder/classes/local/report/action.php index 97515c72d19..5b7db9eacb0 100644 --- a/reportbuilder/classes/local/report/action.php +++ b/reportbuilder/classes/local/report/action.php @@ -125,7 +125,7 @@ final class action { $this->attributes['data-popup-action'] = json_encode(new popup_action('click', $url)); } - return $OUTPUT->action_icon($url, $this->icon, null, self::replace_placeholders($this->attributes, $row)); + return $OUTPUT->action_link($url, $this->title, null, self::replace_placeholders($this->attributes, $row), $this->icon); } /** diff --git a/reportbuilder/classes/table/system_report_table.php b/reportbuilder/classes/table/system_report_table.php index 4d706646f35..0724e7c09f0 100644 --- a/reportbuilder/classes/table/system_report_table.php +++ b/reportbuilder/classes/table/system_report_table.php @@ -18,6 +18,7 @@ declare(strict_types=1); namespace core_reportbuilder\table; +use action_menu; use core_table\local\filter\filterset; use html_writer; use moodle_exception; @@ -212,11 +213,14 @@ class system_report_table extends base_report_table { * @return string */ private function format_row_actions(stdClass $row): string { - $actions = array_map(static function(action $action) use ($row): string { - return (string) $action->get_action_link($row); - }, $this->report->get_actions()); + global $OUTPUT; - return implode('', $actions); + $menu = new action_menu(); + $menu->set_menu_trigger($OUTPUT->pix_icon('a/setting', get_string('actions', 'core_reportbuilder'))); + foreach ($this->report->get_actions() as $action) { + $menu->add($action->get_action_link($row)); + } + return $OUTPUT->render($menu); } /** diff --git a/reportbuilder/tests/behat/behat_reportbuilder.php b/reportbuilder/tests/behat/behat_reportbuilder.php index 02b2d6b8c8d..93251aa1cf1 100644 --- a/reportbuilder/tests/behat/behat_reportbuilder.php +++ b/reportbuilder/tests/behat/behat_reportbuilder.php @@ -95,4 +95,17 @@ class behat_reportbuilder extends behat_base { $editlabel = get_string('aggregatecolumn', 'core_reportbuilder', $column); $this->execute('behat_forms::i_set_the_field_to', [$this->escape($editlabel), $this->escape($aggregation)]); } + + /** + * Press a given action from the action menu in a given report row + * + * @When I press :action action in the :row report row + * + * @param string $action + * @param string $row + */ + public function i_press_action_in_the_report_row(string $action, string $row): void { + $this->execute('behat_action_menu::i_open_the_action_menu_in', [$this->escape($row), 'table_row']); + $this->execute('behat_action_menu::i_choose_in_the_open_action_menu', [$this->escape($action)]); + } } diff --git a/reportbuilder/tests/behat/customreports.feature b/reportbuilder/tests/behat/customreports.feature index 37a782ecbb5..afec5984e3c 100644 --- a/reportbuilder/tests/behat/customreports.feature +++ b/reportbuilder/tests/behat/customreports.feature @@ -75,7 +75,7 @@ Feature: Manage custom reports | My report | core_user\reportbuilder\datasource\users | And I log in as "admin" When I navigate to "Reports > Report builder > Custom reports" in site administration - And I click on "Edit report details" "link" in the "My report" "table_row" + When I press "Edit report details" action in the "My report" report row And I set the following fields in the "Edit report details" "dialogue" to these values: | Name | My renamed report | And I click on "Save" "button" in the "Edit report details" "dialogue" @@ -108,7 +108,7 @@ Feature: Manage custom reports | My report | core_user\reportbuilder\datasource\users | And I log in as "admin" When I navigate to "Reports > Report builder > Custom reports" in site administration - And I click on "Delete report" "link" in the "My report" "table_row" + And I press "Delete report" action in the "My report" report row And I click on "Delete" "button" in the "Delete report" "dialogue" Then I should see "Report deleted" And I should see "Nothing to display" @@ -130,17 +130,24 @@ Feature: Manage custom reports Then I should see "Preview" in the "[data-region='core_reportbuilder/report-header']" "css_element" And I should not see "Edit" in the "[data-region='core_reportbuilder/report-header']" "css_element" - Scenario Outline: Access report clicking on the report name or view icon + Scenario: Access report clicking on the report name Given the following "core_reportbuilder > Reports" exist: | name | source | | My report | core_user\reportbuilder\datasource\users | When I log in as "admin" And I navigate to "Reports > Report builder > Custom reports" in site administration - And I click on "" "link" in the "My report" "table_row" - Then "Preview" in the "[data-region='core_reportbuilder/report']" "css_element" - And "Edit" in the "[data-region='core_reportbuilder/report']" "css_element" - And "button[title='Filters']" "css_element" in the "[data-region='core_reportbuilder/report']" "css_element" - Examples: - | link | previewvisible | editvisible | filtersvisible | - | My report | I should see | I should not see | should not exist | - | View | I should not see | I should not see | should exist | + And I click on "My report" "link" in the "My report" "table_row" + Then I should see "Preview" in the "[data-region='core_reportbuilder/report']" "css_element" + And I should not see "Edit" in the "[data-region='core_reportbuilder/report']" "css_element" + And "button[title='Filters']" "css_element" should not exist in the "[data-region='core_reportbuilder/report']" "css_element" + + Scenario: Access report clicking on the view icon + Given the following "core_reportbuilder > Reports" exist: + | name | source | + | My report | core_user\reportbuilder\datasource\users | + When I log in as "admin" + And I navigate to "Reports > Report builder > Custom reports" in site administration + And I press "View" action in the "My report" report row + Then I should not see "Preview" in the "[data-region='core_reportbuilder/report']" "css_element" + And I should not see "Edit" in the "[data-region='core_reportbuilder/report']" "css_element" + And "button[title='Filters']" "css_element" should exist in the "[data-region='core_reportbuilder/report']" "css_element" diff --git a/reportbuilder/tests/behat/schedules.feature b/reportbuilder/tests/behat/schedules.feature index 498575493b6..dede1eace80 100644 --- a/reportbuilder/tests/behat/schedules.feature +++ b/reportbuilder/tests/behat/schedules.feature @@ -70,7 +70,7 @@ Feature: Manage custom report schedules | My report | My schedule | And I am on the "My report" "reportbuilder > Editor" page logged in as "admin" And I click on the "Schedules" dynamic tab - When I click on "Edit schedule details" "link" in the "My schedule" "table_row" + When I press "Edit schedule details" action in the "My schedule" report row And I set the following fields in the "Edit schedule details" "dialogue" to these values: | Name | My updated schedule | | Starting from | ##tomorrow 11:00## | @@ -87,7 +87,7 @@ Feature: Manage custom report schedules | My report | My schedule | And I am on the "My report" "reportbuilder > Editor" page logged in as "admin" And I click on the "Schedules" dynamic tab - When I click on "Send schedule" "link" in the "My schedule" "table_row" + When I press "Send schedule" action in the "My schedule" report row And I click on "Confirm" "button" in the "Send schedule" "dialogue" Then I should see "Schedule sent" @@ -97,7 +97,7 @@ Feature: Manage custom report schedules | My report | My schedule | And I am on the "My report" "reportbuilder > Editor" page logged in as "admin" And I click on the "Schedules" dynamic tab - When I click on "Delete schedule" "link" in the "My schedule" "table_row" + When I press "Delete schedule" action in the "My schedule" report row And I click on "Delete" "button" in the "Delete schedule" "dialogue" Then I should see "Schedule deleted" And I should see "Nothing to display" -- 2.43.0