diff --git a/frontend/src/components/QueryBuilderV2/QueryAddOns/HavingFilter/HavingFilter.tsx b/frontend/src/components/QueryBuilderV2/QueryAddOns/HavingFilter/HavingFilter.tsx new file mode 100644 index 000000000000..99662e3df570 --- /dev/null +++ b/frontend/src/components/QueryBuilderV2/QueryAddOns/HavingFilter/HavingFilter.tsx @@ -0,0 +1,99 @@ +import { Button, Select } from 'antd'; +import { useEffect, useState } from 'react'; + +const havingOperators = [ + { + label: '=', + value: '=', + }, + { + label: '!=', + value: '!=', + }, + { + label: '>', + value: '>', + }, + { + label: '<', + value: '<', + }, + { + label: '>=', + value: '>=', + }, + { + label: '<=', + value: '<=', + }, + { + label: 'IN', + value: 'IN', + }, + { + label: 'NOT_IN', + value: 'NOT_IN', + }, +]; + +function HavingFilter({ + selectedAggreateOptions, + onClose, +}: { + selectedAggreateOptions: { func: string; arg: string }[]; + onClose: () => void; +}): JSX.Element { + const [selectedHavingOptions, setSelectedHavingOptions] = useState( + [], + ); + + const [options, setOptions] = useState<{ label: string; value: string }[]>([]); + + useEffect(() => { + const options = []; + + for (let i = 0; i < selectedAggreateOptions.length; i++) { + const opt = selectedAggreateOptions[i]; + + for (let j = 0; j < havingOperators.length; j++) { + const operator = havingOperators[j]; + + options.push({ + label: `${opt.func}(${opt.arg}) ${operator.label}`, + value: `${opt.func}(${opt.arg}) ${operator.label}`, + }); + } + } + + console.log('options', options); + + setOptions(options); + }, [selectedAggreateOptions]); + + console.log( + 'selectedHavingOptions', + selectedHavingOptions, + selectedAggreateOptions, + setSelectedHavingOptions, + ); + + console.log('options', options); + + return ( +
+ */} - - +
every
diff --git a/frontend/src/components/QueryBuilderV2/QueryAggregation/QueryAggregationSelect.tsx b/frontend/src/components/QueryBuilderV2/QueryAggregation/QueryAggregationSelect.tsx index bc89df4f5b61..1776deb74728 100644 --- a/frontend/src/components/QueryBuilderV2/QueryAggregation/QueryAggregationSelect.tsx +++ b/frontend/src/components/QueryBuilderV2/QueryAggregation/QueryAggregationSelect.tsx @@ -110,7 +110,11 @@ function getFunctionContextAtCursor( } // eslint-disable-next-line react/no-this-in-sfc -function QueryAggregationSelect(): JSX.Element { +function QueryAggregationSelect({ + onAggregationOptionsSelect, +}: { + onAggregationOptionsSelect: (value: { func: string; arg: string }[]) => void; +}): JSX.Element { const { currentQuery } = useQueryBuilder(); const queryData = currentQuery.builder.queryData[0]; const [input, setInput] = useState(''); @@ -142,6 +146,8 @@ function QueryAggregationSelect(): JSX.Element { }); } setFunctionArgPairs(pairs); + onAggregationOptionsSelect(pairs); + // eslint-disable-next-line react-hooks/exhaustive-deps }, [input]); // Find function context for fetching suggestions diff --git a/frontend/src/components/QueryBuilderV2/QueryBuilderV2.tsx b/frontend/src/components/QueryBuilderV2/QueryBuilderV2.tsx index 746cb87e4585..bdb5041a9159 100644 --- a/frontend/src/components/QueryBuilderV2/QueryBuilderV2.tsx +++ b/frontend/src/components/QueryBuilderV2/QueryBuilderV2.tsx @@ -1,6 +1,7 @@ import './QueryBuilderV2.styles.scss'; import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder'; +import { useState } from 'react'; import QueryAddOns from './QueryAddOns/QueryAddOns'; import QueryAggregation from './QueryAggregation/QueryAggregation'; @@ -9,14 +10,25 @@ import QuerySearch from './QuerySearch/QuerySearch'; function QueryBuilderV2(): JSX.Element { const { currentQuery } = useQueryBuilder(); + const [selectedAggreateOptions, setSelectedAggreateOptions] = useState< + { func: string; arg: string }[] + >([]); + + console.log('selectedAggreateOptions', selectedAggreateOptions); + return (
- + { + setSelectedAggreateOptions(pairs); + }} + />
);