From 005cc26a10b89c34ac6a735bd00749a43d291456 Mon Sep 17 00:00:00 2001 From: Andrey Mikhadyuk Date: Mon, 13 Nov 2023 16:24:47 +0300 Subject: [PATCH 1/2] fix commons sorting --- .../components/ProjectsTree/hooks/useMenuItems.ts | 12 +++++++++++- .../FeedBreadcrumbsItem/FeedBreadcrumbsItem.tsx | 13 ++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/shared/layouts/CommonSidenavLayout/components/SidenavContent/components/ProjectsTree/hooks/useMenuItems.ts b/src/shared/layouts/CommonSidenavLayout/components/SidenavContent/components/ProjectsTree/hooks/useMenuItems.ts index 1eb5f92517..78add419af 100644 --- a/src/shared/layouts/CommonSidenavLayout/components/SidenavContent/components/ProjectsTree/hooks/useMenuItems.ts +++ b/src/shared/layouts/CommonSidenavLayout/components/SidenavContent/components/ProjectsTree/hooks/useMenuItems.ts @@ -24,12 +24,22 @@ export const useMenuItems = (options: Options): MenuItem[] => { onCommonClick(stateItem.commonId); }, })) - .sort((item) => (item.id === activeStateItemId ? -1 : 1)) + .sort((prevItem, nextItem) => { + if (prevItem.id === activeStateItemId) { + return -1; + } + if (nextItem.id === activeStateItemId) { + return 1; + } + + return 0; + }) .concat({ id: CREATE_COMMON_ITEM_ID, text: "Create a common", onClick: onCommonCreationClick, }); + console.log(items.map((item) => item.text)); return items; }; diff --git a/src/shared/layouts/MultipleSpacesLayout/components/Header/components/Breadcrumbs/components/FeedItemBreadcrumbs/components/FeedBreadcrumbsItem/FeedBreadcrumbsItem.tsx b/src/shared/layouts/MultipleSpacesLayout/components/Header/components/Breadcrumbs/components/FeedItemBreadcrumbs/components/FeedBreadcrumbsItem/FeedBreadcrumbsItem.tsx index 50b81a54e4..e28802c99f 100644 --- a/src/shared/layouts/MultipleSpacesLayout/components/Header/components/Breadcrumbs/components/FeedItemBreadcrumbs/components/FeedBreadcrumbsItem/FeedBreadcrumbsItem.tsx +++ b/src/shared/layouts/MultipleSpacesLayout/components/Header/components/Breadcrumbs/components/FeedItemBreadcrumbs/components/FeedBreadcrumbsItem/FeedBreadcrumbsItem.tsx @@ -52,9 +52,16 @@ const FeedBreadcrumbsItem: FC = (props) => { () => baseItems.length === 0 ? [activeItem] - : [...baseItems].sort((prevItem) => - prevItem.commonId === activeItem.commonId ? -1 : 1, - ), + : [...baseItems].sort((prevItem, nextItem) => { + if (prevItem.commonId === activeItem.commonId) { + return -1; + } + if (nextItem.commonId === activeItem.commonId) { + return 1; + } + + return 0; + }), [baseItems, activeItem], ); From 0d24349de0943d68611b68b46177f63740dbc23d Mon Sep 17 00:00:00 2001 From: Andrey Mikhadyuk Date: Mon, 13 Nov 2023 19:46:59 +0300 Subject: [PATCH 2/2] remove unnecessary log --- .../SidenavContent/components/ProjectsTree/hooks/useMenuItems.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/shared/layouts/CommonSidenavLayout/components/SidenavContent/components/ProjectsTree/hooks/useMenuItems.ts b/src/shared/layouts/CommonSidenavLayout/components/SidenavContent/components/ProjectsTree/hooks/useMenuItems.ts index 78add419af..da65bfff9e 100644 --- a/src/shared/layouts/CommonSidenavLayout/components/SidenavContent/components/ProjectsTree/hooks/useMenuItems.ts +++ b/src/shared/layouts/CommonSidenavLayout/components/SidenavContent/components/ProjectsTree/hooks/useMenuItems.ts @@ -39,7 +39,6 @@ export const useMenuItems = (options: Options): MenuItem[] => { text: "Create a common", onClick: onCommonCreationClick, }); - console.log(items.map((item) => item.text)); return items; };