-
Notifications
You must be signed in to change notification settings - Fork 13.4k
refactor: Sidebar badges #37638
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
refactor: Sidebar badges #37638
Changes from 18 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
9fda01d
refactor(sidebar-v1): SideBarItemTemplateWithData to use hook useUnre…
aleksandernsilva 74e0607
refactor(sidebar-v1): OmnichannelBadges to export default
aleksandernsilva 35185a9
refactor(sidebar-v2): OmnichannelBadges to export default
aleksandernsilva 478b279
refactor(sidebar-v1): SidebarItemBadges
aleksandernsilva e8d5b25
refactor(sidebar-v2): SidebarItemBadges
aleksandernsilva 4daa2c3
refactor(navigation): SidebarItemBadges
aleksandernsilva 2048cd0
refactor(sidepanel): RoomSidePanelItemBadges
aleksandernsilva a58b4c3
refactor: exported UnreadData type
aleksandernsilva d3da04d
chore(navigation): removed unused OmnichannelBadges
aleksandernsilva 59e40c2
refactor(navigation): adjusted import
aleksandernsilva c75546a
refactor(navbar-v2): NavBarSearchItemWithData
aleksandernsilva f033c06
test: fixed typo
aleksandernsilva 8e405f2
test: added wrapper
aleksandernsilva a1e635d
refactor: use highlightUnread
aleksandernsilva 7ca04cd
chore: code style
aleksandernsilva 55b16b9
test: adjusted to use accessible locators
aleksandernsilva e6658db
refactor: moved OmnichannelBadges to views/omnichannel
aleksandernsilva 5aa2110
refactor(sidebar-v1): replaced ISubscription & IRoom types with Subsc…
aleksandernsilva bb29143
Merge branch 'develop' into refactor/sidebar-badges
kodiakhq[bot] 5d30f18
Merge branch 'develop' into refactor/sidebar-badges
kodiakhq[bot] 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
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
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
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
This file was deleted.
Oops, something went wrong.
53 changes: 53 additions & 0 deletions
53
apps/meteor/client/sidebar/badges/SidebarItemBadges.spec.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,53 @@ | ||
| import { mockAppRoot } from '@rocket.chat/mock-providers'; | ||
| import { render, screen } from '@testing-library/react'; | ||
|
|
||
| import SidebarItemBadges from './SidebarItemBadges'; | ||
| import { createFakeSubscription } from '../../../tests/mocks/data'; | ||
|
|
||
| jest.mock('../../views/omnichannel/components/OmnichannelBadges', () => ({ | ||
| __esModule: true, | ||
| default: () => <i role='status' aria-label='OmnichannelBadges' />, | ||
| })); | ||
|
|
||
| describe('SidebarItemBadges', () => { | ||
| const appRoot = mockAppRoot() | ||
| .withTranslations('en', 'core', { | ||
| Message_request: 'Message request', | ||
| mentions_counter_one: '{{count}} mention', | ||
| mentions_counter_other: '{{count}} mentions', | ||
| __unreadTitle__from__roomTitle__: '{{unreadTitle}} from {{roomTitle}}', | ||
| }) | ||
| .build(); | ||
|
|
||
| afterEach(() => { | ||
| jest.resetAllMocks(); | ||
| }); | ||
|
|
||
| it('should render UnreadBadge when there are unread messages', () => { | ||
| render(<SidebarItemBadges room={createFakeSubscription({ unread: 1, userMentions: 1, groupMentions: 0 })} roomTitle='Test Room' />, { | ||
| wrapper: appRoot, | ||
| }); | ||
|
|
||
| expect(screen.getByRole('status', { name: '1 mention from Test Room' })).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should not render UnreadBadge when there are no unread messages', () => { | ||
| render(<SidebarItemBadges room={createFakeSubscription({ unread: 0, userMentions: 0, groupMentions: 0 })} roomTitle='Test Room' />, { | ||
| wrapper: appRoot, | ||
| }); | ||
|
|
||
| expect(screen.queryByRole('status', { name: 'Test Room' })).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should render OmnichannelBadges when the room is an omnichannel room', () => { | ||
| render(<SidebarItemBadges room={createFakeSubscription({ t: 'l' })} />, { wrapper: appRoot }); | ||
|
|
||
| expect(screen.getByRole('status', { name: 'OmnichannelBadges' })).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should not render OmnichannelBadges when the room is not an omnichannel room', () => { | ||
| render(<SidebarItemBadges room={createFakeSubscription({ t: 'p' })} />, { wrapper: appRoot }); | ||
|
|
||
| expect(screen.queryByRole('status', { name: 'OmnichannelBadges' })).not.toBeInTheDocument(); | ||
| }); | ||
| }); |
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,25 @@ | ||
| import { isOmnichannelRoom } from '@rocket.chat/core-typings'; | ||
| import { Margins } from '@rocket.chat/fuselage'; | ||
| import type { SubscriptionWithRoom } from '@rocket.chat/ui-contexts'; | ||
|
|
||
| import UnreadBadge from './UnreadBadge'; | ||
| import OmnichannelBadges from '../../views/omnichannel/components/OmnichannelBadges'; | ||
| import { useUnreadDisplay } from '../hooks/useUnreadDisplay'; | ||
|
|
||
| type SidebarItemBadgesProps = { | ||
| room: SubscriptionWithRoom; | ||
| roomTitle?: string; | ||
| }; | ||
|
|
||
| const SidebarItemBadges = ({ room, roomTitle }: SidebarItemBadgesProps) => { | ||
| const { unreadCount, unreadTitle, unreadVariant, showUnread } = useUnreadDisplay(room); | ||
|
|
||
| return ( | ||
| <Margins inlineStart={8}> | ||
| {showUnread && <UnreadBadge title={unreadTitle} roomTitle={roomTitle} variant={unreadVariant} total={unreadCount.total} />} | ||
| {isOmnichannelRoom(room) && <OmnichannelBadges room={room} />} | ||
| </Margins> | ||
| ); | ||
| }; | ||
|
|
||
| export default SidebarItemBadges; | ||
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,27 @@ | ||
| import { Badge } from '@rocket.chat/fuselage'; | ||
| import { useTranslation } from 'react-i18next'; | ||
|
|
||
| type UnreadBadgeProps = { | ||
| title: string; | ||
| roomTitle?: string; | ||
| variant: 'primary' | 'warning' | 'danger' | 'secondary'; | ||
| total: number; | ||
| }; | ||
|
|
||
| const UnreadBadge = ({ title, variant, total, roomTitle }: UnreadBadgeProps) => { | ||
| const { t } = useTranslation(); | ||
|
|
||
| return ( | ||
| <Badge | ||
| role='status' | ||
| {...({ style: { display: 'inline-flex', flexShrink: 0 } } as any)} | ||
| variant={variant} | ||
| title={title} | ||
| aria-label={t('__unreadTitle__from__roomTitle__', { unreadTitle: title, roomTitle })} | ||
| > | ||
| <span aria-hidden>{total}</span> | ||
| </Badge> | ||
| ); | ||
| }; | ||
|
|
||
| export default UnreadBadge; |
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
Oops, something went wrong.
Oops, something went wrong.
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.