Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Dynamic filters 2.0 #2268

Open
3 tasks done
adrianthedev opened this issue Dec 20, 2023 · 3 comments
Open
3 tasks done

[RFC] Dynamic filters 2.0 #2268

adrianthedev opened this issue Dec 20, 2023 · 3 comments

Comments

@adrianthedev
Copy link
Collaborator

adrianthedev commented Dec 20, 2023

The Dynamic filters feature is a powerful and beautiful way of letting users query data.

We'd love to give the developer an API with which they can further customize the filters.
Some of the things we'd like to have customizable:

  • field (text, number, combobox, date)
  • conditions (is, is not, is withing, etc.)
  • suggestions (options)
  • query logic. give the developer the raw power to make the query what they want.

Let's also change the API in which they are declared. It's clear to me that just calling filterable is not enough. It's a good "easy" way to do it, but we need more power.

Things to consider with this new API/DSL:

  • should we build them on the resource?
  • should we build them in a separate file?

Related issues

  1. Enhancement
  2. Enhancement
  3. Enhancement Stale exempt

Examples

Pseudo-API below. Not final.

field :name, as: :select, filterable: {
  conditions: [:is, :is_not],
  options: -> { User.states }
}
self.dynamic_filters = -> {
  filters: [
    {
      attribute: :name,
      type: :select,
      conditions: [:is, :present, :blank, :nil],
      field: {
        type: :select,
        options: [:one, :two, :three
      }
    }
  ]
}
@adrianthedev adrianthedev changed the title Customized dynamic filters Customizable dynamic filters Dec 21, 2023
@adrianthedev adrianthedev added this to the [Draft] Avo Q2 2024 milestone Jan 9, 2024
@adrianthedev adrianthedev changed the title Customizable dynamic filters Dynamic filters 2.0 Apr 15, 2024
@adrianthedev adrianthedev pinned this issue Apr 15, 2024
@adrianthedev adrianthedev changed the title Dynamic filters 2.0 [RFC] Dynamic filters 2.0 Apr 15, 2024
@adrianthedev
Copy link
Collaborator Author

Experiments

  self.dynamic_filters = {
    fields: [:status, :state],
    filters: [
      # hierarchy
      # - database
      # - field
      # - dynamic_filters
      avo_filter(attribute: :name, type: :select),
      Avo::Filter.new(attribute: :name, type: :select),
      Avo::Filter.new(attribute: :name, type: :select),
      Avo::Filter.new(attribute: :name, type: :select),
      Avo::Filter.new(attribute: :name, type: :select),
      {
        attribute: :name,
        type: :select,
        conditions: [:is, :present, :blank, :nil],
        field: {
          type: :select,
          options: [:one, :two, :three]
        },
        # fields: [{
        #   id: :first_name,
        #   type: :select,
        #   options: [:one, :two, :three]
        # },{
        #   id: :last_name,
        #   type: :select,
        #   options: [:one, :two, :three]
        # }]
      },
      {
        attribute: :last_name,
        type: :select,
        conditions: [:is, :present, :blank, :nil],
        field: {
          type: :select,
          options: [:one, :two, :three]
        }
      }
    ]
  }

filterable: Avo::Filter.new(attribute: :name, type: :select),

@jetienne
Copy link

@adrianthedev do you plan for some lazy loading version? Or even a belongs-to type?

@adrianthedev
Copy link
Collaborator Author

@adrianthedev do you plan for some lazy loading version? Or even a belongs-to type?

Yes @jetienne.
Me and the team are going to talk about and build some kind of lazy-loaded select somehow which can be applied system-wide.
We'll evaluate https://github.com/josefarias/hotwire_combobox. Looks promising.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: To Do
Development

No branches or pull requests

2 participants