# Customizing the Guessers Using `` or `` directly is a great way to quickly get started with API Platform Admin. They will introspect your API schema (using `@api-platform/api-doc-parser`) and automatically generate CRUD pages for all the resources it exposes. They will even [configure filtering, sorting, and real-time updates with Mercure](./schema.md) if your API supports it. For some this may be enough, but you will often find yourself wanting to customize the generated pages further. For instance, you may want to: - Hide or reorder resources in the menu - Hide or reorder columns in the list view - Hide or reorder fields in the show, create and edit views - Customize the generated list, e.g. add a default sort order - Customize the generated create and edit views, e.g. to add a warning when there are unsaved changes - Customize the generated inputs, e.g. set a custom label or make a text input multiline Such changes can't be achieved by modifying the Schema, they require customizing the React components generated by API Platform Admin. Fortunately, API Platform Admin has you covered! ## From `` To `` If you are using `` or `` directly, there is a simple way to start customizing the generated pages. Simply open your browser's developer tools and look at the console. You will see messages like this: ```txt If you want to override at least one resource, paste this content in the component of your app: ``` This message tells you which resources are exposed by your API and how to customize the generated pages for each of them. Let's say we'd like to hide the `greetings` resource from the menu. We can do this by replacing the `` component (`` in our case) children with a list of ``: ```diff -import { HydraAdmin } from "@api-platform/admin"; +import { HydraAdmin, ResourceGuesser } from "@api-platform/admin"; const App = () => ( - + + + + ); ``` Now the `greetings` resource will no longer be displayed in the menu. ![Customized Admin menu](./images/admin-menu.png) `` also accepts all props react-admin's [``](https://marmelab.com/react-admin/Resource.html) component accepts. This means that, for instance, you can use the `list` prop to use your own list component, but keep using the create, edit and show components introspected by ``: ```diff import { HydraAdmin, ResourceGuesser } from "@api-platform/admin"; +import { BookList } from "./BookList"; const App = () => ( - + ); ``` Likewise, you can use the `icon` prop to customize the icon displayed in the menu: ```diff +import AutoStoriesIcon from '@mui/icons-material/AutoStories'; +import ReviewsIcon from '@mui/icons-material/Reviews'; import { HydraAdmin, ResourceGuesser } from "@api-platform/admin"; const App = () => ( - + - + ); ``` Here is the result: ![Admin menu with custom icons](./images/admin-menu-icons.png) ## Customizing the `` By default, `` will render a `` component as the list view for a resource. This component will automatically introspect the API schema and generate a list view with all the fields of the resource. ![Admin default generated list view](./images/admin-default-list.png) This is already usable, but may not provide the best user experience yet. To start customizing the list view, you can look at the DevTools console. You will see messages like this: ```txt If you want to override at least one field, create a BookList component with this content: import { ListGuesser, FieldGuesser } from "@api-platform/admin"; export const BookList = () => ( ); Then, update your main admin component: import { HydraAdmin, ResourceGuesser } from "@api-platform/admin"; import { BookList } from './BookList'; const App = () => ( {/* ... */} ); ``` If you follow these instructions, you will end up with the same view as before, but now you can start customizing it. For instance, we'll hide the 'Description' column as it takes too much space (we'll reserve that to the show view). And we will also add a default sort order to show the most recent books first. Here's how to achieve this: ```diff export const BookList = () => ( - + - ); ``` And here is the result: ![Admin with customized list guesser](./images/admin-custom-list-guesser.png) That's already better isn't it? 🙂 ## Customizing the `` Removing or reordering `` components is not the only thing we can do. We can also customize them. Indeed, `` will forward additional props to the underlying React Admin [Field component](https://marmelab.com/react-admin/Fields.html). This means we can use any [common field prop](https://marmelab.com/react-admin/Fields.html#common-field-props) on them. For instance, let's add a `label` prop to customize the label of the ISBN column to be all uppercase: ```diff export const BookList = () => ( - + ); ``` And here is the result: ![Admin with customized list guesser and field guesser](./images/admin-custom-list-field-guesser.png) ## Customizing the `` Following the same principles as the `` (including looking at the DevTools console) we can customize the show view. In the following example, the show view for the `books` resource was customized to make the label of the `isbn` field uppercase: ```tsx import { HydraAdmin, ResourceGuesser, ShowGuesser, FieldGuesser, } from '@api-platform/admin'; const BookShow = () => ( ); export default () => ( ); ``` Here is the result: ![Admin with customized show guesser](./images/admin-custom-show-guesser.png) ## From `` To React Admin Fields As mentioned in the [Customizing the ``](./customizing.md#customizing-the-fieldguesser) section, we can use any [common field prop](https://marmelab.com/react-admin/Fields.html#common-field-props) from React Admin to customize the `` elements. However in some cases you may want to go further and use a React Admin [field components](https://marmelab.com/react-admin/Fields.html), such as [``](https://marmelab.com/react-admin/TextField.html), [``](https://marmelab.com/react-admin/DateField.html) or [``](https://marmelab.com/react-admin/ReferenceField.html) directly, to access more advanced features. For instance, you can replace a `` with a [``](https://marmelab.com/react-admin/DateField.html) to control more precisely how the publication date is displayed, leveraging the [`showTime`](https://marmelab.com/react-admin/DateField.html#showtime) prop: ```diff import { ShowGuesser, FieldGuesser } from '@api-platform/admin'; +import { DateField } from 'react-admin'; const ReviewShow = () => ( - + ); ``` ## Customizing the `` and `` Customizing the `` and `` is very similar to customizing the ``. We can start by looking at the DevTools console to get the initial code of the components. ```txt If you want to override at least one input, create a ReviewEdit component with this content: import { EditGuesser, InputGuesser } from "@api-platform/admin"; export const ReviewEdit = () => ( ); Then, update your main admin component: import { HydraAdmin, ResourceGuesser } from "@api-platform/admin"; import { ReviewEdit } from './ReviewEdit'; const App = () => ( {/* ... */} ); ``` Let's customize this `ReviewEdit` component to: - reorder the inputs - make the `body` input multiline - mark the `publicationDate` input as read-only ```diff export const ReviewEdit = () => ( - - - - - + + + + + ); ``` Here is the result: ![Admin with customized edit guesser](./images/admin-custom-edit-guesser.png) **Tip:** Here, we leveraged the `multiline` and `readOnly` props of the `` component. But you can use any [common input prop](https://marmelab.com/react-admin/Inputs.html#common-input-props) supported by React Admin [Inputs](https://marmelab.com/react-admin/Inputs.html) on them. ## From `` To React Admin Inputs As mentioned in the previous section, we can use any [common input prop](https://marmelab.com/react-admin/Inputs.html#common-input-props) from React Admin to customize the `` elements. However in some cases you may want to go further and use a React Admin [input components](https://marmelab.com/react-admin/Inputs.html), such as [``](https://marmelab.com/react-admin/TextInput.html), [``](https://marmelab.com/react-admin/DateInput.html) or [``](https://marmelab.com/react-admin/ReferenceInput.html) directly, to access more advanced features. A good example is to use an [Autocomplete Input to edit a relation](./handling-relations.md#using-an-autocomplete-input-for-relations). This leverages both [``](https://marmelab.com/react-admin/ReferenceInput.html) and [``](https://marmelab.com/react-admin/AutocompleteInput.html) to offer a better user experience when editing the relation: ```diff import { EditGuesser, InputGuesser } from '@api-platform/admin'; +import { ReferenceInput, AutocompleteInput } from 'react-admin'; const ReviewsEdit = () => ( - + + ({ title: searchText })} + optionText="title" + /> + ); ``` ![Admin With AutocompleteInput](./images/AutocompleteInput.png) > [!WARNING] > When replacing `` with a React Admin input component, the validation rules are not automatically applied. You will need to manually add them back. Fortunately, this is very easy to do. Read the [Validation With React Admin Inputs](./validation.md#validation-with-react-admin-inputs) section to learn more. ## Next Step The above examples are limited to customizing the various API Platform Admin Guessers, but this is just the tip of the iceberg. By leveraging React Admin components and props, you can go much further in customizing the generated pages. Head to the next section, [Customizing the Admin](./advanced-customization.md), for step-by-step examples.