fix(client): auto jump to the first menu item after login

This commit is contained in:
chenos 2021-10-10 22:24:30 +08:00
parent 516c1be50d
commit 2ce3b9d21b

View File

@ -138,7 +138,7 @@ function LayoutWithMenu(props: LayoutWithMenuProps) {
setActiveKey(match.params.name);
}, [match.params.name]);
const onMenuItemRemove = () => {
history.push(`/admin`);
history.push(`/admin/${uid()}`);
};
console.log({ activeKey, selectedKeys });
return (
@ -206,6 +206,7 @@ function Content({ activeKey }) {
export function AdminLayout({ route, ...others }: any) {
const match = useRouteMatch<any>();
const { data = {}, loading } = useRequest(
`ui_schemas:getTree/${route.uiSchemaKey}`,
{
@ -214,10 +215,34 @@ export function AdminLayout({ route, ...others }: any) {
},
);
const first: any = Object.values(data?.properties||{}).shift();
const findMenuLinkProperties = (schema: Schema): Schema[] => {
if (!schema) {
return [];
}
if (schema['x-component'] == 'Menu.Link') {
return [schema];
}
return schema.reduceProperties((items, current) => {
if (current['x-component'] == 'Menu.Link') {
return [...items, current];
}
return [...items, ...findMenuLinkProperties(current)];
}, []);
};
if (loading) {
return <Spin size={'large'} className={'nb-spin-center'} />;
}
const f = findMenuLinkProperties(new Schema(first||{})).shift();
if (f?.['key'] && !match.params.name) {
return <Redirect to={`/admin/${f?.['key']}`} />;
}
const findProperties = (schema: Schema): Schema[] => {
if (!schema) {
return [];
@ -240,8 +265,6 @@ export function AdminLayout({ route, ...others }: any) {
parent = parent.parent;
}
console.log('current?.title', current, current?.title, defaultSelectedKeys);
return (
<AuthProvider>
<SystemSettingsProvider>