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

Merged
merged 24 commits into from
Jan 31, 2025
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
617ead6
feature: add automatic field detection in resources
ObiWanKeoni Dec 11, 2024
b30d05a
Merge branch 'main' into feature/automatic-field-detection
ObiWanKeoni Dec 11, 2024
3e55c88
Apply suggestions from code review
ObiWanKeoni Jan 9, 2025
f6e8b23
Optimize model enum check
ObiWanKeoni Jan 9, 2025
ac66258
Rubocop / Refactor for readability + solving problems with select inputs
ObiWanKeoni Jan 10, 2025
b5f0c6f
Fix up tags and rich texts a bit
ObiWanKeoni Jan 10, 2025
657c2da
Rubocop
ObiWanKeoni Jan 10, 2025
c76f034
Oops - use `standardrb` instead of `rubocop`
ObiWanKeoni Jan 10, 2025
3faf2da
Few more lint fixes
ObiWanKeoni Jan 10, 2025
7bc8c90
Couple more
ObiWanKeoni Jan 10, 2025
9f1bc4c
Indentation
ObiWanKeoni Jan 10, 2025
cd5c5e5
Merge branch 'main' into feature/automatic-field-detection
Paul-Bob Jan 10, 2025
4b36f1f
PR suggestions
ObiWanKeoni Jan 10, 2025
329d0c8
Lint spec file
ObiWanKeoni Jan 10, 2025
d7dd291
Remove custom resource in favor of using temporary items
ObiWanKeoni Jan 10, 2025
2ffac80
Add after blocks for cleanup
ObiWanKeoni Jan 13, 2025
a6db237
Lint
ObiWanKeoni Jan 13, 2025
0892908
Add back resource with discovered fields
ObiWanKeoni Jan 14, 2025
82fab1d
Fix status issue and remedy test setup
ObiWanKeoni Jan 16, 2025
bff6416
Merge branch 'main' into feature/automatic-field-detection
ObiWanKeoni Jan 29, 2025
5d60d7e
Update to use Avo::Mappings
ObiWanKeoni Jan 29, 2025
8abf435
Higher specificity for specs
ObiWanKeoni Jan 30, 2025
bc04386
Attempt to wait for post to load
ObiWanKeoni Jan 30, 2025
490a2e2
More reliable specs
ObiWanKeoni Jan 30, 2025
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
Prev Previous commit
Next Next commit
Remove custom resource in favor of using temporary items
  • Loading branch information
ObiWanKeoni committed Jan 10, 2025
commit d7dd291ad1f47c08ce68ddb5cc9c834a857a8ec4
35 changes: 0 additions & 35 deletions spec/dummy/app/avo/resources/field_discovery_user.rb

This file was deleted.

This file was deleted.

42 changes: 36 additions & 6 deletions spec/system/avo/has_field_discovery_spec.rb
Original file line number Diff line number Diff line change
@@ -4,8 +4,38 @@
let!(:user) { create :user, first_name: "John", last_name: "Doe", birthday: "1990-01-01", email: "john.doe@example.com" }
let!(:post) { create :post, user: user, name: "Sample Post" }

before do
Avo::Resources::User.with_temporary_items do
main_panel do
discover_columns except: %i[email active is_admin? birthday is_writer outside_link custom_css]
discover_associations only: %i[cv_attachment]

sidebar do
with_options only_on: :show do
discover_columns only: %i[email], as: :gravatar, link_to_record: true, as_avatar: :circle
field :heading, as: :heading, label: ""
discover_columns only: %i[active], name: "Is active"
end

discover_columns only: %i[birthday]

field :password, as: :password, name: "User Password", required: false, only_on: :forms, help: 'You may verify the password strength <a href="http://www.passwordmeter.com/" target="_blank">here</a>.'
field :password_confirmation, as: :password, name: "Password confirmation", required: false, revealable: true

with_options only_on: :forms do
field :dev, as: :heading, label: '<div class="underline uppercase font-bold">DEV</div>', as_html: true
discover_columns only: %i[custom_css]
end
end
end

discover_associations only: %i[posts]
discover_associations except: %i[posts post cv_attachment]
end
end

describe "Show Page" do
let(:url) { "/admin/resources/field_discovery_users/#{user.slug}" }
let(:url) { "/admin/resources/users/#{user.slug}" }

before { visit url }

@@ -37,7 +67,7 @@
# Verify `posts` association
expect(page).to have_text "Posts"
expect(page).to have_text "Sample Post"
expect(page).to have_link "Sample Post", href: "/admin/resources/posts/#{post.slug}?via_record_id=#{user.slug}&via_resource_class=Avo%3A%3AResources%3A%3AFieldDiscoveryUser"
expect(page).to have_link "Sample Post", href: "/admin/resources/posts/#{post.slug}?via_record_id=#{user.slug}&via_resource_class=Avo%3A%3AResources%3A%3AUser"

# Verify `cv_attachment` association is present
expect(page).to have_text "CV"
@@ -73,7 +103,7 @@
end

describe "Index Page" do
let(:url) { "/admin/resources/field_discovery_users" }
let(:url) { "/admin/resources/users" }

before { visit url }

@@ -89,7 +119,7 @@
end

describe "Form Page" do
let(:url) { "/admin/resources/field_discovery_users/#{user.id}/edit" }
let(:url) { "/admin/resources/users/#{user.id}/edit" }

before { visit url }

@@ -130,7 +160,7 @@
end

describe "Has One Attachment" do
let(:url) { "/admin/resources/field_discovery_users/#{user.id}/edit" }
let(:url) { "/admin/resources/users/#{user.id}/edit" }

before { visit url }

@@ -218,7 +248,7 @@
end

describe "Ignored Fields" do
before { visit "/admin/resources/field_discovery_users/#{user.slug}" }
before { visit "/admin/resources/users/#{user.slug}" }

it "does not display sensitive fields" do
wait_for_loaded