activeadmin-plugins / active_admin_datetimepicker

:calendar: active_admin_datetimepicker gem
MIT License
72 stars 48 forks source link

Selecting a date triggers file download 'null_null.csv' #71

Closed chrisgeek closed 3 years ago

chrisgeek commented 3 years ago

Gem Version 0.7.3 and 0.7.4 Rails 5 Ruby 2.6

When selecting a date, a download is triggered when the month or year select drop down is clicked. Find attached a demo video

https://user-images.githubusercontent.com/12730606/109497689-b5de7100-7a92-11eb-988e-50f324ee5d06.mp4

workgena commented 3 years ago

Hi @chrisgeek 👋

From the first glance, it seems that:

In the other part of an application it has and JavaScript event listener which triggers downloading "CSV". And since it is not related to current form, it can't find "name" and "data" to generate file name - it transforms to "null" + _ + "null" + ".csv".

It is very little change that this bug is caused by the active_admin_datetimepicker-plugin itself.

To fix it, the JavaScript(or probably jQuery) selector which triggers the Download needs to be rewritten in more precise manner. For example(abstract example):

$('.created_by a').click --> $('.created_by a.download_link').click

workgena commented 3 years ago

Also the Gemfile might be useful for our investigation.

chrisgeek commented 3 years ago

Here is what Gemfile looks like

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.6.3'

# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use ActiveStorage variant
# gem 'mini_magick', '~> 4.8'
gem 'active_admin_datetimepicker', '~> 0.7.4'
gem 'active_admin_import'
gem 'activeadmin'
gem 'activeadmin_addons'
gem 'amoeba'
gem 'auto_strip_attributes'
gem 'bootsnap', require: false # Reduces boot times through caching; required in config/boot.rb
gem 'bootstrap'
gem 'bootstrap3-datetimepicker-rails'
gem 'cancancan'
gem 'cocoon'
gem 'coffee-rails'
gem 'devise'
gem 'devise_invitable', '~> 2.0.0'
gem 'font-awesome-sass'
gem 'groupdate'
gem 'haml-rails'
gem 'jbuilder'
gem 'jquery-rails'
gem 'jquery-ui-rails'
gem 'local_time'
gem 'paranoia', '~> 2.2'
gem 'pg', '>= 0.18', '< 2.0'
gem 'pretender'
gem 'puma'
gem 'rails', '~> 5.2'
gem 'ranked-model'
gem 'simple_form'
gem 'storext'
gem 'turbolinks'
gem 'uglifier'
gem 'webdack-uuid_migration'

group :development, :test do
  gem 'pry'                 # Call `binding.pry` to get a debugger console
  gem 'pry-byebug'
  gem 'pry-rails'
  gem 'rubocop-faker'
  gem 'rubocop-performance'
  gem 'rubocop-rspec'
  gem 'active_mocker'
end

group :development do
  gem 'awesome_print'
  gem 'better_errors'
  gem 'binding_of_caller'
  gem 'brakeman'
  gem 'letter_opener'
  gem 'listen'
  gem 'spring'              # Spring keeps app running in bg to speed up development. More: https://github.com/rails/spring
  gem 'spring-watcher-listen'
end

group :test do
  gem 'apparition'
  gem 'capybara'
  gem 'database_cleaner'
  gem 'factory_bot_rails'
  gem 'faker'
  gem 'poltergeist'
  gem 'rspec-rails'
  gem 'shoulda-matchers'
  gem 'simplecov', require: false
  gem 'webdrivers'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]
workgena commented 3 years ago

For investigation I would suggest to disable following gems(one by one):

gem 'active_admin_import'
gem 'activeadmin_addons'
gem 'bootstrap'
gem 'bootstrap3-datetimepicker-rails'

And try once more without them, to make sure they are not conflicting.

chrisgeek commented 3 years ago

@workgena You were right, some other JS function triggered the behaviour. Thanks !