Skip to content

Commit

Permalink
Use a beta toggle for Color themes
Browse files Browse the repository at this point in the history
  • Loading branch information
Moises Deniz authored and hellcp-work committed Jan 18, 2024
1 parent a475116 commit 6b28cf0
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/api/app/helpers/webui/webui_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,11 @@ def valid_xml_id(rawid)
rawid = "_#{rawid}" unless /^[A-Za-z_]/.match?(rawid) # xs:ID elements have to start with character or '_'
CGI.escapeHTML(rawid.gsub(%r{[+&: ./~()@#]}, '_'))
end

def theme_from_user
return "light" unless feature_enabled?("color_themes")
User.session&.color_theme || "system"
end
end

# rubocop:enable Metrics/ModuleLength
2 changes: 1 addition & 1 deletion src/api/app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class User < ApplicationRecord
validates :password, confirmation: true, allow_blank: true
validates :biography, length: { maximum: MAX_BIOGRAPHY_LENGTH_ALLOWED }
validates :rss_secret, uniqueness: true, length: { maximum: 200 }, allow_blank: true
validates :color_theme, inclusion: { in: color_themes.keys }
validates :color_theme, inclusion: { in: color_themes.keys }, if: -> { Flipper.enabled?("color_themes") }

after_create :create_home_project, :measure_create
after_update :measure_delete
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/views/layouts/webui/webui.html.haml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
!!!
%html{ lang: 'en', "data-bs-theme-from-user": User.session&.color_theme || "system" }
%html{ lang: 'en', "data-bs-theme-from-user": theme_from_user }
%head
%meta{ content: 'charset=utf-8' }/
%meta{ name: 'viewport', content: 'width=device-width, initial-scale=1, shrink-to-fit=no' }
Expand Down
7 changes: 4 additions & 3 deletions src/api/app/views/webui/user/_edit_account_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
%small.form-text#bio-chars-counter
.mb-3
= f.text_field(:email, required: true, email: true, placeholder: 'Email', readonly: behind_proxy, class: 'form-control')
.mb-3
= f.label :color_theme, "Theme"
= f.select(:color_theme, options_for_select(User.color_themes.keys), {}, class: 'form-select')
- if feature_enabled?("color_themes")
.mb-3
= f.label :color_theme, "Theme"
= f.select(:color_theme, options_for_select(User.color_themes.keys), {}, class: 'form-select')
.mb-3
- if behind_proxy
%p
Expand Down
3 changes: 2 additions & 1 deletion src/api/config/initializers/flipper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
# to users in the web UI for beta features.
ENABLED_FEATURE_TOGGLES = [
{ name: :request_show_redesign, description: 'Redesign of the request pages to improve the collaboration workflow' },
{ name: :content_moderation, description: 'Reporting inappropriate content' }
{ name: :content_moderation, description: 'Reporting inappropriate content' },
{ name: :color_themes, description: 'Color themes' }
].freeze

Flipper.configure do
Expand Down

0 comments on commit 6b28cf0

Please sign in to comment.