mirror of https://github.com/buster-so/buster.git
abstract listing metrics
This commit is contained in:
parent
05ce401d15
commit
88047b5e40
|
@ -33,9 +33,6 @@ export const useDashboards = () => {
|
|||
getDashboardFromList
|
||||
} = useDashboardLists();
|
||||
|
||||
//METRICS INDIVIDUAL
|
||||
const { onDashboardOpenMetric } = useDashboardMetrics({ openedDashboardId });
|
||||
|
||||
//DASHBOARD INDIVIDUAL
|
||||
const {
|
||||
dashboards,
|
||||
|
@ -80,9 +77,6 @@ export const useDashboards = () => {
|
|||
dashboards,
|
||||
removeItemFromIndividualDashboard,
|
||||
|
||||
//DASHBOARD METRICS
|
||||
onDashboardOpenMetric,
|
||||
|
||||
//OTHER
|
||||
onBulkAddRemoveToDashboard,
|
||||
onRemoveFromCollection,
|
||||
|
|
|
@ -4,7 +4,7 @@ import {
|
|||
VerificationStatus
|
||||
} from '@/api/asset_interfaces';
|
||||
import { ShareRole } from '@/api/asset_interfaces';
|
||||
import { createMockMetric } from '../Metrics/MOCK_METRIC';
|
||||
import { createMockMetric } from '../Metrics/BusterMetricsIndividualProvider/MOCK_METRIC';
|
||||
|
||||
interface DashboardMockResponse {
|
||||
dashboard: BusterDashboard;
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
import { BusterDashboardResponse } from '@/api/asset_interfaces';
|
||||
import { useRef, useState } from 'react';
|
||||
import { useBusterWebSocket } from '../../BusterWebSocket';
|
||||
import { useDashboardLists } from '../useDashboardLists';
|
||||
import { useDashboardAssosciations } from './useDashboardAssosciations';
|
||||
import { useDashboardUpdateConfig } from './useDashboardUpdateConfig';
|
||||
import { useDashboardSubscribe } from './useDashboardSubscribe';
|
||||
import { useDashboardCreate } from './useDashboardCreate';
|
||||
import { useShareDashboard } from './useShareDashboard';
|
||||
import { useShareDashboard } from './useDashboardShare';
|
||||
import { useMemoizedFn } from 'ahooks';
|
||||
|
||||
export const useDashboardIndividual = ({
|
||||
|
@ -20,8 +19,6 @@ export const useDashboardIndividual = ({
|
|||
setDashboardsList: ReturnType<typeof useDashboardLists>['setDashboardsList'];
|
||||
updateDashboardNameInList: ReturnType<typeof useDashboardLists>['updateDashboardNameInList'];
|
||||
}) => {
|
||||
const busterSocket = useBusterWebSocket();
|
||||
|
||||
const [dashboards, setDashboard] = useState<Record<string, BusterDashboardResponse>>({});
|
||||
|
||||
const dashboardsSubscribed = useRef<Record<string, boolean>>({});
|
||||
|
|
|
@ -21,7 +21,7 @@ export const useShareDashboard = () => {
|
|||
) => {
|
||||
return busterSocket.emit({
|
||||
route: '/dashboards/update',
|
||||
payload: { ...props }
|
||||
payload: props
|
||||
});
|
||||
}
|
||||
);
|
|
@ -0,0 +1,12 @@
|
|||
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>
|
||||
);
|
||||
});
|
||||
BusterMetricsProvider.displayName = 'BusterMetricProvider';
|
|
@ -1,29 +1,23 @@
|
|||
import React, { PropsWithChildren, useRef, useState } from 'react';
|
||||
import React, { PropsWithChildren, useRef } from 'react';
|
||||
import {
|
||||
createContext,
|
||||
ContextSelector,
|
||||
useContextSelector
|
||||
} from '@fluentui/react-context-selector';
|
||||
import { BusterMetricsListProvider } from './BusterMetricsListProvider';
|
||||
import { BusterMetricsListProvider } from '../BusterMetricsListProvider';
|
||||
import { useMemoizedFn, useMount } from 'ahooks';
|
||||
import type { IBusterMetric } from './interfaces';
|
||||
import type { IBusterMetric } from '../interfaces';
|
||||
import { BusterMetric } from '@/api/asset_interfaces';
|
||||
import { useBusterWebSocket } from '../BusterWebSocket';
|
||||
import { useParams } from 'next/navigation';
|
||||
import { useBusterAssetsContextSelector } from '../Assets/BusterAssetsProvider';
|
||||
import { useBusterNotifications } from '../BusterNotifications';
|
||||
import { useTransition } from 'react';
|
||||
import { RustApiError } from '@/api/buster_rest/errors';
|
||||
import { resolveEmptyMetric, upgradeMetricToIMetric } from './helpers';
|
||||
import { MetricUpdateMetric } from '@/api/buster_socket/metrics';
|
||||
import { useBusterMetricDataContextSelector } from '../MetricData';
|
||||
import { createMockMetric } from './MOCK_METRIC';
|
||||
import { useUpdateMetricConfig } from './useUpdateMetricConfig';
|
||||
import { useUpdateMetricAssosciations } from './useUpdateMetricAssosciations';
|
||||
import { useShareMetric } from './useShareMetric';
|
||||
import { resolveEmptyMetric, upgradeMetricToIMetric } from '../helpers';
|
||||
import { useBusterMetricDataContextSelector } from '../../MetricData';
|
||||
import { useUpdateMetricConfig } from './useMetricUpdateConfig';
|
||||
import { useUpdateMetricAssosciations } from './useMetricUpdateAssosciations';
|
||||
import { useShareMetric } from './useMetricShare';
|
||||
import { useMetricSubscribe } from './useMetricSubscribe';
|
||||
import { useParams } from 'next/navigation';
|
||||
|
||||
export const useBusterMetrics = () => {
|
||||
export const useBusterMetricsIndividual = () => {
|
||||
const [isPending, startTransition] = useTransition();
|
||||
const { metricId: selectedMetricId } = useParams<{ metricId: string }>();
|
||||
const metricsRef = useRef<Record<string, IBusterMetric>>({});
|
||||
|
@ -134,29 +128,31 @@ export const useBusterMetrics = () => {
|
|||
};
|
||||
};
|
||||
|
||||
const BusterMetrics = createContext<ReturnType<typeof useBusterMetrics>>(
|
||||
{} as ReturnType<typeof useBusterMetrics>
|
||||
const BusterMetricsIndividual = createContext<ReturnType<typeof useBusterMetricsIndividual>>(
|
||||
{} as ReturnType<typeof useBusterMetricsIndividual>
|
||||
);
|
||||
|
||||
export const BusterMetricsProvider: React.FC<PropsWithChildren> = React.memo(({ children }) => {
|
||||
return (
|
||||
<BusterMetrics.Provider value={useBusterMetrics()}>
|
||||
<BusterMetricsListProvider>{children}</BusterMetricsListProvider>
|
||||
</BusterMetrics.Provider>
|
||||
);
|
||||
});
|
||||
BusterMetricsProvider.displayName = 'BusterMetricsProvider';
|
||||
export const BusterMetricsIndividualProvider: React.FC<PropsWithChildren> = React.memo(
|
||||
({ children }) => {
|
||||
return (
|
||||
<BusterMetricsIndividual.Provider value={useBusterMetricsIndividual()}>
|
||||
{children}
|
||||
</BusterMetricsIndividual.Provider>
|
||||
);
|
||||
}
|
||||
);
|
||||
BusterMetricsIndividualProvider.displayName = 'BusterMetricsIndividualProvider';
|
||||
|
||||
export const useBusterMetricsContextSelector = <T,>(
|
||||
selector: ContextSelector<ReturnType<typeof useBusterMetrics>, T>
|
||||
export const useBusterMetricsIndividualContextSelector = <T,>(
|
||||
selector: ContextSelector<ReturnType<typeof useBusterMetricsIndividual>, T>
|
||||
) => {
|
||||
return useContextSelector(BusterMetrics, selector);
|
||||
return useContextSelector(BusterMetricsIndividual, selector);
|
||||
};
|
||||
|
||||
export const useBusterMetricIndividual = ({ metricId }: { metricId: string }) => {
|
||||
const subscribeToMetric = useBusterMetricsContextSelector((x) => x.subscribeToMetric);
|
||||
const subscribeToMetric = useBusterMetricsIndividualContextSelector((x) => x.subscribeToMetric);
|
||||
const fetchDataByMetricId = useBusterMetricDataContextSelector((x) => x.fetchDataByMetricId);
|
||||
const metric = useBusterMetricsContextSelector((x) => x.metrics[metricId]);
|
||||
const metric = useBusterMetricsIndividualContextSelector((x) => x.metrics[metricId]);
|
||||
const metricData = useBusterMetricDataContextSelector(({ getDataByMetricId }) =>
|
||||
getDataByMetricId(metricId)
|
||||
);
|
|
@ -5,7 +5,7 @@ import {
|
|||
ShareRole,
|
||||
VerificationStatus
|
||||
} from '@/api/asset_interfaces';
|
||||
import { IBusterMetric } from './interfaces';
|
||||
import { IBusterMetric } from '../interfaces';
|
||||
import { faker } from '@faker-js/faker';
|
||||
import { ChartType } from '@/components/charts';
|
||||
|
|
@ -0,0 +1 @@
|
|||
export * from './BusterMetricsIndividualProvider';
|
|
@ -1,11 +1,11 @@
|
|||
import { useMemoizedFn } from 'ahooks';
|
||||
import { useBusterAssetsContextSelector } from '../Assets/BusterAssetsProvider';
|
||||
import { IBusterMetric } from './interfaces';
|
||||
import { useBusterAssetsContextSelector } from '../../Assets/BusterAssetsProvider';
|
||||
import { IBusterMetric } from '../interfaces';
|
||||
import { createMockMetric } from './MOCK_METRIC';
|
||||
import { useBusterWebSocket } from '../BusterWebSocket';
|
||||
import { useBusterWebSocket } from '../../BusterWebSocket';
|
||||
import { BusterMetric } from '@/api/asset_interfaces';
|
||||
import { RustApiError } from '@/api/buster_rest/errors';
|
||||
import { resolveEmptyMetric } from './helpers';
|
||||
import { resolveEmptyMetric } from '../helpers';
|
||||
import React from 'react';
|
||||
|
||||
export const useMetricSubscribe = ({
|
|
@ -1,11 +1,11 @@
|
|||
import { useMemoizedFn } from 'ahooks';
|
||||
import last from 'lodash/last';
|
||||
import { MutableRefObject } from 'react';
|
||||
import { IBusterMetric } from './interfaces';
|
||||
import { useBusterWebSocket } from '../BusterWebSocket';
|
||||
import { useUserConfigContextSelector } from '../Users';
|
||||
import { useBusterNotifications } from '../BusterNotifications';
|
||||
import { useDashboardContextSelector } from '../Dashboards';
|
||||
import { IBusterMetric } from '../interfaces';
|
||||
import { useBusterWebSocket } from '../../BusterWebSocket';
|
||||
import { useUserConfigContextSelector } from '../../Users';
|
||||
import { useBusterNotifications } from '../../BusterNotifications';
|
||||
import { useDashboardContextSelector } from '../../Dashboards';
|
||||
|
||||
export const useUpdateMetricAssosciations = ({
|
||||
metricsRef,
|
|
@ -1,5 +1,5 @@
|
|||
import { useDebounceFn, useMemoizedFn } from 'ahooks';
|
||||
import type { IBusterMetric } from './interfaces';
|
||||
import type { IBusterMetric } from '../interfaces';
|
||||
import {
|
||||
BusterMetric,
|
||||
DEFAULT_CHART_CONFIG,
|
||||
|
@ -7,10 +7,10 @@ import {
|
|||
ShareRole,
|
||||
VerificationStatus
|
||||
} from '@/api/asset_interfaces';
|
||||
import { prepareMetricUpdateMetric } from './helpers';
|
||||
import { prepareMetricUpdateMetric } from '../helpers';
|
||||
import { MetricUpdateMetric } from '@/api/buster_socket/metrics';
|
||||
import { ColumnSettings, IColumnLabelFormat } from '@/components/charts';
|
||||
import { useBusterWebSocket } from '../BusterWebSocket';
|
||||
import { useBusterWebSocket } from '../../BusterWebSocket';
|
||||
|
||||
export const useUpdateMetricConfig = ({
|
||||
getMetricId,
|
|
@ -1,11 +1,9 @@
|
|||
'use client';
|
||||
|
||||
import React, { PropsWithChildren, useEffect, useMemo, useState } from 'react';
|
||||
import { useAppLayoutContextSelector } from '@/context/BusterAppLayout';
|
||||
import { BusterMetricListItem, VerificationStatus } from '@/api/asset_interfaces';
|
||||
import isEmpty from 'lodash/isEmpty';
|
||||
import { useBusterWebSocket } from '../BusterWebSocket';
|
||||
import { BusterRoutes } from '@/routes';
|
||||
import { useBusterWebSocket } from '../../BusterWebSocket';
|
||||
import { useMemoizedFn, useThrottleFn } from 'ahooks';
|
||||
import { createFilterRecord, metricsArrayToRecord } from './helpers';
|
||||
import {
|
||||
|
@ -13,7 +11,6 @@ import {
|
|||
useContextSelector,
|
||||
ContextSelector
|
||||
} from '@fluentui/react-context-selector';
|
||||
import { useBusterMetricsContextSelector } from './BusterMetricsProvider';
|
||||
|
||||
interface IMetricsList {
|
||||
fetching: boolean;
|
|
@ -0,0 +1,23 @@
|
|||
import { BusterMetricListItem, VerificationStatus } from '@/api/asset_interfaces';
|
||||
|
||||
export const metricsArrayToRecord = (metrics: BusterMetricListItem[]) => {
|
||||
return metrics.reduce(
|
||||
(acc, metric) => {
|
||||
acc[metric.id] = metric;
|
||||
return acc;
|
||||
},
|
||||
{} as Record<string, BusterMetricListItem>
|
||||
);
|
||||
};
|
||||
|
||||
export const createFilterRecord = ({
|
||||
filters = [],
|
||||
admin_view
|
||||
}: {
|
||||
filters?: VerificationStatus[];
|
||||
admin_view: boolean;
|
||||
}): string => {
|
||||
const filtersString = filters.join(',');
|
||||
const adminViewString = admin_view ? 'admin_view' : '';
|
||||
return filtersString + adminViewString;
|
||||
};
|
|
@ -0,0 +1 @@
|
|||
export * from './BusterMetricsListProvider';
|
|
@ -5,16 +5,6 @@ import { BusterChartConfigProps } from '@/components/charts';
|
|||
import { BusterMetricListItem, VerificationStatus } from '@/api/asset_interfaces';
|
||||
import { defaultIBusterMetric } from '../config';
|
||||
|
||||
export const metricsArrayToRecord = (metrics: BusterMetricListItem[]) => {
|
||||
return metrics.reduce(
|
||||
(acc, metric) => {
|
||||
acc[metric.id] = metric;
|
||||
return acc;
|
||||
},
|
||||
{} as Record<string, BusterMetricListItem>
|
||||
);
|
||||
};
|
||||
|
||||
export const canEditChart = (
|
||||
metricId: string | undefined | null,
|
||||
messageData: BusterMetricData,
|
||||
|
@ -41,15 +31,3 @@ export const resolveEmptyMetric = (
|
|||
}
|
||||
return metric;
|
||||
};
|
||||
|
||||
export const createFilterRecord = ({
|
||||
filters = [],
|
||||
admin_view
|
||||
}: {
|
||||
filters?: VerificationStatus[];
|
||||
admin_view: boolean;
|
||||
}): string => {
|
||||
const filtersString = filters.join(',');
|
||||
const adminViewString = admin_view ? 'admin_view' : '';
|
||||
return filtersString + adminViewString;
|
||||
};
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
export * from './BusterMetricsListProvider';
|
||||
export * from './BusterMetricsProvider';
|
||||
export * from './BusterMetricsIndividualProvider';
|
||||
export * from './BusterMetricProvider';
|
||||
export * from './interfaces';
|
||||
|
|
Loading…
Reference in New Issue