Browse Source

Fixes #3335 - State list of tickets ignore locale for their sorting

Romit Choudhary 3 years ago
parent
commit
26b9eb0281

+ 5 - 11
app/assets/javascripts/app/controllers/_ui_element/_application_ui_element.coffee

@@ -114,27 +114,21 @@ class App.UiElement.ApplicationUiElement
 
         App.Log.debug 'ControllerForm', '_getRelationOptionList:filter-array', attribute.filter
 
+        filter = _.clone(attribute.filter)
+        if !attribute.rejectNonExistentValues && params[ attribute.name ] && !_.contains(filter, params[ attribute.name ])
+          filter.push(params[ attribute.name ])
+
         # check all records
         for record in App[ attribute.relation ].search(sortBy: attribute.sortBy, translate: attribute.translate)
 
           # check all filter attributes
-          for key in attribute.filter
+          for key in filter
 
             # check all filter values as array
             # if it's matching, use it for selection
             if record['id'] is key || ( record['id'] && key && record['id'].toString() is key.toString() )
               list.push record
 
-        # check if current value need to be added
-        if params[ attribute.name ] && !attribute.rejectNonExistentValues
-          hit = false
-          for value in list
-            if value['id'].toString() is params[ attribute.name ].toString()
-              hit = true
-          if !hit
-            currentRecord = App[ attribute.relation ].find(params[ attribute.name ])
-            list.push currentRecord
-
       # no data filter matched
       else
         App.Log.debug 'ControllerForm', '_getRelationOptionList:filter-data no filter matched'

+ 3 - 3
spec/system/ticket/zoom_spec.rb

@@ -923,11 +923,11 @@ RSpec.describe 'Ticket zoom', type: :system do
       let(:user) { create(:customer) }
       let(:ticket) { create(:ticket, customer: user) }
 
-      it 'shows ticket state dropdown options in sorted order, with new at the end' do
+      it 'shows ticket state dropdown options in sorted order' do
         visit "ticket/zoom/#{ticket.id}"
 
         await_empty_ajax_queue
-        expect(all('select[name=state_id] option').map(&:text)).to eq(%w[geschlossen offen neu])
+        expect(all('select[name=state_id] option').map(&:text)).to eq(%w[geschlossen neu offen])
       end
     end
 
@@ -935,7 +935,7 @@ RSpec.describe 'Ticket zoom', type: :system do
       let(:user) { create(:agent, groups: [permitted_group]) }
       let(:permitted_group) { create(:group) }
 
-      it 'shows ticket state dropdown options in sorted order, with new in sorted position' do
+      it 'shows ticket state dropdown options in sorted order' do
         visit 'ticket/create'
 
         await_empty_ajax_queue