Hello, I have been attempting to use the new encod...
# avo-2
b
Hello, I have been attempting to use the new encode_filter_params but have not been able to get it to work following the documentation. I can successfully encode to Base64, but the URL is not prepending with “…filters=…” It’s simply encoding the params and appending it to the URL which Avo is unable to interpret. Also, it appears the only way to pass params via URLs for now is using the filters correct? This is an elegant approach but appears tightly integrated requiring a lot of extra steps for simply passing some data from one view to another, etc… This
Copy code
redirect_to avo.resources_communities_path Avo::Filters::BaseFilter.encode_filters({"ClientFilter"=>models[0].id})
Produces
Copy code
http://localhost:3000/crm/resources/communities.eyJwYXJhbXMiOnt9fQ==%0A
While I believe for this whole thing to work it needs to produce this
Copy code
localhost:3000/crm/resources/communities?page=1&filters=eyJDbGllbnRGaWx0ZXIiOjQwMDExfQ==%0A
Am I not encoding it properly? Is there another, easier, way to pass data via URLs I am missing? Thanks!
l
I think you have to assign the value to the
filters
param
Copy code
ruby
redirect_to avo.resources_communities_path(filters: Avo::Filters::BaseFilter.encode_filters({"ClientFilter"=>models[0].id}))
but I'll default to @wide-art-99889's input here
b
Indeed this worked! 👍 Looks like the documentation needs to be corrected here, though.
l
done! thanks!
b
Also, how could I access these params from an Action? Following the docs I am unable to access them via the following:
Copy code
class DummyAction < Avo::BaseAction
  self.name = "Dummy action"

  def handle(**args)
    filters = Avo::Filters::BaseFilter.decode_filters(params[:filters])

    do_something_important_with_the_filters filters
  end
end
Are we able to access any URL params from an Action? I.e. do I need to even encode something I simply want to pass from a URL to an Action?
l
hmmm, you should get the
params
object
I tested it now and I was able to get the params
b
using
Copy code
Avo::Filters::BaseFilter.decode_filters(params[:filters])
?
l
I tested
params
🙂
could you post a GH issue please?
I'll ask @loud-jewelry-99127 to have a look when he's has the time
I'm working overtime to get Avo 3 out the door and I don't want to get tooo distracted
b
yes thanks for your help!
i meant 👍
l
haha. yeah, no worries 😛
thanks for understanding!
b
found a solution! discovered something interesting along the way... The following does not work as it cannot evaluate params[:client_id] on the index view
Copy code
action ExportCsv
  action ShortlistCommunities,
    arguments: {
      client_id: Avo::App.view_context.params[:client_id].to_i
    }
However, this does work!
Copy code
CLIENT_ID = Avo::App.view_context.params[:client_id].to_i

  action ExportCsv
  action ShortlistCommunities,
    arguments: {
      client_id: CLIENT_ID
    }
l
Avo::App.view_context.params[:client_id].to_i
can be shortened to skip the
view_context
like so
Avo::App.params[:client_id].to_i
AFAIK
b
hmm just tried and it doesn't work
l
hmmm. ok. then off the
view_context
it is 😛
b
running into one more issue...apparently while this approach works, it looks like the Resource is cached and thus not updating on new route...any idea how to avoid caching so it updates each time as the URL params change?
l
hmm, you mean after an action runs?
you can use the
reload
action reponse
b
In my initial approach, I evaluate
Copy code
Avo::App.view_context.params[:client_id].to_i
in CommunityResource and pass the params as arguments to an Action. This works the first time, but does not in subsequent routes (ie navigate to another page and back). In my console I can see Avo::CommunitiesController is able to detect the query params as the URL changes even after first load. Wondering how I can expose those params to CommunityResource and Action? The end goal = 1. visit Client profile and Select "Search Communities" action which navigates to Community Index View with query param containing client_id 2. on Community Index View evaluate the client_id param (if available) and show the user which Client they are currently searching Communities on behalf of 3. select a subset communities and utilize an Action to save them to a list for that specific client (currently I am passing the client_id as an argument to the Action from the CommunityResource)
l
could I ask you to create a recording of this and post it on a GitHub issue, please?
I know you laid it out step by step, but it's difficult for me to understand fully. maybe a video will make more sense?
b
my gut says this is a Rails thing as I think I am not grasping exactly how params are exposed and when
w
I opened https://github.com/avo-hq/avo/issues/1725 with a brief description of what we are hoping to accomplish
l
thank you! you're the best!