diff --git a/.changeset/pink-dodos-greet.md b/.changeset/pink-dodos-greet.md new file mode 100644 index 000000000000..f122a2e72fc7 --- /dev/null +++ b/.changeset/pink-dodos-greet.md @@ -0,0 +1,5 @@ +--- +'@rocket.chat/meteor': patch +--- + +Fixes sidepanel not replicating sidebar sort preference diff --git a/apps/meteor/client/hooks/useSortQueryOptions.spec.tsx b/apps/meteor/client/hooks/useSortQueryOptions.spec.tsx new file mode 100644 index 000000000000..63be719bf982 --- /dev/null +++ b/apps/meteor/client/hooks/useSortQueryOptions.spec.tsx @@ -0,0 +1,28 @@ +import { mockAppRoot } from '@rocket.chat/mock-providers'; +import { renderHook } from '@testing-library/react'; + +import { useSortQueryOptions } from './useSortQueryOptions'; + +it("should return query option to sort by last message when user preference is 'activity'", () => { + const { result } = renderHook(() => useSortQueryOptions(), { + legacyRoot: true, + wrapper: mockAppRoot().withUserPreference('sidebarSortby', 'activity').build(), + }); + expect(result.current.sort).toHaveProperty('lm', -1); +}); + +it("should return query option to sort by name when user preference is 'name'", () => { + const { result } = renderHook(() => useSortQueryOptions(), { + legacyRoot: true, + wrapper: mockAppRoot().withUserPreference('sidebarSortby', 'name').build(), + }); + expect(result.current.sort).toHaveProperty('lowerCaseName', 1); +}); + +it("should return query option to sort by fname when user preference is 'name' and showRealName is true", () => { + const { result } = renderHook(() => useSortQueryOptions(), { + legacyRoot: true, + wrapper: mockAppRoot().withUserPreference('sidebarSortby', 'name').withSetting('UI_Use_Real_Name', true).build(), + }); + expect(result.current.sort).toHaveProperty('lowerCaseFName', 1); +}); diff --git a/apps/meteor/client/sidebarv2/hooks/useQueryOptions.ts b/apps/meteor/client/hooks/useSortQueryOptions.ts similarity index 94% rename from apps/meteor/client/sidebarv2/hooks/useQueryOptions.ts rename to apps/meteor/client/hooks/useSortQueryOptions.ts index 55fd137759d1..e65c6f9411f9 100644 --- a/apps/meteor/client/sidebarv2/hooks/useQueryOptions.ts +++ b/apps/meteor/client/hooks/useSortQueryOptions.ts @@ -1,7 +1,7 @@ import { useUserPreference, useSetting } from '@rocket.chat/ui-contexts'; import { useMemo } from 'react'; -export const useQueryOptions = (): { +export const useSortQueryOptions = (): { sort: | { lm?: -1 | 1 | undefined; diff --git a/apps/meteor/client/sidebarv2/hooks/useRoomList.ts b/apps/meteor/client/sidebarv2/hooks/useRoomList.ts index b33fafbea803..921d956147ba 100644 --- a/apps/meteor/client/sidebarv2/hooks/useRoomList.ts +++ b/apps/meteor/client/sidebarv2/hooks/useRoomList.ts @@ -4,10 +4,10 @@ import type { SubscriptionWithRoom, TranslationKey } from '@rocket.chat/ui-conte import { useUserPreference, useUserSubscriptions, useSetting } from '@rocket.chat/ui-contexts'; import { useMemo } from 'react'; -import { useQueryOptions } from './useQueryOptions'; import { useVideoConfIncomingCalls } from '../../contexts/VideoConfContext'; import { useOmnichannelEnabled } from '../../hooks/omnichannel/useOmnichannelEnabled'; import { useQueuedInquiries } from '../../hooks/omnichannel/useQueuedInquiries'; +import { useSortQueryOptions } from '../../hooks/useSortQueryOptions'; const query = { open: { $ne: false } }; @@ -44,7 +44,7 @@ export const useRoomList = ({ collapsedGroups }: { collapsedGroups?: string[] }) const isDiscussionEnabled = useSetting('Discussion_enabled'); const sidebarShowUnread = useUserPreference('sidebarShowUnread'); - const options = useQueryOptions(); + const options = useSortQueryOptions(); const rooms = useUserSubscriptions(query, options); diff --git a/apps/meteor/client/views/room/Sidepanel/hooks/useTeamslistChildren.ts b/apps/meteor/client/views/room/Sidepanel/hooks/useTeamslistChildren.ts index 530a3a7658c6..e186a3b0a806 100644 --- a/apps/meteor/client/views/room/Sidepanel/hooks/useTeamslistChildren.ts +++ b/apps/meteor/client/views/room/Sidepanel/hooks/useTeamslistChildren.ts @@ -4,12 +4,15 @@ import type { Mongo } from 'meteor/mongo'; import { useEffect, useMemo } from 'react'; import { Rooms } from '../../../../../app/models/client'; +import { useSortQueryOptions } from '../../../../hooks/useSortQueryOptions'; export const useTeamsListChildrenUpdate = ( parentRid: string, teamId?: string | null, sidepanelItems?: 'channels' | 'discussions' | null, ) => { + const options = useSortQueryOptions(); + const query = useMemo(() => { const query: Mongo.Selector = { $or: [ @@ -34,11 +37,8 @@ export const useTeamsListChildrenUpdate = ( }, [parentRid, teamId, sidepanelItems]); const result = useQuery({ - queryKey: ['sidepanel', 'list', parentRid, sidepanelItems], - queryFn: () => - Rooms.find(query, { - sort: { lm: -1 }, - }).fetch(), + queryKey: ['sidepanel', 'list', parentRid, sidepanelItems, options], + queryFn: () => Rooms.find(query, options).fetch(), enabled: sidepanelItems !== null && teamId !== null, refetchInterval: 5 * 60 * 1000, keepPreviousData: true,