ra-core
Version:
Core components of react-admin, a frontend Framework for building admin applications on top of REST services, using ES6, React
86 lines • 5.15 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.CoreAdminRoutes = void 0;
const React = __importStar(require("react"));
const react_1 = require("react");
const auth_1 = require("../auth/index.cjs");
const routing_1 = require("../routing/index.cjs");
const useConfigureAdminRouterFromChildren_1 = require("./useConfigureAdminRouterFromChildren.cjs");
const HasDashboardContext_1 = require("./HasDashboardContext.cjs");
const NavigateToFirstResource_1 = require("./NavigateToFirstResource.cjs");
const CoreAdminRoutes = (props) => {
(0, routing_1.useScrollToTop)();
const { Route, Routes } = (0, routing_1.useRouterProvider)();
const { customRoutesWithLayout, customRoutesWithoutLayout, status, resources, } = (0, useConfigureAdminRouterFromChildren_1.useConfigureAdminRouterFromChildren)(props.children);
const { layout: Layout, catchAll: CatchAll, dashboard, loading: LoadingPage, requireAuth, ready: Ready, authenticationError: AuthenticationError = Noop, accessDenied: AccessDenied = Noop, } = props;
const { authenticated, isPending: isPendingAuthenticated } = (0, auth_1.useAuthState)(undefined,
// do not log the user out on failure to allow access to custom routes with no layout
false, { enabled: requireAuth });
if (status === 'empty') {
if (!Ready) {
throw new Error('The admin is empty. Please provide an empty component, or pass Resource or CustomRoutes as children.');
}
return React.createElement(Ready, null);
}
// Note: custom routes with no layout are always rendered, regardless of the auth status
if (status === 'loading' || (requireAuth && isPendingAuthenticated)) {
return (React.createElement(Routes, null,
customRoutesWithoutLayout,
React.createElement(Route, { path: "*", element: React.createElement("div", { style: { height: '100vh' } },
React.createElement(LoadingPage, null)) })));
}
if (requireAuth && (isPendingAuthenticated || !authenticated)) {
return (React.createElement(Routes, null,
customRoutesWithoutLayout,
React.createElement(Route, { path: "*", element: React.createElement(auth_1.LogoutOnMount, null) })));
}
return (React.createElement(Routes, null,
customRoutesWithoutLayout,
React.createElement(Route, { path: "/*", element: React.createElement(HasDashboardContext_1.HasDashboardContextProvider, { value: !!dashboard },
React.createElement(Layout, null,
React.createElement(Routes, null,
customRoutesWithLayout,
react_1.Children.map(resources, resource => (React.createElement(Route, { key: resource.props.name, path: `${resource.props.name}/*`, element: resource }))),
React.createElement(Route, { path: "/", element: dashboard ? (React.createElement(auth_1.WithPermissions, { authParams: defaultAuthParams, component: dashboard, loading: LoadingPage })) : (React.createElement(NavigateToFirstResource_1.NavigateToFirstResource, { loading: LoadingPage })) }),
React.createElement(Route, { path: "/authentication-error", element: React.createElement(AuthenticationError, null) }),
React.createElement(Route, { path: "/access-denied", element: React.createElement(AccessDenied, null) }),
React.createElement(Route, { path: "*", element: React.createElement(CatchAll, null) })))) })));
};
exports.CoreAdminRoutes = CoreAdminRoutes;
// FIXME in v6: make dashboard anonymous by default to remove this hack
const defaultAuthParams = { params: { route: 'dashboard' } };
const Noop = () => null;
//# sourceMappingURL=CoreAdminRoutes.js.map