Skip to content

Commit

Permalink
feat: has and nhas filters is now enabled (#3567)
Browse files Browse the repository at this point in the history
  • Loading branch information
palashgdev authored Oct 2, 2023
1 parent 9f75168 commit 81b10d1
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 40 deletions.
13 changes: 13 additions & 0 deletions frontend/src/container/LogDetailedView/config.ts
Original file line number Diff line number Diff line change
@@ -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,
};
4 changes: 2 additions & 2 deletions frontend/src/container/LogDetailedView/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ describe('Get Data Types utils', () => {
});

// Edge cases
it('should return Int64 for empty array input', () => {
expect(getDataTypes([])).toBe(DataTypes.Int64);
it('should return Empty for empty array input', () => {
expect(getDataTypes([])).toBe(DataTypes.EMPTY);
});

it('should handle mixed array (return based on first element)', () => {
Expand Down
77 changes: 43 additions & 34 deletions frontend/src/container/LogDetailedView/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ILog, ILogAggregateAttributesResources } from 'types/api/logs/log';
import { DataTypes } from 'types/api/queryBuilder/queryAutocompleteResponse';

import BodyTitleRenderer from './BodyTitleRenderer';
import { typeToArrayTypeMapper } from './config';
import { AnyObject, IFieldAttributes } from './LogDetailedView.types';

export const recursiveParseJSON = (obj: string): Record<string, unknown> => {
Expand Down Expand Up @@ -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 = (
fieldKey: string,
dataType: DataTypes,
Expand Down Expand Up @@ -217,3 +184,45 @@ export const aggregateAttributesResourcesToString = (logData: ILog): string => {

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);
};
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ function QueryBuilderSearch({
handleSearch(value);
};

const isDisabled =
!!searchValue ||
OPERATORS.HAS === tagOperator ||
OPERATORS.NHAS === tagOperator;
const isDisabled = !!searchValue;

return (
<Tag closable={!searchValue && closable} onClose={onCloseHandler}>
Expand Down

0 comments on commit 81b10d1

Please sign in to comment.