Skip to content

Commit

Permalink
fix menu selectedKeys
Browse files Browse the repository at this point in the history
Signed-off-by: Xuhui zhang <[email protected]>
  • Loading branch information
zxh326 committed Jun 21, 2024
1 parent 5de6e9a commit de691ff
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
21 changes: 13 additions & 8 deletions dashboard-ui-v2/src/components/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
import enUS from 'antd/locale/en_US'
import zhCN from 'antd/locale/zh_CN'
import { FormattedMessage, IntlProvider } from 'react-intl'
import { Link } from 'react-router-dom'
import { Link, useLocation } from 'react-router-dom'

import { DSIcon, PODIcon, PVCIcon, PVIcon, SCIcon } from '@/icons'
import en from '@/locales/en-US'
Expand All @@ -42,7 +42,7 @@ const items: MenuProps['items'] = [
<FormattedMessage id="appPodTable" />
</Link>
),
key: '1',
key: '/pods',
},
{
icon: <DSIcon />,
Expand All @@ -51,27 +51,28 @@ const items: MenuProps['items'] = [
<FormattedMessage id="sysPodTable" />
</Link>
),
key: '2',
key: '/syspods',
},
{
icon: <PVIcon />,
label: <Link to="/pvs">PV</Link>,
key: '3',
key: '/pvs',
},
{
icon: <PVCIcon />,
label: <Link to="/pvcs">PVC</Link>,
key: '4',
key: '/pvcs',
},
{
icon: <SCIcon />,
label: <Link to="/storageclass">Storage Class</Link>,
key: '5',
key: '/storageclass',
},
]

export default function Layout(props: { children: ReactNode }) {
const [locale, setLocale] = useState<string>()
const location = useLocation()

useEffect(() => {
if (locale) {
Expand Down Expand Up @@ -135,8 +136,12 @@ export default function Layout(props: { children: ReactNode }) {
>
<Menu
mode="inline"
defaultSelectedKeys={['1']}
defaultOpenKeys={['1']}
selectedKeys={[
location.pathname == '/'
? '/pods'
: `/${location.pathname.split('/')[1]}`,
]}
defaultOpenKeys={['/pods']}
style={{ height: '100%' }}
items={items}
/>
Expand Down
2 changes: 1 addition & 1 deletion dashboard-ui-v2/src/components/pvs-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const PVsTable: React.FC<{
title: <FormattedMessage id="name" />,
key: 'name',
render: (pv) => (
<Link to={`/pv/${pv.metadata.name}/`}>{pv.metadata.name}</Link>
<Link to={`/pvs/${pv.metadata.name}/`}>{pv.metadata.name}</Link>
),
},
{
Expand Down

0 comments on commit de691ff

Please sign in to comment.