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: add automatic field detection in resources #3516

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ObiWanKeoni
Copy link
Contributor

@ObiWanKeoni ObiWanKeoni commented Dec 11, 2024

Description

Fixes #3390

This is my working prototype for the issue linked above. It inspects the model much like the resource generator in:
https://github.com/avo-hq/avo/blob/617ead62d09f3f8c04a7438c5fc7cc461f5fcee8/lib/generators/avo/resource_generator.rb

As it gathers all of the columns and associations, it calls the #field method to add a field item dynamically. I've added a new User resource with many different use cases of the discover_columns and discover_associations methods.

Important

As I am still very new to contributing here, I am unfamiliar with some of the design patterns and decisions made thus far in Avo. I would advise that reviewers pay special attention to whether I have broken patterns necessary for cleanliness and readability. There may also be opportunities for refactoring and applying these discovered fields to, say, tab groups but I wanted to get initial feedback before proceeding with the patterns I've established so far.

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 & recording

Manual review steps

  1. Step 1
  2. Step 2

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

end

# Discovers and configures database columns as fields
def discover_columns(only: nil, except: nil, **field_options)
Copy link

Choose a reason for hiding this comment

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

Method discover_columns has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.

end
end

def discover_attachments
Copy link

Choose a reason for hiding this comment

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

Method discover_attachments has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.

end
end

def discover_basic_associations
Copy link

Choose a reason for hiding this comment

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

Method discover_basic_associations has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.

Copy link

codeclimate bot commented Dec 11, 2024

Code Climate has analyzed commit b30d05a and detected 3 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 3

View more on Code Climate.

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.

This is amazing, @ObiWanKeoni!

I've been testing some scenarios locally, and it's awesome!

I took a look at the code, and it's fantastic that you managed to keep it within the HasFieldDiscovery concern. This will undoubtedly make our review much easier!

Congratulations on this incredible work!

We'll provide a detailed code review once we validate the DSL and its behavior.

@adrianthedev adrianthedev mentioned this pull request Dec 18, 2024
4 tasks
Copy link
Contributor

This PR has been marked as stale because there was no activity for the past 15 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add automatic field detection in resources
3 participants