import { css } from '@emotion/css'; import { Layout, Spin } from 'antd'; import React, { createContext, useContext, useMemo, useRef } from 'react'; import { useHistory, useRouteMatch } from 'react-router-dom'; import { ACLAllowConfigure, ACLRolesCheckProvider, CurrentUser, CurrentUserProvider, findByUid, findMenuItem, RemoteCollectionManagerProvider, RemotePluginManagerToolbar, RemoteSchemaTemplateManagerProvider, SchemaComponent, useACLRoleContext, useDocumentTitle, useRequest, useRoute, useSystemSettings } from '../../../'; import { useCollectionManager } from '../../../collection-manager'; import { PoweredBy } from '../../../powered-by'; const filterByACL = (schema, options) => { const { allowAll, allowConfigure, allowMenuItemIds = [] } = options; if (allowAll || allowConfigure) { return schema; } const filterSchema = (s) => { if (!s) { return; } for (const key in s.properties) { if (Object.prototype.hasOwnProperty.call(s.properties, key)) { const element = s.properties[key]; if (element['x-uid'] && !allowMenuItemIds.includes(element['x-uid'])) { delete s.properties[key]; } } } }; filterSchema(schema); return schema; }; const SchemaIdContext = createContext(null); const useMenuProps = () => { const defaultSelectedUid = useContext(SchemaIdContext); return { selectedUid: defaultSelectedUid, defaultSelectedUid, }; }; const MenuEditor = (props) => { const { setTitle } = useDocumentTitle(); const history = useHistory(); const match = useRouteMatch(); const defaultSelectedUid = match.params.name; const { sideMenuRef } = props; const ctx = useACLRoleContext(); const route = useRoute(); const onSelect = ({ item }) => { const schema = item.props.schema; setTitle(schema.title); history.push(`/admin/${schema['x-uid']}`); }; const { data, loading } = useRequest( { url: `/uiSchemas:getJsonSchema/${route.uiSchemaUid}`, }, { refreshDeps: [route.uiSchemaUid], onSuccess(data) { const schema = filterByACL(data?.data, ctx); if (defaultSelectedUid) { const s = findByUid(schema, defaultSelectedUid); if (s) { setTitle(s.title); } } else { const s = findMenuItem(schema); if (s) { history.push(`/admin/${s['x-uid']}`); setTitle(s.title); } } }, }, ); const schema = useMemo(() => { const s = filterByACL(data?.data, ctx); if (s?.['x-component-props']) { s['x-component-props']['useProps'] = useMenuProps; } return s; }, [data?.data]); if (loading) { return ; } return ( ); }; const InternalAdminLayout = (props: any) => { const route = useRoute(); const history = useHistory(); const match = useRouteMatch(); const { setTitle } = useDocumentTitle(); const sideMenuRef = useRef(); const result = useSystemSettings(); const { service } = useCollectionManager(); return ( .ant-menu-item:hover { background-color: rgba(255, 255, 255, 0.1); } `} style={{ height: 46, lineHeight: '46px', position: 'relative', paddingLeft: 0 }} >
{/* {result?.data?.data?.title} */}
{service.contentLoading ? : props.children}
); }; export const AdminLayout = (props) => { return ( ); }; export default AdminLayout;