Skip to content

Commit af4fb9c

Browse files
Riley Bąkowskagitbook-bot
Riley Bąkowska
authored andcommitted
GitBook: [#65] ComponentLoader
1 parent 8dca374 commit af4fb9c

9 files changed

+275
-233
lines changed

SUMMARY.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,13 @@
3232
* [Password](basics/features/password.md)
3333
* [Writing your own features](basics/features/writing-your-own-features.md)
3434

35-
## UI Customizations
35+
## UI Customization
3636

37-
* [Overwriting CSS styles](ui-customizations/overwriting-css-styles.md)
38-
* [Customizing dashboard](ui-customizations/customize-dashboard.md)
37+
* [Writing your own Components](ui-customization/writing-your-own-components.md)
38+
* [Overwriting CSS styles](ui-customization/overwriting-css-styles.md)
3939

4040
## Tutorials
4141

42-
* [Writing your own Components](tutorials/writing-your-own-components.md)
4342
* [Using AdminJS features](tutorials/using-adminjs-features.md)
4443
* [Adding Role-Based Access Control](tutorials/adding-role-based-access-control.md)
4544
* [Internationalization (i18n)](tutorials/internationalization-i18n.md)

basics/action.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ The `handler` must return `records` in case of `bulk` or `resource` actions or `
8181

8282
The last important option is `component`. This can either be `false` which means that the backend `handler` will be triggered once you press the button or you can provide your custom component that will be rendered.
8383

84-
An example with `component` usage:
84+
#### Action with custom component
8585

8686
{% code title="my-custom-action.tsx" %}
8787
```jsx
@@ -123,7 +123,7 @@ const UserResource = {
123123
actions: {
124124
myCustomAction: {
125125
actionType: 'record',
126-
component: AdminJS.bundle('./my-custom-action'),
126+
component: Components.MyCustomAction, // see "Writing your own Components"
127127
handler: (request, response, context) => {
128128
const { record, currentAdmin } = context
129129
return {
@@ -333,7 +333,7 @@ const UserResource = {
333333
actions: {
334334
myCustomAction: {
335335
actionType: 'record',
336-
component: AdminJS.bundle('./my-custom-action'),
336+
component: Components.MyCustomAction, // see "Writing your own Components"
337337
handler: (request, response, context) => {
338338
const { record, currentAdmin } = context
339339
return {

basics/property.md

+5-12
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,20 @@ const RandomPicture: React.FC<ShowPropertyProps> = (props) => {
3333
export default RandomPicture
3434
```
3535

36-
```typescript
37-
import AdminJS from 'adminjs'
38-
// other imports
39-
40-
const RANDOM_PICTURE = AdminJS.bundle('./random-picture')
41-
42-
const UserResource = {
43-
resource: User,
36+
<pre class="language-typescript"><code class="lang-typescript"><strong>const UserResource = {
37+
</strong> resource: User,
4438
options: {
4539
properties: {
4640
randomPicture: {
4741
type: 'string',
4842
components: {
49-
list: RANDOM_PICTURE,
50-
show: RANDOM_PICTURE,
43+
list: Components.MyCustomAction, // see "Writing your own Components"
44+
show: Components.MyCustomAction,
5145
},
5246
},
5347
},
5448
},
55-
}
56-
```
49+
}</code></pre>
5750

5851
Every property can be further customized. That will be covered in the later parts of this section.
5952

installation/getting-started.md

+18
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,21 @@ After you have installed AdminJS dependencies, proceed to:
4545

4646
* [Plugins](plugins/) section for instructions on how to setup AdminJS with your framework.
4747
* [Adapters](adapters/) section for instructions on how to connect your AdminJS instance to your database.
48+
49+
### Frontend bundling
50+
51+
AdminJS needs to generate its own frontend. In the production environment, you would bundle all frontend files during build step of your deployment process, but that would be quite annoying to do in development.
52+
53+
For this reason you should add `adminJS.watch()` function call after setting up all plugins and adapters. This only affects development environment (`process.env.NODE_ENV === 'development'`) and launches a separate bundling process in the background.
54+
55+
```typescript
56+
import AdminJS from 'adminjs'
57+
58+
const adminJS = new AdminJS({
59+
// ...
60+
})
61+
62+
adminJS.watch()
63+
```
64+
65+
Without this step in development, AdminJS will start but won't display anything useful in the browser (except for some parsing errors in the console).

tutorials/using-adminjs-features.md

+14
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,20 @@ const feature = buildFeature({
9696
})
9797
```
9898

99+
If you need to access AdminJS instance (for example to add or override components, see [writing-your-own-components.md](../ui-customization/writing-your-own-components.md "mention")), you can do so like this:
100+
101+
```typescript
102+
const { buildFeature } = require('adminjs')
103+
104+
const feature = buildFeature(admin => {
105+
const MyComponent = admin.loader.add('MyComponent', './my-component')
106+
107+
return {
108+
// you can now use `MyComponent` here
109+
}
110+
})
111+
```
112+
99113
### Available features
100114

101115
#### Supported by AdminJS team

tutorials/writing-your-own-components.md

-185
This file was deleted.

0 commit comments

Comments
 (0)