Skip to content

feat: labels indicator #1161

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 21 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/components/NotificationRow.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,25 @@ describe('components/NotificationRow.tsx', () => {
});
});

describe('notification labels', () => {
it('should render labels metric when available', async () => {
jest
.spyOn(global.Date, 'now')
.mockImplementation(() => new Date('2024').valueOf());

const mockNotification = mockSingleNotification;
mockNotification.subject.labels = ['enhancement', 'good-first-issue'];

const props = {
notification: mockNotification,
hostname: 'github.com',
};

const tree = render(<NotificationRow {...props} />);
expect(tree).toMatchSnapshot();
});
});

describe('linked issues/prs', () => {
it('should render when linked to one issue/pr', async () => {
jest
Expand Down
17 changes: 17 additions & 0 deletions src/components/NotificationRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
FeedPersonIcon,
IssueClosedIcon,
ReadIcon,
TagIcon,
} from '@primer/octicons-react';
import {
type FC,
Expand Down Expand Up @@ -92,6 +93,10 @@ export const NotificationRow: FC<IProps> = ({ notification, hostname }) => {
notification.subject.comments > 1 ? 'comments' : 'comment'
}`;

const labelsPillDescription = notification.subject.labels
?.map((label) => `🏷️ ${label}`)
.join('\n');

const linkedIssuesPillDescription = `Linked to ${
notification.subject.linkedIssues?.length > 1 ? 'issues' : 'issue'
} ${notification.subject?.linkedIssues?.join(', ')}`;
Expand Down Expand Up @@ -201,6 +206,18 @@ export const NotificationRow: FC<IProps> = ({ notification, hostname }) => {
</button>
</span>
)}
{notification.subject?.labels?.length > 0 && (
<span className="ml-1" title={labelsPillDescription}>
<button type="button" className={Constants.PILL_CLASS_NAME}>
<TagIcon
size={12}
className={`mr-1 ${IconColor.GRAY}`}
aria-label={labelsPillDescription}
/>
{notification.subject.labels.length}
</button>
</span>
)}
</span>
</span>
</div>
Expand Down
Loading