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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user