Table filters refactor (#5086)

- Fix a couple of bugs
- Code cleanup
This commit is contained in:
Oliver 2023-06-22 10:29:14 +10:00 committed by GitHub
parent deffcc2814
commit 693d24b4b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 18 additions and 42 deletions

View File

@ -1086,11 +1086,7 @@ function loadBuildOutputTable(build_info, options={}) {
params.is_building = true;
params.build = build_info.pk;
var filters = {};
for (var key in params) {
filters[key] = params[key];
}
var filters = Object.assign({}, params);
setupFilterList('builditems', $(table), options.filterTarget || '#filter-list-incompletebuilditems', {
labels: {

View File

@ -74,8 +74,7 @@ function loadTableFilters(tableKey, query={}) {
});
// Override configurable filters with hard-coded query
Object.assign(filters, query);
filters = Object.assign(filters, query);
return filters;
}
@ -488,9 +487,9 @@ function setupFilterList(tableKey, table, target, options={}) {
`);
for (var key in filters) {
var value = getFilterOptionValue(tableKey, key, filters[key]);
var title = getFilterTitle(tableKey, key);
var description = getFilterDescription(tableKey, key);
let value = getFilterOptionValue(tableKey, key, filters[key]);
let title = getFilterTitle(tableKey, key);
let description = getFilterDescription(tableKey, key);
var filter_tag = `
<div title='${description}' class='filter-tag'>

View File

@ -1895,11 +1895,7 @@ function loadRelatedPartsTable(table, part_id, options={}) {
options.params.part = part_id;
var filters = {};
for (var key in options.params) {
filters[key] = options.params[key];
}
var filters = Object.assign({}, options.params);
setupFilterList('related', $(table), options.filterTarget);
@ -2242,8 +2238,6 @@ function loadPartTable(table, url, options={}) {
// Ensure category detail is included
options.params['category_detail'] = true;
var params = options.params || {};
let filters = {};
if (!options.disableFilters) {
@ -2268,6 +2262,9 @@ function loadPartTable(table, url, options={}) {
});
}
// Update fields with passed parameters
filters = Object.assign(filters, options.params);
var columns = [
{
field: 'pk',
@ -2435,7 +2432,7 @@ function loadPartTable(table, url, options={}) {
name: table_name,
queryParams: filters,
groupBy: false,
original: params,
original: options.params,
sidePagination: 'server',
pagination: 'true',
formatNoMatches: function() {
@ -2781,10 +2778,7 @@ function loadPartTestTemplateTable(table, options) {
setupFilterList('parttests', table, filterListElement);
// Override the default values, or add new ones
for (var key in params) {
filters[key] = params[key];
}
filters = Object.assign(filters, params);
table.inventreeTable({
method: 'get',

View File

@ -1886,10 +1886,7 @@ function loadStockTable(table, options) {
});
}
// Override the default values, or add new ones
for (var key in params) {
filters[key] = params[key];
}
filters = Object.assign(filters, params);
var col = null;
@ -2450,9 +2447,7 @@ function loadStockLocationTable(table, options) {
plural_name: '{% trans "stock locations" %}',
});
for (var key in params) {
filters[key] = params[key];
}
filters = Object.assign(filters, params);
// Function to request sub-location items
function requestSubItems(parent_pk) {

View File

@ -471,7 +471,7 @@ function getBuildTableFilters() {
async: false,
success: function(response) {
for (var key in response) {
var owner = response[key];
let owner = response[key];
ownersList[owner.pk] = {
key: owner.pk,
value: `${owner.name} (${owner.label})`,

View File

@ -252,17 +252,11 @@ function reloadTableFilters(table, filters, options={}) {
options = table.bootstrapTable('getOptions');
// Construct a new list of filters to use for the query
var params = {};
for (var k in filters) {
params[k] = filters[k];
}
let params = Object.assign({}, filters);
// Original query params will override
if (options.original != null) {
for (var key in options.original) {
params[key] = options.original[key];
}
if (options.original) {
params = Object.assign(params, options.original);
}
// Store the total set of query params
@ -318,9 +312,7 @@ function convertQueryParameters(params, filters) {
}
for (var key in filters) {
params[key] = filters[key];
}
params = Object.assign(params, filters);
// Add "order" back in (if it was originally specified by InvenTree)
// Annoyingly, "order" shadows some field names in InvenTree...