From 2ce3b9d21bfafe39d1b18b66d8f1fd0fe2a52b5a Mon Sep 17 00:00:00 2001 From: chenos Date: Sun, 10 Oct 2021 22:24:30 +0800 Subject: [PATCH] fix(client): auto jump to the first menu item after login --- .../src/components/admin-layout/index.tsx | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/packages/client/src/components/admin-layout/index.tsx b/packages/client/src/components/admin-layout/index.tsx index 568179eef..3e12d42c4 100644 --- a/packages/client/src/components/admin-layout/index.tsx +++ b/packages/client/src/components/admin-layout/index.tsx @@ -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(); + 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 ; } + const f = findMenuLinkProperties(new Schema(first||{})).shift(); + + if (f?.['key'] && !match.params.name) { + return ; + } + 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 (