lardcanoe

lardcanoe

I’m adding a visual query builder, and https://react-querybuilder.js.org/ seems like the most robust one.

It will be used with Ash resources, some of which will have embedded schemas.

I’m looking for a gut reaction, or recommendation, on the best way to hook these up.

First is mapping Ash resources to its field format, which is like:

const fields: Field[] = [
  { name: 'name', label: 'Name', datatype: 'text' },
  { name: 'birthday', label: 'Birthday', datatype: 'date', inputType: 'date' },
  { name: 'guitars', label: 'Guitars', datatype: 'number', inputType: 'number' },
  {
    name: 'favoriteMovie',
    label: 'Favorite Movie',
    datatype: 'text',
    operators: [{ name: '=', label: 'is' }],
  },
];

Second, is taking its output, and mapping that to an Ash Query filter. There are numerous export options, see Export | React Query Builder, and I couldn’t tell which would be the best starting point.

Thank you!

Showing Posts 1 to 8

zachdaniel

zachdaniel

Creator of Ash

Ash actually accepts a map syntax for its filters :slight_smile: you’d pass a map into Ash.Filter.parse_input.

A small note about it in the docs: Ash.Filter — ash v3.29.3

Edit: I assume you aren’t using liveview?

lardcanoe

lardcanoe OP

k, I had stumbled on Ash.Query.html#filter_input/2 Ash.Query — ash v3.29.3 so I can munge it to conform to that.

I am using Liveview. I just didn’t want to spend a day or two making a simplistic version of the react query builder. Or were you going somewhere else with that? If I manage to get this PoC to beta, maybe I would rip out the react tools with custom liveview ones.

To construct the fields for the builder, something like MyApp.MyResource.spark_dsl_config[[:attributes]] seems like my best starting point. Agree?

zachdaniel

zachdaniel

Creator of Ash

So, we have the data structure for backing a filter form, but not the UI, meant to be used with live view. It can be a bit complicated to wield, but once you get it working it’s quite useful. Check out Ash.FilterForm. Maybe someone from the community can provide an example implementation/tips. I know @frankdugan3 has used it, among others. Would like to work up an example and better docs, haven’t had the chance.

dblack

dblack

Here’s an example implementation of Filter form

https://github.com/totaltrash/filter_form_example

zachdaniel

zachdaniel

Creator of Ash

Oh, right, how could I have forgotten! That’s a great example :slight_smile: thanks @dblack

jakeboone02

jakeboone02

Maintainer of React Query Builder here. I’m not familiar with this framework but this post came up in my Google alerts. If there’s anything I can do or questions I can answer about RQB, let me know!

lardcanoe

lardcanoe OP

FilterForm is pretty cool. Thanks for pointing that out!

The one shipped in ash_phoenix seems to be missing relationships. A demo you posted in Zach Daniel posted on LinkedIn shows relationships being used. Any thoughts on how that was accomplished? :innocent:

The users of this feature are used to writing their own SQL, so I’m tempted to just let them write some JSON which gets converted to a Map that is compatible with Ash.Query.filter and just move one with life and build the UI later. This was one of those “if it is quick to implement, do it, otherwise move on” features.

Ash.Query.filter(resource, [or: [
  [first_name: "Zar"],
  [last_name: "Doz"],
  [or: [
    [high_score: [greater_than: 10]]],
    [high_score: [less_than: -10]]
  ]
]])

That being said, can user text input, like first_name == "Zar" and last_name in ["Doz", "Daz"] and high_score > 10 be passed to any of the Ash filter or expr functions, or is that bonkers?

Thank you to everyone!

zachdaniel

zachdaniel

Creator of Ash

Unfortunately no, there is no text based filter parser, although writing one that ships with ash core is doable. But not going to happen any time soon :joy:

— All posts loaded —

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews