The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/apps/meteor/client/views/audit/hooks/useSettingSelectOptions.ts

41 lines
1.1 KiB

import { useSettings } from '@rocket.chat/ui-contexts';
import { useInfiniteQuery } from '@tanstack/react-query';
import { useCallback } from 'react';
type SettingSelectOption = {
label: string;
value: string;
_id: string;
};
export const useSettingSelectOptions = (filter = '') => {
const settings = useSettings();
const fetchData = useCallback(
async (start = 0): Promise<SettingSelectOption[]> => {
return settings
.map(({ _id }) => ({ label: _id, value: _id, _id }))
.filter(({ label }) => label.toUpperCase().includes(filter.toUpperCase()))
.slice(start, start + 50);
},
[filter, settings],
);
return useInfiniteQuery({
queryKey: ['settings', filter],
queryFn: ({ pageParam }) => fetchData(pageParam),
getNextPageParam: (lastPage, _allPages, lastPageParam) => {
if (lastPage.length === 0) {
return undefined;
}
return lastPageParam + 1;
},
getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => {
if (firstPageParam <= 1) {
return undefined;
}
return firstPageParam - 1;
},
initialPageParam: 0,
});
};