This repository has been archived by the owner on Oct 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move always expanded items to overflow
- Loading branch information
1 parent
4fb0517
commit fbc24ca
Showing
4 changed files
with
143 additions
and
30 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
packages/sn-filter-pane/src/components/ListboxGrid/distribute-always-expanded.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// const flatten = (arr = []) => arr.reduce((prev, cur) => prev.concat(cur)); | ||
|
||
import { IListboxResource } from '../../hooks/types'; | ||
import { IColumn } from './interfaces'; | ||
|
||
export function getSadItem(column: IColumn) { | ||
const sadItem = column.items?.filter((item) => item.alwaysExpanded && !item.expand)[0]; | ||
return sadItem; | ||
} | ||
|
||
export function moveOverflowItemToColumn(columnItems: IListboxResource[], overflowing: IListboxResource[]) { | ||
const newOverflowing = [...overflowing]; | ||
const newColumnItems = [...columnItems]; | ||
let changed = 0; | ||
const overflowIndex = newOverflowing.findIndex((itm: IListboxResource) => !itm.alwaysExpanded); | ||
if (overflowIndex > -1) { | ||
const itemToColumn = newOverflowing.splice(overflowIndex, 1)[0]; | ||
newColumnItems.splice(0, 0, itemToColumn); | ||
changed += 1; | ||
} | ||
return { | ||
changed, | ||
columnItems: newColumnItems as IListboxResource[], | ||
overflowing: newOverflowing as IListboxResource[], | ||
}; | ||
} | ||
|
||
export function moveSadItemToOverflow(sadItem: IListboxResource, parentColumn: IColumn, overflowing: IListboxResource[]) { | ||
const sadItemIndex = parentColumn.items?.indexOf(sadItem) as number; | ||
if (sadItemIndex === -1) { | ||
return { | ||
changed: 0, | ||
parentColumnItems: parentColumn.items as IListboxResource[], | ||
overflowing: overflowing as IListboxResource[], | ||
}; | ||
} | ||
parentColumn.items?.splice(sadItemIndex, 1); // remove from parent column | ||
return { | ||
changed: 1, | ||
columnItems: parentColumn.items as IListboxResource[], | ||
overflowing: [...overflowing, { ...sadItem, expand: false }] as IListboxResource[], | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters