https://avo.cool logo
filters not being preserved
# general
m
or am I doing something wrong?
(and I'm using basic filters)
Ah, it seems to behave differently if rendered in the association turbo frame or not.
I’ll have more details soon
l
Hi
that fix is unrelated
It seems to be a bug when filters are applied on a association field
m
Thankfully I‘m not losing it 😅
l
do you have any details?
m
I‘ll post them when I‘m back at my computer. But it’s just two simple Boolean filters
I think the queries they trigger shouldn’t matter? One is querying a timestamp (simple if/else) and the other a JSONB field
l
Yeah it doesn't matter the query
the frame url is not updated on filter apply
actually it applies, need to dig into it
m
here are the filters, just for the record:
Copy code
rb
class Avo::Filters::EventRegistrations < Avo::Filters::BooleanFilter
  self.name = "Event Anmeldungen"
  # self.visible = -> do
  #   true
  # end

  def apply(request, query, values)
    return query if values["registered"] && values["unregistered"]

    if values["registered"]
      query = query.where.not(registered_at: nil)
    elsif values["unregistered"]
      query = query.where(registered_at: nil)
    end

    query
  end

  def options
    {
      registered: "Angemeldet",
      unregistered: "Nicht Angemeldet"
    }
  end
end

class Avo::Filters::EventRoles < Avo::Filters::BooleanFilter
  self.name = "Event Rollen"
  # self.visible = -> do
  #   true
  # end

  def apply(request, query, values)
    return query if values.values.all? { _1 }

    conditions = values
                   .select { |_, value| value == true }
                   .keys
                   .map { |role| "event_roles ->> '#{role}' = 'true'" }
                   .join(" OR ")

    query.where(conditions)
  end

  def options
    roles
  end

  def roles
    Event.find(params[:id])&.roles || {}
  end
end
the second is a bit more involved, but interestingly it does seem to work correctly if I take the Turbo Frame URL and paste it in a different browser tab
i.e. .../admin/resources/events/214/event_participations?view=show&turbo_frame=has_many_field_show_event_participations&page=1&encoded_filters=...
well, also not completely... also wrong, but different 😅
l
Yeah, needs investigation
m
can I help with this somehow? it's rather... pressing 🥴
l
Hi
Of course! Any help is appreciated
m
I mean, not a question of life and death
l
the filters code is all on the
avo
community
m
I'll take a look
l
let me know if you hit any obstacle with the setup / reproduction
we would merge a PR and cut a release with this fix
m
can't give you an ETA yet... other fires to put out 🧯 ... launch week y'know 😉
but I'll sure allocate some time monday at the latest
l
There is no pressure at all on community contributions. Take your time and make sure to ping me whenever you hit any blocker
Really appreciate the initiative
m
found the issue it's in
Copy code
js
  uriParams() {
    return URI(window.location.toString()).query(true);
  }
we need to check if we're in a Turbo Frame
then use its
src
, not the
window.location
I'll try a fix
okay, this works:
Copy code
js
  uriParams() {
    const turboFrame = this.urlRedirectTarget.dataset.turboFrame;
    return URI(
      !turboFrame
        ? window.location.toString()
        : this.element.closest(`turbo-frame#${turboFrame}`).src,
    ).query(true);
  }
now I just need to find a way to use your prettier settings 😄
okay I think I've got it... PR incoming...
l
That makes sense. Thanks for looking into in!