Skip to content

Multiple admin panels #265

@xNilsson

Description

@xNilsson

Is your feature request related to a problem? Please describe.

This might be a niche problem, but I have a use case where I want to have separate admin panels handling different domains in a Phoenix app. Currently, the ash_admin dashboard displays all domains, which can become problematic when domains have overlapping names or when segregation of domain management is required.

The reason for multiple admin panels is that I want to build 2+ websites/products, but to reuse functionality and have less hosting costs I want to share the same Phoenix app.

Describe the solution you'd like

I propose extending the current implementation to support multiple ash_admin dashboards by introducing group-based filtering. The changes would include:

  • Extending the AshAdmin.Domain DSL with a field called group, which is an optional atom that defaults to nil.
  • Updating the ash_admin router macro to accept a new option, for example:
    ash_admin("/admin", group: :a_group_name)
  • Adjusting the LiveView mount function in AshAdmin.PageLive to:
    • Retrieve the group value from the session.
    • In domains/1 If a group is provided, filter the list of domains to include only those with a matching group.

Describe alternatives you've considered

An alternative approach might involve using a separate configuration (e.g., an :ash_admin_groups setting) to manage domain grouping. However, leveraging the existing DSL by adding a group attribute seems to be a cleaner and more integrated solution.

Express the feature either with a change to resource syntax, or with a change to the resource interface

For example:

# In the domain
admin do
  name("MyDomain")
  show?(true)
  group(:a_group_name)
end

# In the router:
ash_admin("/admin", group: :a_group_name)  # Dashboard filters to display only domains for group :a_group_name

Additional context

I'm considering putting together a PR for this feature. Based on my understanding of the codebase, the required changes include extending the DSL in AshAdmin.Domain, updating the router macro to pass the group option, and filtering domains in the LiveView mount function based on the provided group.

Not sure if there are other issues that can arrise when having mutiple dashboards. Currently I want to have them both in /admin, but separated by host used. E.g. myapp.com/admin and myotherapp.com/admin.

Would you be open to a PR for this setup? And do you see any potential pitfalls or have suggestions on this approach?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions