fix: added support for body contains X tag on pressing enter after selecting attribute key (#6059)

* fix: added empty operator in the top to support body contains

* fix: address review comments
This commit is contained in:
Vikrant Gupta 2024-09-25 20:31:06 +05:30 committed by GitHub
parent 35f8e133a9
commit 55f653d92e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -286,16 +286,62 @@ function QueryBuilderSearchV2(
parsedValue = value; parsedValue = value;
} }
if (currentState === DropdownState.ATTRIBUTE_KEY) { if (currentState === DropdownState.ATTRIBUTE_KEY) {
setCurrentFilterItem((prev) => ({ // Case - convert abc def ghi type attribute keys directly to body contains abc def ghi
...prev, if (
key: parsedValue as BaseAutocompleteData, isObject(parsedValue) &&
op: '', parsedValue?.key &&
value: '', parsedValue?.key?.split(' ').length > 1
})); ) {
setCurrentState(DropdownState.OPERATOR); setTags((prev) => [
setSearchValue((parsedValue as BaseAutocompleteData)?.key); ...prev,
{
key: {
key: 'body',
dataType: DataTypes.String,
type: '',
isColumn: true,
isJSON: false,
// eslint-disable-next-line sonarjs/no-duplicate-string
id: 'body--string----true',
},
op: OPERATORS.CONTAINS,
value: (parsedValue as BaseAutocompleteData)?.key,
},
]);
setCurrentFilterItem(undefined);
setSearchValue('');
setCurrentState(DropdownState.ATTRIBUTE_KEY);
} else {
setCurrentFilterItem((prev) => ({
...prev,
key: parsedValue as BaseAutocompleteData,
op: '',
value: '',
}));
setCurrentState(DropdownState.OPERATOR);
setSearchValue((parsedValue as BaseAutocompleteData)?.key);
}
} else if (currentState === DropdownState.OPERATOR) { } else if (currentState === DropdownState.OPERATOR) {
if (value === OPERATORS.EXISTS || value === OPERATORS.NOT_EXISTS) { if (isEmpty(value) && currentFilterItem?.key?.key) {
setTags((prev) => [
...prev,
{
key: {
key: 'body',
dataType: DataTypes.String,
type: '',
isColumn: true,
isJSON: false,
id: 'body--string----true',
},
op: OPERATORS.CONTAINS,
value: currentFilterItem?.key?.key,
},
]);
setCurrentFilterItem(undefined);
setSearchValue('');
setCurrentState(DropdownState.ATTRIBUTE_KEY);
} else if (value === OPERATORS.EXISTS || value === OPERATORS.NOT_EXISTS) {
setTags((prev) => [ setTags((prev) => [
...prev, ...prev,
{ {
@ -399,6 +445,7 @@ function QueryBuilderSearchV2(
whereClauseConfig?.customKey === 'body' && whereClauseConfig?.customKey === 'body' &&
whereClauseConfig?.customOp === OPERATORS.CONTAINS whereClauseConfig?.customOp === OPERATORS.CONTAINS
) { ) {
// eslint-disable-next-line sonarjs/no-identical-functions
setTags((prev) => [ setTags((prev) => [
...prev, ...prev,
{ {
@ -519,19 +566,20 @@ function QueryBuilderSearchV2(
setCurrentState(DropdownState.OPERATOR); setCurrentState(DropdownState.OPERATOR);
} }
} }
if (suggestionsData?.payload?.attributes?.length === 0) { // again let's not auto select anything for the user
if (tagOperator) {
setCurrentFilterItem({ setCurrentFilterItem({
key: { key: {
key: tagKey.split(' ')[0], key: tagKey,
dataType: DataTypes.EMPTY, dataType: DataTypes.EMPTY,
type: '', type: '',
isColumn: false, isColumn: false,
isJSON: false, isJSON: false,
}, },
op: '', op: tagOperator,
value: '', value: '',
}); });
setCurrentState(DropdownState.OPERATOR); setCurrentState(DropdownState.ATTRIBUTE_VALUE);
} }
} else if ( } else if (
// Case 2 - if key is defined but the search text doesn't match with the set key, // Case 2 - if key is defined but the search text doesn't match with the set key,
@ -607,13 +655,32 @@ function QueryBuilderSearchV2(
// the useEffect takes care of setting the dropdown values correctly on change of the current state // the useEffect takes care of setting the dropdown values correctly on change of the current state
useEffect(() => { useEffect(() => {
if (currentState === DropdownState.ATTRIBUTE_KEY) { if (currentState === DropdownState.ATTRIBUTE_KEY) {
const { tagKey } = getTagToken(searchValue);
if (isLogsExplorerPage) { if (isLogsExplorerPage) {
setDropdownOptions( // add the user typed option in the dropdown to select that and move ahead irrespective of the matches and all
suggestionsData?.payload?.attributes?.map((key) => ({ setDropdownOptions([
...(!isEmpty(tagKey) &&
!suggestionsData?.payload?.attributes?.some((val) =>
isEqual(val.key, tagKey),
)
? [
{
label: tagKey,
value: {
key: tagKey,
dataType: DataTypes.EMPTY,
type: '',
isColumn: false,
isJSON: false,
},
},
]
: []),
...(suggestionsData?.payload?.attributes?.map((key) => ({
label: key.key, label: key.key,
value: key, value: key,
})) || [], })) || []),
); ]);
} else { } else {
setDropdownOptions( setDropdownOptions(
data?.payload?.attributeKeys?.map((key) => ({ data?.payload?.attributeKeys?.map((key) => ({
@ -643,12 +710,14 @@ function QueryBuilderSearchV2(
op.label.startsWith(partialOperator.toLocaleUpperCase()), op.label.startsWith(partialOperator.toLocaleUpperCase()),
); );
} }
operatorOptions = [{ label: '', value: '' }, ...operatorOptions];
setDropdownOptions(operatorOptions); setDropdownOptions(operatorOptions);
} else if (strippedKey.endsWith('[*]') && strippedKey.startsWith('body.')) { } else if (strippedKey.endsWith('[*]') && strippedKey.startsWith('body.')) {
operatorOptions = [OPERATORS.HAS, OPERATORS.NHAS].map((operator) => ({ operatorOptions = [OPERATORS.HAS, OPERATORS.NHAS].map((operator) => ({
label: operator, label: operator,
value: operator, value: operator,
})); }));
operatorOptions = [{ label: '', value: '' }, ...operatorOptions];
setDropdownOptions(operatorOptions); setDropdownOptions(operatorOptions);
} else { } else {
operatorOptions = QUERY_BUILDER_OPERATORS_BY_TYPES.universal.map( operatorOptions = QUERY_BUILDER_OPERATORS_BY_TYPES.universal.map(
@ -663,6 +732,7 @@ function QueryBuilderSearchV2(
op.label.startsWith(partialOperator.toLocaleUpperCase()), op.label.startsWith(partialOperator.toLocaleUpperCase()),
); );
} }
operatorOptions = [{ label: '', value: '' }, ...operatorOptions];
setDropdownOptions(operatorOptions); setDropdownOptions(operatorOptions);
} }
} }