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

(BIDS-2531) add filter for online/offline, fix all count #2638

Merged
merged 3 commits into from
Nov 2, 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
4 changes: 4 additions & 0 deletions handlers/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ func parseValidatorsDataQueryParams(r *http.Request) (*ValidatorsDataQueryParams
filterByState := q.Get("filterByState")
var qryStateFilter string
switch filterByState {
case "online":
qryStateFilter = "WHERE validators.status LIKE '%online'"
case "offline":
qryStateFilter = "WHERE validators.status LIKE '%offline'"
case "pending":
qryStateFilter = "WHERE validators.status = 'pending'"
case "active":
Expand Down
11 changes: 8 additions & 3 deletions templates/validators.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,22 @@
const exitingOfflineCount = {{.ExitingOfflineCount}};
const exitedCount = {{.ExitedCount}};
const voluntaryExitsCount = {{.VoluntaryExitsCount}};
const onlineCount = {{.ActiveOnlineCount}} + {{.SlashingOnlineCount}} + {{.ExitingOnlineCount}}
const offlineCount = {{.ActiveOfflineCount}} + {{.SlashingOfflineCount}} + {{.ExitingOfflineCount}}

var stateFilterDropDownHtml = `<div><label>
<div class="dropdown" style="display:inline-block;">
<button class="btn btn-primary dropdown-toggle text-white" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"><span>All ${totalCount}</span></button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<h6 class="dropdown-header"><span>Filter state</span> <span><span class="text-success">online</span> | <span class="text-danger">offline</span></span></h6>
<hr style="margin:0.5rem 0">
<a class="dropdown-item" href="#all" data-filter-validators="all"><span>All</span> <span>${totalCount}</span></a>
<a class="dropdown-item" href="#deposited" data-filter-validators="deposited"><span>Deposited</span> <span>${depositedCount}</span></a>
<a class="dropdown-item" href="#pending" data-filter-validators="pending"><span>Pending</span> <span>${pendingCount}</span></a>
<a class="dropdown-item" href="#online" data-filter-validators="online"><span>Online</span> <span>${onlineCount}</span></a>
<a class="dropdown-item" href="#offline" data-filter-validators="offline"><span>Offline</span> <span>${offlineCount}</span></a>
<a class="dropdown-item" href="#active" data-filter-validators="active"><span>Active</span><span> <span class="text-success">${activeOnlineCount}</span> | <span class="text-danger">${activeOfflineCount}</span></span></a>
<a class="dropdown-item" href="#slashing" data-filter-validators="slashing"><span>Slashing</span><span> <span class="text-success">${slashingOnlineCount}</span> | <span class="text-danger">${slashingOfflineCount}</span></span></a>
<a class="dropdown-item" href="#deposited" data-filter-validators="deposited"><span>Deposited</span> <span>${depositedCount}</span></a>
<a class="dropdown-item" href="#pending" data-filter-validators="pending"><span>Pending</span> <span>${pendingCount}</span></a>
<a class="dropdown-item" href="#exiting" data-filter-validators="exiting"><span>Exiting</span><span> <span class="text-success">${exitingOnlineCount}</span> | <span class="text-danger">${exitingOfflineCount}</span></span></a>
<a class="dropdown-item" href="#exited" data-filter-validators="exited"><span>Exited</span> <span>${exitedCount}</span></a>
<a class="dropdown-item" href="#voluntary" data-filter-validators="voluntary"><span>Vol. Exits</span> <span>${voluntaryExitsCount}</span></a>
Expand All @@ -38,7 +43,7 @@ <h6 class="dropdown-header"><span>Filter state</span> <span><span class="text-su
$(`.filter-by-status a[data-filter-validators=${state}]`).addClass('active');
$('.filter-by-status .btn:first-child').html($(`.filter-by-status a[data-filter-validators=${state}]`).html());
// 0pubkey, 1idx, 2bal, 3state, 4active, 5exit, 6withdraw, 7lastattest, 8slashed
if (state === "all") {
if (state === "all" || state === "offline" || state === "online") {
validatorsDataTable.column(3).visible(true);
validatorsDataTable.column(4).visible(true);
validatorsDataTable.column(5).visible(true);
Expand Down