Skip to content

Commit 5b80852

Browse files
committed
refactor: rename ISidebarCustomCategory to ISidebarCategory and update related code
- Updated type imports and usages from ISidebarCustomCategory to ISidebarCategory across multiple files. - Adjusted user preferences and API endpoints to reflect the new category structure. - Removed unused hooks and functions related to custom categories. - Modified tests to align with the new category naming conventions.
1 parent d12571b commit 5b80852

22 files changed

Lines changed: 158 additions & 245 deletions

apps/meteor/client/sidebar/RoomList/RoomList.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import RoomListRow from './RoomListRow';
1111
import RoomListRowWrapper from './RoomListRowWrapper';
1212
import RoomListWrapper from './RoomListWrapper';
1313
import { useOpenedRoom } from '../../lib/RoomManager';
14-
import { useAllGroupsOrder } from '../hooks/useAllGroupsOrder';
1514
import { useAvatarTemplate } from '../hooks/useAvatarTemplate';
1615
import { useCollapsedGroups } from '../hooks/useCollapsedGroups';
16+
import { useCustomCategories } from '../hooks/useCustomCategories';
1717
import { usePreventDefault } from '../hooks/usePreventDefault';
1818
import { useRoomList } from '../hooks/useRoomList';
1919
import { useShortcutOpenMenu } from '../hooks/useShortcutOpenMenu';
@@ -26,7 +26,7 @@ const RoomList = () => {
2626

2727
const { collapsedGroups, handleClick, handleKeyDown } = useCollapsedGroups();
2828
const { groups, groupsCount, totalCount } = useRoomList({ collapsedGroups });
29-
const { move: moveGroup } = useAllGroupsOrder();
29+
const { move: moveGroup } = useCustomCategories();
3030
const avatarTemplate = useAvatarTemplate();
3131
const sideBarItemTemplate = useTemplateByViewMode();
3232
const { ref } = useResizeObserver<HTMLElement>({ debounceDelay: 100 });

apps/meteor/client/sidebar/RoomMenu.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ const enterpriseCategoryRenderOptions = {
112112
.withJohnDoe()
113113
.withQueryClient(buildEnterpriseQueryClient())
114114
.withSubscription(createFakeSubscription({ rid: 'roomId', f: false, t: 'c' }))
115-
.withUserPreference('sidebarCustomCategories', [{ _id: 'cat-design', name: 'Design', rooms: ['roomId'], showUnreads: true }])
115+
.withUserPreference('sidebarCategories', [{ _id: 'cat-design', name: 'Design', showUnreads: true }])
116116
.build(),
117117
};
118118

apps/meteor/client/sidebar/categories/CategoryMenu.tsx

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ISidebarCustomCategory } from '@rocket.chat/core-typings';
1+
import type { ISidebarCategory } from '@rocket.chat/core-typings';
22
import { Menu, MenuItem, MenuItemContent, MenuItemIcon, MenuSection, MenuSubmenuTrigger, ToggleSwitch } from '@rocket.chat/fuselage';
33
import { useToggle } from '@rocket.chat/fuselage-hooks';
44
import type { GenericMenuItemProps } from '@rocket.chat/ui-client';
@@ -9,11 +9,9 @@ import { useTranslation } from 'react-i18next';
99
import { useCategoryModals } from './useCategoryModals';
1010
import { useCreateNewItems } from '../../navbar/NavBarPagesGroup/hooks/useCreateNewItems';
1111
import { useCustomCategories } from '../hooks/useCustomCategories';
12-
import { useKeepUnreadsOnTopGroups } from '../hooks/useKeepUnreadsOnTopGroups';
13-
import { useShowUnreadsGroups } from '../hooks/useShowUnreadsGroups';
1412

1513
type CategoryMenuProps = {
16-
category?: ISidebarCustomCategory;
14+
category?: ISidebarCategory;
1715
groupKey: string;
1816
showUnreads: boolean;
1917
keepUnreadsOnTop: boolean;
@@ -38,13 +36,7 @@ const CategoryMenu = ({
3836
const close = () => toggleOpen(false);
3937

4038
const { openManage, openDelete } = useCategoryModals();
41-
const {
42-
toggleShowUnreads: toggleCustomShowUnreads,
43-
toggleKeepUnreadsOnTop: toggleCustomKeepUnreadsOnTop,
44-
moveRoom,
45-
} = useCustomCategories();
46-
const { toggleShowUnreads: toggleSystemShowUnreads } = useShowUnreadsGroups();
47-
const { toggleKeepUnreadsOnTop: toggleSystemKeepUnreadsOnTop } = useKeepUnreadsOnTopGroups();
39+
const { toggleShowUnreads, toggleKeepUnreadsOnTop, moveRoom } = useCustomCategories();
4840
const sidebarShowUnread = useUserPreference<boolean>('sidebarShowUnread', false);
4941
const disableAlwaysDisplay = Boolean(sidebarShowUnread) && groupKey !== 'Unread';
5042

@@ -59,9 +51,8 @@ const CategoryMenu = ({
5951
const rawCreateItems = useCreateNewItems({ onCreateSuccess });
6052
const createItems = category ? rawCreateItems : [];
6153

62-
const handleToggleShowUnreads = () => (category ? toggleCustomShowUnreads(category._id) : toggleSystemShowUnreads(groupKey));
63-
const handleToggleKeepUnreadsOnTop = () =>
64-
category ? toggleCustomKeepUnreadsOnTop(category._id) : toggleSystemKeepUnreadsOnTop(groupKey);
54+
const handleToggleShowUnreads = () => toggleShowUnreads(category?._id ?? groupKey);
55+
const handleToggleKeepUnreadsOnTop = () => toggleKeepUnreadsOnTop(category?._id ?? groupKey);
6556

6657
const orderItems: GenericMenuItemProps[] = [
6758
{

apps/meteor/client/sidebar/categories/DeleteCategoryModal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ISidebarCustomCategory } from '@rocket.chat/core-typings';
1+
import type { ISidebarCategory } from '@rocket.chat/core-typings';
22
import { Box } from '@rocket.chat/fuselage';
33
import { GenericModal } from '@rocket.chat/ui-client';
44
import { useToastMessageDispatch } from '@rocket.chat/ui-contexts';
@@ -7,7 +7,7 @@ import { useTranslation } from 'react-i18next';
77
import { useCustomCategories } from '../hooks/useCustomCategories';
88

99
type DeleteCategoryModalProps = {
10-
category: ISidebarCustomCategory;
10+
category: ISidebarCategory;
1111
onClose: () => void;
1212
};
1313

apps/meteor/client/sidebar/categories/ManageCategoryModal.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ISidebarCustomCategory } from '@rocket.chat/core-typings';
1+
import type { ISidebarCategory } from '@rocket.chat/core-typings';
22
import { Box } from '@rocket.chat/fuselage';
33
import { Field, FieldError, FieldGroup, FieldLabel, FieldRow, TextInput } from '@rocket.chat/fuselage-forms';
44
import { GenericModal } from '@rocket.chat/ui-client';
@@ -13,7 +13,7 @@ import { MAX_CATEGORY_NAME_LENGTH, useCustomCategories } from '../hooks/useCusto
1313
const OPEN_QUERY = { open: { $ne: false } } as const;
1414

1515
type ManageCategoryModalProps = {
16-
category: ISidebarCustomCategory;
16+
category: ISidebarCategory;
1717
onClose: () => void;
1818
};
1919

@@ -22,11 +22,9 @@ const ManageCategoryModal = ({ category, onClose }: ManageCategoryModalProps) =>
2222
const dispatchToastMessage = useToastMessageDispatch();
2323
const { updateCategory, validateName } = useCustomCategories();
2424

25-
// Load the rooms currently assigned to this category from subscriptions.
2625
const categorySubscriptions = useUserSubscriptions(OPEN_QUERY, {});
2726
const initialRoomIds = useMemo(
2827
() => categorySubscriptions.filter((s) => s.category === category._id).map((s) => s.rid),
29-
// Intentionally computed once on mount — category._id is stable for a given modal instance.
3028
// eslint-disable-next-line react-hooks/exhaustive-deps
3129
[],
3230
);

apps/meteor/client/sidebar/categories/useCategoryModals.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ISidebarCustomCategory } from '@rocket.chat/core-typings';
1+
import type { ISidebarCategory } from '@rocket.chat/core-typings';
22
import { useSetModal } from '@rocket.chat/ui-contexts';
33
import { useMemo } from 'react';
44

@@ -30,8 +30,8 @@ export const useCategoryModals = () => {
3030

3131
return {
3232
openCreate: (room?: MovableRoom) => setModal(<CreateCategoryModal room={room} onClose={onClose} />),
33-
openManage: (category: ISidebarCustomCategory) => setModal(<ManageCategoryModal category={category} onClose={onClose} />),
34-
openDelete: (category: ISidebarCustomCategory) => setModal(<DeleteCategoryModal category={category} onClose={onClose} />),
33+
openManage: (category: ISidebarCategory) => setModal(<ManageCategoryModal category={category} onClose={onClose} />),
34+
openDelete: (category: ISidebarCategory) => setModal(<DeleteCategoryModal category={category} onClose={onClose} />),
3535
};
3636
}, [handleManageSubscription, setModal, shouldShowUpsell]);
3737
};

apps/meteor/client/sidebar/categories/useRoomCategoryItems.spec.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ const makeCategories = () =>
2020
categories: [catA, catB],
2121
moveRoom: jest.fn(),
2222
removeRoom: jest.fn(),
23-
getRoomCategory: jest.fn(() => undefined),
2423
validateName: jest.fn(),
2524
createCategory: jest.fn(),
2625
createCategoryAndMoveRoom: jest.fn(),

apps/meteor/client/sidebar/hooks/useAllGroupsOrder.ts

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)