UNPKG

react-admin

Version:

A frontend Framework for building admin applications on top of REST services, using ES6, React and Material UI

98 lines 4.26 kB
import * as React from 'react'; import { localStorageStore } from 'ra-core'; import { AdminUI, AdminContext, } from 'ra-ui-materialui'; import { defaultI18nProvider } from './defaultI18nProvider'; var defaultStore = localStorageStore(); /** * Main admin component, entry point to the application. * * Initializes the various contexts (auth, data, i18n, router) * and defines the main routes. * * Expects a list of resources as children, or a function returning a list of * resources based on the permissions. * * @example * * // static list of resources * * import { * Admin, * Resource, * ListGuesser, * useDataProvider, * } from 'react-admin'; * * const App = () => ( * <Admin dataProvider={myDataProvider}> * <Resource name="posts" list={ListGuesser} /> * </Admin> * ); * * // dynamic list of resources based on permissions * * import { * Admin, * Resource, * ListGuesser, * useDataProvider, * } from 'react-admin'; * * const App = () => ( * <Admin dataProvider={myDataProvider}> * {permissions => [ * <Resource name="posts" key="posts" list={ListGuesser} />, * ]} * </Admin> * ); * * // If you have to build a dynamic list of resources using a side effect, * // you can't use <Admin>. But as it delegates to sub components, * // it's relatively straightforward to replace it: * * import * as React from 'react'; import { useEffect, useState } from 'react'; * import { * AdminContext, * AdminUI, * defaultI18nProvider, * localStorageStore, * Resource, * ListGuesser, * useDataProvider, * } from 'react-admin'; * * const store = localStorageStore(); * * const App = () => ( * <AdminContext dataProvider={myDataProvider} i18nProvider={defaultI18nProvider} store={store}> * <Resources /> * </AdminContext> * ); * * const Resources = () => { * const [resources, setResources] = useState([]); * const dataProvider = useDataProvider(); * useEffect(() => { * dataProvider.introspect().then(r => setResources(r)); * }, []); * * return ( * <AdminUI> * {resources.map(resource => ( * <Resource name={resource.name} key={resource.key} list={ListGuesser} /> * ))} * </AdminUI> * ); * }; */ export var Admin = function (props) { var accessDenied = props.accessDenied, authCallbackPage = props.authCallbackPage, authenticationError = props.authenticationError, authProvider = props.authProvider, basename = props.basename, catchAll = props.catchAll, children = props.children, darkTheme = props.darkTheme, dashboard = props.dashboard, dataProvider = props.dataProvider, defaultTheme = props.defaultTheme, disableTelemetry = props.disableTelemetry, error = props.error, _a = props.i18nProvider, i18nProvider = _a === void 0 ? defaultI18nProvider : _a, layout = props.layout, lightTheme = props.lightTheme, loading = props.loading, loginPage = props.loginPage, notification = props.notification, queryClient = props.queryClient, ready = props.ready, requireAuth = props.requireAuth, _b = props.store, store = _b === void 0 ? defaultStore : _b, theme = props.theme, _c = props.title, title = _c === void 0 ? 'React Admin' : _c; if (loginPage === true && process.env.NODE_ENV !== 'production') { console.warn('You passed true to the loginPage prop. You must either pass false to disable it or a component class to customize it'); } return (React.createElement(AdminContext, { authProvider: authProvider, basename: basename, darkTheme: darkTheme, dataProvider: dataProvider, defaultTheme: defaultTheme, i18nProvider: i18nProvider, lightTheme: lightTheme, queryClient: queryClient, store: store, theme: theme }, React.createElement(AdminUI, { accessDenied: accessDenied, authCallbackPage: authCallbackPage, authenticationError: authenticationError, catchAll: catchAll, dashboard: dashboard, disableTelemetry: disableTelemetry, error: error, layout: layout, loading: loading, loginPage: loginPage, notification: notification, ready: ready, requireAuth: requireAuth, title: title }, children))); }; export default Admin; //# sourceMappingURL=Admin.js.map