feat: has and nhas filters is now enabled (#3567)

This commit is contained in:
Palash Gupta 2023-10-02 05:04:04 +00:00 committed by GitHub
parent 9f751688cc
commit 81b10d126a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 59 additions and 40 deletions

View File

@ -0,0 +1,13 @@
import { DataTypes } from 'types/api/queryBuilder/queryAutocompleteResponse';
export const typeToArrayTypeMapper: { [key in DataTypes]: DataTypes } = {
[DataTypes.String]: DataTypes.ArrayString,
[DataTypes.Float64]: DataTypes.ArrayFloat64,
[DataTypes.Int64]: DataTypes.ArrayInt64,
[DataTypes.bool]: DataTypes.ArrayBool,
[DataTypes.EMPTY]: DataTypes.EMPTY,
[DataTypes.ArrayFloat64]: DataTypes.ArrayFloat64,
[DataTypes.ArrayInt64]: DataTypes.ArrayInt64,
[DataTypes.ArrayString]: DataTypes.ArrayString,
[DataTypes.ArrayBool]: DataTypes.ArrayBool,
};

View File

@ -176,8 +176,8 @@ describe('Get Data Types utils', () => {
}); });
// Edge cases // Edge cases
it('should return Int64 for empty array input', () => { it('should return Empty for empty array input', () => {
expect(getDataTypes([])).toBe(DataTypes.Int64); expect(getDataTypes([])).toBe(DataTypes.EMPTY);
}); });
it('should handle mixed array (return based on first element)', () => { it('should handle mixed array (return based on first element)', () => {

View File

@ -5,6 +5,7 @@ import { ILog, ILogAggregateAttributesResources } from 'types/api/logs/log';
import { DataTypes } from 'types/api/queryBuilder/queryAutocompleteResponse'; import { DataTypes } from 'types/api/queryBuilder/queryAutocompleteResponse';
import BodyTitleRenderer from './BodyTitleRenderer'; import BodyTitleRenderer from './BodyTitleRenderer';
import { typeToArrayTypeMapper } from './config';
import { AnyObject, IFieldAttributes } from './LogDetailedView.types'; import { AnyObject, IFieldAttributes } from './LogDetailedView.types';
export const recursiveParseJSON = (obj: string): Record<string, unknown> => { export const recursiveParseJSON = (obj: string): Record<string, unknown> => {
@ -107,40 +108,6 @@ export function flattenObject(obj: AnyObject, prefix = ''): AnyObject {
}, {}); }, {});
} }
const isFloat = (num: number): boolean => num % 1 !== 0;
export const getDataTypes = (value: unknown): DataTypes => {
if (typeof value === 'string') {
return DataTypes.String;
}
if (typeof value === 'number') {
return isFloat(value) ? DataTypes.Float64 : DataTypes.Int64;
}
if (typeof value === 'boolean') {
return DataTypes.bool;
}
if (Array.isArray(value)) {
const firstElement = value[0];
if (typeof firstElement === 'string') {
return DataTypes.ArrayString;
}
if (typeof firstElement === 'boolean') {
return DataTypes.ArrayBool;
}
if (typeof firstElement === 'number') {
return isFloat(firstElement) ? DataTypes.ArrayFloat64 : DataTypes.ArrayInt64;
}
}
return DataTypes.Int64;
};
export const generateFieldKeyForArray = ( export const generateFieldKeyForArray = (
fieldKey: string, fieldKey: string,
dataType: DataTypes, dataType: DataTypes,
@ -217,3 +184,45 @@ export const aggregateAttributesResourcesToString = (logData: ILog): string => {
return JSON.stringify(outputJson, null, 2); return JSON.stringify(outputJson, null, 2);
}; };
const isFloat = (num: number): boolean => num % 1 !== 0;
const isBooleanString = (str: string): boolean =>
str.toLowerCase() === 'true' || str.toLowerCase() === 'false';
const determineType = (val: unknown): DataTypes => {
if (typeof val === 'string') {
if (isBooleanString(val)) {
return DataTypes.bool;
}
const numberValue = parseFloat(val);
if (!Number.isNaN(numberValue)) {
return isFloat(numberValue) ? DataTypes.Float64 : DataTypes.Int64;
}
return DataTypes.String;
}
if (typeof val === 'number') {
return isFloat(val) ? DataTypes.Float64 : DataTypes.Int64;
}
if (typeof val === 'boolean') {
return DataTypes.bool;
}
return DataTypes.EMPTY;
};
export const getDataTypes = (value: unknown): DataTypes => {
const getArrayType = (elementType: DataTypes): DataTypes =>
typeToArrayTypeMapper[elementType] || DataTypes.EMPTY;
if (Array.isArray(value)) {
return getArrayType(determineType(value[0]));
}
return determineType(value);
};

View File

@ -87,10 +87,7 @@ function QueryBuilderSearch({
handleSearch(value); handleSearch(value);
}; };
const isDisabled = const isDisabled = !!searchValue;
!!searchValue ||
OPERATORS.HAS === tagOperator ||
OPERATORS.NHAS === tagOperator;
return ( return (
<Tag closable={!searchValue && closable} onClose={onCloseHandler}> <Tag closable={!searchValue && closable} onClose={onCloseHandler}>