import { useState } from 'react'; import { ActionIcon } from '/@/shared/components/action-icon/action-icon'; import { Group } from '/@/shared/components/group/group'; import { NumberInput } from '/@/shared/components/number-input/number-input'; import { Select } from '/@/shared/components/select/select'; import { TextInput } from '/@/shared/components/text-input/text-input'; import { QueryBuilderRule } from '/@/shared/types/types'; type DeleteArgs = { groupIndex: number[]; level: number; uniqueId: string; }; interface QueryOptionProps { data: QueryBuilderRule; filters: { label: string; type: string; value: string }[]; groupIndex: number[]; level: number; noRemove: boolean; onChangeField: (args: any) => void; onChangeOperator: (args: any) => void; onChangeValue: (args: any) => void; onDeleteRule: (args: DeleteArgs) => void; operators: { boolean: { label: string; value: string }[]; date: { label: string; value: string }[]; number: { label: string; value: string }[]; string: { label: string; value: string }[]; }; selectData?: { label: string; value: string }[]; } const QueryValueInput = ({ data, onChange, type, ...props }: any) => { const [numberRange, setNumberRange] = useState([0, 0]); switch (type) { case 'boolean': return ( ); case 'string': return ( ); default: return <>; } }; export const QueryBuilderOption = ({ data, filters, groupIndex, level, noRemove, onChangeField, onChangeOperator, onChangeValue, onDeleteRule, operators, selectData, }: QueryOptionProps) => { const { field, operator, uniqueId, value } = data; const handleDeleteRule = () => { onDeleteRule({ groupIndex, level, uniqueId }); }; const handleChangeField = (e: any) => { onChangeField({ groupIndex, level, uniqueId, value: e }); }; const handleChangeOperator = (e: any) => { onChangeOperator({ groupIndex, level, uniqueId, value: e }); }; const handleChangeValue = (e: any) => { const isDirectValue = typeof e === 'string' || typeof e === 'number' || typeof e === 'undefined'; if (isDirectValue) { return onChangeValue({ groupIndex, level, uniqueId, value: e, }); } // const isDate = e instanceof Date; // if (isDate) { // return onChangeValue({ // groupIndex, // level, // uniqueId, // value: dayjs(e).format('YYYY-MM-DD'), // }); // } const isArray = Array.isArray(e); if (isArray) { return onChangeValue({ groupIndex, level, uniqueId, value: e, }); } return onChangeValue({ groupIndex, level, uniqueId, value: e.currentTarget.value, }); }; const fieldType = filters.find((f) => f.value === field)?.type; const operatorsByFieldType = operators[fieldType as keyof typeof operators]; const ml = (level + 1) * 10; return ( {field ? ( ) : ( )} ); };