React Admin

A frontend Framework for building B2B applications running in the browser o...

README

react-admin Build status FOSSA Status StandWithUkraine


A frontend Framework for building data-driven applications running in the browser on top of REST/GraphQL APIs, using ES6, React and Material Design. Open sourced and maintained by marmelab.

react-admin-demo

Features


🔌 Backend Agnostic: Connects to any API (REST or GraphQL, see the list of more than 45 adapters)

🧩 All The Building Blocks You Need: Provides hooks and components for authentication, routing, forms & validation, datagrid, search & filter, relationships, validation, roles & permissions, rich text editor, i18n, notifications, menus, theming, caching, etc.

🪡 High Quality: Accessibility, responsive, secure, fast, testable

💻 Great Developer Experience: Complete documentation, IDE autocompletion, type safety, storybook, demo apps with source code, modular architecture, declarative API

👑 Great User Experience: Optimistic rendering, filter-as-you-type, undo, preferences, saved queries

🛠 Complete Customization: Replace any component with your own

☂️ Opt-In Types: Develop either in TypeScript or JavaScript

👨‍👩‍👧‍👦 Powered by MUI, react-hook-form, react-router, react-query, TypeScript and a few more

Installation


React-admin is available from npm. You can install it (and its required dependencies)
using:

  1. ```sh
  2. npm install react-admin
  3. #or
  4. yarn add react-admin
  5. ```

Documentation


Read the Tutorial for a 30 minutes introduction. After that, head to the Documentation, or checkout the source code of the demo for an example usage.

At a Glance


  1. ``` js
  2. // in app.js
  3. import * as React from "react";
  4. import { render } from 'react-dom';
  5. import { Admin, Resource } from 'react-admin';
  6. import restProvider from 'ra-data-simple-rest';

  7. import { PostList, PostEdit, PostCreate, PostIcon } from './posts';

  8. render(
  9.     <Admin dataProvider={restProvider('http://localhost:3000')}>
  10.         <Resource name="posts" list={PostList} edit={PostEdit} create={PostCreate} icon={PostIcon} />
  11.     </Admin>,
  12.     document.getElementById('root')
  13. );
  14. ```

The `` component is a configuration component that allows to define sub components for each of the admin view: `list`, `edit`, and `create`. These components use MUI and custom components from react-admin:

  1. ``` js
  2. // in posts.js
  3. import * as React from "react";
  4. import { List, Datagrid, Edit, Create, SimpleForm, DateField, TextField, EditButton, TextInput, DateInput, useRecordContext } from 'react-admin';
  5. import BookIcon from '@mui/icons-material/Book';
  6. export const PostIcon = BookIcon;

  7. export const PostList = () => (
  8.     <List>
  9.         <Datagrid>
  10.             <TextField source="id" />
  11.             <TextField source="title" />
  12.             <DateField source="published_at" />
  13.             <TextField source="average_note" />
  14.             <TextField source="views" />
  15.             <EditButton />
  16.         </Datagrid>
  17.     </List>
  18. );

  19. const PostTitle = () => {
  20.     const record = useRecordContext();
  21.     return <span>Post {record ? `"${record.title}"` : ''}</span>;
  22. };

  23. export const PostEdit = () => (
  24.     <Edit title={<PostTitle />}>
  25.         <SimpleForm>
  26.             <TextInput disabled source="id" />
  27.             <TextInput source="title" />
  28.             <TextInput source="teaser" options={{ multiline: true }} />
  29.             <TextInput multiline source="body" />
  30.             <DateInput label="Publication date" source="published_at" />
  31.             <TextInput source="average_note" />
  32.             <TextInput disabled label="Nb views" source="views" />
  33.         </SimpleForm>
  34.     </Edit>
  35. );

  36. export const PostCreate = () => (
  37.     <Create title="Create a Post">
  38.         <SimpleForm>
  39.             <TextInput source="title" />
  40.             <TextInput source="teaser" options={{ multiline: true }} />
  41.             <TextInput multiline source="body" />
  42.             <TextInput label="Publication date" source="published_at" />
  43.             <TextInput source="average_note" />
  44.         </SimpleForm>
  45.     </Create>
  46. );
  47. ```

Does It Work With My API?


Yes.

React-admin uses an adapter approach, with a concept called Data Providers. Existing providers can be used as a blueprint to design your API, or you can write your own Data Provider to query an existing API. Writing a custom Data Provider is a matter of hours.

Data Provider architecture

See the Data Providers documentation for details.

Batteries Included But Removable


React-admin is designed as a library of loosely coupled React components and hooks exposing reusable controller logic. It is very easy to replace any part of react-admin with your own, e.g. to use a custom datagrid, GraphQL instead of REST, or Bootstrap instead of Material Design.

Examples


There are several examples inside the examples folder:

simple (CodeSandbox, StackBlitz): a simple blog with posts, comments and users that we use for our e2e tests.
e-commerce: (demo, source) A fictional poster shop admin, serving as the official react-admin demo.
CRM: (demo, source) A customer relationship management application
tutorial (CodeSandbox): the application built while following the tutorial.

You can run those example applications by calling:

  1. ```sh
  2. # At the react-admin project root
  3. make install
  4. # or
  5. yarn install

  6. # Run the simple application
  7. make run-simple

  8. # Run the tutorial application
  9. make build
  10. make run-tutorial

  11. # Run the demo application
  12. make build
  13. make run-demo
  14. ```

And then browse to the URL displayed in your console.

Support


You can get professional support from Marmelab via React-Admin Enterprise Edition, or community support via StackOverflow.

Versions In This Repository


master - commits that will be included in the next _patch_ release

next - commits that will be included in the next _major_ or _minor_ release

Bugfix PRs that don't break BC should be made against master. All other PRs (new features, bugfix with BC break) should be made against next.

Contributing


If you want to give a hand: Thank you! There are many things you can do to help making react-admin better.

The easiest task is bug triaging. Check that new issues on GitHub follow the issue template and give a way to reproduce the issue. If not, comment on the issue to ask precisions. Then, try and reproduce the issue following the description. If you managed to reproduce the issue, add a comment to say it. Otherwise, add a comment to say that something is missing.

The second way to contribute is to answer support questions on StackOverflow. There are many beginner questions there, so even if you're not super experienced with react-admin, there is someone you can help there.

Pull requests for bug fixes are welcome on the GitHub repository. There is always a bunch of issues labeled "Good First Issue" in the bug tracker - start with these.

If you want to add a feature, you can open a Pull request on the next branch. We don't accept all features - we try to keep the react-admin code small and manageable. Try and see if your feature can't be built as an additional npm package. If you're in doubt, open a "Feature Request" issue to see if the core team would accept your feature before developing it.

For all Pull requests, you must follow the coding style of the existing files (based on prettier), and include unit tests and documentation. Be prepared for a thorough code review, and be patient for the merge - this is an open-source initiative.

Tip: Most of the commands used by the react-admin developers are automated in the makefile. Feel free to type make without argument to see a list of the available commands.

Setup


Clone this repository and run make install to grab the dependencies, then make build to compile the sources from TypeScript to JS.

Online one-click Setup


You can use Gitpod(An Online Open Source VS Code like IDE which is free for Open Source) for working on issues and making PRs. With a single click it will launch a workspace and automatically clone the repo, run make install and make start so that you can start straight away.
Open in Gitpod

Testing Your Changes In The Example Apps


When developing, most of the time we use the simple example to do visual check. It's the same application that we use in CodeSandbox to reproduce errors (see https://codesandbox.io/s/github/marmelab/react-admin/tree/master/examples/simple). The source is located under examples/simple/. Call make run to launch that example on port 8080 (http://localhost:8080). This command includes a watch on the react-admin source, so any of the changes you make to the react-admin packages triggers a live update of the simple example in your browser.

However, the simple example is sometimes too limited. You can use the demo example (the source for https://marmelab.com/react-admin-demo/), which is more complete. The source is located under examples/demo/. Call make run-demo to launch the demo example with a REST dataProvider, or make run-graphql-demo to run it with a GraphQL dataProvider. Unfortunately, due to the fact that we use Create React App for this demo, these commands don't watch the changes made in the packages. You'll have to rebuild the react-admin packages after a change (using make build, or the more targeted make build-ra-core, make build-ra-ui-materialui, etc.) to see the effect in the demo app.

Both of these examples work without server - the API is simulated on the client-side.

Testing Your Changes In Your App


Using yarn link, you can have your project use a local checkout of the react-admin package instead of npm. This allows you to test react-admin changes in your app:

  1. ```sh
  2. # Register your local react-admin as a linkable package
  3. $ cd /code/path/to/react-admin/packages/react-admin && yarn link

  4. # Replace the npm-installed version with a symlink to your local version
  5. $ cd /code/path/to/myapp/ && yarn link react-admin

  6. # If you run into issues with React red-screen, then you need to register your app's version of React as a linkable package 

  7. $ cd /code/path/to/myapp/node_modules/react && yarn link
  8. # And then replace the npm-installed version of React with a symlink to your app's node_modules version
  9. $ cd /code/path/to/react-admin/ && yarn link react

  10. # Rebuild the packages with the same version of React
  11. $ cd /code/path/to/react-admin/ && make build

  12. # Return to your app and ensure all dependencies have resolved
  13. $ cd /code/path/to/myapp/ && yarn install

  14. # Start your app
  15. $ yarn start
  16. ```

Automated Tests


Automated tests are also crucial in our development process. You can run all the tests (linting, unit and functional tests) by calling:

  1. ```sh
  2. make test
  3. ```

Unit tests use jest, so you should be able to run a subset of tests, or run tests continuously on change, by passing options to

  1. ```sh
  2. yarn jest
  3. ```

Besides, tests related to the modified files are run automatically at commit using a git pre-commit hook. This means you won't be able to commit your changes if they break the tests.

When working on the end-to-end tests, you can leverage cypress runner by starting the simple example yourself (make run-simple or yarn run-simple) and starting cypress in another terminal (make test-e2e-local or yarn test-e2e-local).

Coding Standards


If you have coding standards problems, you can fix them automatically using prettier by calling

  1. ```sh
  2. make prettier
  3. ```

However, these commands are run automatically at each commit so you shouldn't have to worry about them.

Documentation


If you want to contribute to the documentation, install jekyll, then call

  1. ```sh
  2. make doc
  3. ```

And then browse to http://localhost:4000/

License


React-admin is licensed under the MIT License, sponsored and supported by marmelab.
FOSSA Status

Donate


This library is free to use, even for commercial purpose. If you want to give back, please talk about it, help newcomers, or contribute code. But the best way to give back is todonate to a charity. We recommend Doctors Without Borders.