# new AdminBro(options)
Parameters:
Name | Type | Description |
---|---|---|
options |
AdminBroOptions | Options passed to AdminBro |
Example
const AdminBro = require('admin-bro')
const admin = new AdminBro(AdminBroOptions)
Members
# static ACTIONS
List of all default actions. If you want to change the behavior for all actions like: list, edit, show, delete and bulkDelete you can do this here.
Example
Modifying accessibility rules for all show actions
const { ACTIONS } = require('admin-bro')
ACTIONS.show.isAccessible = () => {...}
# resources
List of all resources available for the AdminBro. They can be fetched with the AdminBro#findResource method
Methods
# static bundle(src, componentNameopt) → {String}
Requires given .jsx/.tsx
file, that it can be bundled to the frontend.
It will be available under AdminBro.UserComponents[componentId].
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
src |
String | Path to a file containing react component. |
|
componentName |
OverridableComponent |
<optional> |
name of the component which you want to override |
componentId - uniq id of a component
Examples
Passing custom components in AdminBro options
const adminBroOptions = {
dashboard: {
component: AdminBro.bundle('./path/to/component'),
}
}
Overriding AdminBro core components
// somewhere in the code
AdminBro.bundle('./path/to/new-sidebar/component', 'SidebarFooter')
# static registerAdapter(options)
Registers various database adapters written for AdminBro.
Parameters:
Name | Type | Description |
---|---|---|
options |
Object | |
Database |
Class.<BaseDatabase> | subclass of BaseDatabase |
Resource |
Class.<BaseResource> | subclass of BaseResource |
Example
const AdminBro = require('admin-bro')
const MongooseAdapter = require('admin-bro-mongoose')
AdminBro.registerAdapter(MongooseAdapter)
# findResource(resourceId) → {BaseResource}
Returns resource base on its ID
Parameters:
Name | Type | Description |
---|---|---|
resourceId |
String | ID of a resource defined under BaseResource#id |
When resource with given id cannot be found
found resource
Example
const User = admin.findResource('users')
await User.findOne(userId)
# async initialize()
Initializes AdminBro instance in production. This function should be called by all external plugins.
# async renderLogin(options) → {Promise.<string>}
Renders an entire login page with email and password fields using Renderer.
Used by external plugins
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
options |
Object | ||
action |
String | Login form action url - it could be '/admin/login' |
|
errorMessage |
String |
<optional> |
Optional error message. When set, renderer will print this message in the form |
HTML of the rendered page
# async watch() → {Promise.<never>}
Watches for local changes in files imported via AdminBro.bundle. It doesn't work on production environment.
Type Definitions
# CurrentAdmin
Currently logged in admin.
Usage with TypeScript
import { CurrentAdmin } from 'admin-bro'
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
email |
string | Admin has one required field which is an email |
|
title |
string |
<optional> |
Optional title/role of an admin - this will be presented below the email |
avatarUrl |
string |
<optional> |
Optional url for an avatar photo |
id |
string |
<optional> |
Id of your admin user |
{...} |
any | Also you can put as many other fields to it as you like. |
# OverridableComponent
Name of the components which can be overridden by AdminBro.bundle. It currently following components can be override:
- LoggedIn
- NoRecords
- SidebarResourceSection
- SidebarFooter
- SidebarBranding
- New:
- in version 3.3
View Source admin-bro/src/frontend/utils/overridable-component.ts, line 2
# UploadedFile
File uploaded via FormData to the backend.
Properties:
Name | Type | Description |
---|---|---|
size |
number | The size of the uploaded file in bytes., this property says how many bytes of the file have been written to disk yet. |
path |
string | The path this file is being written to. |
type |
string | The mime type of this file, according to the uploading client. |
name |
string | null | The name this file had according to the uploading client. |