Skip to content

Commit

Permalink
(BIDS-2481) Fixed dashboard datatables
Browse files Browse the repository at this point in the history
  • Loading branch information
Eisei24 committed Sep 20, 2023
1 parent c309893 commit a29b4ae
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
15 changes: 4 additions & 11 deletions static/js/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,6 @@ $(document).ready(function () {
window.dispatchEvent(new CustomEvent("dashboard_validators_set"))

if (state.validators.length) {
var uRLSearchParams = new URLSearchParams([["validators", state.validators.join(",")]])
var qryStr = "?validators=" + state.validators.join(",")
if (window.location.search != qryStr) {
var newUrl = window.location.pathname + qryStr + window.location.hash
Expand All @@ -1183,7 +1182,7 @@ $(document).ready(function () {
document.querySelector("#clear-search").style.visibility = "visible"

$.ajax({
url: dataTableLoader("/dashboard/data/validators", uRLSearchParams),
url: "/dashboard/data/validators" + qryStr,
success: function (result) {
var t1 = Date.now()
console.log(`loaded validators-data: length: ${result.data.length}, fetch: ${t1 - t0}ms`)
Expand Down Expand Up @@ -1234,7 +1233,7 @@ $(document).ready(function () {
document.querySelector("#bookmark-button").style.visibility = "visible"

$.ajax({
url: dataTableLoader("/dashboard/data/earnings", uRLSearchParams),
url: "/dashboard/data/earnings" + qryStr,
success: function (result) {
var t1 = Date.now()
console.log(`loaded earnings: fetch: ${t1 - t0}ms`)
Expand Down Expand Up @@ -1321,13 +1320,7 @@ $(document).ready(function () {
function renderCharts() {
var t0 = Date.now()
$.ajax({
url: dataTableLoader(
"/dashboard/data/allbalances",
new URLSearchParams([
["validators", state.validators.join(",")],
["days", "31"],
])
),
url: "/dashboard/data/allbalances?validators=" + state.validators.join(",") + "&days=31",
success: function (result) {
var t1 = Date.now()
createIncomeChart(result.consensusChartData, result.executionChartData)
Expand All @@ -1338,7 +1331,7 @@ $(document).ready(function () {
},
})
$.ajax({
url: dataTableLoader("/dashboard/data/proposals", new URLSearchParams([["validators", state.validators.join(",")]])),
url: "/dashboard/data/proposals?validators=" + state.validators.join(","),
success: function (result) {
var t1 = Date.now()
if (result && result.length) {
Expand Down
9 changes: 7 additions & 2 deletions static/js/datatable_loader.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/**
* function dataTableLoader(path)
* function dataTableLoader(path, param)
* used to create an ajax function for a DataTable.
* This function is used to load data from the server for a DataTable.
* It is debounced to avoid multiple requests to the server when the user clicks on the pagination buttons.
* There is also a retry mechanism that retries the server request if the request fails.
* @param path: Path to load the table data from the server
* @param param: Additional parameters to be passed to the server
* @param dataSrc: Function to be called on the data returned from the server
*/
function dataTableLoader(path, param) {
function dataTableLoader(path, param, dataSrc) {
const MAX_RETRIES = 5
const DEBOUNCE_DELAY = 500
const RETRY_DELAY = 1000
Expand All @@ -33,6 +35,9 @@ function dataTableLoader(path, param) {
return response.json()
})
.then((data) => {
if (typeof dataSrc === "function") {
data = dataSrc({ data })
}
callback(data)
})
.catch((err) => {
Expand Down
7 changes: 2 additions & 5 deletions templates/validator/tables.html
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,7 @@
order: [[0, 'desc']],
lengthChange: false,
searching: false,
ajax: {
url: dataTableLoader(`/validator/${index}/withdrawals`),
dataSrc: function ( { data } ) {
ajax: dataTableLoader(`/validator/${index}/withdrawals`, "", function ( {data} ) {
// add the estimate row if it exists
{{ if .NextWithdrawalRow }}
let row = {{.NextWithdrawalRow}}
Expand All @@ -207,8 +205,7 @@
}
{{ end }}
return data
},
},
}),
pagingType: 'input',
pageLength: 10,
language: {
Expand Down

0 comments on commit a29b4ae

Please sign in to comment.