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

Feature/better error for missing resource #2062

Merged

Conversation

bryszard
Copy link
Contributor

@bryszard bryszard commented Nov 26, 2023

Description

Fixes # 1960

We're adding a better handling for errors when we encounter a missing resource on association fields.

Right now the error is unhelpful and requires developer to understand the internal logic of Avo.
We want to give a better Dev Experience and point to solutions.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works

Screenshots

Error:

UPDATED WITH NEW MESSAGE
image

Video

BEFORE APPLYING REVIEW SUGGESTIONS
https://github.com/avo-hq/avo/assets/12682792/3b4f14f8-700a-4770-ba37-cecd66683052

Manual review steps

  1. Go to the dummy app to Teams page and choose any Team, add show_location_field=1 query param
  2. On the Team show page go to the bottom and observe what happens with the slot for locations field.
  3. Go to the Courses page and choose any Course, add show_location_field=1 query param
  4. On the Course show page go to the bottom and observe what happens with the slot for locations field.
  5. Go to the Stores page , add show_location_field=1 query param and see the error
  6. Go to the Events page, add show_location_field=1 query param and see the error

Manual reviewer: please leave a comment with output from the test if that's the case.

Copy link

codeclimate bot commented Nov 26, 2023

Code Climate has analyzed commit 9bec1b8 and detected 0 issues on this pull request.

View more on Code Climate.

@Paul-Bob Paul-Bob changed the base branch from main to 2.x November 27, 2023 10:36
@Paul-Bob Paul-Bob self-requested a review November 27, 2023 11:34
@adrianthedev
Copy link
Collaborator

This looks great @bryszard! Thank you!
Would you be able to move it to the main branch so it will work with Avo 3?

@bryszard
Copy link
Contributor Author

bryszard commented Dec 1, 2023

Definitely.

I have kind of a busy time, but I plan to finish it in the next several days.

Copy link
Collaborator

@adrianthedev adrianthedev left a comment

Choose a reason for hiding this comment

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

This looks great!

I think this catch can be added to BelongsToField.target_resource, HasBaseField.field_resource and HasBaseField.target_resource.

app/controllers/avo/application_controller.rb Outdated Show resolved Hide resolved
@adrianthedev
Copy link
Collaborator

No worries. Take your time, and thank you for the contribution ❤️

@bryszard bryszard force-pushed the feature/better_error_for_missing_resource branch from f6d5ab9 to d54ea37 Compare December 6, 2023 08:20
@bryszard bryszard changed the base branch from 2.x to main December 6, 2023 08:22
@bryszard
Copy link
Contributor Author

bryszard commented Dec 6, 2023

@Paul-Bob I'm ready for review, although I have a doubt:

Since I've merged the newest main I have a problem with the display of the dummy app. The resources are not grouped correctly as they used to and as they do when I check the Demo App. They are all displayed in one non-collapsable group in alphabetical order:

image

Do you know what could be the problem?

@bryszard bryszard marked this pull request as ready for review December 6, 2023 12:27
@Paul-Bob
Copy link
Contributor

Paul-Bob commented Dec 6, 2023

@bryszard

The resources are not grouped correctly as they used to

They are grouped correctly, give a quick read here https://docs.avohq.io/3.0/resource-panels.html

We refactored the way that items are fetched from resource on avo3 allowing more customization

Let me know if the docs are clear or if there are some thinks that can be better explained

PS: Thank you for the contribution. I'll review it during this week

@adrianthedev
Copy link
Collaborator

I'm checking your commits and you're a legend @bryszard.
Thank you for taking the time to fix these 💪
We appreciate it.

Copy link
Contributor

@Paul-Bob Paul-Bob left a comment

Choose a reason for hiding this comment

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

Great PR @bryszard! Thank you!!

I let a comment about removing the error suppression on tests, anything else it's great!

Copy link
Collaborator

@adrianthedev adrianthedev left a comment

Choose a reason for hiding this comment

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

I tweaked the message and the tests.

I noticed that you disabled the error catching, but I think it's important to not do that.
We can check if an error was raised. I pushed a sample on the test you created.

On the last two specs we should not disable the error catching.
We should take a different approach. Maybe like I did on events?
Show the field only if a param is present?
This way we won't get random crashes when we do other tests or navigate the app, but still be able to test that scenario.

One thing that I'm a bit afraid of is coupling of the database tables.
For example, you can't have an event without a location. So in reality in the UI we will never be able to create an event because it will fail on the new page (no location resource present).
How about making the location optional to the event?
Maybe the same with location and stores?

Thsi way they are not so coupled and will give us some leeway with creating records.

To do:

  • Make models less coupled
  • remove the error catching from the two unrelated tests
  • show the error fields only if a param is present so we can test them

This is solid progress!
Thank you!

Let's address the issues above and we'll be able to merge it very soon.

spec/system/avo/skip_show_view_spec.rb Outdated Show resolved Hide resolved
spec/system/avo/resource_sidebar_spec.rb Outdated Show resolved Hide resolved
@adrianthedev
Copy link
Collaborator

BTW @bryszard, are you on our Discord?

@bryszard
Copy link
Contributor Author

bryszard commented Dec 8, 2023

BTW @bryszard, are you on our Discord?

Yes, Adrian, I am there :)

@bryszard
Copy link
Contributor Author

Thank you guys for the review. I'm back from holiday and will be able to adjust it in the next days.

@bryszard
Copy link
Contributor Author

bryszard commented Dec 12, 2023

@bryszard

The resources are not grouped correctly as they used to

They are grouped correctly, give a quick read here https://docs.avohq.io/3.0/resource-panels.html

We refactored the way that items are fetched from resource on avo3 allowing more customization

Let me know if the docs are clear or if there are some thinks that can be better explained

PS: Thank you for the contribution. I'll review it during this week

@Paul-Bob I think I found the reason - you've moved the Avo::Menu::Builder to the avo-menu plugin and it's under Pro licence (https://docs.avohq.io/3.0/menu-editor.html). When I run the dummy app I don't have it.

irb(main):006> Avo::Menu::Builder
(irb):6:in `<main>': uninitialized constant Avo::Menu (NameError)

@bryszard
Copy link
Contributor Author

bryszard commented Dec 12, 2023

@adrianthedev I've applied all the suggestions, but there is one failing spec:

After moving the model_missing_resource_spec to spec/features now for some reason it is raising #<ActionController::RoutingError: No route matches [GET] "/admin/resources/events"> (eg. here)

The problem is that I cannot reproduce it locally with bin/test ./spec/features/avo/model_missing_resource_spec.rb. I also don't see a problem with that route when running bin/dev. Could you help me here? :)

@Paul-Bob
Copy link
Contributor

@bryszard

The resources are not grouped correctly as they used to

They are grouped correctly, give a quick read here https://docs.avohq.io/3.0/resource-panels.html
We refactored the way that items are fetched from resource on avo3 allowing more customization
Let me know if the docs are clear or if there are some thinks that can be better explained
PS: Thank you for the contribution. I'll review it during this week

@Paul-Bob I think I found the reason - you've moved the Avo::Menu::Builder to the avo-menu plugin and it's under Pro licence (https://docs.avohq.io/3.0/menu-editor.html). When I run the dummy app I don't have it.

irb(main):006> Avo::Menu::Builder
(irb):6:in `<main>': uninitialized constant Avo::Menu (NameError)

Ah you meant the menu, yes, on avo versions > 3 the main branch contains mainly community version features, the pro/advanced features are distributed by packages.

Copy link
Contributor

@Paul-Bob Paul-Bob left a comment

Choose a reason for hiding this comment

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

@adrianthedev I've applied all the suggestions, but there is one failing spec:

After moving the model_missing_resource_spec to spec/features now for some reason it is raising #<ActionController::RoutingError: No route matches [GET] "/admin/resources/events"> (eg. here)

spec/features/avo/generators/resource_generator_spec.rb was overriding than deleting the event resource and controller I pushed a commit with a fix

Great PR this kind of feature will increase developer experience by far!

Thank you!

@adrianthedev adrianthedev force-pushed the feature/better_error_for_missing_resource branch from b2e0941 to 9bec1b8 Compare December 19, 2023 12:36
Copy link
Collaborator

@adrianthedev adrianthedev left a comment

Choose a reason for hiding this comment

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

Stellar work @bryszard!
This was a big pain point for Avo users, not getting enough feedback on what's wrong.

Thank you for your time and contribution.

@adrianthedev adrianthedev merged commit f4813ed into avo-hq:main Dec 19, 2023
11 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show special notification for when a resource is missing
3 participants