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

Display and update extra data #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ And visit [http://localhost:9292/](http://localhost:9292/).
Alternatively you can also configure which Redis with:

```sh
REDIS_HOST=localhost REDIS_PORT=6379 REDIS_DB=10 be rerun rackup
REDIS_HOST=localhost REDIS_PORT=6379 REDIS_DB=10 bundle exec rerun rackup
```

## License
Expand Down
16 changes: 16 additions & 0 deletions lib/rollout/ui/views/features/show.slim
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ form.p-6.bg-gray-100.max-w-lg.w-full.text-sm.rounded-sm action=feature_path(@fea
)
= @feature.users.join(', ')

.mb-5
label.block.text-gray-500.mb-2 Additional Data

dl
- @feature.data.each do |name, val|
- next if name == 'description'
.sm:grid.sm:grid-cols-3.sm:gap-4.sm:px-6
dd.text-sm.leading-5.font-medium.text-gray-500 = name
input.appearance-none.border.rounded-sm.w-full.py-2.px-4.text-gray-600.leading-relaxed.bg-white.mt-1.sm:mt-0.sm:col-span-2(
name=name
id=name
value=(val == true ? 'true' : (val == false ? 'false' : val))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you can simply write this as value=val.to_s

class='hover:border-gray-500'
)


.flex.items-center.justify-end
form action=delete_feature_path(@feature.name) method='POST'
button.mr-5.text-gray-600(class='hover:underline' type='submit' onclick="return confirm('Are you sure you want to delete #{@feature.name}?')")
Expand Down
15 changes: 14 additions & 1 deletion lib/rollout/ui/web.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,20 @@ class Web < Sinatra::Base
if params[:users]
feature.users = params[:users].split(',').map(&:strip).uniq.sort
end
feature.data.update(description: params[:description])
feature.data.each do |name, old_val|
new_val = params[name]

# keep type the same (for integers/boolean/strings)
new_val = if old_val.is_a? Integer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be more bulletproof and ellegant to use a regexp to see if it's a number, eg https://medium.com/launch-school/number-validation-with-regex-ruby-393954e46797

new_val.to_i
elsif !!old_val == old_val
new_val == 'true' ? true : (new_val == 'false' ? false : !!new_val)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nested ternary operators are crazy hard to read... using regex and case here might also be more readable

else
new_val
end

feature.data.update(name => new_val)
end
end
end

Expand Down
1 change: 0 additions & 1 deletion rollout-ui.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ Gem::Specification.new do |spec|
spec.add_dependency 'sinatra', '~> 2.0'
spec.add_dependency 'slim', '~> 4.0'

spec.add_development_dependency 'bundler', '~> 1.17'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rspec', '~> 3.0'
spec.add_development_dependency 'rerun', '~> 0.13'
Expand Down