ra-core
Version:
Core components of react-admin, a frontend Framework for building admin applications on top of REST services, using ES6, React
44 lines • 3.15 kB
JavaScript
import * as React from 'react';
import { useEffect, isValidElement, createElement, useState, } from 'react';
import { ErrorBoundary } from 'react-error-boundary';
import { CoreAdminRoutes } from "./CoreAdminRoutes.js";
import { useResetErrorBoundaryOnLocationChange, useRouterProvider, } from "../routing/index.js";
import { Ready } from "../util/index.js";
import { DefaultTitleContextProvider } from "./DefaultTitleContext.js";
const DefaultLayout = ({ children }) => (React.createElement(React.Fragment, null, children));
const DefaultError = ({ error, errorInfo, resetErrorBoundary }) => {
useResetErrorBoundaryOnLocationChange(resetErrorBoundary);
return (React.createElement("div", null,
React.createElement("h1", null, "Error"),
React.createElement("pre", null,
error.message,
errorInfo?.componentStack)));
};
export const CoreAdminUI = (props) => {
const [errorInfo, setErrorInfo] = useState({});
const { Route, Routes } = useRouterProvider();
const { authCallbackPage: LoginCallbackPage = false, catchAll = Noop, children, dashboard, disableTelemetry = false, error: ErrorComponent = DefaultError, layout = DefaultLayout, loading = Noop, loginPage: LoginPage = false, ready = Ready, requireAuth = false, title = 'React Admin', authenticationError = Noop, accessDenied = Noop, } = props;
useEffect(() => {
if (disableTelemetry ||
process.env.NODE_ENV !== 'production' ||
typeof window === 'undefined' ||
typeof window.location === 'undefined' ||
typeof Image === 'undefined') {
return;
}
const img = new Image();
img.src = `https://react-admin-telemetry.marmelab.com/react-admin-telemetry?domain=${window.location.hostname}`;
}, [disableTelemetry]);
const handleError = (error, info) => setErrorInfo(info);
return (React.createElement(DefaultTitleContextProvider, { value: title },
React.createElement(ErrorBoundary, { onError: handleError, fallbackRender: ({ error, resetErrorBoundary }) => (React.createElement("div", { style: { minHeight: '100vh' } },
React.createElement(ErrorComponent, { error: error, errorInfo: errorInfo, resetErrorBoundary: resetErrorBoundary }))) },
React.createElement(Routes, null,
LoginPage !== false && LoginPage !== true ? (React.createElement(Route, { path: "/login", element: createOrGetElement(LoginPage) })) : null,
LoginCallbackPage !== false &&
LoginCallbackPage !== true ? (React.createElement(Route, { path: "/auth-callback", element: createOrGetElement(LoginCallbackPage) })) : null,
React.createElement(Route, { path: "/*", element: React.createElement(CoreAdminRoutes, { catchAll: catchAll, dashboard: dashboard, layout: layout, loading: loading, requireAuth: requireAuth, ready: ready, authenticationError: authenticationError, accessDenied: accessDenied }, children) })))));
};
const createOrGetElement = el => (isValidElement(el) ? el : createElement(el));
const Noop = () => null;
//# sourceMappingURL=CoreAdminUI.js.map