Skip to content

Commit

Permalink
Add disable confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Mikhail committed Jan 9, 2024
1 parent 1b8edee commit a1d6506
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
5 changes: 5 additions & 0 deletions lib/flipper/ui/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ class Configuration
# Default is false.
attr_accessor :confirm_fully_enable

# Public: if you want to get a confirm pop up box while disabling a feature
# Default is false.
attr_accessor :confirm_disable

VALID_BANNER_CLASS_VALUES = %w(
danger
dark
Expand Down Expand Up @@ -91,6 +95,7 @@ def initialize
@show_feature_description_in_list = false
@actors_separator = ','
@confirm_fully_enable = false
@confirm_disable = true
@read_only = false
end

Expand Down
15 changes: 13 additions & 2 deletions lib/flipper/ui/public/js/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,24 @@ $(function () {
e.preventDefault();
}
});


$("#disable_feature__button").on("click", function (e) {
const featureName = $(e.target).data("confirmation-text");
const promptMessage = prompt(
`Are you sure you want to disable this feature for everyone? Please enter the name of the feature to confirm it: ${featureName}`
);

if (promptMessage !== featureName) {
e.preventDefault();
}
});

$("#delete_feature__button").on("click", function (e) {
const featureName = $(e.target).data("confirmation-text");
const promptMessage = prompt(
`Are you sure you want to remove this feature from the list of features and disable it for everyone? Please enter the name of the feature to confirm it: ${featureName}`
);

if (promptMessage !== featureName) {
e.preventDefault();
}
Expand Down
9 changes: 7 additions & 2 deletions lib/flipper/ui/views/feature.erb
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,13 @@

<% unless @feature.off? %>
<div class="col">
<button type="submit" name="action" value="Disable" class="btn btn-outline-danger btn-block">
<span class="d-block" data-toggle="tooltip" title="Disable for everyone by clearing all percentages, groups and actors.">
<button type="submit" name="action" value="Disable" <% if Flipper::UI.configuration.confirm_disable %>id="disable_feature__button"<% end %> class="btn btn-outline-danger btn-block">
<span class="d-block" data-toggle="tooltip"
<% if Flipper::UI.configuration.confirm_disable %>
data-confirmation-text="<%= feature_name %>"
<% end %>
title="Disable for everyone by clearing all percentages, groups and actors."
>
Disable
</span>
</button>
Expand Down

0 comments on commit a1d6506

Please sign in to comment.