From 052379fc74ea17e1c38816012ae9fbc06de9c8e1 Mon Sep 17 00:00:00 2001 From: PanSpagetka Date: Tue, 11 Jun 2019 16:27:42 +0200 Subject: [PATCH] Code styling --- .../miq_request_methods.rb | 24 ++++++++----------- app/javascript/components/taggingWrapper.jsx | 4 ++-- app/javascript/miq-redux/middleware.js | 2 +- .../spec/miq-redux/middleware.spec.js | 2 +- app/views/miq_request/_prov_field.html.haml | 2 +- 5 files changed, 15 insertions(+), 19 deletions(-) diff --git a/app/controllers/application_controller/miq_request_methods.rb b/app/controllers/application_controller/miq_request_methods.rb index 2bf378fe40d6..a8cfe90448f1 100644 --- a/app/controllers/application_controller/miq_request_methods.rb +++ b/app/controllers/application_controller/miq_request_methods.rb @@ -986,16 +986,16 @@ def workflow_instance_from_vars(req) def build_tags_tree(wf, vm_tags, edit_mode) # for some reason @tags is set in wf, and it is changed by map bellow which causes bugs wf.instance_variable_set(:@tags, nil) - tags = wf.allowed_tags - tags.each do |cat| - cat[:values] = cat[:children].map do |tag| - { :id => tag.first, :description => tag.second[:description] } - end - cat[:id] = cat[:name] - cat[:singleValue] = cat[:single_value] - cat.delete(:children) - cat.delete(:name) - end + tags = wf.allowed_tags.map do |cat| + { + :values => cat[:children].map do |tag| + {:id => tag.first, :description => tag.second[:description]} + end, + :id => cat[:name], + :description => cat[:description], + :singleValue => cat[:single_value], + } + end assignments = Classification.select { |tag| vm_tags.include?(tag.id) } assigned_tags = assignments.map do |tag| @@ -1008,10 +1008,6 @@ def build_tags_tree(wf, vm_tags, edit_mode) } end.uniq - @button_urls = { - :save_url => '', - :cancel_url => '' - } @tags = {:tags => tags, :assignedTags => assigned_tags, :affectedItems => []} end diff --git a/app/javascript/components/taggingWrapper.jsx b/app/javascript/components/taggingWrapper.jsx index cb613ff4ff1e..21f1729ee1aa 100644 --- a/app/javascript/components/taggingWrapper.jsx +++ b/app/javascript/components/taggingWrapper.jsx @@ -21,7 +21,7 @@ const params = (type = 'default', state, tag = {}) => ({ })[type] const onDelete = (type = 'default', params = [], deleted_element) => ({ - provision: {...params, ids_checked: params.ids_checked.filter(element => element !== deleted_element)}, + provision: {...params, check: 0, ids_checked: params.ids_checked.filter(element => element !== deleted_element)}, default: params, })[type] @@ -85,7 +85,7 @@ TaggingWrapper.propTypes = { urls: PropTypes.shape({ cancel_url: PropTypes.string.isRequired, save_url: PropTypes.string.isRequired, - }).isRequired, + }), tags: PropTypes.shape({ tags: PropTypes.arrayOf(PropTypes.shape({ id: PropTypes.number.isRequired, diff --git a/app/javascript/miq-redux/middleware.js b/app/javascript/miq-redux/middleware.js index cc13e1f16c85..b1008d151957 100644 --- a/app/javascript/miq-redux/middleware.js +++ b/app/javascript/miq-redux/middleware.js @@ -10,7 +10,7 @@ export const taggingMiddleware = store => next => action => { $.post(meta.url, params) } else if (type === 'UI-COMPONENTS_TAGGING_DELETE_ASSIGNED_TAG') { params = meta.onDelete(meta.type, params, tag.tagValue.id); - $.post(meta.url, {...params, check: 0}) + $.post(meta.url, params) } } let result = next(action) diff --git a/app/javascript/spec/miq-redux/middleware.spec.js b/app/javascript/spec/miq-redux/middleware.spec.js index 668c39a162a6..9e904f75474d 100644 --- a/app/javascript/spec/miq-redux/middleware.spec.js +++ b/app/javascript/spec/miq-redux/middleware.spec.js @@ -31,7 +31,7 @@ it('calls post for UI-COMPONENTS_TAGGING_TOGGLE_TAG_VALUE_CHANGE action', () => }; const action = { type: 'UI-COMPONENTS_TAGGING_TOGGLE_TAG_VALUE_CHANGE', meta: { url: 'url/bla', params: jest.fn() }, tag: {tagCategory: {id: 1}, tagValue: { id:2 }}} taggingMiddleware(store)(next)(action); - expect(next.mock.calls).toEqual( [[{"meta": {"url": "url/bla", "params": [Function mockConstructor]}, "tag": {"tagCategory": {"id": 1}, "tagValue": {"id": 2}}, "type": "UI-COMPONENTS_TAGGING_TOGGLE_TAG_VALUE_CHANGE"}]]); + expect(next.mock.calls).toEqual( [[{"meta": {"url": "url/bla", "params": jest.fn()}, "tag": {"tagCategory": {"id": 1}, "tagValue": {"id": 2}}, "type": "UI-COMPONENTS_TAGGING_TOGGLE_TAG_VALUE_CHANGE"}]]); expect(spy).toHaveBeenCalledWith("url/bla", {"cat": 1, "check": 1, "id": {}, "tree_typ": "tags", "val": 2}); }); diff --git a/app/views/miq_request/_prov_field.html.haml b/app/views/miq_request/_prov_field.html.haml index e11d1b074934..4f293cdc092b 100644 --- a/app/views/miq_request/_prov_field.html.haml +++ b/app/views/miq_request/_prov_field.html.haml @@ -298,7 +298,7 @@ - check = @miq_request.id - else - check = 'new' - = react 'TaggingWrapperConnected', { :tags => @tags, :urls => @button_urls, :options => { :type => 'provision', :hideHeaders => true, :hideButtons => true, :url => url_for_only_path(:action => 'prov_field_changed')} } + = react 'TaggingWrapperConnected', { :tags => @tags, :options => { :type => 'provision', :hideHeaders => true, :hideButtons => true, :url => url_for_only_path(:action => 'prov_field_changed')} } - unless field_hash[:notes_display] == :hide || field_hash[:notes].blank? -# Display notes if available = field_hash[:notes]