Skip to content
New issue

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

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

Already on GitHub? # to your account

Document dynamic resources #5004

Merged
merged 6 commits into from
Jul 6, 2020
Merged

Document dynamic resources #5004

merged 6 commits into from
Jul 6, 2020

Conversation

Luwangel
Copy link
Contributor

@Luwangel Luwangel commented Jul 3, 2020

Fixes #4629
Follows #3907

Todo

  • Write a section in the documentation about the and the components

@Luwangel Luwangel added documentation RFR Ready For Review labels Jul 3, 2020
@Luwangel Luwangel force-pushed the document-dynamic-resources branch from ebd2388 to d8eb7fe Compare July 3, 2020 10:57
docs/Admin.md Outdated
- [`loginPage`](#loginpage)
- [`logoutButton`](#logoutbutton)
- [`initialState`](#initialstate)
- [`history`](#history)
- [Internationalization](#internationalization)
- [Declaring resources at runtime](#declaring-resources-at-runtime)
- [Use a Function As its Child](#use-a-function-as-its-child)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should link to level 3 headers in this list

docs/Admin.md Outdated
You might want to dynamically define the resources when the app starts. The `<Admin>` component accepts a function as its child and this function can return a Promise. If you also defined an `authProvider`, the child function will receive the result of a call to `authProvider.getPermissions()` (you can read more about this in the [Authorization](./Authorization.md) chapter).
You might want to dynamically define the resources when the app starts.

### Use a Function As its Child
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### Use a Function As its Child
### Using a Function As `<Admin>` Child

docs/Admin.md Outdated
@@ -559,13 +559,16 @@ The `i18nProvider` props let you translate the GUI. The [Translation Documentati

## Declaring resources at runtime

You might want to dynamically define the resources when the app starts. The `<Admin>` component accepts a function as its child and this function can return a Promise. If you also defined an `authProvider`, the child function will receive the result of a call to `authProvider.getPermissions()` (you can read more about this in the [Authorization](./Authorization.md) chapter).
You might want to dynamically define the resources when the app starts.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence alone with the section title afterwards feels odd.

docs/Admin.md Outdated
@@ -595,6 +598,44 @@ const App = () => (
);
```

### Unplug the <Admin> using the `<AdminContext>` and the `<AdminUI>`

Setting Resources dynamically is still very cumbersome: even if `<Admin>` accepts [a function as child](#declaring-resources-at-runtime), this function can't execute hooks.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Setting Resources dynamically is still very cumbersome: even if `<Admin>` accepts [a function as child](#declaring-resources-at-runtime), this function can't execute hooks.
Setting Resources dynamically using the children-as-function syntax may not be enough in all cases, because this function can't execute hooks.

docs/Admin.md Outdated

Setting Resources dynamically is still very cumbersome: even if `<Admin>` accepts [a function as child](#declaring-resources-at-runtime), this function can't execute hooks.

So it's impossible, for instance, to have a dynamic list of resources based on a call to the dataProvider (since the dataProvider is only defined after the Admin component renders).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
So it's impossible, for instance, to have a dynamic list of resources based on a call to the dataProvider (since the dataProvider is only defined after the Admin component renders).
So it's impossible, for instance, to have a dynamic list of resources based on a call to the `dataProvider` (since the `dataProvider` is only defined after the `<Admin>` component renders).

docs/Admin.md Outdated

So it's impossible, for instance, to have a dynamic list of resources based on a call to the dataProvider (since the dataProvider is only defined after the Admin component renders).

To do so, you have to build your own <Admin> component using both the <AdminContext> and the <AdminUI> (as we do internally). It's straightforward.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add backticks around components

docs/Admin.md Outdated

So it's impossible, for instance, to have a dynamic list of resources based on a call to the dataProvider (since the dataProvider is only defined after the Admin component renders).

To do so, you have to build your own <Admin> component using both the <AdminContext> and the <AdminUI> (as we do internally). It's straightforward.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
To do so, you have to build your own <Admin> component using both the <AdminContext> and the <AdminUI> (as we do internally). It's straightforward.
To overcome this limitation, you can build your own `<Admin>` component using two lower-level components: `<AdminContext>` (responsible for putting the providers in contexts) and `<AdminUI>` (responsible for displaying the UI). Here is an example:

docs/Admin.md Outdated
const dataProvider = useDataProvider();

useEffect(() => {
dataProvider.introspect().then(r => setResources(r));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

introspect isn't a legal dataProvider verb, so you'll have to be more explicit here

@fzaninotto fzaninotto merged commit 8e83fec into master Jul 6, 2020
@fzaninotto fzaninotto deleted the document-dynamic-resources branch July 6, 2020 10:17
@fzaninotto fzaninotto added this to the 3.6.3 milestone Jul 6, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
documentation RFR Ready For Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Documentation about setting resources dynamically is outdated
2 participants