Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple admin panels #265

Open
cNille opened this issue Feb 2, 2025 · 3 comments
Open

Multiple admin panels #265

cNille opened this issue Feb 2, 2025 · 3 comments
Labels
enhancement New feature or request

Comments

@cNille
Copy link

cNille commented Feb 2, 2025

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?

@cNille cNille added the enhancement New feature or request label Feb 2, 2025
@zachdaniel
Copy link
Contributor

Hey there! I'd accept a PR for adding a group to domains, yes 😄. Ultimately AshAdmin will be rewritten (like not in the next few weeks/months or anything), and part of that will include the ability to easily define multiple admin UIs. But your solution is a good solution for the short term 👍

@cNille
Copy link
Author

cNille commented Feb 2, 2025

Thanks for quick reply! I have pushed a pull-request now with the feature :D

Improving on AshAdmin sounds like a fun project. Is there somewhere where I can read up on the roadmap and what features are missing/needs improving? :)

I'm new to open source contributing, and seeing that ash_admin is only around 8000 lines of elixir code makes it feel quite approachable. So I'd be happy to be on the loop on future work!

@zachdaniel
Copy link
Contributor

Only the issues in this project :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants