LiveAdmin - Phoenix admin UI built on LiveView

New release v0.9.0 :champagne:

API changes

Star attraction is a completely overhauled router config API. This was initially inspired by questions raised in this thread about the proper place for configuration, which lead to my realizing that although it was technically possible to run multiple instances of live_admin in a single app, this was pretty cumbersome (see Allow admin-instance resource config · Issue #34 · tfwright/live_admin · GitHub and support configuring via the router rather than app config by mayel · Pull Request #33 · tfwright/live_admin · GitHub).

The refactor essentially consists of 2 main parts:

  1. The live_admin macro now takes a block, in which you specify each resource route using a new admin_resource macro.
  2. Instead of passing a list of config options directly, you pass a module which uses the LiveAdmin.Resource module, and all “extra” resource configuration is specified there, with the exception of slug_with (“general” configuration will still be passed to live_admin)

So, assuming you had this in 0.8.x:

defmodule MyApp.Router do
  import LiveAdmin.Router

  live_admin "/admin", title: "My Admin UI", resources: [{MyApp.FooSchema, slug_with: "foos", label_with: "Foo"}]
end

You must now do this after updating to 0.9:

defmodule MyApp.FooSchema do
  use LiveAdmin.Resource, label_with: "Foo"
end

defmodule MyApp.Router do
  import LiveAdmin.Router

  live_admin "/admin", title: "My Admin UI" do
    admin_resource "/foos", MyApp.FooSchema
  end
end

Note that the “resource” module can be any module, but if it is not an Ecto schema, then the schema option must be specified. Additionally, it is now possible to specify the ecto_repo option at the live_admin and/or resource level, as was already the case with most other configs. For more information consult the LiveAdmin.Resource and LiveAdmin.Router module docs.

UI changes

Field “type” classes are now on the group rather than the specific input. This should make it slightly easier to target various related elements in the form. This should only affect you if you were overriding any of the .field__foo classes. You will need to update the selectors for any such overrides to be something like .field__foo input, but this will vary from case to case. Apologies to anyone affected since obviously this will be somewhat tedious. I am really hoping to keep FE changes to a minimum going forward, and then frozen for major versions after 1.0.

6 Likes