avo icon indicating copy to clipboard operation
avo copied to clipboard

Expand dynamic filter conditions

Open Paul-Bob opened this issue 6 months ago • 5 comments

I start to see a pattern.

Maybe the conditions should not be an array of labels or {key => label} like we'd use on the select input, but have more advanced objects with settings and stuff.


conditions: [{

  id: :is_within,

  label: "Is within",

  is_range: true,

  small_label: "> x <" # this is displayed on the pill when the filter is collapsed

}, {

  id: is_greater,

  label: "Greater than",

  small_label: ">="

}]

But maybe still have it work with a simple array or select-styled options.


[:is_within, :is_greater]



# or



{is_within: "Is within", is_greater: "Greater than"}

We'd also have to support some kind of fields switching for that. Maybe render two fields of that type instead of one and append start and end to those ID's.

So the query get's both of them.


def filters

  dynamic_filter :date, conditions: [

    {

      id: :is_within,

      label: "Is within",

      is_range: true,

      small_label: "> x <" # this is displayed on the pill when the filter is collapsed

    },

    {

      id: is_greater,

      label: "Greater than",

      small_label: ">="

    }

  ],

  query: -> {

    # Get these params and two fields in the UI for the `is_within` filter

    params[:date][:start]

    params[:date][:end]



    # this one and one field for the `is_greater` filter

    params[:date]



    query.DO_SOMETHING_WITH_THOSE_PARAMS

  }

end

WDYT?

Originally posted by @adrianthedev in #3013

Paul-Bob avatar Aug 09 '24 16:08 Paul-Bob