From bb912b28cad0da0f04dae9dd89ce66bfd09406a7 Mon Sep 17 00:00:00 2001 From: Nate Kelley Date: Fri, 14 Feb 2025 21:41:57 -0700 Subject: [PATCH] filter metric list --- .../context/Metrics/BusterMetricProvider.tsx | 7 +- .../BusterMetricsListProvider.tsx | 98 ------------------- .../BusterMetricsListProvider/index.ts | 2 +- .../useBusterMetricListByFilter.tsx | 42 ++++++++ 4 files changed, 44 insertions(+), 105 deletions(-) delete mode 100644 web/src/context/Metrics/BusterMetricsListProvider/BusterMetricsListProvider.tsx create mode 100644 web/src/context/Metrics/BusterMetricsListProvider/useBusterMetricListByFilter.tsx diff --git a/web/src/context/Metrics/BusterMetricProvider.tsx b/web/src/context/Metrics/BusterMetricProvider.tsx index 2eca71049..e5d8be2c3 100644 --- a/web/src/context/Metrics/BusterMetricProvider.tsx +++ b/web/src/context/Metrics/BusterMetricProvider.tsx @@ -1,12 +1,7 @@ -import { BusterMetricsListProvider } from './BusterMetricsListProvider'; import { BusterMetricsIndividualProvider } from './BusterMetricsIndividualProvider'; import React, { PropsWithChildren } from 'react'; export const BusterMetricsProvider: React.FC = React.memo(({ children }) => { - return ( - - {children} - - ); + return {children}; }); BusterMetricsProvider.displayName = 'BusterMetricProvider'; diff --git a/web/src/context/Metrics/BusterMetricsListProvider/BusterMetricsListProvider.tsx b/web/src/context/Metrics/BusterMetricsListProvider/BusterMetricsListProvider.tsx deleted file mode 100644 index 53540ff30..000000000 --- a/web/src/context/Metrics/BusterMetricsListProvider/BusterMetricsListProvider.tsx +++ /dev/null @@ -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>( - {} as ReturnType -); - -export const BusterMetricsListProvider: React.FC = React.memo(({ children }) => { - const metricsContext = useMetricsList(); - - return {children}; -}); -BusterMetricsListProvider.displayName = 'BusterMetricsListProvider'; - -export const useBusterMetricsListContextSelector = ( - selector: ContextSelector, 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 - }; -}; diff --git a/web/src/context/Metrics/BusterMetricsListProvider/index.ts b/web/src/context/Metrics/BusterMetricsListProvider/index.ts index 7bf6eaf21..2740a7f46 100644 --- a/web/src/context/Metrics/BusterMetricsListProvider/index.ts +++ b/web/src/context/Metrics/BusterMetricsListProvider/index.ts @@ -1 +1 @@ -export * from './BusterMetricsListProvider'; +export * from './useBusterMetricListByFilter'; diff --git a/web/src/context/Metrics/BusterMetricsListProvider/useBusterMetricListByFilter.tsx b/web/src/context/Metrics/BusterMetricsListProvider/useBusterMetricListByFilter.tsx new file mode 100644 index 000000000..0289a4218 --- /dev/null +++ b/web/src/context/Metrics/BusterMetricsListProvider/useBusterMetricListByFilter.tsx @@ -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 + }; +};