refactor: add prepareFilterQuery to utils (#2219)

* refactor: add `prepareFilterQuery` to utils
factored out the preparation of the url params for a paginated table and its requests.
usermanager will also use that.
This commit is contained in:
dni ⚡
2024-01-30 08:05:39 +01:00
committed by GitHub
parent ce9b2c3b77
commit 10944bf100
5 changed files with 37 additions and 33 deletions
+19 -2
View File
@@ -130,8 +130,7 @@ window.LNbits = {
}
)
},
getPayments: function (wallet, query) {
const params = new URLSearchParams(query)
getPayments: function (wallet, params) {
return this.request(
'get',
'/api/v1/payments/paginated?' + params,
@@ -366,6 +365,24 @@ window.LNbits = {
return data
}
},
prepareFilterQuery(tableConfig, props) {
if (props) {
tableConfig.pagination = props.pagination
}
let pagination = tableConfig.pagination
tableConfig.loading = true
const query = {
limit: pagination.rowsPerPage,
offset: (pagination.page - 1) * pagination.rowsPerPage,
sortby: pagination.sortBy ?? '',
direction: pagination.descending ? 'desc' : 'asc',
...tableConfig.filter
}
if (tableConfig.search) {
query.search = tableConfig.search
}
return new URLSearchParams(query)
},
exportCSV: function (columns, data, fileName) {
var wrapCsvValue = function (val, formatFn) {
var formatted = formatFn !== void 0 ? formatFn(val) : val