mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-14 01:55:57 +08:00
feat: has and nhas filters is now enabled (#3567)
This commit is contained in:
parent
9f751688cc
commit
81b10d126a
13
frontend/src/container/LogDetailedView/config.ts
Normal file
13
frontend/src/container/LogDetailedView/config.ts
Normal 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,
|
||||
};
|
@ -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)', () => {
|
||||
|
@ -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> => {
|
||||
@ -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,
|
||||
@ -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);
|
||||
};
|
||||
|
@ -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}>
|
||||
|
Loading…
x
Reference in New Issue
Block a user