avo
avo copied to clipboard
fix: remove ActiveRecord inferrence from component
Description
Fixes https://github.com/avo-hq/avo/issues/3192
Checklist:
- [x] 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
Code Climate has analyzed commit c8317fab and detected 0 issues on this pull request.
View more on Code Climate.
For my error (following https://docs.avohq.io/3.0/guides/rest-api-integration.html), I need to make this change to make it pass. I'm happy to make a separate PR, but it feels like it should be together.
FYI_Any does not include nil so you may need to do the same to fix https://github.com/avo-hq/avo/issues/3192 for @xeron.
class Avo::Views::ResourceEditComponent
...
prop :record, _Nilable(_Any)
...
end
FYI
_Anydoes not includenilso you may need to do the same to fix #3192 for @xeron.
I'm not setting current_user to nil, I'm passing a Struct, only name attribute is nil.
We discovered a second error today. So far the following would fix our two issues for us:
class Avo::PanelComponent < Avo::BaseComponent
...
prop :name, _Nilable(_Union(_String, _Integer)) do |value|
value || @args&.dig(:title)
end
...
end
class Avo::Views::ResourceEditComponent < Avo::ResourceComponent
...
prop :resource, _Nilable(_Any)
...
end
Lies... This is what I had to do (so far):
# in config/initializers/avo.rb
module OverrideAvoPanelComponent
extend ActiveSupport::Concern
included do
prop :name, _Nilable(_Union(_String, _Integer)) do |value|
value || @args&.dig(:title)
end
end
end
module OverrideAvoPanelNameComponent
extend ActiveSupport::Concern
included do
prop :name, _Nilable(_Union(_String, _Integer))
end
end
module OverrideAvoResourceEditComponent
extend ActiveSupport::Concern
included do
prop :record, _Nilable(_Any)
end
end
module OverrideAvoFieldBadgeViewerComponent
extend ActiveSupport::Concern
included do
prop :value, _Union(_String, _Symbol)
end
end
Rails.configuration.to_prepare do
Avo::PanelComponent.include(OverrideAvoPanelComponent)
Avo::PanelNameComponent.include(OverrideAvoPanelNameComponent)
Avo::Fields::Common::BadgeViewerComponent.include(OverrideAvoFieldBadgeViewerComponent)
Avo::Views::ResourceEditComponent.include(OverrideAvoResourceEditComponent)
end
Thanks @rickychilcott for brainstorming this with us.
I don't quite get why cast the resource as any here prop :resource, _Nilable(_Any)?
I mean... we are expecting a resource to be given otherwise it will most likely crash.
This PR has been merged into main. The functionality will be available in the next release.
Please check the release guide for more information.