WIP Feature : categoriesSelectList & Fix: Items

This commit is contained in:
elforjani3
2020-10-21 19:22:04 +02:00
parent ab4ec24619
commit 0e342ca02e
6 changed files with 80 additions and 56 deletions

View File

@@ -0,0 +1,49 @@
import React, { useCallback } from 'react';
import { FormattedMessage as T } from 'react-intl';
import { ListSelect } from 'components';
import { MenuItem } from '@blueprintjs/core';
export default function CategoriesSelectList({
categoriesList,
selecetedCategoryId,
defaultSelectText = <T id={'select_category'} />,
onCategorySelected,
...restProps
}) {
// Filter Items Category
const filterItemCategory = (query, item, _index, exactMatch) => {
const normalizedTitle = item.name.toLowerCase();
const normalizedQuery = query.toLowerCase();
if (exactMatch) {
return normalizedTitle === normalizedQuery;
} else {
return `${item.code} ${normalizedTitle}`.indexOf(normalizedQuery) >= 0;
}
};
const handleItemCategorySelected = useCallback(
(ItemCategory) => onCategorySelected && onCategorySelected(ItemCategory),
[],
);
const categoryItem = useCallback(
(item, { handleClick }) => (
<MenuItem key={item.id} text={item.name} onClick={handleClick} />
),
[],
);
return (
<ListSelect
items={categoriesList}
selectedItemProp={'id'}
selectedItem={selecetedCategoryId}
labelProp={'name'}
defaultText={defaultSelectText}
onItemSelect={handleItemCategorySelected}
itemPredicate={filterItemCategory}
itemRenderer={categoryItem}
{...restProps}
/>
);
}

View File

@@ -25,6 +25,8 @@ import Dialog from './Dialog/Dialog';
import DialogContent from './Dialog/DialogContent';
import DialogSuspense from './Dialog/DialogSuspense';
import InputPrependButton from './Forms/InputPrependButton';
import CategoriesSelectList from './CategoriesSelectList';
const Hint = FieldHint;
export {
@@ -55,5 +57,6 @@ export {
Dialog,
DialogContent,
DialogSuspense,
InputPrependButton
};
InputPrependButton,
CategoriesSelectList
};