mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
WIP Feature : categoriesSelectList & Fix: Items
This commit is contained in:
49
client/src/components/CategoriesSelectList.js
Normal file
49
client/src/components/CategoriesSelectList.js
Normal 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}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -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
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user