mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 07:10:33 +00:00
feat(balance): add FMultiSelect.
This commit is contained in:
66
src/components/FMultiSelect/BranchesMultiSelect.js
Normal file
66
src/components/FMultiSelect/BranchesMultiSelect.js
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { MenuItem } from '@blueprintjs/core';
|
||||||
|
import { MultiSelect as FMultiSelect } from 'blueprint-formik';
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @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.name}. ${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={modifiers.selected ? 'tick' : 'blank'}
|
||||||
|
label={branch.name.toString()}
|
||||||
|
key={branch.id}
|
||||||
|
onClick={handleClick}
|
||||||
|
text={text}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const branchSelectProps = {
|
||||||
|
itemPredicate: branchItemPredicate,
|
||||||
|
itemRenderer: branchItemRenderer,
|
||||||
|
valueAccessor: 'id',
|
||||||
|
labelAccessor: 'name',
|
||||||
|
tagRenderer: 'name',
|
||||||
|
};
|
||||||
|
|
||||||
|
export function BranchesMultiSelect({ branches, ...rest }) {
|
||||||
|
return (
|
||||||
|
<FMultiSelect
|
||||||
|
items={branches}
|
||||||
|
{...branchSelectProps}
|
||||||
|
{...rest}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
1
src/components/FMultiSelect/index.js
Normal file
1
src/components/FMultiSelect/index.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export * from './BranchesMultiSelect';
|
||||||
@@ -101,6 +101,7 @@ export * from './FeatureGuard';
|
|||||||
export * from './ExchangeRate';
|
export * from './ExchangeRate';
|
||||||
export * from './Branches';
|
export * from './Branches';
|
||||||
export * from './Warehouses';
|
export * from './Warehouses';
|
||||||
|
export * from './FMultiSelect'
|
||||||
|
|
||||||
const Hint = FieldHint;
|
const Hint = FieldHint;
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import withBalanceSheetActions from './withBalanceSheetActions';
|
|||||||
|
|
||||||
import BalanceSheetHeaderGeneralPanal from './BalanceSheetHeaderGeneralPanal';
|
import BalanceSheetHeaderGeneralPanal from './BalanceSheetHeaderGeneralPanal';
|
||||||
import BalanceSheetHeaderComparisonPanal from './BalanceSheetHeaderComparisonPanal';
|
import BalanceSheetHeaderComparisonPanal from './BalanceSheetHeaderComparisonPanal';
|
||||||
|
import BalanceSheetHeaderDimensionsPanel from './BalanceSheetHeaderDimensionsPanel';
|
||||||
import FinancialStatementHeader from '../../FinancialStatements/FinancialStatementHeader';
|
import FinancialStatementHeader from '../../FinancialStatements/FinancialStatementHeader';
|
||||||
|
|
||||||
import { compose, transformToForm } from 'utils';
|
import { compose, transformToForm } from 'utils';
|
||||||
@@ -40,6 +41,7 @@ function BalanceSheetHeader({
|
|||||||
...pageFilter,
|
...pageFilter,
|
||||||
fromDate: moment(pageFilter.fromDate).toDate(),
|
fromDate: moment(pageFilter.fromDate).toDate(),
|
||||||
toDate: moment(pageFilter.toDate).toDate(),
|
toDate: moment(pageFilter.toDate).toDate(),
|
||||||
|
branches_id: [],
|
||||||
},
|
},
|
||||||
defaultValues,
|
defaultValues,
|
||||||
);
|
);
|
||||||
@@ -85,6 +87,11 @@ function BalanceSheetHeader({
|
|||||||
title={<T id={'balance_sheet.comparisons'} />}
|
title={<T id={'balance_sheet.comparisons'} />}
|
||||||
panel={<BalanceSheetHeaderComparisonPanal />}
|
panel={<BalanceSheetHeaderComparisonPanal />}
|
||||||
/>
|
/>
|
||||||
|
<Tab
|
||||||
|
id="dimensions"
|
||||||
|
title={<T id={'dimensions'} />}
|
||||||
|
panel={<BalanceSheetHeaderDimensionsPanel />}
|
||||||
|
/>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
|
|
||||||
<div class="financial-header-drawer__footer">
|
<div class="financial-header-drawer__footer">
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Button } from '@blueprintjs/core';
|
||||||
|
import { BranchesMultiSelect } from 'components';
|
||||||
|
|
||||||
|
import { useBranches } from 'hooks/query';
|
||||||
|
|
||||||
|
function BalanceSheetHeaderDimensionsPanel() {
|
||||||
|
// Fetches the branches list.
|
||||||
|
const {
|
||||||
|
isLoading: isBranchesLoading,
|
||||||
|
isFetching: isBranchesFetching,
|
||||||
|
data: branches,
|
||||||
|
} = useBranches();
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<BranchesMultiSelect
|
||||||
|
name={'branches_id'}
|
||||||
|
branches={branches}
|
||||||
|
input={BranchMulitSelectButton}
|
||||||
|
// onItemSelect={}
|
||||||
|
popoverProps={{ minimal: true }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default BalanceSheetHeaderDimensionsPanel;
|
||||||
|
|
||||||
|
function BranchMulitSelectButton() {
|
||||||
|
return <Button text={'Button'} minimal={true} />;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user