From 75d717055e1b6aa063f85d83a3773bfec09fdec1 Mon Sep 17 00:00:00 2001 From: Boris Serdiuk Date: Tue, 26 Sep 2023 11:53:14 +0200 Subject: [PATCH] refactor: Remove unused code from splitItems utility (#1580) --- .../drawer/__tests__/drawers-helpers.test.ts | 7 ------- src/app-layout/drawer/drawers-helpers.ts | 14 ++++---------- src/app-layout/mobile-toolbar/index.tsx | 2 +- src/app-layout/visual-refresh/drawers.tsx | 2 +- 4 files changed, 6 insertions(+), 19 deletions(-) diff --git a/src/app-layout/drawer/__tests__/drawers-helpers.test.ts b/src/app-layout/drawer/__tests__/drawers-helpers.test.ts index ec83684b77..f40386d012 100644 --- a/src/app-layout/drawer/__tests__/drawers-helpers.test.ts +++ b/src/app-layout/drawer/__tests__/drawers-helpers.test.ts @@ -41,10 +41,3 @@ test('moves single overflow item into visible items', () => { overflowItems: [], }); }); - -test('when mobile and items length is 3, adds one to split index', () => { - expect(splitItems([{ id: '1' }, { id: '2' }, { id: '3' }], 2, undefined, true)).toEqual({ - visibleItems: [{ id: '1' }, { id: '2' }, { id: '3' }], - overflowItems: [], - }); -}); diff --git a/src/app-layout/drawer/drawers-helpers.ts b/src/app-layout/drawer/drawers-helpers.ts index 45a178eb8b..1fc7dc5857 100644 --- a/src/app-layout/drawer/drawers-helpers.ts +++ b/src/app-layout/drawer/drawers-helpers.ts @@ -4,20 +4,14 @@ export function splitItems( maybeItems: Array | undefined, splitIndex: number, - activeId: string | null | undefined, - isMobile = false + activeId: string | undefined ) { const items = maybeItems ?? []; - let visibleItems = items.slice(0, splitIndex); - let overflowItems = items.slice(splitIndex, items.length); + const visibleItems = items.slice(0, splitIndex); + const overflowItems = items.slice(splitIndex); if (overflowItems.length === 1) { - visibleItems = items.slice(0, splitIndex + 1); - overflowItems = []; - } - - if (isMobile && items.length === 3) { - splitIndex = splitIndex + 1; + return { visibleItems: items, overflowItems: [] }; } if (activeId && overflowItems.length > 0 && visibleItems.length > 0) { diff --git a/src/app-layout/mobile-toolbar/index.tsx b/src/app-layout/mobile-toolbar/index.tsx index 53bdcb5215..024257fcfa 100644 --- a/src/app-layout/mobile-toolbar/index.tsx +++ b/src/app-layout/mobile-toolbar/index.tsx @@ -94,7 +94,7 @@ export function MobileToolbar({ } }, [anyPanelOpen]); - const { overflowItems, visibleItems } = splitItems(drawers?.items, 2, drawers?.activeDrawerId, true); + const { overflowItems, visibleItems } = splitItems(drawers?.items, 2, drawers?.activeDrawerId); return (