-
Notifications
You must be signed in to change notification settings - Fork 6
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
Feature flags GUI #513
Merged
jsuchal
merged 18 commits into
slovensko-digital:main
from
richardlences:feature/feature_flags_gui
Dec 5, 2024
Merged
Feature flags GUI #513
Changes from 15 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
3cd9a97
Feature flags GUI v 0.1
richardlences 37a9671
Merge branch 'main' into feature/feature_flags_gui
richardlences 1c2ac81
Merge main
richardlences a493cb2
create feature flag policy
richardlences 4f7f620
Fixes based on review
richardlences c293f80
Feature flags system test
richardlences f3235b3
.env.test remove unwanted changes
richardlences 915f55c
.env.test remove unwanted changes
richardlences adb1bf9
Fixes
richardlences 7ca026f
Merge branch 'main' into feature/feature_flags_gui
richardlences d8e9945
fix test
richardlences 815bbca
feature flag routing fix
richardlences e4cab68
show only available features
richardlences eb98bc6
test fix
richardlences 9c129bf
Make only some features visible
richardlences 36f9492
delete unwandet file
richardlences 0820efd
Update test/system/admin/feature_flags_management_test.rb
jsuchal c65435b
Rename
jsuchal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
inherit_from: | ||
- ".rubocop.yml" | ||
Layout/InitialIndentation: | ||
Enabled: false | ||
Layout/LineLength: | ||
Enabled: false | ||
Layout/TrailingEmptyLines: | ||
Enabled: false | ||
Layout/TrailingWhitespace: | ||
Enabled: false | ||
Naming/FileName: | ||
Enabled: false | ||
Style/FrozenStringLiteralComment: | ||
Enabled: false | ||
Lint/UselessAssignment: | ||
Enabled: false | ||
Rails/OutputSafety: | ||
Enabled: false |
21 changes: 21 additions & 0 deletions
21
app/components/admin/feature_flags/feature_flags_list_row_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<div class="self-stretch p-4 border-b border-gray-200 items-center gap-4 inline-flex"> | ||
<div class="grow shrink basis-0 gap-1"> | ||
<div class="text-gray-900 text-lg font-medium leading-loose w-fit"> | ||
<div class="grow shrink basis-0 flex-col justify-start items-start gap-1 inline-flex"> | ||
<div class="text-center text-gray-900 text-lg font-medium leading-loose"> | ||
<%= t "feature_flags.#{@feature_flag}.name"%> | ||
</div> | ||
<div class="text-center text-gray-500 text-base font-normal leading-normal"> | ||
<%= t "feature_flags.#{@feature_flag}.description"%> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<%= form_with model: Current.tenant, url: admin_tenant_feature_flag_path(Current.tenant, @feature_flag), title: "Toggle feature state", method: :patch do |form| %> | ||
<%= form.hidden_field :enabled, value: !@enabled %> | ||
<%= form.button name: @feature_flag, class: "#{@enabled ? "bg-indigo-600" : "bg-gray-200"} relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-indigo-600 focus:ring-offset-2", role: :switch, aria: { checked: @enabled } do %> | ||
<span class="sr-only">Use setting</span> | ||
<span aria-hidden="true" class="<%= @enabled ? "translate-x-5" : "translate-x-0" %> pointer-events-none inline-block h-5 w-5 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out"></span> | ||
<% end %> | ||
<% end %> | ||
</div> |
6 changes: 6 additions & 0 deletions
6
app/components/admin/feature_flags/feature_flags_list_row_component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class Admin::FeatureFlags::FeatureFlagsListRowComponent < ViewComponent::Base | ||
def initialize(flag, enabled_features) | ||
@feature_flag = flag | ||
@enabled = enabled_features.include?(flag) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
class Admin::FeatureFlagsController < ApplicationController | ||
before_action :set_tenant | ||
|
||
def index | ||
authorize([:admin, :feature_flag]) | ||
if params.include?(:labs) | ||
@feature_flags = @tenant.list_all_features | ||
else | ||
@feature_flags = @tenant.list_available_features | ||
end | ||
@enabled_features = @tenant.feature_flags | ||
end | ||
|
||
def update | ||
authorize([:admin, :feature_flag]) | ||
if feature_flags_params[:enabled] == "true" | ||
@tenant.feature_flags << params[:id] | ||
else | ||
@tenant.feature_flags.delete(params[:id]) | ||
end | ||
@tenant.save! | ||
redirect_to admin_tenant_feature_flags_path | ||
end | ||
|
||
private | ||
|
||
def set_tenant | ||
@tenant = policy_scope([:admin, :feature_flag]).find(params[:tenant_id]) | ||
end | ||
|
||
def feature_flags_params | ||
params.require(:tenant).permit(:enabled) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
class Admin::FeatureFlagPolicy < ApplicationPolicy | ||
attr_reader :user, :tenant | ||
|
||
def initialize(user, tenant) | ||
@user = user | ||
@tenant = tenant | ||
end | ||
|
||
class Scope < Scope | ||
def resolve | ||
Tenant.where(id: @user.tenant) | ||
end | ||
end | ||
|
||
def index? | ||
@user.admin? | ||
end | ||
|
||
def update? | ||
@user.admin? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<div class="w-full p-4 flex-col justify-start items-start gap-4 inline-flex"> | ||
<div class="self-stretch bg-white rounded-md border border-gray-200 flex-col justify-start items-start flex"> | ||
<div class="self-stretch p-6 border-b border-gray-200 justify-start items-center gap-4 inline-flex"> | ||
<div class="grow shrink basis-0 text-gray-900 text-xl font-semibold leading-[35px]">Aktivácia rozšírení</div> | ||
</div> | ||
<% @feature_flags.each do |flag| %> | ||
<div class="self-stretch flex-col justify-start items-start flex"> | ||
<%= render Admin::FeatureFlags::FeatureFlagsListRowComponent.new(flag.to_s, @enabled_features) %> | ||
</div> | ||
<% end %> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require "application_system_test_case" | ||
|
||
class FeatureFlagsManagementTest < ApplicationSystemTestCase | ||
setup do | ||
sign_in_as(:admin) | ||
visit root_path | ||
click_link "Nastavenia" | ||
click_link "Aktivácia rozšírení" | ||
jsuchal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end | ||
|
||
test "admin can enable and disable a feature" do | ||
available_features = users(:admin).tenant.list_available_features | ||
enabled = users(:admin).tenant.feature_enabled?(available_features[0]) | ||
click_button available_features[0] | ||
assert_button available_features[0] | ||
users(:admin).tenant.reload | ||
assert_not_equal enabled, users(:admin).tenant.feature_enabled?(available_features[0]) | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tento súbor tu asi nemá byť
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha ano uz som to odstranil