-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
docs: Revamp API Platform Admin docs #2141
base: 4.1
Are you sure you want to change the base?
Conversation
1fca087
to
9dbcf96
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work! Kudos for that.
The new chapters are 💯 . You helped improve the old ones, but some passages are still hard to follow.
``` | ||
|
||
**Tip:** if you don't want to hardcode the API URL, you can [use an environment variable](https://vite.dev/guide/env-and-mode). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This tip is only available if the user has used CRA, if the distribution is used it's Next.js instead (we should probably use Vite instead tough 😄).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I'll add a link for both.
admin/schema-org.md
Outdated
@@ -0,0 +1,147 @@ | |||
# Customizing the Schema |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the filename should just be schema.md
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. I renamed the file to workaround a bug causing the section to not be highlighted in the left menu, but we can go even further with the renaming. I'll push a new commit.
|
||
However the UX can often be improved by setting a default action when clicking on a row, and removing the `Show` and `Edit` buttons. | ||
|
||
To hide these buttons, we will need to replace the `<ListGuesser>` by a [`<List>`](https://marmelab.com/react-admin/List.html) component, provided by `react-admin`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's too bad, I think this example is not really suited: we should be able to change the <ListGuesser>
component to support removing its buttons.
It's the philosophy of API Platform Admin: making sure the user can customize simple things by keeping the guessers as most as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand your POV.
To me, both requirements can coexist. API Platform Admin can allow to customize simple things by tweaking the guessers.
But we should also let the users break free of the guessers when they need to, and guide them towards the use of native RA components.
In the end:
- I agree adding an option to
<ListGuesser>
to hide these buttons is a good idea (and likewise, I'll add it to our suggestions backlog) - But to me, it's also important to show them how they can use the native RA components instead, and what it will bring to them.
I agree this example will no longer be relevant when <ListGuesser>
offers an option to hide the buttons (and if you have a better example I'll be glad to read about it!), but for now it's relevant so I think we should keep it.
|
||
If the user clicks on the undo button, the record will be restored to its previous state. Otherwise, the change is persisted to the API. | ||
|
||
Let's, for instance, add the possibility to undo an update to a book. To do that, we will replace the generated `<EditGuesser>` by the [`<Edit>`](https://marmelab.com/react-admin/Edit.html) component, provided by `react-admin`. Undoable mutations are enabled by default for the `<Edit>` component. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as my previous comment, setting the mutationMode
prop of <EditGuesser>
is sufficient to do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same answer (encourage users to use RA components directly)
|
||
When the user tries to navigate away from a form with unsaved changes, a confirmation dialog will be displayed, asking the user if they want to leave the page. This prevents the risk of losing unsaved data. | ||
|
||
Reusing the `BookEdit` component from the previous example, all we need to do is to leverage the [`warnWhenUnsavedChanges`](https://marmelab.com/react-admin/SimpleForm.html#warnwhenunsavedchanges) prop of the `<SimpleForm>` component to enable this feature. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as my previous comments: this props is exposed by the <EditGuesser>
component.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same answer as for <EditGuesser>
(encourage users to use RA components directly).
This also highlights another advantage: helping users understand that the warnWhenUnsavedChanges
is carried by <SimpleForm>
will help them find other props they might need in the RA docs.
import { Rating } from '@mui/material'; | ||
|
||
const ReviewShow = () => ( | ||
<Show> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not using the <ShowGuesser>
component here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same answer as for <EditGuesser>
(encourage users to use RA components directly)
<Edit warnWhenUnsavedChanges> | ||
<SimpleForm sx={{ maxWidth: 500 }}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not using the <EditGuesser>
component here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, we could! But the goal of this whole section is to encourage users to break out of the guessers and start using React Admin components directly. Besides, it also helps understanding that <EditGuesser>
actually renders both an <Edit>
and a <SimpleForm>
. Lastly this makes it easier to move to a different Form component later on.
We can improve the UX further by rendering an [`<AutocompleteInput>`](https://marmelab.com/react-admin/AutocompleteInput.html) instead. | ||
|
||
`<AutocompleteInput>` allows to search for a related record by typing its name in an input field. This is much more convenient when there are many records to choose from. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a lot of tip for replacing the <InputGuesser>
by an <AutocompleteInput>
. I think API Platform Admin should provide a prop to do this instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree! I've added the idea to our backlog so we can open a PR implementing that in the future 🙂
Co-authored-by: Alan Poulain <contact@alanpoulain.eu>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the extensive review! 👍
We can improve the UX further by rendering an [`<AutocompleteInput>`](https://marmelab.com/react-admin/AutocompleteInput.html) instead. | ||
|
||
`<AutocompleteInput>` allows to search for a related record by typing its name in an input field. This is much more convenient when there are many records to choose from. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree! I've added the idea to our backlog so we can open a PR implementing that in the future 🙂
<Edit warnWhenUnsavedChanges> | ||
<SimpleForm sx={{ maxWidth: 500 }}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, we could! But the goal of this whole section is to encourage users to break out of the guessers and start using React Admin components directly. Besides, it also helps understanding that <EditGuesser>
actually renders both an <Edit>
and a <SimpleForm>
. Lastly this makes it easier to move to a different Form component later on.
import { Rating } from '@mui/material'; | ||
|
||
const ReviewShow = () => ( | ||
<Show> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same answer as for <EditGuesser>
(encourage users to use RA components directly)
|
||
When the user tries to navigate away from a form with unsaved changes, a confirmation dialog will be displayed, asking the user if they want to leave the page. This prevents the risk of losing unsaved data. | ||
|
||
Reusing the `BookEdit` component from the previous example, all we need to do is to leverage the [`warnWhenUnsavedChanges`](https://marmelab.com/react-admin/SimpleForm.html#warnwhenunsavedchanges) prop of the `<SimpleForm>` component to enable this feature. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same answer as for <EditGuesser>
(encourage users to use RA components directly).
This also highlights another advantage: helping users understand that the warnWhenUnsavedChanges
is carried by <SimpleForm>
will help them find other props they might need in the RA docs.
|
||
If the user clicks on the undo button, the record will be restored to its previous state. Otherwise, the change is persisted to the API. | ||
|
||
Let's, for instance, add the possibility to undo an update to a book. To do that, we will replace the generated `<EditGuesser>` by the [`<Edit>`](https://marmelab.com/react-admin/Edit.html) component, provided by `react-admin`. Undoable mutations are enabled by default for the `<Edit>` component. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same answer (encourage users to use RA components directly)
|
||
However the UX can often be improved by setting a default action when clicking on a row, and removing the `Show` and `Edit` buttons. | ||
|
||
To hide these buttons, we will need to replace the `<ListGuesser>` by a [`<List>`](https://marmelab.com/react-admin/List.html) component, provided by `react-admin`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand your POV.
To me, both requirements can coexist. API Platform Admin can allow to customize simple things by tweaking the guessers.
But we should also let the users break free of the guessers when they need to, and guide them towards the use of native RA components.
In the end:
- I agree adding an option to
<ListGuesser>
to hide these buttons is a good idea (and likewise, I'll add it to our suggestions backlog) - But to me, it's also important to show them how they can use the native RA components instead, and what it will bring to them.
I agree this example will no longer be relevant when <ListGuesser>
offers an option to hide the buttons (and if you have a better example I'll be glad to read about it!), but for now it's relevant so I think we should keep it.
admin/schema-org.md
Outdated
@@ -0,0 +1,147 @@ | |||
# Customizing the Schema |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. I renamed the file to workaround a bug causing the section to not be highlighted in the left menu, but we can go even further with the renaming. I'll push a new commit.
``` | ||
|
||
**Tip:** if you don't want to hardcode the API URL, you can [use an environment variable](https://vite.dev/guide/env-and-mode). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I'll add a link for both.
This PR aims at generally improving the API Platform Admin documentation, notably:
This PR relies on customization examples brought by api-platform/admin#600
Here is the new TOC I implemented:
i. General intro about what API Platform Admin is
ii. When can I use it
iii. Introduce React Admin
iv. Feature @fzaninotto 's presentation given at the API Platform Conference 2024
v. List features offered by the Admin
i. Introduce HydraAdmin
ii. Introduce OpenApiAdmin
i. Show how to customize the Admin with just PHP changes
ii. Includes the 'Using the Schema.org Vocabulary' content
i. Learn how to use FieldGuesser and InputGuesser
ii. Includes current section 'Customizing the Admin'
i. Provide examples of more advanced customization, leveraging React Admin components
TODO
How to test
docs-versions.txt
to add a version namedrevamp-admin-docs
(name of the branch of this PR)hugo.toml
to add a version namedrevamp-admin-docs
with pathvrevamp-admin-docs
hugo
on your machine (sudo apt install hugo
)README.md
of thedocs-website
repohugo serve