mirror of https://github.com/buster-so/buster.git
fetch dashboard
This commit is contained in:
parent
a05a81feaf
commit
6c4e96a73f
|
@ -72,8 +72,8 @@ const useGetDashboardAndInitializeMetrics = () => {
|
|||
export const useGetDashboard = <TData = BusterDashboardResponse>(
|
||||
{
|
||||
id,
|
||||
version_number: version_number_prop
|
||||
}: { id: string | undefined; version_number?: number | null },
|
||||
versionNumber: versionNumberProp
|
||||
}: { id: string | undefined; versionNumber?: number | null },
|
||||
params?: Omit<
|
||||
UseQueryOptions<BusterDashboardResponse, RustApiError, TData>,
|
||||
'queryKey' | 'queryFn'
|
||||
|
@ -85,12 +85,14 @@ export const useGetDashboard = <TData = BusterDashboardResponse>(
|
|||
};
|
||||
const versionNumberQueryParam = useSearchParams().get('versionNumber');
|
||||
|
||||
const versionNumber = versionNumberQueryParam || verionNumberPathParam;
|
||||
const versionNumberFromParams = versionNumberQueryParam || verionNumberPathParam;
|
||||
|
||||
const version_number = useMemo(() => {
|
||||
if (version_number_prop === null) return undefined;
|
||||
return version_number_prop || versionNumber ? parseInt(versionNumber!) : undefined;
|
||||
}, [version_number_prop, versionNumber]);
|
||||
if (versionNumberProp === null) return undefined;
|
||||
return versionNumberProp || versionNumberFromParams
|
||||
? parseInt(versionNumberFromParams!)
|
||||
: undefined;
|
||||
}, [versionNumberProp, versionNumberFromParams]);
|
||||
|
||||
return useQuery({
|
||||
...dashboardQueryKeys.dashboardGetDashboard(id!, version_number),
|
||||
|
|
|
@ -5,12 +5,12 @@ export default async function MetricLayout({
|
|||
params
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
params: Promise<{ metricId: string }>;
|
||||
params: Promise<{ metricId: string; versionNumber?: number }>;
|
||||
}) {
|
||||
const { metricId } = await params;
|
||||
const { metricId, versionNumber } = await params;
|
||||
|
||||
return (
|
||||
<AppAssetCheckLayout assetId={metricId} type="metric">
|
||||
<AppAssetCheckLayout assetId={metricId} type="metric" versionNumber={versionNumber}>
|
||||
{children}
|
||||
</AppAssetCheckLayout>
|
||||
);
|
||||
|
|
|
@ -15,14 +15,15 @@ import { HydrationBoundaryAssetStore } from '@/context/Assets/HydrationBoundaryA
|
|||
export type AppAssetCheckLayoutProps = {
|
||||
assetId: string;
|
||||
type: 'metric' | 'dashboard';
|
||||
versionNumber?: number;
|
||||
};
|
||||
|
||||
export const AppAssetCheckLayout: React.FC<
|
||||
{
|
||||
children: React.ReactNode;
|
||||
} & AppAssetCheckLayoutProps
|
||||
> = async ({ children, type, assetId }) => {
|
||||
const queryClient = await prefetchAsset(assetId, type);
|
||||
> = async ({ children, type, assetId, versionNumber }) => {
|
||||
const queryClient = await prefetchAsset(assetId, type, versionNumber);
|
||||
|
||||
const {
|
||||
has_access,
|
||||
|
@ -55,7 +56,7 @@ export const AppAssetCheckLayout: React.FC<
|
|||
return (
|
||||
<HydrationBoundary state={dehydratedState}>
|
||||
<HydrationBoundaryAssetStore asset={queryData}>
|
||||
<AppAssetLoadingContainer assetId={assetId} type={type}>
|
||||
<AppAssetLoadingContainer assetId={assetId} type={type} versionNumber={versionNumber}>
|
||||
{Component}
|
||||
</AppAssetLoadingContainer>
|
||||
</HydrationBoundaryAssetStore>
|
||||
|
@ -63,15 +64,25 @@ export const AppAssetCheckLayout: React.FC<
|
|||
);
|
||||
};
|
||||
|
||||
const prefetchAsset = async (assetId: string, type: 'metric' | 'dashboard') => {
|
||||
const prefetchAsset = async (
|
||||
assetId: string,
|
||||
type: 'metric' | 'dashboard',
|
||||
versionNumber?: number
|
||||
) => {
|
||||
let queryClient = new QueryClient();
|
||||
|
||||
switch (type) {
|
||||
case 'metric':
|
||||
queryClient = await prefetchGetMetric({ id: assetId }, queryClient);
|
||||
queryClient = await prefetchGetMetric(
|
||||
{ id: assetId, version_number: versionNumber },
|
||||
queryClient
|
||||
);
|
||||
break;
|
||||
case 'dashboard':
|
||||
queryClient = await prefetchGetDashboard({ id: assetId }, queryClient);
|
||||
queryClient = await prefetchGetDashboard(
|
||||
{ id: assetId, version_number: versionNumber },
|
||||
queryClient
|
||||
);
|
||||
break;
|
||||
default:
|
||||
const _exhaustiveCheck: never = type;
|
||||
|
|
|
@ -2,24 +2,23 @@
|
|||
|
||||
import { useGetDashboard } from '@/api/buster_rest/dashboards';
|
||||
import { useGetMetric, useGetMetricData } from '@/api/buster_rest/metrics';
|
||||
import { metricsQueryKeys } from '@/api/query_keys/metric';
|
||||
import { FileIndeterminateLoader } from '@/components/features/FileIndeterminateLoader';
|
||||
import { useMount } from '@/hooks';
|
||||
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import React, { useEffect, useMemo, useState } from 'react';
|
||||
import React, { useMemo } from 'react';
|
||||
|
||||
export const AppAssetLoadingContainer: React.FC<{
|
||||
assetId: string;
|
||||
type: 'metric' | 'dashboard';
|
||||
children: React.ReactNode;
|
||||
}> = React.memo(({ assetId, type, children }) => {
|
||||
versionNumber: number | undefined;
|
||||
}> = React.memo(({ assetId, type, children, versionNumber }) => {
|
||||
const {
|
||||
isFetchedConfig: isFetchedMetricConfig,
|
||||
isFetchedData: isFetchedMetricData,
|
||||
error: metricError
|
||||
} = useGetMetricAssetData({
|
||||
assetId,
|
||||
enabled: type === 'metric'
|
||||
enabled: type === 'metric',
|
||||
versionNumber
|
||||
});
|
||||
const {
|
||||
isFetchedConfig: isFetchedDashboardConfig,
|
||||
|
@ -27,7 +26,8 @@ export const AppAssetLoadingContainer: React.FC<{
|
|||
error: dashboardError
|
||||
} = useGetDashboardAssetData({
|
||||
assetId,
|
||||
enabled: type === 'dashboard'
|
||||
enabled: type === 'dashboard',
|
||||
versionNumber
|
||||
});
|
||||
|
||||
const showLoader = useMemo(() => {
|
||||
|
@ -60,12 +60,22 @@ export const AppAssetLoadingContainer: React.FC<{
|
|||
|
||||
AppAssetLoadingContainer.displayName = 'AppAssetLoadingContainer';
|
||||
|
||||
const useGetMetricAssetData = ({ assetId, enabled }: { assetId: string; enabled: boolean }) => {
|
||||
const useGetMetricAssetData = ({
|
||||
assetId,
|
||||
enabled,
|
||||
versionNumber
|
||||
}: {
|
||||
assetId: string;
|
||||
enabled: boolean;
|
||||
versionNumber: number | undefined;
|
||||
}) => {
|
||||
const { isFetched: isMetricFetched, ...rest } = useGetMetric({
|
||||
id: enabled ? assetId : undefined
|
||||
id: enabled ? assetId : undefined,
|
||||
versionNumber
|
||||
});
|
||||
const { isFetched: isMetricDataFetched } = useGetMetricData({
|
||||
id: enabled ? assetId : undefined
|
||||
id: enabled ? assetId : undefined,
|
||||
versionNumber
|
||||
});
|
||||
|
||||
return {
|
||||
|
@ -75,9 +85,18 @@ const useGetMetricAssetData = ({ assetId, enabled }: { assetId: string; enabled:
|
|||
};
|
||||
};
|
||||
|
||||
const useGetDashboardAssetData = ({ assetId, enabled }: { assetId: string; enabled: boolean }) => {
|
||||
const useGetDashboardAssetData = ({
|
||||
assetId,
|
||||
enabled,
|
||||
versionNumber
|
||||
}: {
|
||||
assetId: string;
|
||||
enabled: boolean;
|
||||
versionNumber: number | undefined;
|
||||
}) => {
|
||||
const { isFetched: isDashboardFetched, error: dashboardError } = useGetDashboard({
|
||||
id: enabled ? assetId : undefined
|
||||
id: enabled ? assetId : undefined,
|
||||
versionNumber
|
||||
});
|
||||
|
||||
return {
|
||||
|
|
|
@ -65,7 +65,7 @@ const FileContainerHeaderStandard: React.FC<{
|
|||
/>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex-1">
|
||||
<div className="flex flex-1 items-center justify-end">
|
||||
<SelectedFileButtons selectedFileView={selectedFileView} selectedFileId={selectedFileId} />
|
||||
</div>
|
||||
</>
|
||||
|
|
|
@ -21,14 +21,13 @@ export const useCloseVersionHistory = () => {
|
|||
chatId: string | undefined;
|
||||
}) => {
|
||||
closeSecondaryView();
|
||||
await timeout(chatId ? 250 : 0);
|
||||
await timeout(chatId ? 250 : 0); //wait for the secondary view to close
|
||||
startTransition(() => {
|
||||
const link = getFileLink({
|
||||
fileId: assetId,
|
||||
fileType: type,
|
||||
chatId
|
||||
});
|
||||
alert(link);
|
||||
if (link) onChangePage(link);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ export const DashboardLayoutContainer: React.FC<{
|
|||
return (
|
||||
<>
|
||||
{children}
|
||||
<MemoizedAddToDashboardModal dashboardId={dashboardId} />
|
||||
{/* <MemoizedAddToDashboardModal dashboardId={dashboardId} /> */}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue