Fix advanced filters for ID and Name columns [SCI-6496] (#3865)

This commit is contained in:
Alex Kriuchykhin 2022-02-22 14:49:17 +01:00 committed by GitHub
parent c92dc1fd81
commit dd5939e89d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 63 additions and 8 deletions

View file

@ -21,7 +21,7 @@ const DEFAULT_FILTERS = [
{
id: 2,
column: {
data_type: 'RepositoryTextValue',
data_type: 'RepositoryNonEmptyTextValue',
id: 'row_id',
name: I18n.t('repositories.table.id')
},
@ -31,7 +31,7 @@ const DEFAULT_FILTERS = [
{
id: 3,
column: {
data_type: 'RepositoryTextValue',
data_type: 'RepositoryNonEmptyTextValue',
id: 'row_name',
name: I18n.t('repositories.table.row_name')
},

View file

@ -20,6 +20,7 @@
<script>
// filter types
import RepositoryNonEmptyTextValue from 'vue/repository_filter/filters/repositoryNonEmptyTextValue.vue'
import RepositoryAssetValue from 'vue/repository_filter/filters/repositoryAssetValue.vue'
import RepositoryTextValue from 'vue/repository_filter/filters/repositoryTextValue.vue'
import RepositoryNumberValue from 'vue/repository_filter/filters/repositoryNumberValue.vue'
@ -45,6 +46,7 @@
},
components: {
DropdownSelector,
RepositoryNonEmptyTextValue,
RepositoryAssetValue,
RepositoryTextValue,
RepositoryNumberValue,

View file

@ -0,0 +1,55 @@
<template>
<div class="filter-attributes">
<div class="operator-selector">
<DropdownSelector
:disableSearch="true"
:options="this.operators"
:selectedValue="this.operator"
:selectorId="`OperatorSelector${this.filter.id}`"
@dropdown:changed="updateOperator"
/>
</div>
<div class="sci-input-container">
<input
class="sci-input-field"
type="text"
name="value"
v-model="value"
:placeholder= "this.i18n.t('repositories.show.repository_filter.filters.types.RepositoryNonEmptyTextValue.input_placeholder', {name: this.filter.column.name})"
/>
</div>
</div>
</template>
<script>
import FilterMixin from 'vue/repository_filter/mixins/filter.js'
import DropdownSelector from 'vue/shared/dropdown_selector.vue'
export default {
name: 'RepositoryNonEmptyTextValue',
mixins: [FilterMixin],
data() {
return {
operators: [
{ value: 'contains', label: this.i18n.t('repositories.show.repository_filter.filters.operators.contains') },
{ value: 'doesnt_contain', label: this.i18n.t('repositories.show.repository_filter.filters.operators.does_not_contain') }
],
operator: 'contains',
value: ''
}
},
components: {
DropdownSelector
},
watch: {
value() {
this.parameters = { text: this.value };
this.updateFilter();
}
},
computed: {
isBlank(){
return this.operator == 'contains' && !this.value;
}
}
}
</script>

View file

@ -160,8 +160,6 @@ class RepositoryDatatableService
repository_rows
.where.not("(#{RepositoryRow::PREFIXED_ID_SQL})::text ILIKE ?",
"%#{ActiveRecord::Base.sanitize_sql_like(filter_element_params.dig(:parameters, :text))}%")
when 'empty'
repository_rows.where(id: nil)
else
raise ArgumentError, 'Wrong operator for RepositoryRow ID!'
end
@ -176,8 +174,6 @@ class RepositoryDatatableService
repository_rows
.where.not('repository_rows.name ILIKE ?',
"%#{ActiveRecord::Base.sanitize_sql_like(filter_element_params.dig(:parameters, :text))}%")
when 'empty'
repository_rows.where(name: nil)
else
raise ArgumentError, 'Wrong operator for RepositoryRow Name!'
end

View file

@ -1418,7 +1418,7 @@ en:
filters:
operators:
contains: "Contains"
does_not_contain: "Does not contain"
does_not_contain: "Doesnt contain"
equal_to: "Equal to"
unequal_to: "Not equal to"
greater_than: "Greater than"
@ -1452,6 +1452,8 @@ en:
this_year: "The current calendar year from beginning of 1st January to the end of 31st December"
last_year: "The last calendar year from beginning of 1st January to the end of 31st December"
types:
RepositoryNonEmptyTextValue:
input_placeholder: "Enter %{name}"
RepositoryAssetValue:
input_placeholder: "Enter text"
RepositoryTextValue:
@ -1523,7 +1525,7 @@ en:
name: "Cid"
placeholder: "Enter Cid"
table:
id: 'ID'
id: 'Item ID'
external_id: 'External ID'
assigned: "Assigned"
assigned_tasks: "Assigned to task"