2024-02-28 21:02:05 +03:00
|
|
|
import React, { type FC } from 'react';
|
2024-01-31 04:20:42 +03:00
|
|
|
import { groupBy } from 'lodash-es';
|
|
|
|
import Box from '@mui/material/Box';
|
|
|
|
import { getIndex } from './listHelper';
|
|
|
|
import ListGroupHeaderWrapper from './ListGroupHeaderWrapper';
|
|
|
|
import List from './List';
|
|
|
|
|
2024-03-03 01:31:35 +03:00
|
|
|
import type { ItemDto } from 'types/base/models/item-dto';
|
2024-01-31 04:20:42 +03:00
|
|
|
import type { ListOptions } from 'types/listOptions';
|
|
|
|
import '../listview.scss';
|
|
|
|
|
|
|
|
interface ListsProps {
|
|
|
|
items: ItemDto[];
|
|
|
|
listOptions?: ListOptions;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Lists: FC<ListsProps> = ({ items = [], listOptions = {} }) => {
|
|
|
|
const groupedData = groupBy(items, (item) => {
|
|
|
|
if (listOptions.showIndex) {
|
|
|
|
return getIndex(item, listOptions);
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
});
|
|
|
|
|
|
|
|
const renderListItem = (item: ItemDto, index: number) => {
|
|
|
|
return (
|
|
|
|
<List
|
|
|
|
// eslint-disable-next-line react/no-array-index-key
|
|
|
|
key={`${item.Id}-${index}`}
|
|
|
|
index={index}
|
|
|
|
item={item}
|
|
|
|
listOptions={listOptions}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{Object.entries(groupedData).map(
|
|
|
|
([itemGroupTitle, getItems], index) => (
|
|
|
|
// eslint-disable-next-line react/no-array-index-key
|
|
|
|
<Box key={index}>
|
|
|
|
{itemGroupTitle && (
|
|
|
|
<ListGroupHeaderWrapper index={index}>
|
2024-02-28 21:18:37 +03:00
|
|
|
{itemGroupTitle}
|
2024-01-31 04:20:42 +03:00
|
|
|
</ListGroupHeaderWrapper>
|
|
|
|
)}
|
|
|
|
{getItems.map((item) => renderListItem(item, index))}
|
|
|
|
</Box>
|
|
|
|
)
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Lists;
|