Skip to content
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

Open
wants to merge 36 commits into
base: 4.1
Choose a base branch
from
Open

docs: Revamp API Platform Admin docs #2141

wants to merge 36 commits into from

Conversation

slax57
Copy link

@slax57 slax57 commented Mar 7, 2025

This PR aims at generally improving the API Platform Admin documentation, notably:

  • Updating the code, links, and screenshots
  • Reorganizing the pages to provide a linear, guided read-through for newcomers (see below)
  • Improve documentation regarding the ways to customize the generated Admin, most notably showcasing advanced customization using React Admin components
  • Fix minor issues found while proof-reading

This PR relies on customization examples brought by api-platform/admin#600

Here is the new TOC I implemented:

  1. The API Platform Admin
    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
  2. Getting Started
    i. Introduce HydraAdmin
    ii. Introduce OpenApiAdmin
  3. Customizing the Schema
    i. Show how to customize the Admin with just PHP changes
    ii. Includes the 'Using the Schema.org Vocabulary' content
  4. Customizing Guessers
    i. Learn how to use FieldGuesser and InputGuesser
    ii. Includes current section 'Customizing the Admin'
  5. Customizing the Admin
    i. Provide examples of more advanced customization, leveraging React Admin components
  6. Handling Relations
  7. Validating Forms
  8. Realtime Updates
  9. Authentication
  10. Handling File Upload
  11. Performance -> renamed to Performance Tips
  12. Components -> renamed to Components Reference

TODO

  • Finish the rewrite
  • update the menu
  • Much proof-reading

How to test

  1. Clone https://github.com/api-platform/docs-website
  2. Edit docs-versions.txt to add a version named revamp-admin-docs (name of the branch of this PR)
  3. Edit hugo.toml to add a version named revamp-admin-docs with path vrevamp-admin-docs
  4. Install hugo on your machine (sudo apt install hugo)
  5. Follow the instructions from the README.md of the docs-website repo
  6. Run hugo serve
  7. Browse http://localhost:1313/docs/vrevamp-admin-docs/admin/

@slax57 slax57 force-pushed the revamp-admin-docs branch from 1fca087 to 9dbcf96 Compare March 10, 2025 17:34
@slax57 slax57 changed the title [Doc] Revamp API Platform Admin docs docs: Revamp API Platform Admin docs Mar 12, 2025
Copy link

@fzaninotto fzaninotto left a 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).
Copy link
Member

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 😄).

Copy link
Author

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.

@@ -0,0 +1,147 @@
# Customizing the Schema
Copy link
Member

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.

Copy link
Author

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`.
Copy link
Member

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.

Copy link
Author

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.
Copy link
Member

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.

Copy link
Author

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.
Copy link
Member

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.

Copy link
Author

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>
Copy link
Member

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?

Copy link
Author

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)

Comment on lines +418 to +419
<Edit warnWhenUnsavedChanges>
<SimpleForm sx={{ maxWidth: 500 }}>
Copy link
Member

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?

Copy link
Author

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.

Comment on lines +255 to +257
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.
Copy link
Member

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.

Copy link
Author

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>
Copy link
Author

@slax57 slax57 left a 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! 👍

Comment on lines +255 to +257
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.
Copy link
Author

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 🙂

Comment on lines +418 to +419
<Edit warnWhenUnsavedChanges>
<SimpleForm sx={{ maxWidth: 500 }}>
Copy link
Author

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>
Copy link
Author

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.
Copy link
Author

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.
Copy link
Author

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`.
Copy link
Author

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.

@@ -0,0 +1,147 @@
# Customizing the Schema
Copy link
Author

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).
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants