1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-09-28 17:55:15 +02:00
unleash.unleash/frontend/src/component/common/BreadcrumbNav/BreadcrumbNav.tsx
Nuno Góis ddcfe132e4
feat: new profile page and PATs front-end (#2109)
* feat: new user dropdown and profile page

* fix: add popup boxShadow to dark-theme

* fix: update routes snap

* refactor: move some tab specific logic into tabs component

* add useProfile hook example

* fix profile tab header (no name)

* fix: hide user popup when clicking profile link

* - add PATs to profile;
- add route logic to profile;
- refactor TimeAgoCell title;
- misc fixes and refactoring;

* add profile info to profile tab

* simplify req paths

* add PAT flag to the front-end

* fix: some UI adjustments

* change user popup buttons to links

* fix profile on front-end, add role description

* update delete PAT text

* address some PR comments

* address PR comments

* some more UI fixes and refactoring

* move password request to API hook
2022-10-03 10:49:52 +01:00

99 lines
3.8 KiB
TypeScript

import Breadcrumbs from '@mui/material/Breadcrumbs';
import { Link, useLocation } from 'react-router-dom';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
import { useStyles } from './BreadcrumbNav.styles';
import AccessContext from 'contexts/AccessContext';
import { useContext } from 'react';
import StringTruncator from '../StringTruncator/StringTruncator';
const BreadcrumbNav = () => {
const { isAdmin } = useContext(AccessContext);
const { classes: styles } = useStyles();
const location = useLocation();
const paths = location.pathname
.split('/')
.filter(item => item)
.filter(
item =>
item !== 'create' &&
item !== 'edit' &&
item !== 'view' &&
item !== 'variants' &&
item !== 'logs' &&
item !== 'metrics' &&
item !== 'copy' &&
item !== 'features' &&
item !== 'features2' &&
item !== 'create-toggle' &&
item !== 'settings' &&
item !== 'profile'
);
return (
<ConditionallyRender
condition={
(location.pathname.includes('admin') && isAdmin) ||
!location.pathname.includes('admin')
}
show={
<ConditionallyRender
condition={paths.length > 1}
show={
<Breadcrumbs
className={styles.breadcrumbNav}
aria-label="Breadcrumbs"
>
{paths.map((path, index) => {
const lastItem = index === paths.length - 1;
if (lastItem) {
return (
<p
key={path}
className={
styles.breadcrumbNavParagraph
}
>
<StringTruncator
text={path}
maxWidth="200"
maxLength={25}
/>
</p>
);
}
let link = '/';
paths.forEach((path, i) => {
if (i !== index && i < index) {
link += path + '/';
} else if (i === index) {
link += path;
}
});
return (
<Link
key={path}
className={styles.breadcrumbLink}
to={link}
>
<StringTruncator
maxLength={25}
text={path}
maxWidth="200"
/>
</Link>
);
})}
</Breadcrumbs>
}
/>
}
/>
);
};
export default BreadcrumbNav;