ash-project / ash_admin

A super-admin UI dashboard for Ash Framework applications, built with Phoenix LiveView.
https://hexdocs.pm/ash_admin
MIT License
106 stars 48 forks source link

Select / typeahead combo for foreign key field #222

Open netProphET opened 1 month ago

netProphET commented 1 month ago

Apologies for discontiguous PR.

Relevant discussion points from previous (#210

zachdaniel:

So, this is very cool, but I do worry that it can only really be used for low cardinality relationships. i.e if you had 100k users, you would need a type-ahead that would do things like fetch data after a few characters were displayed etc.

If we add this and someone misuses it, it might look good in dev but then when running in prod it could cause significant issues.

Would you be open to making it a typeahead? It doesn't have to look beautiful :)

netProphET:

Yeah that concern crossed my mind as well, and a typeahead could be a good solution. Definitely don't want to provide the rope to hang a production site with. However, not sure I love typeahead for the really low cardinality relationships, e.g. say you have 3 Categories to pick from. I'm happy to play around with this till we have something that will scale.

zachdaniel:

I think it would make sense to do one of two things: fetch some limited number of results, and if there are less than that that come back, we show a select, and if there are more we show a typeahead. make it configurable from the outset in the source form. Like configuring it from the source.

So I learned a lot doing this, which is great. I may have gone overboard in how I implemented some of this due to my inexperience with some of the idioms. I'm also unsure about the naming choices for the DSL: admin.label_field and admin.relationship_select_max_items. Also I did not implement a minimum # of characters to wait for in the typeahead yet. It doesn't feel too terrible to me to have it start showing results after 1 keystroke (it does use a 300 ms debounce).

Contributor checklist

netProphET commented 1 day ago

Quick update on this: work is still in progress. I've been working with Ash Admin's demo app, which surfaces some concepts I'm still absorbing, and has exposed some weaknesses in my implementation here. More soon.