mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-23 00:00:31 +00:00
73 lines
1.6 KiB
JavaScript
73 lines
1.6 KiB
JavaScript
import React from 'react';
|
|
import intl from 'react-intl-universal';
|
|
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 },
|
|
) => {
|
|
return (
|
|
<MenuItem
|
|
active={modifiers.active}
|
|
disabled={modifiers.disabled}
|
|
icon={isSelected ? 'tick' : 'blank'}
|
|
text={branch.name}
|
|
label={branch.code}
|
|
key={branch.id}
|
|
onClick={handleClick}
|
|
/>
|
|
);
|
|
};
|
|
|
|
const branchSelectProps = {
|
|
itemPredicate: branchItemPredicate,
|
|
itemRenderer: branchItemRenderer,
|
|
valueAccessor: (item) => item.id,
|
|
labelAccessor: (item) => item.code,
|
|
tagRenderer: (item) => item.name,
|
|
};
|
|
|
|
/**
|
|
* branches mulit select.
|
|
* @param {*} param0
|
|
* @returns {JSX.Element}
|
|
*/
|
|
export function BranchMultiSelect({ branches, ...rest }) {
|
|
return (
|
|
<FMultiSelect
|
|
items={branches}
|
|
placeholder={intl.get('branches_multi_select.placeholder')}
|
|
popoverProps={{ minimal: true }}
|
|
{...branchSelectProps}
|
|
{...rest}
|
|
/>
|
|
);
|
|
}
|