mirror of
https://github.com/SigNoz/signoz.git
synced 2025-12-23 18:36:16 +00:00
21 lines
724 B
TypeScript
21 lines
724 B
TypeScript
|
|
import { AttributeKeyOptions } from 'api/queryBuilder/getAttributesKeysValues';
|
||
|
|
import { QUERY_BUILDER_OPERATORS_BY_TYPES } from 'constants/queryBuilder';
|
||
|
|
import { useMemo } from 'react';
|
||
|
|
|
||
|
|
type IOperators =
|
||
|
|
| typeof QUERY_BUILDER_OPERATORS_BY_TYPES.universal
|
||
|
|
| typeof QUERY_BUILDER_OPERATORS_BY_TYPES.string
|
||
|
|
| typeof QUERY_BUILDER_OPERATORS_BY_TYPES.boolean
|
||
|
|
| typeof QUERY_BUILDER_OPERATORS_BY_TYPES.number;
|
||
|
|
|
||
|
|
export const useOperators = (
|
||
|
|
key: string,
|
||
|
|
keys: AttributeKeyOptions[],
|
||
|
|
): IOperators =>
|
||
|
|
useMemo(() => {
|
||
|
|
const currentKey = keys?.find((el) => el.key === key);
|
||
|
|
return currentKey
|
||
|
|
? QUERY_BUILDER_OPERATORS_BY_TYPES[currentKey.dataType]
|
||
|
|
: QUERY_BUILDER_OPERATORS_BY_TYPES.universal;
|
||
|
|
}, [keys, key]);
|