feat(balance sheet): add branch multi select.

This commit is contained in:
elforjani13
2022-02-16 18:07:04 +02:00
parent 3b642540f1
commit e9933031ae
7 changed files with 40 additions and 25 deletions

View File

@@ -0,0 +1,65 @@
import React from 'react';
import { MenuItem } from '@blueprintjs/core';
import { FMultiSelect } from '../Forms';
/**
*
* @param {*} query
* @param {*} branch
* @param {*} _index
* @param {*} exactMatch
* @returns
*/
const branchItemPredicate = (query, branch, _index, exactMatch) => {
const normalizedTitle = branch.name.toLowerCase();
const normalizedQuery = query.toLowerCase();
if (exactMatch) {
return normalizedTitle === normalizedQuery;
} else {
return `${branch.code}. ${normalizedTitle}`.indexOf(normalizedQuery) >= 0;
}
};
/**
*
* @param {*} branch
* @param {*} param1
* @returns
*/
const branchItemRenderer = (
branch,
{ handleClick, modifiers, query },
{ isSelected },
) => {
// const text = `${branch.name}.${isSelected ? 'selected' : 'not-selected'}`;
return (
<MenuItem
active={modifiers.active}
disabled={modifiers.disabled}
icon={isSelected ? 'tick' : 'blank'}
text={branch.name.toString()}
label={branch.name.toString()}
key={branch.id}
onClick={handleClick}
/>
);
};
const branchSelectProps = {
itemPredicate: branchItemPredicate,
itemRenderer: branchItemRenderer,
valueAccessor: (item) => item.id,
labelAccessor: (item) => item.label,
tagRenderer: (item) => item.name,
};
/**
* branches mulit select.
* @param {*} param0
* @returns
*/
export function BranchMultiSelect({ branches, ...rest }) {
return <FMultiSelect items={branches} {...branchSelectProps} {...rest} />;
}

View File

@@ -1 +1,2 @@
export * from './BranchSelect';
export * from './BranchSelect';
export * from './BranchMultiSelect'