Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { type UseQueryOptions } from '@tanstack/react-query';
import queryString from 'query-string';

import { type GetSearchAttributesResponse } from '@/route-handlers/get-search-attributes/get-search-attributes.types';
import request from '@/utils/request';
import { type RequestError } from '@/utils/request/request-error';

import { type UseSearchAttributesParams } from './use-search-attributes.types';

export default function getSearchAttributesQueryOptions({
cluster,
category = 'all',
}: UseSearchAttributesParams): UseQueryOptions<
GetSearchAttributesResponse,
RequestError,
GetSearchAttributesResponse,
[string, UseSearchAttributesParams]
> {
return {
queryKey: ['searchAttributes', { cluster, category }],
queryFn: ({ queryKey: [_, params] }) => {
const url = `/api/clusters/${params.cluster}/search-attributes?${queryString.stringify(
{
category: params.category,
}
)}`;
return request(url).then((res) => res.json());
},
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { useQuery } from '@tanstack/react-query';

import getSearchAttributesQueryOptions from './get-search-attributes-query-options';
import { type UseSearchAttributesParams } from './use-search-attributes.types';

export default function useSearchAttributes(params: UseSearchAttributesParams) {
return useQuery(getSearchAttributesQueryOptions(params));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { type SearchAttributesCategory } from '@/route-handlers/get-search-attributes/get-search-attributes.types';

export type UseSearchAttributesParams = {
cluster: string;
category?: SearchAttributesCategory;
};