-
Notifications
You must be signed in to change notification settings - Fork 13.8k
refactor(ui-contexts,fuselage-ui-kit,ui-client): Decouple room navigation hooks from roomCoordinator and ui-contexts #41508
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
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c68aa2f
refactor: replace roomCoordinator with router navigation in room UI
cardoso f339063
refactor(ui-contexts): move useGoToRoom into fuselage-ui-kit
tassoevan 1bbc968
refactor(ui-contexts): move useRoomRoute into ui-client
tassoevan dd3402b
fix(room): restore special-chars/federation-aware room name in Parent…
tassoevan 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
23 changes: 19 additions & 4 deletions
23
apps/meteor/client/views/room/Header/ParentRoom/ParentDiscussion/ParentDiscussion.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
6 changes: 4 additions & 2 deletions
6
apps/meteor/client/views/room/body/RoomForeword/RoomForewordUsernameList.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
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
66 changes: 66 additions & 0 deletions
66
packages/fuselage-ui-kit/src/blocks/VideoConferenceBlock/hooks/useGoToRoom.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,66 @@ | ||
| import type { IRoom } from '@rocket.chat/core-typings'; | ||
| import { MockedRouterContext, MockedServerContext } from '@rocket.chat/mock-providers'; | ||
| import type { MockedRouterContextProps } from '@rocket.chat/mock-providers'; | ||
| import { renderHook, waitFor } from '@testing-library/react'; | ||
|
|
||
| import { useGoToRoom } from './useGoToRoom'; | ||
|
|
||
| const getWrapper = | ||
| (room: Partial<IRoom> | undefined, router?: MockedRouterContextProps['router']) => | ||
| ({ children }: { children: any }) => { | ||
| return ( | ||
| <MockedServerContext handleRequest={async () => ({ room }) as any}> | ||
| <MockedRouterContext router={router}>{children}</MockedRouterContext> | ||
| </MockedServerContext> | ||
| ); | ||
| }; | ||
|
|
||
| describe('useGoToRoom', () => { | ||
| it('should not navigate if the room is not found', async () => { | ||
| const navigate = jest.fn(); | ||
| const { result } = renderHook(() => useGoToRoom(), { wrapper: getWrapper(undefined, { navigate }) }); | ||
|
|
||
| await result.current('room-id'); | ||
|
|
||
| expect(navigate).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('should build the route by name for channels (c) and navigate to it', async () => { | ||
| const navigate = jest.fn(); | ||
| const getRoomRoute = jest.fn().mockReturnValue({ path: '/channel/some-channel' }); | ||
| const { result } = renderHook(() => useGoToRoom(), { | ||
| wrapper: getWrapper({ _id: 'room-id', t: 'c', name: 'some-channel' }, { navigate, getRoomRoute }), | ||
| }); | ||
|
|
||
| await result.current('room-id'); | ||
|
|
||
| await waitFor(() => expect(getRoomRoute).toHaveBeenCalledWith('c', { name: 'some-channel' })); | ||
| expect(navigate).toHaveBeenCalledWith({ pathname: '/channel/some-channel' }); | ||
| }); | ||
|
|
||
| it('should build the route by name for private groups (p) and navigate to it', async () => { | ||
| const navigate = jest.fn(); | ||
| const getRoomRoute = jest.fn().mockReturnValue({ path: '/group/some-group' }); | ||
| const { result } = renderHook(() => useGoToRoom(), { | ||
| wrapper: getWrapper({ _id: 'room-id', t: 'p', name: 'some-group' }, { navigate, getRoomRoute }), | ||
| }); | ||
|
|
||
| await result.current('room-id'); | ||
|
|
||
| await waitFor(() => expect(getRoomRoute).toHaveBeenCalledWith('p', { name: 'some-group' })); | ||
| expect(navigate).toHaveBeenCalledWith({ pathname: '/group/some-group' }); | ||
| }); | ||
|
|
||
| it('should build the route by rid for direct messages (d) and navigate to it', async () => { | ||
| const navigate = jest.fn(); | ||
| const getRoomRoute = jest.fn().mockReturnValue({ path: '/direct/room-id' }); | ||
| const { result } = renderHook(() => useGoToRoom(), { | ||
| wrapper: getWrapper({ _id: 'room-id', t: 'd', name: 'some-user' }, { navigate, getRoomRoute }), | ||
| }); | ||
|
|
||
| await result.current('room-id'); | ||
|
|
||
| await waitFor(() => expect(getRoomRoute).toHaveBeenCalledWith('d', { rid: 'room-id' })); | ||
| expect(navigate).toHaveBeenCalledWith({ pathname: '/direct/room-id' }); | ||
| }); | ||
| }); |
8 changes: 3 additions & 5 deletions
8
...ages/ui-contexts/src/hooks/useGoToRoom.ts → ...VideoConferenceBlock/hooks/useGoToRoom.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import type { IRoom, RoomType } from '@rocket.chat/core-typings'; | ||
| import { useRouter } from '@rocket.chat/ui-contexts'; | ||
| import { useCallback } from 'react'; | ||
|
|
||
| type RoomRouteData = { | ||
| rid: IRoom['_id']; | ||
| t: RoomType; | ||
| name?: IRoom['name']; | ||
| }; | ||
|
|
||
| /** | ||
| * Returns a function to navigate to a room using existing room data. | ||
| * Unlike `useGoToRoom`, this doesn't make an API call - use it when you already have the room data. | ||
| */ | ||
| export const useRoomRoute = ({ replace = false }: { replace?: boolean } = {}): ((room: RoomRouteData) => void) => { | ||
| const router = useRouter(); | ||
|
|
||
| return useCallback( | ||
| (room: RoomRouteData) => { | ||
| const { t, name, rid } = room; | ||
| const { path } = router.getRoomRoute(t, ['c', 'p'].includes(t) ? { name } : { rid }); | ||
|
|
||
| router.navigate( | ||
| { | ||
| pathname: path, | ||
| }, | ||
| { replace }, | ||
| ); | ||
| }, | ||
| [router, replace], | ||
| ); | ||
| }; | ||
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.
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.