mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
fix(webapp): warehouses select component
This commit is contained in:
@@ -1,75 +1,21 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
|
||||
import { MenuItem, Button } from '@blueprintjs/core';
|
||||
import { FSelect } from '../Forms';
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {*} query
|
||||
* @param {*} warehouse
|
||||
* @param {*} _index
|
||||
* @param {*} exactMatch
|
||||
* @returns
|
||||
*/
|
||||
const warehouseItemPredicate = (query, warehouse, _index, exactMatch) => {
|
||||
const normalizedTitle = warehouse.name.toLowerCase();
|
||||
const normalizedQuery = query.toLowerCase();
|
||||
|
||||
if (exactMatch) {
|
||||
return normalizedTitle === normalizedQuery;
|
||||
} else {
|
||||
return (
|
||||
`${warehouse.code}. ${normalizedTitle}`.indexOf(normalizedQuery) >= 0
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {*} film
|
||||
* @param {*} param1
|
||||
* @returns
|
||||
*/
|
||||
const warehouseItemRenderer = (
|
||||
warehouse,
|
||||
{ handleClick, modifiers, query },
|
||||
) => {
|
||||
const text = `${warehouse.name}`;
|
||||
|
||||
return (
|
||||
<MenuItem
|
||||
active={modifiers.active}
|
||||
disabled={modifiers.disabled}
|
||||
label={warehouse.code}
|
||||
key={warehouse.id}
|
||||
onClick={handleClick}
|
||||
text={text}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
const warehouseSelectProps = {
|
||||
itemPredicate: warehouseItemPredicate,
|
||||
itemRenderer: warehouseItemRenderer,
|
||||
valueAccessor: 'id',
|
||||
labelAccessor: 'name',
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* Warehouse select field.
|
||||
* @param {*} param0
|
||||
* @returns
|
||||
*/
|
||||
export function WarehouseSelect({ warehouses, ...rest }) {
|
||||
return <FSelect {...warehouseSelectProps} {...rest} items={warehouses} />;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {*} param0
|
||||
* @returns
|
||||
*/
|
||||
export function WarehouseSelectButton({ label, ...rest }) {
|
||||
return <Button text={label} />;
|
||||
}
|
||||
return (
|
||||
<FSelect
|
||||
valueAccessor={'id'}
|
||||
labelAccessor={'code'}
|
||||
textAccessor={'name'}
|
||||
popoverProps={{ minimal: true, usePortal: true, inline: false }}
|
||||
{...rest}
|
||||
items={warehouses}
|
||||
/>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user