Skip to content
Permalink
Browse files

Implement UI::Configuration so users can customize Flipper UI text

  • Loading branch information...
AlexWheeler committed Sep 6, 2017
1 parent e950c88 commit 3ced5fb32021a428b369cdabb83afc7e2c64c22c
@@ -12,6 +12,7 @@
require 'flipper/middleware/setup_env'
require 'flipper/middleware/memoizer'
require 'flipper/ui/middleware'
require 'flipper/ui/configuration'

module Flipper
module UI
@@ -25,6 +26,9 @@ class << self
# set to false, users of the UI cannot create features. All feature
# creation will need to be done through the conigured flipper instance.
attr_accessor :feature_creation_enabled

# Public: Set attributes on this instance to customize UI text
attr_reader :configuration
end

self.feature_creation_enabled = true
@@ -49,5 +53,14 @@ def self.app(flipper = nil, options = {})
builder.define_singleton_method(:inspect) { klass.inspect } # pretty rake routes output
builder
end

# Public: yields configuration instance for customizing UI text
def self.configure
yield(configuration)
end

def self.configuration
@configuration ||= ::Flipper::UI::Configuration.new
end
end
end
@@ -0,0 +1,21 @@
require 'flipper/ui/configuration/option'

module Flipper
module UI
class Configuration
attr_reader :actors,
:delete,
:groups,
:percentage_of_actors,
:percentage_of_time

def initialize
@actors = Option.new("Actors", "Enable actors using the form above.")
@groups = Option.new("Groups", "Enable groups using the form above.")
@percentage_of_actors = Option.new("Percentage of Actors", "Percentage of actors functions independently of percentage of time. If you enable 50% of Actors and 25% of Time then the feature will always be enabled for 50% of users and occasionally enabled 25% of the time for everyone.")
@percentage_of_time = Option.new("Percentage of Time", "Percentage of actors functions independently of percentage of time. If you enable 50% of Actors and 25% of Time then the feature will always be enabled for 50% of users and occasionally enabled 25% of the time for everyone.")
@delete = Option.new("Danger Zone", "Deleting a feature removes it from the list of features and disables it for everyone.")
end
end
end
end
@@ -0,0 +1,12 @@
module Flipper
module UI
class Option
attr_accessor :title, :description

def initialize(title, description)
@title = title
@description = description
end
end
end
end
@@ -37,7 +37,7 @@
<div class="column one-half">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Percentage of Actors</h3>
<h3 class="panel-title"><%= Flipper::UI.configuration.percentage_of_actors.title %></h3>
</div>
<div class="panel-body">
<form action="<%= script_name %>/features/<%= @feature.key %>/percentage_of_actors" method="post">
@@ -56,14 +56,14 @@
<input type="text" name="value" <% if @feature.percentage_of_actors_value > 0 %>value="<%= @feature.percentage_of_actors_value %>"<% end %> placeholder="custom (ie: 26, 32, etc.)" class="input-mini">
<input type="submit" name="action" value="Enable" class="btn btn-sm">
</form>
<p class="help"><small>Percentage of actors functions independently of percentage of time. If you enable 50% of Actors and 25% of Time then the feature will always be enabled for 50% of users and occasionally enabled 25% of the time for everyone.</small></p>
<p class="help"><small><%= Flipper::UI.configuration.percentage_of_actors.description %></small></p>
</div>
</div>
</div>
<div class="column one-half">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Percentage of Time</h3>
<h3 class="panel-title"><%= Flipper::UI.configuration.percentage_of_time.title %></h3>
</div>
<div class="panel-body">
<form action="<%= script_name %>/features/<%= @feature.key %>/percentage_of_time" method="post">
@@ -83,7 +83,7 @@
<input type="submit" name="action" value="Enable" class="btn btn-sm">
</form>

<p class="help"><small>Percentage of time functions independently of percentage of actors. If you enable 50% of Actors and 25% of Time then the feature will always be enabled for 50% of users and occasionally enabled 25% of the time for everyone.</small></p>
<p class="help"><small><%= Flipper::UI.configuration.actors.description %></small></p>
</div>
</div>
</div>
@@ -110,15 +110,15 @@
<input type="submit" value="Add Group" class="btn btn-sm">
</form>
<% end %>
<h3 class="panel-title">Groups</h3>
<h3 class="panel-title"><%= Flipper::UI.configuration.groups.title %></h3>
</div>
<% if @feature.groups_value.empty? %>
<div class="blankslate">
<span class="mega-octicon octicon-organization"></span>
<span class="mega-octicon octicon-squirrel"></span>
<span class="mega-octicon octicon-zap"></span>
<h3>No Enabled Groups</h3>
<p>Enable groups using the form above.</p>
<p><%= Flipper::UI.configuration.groups.description %></p>
</div>
<% else %>
<ul class="list-group">
@@ -154,15 +154,15 @@
<input type="text" name="value" placeholder="ie: User:6" class="input-mini">
<input type="submit" value="Add Actor" class="btn btn-sm">
</form>
<h3 class="panel-title">Actors</h3>
<h3 class="panel-title"><%= Flipper::UI.configuration.actors.title %></h3>
</div>
<% if @feature.actors_value.empty? %>
<div class="blankslate">
<span class="mega-octicon octicon-person"></span>
<span class="mega-octicon octicon-squirrel"></span>
<span class="mega-octicon octicon-zap"></span>
<h3>No Enabled Actors</h3>
<p>Enable actors using the form above.</p>
<p><%= Flipper::UI.configuration.actors.description %></p>
</div>
<% else %>
<ul class="list-group">
@@ -194,11 +194,11 @@

<div class="panel panel-danger">
<div class="panel-heading">
<h3 class="panel-title">Danger Zone</h3>
<h3 class="panel-title"><%= Flipper::UI.configuration.delete.title %></h3>
</div>
<div class="panel-body">
<p>
Deleting a feature removes it from the list of features and disables it for everyone.
<%= Flipper::UI.configuration.delete.description %>
</p>

<form action="<%= script_name %>/features/<%= @feature.key %>" method="post" onsubmit="return confirm('Are you sure you want to remove <%= @feature.key %> from the list of features and disable it for everyone?')">
@@ -0,0 +1,45 @@
require 'helper'

RSpec.describe Flipper::UI::Configuration do
let(:configuration) { described_class.new }

describe "#actors" do
it "has default text" do
expect(configuration.actors.title).to eq("Actors")
expect(configuration.actors.description).to eq("Enable actors using the form above.")
end

it "can be updated" do
configuration.actors.title = "Actors Section"
expect(configuration.actors.title).to eq("Actors Section")
end
end

describe "#groups" do
it "has default text" do
expect(configuration.groups.title).to eq("Groups")
expect(configuration.groups.description).to eq("Enable groups using the form above.")
end
end

describe "#percentage_of_actors" do
it "has default text" do
expect(configuration.percentage_of_actors.title).to eq("Percentage of Actors")
expect(configuration.percentage_of_actors.description).to eq("Percentage of actors functions independently of percentage of time. If you enable 50% of Actors and 25% of Time then the feature will always be enabled for 50% of users and occasionally enabled 25% of the time for everyone.")
end
end

describe "#percentage_of_time" do
it "has default text" do
expect(configuration.percentage_of_time.title).to eq("Percentage of Time")
expect(configuration.percentage_of_time.description).to eq("Percentage of actors functions independently of percentage of time. If you enable 50% of Actors and 25% of Time then the feature will always be enabled for 50% of users and occasionally enabled 25% of the time for everyone.")
end
end

describe "#delete" do
it "has default text" do
expect(configuration.delete.title).to eq("Danger Zone")
expect(configuration.delete.description).to eq("Deleting a feature removes it from the list of features and disables it for everyone.")
end
end
end
@@ -146,4 +146,12 @@
described_class.feature_creation_enabled = @original_feature_creation_enabled
end
end

describe 'configure' do
it 'yields configuration instance' do
described_class.configure do |config|
expect(config).to be_instance_of(Flipper::UI::Configuration)
end
end
end
end

0 comments on commit 3ced5fb

Please sign in to comment.
You can’t perform that action at this time.