Skip to content
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

UI: show badges for new releases and deprecations #791

Merged
merged 5 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions flipper.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ Gem::Specification.new do |gem|
gem.metadata = Flipper::METADATA

gem.add_dependency 'concurrent-ruby', '< 2'

gem.required_ruby_version = ">= #{Flipper::REQUIRED_RUBY_VERSION}"
end
6 changes: 6 additions & 0 deletions lib/flipper/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,11 @@ def self.default_strict_value
:warn
end
end

NEXT_REQUIRED_RAILS_VERSION = '6.1.0'.freeze

def self.deprecated_rails_version?
Gem::Version.new(Rails.version) < Gem::Version.new(NEXT_REQUIRED_RAILS_VERSION)
end
end
end
1 change: 1 addition & 0 deletions lib/flipper/ui/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def feature_name
style-src 'self' 'unsafe-inline';
style-src-attr 'unsafe-inline' ;
style-src-elem 'self';
connect-src https://rubygems.org;
CSP

# Public: Call this in subclasses so the action knows its route.
Expand Down
32 changes: 32 additions & 0 deletions lib/flipper/ui/public/js/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Get the latest release from RubyGems.org and show a badge if it's not the current version
function checkLatestRelease() {
// Skip check if last check was less than 1 day ago
if(localStorage.getItem('flipper.releaseCheckedAt') > new Date().getTime() - 86400000) return

fetch('https://rubygems.org/api/v1/gems/flipper.json').then(response => {
bkeepers marked this conversation as resolved.
Show resolved Hide resolved
// Something went wrong, so just give up
if(!response.ok) return
bkeepers marked this conversation as resolved.
Show resolved Hide resolved

response.json().then(release => {
localStorage.setItem('flipper.release', JSON.stringify(release))
// store the last time we checked for a new version
localStorage.setItem('flipper.releaseCheckedAt', new Date().getTime())
showReleaseBadge()
})
})
}

// Show a badge if a new release is available
function showReleaseBadge() {
const badge = document.querySelector('#new-version-badge')
const release = JSON.parse(localStorage.getItem('flipper.release') || false)

if(!badge || !release || badge.dataset.version === release.version) return

badge.innerText = `${release.version} available!`
badge.setAttribute('href', release.metadata.changelog_uri)
badge.classList.remove('d-none')
}

checkLatestRelease()
showReleaseBadge()
15 changes: 15 additions & 0 deletions lib/flipper/ui/views/layout.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@
<a href="https://www.flippercloud.io/docs/ui?utm_source=oss&utm_medium=ui&utm_campaign=docs">Docs</a> &bull;
<a href="<%= script_name %>/settings">Settings</a> &bull;
Version: <%= Flipper::VERSION %>
<a href="#" class="badge badge-warning ml-2 d-none" style="font-size:100%" id="new-version-badge" data-version="<%= Flipper::VERSION %>">
</a>

<% if Flipper.deprecated_ruby_version? %>
<a href="https://github.com/flippercloud/flipper/pull/776" class="badge badge-danger ml-2" style="font-size:100%">
Ruby <%= RUBY_VERSION %> deprecated
</a>
<% end %>

<% if defined?(Rails) && Flipper::Engine.deprecated_rails_version? %>
<a href="https://github.com/flippercloud/flipper/pull/776" class="badge badge-danger ml-2" style="font-size:100%">
Rails <%= Rails.version %> deprecated
</a>
<% end %>
</div>

<nav aria-label="breadcrumb">
Expand Down Expand Up @@ -61,5 +75,6 @@
<script src="<%= script_name + popper_js[:src] %>" integrity="<%= popper_js[:hash] %>" crossorigin="anonymous"></script>
<script src="<%= script_name + bootstrap_js[:src] %>" integrity="<%= bootstrap_js[:hash] %>" crossorigin="anonymous"></script>
<script src="<%= script_name %>/js/application.js"></script>
<script src="<%= script_name %>/js/version.js"></script>
</body>
</html>
8 changes: 8 additions & 0 deletions lib/flipper/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
module Flipper
VERSION = '1.1.2'.freeze

REQUIRED_RUBY_VERSION = '2.6'.freeze

NEXT_REQUIRED_RUBY_VERSION = '3.0'.freeze

def self.deprecated_ruby_version?
Gem::Version.new(RUBY_VERSION) < Gem::Version.new(NEXT_REQUIRED_RUBY_VERSION)
end
end