filter metric list

This commit is contained in:
Nate Kelley 2025-02-14 21:41:57 -07:00
parent db4a5adee1
commit bb912b28ca
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
4 changed files with 44 additions and 105 deletions

View File

@ -1,12 +1,7 @@
import { BusterMetricsListProvider } from './BusterMetricsListProvider';
import { BusterMetricsIndividualProvider } from './BusterMetricsIndividualProvider';
import React, { PropsWithChildren } from 'react';
export const BusterMetricsProvider: React.FC<PropsWithChildren> = React.memo(({ children }) => {
return (
<BusterMetricsIndividualProvider>
<BusterMetricsListProvider>{children}</BusterMetricsListProvider>
</BusterMetricsIndividualProvider>
);
return <BusterMetricsIndividualProvider>{children}</BusterMetricsIndividualProvider>;
});
BusterMetricsProvider.displayName = 'BusterMetricProvider';

View File

@ -1,98 +0,0 @@
'use client';
import React, { PropsWithChildren, useEffect, useMemo, useState } from 'react';
import { VerificationStatus } from '@/api/asset_interfaces';
import {
createContext,
useContextSelector,
ContextSelector
} from '@fluentui/react-context-selector';
import { useSocketQueryEmitOn } from '@/api/buster_socket_query';
import { queryKeys } from '@/api/query_keys';
interface IMetricsList {
fetching: boolean;
fetched: boolean;
fetchedAt: number;
metricListIds: string[];
}
const useMetricsList = () => {
const [metricListFilters, setMetricListFilters] = useState<{
filters?: VerificationStatus[];
admin_view: boolean;
}>({ filters: undefined, admin_view: false });
const { data: metricList, isFetching: fetchingMetricList } = useSocketQueryEmitOn(
{
route: '/metrics/list',
payload: {
page_token: 0,
page_size: 3000, //TODO: make a pagination,
...metricListFilters
}
},
'/metrics/list:getMetricList',
queryKeys['/metrics/list:getMetricsList']()
);
return {
metricList,
metricListFilters,
fetchingMetricList,
setMetricListFilters
};
};
const BusterMetricsList = createContext<ReturnType<typeof useMetricsList>>(
{} as ReturnType<typeof useMetricsList>
);
export const BusterMetricsListProvider: React.FC<PropsWithChildren> = React.memo(({ children }) => {
const metricsContext = useMetricsList();
return <BusterMetricsList.Provider value={metricsContext}>{children}</BusterMetricsList.Provider>;
});
BusterMetricsListProvider.displayName = 'BusterMetricsListProvider';
export const useBusterMetricsListContextSelector = <T,>(
selector: ContextSelector<ReturnType<typeof useMetricsList>, T>
) => {
return useContextSelector(BusterMetricsList, selector);
};
export const useBusterMetricListByFilter = (params: {
filters: VerificationStatus[];
admin_view: boolean;
}) => {
const metricListFilters = useMemo(
() => ({
filters: params.filters,
admin_view: params.admin_view
}),
[params.filters.join(','), params.admin_view]
);
const {
data: metricList,
isFetching,
isFetched
} = useSocketQueryEmitOn(
{
route: '/metrics/list',
payload: {
page_token: 0,
page_size: 3000, //TODO: make a pagination,
...metricListFilters
}
},
'/metrics/list:getMetricList',
queryKeys['/metrics/list:getMetricsList']()
);
return {
metricList,
isFetching,
isFetched
};
};

View File

@ -1 +1 @@
export * from './BusterMetricsListProvider';
export * from './useBusterMetricListByFilter';

View File

@ -0,0 +1,42 @@
'use client';
import React, { useMemo } from 'react';
import { VerificationStatus } from '@/api/asset_interfaces';
import { useSocketQueryEmitOn } from '@/api/buster_socket_query';
import { queryKeys } from '@/api/query_keys';
export const useBusterMetricListByFilter = (params: {
filters: VerificationStatus[];
admin_view: boolean;
}) => {
const metricListFilters = useMemo(
() => ({
filters: params.filters,
admin_view: params.admin_view
}),
[params.filters.join(','), params.admin_view]
);
const {
data: metricList,
isFetching,
isFetched
} = useSocketQueryEmitOn(
{
route: '/metrics/list',
payload: {
page_token: 0,
page_size: 3000, //TODO: make a pagination,
...metricListFilters
}
},
'/metrics/list:getMetricList',
queryKeys['/metrics/list:getMetricsList']()
);
return {
metricList,
isFetching,
isFetched
};
};