-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(admin-ui): jans-link UI changes #1287
- Loading branch information
1 parent
a3e653e
commit 4d964fa
Showing
11 changed files
with
663 additions
and
394 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,106 @@ | ||
import React, { useState } from 'react'; | ||
import React, { useEffect, useState } from 'react' | ||
import Tabs from '@mui/material/Tabs' | ||
import Tab from '@mui/material/Tab' | ||
import Box from '@mui/material/Box' | ||
|
||
import { useLocation, useNavigate } from 'react-router' | ||
|
||
const TabPanel = (props) => { | ||
const { children, value, px, py, index, ...other } = props; | ||
return ( | ||
<div | ||
role="tabpanel" | ||
hidden={value !== index} | ||
id={`simple-tabpanel-${index}`} | ||
aria-labelledby={`simple-tab-${index}`} | ||
{...other} | ||
> | ||
{value === index && ( | ||
<Box px={px} py={py}> | ||
{children} | ||
</Box> | ||
)} | ||
</div> | ||
); | ||
const { children, value, px, py, index, ...other } = props | ||
return ( | ||
<div | ||
role='tabpanel' | ||
hidden={value !== index} | ||
id={`simple-tabpanel-${index}`} | ||
aria-labelledby={`simple-tab-${index}`} | ||
{...other} | ||
> | ||
{value === index && ( | ||
<Box px={px} py={py}> | ||
{children} | ||
</Box> | ||
)} | ||
</div> | ||
) | ||
} | ||
|
||
const a11yProps = (index) => { | ||
return { | ||
id: `simple-tab-${index}`, | ||
"aria-controls": `simple-tabpanel-${index}`, | ||
}; | ||
return { | ||
id: `simple-tab-${index}`, | ||
'aria-controls': `simple-tabpanel-${index}`, | ||
} | ||
} | ||
|
||
const initTabValue = (tabNames, path) => { | ||
const tab = tabNames | ||
.map((tab, index) => { | ||
if (tab.path === path.pathname) { | ||
return { ...tab, index: index } | ||
} | ||
}) | ||
?.filter((tab) => tab)?.[0] | ||
|
||
return tab?.index || 0 | ||
} | ||
|
||
export default function GluuTabs({ | ||
tabNames, | ||
tabToShow | ||
tabNames, | ||
tabToShow, | ||
withNavigation = false, | ||
}) { | ||
const [value, setValue] = useState(0); | ||
const path = useLocation() | ||
const [value, setValue] = useState( | ||
withNavigation ? initTabValue(tabNames, path) : 0 | ||
) | ||
const navigate = useNavigate() | ||
|
||
const handleChange = (event, newValue) => { | ||
setValue(newValue); | ||
}; | ||
const handleChange = (event, newValue) => { | ||
setValue(newValue) | ||
if (withNavigation) { | ||
const tab = tabNames.find((tab, index) => index === newValue) | ||
navigate(tab.path, { replace: true }) | ||
} | ||
} | ||
|
||
return ( | ||
<Box sx={{ width: "100%" }}> | ||
<Box sx={{ borderBottom: 1, borderColor: "divider", }}> | ||
<Tabs | ||
value={value} | ||
variant="scrollable" | ||
onChange={handleChange} | ||
> | ||
{tabNames?.map((name, index) => ( | ||
<Tab | ||
data-testid={name} | ||
key={name + index.toString()} | ||
label={name} | ||
{...a11yProps(index)} | ||
/> | ||
))} | ||
</Tabs> | ||
</Box> | ||
{tabNames?.map((name, index) => ( | ||
<TabPanel value={value} key={name + index.toString()} index={index}> | ||
{tabToShow(name)} | ||
</TabPanel> | ||
))} | ||
</Box> | ||
); | ||
useEffect(() => { | ||
if (withNavigation) { | ||
const tab = tabNames | ||
.map((tab, index) => { | ||
if (tab.path === path.pathname) { | ||
return { ...tab, index: index } | ||
} | ||
}) | ||
?.filter((tab) => tab)?.[0] | ||
|
||
if (!tab) { | ||
navigate(tabNames[0].path, { replace: true }) | ||
setValue(0) | ||
return | ||
} | ||
|
||
navigate(tab.path, { replace: true }) | ||
setValue(tab.index) | ||
} | ||
}, []) | ||
|
||
return ( | ||
<Box sx={{ width: '100%' }}> | ||
<Box sx={{ borderBottom: 1, borderColor: 'divider' }}> | ||
<Tabs value={value} variant='scrollable' onChange={handleChange}> | ||
{tabNames?.map((tab, index) => ( | ||
<Tab | ||
data-testid={withNavigation ? tab.name : tab} | ||
key={(withNavigation ? tab.name : tab) + index.toString()} | ||
label={withNavigation ? tab.name : tab} | ||
{...a11yProps(index)} | ||
/> | ||
))} | ||
</Tabs> | ||
</Box> | ||
{tabNames?.map((tab, index) => ( | ||
<TabPanel value={value} key={(withNavigation ? tab.name : tab) + index.toString()} index={index}> | ||
{tabToShow(withNavigation ? tab.name : tab)} | ||
</TabPanel> | ||
))} | ||
</Box> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.