mirror of
https://github.com/SigNoz/signoz.git
synced 2025-12-25 19:40:24 +00:00
* feat: added dynamic variables creation flow * feat: added keys and value apis and hooks * feat: added api and select component changes * feat: added keys fetching and preview values * feat: added dynamic variable to variable items * feat: handled value persistence and tab switches * feat: added default value and formed a schema for dyn-variables * feat: added client and server side searches * feat: corrected the initial load getfieldKey api * feat: removed fetch on mount restriction
39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
import { getFieldValues } from 'api/dynamicVariables/getFieldValues';
|
|
import { useQuery, UseQueryResult } from 'react-query';
|
|
import { ErrorResponse, SuccessResponse } from 'types/api';
|
|
import { FieldValueResponse } from 'types/api/dynamicVariables/getFieldValues';
|
|
|
|
interface UseGetFieldValuesProps {
|
|
/** Type of signal (traces, logs, metrics) */
|
|
signal?: 'traces' | 'logs' | 'metrics';
|
|
/** Name of the attribute for which values are being fetched */
|
|
name: string;
|
|
/** Optional search text */
|
|
value?: string;
|
|
/** Whether the query should be enabled */
|
|
enabled?: boolean;
|
|
}
|
|
|
|
/**
|
|
* Hook to fetch field values for a given signal type and field name
|
|
*
|
|
* If 'complete' in the response is true:
|
|
* - All subsequent searches should be local (client has complete list)
|
|
*
|
|
* If 'complete' is false:
|
|
* - All subsequent searches should use the API (passing the value param)
|
|
*/
|
|
export const useGetFieldValues = ({
|
|
signal,
|
|
name,
|
|
value,
|
|
enabled = true,
|
|
}: UseGetFieldValuesProps): UseQueryResult<
|
|
SuccessResponse<FieldValueResponse> | ErrorResponse
|
|
> =>
|
|
useQuery<SuccessResponse<FieldValueResponse> | ErrorResponse>({
|
|
queryKey: ['fieldValues', signal, name, value],
|
|
queryFn: () => getFieldValues(signal, name, value),
|
|
enabled,
|
|
});
|