-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add user tooltip for user links
- Loading branch information
Showing
8 changed files
with
149 additions
and
22 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
plugins/qeta-react/src/components/FollowedLists/FollowedUsersList.tsx
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import ListItem from '@mui/material/ListItem'; | ||
import React from 'react'; | ||
import { useTranslation, useUserFollow } from '../../hooks'; | ||
import { RightList, RightListContainer } from '../Styled/RightList'; | ||
import { UserChip } from '../TagsAndEntities/UserChip'; | ||
|
||
export const FollowedUsersList = () => { | ||
const users = useUserFollow(); | ||
const { t } = useTranslation(); | ||
|
||
if (users.users.length === 0 || users.loading) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<RightListContainer> | ||
<RightList title={t('rightMenu.followedUsers')}> | ||
<ListItem style={{ display: 'block' }} dense> | ||
{users.users.map(user => ( | ||
<UserChip key={user} entityRef={user} /> | ||
))} | ||
</ListItem> | ||
</RightList> | ||
</RightListContainer> | ||
); | ||
}; |
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,3 +1,4 @@ | ||
export { FollowedEntitiesList } from './FollowedEntitiesList'; | ||
export { FollowedTagsList } from './FollowedTagsList'; | ||
export { FollowedCollectionsList } from './FollowedCollectionsList'; | ||
export { FollowedUsersList } from './FollowedUsersList'; |
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
89 changes: 89 additions & 0 deletions
89
plugins/qeta-react/src/components/TagsAndEntities/UserChip.tsx
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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { useRouteRef } from '@backstage/core-plugin-api'; | ||
import { userRouteRef } from '../../routes'; | ||
import { useTranslation, useUserFollow } from '../../hooks'; | ||
import { useEntityPresentation } from '@backstage/plugin-catalog-react'; | ||
import React from 'react'; | ||
import Chip from '@mui/material/Chip'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import Grid from '@mui/material/Grid'; | ||
import Typography from '@mui/material/Typography'; | ||
import Button from '@mui/material/Button'; | ||
import Tooltip from '@mui/material/Tooltip'; | ||
|
||
export const UserTooltip = (props: { entityRef: string }) => { | ||
const { entityRef } = props; | ||
const { t } = useTranslation(); | ||
const { | ||
primaryTitle: userName, | ||
Icon, | ||
secondaryTitle, | ||
} = useEntityPresentation( | ||
entityRef.startsWith('user:') ? entityRef : `user:${entityRef}`, | ||
); | ||
const users = useUserFollow(); | ||
|
||
return ( | ||
<Grid container style={{ padding: '0.5rem' }} spacing={1}> | ||
<Grid item xs={12}> | ||
<Typography variant="h6"> | ||
{Icon ? <Icon fontSize="small" /> : null} | ||
{entityRef === 'anonymous' ? t('userLink.anonymous') : userName} | ||
</Typography> | ||
</Grid> | ||
<Grid item xs={12}> | ||
<Typography variant="subtitle2">{secondaryTitle}</Typography> | ||
</Grid> | ||
{!users.loading && ( | ||
<Grid item xs={12}> | ||
<Button | ||
size="small" | ||
variant="outlined" | ||
color={users.isFollowingUser(entityRef) ? 'secondary' : 'primary'} | ||
onClick={() => { | ||
if (users.isFollowingUser(entityRef)) { | ||
users.unfollowUser(entityRef); | ||
} else { | ||
users.followUser(entityRef); | ||
} | ||
}} | ||
> | ||
{users.isFollowingUser(entityRef) | ||
? t('userButton.unfollow') | ||
: t('userButton.follow')} | ||
</Button> | ||
</Grid> | ||
)} | ||
</Grid> | ||
); | ||
}; | ||
|
||
export const UserChip = (props: { entityRef: string }) => { | ||
const navigate = useNavigate(); | ||
const { entityRef } = props; | ||
const userRoute = useRouteRef(userRouteRef); | ||
const { t } = useTranslation(); | ||
const { primaryTitle: userName } = useEntityPresentation( | ||
entityRef.startsWith('user:') ? entityRef : `user:${entityRef}`, | ||
); | ||
if (entityRef === 'anonymous') { | ||
return <>{t('userLink.anonymous')}</>; | ||
} | ||
return ( | ||
<Tooltip | ||
arrow | ||
title={<UserTooltip entityRef={entityRef} />} | ||
enterDelay={400} | ||
> | ||
<Chip | ||
label={userName} | ||
size="small" | ||
className="qetaTagChip" | ||
component="a" | ||
onClick={() => { | ||
navigate(`${userRoute()}/${entityRef}`); | ||
}} | ||
clickable | ||
/> | ||
</Tooltip> | ||
); | ||
}; |
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,14 +1,24 @@ | ||
import React from 'react'; | ||
import { UsersGrid, useTranslation } from '@drodil/backstage-plugin-qeta-react'; | ||
import { | ||
FollowedUsersList, | ||
UsersGrid, | ||
useTranslation, | ||
} from '@drodil/backstage-plugin-qeta-react'; | ||
import { ContentHeader } from '@backstage/core-components'; | ||
import Grid from '@mui/material/Grid'; | ||
|
||
export const UsersPage = () => { | ||
const { t } = useTranslation(); | ||
|
||
return ( | ||
<> | ||
<ContentHeader title={t('usersPage.title')} /> | ||
<UsersGrid /> | ||
</> | ||
<Grid container spacing={4}> | ||
<Grid item md={12} lg={8} xl={9}> | ||
<ContentHeader title={t('usersPage.title')} /> | ||
<UsersGrid /> | ||
</Grid> | ||
<Grid item lg={4} xl={3}> | ||
<FollowedUsersList /> | ||
</Grid> | ||
</Grid> | ||
); | ||
}; |