Closed netProphET closed 1 month ago
Revised approach based on feedback to Issue #209
If I'm on the right track, I'll continue with tests and anything else that needs tidying up or documenting. I'm still a bit new to the ecosystem, so guidance is appreciated.
Exciting! I'll look either this weekend or on Monday 🥳
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 :)
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.
I think it would make sense to do one of two things:
@zachdaniel this is coming together nicely, but I'm having difficulty with, of all things, the query for typeahead suggestions
This is the current non-working state of my function
defp fetch_suggestions(resource, query) do
label_field = AshAdmin.Resource.label_field(resource)
pk_field = Ash.Resource.Info.primary_key(resource)
resource
|> Ash.Query.new()
|> Ash.Query.load([pk_field, label_field])
|> Ash.Query.filter(
contains(
^label_field,
^%Ash.CiString{string: query}
)
)
|> Ash.read!()
|> Enum.map(&{Map.get(&1, label_field), &1.id})
end
I can't seem to make the field name in the contains function dynamic. It works as expected if I replace ^label_field with an actual field name. I'm not sure if I should be turning to a custom action here, or if I'm just missing some syntax with the current approach. Any insight is appreciated.
label_field
should be ^ref(label_field)
Excellent! Thanks. Guess I should rtfm some more ;-)
Addition of a
label_field
in a destination resource configuration signals to use a select box to represent the related resource.label_field
can be a resource attribute or a calculation.Contributor checklist