-
Notifications
You must be signed in to change notification settings - Fork 36
Introduce profile card on assignee hover in Jira Dashboard #301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,5 @@ | ||
| --- | ||
| '@axis-backstage/plugin-jira-dashboard': major | ||
| --- | ||
|
|
||
| Introduce a profile card that appears when hovering over an assignee's name in any table within the Jira Dashboard. |
164 changes: 164 additions & 0 deletions
164
plugins/jira-dashboard/src/components/JiraTable/cells/AssigneeCell.test.tsx
This file contains hidden or 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,164 @@ | ||
| import { render, screen } from '@testing-library/react'; | ||
| import { AssigneeCell } from './AssigneeCell'; | ||
| import { ThemeProvider, createTheme } from '@mui/material/styles'; | ||
| import { MemoryRouter } from 'react-router-dom'; | ||
| import { Issue } from '@axis-backstage/plugin-jira-dashboard-common'; | ||
|
|
||
| jest.mock('@backstage/plugin-catalog-react', () => ({ | ||
| EntityPeekAheadPopover: ({ children }: any) => ( | ||
| <div data-testid="peek-ahead">{children}</div> | ||
| ), | ||
| })); | ||
|
|
||
| const renderWithProviders = (ui: React.ReactElement) => | ||
| render( | ||
| <MemoryRouter> | ||
| <ThemeProvider theme={createTheme()}>{ui}</ThemeProvider> | ||
| </MemoryRouter>, | ||
| ); | ||
|
|
||
| describe('AssigneeCell', () => { | ||
| const baseAssignee: Issue['fields']['assignee'] = { | ||
| name: 'jane.doe', | ||
| key: 'jdoe', | ||
| self: '', | ||
| displayName: 'Jane Doe', | ||
| avatarUrls: { '48x48': 'http://example.com/avatar.jpg' }, | ||
| }; | ||
|
|
||
| it('renders displayName with EntityPeekAheadPopover and correct link when assignee is valid', () => { | ||
| renderWithProviders(<AssigneeCell assignee={baseAssignee} />); | ||
| expect(screen.getByTestId('peek-ahead')).toBeInTheDocument(); | ||
| expect(screen.getByRole('link')).toHaveAttribute( | ||
| 'href', | ||
| '/catalog/default/user/jane.doe', | ||
| ); | ||
| expect(screen.getByText('Jane Doe')).toBeInTheDocument(); | ||
| expect(screen.getByTestId('assignee-avatar')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders "Unassigned" when assignee name is an empty string', () => { | ||
| renderWithProviders( | ||
| <AssigneeCell | ||
| assignee={{ | ||
| ...baseAssignee, | ||
| name: '', | ||
| displayName: '', | ||
| }} | ||
| />, | ||
| ); | ||
|
|
||
| expect(screen.queryByTestId('peek-ahead')).not.toBeInTheDocument(); | ||
| expect(screen.queryByRole('link')).not.toBeInTheDocument(); | ||
| expect(screen.getByText('Unassigned')).toBeInTheDocument(); | ||
| expect(screen.getByTestId('assignee-avatar')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| const unassignedNames = ['unassigned', 'Unassigned', 'UNASSIGNED']; | ||
|
|
||
| test.each(unassignedNames)( | ||
| 'renders "Unassigned" when assignee name is "%s"', | ||
| name => { | ||
| renderWithProviders( | ||
| <AssigneeCell | ||
| assignee={{ | ||
| name, | ||
| displayName: '', | ||
| key: '', | ||
| self: '', | ||
| avatarUrls: { | ||
| '48x48': '', | ||
| }, | ||
| }} | ||
| />, | ||
| ); | ||
|
|
||
| expect(screen.queryByTestId('peek-ahead')).not.toBeInTheDocument(); | ||
| expect(screen.queryByRole('link')).not.toBeInTheDocument(); | ||
| expect(screen.getByText('Unassigned')).toBeInTheDocument(); | ||
| expect(screen.getByTestId('assignee-avatar')).toBeInTheDocument(); | ||
| }, | ||
| ); | ||
|
|
||
| it('renders name if displayName is missing', () => { | ||
| renderWithProviders( | ||
| <AssigneeCell | ||
| assignee={{ | ||
| name: 'john.smith', | ||
| key: 'jsmith', | ||
| self: '', | ||
| displayName: '', | ||
| avatarUrls: { '48x48': '' }, | ||
| }} | ||
| />, | ||
| ); | ||
|
|
||
| expect(screen.getByText('john.smith')).toBeInTheDocument(); | ||
| expect(screen.getByRole('link')).toHaveAttribute( | ||
| 'href', | ||
| '/catalog/default/user/john.smith', | ||
| ); | ||
| expect(screen.getByTestId('assignee-avatar')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders "Unassigned" when assignee.name and displayName are both empty (no fallback to key)', () => { | ||
| renderWithProviders( | ||
| <AssigneeCell | ||
| assignee={{ | ||
| key: 'userkey123', | ||
| name: '', | ||
| self: '', | ||
| displayName: '', | ||
| avatarUrls: { '48x48': '' }, | ||
| }} | ||
| />, | ||
| ); | ||
|
|
||
| expect(screen.getByText('Unassigned')).toBeInTheDocument(); | ||
| expect(screen.queryByRole('link')).not.toBeInTheDocument(); | ||
| expect(screen.getByTestId('assignee-avatar')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders nothing when assignee is undefined', () => { | ||
| const { container } = renderWithProviders( | ||
| <AssigneeCell assignee={undefined} />, | ||
| ); | ||
| expect(container).toBeEmptyDOMElement(); | ||
| }); | ||
|
|
||
| it('normalizes email-like assignee name (fridaja@backstage) to username', () => { | ||
| renderWithProviders( | ||
| <AssigneeCell | ||
| assignee={{ | ||
| ...baseAssignee, | ||
| name: 'fridaja@backstage', | ||
| displayName: 'Frida J', | ||
| }} | ||
| />, | ||
| ); | ||
|
|
||
| expect(screen.getByRole('link')).toHaveAttribute( | ||
| 'href', | ||
| '/catalog/default/user/fridaja', | ||
| ); | ||
| expect(screen.getByText('Frida J')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('normalizes real email (alice@example.com) to username', () => { | ||
| renderWithProviders( | ||
| <AssigneeCell | ||
| assignee={{ | ||
| ...baseAssignee, | ||
| name: 'alice@example.com', | ||
| displayName: 'Alice Example', | ||
| }} | ||
| />, | ||
| ); | ||
|
|
||
| expect(screen.getByRole('link')).toHaveAttribute( | ||
| 'href', | ||
| '/catalog/default/user/alice', | ||
| ); | ||
| expect(screen.getByText('Alice Example')).toBeInTheDocument(); | ||
| }); | ||
| }); |
66 changes: 66 additions & 0 deletions
66
plugins/jira-dashboard/src/components/JiraTable/cells/AssigneeCell.tsx
This file contains hidden or 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,66 @@ | ||
| import { Avatar, Link } from '@backstage/core-components'; | ||
| import Typography from '@mui/material/Typography'; | ||
| import Stack from '@mui/material/Stack'; | ||
| import { Issue } from '@axis-backstage/plugin-jira-dashboard-common'; | ||
| import { EntityPeekAheadPopover } from '@backstage/plugin-catalog-react'; | ||
| import { stringifyEntityRef } from '@backstage/catalog-model'; | ||
|
|
||
| type Props = { | ||
| assignee?: Issue['fields']['assignee']; | ||
| }; | ||
|
|
||
| const normalizeAssigneeName = (name: string): string => { | ||
| if (!name) return ''; | ||
| if (name.includes('@')) { | ||
| return name.split('@')[0]; | ||
| } | ||
| return name; | ||
| }; | ||
| export const AssigneeCell = ({ assignee }: Props) => { | ||
| if (!assignee) { | ||
| return null; | ||
| } | ||
|
|
||
| if (!assignee.name || assignee.name.toLowerCase() === 'unassigned') { | ||
| return ( | ||
| <Stack | ||
| direction="row" | ||
| gap={1} | ||
| alignItems="center" | ||
| data-testid="assignee-avatar" | ||
| > | ||
| <Avatar picture="" customStyles={{ width: 35, height: 35 }} /> | ||
| <Typography variant="body2">Unassigned</Typography> | ||
| </Stack> | ||
| ); | ||
| } | ||
|
|
||
| const entityRef = { | ||
| kind: 'user', | ||
| namespace: 'default', | ||
| name: normalizeAssigneeName(assignee.name), | ||
| }; | ||
|
|
||
| return ( | ||
| <EntityPeekAheadPopover entityRef={stringifyEntityRef(entityRef)}> | ||
| <Link | ||
| to={`/catalog/${entityRef.namespace}/${entityRef.kind}/${entityRef.name}`} | ||
| > | ||
| <Stack | ||
| direction="row" | ||
| gap={1} | ||
| alignItems="center" | ||
| data-testid="assignee-avatar" | ||
| > | ||
| <Avatar | ||
| picture={assignee.avatarUrls?.['48x48'] || ''} | ||
| customStyles={{ width: 35, height: 35 }} | ||
| /> | ||
| <Typography noWrap variant="body2"> | ||
| {assignee.displayName || assignee.name} | ||
| </Typography> | ||
| </Stack> | ||
| </Link> | ||
| </EntityPeekAheadPopover> | ||
| ); | ||
| }; | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.