MSP-3107 add utils for column items
This commit is contained in:
1 parent
bcf776d07e
commit
bef6fa19e3
2 files changed
+42
No files matched your search
@@ -0,0 +1,31 @@
|
||||
import { NavigateFunction, SetURLSearchParams } from 'react-router-dom'
|
||||
|
||||
export const setSelectedItemId = (
|
||||
path: string,
|
||||
id: string,
|
||||
searchParams: string,
|
||||
navigate: NavigateFunction
|
||||
): void => {
|
||||
navigate(
|
||||
{
|
||||
pathname: `${path}/${id}`,
|
||||
search: searchParams
|
||||
},
|
||||
{ replace: true }
|
||||
)
|
||||
}
|
||||
|
||||
export const setSearchValue = (
|
||||
value: string,
|
||||
setSearchParams: SetURLSearchParams,
|
||||
prefix: string = 'search'
|
||||
) => {
|
||||
setSearchParams((prev) => {
|
||||
if (!value) {
|
||||
prev.delete(prefix)
|
||||
} else {
|
||||
prev.set(prefix, value)
|
||||
}
|
||||
return prev
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { ColumnItem } from 'isp-ui-kit/dist/Layout/Column/column.type'
|
||||
|
||||
export const filterFirstColumnItems = <T extends NonNullable<unknown>>(
|
||||
listItems: ColumnItem<T>[],
|
||||
searchValue: string
|
||||
): ColumnItem<T>[] =>
|
||||
listItems
|
||||
? listItems.filter((el) =>
|
||||
el.name.toLowerCase().trim().includes(searchValue.toLowerCase().trim())
|
||||
)
|
||||
: []
|
||||
Reference in new issue
Block a user