Skip to content

Commit

Permalink
fix: sidepanel not replicating sidebar sort preference (#33986)
Browse files Browse the repository at this point in the history
  • Loading branch information
juliajforesti authored Nov 19, 2024
1 parent c7bca10 commit 8688bcd
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/pink-dodos-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Fixes sidepanel not replicating sidebar sort preference
28 changes: 28 additions & 0 deletions apps/meteor/client/hooks/useSortQueryOptions.spec.tsx
Original file line number Diff line number Diff line change
@@ -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);
});
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/client/sidebarv2/hooks/useRoomList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } };

Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<IRoom> = {
$or: [
Expand All @@ -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,
Expand Down

0 comments on commit 8688bcd

Please sign in to comment.