This commit is contained in:
Ahmed Bouhuolia
2025-11-25 21:29:32 +02:00
parent ff04c4b762
commit adfa8852db
7 changed files with 57 additions and 58 deletions

View File

@@ -19,7 +19,7 @@ interface Account {
account_normal?: string;
}
interface AccountSelect extends Account, SelectOptionProps { }
export interface AccountSelect extends Partial<Account>, SelectOptionProps { }
type MultiSelectProps = React.ComponentProps<typeof FMultiSelect>;
@@ -49,10 +49,13 @@ const createNewItemRenderer = (
};
// Create new item from the given query string.
const createNewItemFromQuery = (query: string): SelectOptionProps => ({
const createNewItemFromQuery = (query: string): AccountSelect => ({
label: query,
value: query,
text: query,
id: 0,
name: query,
code: query,
});
/**

View File

@@ -14,7 +14,6 @@ import {
FormattedMessage as T,
} from '@/components';
import { nestedArrayToflatten, filterAccountsByQuery } from '@/utils';
import withDialogActions from '@/containers/Dialog/withDialogActions';
// Create new account renderer.
@@ -31,9 +30,7 @@ const createNewItemRenderer = (query, active, handleClick) => {
// Create new item from the given query string.
const createNewItemFromQuery = (name) => {
return {
name,
};
return { name };
};
// Filters accounts items.
@@ -72,6 +69,22 @@ function AccountsSuggestFieldRoot({
() => nestedArrayToflatten(accounts),
[accounts],
);
const filteredAccounts = useMemo(
() =>
filterAccountsByQuery(flattenAccounts, {
filterByParentTypes,
filterByTypes,
filterByNormal,
filterByRootTypes,
}),
[
flattenAccounts,
filterByParentTypes,
filterByTypes,
filterByNormal,
filterByRootTypes,
],
);
const handleCreateItemSelect = useCallback(
(item) => {
if (!item.id) {

View File

@@ -1,7 +1,14 @@
// @ts-nocheck
import { AccountSelect } from "./AccountsMultiSelect";
// Filters accounts items.
export const accountPredicate = (query, account, _index, exactMatch) => {
export const accountPredicate = (
query: string,
account: AccountSelect,
_index?: number,
exactMatch?: boolean,
) => {
const normalizedTitle = account.name.toLowerCase();
const normalizedQuery = query.toLowerCase();