FIX: Clearing inventory item filter fails with 500 or breaks UI [SCI-9345] (#6358)

This commit is contained in:
Soufiane 2023-10-24 16:05:35 +02:00 committed by GitHub
parent 809aaa8aa3
commit 9809f696a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 8 deletions

View file

@ -72,6 +72,7 @@ window.initRepositoryFilter = () => {
{ id: 'archived_by', name: I18n.t('repositories.table.archived_by'), data_type: 'RepositoryUserValue' },
{ id: 'archived_on', name: I18n.t('repositories.table.archived_on'), data_type: 'RepositoryDateTimeValue' }
];
const defFilters = JSON.parse(JSON.stringify(DEFAULT_FILTERS));
const repositoryFilterContainer = new Vue({
el: '#filterContainer',
data: () => ({
@ -120,12 +121,12 @@ window.initRepositoryFilter = () => {
this.reloadDataTable();
},
clearFilters() {
this.filters = this.filters
.map(filter => {
const newFilter = { ...filter };
newFilter.data["parameters"] = {};
return newFilter;
});
this.filters.forEach((filter, index) => {
const newFilter = { ...filter };
newFilter.data['parameters'] = {};
newFilter.data['operator'] = defFilters[index].data['operator'];
return newFilter;
});
this.filterName = null;
this.dataTableElement.removeAttr('data-repository-filter-json');
$('#modalSaveRepositoryTableFilter').data('repositoryTableFilterId', null);

View file

@ -168,6 +168,8 @@ class RepositoryDatatableService
end
def build_row_id_filter_condition(repository_rows, filter_element_params)
return repository_rows if filter_element_params.dig(:parameters, :text).blank?
case filter_element_params[:operator]
when 'contains'
repository_rows
@ -183,6 +185,8 @@ class RepositoryDatatableService
end
def build_name_filter_condition(repository_rows, filter_element_params)
return repository_rows if filter_element_params.dig(:parameters, :text).blank?
case filter_element_params[:operator]
when 'contains'
repository_rows.where('repository_rows.name ILIKE ?',
@ -351,14 +355,16 @@ class RepositoryDatatableService
end
def build_assigned_filter_condition(repository_rows, filter_element_params)
return repository_rows if filter_element_params.dig(:parameters, :my_module_ids).blank?
case filter_element_params[:operator]
when 'any_of'
repository_rows.joins(:my_modules)
.where(my_modules: { id: filter_element_params.dig(:parameters, :my_module_ids) })
when 'none_of'
repository_rows.where('NOT EXISTS (SELECT NULL FROM my_module_repository_rows
WHERE my_module_repository_rows.repository_row_id = repository_rows.id AND
my_module_repository_rows.my_module_id IN (?))', filter_element_params.dig(:parameters, :my_module_ids))
WHERE my_module_repository_rows.repository_row_id = repository_rows.id AND
my_module_repository_rows.my_module_id IN (?))', filter_element_params.dig(:parameters, :my_module_ids))
when 'all_of'
repository_rows
.joins(:my_modules)