Skip to content

Commit

Permalink
refactor: Remove unused code from splitItems utility (#1580)
Browse files Browse the repository at this point in the history
  • Loading branch information
just-boris authored Sep 26, 2023
1 parent 6544a4d commit 75d7170
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 19 deletions.
7 changes: 0 additions & 7 deletions src/app-layout/drawer/__tests__/drawers-helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
});
});
14 changes: 4 additions & 10 deletions src/app-layout/drawer/drawers-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,14 @@
export function splitItems<T extends { id: string }>(
maybeItems: Array<T> | 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) {
Expand Down
2 changes: 1 addition & 1 deletion src/app-layout/mobile-toolbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div
Expand Down
2 changes: 1 addition & 1 deletion src/app-layout/visual-refresh/drawers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ export function MobileTriggers() {

const splitIndex = 2;

const { visibleItems, overflowItems } = splitItems(drawers, splitIndex, activeDrawerId, true);
const { visibleItems, overflowItems } = splitItems(drawers, splitIndex, activeDrawerId);

function handleItemClick(itemId: string | undefined) {
if (itemId === TOOLS_DRAWER_ID) {
Expand Down

0 comments on commit 75d7170

Please sign in to comment.