2024-07-21 15:19:57 +03:00
|
|
|
'use client';
|
|
|
|
|
|
|
|
import clsx from 'clsx';
|
|
|
|
|
2025-02-10 01:32:55 +03:00
|
|
|
import { SelectSingle } from '@/components/Input';
|
2025-01-28 23:23:42 +03:00
|
|
|
import { CProps } from '@/components/props';
|
2025-02-10 01:32:55 +03:00
|
|
|
|
2025-02-18 23:39:11 +03:00
|
|
|
import { IOperation } from '../models/oss';
|
2025-02-10 01:32:55 +03:00
|
|
|
import { matchOperation } from '../models/ossAPI';
|
2024-07-21 15:19:57 +03:00
|
|
|
|
|
|
|
interface SelectOperationProps extends CProps.Styling {
|
2025-02-19 22:33:09 +03:00
|
|
|
value: IOperation | null;
|
|
|
|
onChange: (newValue: IOperation | null) => void;
|
2024-07-26 21:09:16 +03:00
|
|
|
|
2025-02-19 22:33:09 +03:00
|
|
|
items?: IOperation[];
|
2024-07-21 15:19:57 +03:00
|
|
|
placeholder?: string;
|
2024-07-26 21:09:16 +03:00
|
|
|
noBorder?: boolean;
|
2024-07-21 15:19:57 +03:00
|
|
|
}
|
|
|
|
|
2025-02-19 22:33:09 +03:00
|
|
|
export function SelectOperation({
|
2024-07-21 15:19:57 +03:00
|
|
|
className,
|
|
|
|
items,
|
|
|
|
value,
|
2025-02-04 20:35:55 +03:00
|
|
|
onChange,
|
2024-07-21 15:19:57 +03:00
|
|
|
placeholder = 'Выберите операцию',
|
|
|
|
...restProps
|
|
|
|
}: SelectOperationProps) {
|
2024-12-13 21:31:09 +03:00
|
|
|
const options =
|
|
|
|
items?.map(cst => ({
|
|
|
|
value: cst.id,
|
|
|
|
label: `${cst.alias}: ${cst.title}`
|
|
|
|
})) ?? [];
|
|
|
|
|
2025-02-17 15:12:15 +03:00
|
|
|
function filter(option: { value: string | undefined; label: string }, query: string) {
|
|
|
|
const operation = items?.find(item => item.id === Number(option.value));
|
|
|
|
return !operation ? false : matchOperation(operation, query);
|
2024-12-13 21:31:09 +03:00
|
|
|
}
|
2024-07-21 15:19:57 +03:00
|
|
|
|
|
|
|
return (
|
|
|
|
<SelectSingle
|
|
|
|
className={clsx('text-ellipsis', className)}
|
|
|
|
options={options}
|
2024-07-29 16:56:24 +03:00
|
|
|
value={value ? { value: value.id, label: `${value.alias}: ${value.title}` } : null}
|
2025-02-19 22:33:09 +03:00
|
|
|
onChange={data => onChange(items?.find(cst => cst.id === data?.value) ?? null)}
|
2024-07-21 15:19:57 +03:00
|
|
|
filterOption={filter}
|
|
|
|
placeholder={placeholder}
|
|
|
|
{...restProps}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|