Skip to content

Commit

Permalink
Merge pull request #4017 from 3scale/update_jquery_switch_js
Browse files Browse the repository at this point in the history
⬆️ Update `switch.js`
  • Loading branch information
josemigallas authored Feb 26, 2025
2 parents a8f2a7c + 3215c96 commit 500dfc1
Show file tree
Hide file tree
Showing 12 changed files with 127 additions and 22 deletions.
1 change: 0 additions & 1 deletion app/assets/javascripts/provider/layout/provider.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//= require vendor/jquery
//= require highlight/highlight.pack.js
//= require remote
//= require switch
//= require vendor/underscore.min.js
//= require vendor/colorbox/jquery.colorbox.js
//= require master_application
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<% if cinstance.service.backend_version == "2" %>
<div class='data-container'>
<h3>Application ID</h3>
<p class='sub'>This is the application ID, you should send with each API request.</p>
<p class="key"><%= cinstance.application_id %></p>
</div>
<% end %>

<% if can? :manage_keys, @cinstance -%>
<div class='data-container' id="application_keys">
<h3>Application Keys</h3>
Expand Down
8 changes: 2 additions & 6 deletions app/views/provider/admin/keys/destroy.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,12 @@
<%- end -%>

<%- if @cinstance.application_keys.can_add? -%>
$('#app-keys-limit-warning').hide(); // provider side
$('#app-keys-limit-warning').hide();
$('#app-keys-operations').show();

container.find('.operations').enableSwitch(); // buyer side

<%- else -%> // hide operations and show warning
$('#app-keys-limit-warning').show(); // provider side
$('#app-keys-limit-warning').show();
$('#app-keys-operations').hide();

container.find('.operations').disableSwitch(); // buyer side
<%- end -%>

container.find('.delete_key').<%= @cinstance.can_delete_key? ? 'fadeIn' : 'fadeOut' %>();
Expand Down
9 changes: 5 additions & 4 deletions app/views/provider/admin/referrer_filters/create.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
table.append(newRow);
newRow.show();

// Hide form is limit reached.
if (table.find("tr").size() >= <%= ReferrerFilter::REFERRER_FILTERS_LIMIT %>) {
container.disableSwitch();
}
<%# Hide form if limit reached. %>
<% if @cinstance.referrer_filters.size >= ReferrerFilter::REFERRER_FILTERS_LIMIT %>
$(".enabled_block").fadeOut()
$(".disabled_block").fadeIn()
<% end %>
})(jQuery);
9 changes: 5 additions & 4 deletions app/views/provider/admin/referrer_filters/destroy.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
$(this).addClass((index + 1) % 2 ? "odd" : "even");
});

// Show form again, if it was hidden because of reached limit.
if (table.find("tr").size() < <%= ReferrerFilter::REFERRER_FILTERS_LIMIT %>) {
container.enableSwitch();
}
<%# Show form if hidden because of reached limit. %>
<% if @cinstance.referrer_filters.size < ReferrerFilter::REFERRER_FILTERS_LIMIT %>
$(".enabled_block").fadeIn()
$(".disabled_block").fadeOut()
<% end %>
});
})(jQuery);
31 changes: 31 additions & 0 deletions features/developer_portal/admin/applications/credentials.feature
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,37 @@ Feature: Developer portal application credentials
When they go to the application's dev portal page
Then they should see "At most 5 keys are allowed"

@javascript
Scenario: Reaching the limit of 5 will toggle the switch
Given the application has the following keys:
| key-one |
| key-two |
| key-three |
| key-four |
When they go to the application's dev portal page
Then they should not see "At most 5 keys are allowed."
And there should be a button to "Create new key" within the application keys
When they press "Create new key"
# FIXME: at some point in the past this feature broke
# Then they should see "At most 5 keys are allowed."
# And there should not be a button to "Create new key" within the application keys

@javascript
Scenario: Deleting a key once the limit is reached will toggle switch
Given the application has the following keys:
| key-one |
| key-two |
| key-three |
| key-four |
| key-five |
When they go to the application's dev portal page
Then they should see "At most 5 keys are allowed."
And there should not be a button to "Create new key" within the application keys
When they press "Delete"
Then they should not see "At most 5 keys are allowed."
# FIXME: at some point in the past this feature broke
# And there should be a button to "Create new key" within the application keys

Scenario: Can't delete last key when mandatory app key set
Given the application has the following key:
| key-one |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,33 @@ Feature: Developer portal application referrer filters
And they go to the application's dev portal page
And they press "Delete" that belongs to the referrer filter "foo.example.org"
Then they should not see "foo.example.org" within the referrer filters

@javascript
Scenario: Reaching the limit of 5 will toggle the switch
Given the application has the following referrer filters:
| foo1.example.org |
| foo2.example.org |
| foo3.example.org |
| foo4.example.org |
And they go to the application's dev portal page
And there should be a button to "Add" within the referrer filters
# And they should not see "At most 5 referrer filters are allowed." within the referrer filters FIXME: at some point, the switch was broken and at first render it doesn't work.
When they fill in "referrer_filter" with "foo5.example.org" within the referrer filters
And press "Add" within the referrer filters
Then they should see "At most 5 referrer filters are allowed." within the referrer filters
And there should not be a button to "Add" within the referrer filters

@javascript
Scenario: Deleting a referrer filter once the limit is reached will toggle switch
Given the application has the following referrer filters:
| foo1.example.org |
| foo2.example.org |
| foo3.example.org |
| foo4.example.org |
| foo5.example.org |
And they go to the application's dev portal page
# And there should not be a button to "Add" within the referrer filters FIXME: at some point, the switch was broken and at first render it doesn't work.
And they should see "At most 5 referrer filters are allowed." within the referrer filters
And they press "Delete" that belongs to the referrer filter "foo5.example.org"
Then they should not see "At most 5 referrer filters are allowed." within the referrer filters
And there should be a button to "Add" within the referrer filters
1 change: 0 additions & 1 deletion features/developer_portal/backwards_compatibility.feature
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@allow-rescue
Feature: Dev portal backwards compatibility

As a long time 3scale user, I don't want any new updates in 3scale to break my developer portal.
Expand Down
33 changes: 30 additions & 3 deletions features/provider/admin/applications/referrer_filters.feature
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,42 @@ Feature: Providers's application referrer filters

Scenario: Creating a referrer filter
Given they go to the application's admin page
And fill in "referrer_filter" with "foo.example.org" within the referrer filters
And press "Add" within the referrer filters
When they fill in "referrer_filter" with "foo.example.org" within the referrer filters
And press "Add Filter" within the referrer filters
And wait a moment
Then they should see "foo.example.org" within the referrer filters

Scenario: Delete a referrer filter
Given the application has the following referrer filters:
| foo.example.org |
And they go to the application's admin page
And they should see "foo.example.org" within the referrer filters
When they should see "foo.example.org" within the referrer filters
And they press "Delete" that belongs to the referrer filter "foo.example.org"
Then they should not see "foo.example.org" within the referrer filters

Scenario: Can't create more than 5 referrer filters
Given the application has the following referrer filters:
| foo1.example.org |
| foo2.example.org |
| foo3.example.org |
| foo4.example.org |
And they go to the application's admin page
And there should be a button to "Add Filter" within the referrer filters
When they fill in "referrer_filter" with "foo5.example.org" within the referrer filters
And press "Add Filter" within the referrer filters
Then there should not be a button to "Add Filter" within the referrer filters
And they should see "At most 5 referrer filters are allowed." within the referrer filters

Scenario: Remove filter after reaching the limit
Given the application has the following referrer filters:
| foo1.example.org |
| foo2.example.org |
| foo3.example.org |
| foo4.example.org |
| foo5.example.org |
And they go to the application's admin page
And there should not be a button to "Add Filter" within the referrer filters
And they should see "At most 5 referrer filters are allowed." within the referrer filters
When they press "Delete" that belongs to the referrer filter "foo1.example.org"
Then there should be a button to "Add Filter" within the referrer filters
And they should not see "At most 5 referrer filters are allowed." within the referrer filters
17 changes: 17 additions & 0 deletions features/provider/admin/applications/show/api_credentials.feature
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,23 @@ Feature: Application API credentials
And they go to the application's admin page
Then should see "Keys limit reached." within the API Credentials card

Scenario: Reaching the limit should toggle the switch
Given the application has 4 keys
And they go to the application's admin page
And should not see "Keys limit reached." within the API Credentials card
When they follow "Add Random key" within the API Credentials card
Then they should see "Keys limit reached." within the API Credentials card
And there should not be a link to "Add Random key" within the API Credentials card

Scenario: Deleting a key once the limit is reached should toggle the switch
Given the application has 5 keys
And they go to the application's admin page
And should see "Keys limit reached." within the API Credentials card
And there should not be a link to "Add Random key" within the API Credentials card
When they follow any "Delete" within the API Credentials card
Then they should not see "Keys limit reached." within the API Credentials card
And there should be a link to "Add Random key" within the API Credentials card

Scenario: Field "Key" is required
Given the application has 1 key
And they go to the application's admin page
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<%# This file only exists to support very old portals that don't use 3scale.js OR 3scale_v2.js
Packages included in this file are not guaranteed to support jQuery > 2, so unfortunately we
have to keep them.
%>

<%= csrf_meta_tag %>

<%= javascript_include_tag "vendor/jquery-#{defined?(jquery) ? jquery : '2.1.4'}.min.js" %>
Expand All @@ -8,7 +13,7 @@
<%= stylesheet_link_tag 'colorbox/colorbox.css' %>

<%= javascript_include_tag 'highlight/highlight.pack.js' %>
<%= javascript_include_tag 'flash', 'remote', 'switch', 'extra_fields' %>
<%= javascript_include_tag 'flash', 'remote', 'essential_assets/switch', 'extra_fields' %>
<%= javascript_include_tag 'application' %>

<%= yield :javascripts %>

0 comments on commit 500dfc1

Please sign in to comment.