import './QueryFunctions.styles.scss'; import { Button, Tooltip } from 'antd'; import cx from 'classnames'; import { useIsDarkMode } from 'hooks/useDarkMode'; import { cloneDeep, pullAt } from 'lodash-es'; import { Plus } from 'lucide-react'; import { useState } from 'react'; import { QueryFunctionProps } from 'types/api/queryBuilder/queryBuilderData'; import { QueryFunctionsTypes } from 'types/common/queryBuilder'; import Function from './Function'; const defaultFunctionStruct: QueryFunctionProps = { name: QueryFunctionsTypes.CUTOFF_MIN, args: [], }; interface QueryFunctionsProps { queryFunctions: QueryFunctionProps[]; onChange: (functions: QueryFunctionProps[]) => void; } // SVG component function FunctionIcon({ fillColor = 'white', className, }: { fillColor: string; className: string; }): JSX.Element { return ( ); } export default function QueryFunctions({ queryFunctions, onChange, }: QueryFunctionsProps): JSX.Element { const [functions, setFunctions] = useState( queryFunctions, ); const isDarkMode = useIsDarkMode(); const handleAddNewFunction = (): void => { const updatedFunctionsArr = [ ...functions, { ...defaultFunctionStruct, }, ]; setFunctions(updatedFunctionsArr); onChange(updatedFunctionsArr); }; const handleDeleteFunction = ( queryFunction: QueryFunctionProps, index: number, ): void => { const clonedFunctions = cloneDeep(functions); pullAt(clonedFunctions, index); setFunctions(clonedFunctions); onChange(clonedFunctions); }; const handleUpdateFunctionName = ( func: QueryFunctionProps, index: number, value: string, ): void => { const updateFunctions = cloneDeep(functions); if (updateFunctions && updateFunctions.length > 0 && updateFunctions[index]) { updateFunctions[index].name = value; setFunctions(updateFunctions); onChange(updateFunctions); } }; const handleUpdateFunctionArgs = ( func: QueryFunctionProps, index: number, value: string, ): void => { const updateFunctions = cloneDeep(functions); if (updateFunctions && updateFunctions.length > 0 && updateFunctions[index]) { updateFunctions[index].args = [value]; setFunctions(updateFunctions); onChange(updateFunctions); } }; return (
0 ? 'hasFunctions' : '', )} >
{functions.map((func, index) => ( ))}
= 3 ? 'Functions are in early access. You can add a maximum of 3 function as of now.' : '' } placement="right" >
); }