diff --git a/public/grade/report/singleview/index.php b/public/grade/report/singleview/index.php index 22899ac7872..c9da93e1a69 100644 --- a/public/grade/report/singleview/index.php +++ b/public/grade/report/singleview/index.php @@ -31,6 +31,7 @@ require_once($CFG->dirroot.'/grade/report/lib.php'); $courseid = required_param('id', PARAM_INT); $groupid = optional_param('group', null, PARAM_INT); +$reset = optional_param('reset', 0, PARAM_BOOL); // Making this work with profile reports. $userid = optional_param('userid', null, PARAM_INT); @@ -105,7 +106,7 @@ switch ($itemtype) { } // If the item id (user id) cannot be defined or the user id is not part of the list of gradable users, // display the user select zero state. - if (is_null($itemid) || !array_key_exists($itemid, grade_report::get_gradable_users($courseid, $currentgroup))) { + if (is_null($itemid) || !array_key_exists($itemid, grade_report::get_gradable_users($courseid, $currentgroup)) || $reset) { $itemtype = 'user_select'; unset($SESSION->gradereport_singleview["useritem-{$context->id}"]); } diff --git a/public/grade/report/singleview/renderer.php b/public/grade/report/singleview/renderer.php index 8853f861a9c..737c7cef63a 100644 --- a/public/grade/report/singleview/renderer.php +++ b/public/grade/report/singleview/renderer.php @@ -46,7 +46,11 @@ class gradereport_singleview_renderer extends plugin_renderer_base { */ public function users_selector(object $course, ?int $userid = null, ?int $groupid = null): string { $courserenderer = $this->page->get_renderer('core', 'course'); - $resetlink = new moodle_url('/grade/report/singleview/index.php', ['id' => $course->id, 'group' => $groupid ?? 0]); + $resetlink = new moodle_url('/grade/report/singleview/index.php', [ + 'id' => $course->id, + 'group' => $groupid ?? 0, + 'reset' => 1, + ]); $usersearch = ''; if ($userid) { diff --git a/public/grade/report/singleview/tests/behat/usersearch.feature b/public/grade/report/singleview/tests/behat/usersearch.feature index d47cfb08812..9584d187446 100644 --- a/public/grade/report/singleview/tests/behat/usersearch.feature +++ b/public/grade/report/singleview/tests/behat/usersearch.feature @@ -220,3 +220,22 @@ Feature: Within the singleview report, a teacher can search for users. And the focused element is "Clear search input" "button" in the ".user-search" "css_element" And I press the enter key And I confirm "Turtle Manatee" does not exist in the "Search users" search combo box + + Scenario: A teacher can clear the search and reload the page to show no student details + # A teacher searches for and selects a specific user. + Given I set the field "Search users" to "Turtle" + And I wait until "Turtle Manatee" "option_role" exists + When I click on "Turtle Manatee" "list_item" + # After selection, page reloads and displays only that user. + And I wait until the page is ready + Then "Turtle Manatee" "heading" should exist + # Search input retains the selected user for context. + And the field "Search users" matches value "Turtle Manatee" + + # Teacher clicks the Clear link to reset the search and reload the page. + When I click on "Clear" "link" + # Page reloads with search field cleared and no student details displayed (empty state). + And I wait until the page is ready + Then the field "Search users" matches value "" + # All student headings should disappear (no students shown on empty state). + And "Turtle Manatee" "heading" should not exist diff --git a/public/grade/report/user/classes/output/action_bar.php b/public/grade/report/user/classes/output/action_bar.php index fbdebc3f92b..7908045c70e 100644 --- a/public/grade/report/user/classes/output/action_bar.php +++ b/public/grade/report/user/classes/output/action_bar.php @@ -97,7 +97,7 @@ class action_bar extends \core_grades\output\action_bar { $data['groupselector'] = $groupselector->export_for_template($output); } - $resetlink = new moodle_url('/grade/report/user/index.php', ['id' => $courseid, 'group' => 0]); + $resetlink = new moodle_url('/grade/report/user/index.php', ['id' => $courseid, 'group' => 0, 'reset' => 1]); $baseurl = new moodle_url('/grade/report/user/index.php', ['id' => $courseid]); $PAGE->requires->js_call_amd('gradereport_user/user', 'init', [$baseurl->out(false)]); diff --git a/public/grade/report/user/index.php b/public/grade/report/user/index.php index f2a644137d1..9bae87674fc 100644 --- a/public/grade/report/user/index.php +++ b/public/grade/report/user/index.php @@ -31,6 +31,7 @@ $courseid = required_param('id', PARAM_INT); // 0 - view all reports. null - view own report. non-zero and non-null - view other user report. $userid = optional_param('userid', null, PARAM_INT); $userview = optional_param('userview', 0, PARAM_INT); +$reset = optional_param('reset', 0, PARAM_BOOL); $PAGE->set_url(new moodle_url('/grade/report/user/index.php', ['id' => $courseid])); @@ -130,6 +131,10 @@ if (has_capability('moodle/grade:viewall', $context)) { $userid = $USER->id; } + // If the reset parameter is set, clear any stored (last viewed) user in a session variable. + if ($reset) { + unset($SESSION->gradereport_user["useritem-{$context->id}"]); + } // If there is a stored (last viewed) user in a session variable, bypass the user select zero state and display the // report for that user. $lastvieweduserid = $SESSION->gradereport_user["useritem-{$context->id}"] ?? null; diff --git a/public/grade/report/user/tests/behat/usersearch.feature b/public/grade/report/user/tests/behat/usersearch.feature index 0ee9a6e7a63..335aed85ac7 100644 --- a/public/grade/report/user/tests/behat/usersearch.feature +++ b/public/grade/report/user/tests/behat/usersearch.feature @@ -261,3 +261,22 @@ Feature: Within the User report, a teacher can search for users. And "User Test" "heading" should not exist And "Teacher 1" "heading" should not exist And "Turtle Manatee" "heading" should not exist + + Scenario: A teacher can clear the search and reload the page to show no student details + # A teacher searches for and selects a specific user. + Given I set the field "Search users" to "Dummy" + And I wait until "Dummy User" "option_role" exists + When I click on "Dummy User" "list_item" + # After selection, page reloads and displays only that user. + And I wait until the page is ready + Then "Dummy User" "heading" should exist + # Search input retains the selected user for context. + And the field "Search users" matches value "Dummy User" + + # Teacher clicks the Clear link to reset the search and reload the page. + When I click on "Clear" "link" + # Page reloads with search field cleared and no student details displayed (empty state). + And I wait until the page is ready + Then the field "Search users" matches value "" + # All student headings should disappear (no students shown on empty state). + And "Dummy User" "heading" should not exist