Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mapping Rules] Sorting mapping rules #530

Merged
merged 24 commits into from Mar 1, 2019
Merged

Conversation

didierofrivia
Copy link
Member

@didierofrivia didierofrivia commented Jan 22, 2019

Depends on #658

What this PR does / why we need it:

Feature: Sort mapping rules + last called
feb-25-2019 15-04-32

Which issue(s) this PR fixes

fixes https://issues.jboss.org/browse/THREESCALE-1787

Verification steps

  1. Visit APIcast configuration page
  2. Play with the order of the mapping rules
  3. Profit!

Special notes for your reviewer:

  • Done the easiest way
  • This is meant to be removed in the near future favoring an entire page craft in React using APIcast json schema config.

TODO:

  • Fixing some bugs
  • Cuke
  • Rails part

@didierofrivia didierofrivia self-assigned this Jan 22, 2019
@codecov
Copy link

codecov bot commented Jan 23, 2019

Codecov Report

Merging #530 into master will decrease coverage by <.01%.
The diff coverage is 98.7%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #530      +/-   ##
==========================================
- Coverage   92.79%   92.78%   -0.01%     
==========================================
  Files        2374     2375       +1     
  Lines       76818    76888      +70     
==========================================
+ Hits        71280    71341      +61     
- Misses       5538     5547       +9
Impacted Files Coverage Δ
test/workers/delete_plain_object_worker_test.rb 100% <100%> (ø) ⬆️
test/unit/apicast/proxy_source_test.rb 100% <100%> (ø)
app/models/proxy_rule.rb 98.3% <100%> (+0.05%) ⬆️
test/integration/api/integration_test.rb 100% <100%> (ø) ⬆️
app/controllers/api/integrations_controller.rb 75% <90.9%> (+0.78%) ⬆️
...tegration/api/application_plans_controller_test.rb 88.88% <0%> (-11.12%) ⬇️
app/models/payment_transaction.rb 81.72% <0%> (+1.07%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 184f570...21e6d5a. Read the comment docs.

Copy link
Contributor

@hallelujah hallelujah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok so now we need to save the order in the db
Meaning we need to have a column for the position.
I think we are already doing that for some models.

@hallelujah hallelujah self-assigned this Jan 24, 2019
@didierofrivia
Copy link
Member Author

@hallelujah Only thing needed are what you mentioned.

@didierofrivia didierofrivia force-pushed the feature/sorting-mapping-rules branch 2 times, most recently from eeb5030 to 3c8ffe0 Compare February 11, 2019 16:01
@macejmic macejmic temporarily deployed to preview01 February 25, 2019 14:29 Inactive
@didierofrivia didierofrivia changed the title [WIP] [Mapping Rules] Sorting mapping rules [Mapping Rules] Sorting mapping rules Feb 26, 2019
@didierofrivia didierofrivia temporarily deployed to preview01 February 26, 2019 15:20 Inactive
@didierofrivia didierofrivia requested a review from a team February 26, 2019 15:23
@@ -2,6 +2,7 @@

disabled ||= !rule.new_record? && !@marked_for_update.try(:include?,rule.id.to_s)
html_options = { :disabled => disabled , :class => 'message-when-change' }
index ||= false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same template is used here https://github.com/3scale/porta/pull/530/files#diff-2eeed0d10ff9fe7aedaf9123ec70b297L25 where we are not passing index. So when it tries to access it here: https://github.com/3scale/porta/pull/530/files#diff-8aca4cca05f925b4b00a70b406f9638dR33, it breaks. Do you think it can be better some other way? (consider this integration page is not worthy a major refactor)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK then you could use index = local_assigns[:index] instead of implicit variable assignment. And that will ensure that the variable exists whatever it is. variable ||= boolean is kinda ugly to read :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed hehe, didn't know how to do something like that in ruby basically. thanks!

tr
= render 'api/integrations/apicast/shared/mapping_rule', form: f, rule: rule, metrics: metrics
tr#new-proxy-rule-template style="display:none;"
- @proxy.proxy_rules.ordered.each_with_index do |rule, i|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe an instance variable in the controller or better a presenter instead of @proxy.proxy_rules.ordered

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not convinced this deserves a presenter given the short life expectancy of this integration page. Any other way you might suggest to change this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

jQuery(this).val(jQuery(this).data('selected'))
})
jQuery(function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really needed? As I understand, on drag (start) it adds 4px width on each td where the element was dragged.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you do not add this code, will it be ugly? Can it be done in pure CSS?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly nope, this trick is needed because of jqueryui#sortable lib and the use of tables.

@@ -0,0 +1,5 @@
class AddPositionToMappingRules < ActiveRecord::Migration
def change
add_column :proxy_rules, :position, :integer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does not need a migration to be done from @3scale/operations

@@ -0,0 +1,5 @@
class AddLastToProxyRules < ActiveRecord::Migration
def change
add_column :proxy_rules, :last, :boolean, default: false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a migration to be done by @3scale/operations because it has a NON-NULL default

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@macejmic do not forget to remove that when this is merged #658

db/schema.rb Outdated
@@ -11,7 +11,7 @@
#
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to make the schema for Postgres and Oracle as well. make schema for Oracle IIRC

When I have policies feature enabled
And apicast registry is stubbed
And I go to the integration page for service "one"
Then I should see the Policy Chain

@javascript @selenium
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now @selenium and @javascript are the same
They all both run under chrome-headless

end
end

Given(/^I drag the last mapping rule to the first position$/) do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably good to have it catch first position as (position \d+)

hallelujah
hallelujah previously approved these changes Feb 28, 2019
Copy link
Contributor

@hallelujah hallelujah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, would be nice to have the migration separated from this PR

It will be safe because it is adding a nullable column with a default

* Done the easiest way
* This is meant to remove in the near future favoring an entire page
craft in React using APIcast json schema config.
* Missing some styling
@macejmic macejmic force-pushed the feature/sorting-mapping-rules branch 2 times, most recently from 4f16739 to bd2c29a Compare March 1, 2019 12:37
hallelujah
hallelujah previously approved these changes Mar 1, 2019
@@ -201,6 +203,17 @@ def authorize
authorize! :edit, @service
end

def update_mapping_rules_position
proxy_rules_attributes.each_value do |attrs|
proxy_rule = @proxy.proxy_rules.find_by(id: attrs['id'])
Copy link
Contributor

@hallelujah hallelujah Mar 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that could be to fix codeclimate issue

Suggested change
proxy_rule = @proxy.proxy_rules.find_by(id: attrs['id'])
proxy_rule = @proxy.proxy_rules.find_by(id: attrs['id']) || next

def update_mapping_rules_position
proxy_rules_attributes.each_value do |attrs|
proxy_rule = @proxy.proxy_rules.find_by(id: attrs['id'])
proxy_rule&.set_list_position(attrs['position'])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then remove the nil check

Suggested change
proxy_rule&.set_list_position(attrs['position'])
proxy_rule.set_list_position(attrs['position'])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants