-
Notifications
You must be signed in to change notification settings - Fork 13.1k
regression: Select sidepanel filter when navigating to room #36808
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
6 commits
Select commit
Hold shift + click to select a range
c0c475b
fix: redirect to correct filter when opening room
dougfabris bee12b2
Merge branch 'release-7.10.0' into reg/redirectToFilter
ggazzo 32fa6bf
review
ggazzo 0b8e031
fix: if the room has team parent and has discussions, it doesnt get m…
ggazzo b278b93
refactor: integrate local storage for side panel filters and remove u…
ggazzo 76ff48e
fix: discussions from teams
dougfabris 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
23 changes: 0 additions & 23 deletions
23
apps/meteor/client/views/navigation/hooks/useSidePanelFilters.ts
This file was deleted.
Oops, something went wrong.
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 |
|---|---|---|
|
|
@@ -7,19 +7,26 @@ import { | |
| isPublicRoom, | ||
| isTeamRoom, | ||
| } from '@rocket.chat/core-typings'; | ||
| import type { ILivechatInquiryRecord } from '@rocket.chat/core-typings'; | ||
| import { useDebouncedValue } from '@rocket.chat/fuselage-hooks'; | ||
| import type { ILivechatInquiryRecord, IRoom } from '@rocket.chat/core-typings'; | ||
| import { useDebouncedValue, useEffectEvent } from '@rocket.chat/fuselage-hooks'; | ||
| import type { SubscriptionWithRoom, TranslationKey } from '@rocket.chat/ui-contexts'; | ||
| import { useSetting, useUserPreference, useUserSubscriptions } from '@rocket.chat/ui-contexts'; | ||
| import { useSetting, useUserPreference, useUserSubscriptions, useLayout } from '@rocket.chat/ui-contexts'; | ||
| import type { ReactNode } from 'react'; | ||
| import { useMemo } from 'react'; | ||
| import { useEffect, useMemo } from 'react'; | ||
|
|
||
| import { useOmnichannelEnabled } from '../../../hooks/omnichannel/useOmnichannelEnabled'; | ||
| import { useQueuedInquiries } from '../../../hooks/omnichannel/useQueuedInquiries'; | ||
| import { useSortQueryOptions } from '../../../hooks/useSortQueryOptions'; | ||
| import { RoomManager } from '../../../lib/RoomManager'; | ||
| import { Rooms } from '../../../stores'; | ||
| import type { GroupedUnreadInfoData, AllGroupsKeys, AllGroupsKeysWithUnread } from '../contexts/RoomsNavigationContext'; | ||
| import { RoomsNavigationContext, getEmptyUnreadInfo, isUnreadSubscription } from '../contexts/RoomsNavigationContext'; | ||
| import { useSidePanelFilters } from '../hooks/useSidePanelFilters'; | ||
| import { | ||
| RoomsNavigationContext, | ||
| getEmptyUnreadInfo, | ||
| getFilterKey, | ||
| isUnreadSubscription, | ||
| useSidePanelFilter, | ||
| } from '../contexts/RoomsNavigationContext'; | ||
| import { useSidePanelParentRid } from '../hooks/useSidePanelParentRid'; | ||
|
|
||
| const query = { open: { $ne: false } }; | ||
|
|
@@ -156,11 +163,63 @@ const useRoomsGroups = (): [GroupMap, UnreadGroupDataMap] => { | |
| }; | ||
|
|
||
| const RoomsNavigationContextProvider = ({ children }: { children: ReactNode }) => { | ||
| const { currentFilter, setFilter } = useSidePanelFilters(); | ||
| const { parentRid } = useSidePanelParentRid(); | ||
| const { | ||
| sidePanel: { openSidePanel }, | ||
| } = useLayout(); | ||
| const { setParentRoom, parentRid } = useSidePanelParentRid(); | ||
|
|
||
| const [currentFilter, unread, , setCurrentFilter] = useSidePanelFilter(); | ||
|
|
||
| const setFilter = useEffectEvent((filter: AllGroupsKeys, unread: boolean, parentRid?: IRoom['_id']) => { | ||
| openSidePanel(); | ||
| setCurrentFilter(getFilterKey(filter, unread)); | ||
| setParentRoom(filter, parentRid); | ||
| }); | ||
|
|
||
| const [groups, unreadGroupData] = useRoomsGroups(); | ||
|
|
||
| const handleRoomOpened = useEffectEvent((rid: string) => { | ||
| const room = Rooms.use.getState().find((r) => r._id === rid); | ||
|
|
||
| if (!room) { | ||
| return; | ||
| } | ||
|
|
||
| if (isTeamRoom(room)) { | ||
| setFilter('teams', unread, rid); | ||
| return; | ||
| } | ||
|
|
||
| if (isDirectMessageRoom(room)) { | ||
| setFilter('directMessages', unread, rid); | ||
| return; | ||
| } | ||
|
|
||
| if (room.teamId && currentFilter === 'teams') { | ||
| const teamRid = Rooms.use.getState().find((r) => Boolean(r.teamId === room.teamId && r.teamMain))?._id; | ||
|
||
|
|
||
| /** | ||
| * if the room is the parent rid is still the same, don't change the filter | ||
| * the filter decision is going to be done by `useRedirectToFilter` when the item is clicked | ||
| **/ | ||
| if (parentRid === teamRid) { | ||
| return; | ||
| } | ||
| setFilter('teams', unread, teamRid); | ||
| return; | ||
| } | ||
|
|
||
| if (room.prid) { | ||
| const parentRoom = Rooms.use.getState().find((r) => Boolean(r._id === room.prid)); | ||
| setFilter(parentRoom?.teamMain ? 'teams' : 'channels', unread, parentRoom?._id); | ||
| return; | ||
| } | ||
|
|
||
| setFilter('channels', false, rid); | ||
| }); | ||
|
|
||
| useEffect(() => RoomManager.on('opened', handleRoomOpened), [handleRoomOpened]); | ||
|
|
||
| const contextValue = useMemo(() => { | ||
| return { | ||
| currentFilter, | ||
|
|
||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fallback logic
room.prid || roomIdcould be confusing. Consider adding a comment explaining when room.prid would be undefined and why roomId is the appropriate fallback.