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 32 commits into
base: 4.1
Choose a base branch
from
Open

docs: Revamp API Platform Admin docs #2141

wants to merge 32 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.

@@ -1,19 +1,23 @@
# Components
# Components Reference

Choose a reason for hiding this comment

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

I don't understand the "Resource Components" title below. Also, I'm not sure we need this title level. Can't we directly list the components as h2? After all, we're in a components documentation...

(for Hydra documented APIs, use the [HydraAdmin component](components.md#hydraadmin) instead,
for OpenAPI documented APIs, use the [OpenApiAdmin component](components.md#openapiadmin) instead).
It also creates a [schema analyzer](components.md#schema-analyzer) context, where the `schemaAnalyzer` service (for getting information about the provided API documentation) is stored.
`<AdminGuesser>` renders automatically an [`<Admin>` component](https://marmelab.com/react-admin/Admin.html) for resources exposed by a web API documented with any format supported by `@api-platform/api-doc-parser`.

Choose a reason for hiding this comment

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

Suggested change
`<AdminGuesser>` renders automatically an [`<Admin>` component](https://marmelab.com/react-admin/Admin.html) for resources exposed by a web API documented with any format supported by `@api-platform/api-doc-parser`.
`<AdminGuesser>` automatically renders an [`<Admin>` component](https://marmelab.com/react-admin/Admin.html) for resources exposed by a web API documented with any format supported by `@api-platform/api-doc-parser`.


`<AdminGuesser>` renders all exposed resources by default, but you can choose what resource you want to render by passing [ResourceGuesser components](components.md#resourceguesser) as children.
Deprecated resources are hidden by default, but you can add them back using an explicit `<ResourceGuesser>` component.
**Tip:** For Hydra documented APIs, use the [`<HydraAdmin>` component](#hydraadmin) instead.

Choose a reason for hiding this comment

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

This I don't understand. Should I use AdminGuesser or HydraAdmin?


**Tip:** Deprecated resources are hidden by default, but you can add them back using an explicit `<ResourceGuesser>` component.

```tsx

Choose a reason for hiding this comment

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

I'd move this piece of code earlier, just after the first sentence of the section.

// App.js
**Tip:** For OpenAPI documented APIs, use the [`<OpenApiAdmin>` component](#openapiadmin) instead.

It also creates a [schema analyzer](#hydra-schema-analyzer) context, where the `schemaAnalyzer` service (for getting information about the provided API documentation) is stored.

Choose a reason for hiding this comment

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

This is confusing: AdminGuesser creates a schema analyzer, but it also accepts a schemaAnalyzer prop?

Copy link
Author

Choose a reason for hiding this comment

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

I kept that part from the previous version of the doc. But now that I think about it, it doesn't bring much, and the schema analyzer context is never mentioned again in the docs, so unless we decide to properly document it at some point, it's best to remove this sentence altogether IMHO.

@@ -11,12 +11,10 @@ If a relation is an array of [embeddeds or an embedded](../core/serialization.md
The embedded data will be displayed as text field and editable as text input: the admin cannot determine the fields present in it.
To display the fields you want, see [this section](handling-relations.md#display-a-field-of-an-embedded-relation).

Choose a reason for hiding this comment

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

use the section name in the link instead of "this section"

You can also ask the admin to automatically replace the embedded resources' data by their IRI,
by setting the `useEmbedded` parameter of the Hydra data provider to `false`.
Embedded data is inserted to a local cache: it will not be necessary to make more requests if you reference some fields of the embedded resource later on.
You can also ask the admin to return the embedded resources' IRI instead of the full record, by setting the `useEmbedded` parameter of the Hydra data provider to `false`.

Choose a reason for hiding this comment

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

Not sure I understand what this means. Could you maybe give an example response?

Copy link
Author

Choose a reason for hiding this comment

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

For the same reason, no, unfortunately :(

@@ -20,7 +27,7 @@ const getHeaders = () =>
: {};
```

Extend the Hydra fetch function with custom headers for authentication.
Then, extend the Hydra `fetch` function to use the `getHeaders` function to add the `Authorization` header to the requests.

```typescript
const fetchHydra = (url, options = {}) =>

Choose a reason for hiding this comment

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

missing import statement for the baseFetchHydra


Redirect users to a `/login` path, if no token is available in the `localStorage`.
Then, we'll create a `<RedirectToLogin>` component, that will redirect users to the `/login` route if no token is available in the `localStorage`, and perform the introspection otherwise.

Choose a reason for hiding this comment

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

perform the introspection

Not sure what this means. And how does this concern authentication?

Copy link
Author

Choose a reason for hiding this comment

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

I basically calls the dataProvider's introspect function. To be fair I'm not 100% sure this is necessary, at least with modern React Admin which should already redirect to the login page if no token is available, but I'm not tooled enough to neither confirm nor infirm this.

Extend the `parseHydraDocumentaion` function from the [API Doc Parser library](https://github.com/api-platform/api-doc-parser)
to handle the documentation parsing. Customize it to clear
expired tokens when encountering unauthorized `401` response.
We will customize it to clear expired tokens when encountering unauthorized `401` response.

```typescript
const apiDocumentationParser = (setRedirectToLogin) => async () => {

Choose a reason for hiding this comment

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

missing import for the function to extend

@slax57 slax57 marked this pull request as ready for review March 14, 2025 18:20
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.

3 participants