From f2e4c579afb81019a22dfc07c78c7ec141ee5c71 Mon Sep 17 00:00:00 2001 From: aignatov-bio <47317017+aignatov-bio@users.noreply.github.com> Date: Tue, 15 Feb 2022 15:03:25 +0100 Subject: [PATCH] Multiple UX fixes for filters [SCI-6525] (#3858) Co-authored-by: Anton --- app/assets/javascripts/repositories/show.js | 5 ++ .../javascripts/sitewide/dropdown_selector.js | 5 +- .../stylesheets/repository/filters.scss | 64 +++++++++++++++++-- .../vue/repository_filter/container.vue | 1 + .../filters/repositoryDateRangeValue.vue | 1 + .../filters/repositoryDateTimeRangeValue.vue | 1 + .../filters/repositoryDateTimeValue.vue | 26 ++++++-- .../filters/repositoryDateValue.vue | 26 ++++++-- .../filters/repositoryNumberValue.vue | 44 ++++++------- .../filters/repositoryTimeRangeValue.vue | 1 + .../filters/repositoryTimeValue.vue | 1 + .../_save_repository_filter_modal.html.erb | 2 +- .../repositories/_toolbar_buttons.html.erb | 10 +-- config/locales/en.yml | 7 ++ 14 files changed, 145 insertions(+), 49 deletions(-) diff --git a/app/assets/javascripts/repositories/show.js b/app/assets/javascripts/repositories/show.js index dece2dda0..bb574196a 100644 --- a/app/assets/javascripts/repositories/show.js +++ b/app/assets/javascripts/repositories/show.js @@ -202,6 +202,10 @@ $('#modalSaveRepositoryTableFilter #repository_table_filter_name').val(''); }); + $('#modalSaveRepositoryTableFilter').on('shown.bs.modal', function() { + $('#repository_table_filter_name').focus(); + }); + $(document).on('click', '#overwriteFilterLink', function() { var $modal = $('#modalSaveRepositoryTableFilter'); @@ -213,6 +217,7 @@ $modal.removeData('overwrite'); }); + $('#modalSaveRepositoryTableFilter #repository_table_filter_name') .val($modal.data('repositoryTableFilterName')); }); diff --git a/app/assets/javascripts/sitewide/dropdown_selector.js b/app/assets/javascripts/sitewide/dropdown_selector.js index a9d441a97..9f764ae24 100644 --- a/app/assets/javascripts/sitewide/dropdown_selector.js +++ b/app/assets/javascripts/sitewide/dropdown_selector.js @@ -520,6 +520,7 @@ var dropdownSelector = (function() { var customStyle = selector2.data('config').optionStyle; return $(` -
+
- - +
@@ -60,7 +58,6 @@ { value: 'less_than_or_equal_to', label: this.i18n.t('repositories.show.repository_filter.filters.operators.less_than_or_equal_to') }, { value: 'between', label: this.i18n.t('repositories.show.repository_filter.filters.operators.between') } ], - numberRegexp: /[^0-9.]/g, operator: 'equal_to', value: '', from: '', @@ -71,29 +68,24 @@ DropdownSelector }, methods: { - updateRange() { - this.value = { - from: this.from, - to: this.to - }; + validateNumber(number) { + return number.replace(/[^0-9.]/g, '').match(/^\d*(\.\d{0,10})?/)[0] }, }, watch: { - operator() { - if(this.operator !== 'between' && !(typeof this.value === 'string')) this.value = ''; - if(this.operator === 'between') this.value = {to: '', from: ''}; - }, value() { - if (this.operator === 'between') { - this.value = { - from: this.from.replace(this.numberRegexp, '').match(/^\d*(\.\d{0,10})?/)[0], - to: this.to.replace(this.numberRegexp, '').match(/^\d*(\.\d{0,10})?/)[0] - }; - this.parameters = this.value; - } else { - this.value = this.value.replace(this.numberRegexp, '').match(/^\d*(\.\d{0,10})?/)[0] - this.parameters = { number: this.value } - } + this.value = this.validateNumber(this.value) + this.parameters = { number: this.value } + this.updateFilter(); + }, + to() { + this.to = this.validateNumber(this.to) + this.parameters = {from: this.from, to: this.to} + this.updateFilter(); + }, + from() { + this.from = this.validateNumber(this.from) + this.parameters = {from: this.from, to: this.to} this.updateFilter(); } }, diff --git a/app/javascript/vue/repository_filter/filters/repositoryTimeRangeValue.vue b/app/javascript/vue/repository_filter/filters/repositoryTimeRangeValue.vue index d005c9502..6e908633c 100644 --- a/app/javascript/vue/repository_filter/filters/repositoryTimeRangeValue.vue +++ b/app/javascript/vue/repository_filter/filters/repositoryTimeRangeValue.vue @@ -11,6 +11,7 @@
+
diff --git a/app/javascript/vue/repository_filter/filters/repositoryTimeValue.vue b/app/javascript/vue/repository_filter/filters/repositoryTimeValue.vue index feaa8b029..bbe320c3a 100644 --- a/app/javascript/vue/repository_filter/filters/repositoryTimeValue.vue +++ b/app/javascript/vue/repository_filter/filters/repositoryTimeValue.vue @@ -12,6 +12,7 @@
+
diff --git a/app/views/repositories/_save_repository_filter_modal.html.erb b/app/views/repositories/_save_repository_filter_modal.html.erb index e2e1a64db..5c6d6a673 100644 --- a/app/views/repositories/_save_repository_filter_modal.html.erb +++ b/app/views/repositories/_save_repository_filter_modal.html.erb @@ -11,7 +11,7 @@
- +
diff --git a/app/views/repositories/_toolbar_buttons.html.erb b/app/views/repositories/_toolbar_buttons.html.erb index 16b35f50e..dfb91b8f9 100644 --- a/app/views/repositories/_toolbar_buttons.html.erb +++ b/app/views/repositories/_toolbar_buttons.html.erb @@ -24,7 +24,7 @@ -