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

fix: BUG 131913 stop losing the filter text when filtering the test history #2952

Merged
merged 1 commit into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 8 additions & 1 deletion www/assets/js/history-loggedin.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,19 @@

function handleDaySelector() {
const daySelector = document.querySelector("select[name=days]");
const filter = document.getElementById('filter');

daySelector.addEventListener("change", (e) => {
const days = e.target.value;
const protocol = window.location.protocol;
const hostname = window.location.hostname;
const redirectUri = protocol + "//" + hostname + "/testlog/" + days + "/";

if (filter.value) {
document.querySelector('form[name=filterLog]').submit();
return;
}

const redirectUri = protocol + "//" + hostname + "/testlog/" + days + "/";
window.location = redirectUri;
});
}
Expand Down
2 changes: 1 addition & 1 deletion www/resources/views/pages/testhistory.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<div class="history_filter">
<label for="filter">Filter test history:</label>
<input id="filter" name="filter" type="text" onkeyup="filterHistory()" placeholder="Search">
<input id="filter" name="filter" type="text" onkeyup="filterHistory()" placeholder="Search" value="{{ $filter ?? '' }}">
@if ($is_logged_in)
<label for="days" class="a11y-hidden">Select how far back you want to see</label>
<select name="days" id="days">
Expand Down
7 changes: 4 additions & 3 deletions www/testlog.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
$csv = isset($_GET['f']) && !strcasecmp($_GET['f'], 'csv');
$priority = (isset($_REQUEST['priority']) && is_numeric($_REQUEST['priority'])) ? intval($_REQUEST['priority']) : null;
$days = (int)($_GET['days'] ?? 7);
$filter = $_GET["filter"];
$filterstr = $filter ? preg_replace('/[^a-zA-Z0-9 \@\/\:\.\(\))\-\+]/', '', strtolower($filter)) : null;


$GLOBALS['tab'] = 'Test History';
$GLOBALS['page_description'] = 'History of website performance speed tests run on WebPageTest.';
Expand All @@ -52,7 +55,7 @@
'local' => isset($_REQUEST['local']) && $_REQUEST['local'],
'body_class' => 'history',
'page_title' => 'WebPageTest - Test History',

'filter' => $filterstr
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you have the regex above, but I'd just use htmlspecialchars() https://www.php.net/htmlspecialchars

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey jeff since its being rendered on a blade template it should be going through this function already, should we add anyway?

image

https://laravel.com/docs/10.x/blade

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh that's right! nice catch. spaced the whole "this is on blade" thing.

];

echo view('pages.testhistory', $vars);
Expand All @@ -70,8 +73,6 @@
}

$from = (isset($_GET["from"]) && strlen($_GET["from"])) ? $_GET["from"] : 'now';
$filter = $_GET["filter"];
$filterstr = $filter ? preg_replace('/[^a-zA-Z0-9 \@\/\:\.\(\))\-\+]/', '', strtolower($filter)) : null;
$onlyVideo = !empty($_REQUEST['video']);
$all = ($admin || !Util::getSetting('forcePrivate')) && !empty($_REQUEST['all']);
$repeat = !empty($_REQUEST['repeat']);
Expand Down