Admin Extensibility #4116
Replies: 12 comments 12 replies
-
All of this looks awesome! One topic I want to throw out for comment: In combination with this more user-friendly way of installing plugins, there would be a log of benefit to revamping how Medusa handles (1) config variables and (2) which packages are loaded as plugins.
Edit: Looking at the roadmap, it seems like some work on (1) settings is already there. I got over-excited and jumped the gun! |
Beta Was this translation helpful? Give feedback.
-
@kasperkristensen Thanks for the extensive overview and early info. Would the first iteration allow us also to replace some of the native widgets, which come bundled with the admin, with custom ones? |
Beta Was this translation helpful? Give feedback.
-
Some useful case of extend is a possibility to add new fields for product, for example short description, or possibility to add metadata for options from admin dashboard( this is both real examples of our needs in project).
|
Beta Was this translation helpful? Give feedback.
-
@kasperkristensen Great initiative to bring such feature into Medusa but I had a question regarding the building of these widgets. Is there a plan for providing a design system that we can use or do we have to be familiar with the admin UI repository and the components built there? |
Beta Was this translation helpful? Give feedback.
-
Hi @kasperkristensen , |
Beta Was this translation helpful? Give feedback.
-
Would be nice if there was a plugin that let the global admin choose whether users can access the admin dashboard. Users can then add products and see everything regarding only their own products. This would make it easy to create a marketplace. |
Beta Was this translation helpful? Give feedback.
-
There is no InjectionZone for Categories ? |
Beta Was this translation helpful? Give feedback.
-
Any ETA on hot reloading while developing? |
Beta Was this translation helpful? Give feedback.
-
medusa-admin eject -o Says the eject command does not exist |
Beta Was this translation helpful? Give feedback.
-
Is there any way to use this to hide some menu items in left nav of admin dashboard ? |
Beta Was this translation helpful? Give feedback.
-
Hello, The current implementation allows for customization but forces to use the Admin dashboard as it is shipped at all times (no way to hide left vertical tabs or navigate to a custom route after login). I am trying to build a marketplace, so the Admin for me also needs to support Role Based Access Control, which with the current extensibility features i am only able to do by hacking my way around and forking the Admin UI. To avoid this and support marketplaces, i think we should be provided out-of-the-box with features:
Is anything like this been worked on now / in the near future? |
Beta Was this translation helpful? Give feedback.
-
I want to create custom ui pages in medusa admin, it should be visible in sidebar as well , i was able to create one page but the second page is not working. |
Beta Was this translation helpful? Give feedback.
-
Preface
This feature is still under development and will likely change as we continue to work on it over the coming weeks. It should not be seen as a finalized feature in any way. We are sharing this early stage preview because we are very interested in getting feedback from users. We want to hear about your potential use cases for admin extensibility and what you would like to see as part of this feature.
Please note that the first iteration will have limited extension capabilities. This means that developers will not be able to fully extend, customize, or replace all parts of the existing admin. Instead, the first iteration will be limited to injecting
Widgets
into the edit pages, list pages, and the login page.This document will be updated if changes are made to the feature.
Abstract
This feature aims to enable developers to extend the admin dashboard both through local extensions written in their server directory, and through plugins. Developers should be able to hook into predetermined parts of the admin, such as adding a widget to the product details page or creating an entirely new page.
Motivation
Currently, developers have to either fork and customize their admin dashboard or create a separate dashboard to manage any custom logic they have introduced to their Medusa server. However, this is not a very scalable solution because it is difficult to maintain these customizations while also pulling upstream changes to the admin dashboard.
To address this issue, we are introducing admin extensibility. Our goal is to provide developers with a clear and streamlined way to add support for their custom logic in the admin dashboard, without the added burden of maintaining a fork or separate dashboards.
Goals
Proposal
Widgets
A widget is a section that can be injected into an existing page of the current dashboard, where these widgets can be injected is determined by a list of valid
injectionZones
. Some examples of these zones areproduct.details
,order.list
,customer.details
,login
.Based on the
injectionZone
theWidget
will be rendered in the correct place in the dashboard.Widgets with the InjectionZone
customer.details
will be rendered in the outlined area.List of supported
InjectionZones
, note that these zones are preliminary and may change:product.details
(/a/products/:id
)product.list
(/a/products
)product_collection.details
(/a/collections/:id
)product_collection.list
(/a/products
collection view)customer.details
(/a/customers/:id
)customer.list
(/a/customers
)customer_group.details
(/a/customers/:id
)customer_group.list
(/a/customers/groups/:id
)discount.details
(/a/discounts/:id
)discount.list
(/a/discounts
)order.details
(/a/orders/:id
)order.list
(/a/orders
)draft_order.details
(/a/draft-orders/:id
)draft_order.list
(/a/draft-orders
)price_list.details
(/a/pricing/:id
)price_list.list
(/a/pricing
)gift_card.details
(/a/gift-cards/manage
)gift_card.list
(/a/gift-cards
)custom_gift_card
(/a/gift-cards/:id
)login.before
(/login
above inputs)login.after
(/login
below inputs)Creating a Widget
Widgets can be defined in any
.{tsx|jsx}
file located within thesrc/admin
folder. For the widget to be registered correctly, it needs to be passed to a special helper function calledextend
. This function must be thedefault export
of thesrc/admin/index.{ts|js}
file.The
extend
function has aidentifier
parameter that indicates the origin of the extension. For local extensions, we recommend using an identifier like"local"
to clearly indicate that the extension(s) come from the local server directory. Plugins should pass the same value as what is written in thename
field of the package'spackage.json
.When adding a widget, it should be placed under the injection zone where you want the plugin to be rendered. In the example above, the widget should be rendered at
product.details
, so it is added towidgets.product.details
. Injection zones accept an array of widgets, consisting of aComponent
and aname
. The name should be unique so that it is easy to identify. This, combined with theidentifier
, is used to render an error message if a widget crashes during development.Building an extension
To build extensions, use the
@medusajs/admin-sdk
CLI tool. This tool bundles the extension using Rollup, allowing it to be used within the admin dashboard. Our goal is to integrate this tool into themedusa-cli
so that the workflow for working on local extensions remains the same as it is today when extending server logic. However, plugin maintainers will still need to run the command separately before releasing their plugin.The build command is
extensions build
, and also supports building the extensions in watch mode by passing the flag-w
.How extensions are loaded
Extensions are loaded during the build step of the admin project. To find extensions, the admin build command searches for
dist/admin/index.js
in the developer's server directory and fornode_modules/<plugin>/dist/admin/index.js
for each plugin registered in the project'smedusa-config.js
file. Whether a developer works on local or plugin extensions, the folder structure is the same.When the admin build command finds an extension, it writes the import path to a file that is then used to import all extensions into the dashboard. From here, the extensions are passed on to a context that is called at the various injection zones to render the extensions in their correct place.
Widgets are rendered within a
WidgetContainer
that serves two functions. First, it passes the appropriate props to theWidget
, such asOrderWidgetProps
in the example above. Second, it acts as an error boundary, preventing errors in an injected widget from crashing the entire Admin application. If an unhandled error is thrown within aWidget
, theWidgetContainer
shows an error notification in the UI. The notification provides details on whichWidget
(usingname
) crashed and the origin (identifier
passed toextend
) of the faulty widget (local or plugin).Demo
A video demonstration is available at →
https://www.loom.com/share/f46f163f670c4640bf4a2f1859439a25
Source code for the demo is available at →
https://github.com/kasperkristensen/admin-widget-demo/tree/main
Current limitations
The
admin dev
command is currently bugged, preventing extensions from running in a dev environment. This means that hot-reloading changes is not supported. Instead, you will need to rebuild extensions and then the admin to see changes take effect. We have updated theyarn start
command to include this process, as well as restarting your server for a more convenient experience, while we work on fixing the development flow.Currently, extensions only support styling using
tailwind
. For the best developer experience, we recommend creating a barebonestailwind.config.js
file at the root of your project and installing theTailwind CSS IntelliSense
VS Code plugin.Our plan for later this year is to ship a UI library. This will make it easier to create extensions that fit seamlessly into the look and feel of the dashboard. Additionally, we plan to allow users to pass custom
Rollup
config options to the extension build tool to support their preferred styling approach.Widgets are currently not rendered at any of the
<domain>.list
andlogin
injection zones. They will be added in a later snapshot.Roadmap
Below is a roadmap of future iterations for this feature. The first iteration is currently being worked on and will add support for
widgets
in the details pages of all domain detail pages, domain overview pages, and login page.The following iterations will add support for new types of extensions:
Second Iteration
Support
pages
that allow developers to add new settings pages and new domain pages. Settings pages will render as a card in the settings overview and create a new page in the dashboard. New domain pages will render as a link in the sidebar and create a new page in the dashboard.Third Iteration
Support replacing existing domains, domain sections, domain create flows, and setting pages
Related projects
We are also planning on shipping a UI library later this year that will make it easier to build extensions that fit in seamlessly with the existing admin. The current plan is to begin working on it simultaneously with the second and third iterations of extensibility and roll it continuously as components are ready.
Beta Was this translation helpful? Give feedback.
All reactions