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

Kiwi Editor - Add understandable flash message #3981

Merged
merged 5 commits into from
Oct 18, 2017

Conversation

DavidKang
Copy link
Contributor

@DavidKang DavidKang commented Oct 10, 2017

We added a more understandable error message in the Kiwi Editor and also in the file view when the importation has a failure due to an invalid kiwi file. We also highlight the repository or package that has an error.

Before

screenshot from 2017-10-10 15-46-41

screenshot from 2017-10-10 15-48-42

After

screenshot from 2017-10-11 19-52-54

screenshot from 2017-10-11 19-48-06

@DavidKang DavidKang added the Frontend Things related to the OBS RoR app label Oct 10, 2017
@codecov
Copy link

codecov bot commented Oct 10, 2017

Codecov Report

Merging #3981 into master will decrease coverage by 0.03%.
The diff coverage is 66.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3981      +/-   ##
==========================================
- Coverage   89.21%   89.17%   -0.04%     
==========================================
  Files         308      309       +1     
  Lines       18199    18221      +22     
==========================================
+ Hits        16236    16249      +13     
- Misses       1963     1972       +9
Flag Coverage Δ
#api 80.35% <32.25%> (-0.1%) ⬇️
#rspec 69.78% <100%> (+0.02%) ⬆️
#webui 61.68% <41.93%> (-0.05%) ⬇️

@DavidKang DavidKang force-pushed the kiwi-editor-flash-messages branch 4 times, most recently from 22ecbd5 to 9a66660 Compare October 10, 2017 18:32
@adrianschroeter
Copy link
Member

looks much better :)

@DavidKang DavidKang added the DO NOT MERGE ⚠️ Explain yourself if you add/remove this label to a PR label Oct 11, 2017
@DavidKang
Copy link
Contributor Author

DO NOT MERGE, I still improving the error messages

David Kang added 2 commits October 11, 2017 15:30
We added a more understandable error message in the Kiwi Editor and also
in the file view when the importation has a failure due to an invalid
kiwi file.
We highlighted the repositories and packages that are not valid.
@DavidKang DavidKang force-pushed the kiwi-editor-flash-messages branch 5 times, most recently from 3a183d1 to 764b5c4 Compare October 11, 2017 19:03
@DavidKang DavidKang removed the DO NOT MERGE ⚠️ Explain yourself if you add/remove this label to a PR label Oct 11, 2017
@DavidKang DavidKang changed the title [webui] Add understandable flash message in Kiwi Kiwi Editor - Add understandable flash message Oct 16, 2017
@DavidKang
Copy link
Contributor Author

@openSUSE/open-build-service, could someone review it, please 😸

@@ -105,6 +106,23 @@ def cleanup_non_project_repositories!
@image.repositories.delete_all
params[:kiwi_image].delete(:repositories_attributes)
end

def image_error_messages(title, image, packages)

Choose a reason for hiding this comment

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

I think this should go in a model not the controller?

if record.errors.present?
message["#{key.capitalize}: #{record.name}"] ||= []
message["#{key.capitalize}: #{record.name}"] << record.errors.messages.map { |_key, value| value }
message["#{key.capitalize}: #{record.name}"].flatten!

Choose a reason for hiding this comment

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

Why is this method necessary? Can we not just use the errors object/hash that ActiveRecord gives us?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the error hash gives us 'Repository[0]...` and I'm trying to do this more understandable grouping all the errors related to each element.

Choose a reason for hiding this comment

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

I guess what I dont like so much about this method is that it fixes a more general problem with active record validations on nested fields so IMO the ideal would be to somehow override ActiveRecord's validation and fix the problem there.. However that might not be so easy to do.. There is some discusion in this PR about how to do that but the only solution offered is to just convert the keys to what you want like David is doing here:

rails/rails#19686

Maybe can you rename this method to something like parsed_errors and then include a comment explaining why we need to convert the original error keys from ActiveRecord?

records.each do |record|
if record.errors.present?
message["#{key.capitalize}: #{record.name}"] ||= []
message["#{key.capitalize}: #{record.name}"] << record.errors.messages.map { |_key, value| value }

Choose a reason for hiding this comment

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

Can do:

record.errors.messages.values

@@ -20,7 +20,8 @@ def import_from_package
if package.kiwi_image.blank? || package.kiwi_image.destroyed?
package.kiwi_image = ::Kiwi::Image.build_from_xml(package.source_file(kiwi_file), package.kiwi_file_md5)
unless package.save
errors = ["Kiwi File '#{kiwi_file}' has errors:", package.kiwi_image.errors.full_messages].join('<br />')
errors = image_error_messages("Kiwi File '#{kiwi_file}' has errors:",
package.kiwi_image, [package.kiwi_image.package_groups.map(&:packages)].flatten.compact)
redirect_to package_view_file_path(project: package.project, package: package, filename: kiwi_file), error: errors
Copy link

@evanrolfe evanrolfe Oct 16, 2017

Choose a reason for hiding this comment

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

Why not render the show page like its done in #update instead of redirecting?

render action: :show

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because we are redirecting to package_view_file and this needs to set other instances variables.

@DavidKang DavidKang force-pushed the kiwi-editor-flash-messages branch 4 times, most recently from 6e5231d to 88bdff2 Compare October 16, 2017 21:12
@DavidKang
Copy link
Contributor Author

@evanrolfe, could you review it again, please 😸

Copy link

@evanrolfe evanrolfe left a comment

Choose a reason for hiding this comment

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

LGTM

We added test for flash_content helper and also included Haml::Helpers.
@DavidKang DavidKang merged commit d5df057 into openSUSE:master Oct 18, 2017
@DavidKang DavidKang deleted the kiwi-editor-flash-messages branch October 31, 2017 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Frontend Things related to the OBS RoR app
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants