avo icon indicating copy to clipboard operation
avo copied to clipboard

fix: remove ActiveRecord inferrence from component

Open adrianthedev opened this issue 1 year ago • 5 comments

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

adrianthedev avatar Aug 27 '24 20:08 adrianthedev

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

View more on Code Climate.

qlty-cloud-legacy[bot] avatar Aug 27 '24 21:08 qlty-cloud-legacy[bot]

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

rickychilcott avatar Aug 28 '24 00:08 rickychilcott

FYI_Any does not include nil so 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.

xeron avatar Aug 28 '24 03:08 xeron

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

rickychilcott avatar Aug 28 '24 20:08 rickychilcott

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

rickychilcott avatar Aug 29 '24 15:08 rickychilcott

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.

adrianthedev avatar Sep 03 '24 07:09 adrianthedev

This PR has been merged into main. The functionality will be available in the next release.

Please check the release guide for more information.

github-actions[bot] avatar Sep 03 '24 10:09 github-actions[bot]