From ce8fdd509b3b538b13ce2c4955e5e8f039e8da90 Mon Sep 17 00:00:00 2001 From: Vikrant Gupta <54737045+Vikrant2520@users.noreply.github.com> Date: Mon, 18 Dec 2023 13:51:39 +0530 Subject: [PATCH] fix: [GH-3585]: operator suggestion should work on the substring typed in by the user (#4246) * fix: [GH-3585]: operator suggestion logic * fix: [GH-3585]: address review comments * fix: [GH-3585]: address review comments --- frontend/src/hooks/queryBuilder/useOptions.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/frontend/src/hooks/queryBuilder/useOptions.ts b/frontend/src/hooks/queryBuilder/useOptions.ts index 82dc2c1e24..2ecdf29e07 100644 --- a/frontend/src/hooks/queryBuilder/useOptions.ts +++ b/frontend/src/hooks/queryBuilder/useOptions.ts @@ -80,9 +80,15 @@ export const useOptions = ( const getKeyOperatorOptions = useCallback( (key: string) => { - const operatorsOptions = operators?.map((operator) => ({ - value: `${key} ${operator} `, - label: `${key} ${operator} `, + const keyOperator = key.split(' '); + const partialOperator = keyOperator?.[1]; + const partialKey = keyOperator?.[0]; + const filteredOperators = operators?.filter((operator) => + operator.startsWith(partialOperator?.toUpperCase()), + ); + const operatorsOptions = filteredOperators?.map((operator) => ({ + value: `${partialKey} ${operator} `, + label: `${partialKey} ${operator} `, })); if (whereClauseConfig) { return [