ash-project / ash_admin

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

Select input for foreign key field #209

Open netProphET opened 1 week ago

netProphET commented 1 week ago

A common pattern in admin UIs is to let the user select a foreign key value from a list of options from the related table. For example, when creating or editing an Item, the user might like to pick a Category from a list instead of copy/pasting a Category id from another view.

I've confirmed that this feature does not currently exist in ash_admin.

I have cooked up a naive solution which I'm happy to share via PR, but as I'm new to Ash (as well as Elixir) I suspect I don't have the configuration part well solved, or the feature set for that matter. It feels like with Ash it's important to get this part right first.

An example

In ash_admin:

Then my Resources look like this:

MyProject.Catalog.Item

  admin do
    form do
      field :category_id,
        type: :select,
        options: %{
          module: MyProject.Catalog.Category
        }
    end
  end

MyProject.Catalog.Category

  actions do
    read :select_options do
      prepare build(select: [:id, :name])
    end
  end

Things I'm unsure about:

I look forward to thoughts on this.

zachdaniel commented 1 week ago

I think that this should likely be derived automatically based on configuration in the destination resource perhaps?

Something like:

This allows doing things on your users like

label_field :admin_label

....

calculate :admin_label, :string, expr("#{email} (#{id})")