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

Add a basic search functionality #871

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
72 changes: 70 additions & 2 deletions report/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,48 @@
{% block content %}

<style>
.search-container {
margin: 20px 0;
max-width: 600px;
position: relative;
}

.search-container input {
width: 100%;
padding: 8px 12px;
font-size: 16px;
border: 2px solid gainsboro;
border-radius: 5px;
background-color: white;
transition: all 0.3s ease;
outline: none;
color: black;
}

.search-container::before {
content: "🔍";
position: absolute;
right: 24px;
top: 50%;
transform: translateY(-50%);
font-size: 18px;
pointer-events: none;
transition: color 0.3s ease;
}

.search-container input::placeholder {
color: #555;
font-weight: 300;
}

.search-container input:focus {
border-color: 'skyblue';
}

.search-container:focus-within::before {
color: 'skyblue';
}

td .benchmark .function,
td .signature {
overflow-wrap: anywhere;
Expand Down Expand Up @@ -64,6 +106,10 @@

</style>

<div class="search-container">
<input type="text" id="searchInput" placeholder="Search...">
</div>

<table class="sortable-table" id="benchmark-table">
<thead>
<tr>
Expand All @@ -79,7 +125,9 @@
</thead>
<tbody>
{% for benchmark in benchmarks %}
<tr>
<tr class="searchable-row"
data-project="{{ benchmark.project }}"
data-benchmark="{{ benchmark.signature }}">
<td class="table-index">{{ loop.index }}</td>
<td data-sort-value="{{ benchmark.id }}">
<div class="project">{{ benchmark.project }}</div>
Expand Down Expand Up @@ -116,7 +164,8 @@ <h2>Project summary</h2>
</thead>
<tbody>
{% for project in projects %}
<tr>
<tr class="searchable-row"
data-project="{{ project.name }}">
<td class="table-index">{{ loop.index }}</td>
<td data-sort-value="{{ project.name }}">{{ project.name }}</td>
<td data-sort-value="{{ project.count }}">{{ project.count }}</td>
Expand Down Expand Up @@ -269,5 +318,24 @@ <h2>Accumulated results</h2>

}
})();

document.getElementById('searchInput').addEventListener('input', function(e) {
const searchTerm = e.target.value.toLowerCase();
const rows = document.getElementsByClassName('searchable-row');

Array.from(rows).forEach(row => {
// TODO(myanvoos): Expand search criteria
const project = row.dataset.project.toLowerCase();

let matches = project.includes(searchTerm)

if (row.dataset.benchmark) {
const benchmark = row.dataset.benchmark.toLowerCase();
matches = matches || benchmark.includes(searchTerm);
}

row.style.display = matches ? '' : 'none';
});
});
</script>
{% endblock %}