import * as React from 'react'; import { Routes, Route, Link } from 'react-router-dom'; import { Resource, testDataProvider, TestMemoryRouter } from 'ra-core'; import type { AuthProvider } from 'ra-core'; import { Layout, ListGuesser, EditGuesser, ShowGuesser, } from 'ra-ui-materialui'; import { Box, Typography, Button } from '@mui/material'; import fakeRestDataProvider from 'ra-data-fakerest'; import { useQueryClient, QueryClient } from '@tanstack/react-query'; import { Admin, AdminProps } from './Admin'; export default { title: 'react-admin/Admin', }; const PostList = () =>

Post List

; const CommentList = () =>

Comment List

; export const Basic = () => ( ); export const InsideRouter = () => ( ); export const SubPath = () => (

Main

Go to admin
} /> } />
); // @ts-ignore const FailingAppBar = () => { throw new Error('AppBar rendering failed'); }; const FailedLayout = props => ; export const DefaultError = () => ( ); const ErrorPage = ({ errorInfo }: { errorInfo?: React.ErrorInfo }) => ( Error ); export const CustomError = () => ( ); const dataProvider = fakeRestDataProvider({ books: [ { id: 1, title: 'War and Peace', author_id: 1 }, { id: 2, title: 'Pride and Prejudice', author_id: 2 }, { id: 3, title: 'The Picture of Dorian Gray', author_id: 3 }, ], authors: [ { id: 1, firstName: 'Leo', lastName: 'Tolstoy' }, { id: 2, firstName: 'Jane', lastName: 'Austen' }, { id: 3, firstName: 'Oscar', lastName: 'Wilde' }, ], users: [ { id: 1, fullName: 'John Appleseed' }, { id: 2, fullName: 'Jane Doe' }, ], }); export const AccessControl = () => ; export const AccessControlInSubPath = () => (

Main

Go to admin
} /> } />
); const AccessControlAdmin = ({ AdminProps }: { AdminProps?: AdminProps }) => { const readerPermissions = [ { action: 'list', resource: 'books' }, { action: 'show', resource: 'books' }, { action: 'list', resource: 'authors' }, { action: 'show', resource: 'authors' }, ]; const editorPermissions = [ { action: 'list', resource: 'books' }, { action: 'create', resource: 'books' }, { action: 'edit', resource: 'books' }, { action: 'delete', resource: 'books' }, { action: 'list', resource: 'authors' }, { action: 'create', resource: 'authors' }, { action: 'edit', resource: 'authors' }, { action: 'delete', resource: 'authors' }, ]; const adminPermissions = [ ...editorPermissions, { action: 'list', resource: 'users' }, { action: 'show', resource: 'users' }, { action: 'create', resource: 'users' }, { action: 'edit', resource: 'users' }, { action: 'delete', resource: 'users' }, ]; const [permissions, setPermissions] = React.useState(readerPermissions); const [triggerAccessControlError, setTriggerAccessControlError] = React.useState(false); const authProvider: AuthProvider = { // authentication async login() {}, async checkError() {}, async checkAuth() {}, async logout() {}, async getIdentity() { return { id: 'user', fullName: 'John Doe' }; }, async handleCallback() {}, // for third-party authentication only // authorization (optional) async canAccess({ resource, action }) { if (triggerAccessControlError) { throw new Error('Access control error'); } return permissions.some( p => p.resource === resource && p.action === action ); }, async getPermissions() {}, }; const CustomLayout = ({ children }) => { const queryClient = useQueryClient(); return (
{children}
); }; return ( Create view} /> Create view} recordRepresentation={record => `${record.firstName} ${record.lastName}` } /> Create view} /> ); };