From bcb2824e07e91d1b667189f930f89df88079613d Mon Sep 17 00:00:00 2001 From: Yunus M Date: Sun, 27 Apr 2025 22:03:00 +0530 Subject: [PATCH] feat: handle string and number values correctly --- .../CodeMirrorWhereClause.tsx | 46 +++++++++++-------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/frontend/src/components/QueryBuilderV2/CodeMirrorWhereClause/CodeMirrorWhereClause.tsx b/frontend/src/components/QueryBuilderV2/CodeMirrorWhereClause/CodeMirrorWhereClause.tsx index 43a91e226591..0aded7a50cba 100644 --- a/frontend/src/components/QueryBuilderV2/CodeMirrorWhereClause/CodeMirrorWhereClause.tsx +++ b/frontend/src/components/QueryBuilderV2/CodeMirrorWhereClause/CodeMirrorWhereClause.tsx @@ -122,8 +122,6 @@ function CodeMirrorWhereClause(): JSX.Element { async (key: string): Promise => { if (!key || (key === activeKey && !isLoadingSuggestions)) return; - console.log('Fetching suggestions for key:', key); - // Set loading state and store the key we're fetching for setIsLoadingSuggestions(true); lastKeyRef.current = key; @@ -149,26 +147,42 @@ function CodeMirrorWhereClause(): JSX.Element { const stringValues = values.stringValues || []; const numberValues = values.numberValues || []; - // Generate options from string values - const stringOptions = stringValues.map((value: string) => ({ - label: value || '""', - type: 'value', - })); + // Generate options from string values - explicitly handle empty strings + const stringOptions = stringValues + // Strict filtering for empty string - we'll handle it as a special case if needed + .filter( + (value: string | null | undefined): value is string => + value !== null && value !== undefined && value !== '', + ) + .map((value: string) => ({ + label: value, + type: 'value', + })); // Generate options from number values - const numberOptions = numberValues.map((value: number) => ({ - label: value.toString(), - type: 'number', - })); + const numberOptions = numberValues + .filter( + (value: number | null | undefined): value is number => + value !== null && value !== undefined, + ) + .map((value: number) => ({ + label: value.toString(), + type: 'number', + })); - // Update suggestions - const allOptions = [...stringOptions, ...numberOptions]; + // Combine all options and make sure we don't have duplicate labels + let allOptions = [...stringOptions, ...numberOptions]; + + // Remove duplicates by label + allOptions = allOptions.filter( + (option, index, self) => + index === self.findIndex((o) => o.label === option.label), + ); // Only if we're still on the same key if (lastKeyRef.current === key) { if (allOptions.length > 0) { setValueSuggestions(allOptions); - console.log('Updated value suggestions:', allOptions); } else { setValueSuggestions([ { label: 'No suggestions available', type: 'text' }, @@ -319,13 +333,9 @@ function CodeMirrorWhereClause(): JSX.Element { } if (queryContext.isInValue) { - console.log('is In Value', queryContext.currentToken); - // Fetch values based on the key - use the keyToken if available const key = queryContext.keyToken || queryContext.currentToken; - console.log('key', key); - // Trigger fetch only if key is different from activeKey or if we're still loading if (key && (key !== activeKey || isLoadingSuggestions)) { // Don't trigger a new fetch if we're already loading for this key