mirror of https://github.com/buster-so/buster.git
filter metric list
This commit is contained in:
parent
db4a5adee1
commit
bb912b28ca
|
@ -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';
|
||||
|
|
|
@ -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
|
||||
};
|
||||
};
|
|
@ -1 +1 @@
|
|||
export * from './BusterMetricsListProvider';
|
||||
export * from './useBusterMetricListByFilter';
|
||||
|
|
|
@ -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
|
||||
};
|
||||
};
|
Loading…
Reference in New Issue