mirror of https://github.com/buster-so/buster.git
Add additional type checks
This commit is contained in:
parent
26108e8029
commit
824ee25ef8
|
@ -20,7 +20,7 @@ export const useGetDashboardVersionNumber = (
|
|||
|
||||
// Get the dashboard_version_number query param from the route
|
||||
const paramVersionNumber = useSearch({
|
||||
from: '/app/_app/_asset/dashboards/$dashboardId',
|
||||
from: '/app/_app/_asset/dashboards/$dashboardId/',
|
||||
shouldThrow: false,
|
||||
select: stableVersionSearchSelector,
|
||||
});
|
||||
|
|
|
@ -3,25 +3,43 @@ import type { OptionsTo } from '@/types/routes';
|
|||
|
||||
export const getFavoriteRoute = (favorite: Pick<UserFavorite, 'asset_type' | 'id'>): OptionsTo => {
|
||||
if (favorite.asset_type === 'chat') {
|
||||
return { to: '/app/chats/$chatId', params: { chatId: favorite.id } };
|
||||
return {
|
||||
to: '/app/chats/$chatId',
|
||||
params: { chatId: favorite.id },
|
||||
} as const satisfies OptionsTo;
|
||||
}
|
||||
|
||||
if (favorite.asset_type === 'metric') {
|
||||
return { to: '/app/metrics/$metricId', params: { metricId: favorite.id } };
|
||||
return {
|
||||
to: '/app/metrics/$metricId',
|
||||
params: { metricId: favorite.id },
|
||||
} as const satisfies OptionsTo;
|
||||
}
|
||||
|
||||
if (favorite.asset_type === 'dashboard') {
|
||||
return { to: '/app/dashboards/$dashboardId', params: { dashboardId: favorite.id } };
|
||||
return {
|
||||
to: '/app/dashboards/$dashboardId',
|
||||
params: { dashboardId: favorite.id },
|
||||
} as const satisfies OptionsTo;
|
||||
}
|
||||
|
||||
if (favorite.asset_type === 'collection') {
|
||||
return { to: '/app/collections/$collectionId', params: { collectionId: favorite.id } };
|
||||
return {
|
||||
to: '/app/collections/$collectionId',
|
||||
params: { collectionId: favorite.id },
|
||||
} as const satisfies OptionsTo;
|
||||
}
|
||||
|
||||
if (favorite.asset_type === 'report') {
|
||||
return { to: '/app/reports/$reportId', params: { reportId: favorite.id } };
|
||||
return {
|
||||
to: '/app/reports/$reportId',
|
||||
params: { reportId: favorite.id },
|
||||
} as const satisfies OptionsTo;
|
||||
}
|
||||
|
||||
const _exhaustiveCheck: never = favorite.asset_type;
|
||||
return { to: '/app/chats/$chatId', params: { chatId: favorite.id } };
|
||||
return {
|
||||
to: '/app/chats/$chatId',
|
||||
params: { chatId: favorite.id },
|
||||
} as const satisfies OptionsTo;
|
||||
};
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
import type {
|
||||
ActiveOptions,
|
||||
LinkProps,
|
||||
RegisteredRouter,
|
||||
ValidateLinkOptions,
|
||||
} from '@tanstack/react-router';
|
||||
import type { LinkProps, RegisteredRouter } from '@tanstack/react-router';
|
||||
import type React from 'react';
|
||||
import type { LinkOptionsTo, OptionsTo } from '@/types/routes';
|
||||
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
import type { AssetType } from '@buster/server-shared/assets';
|
||||
import type { QueryClient } from '@tanstack/react-query';
|
||||
import {
|
||||
type AnyRoute,
|
||||
type BeforeLoadContextOptions,
|
||||
type BeforeLoadContextParameter,
|
||||
type BeforeLoadFn,
|
||||
redirect,
|
||||
} from '@tanstack/react-router';
|
||||
import { MatchRoute, redirect } from '@tanstack/react-router';
|
||||
import { z } from 'zod';
|
||||
import { prefetchGetMetric } from '@/api/buster_rest/metrics';
|
||||
import type { AppRouterContext } from '@/router';
|
||||
|
@ -26,7 +20,7 @@ export const beforeLoad: any = async ({
|
|||
params,
|
||||
search,
|
||||
}: {
|
||||
matches: { routeId: FileRouteTypes['id'] }[];
|
||||
matches: { routeId: FileRouteTypes['id']; fullPath: FileRouteTypes['fullPaths'] }[];
|
||||
params: {
|
||||
metricId: string;
|
||||
};
|
||||
|
@ -40,7 +34,8 @@ export const beforeLoad: any = async ({
|
|||
if (isIndexRoute) {
|
||||
throw redirect({
|
||||
//relative path required the use of as...
|
||||
to: './chart' as '/app/metrics/$metricId/chart',
|
||||
from: lastMatch.fullPath,
|
||||
to: './chart',
|
||||
params,
|
||||
search,
|
||||
});
|
||||
|
|
|
@ -1,14 +1,6 @@
|
|||
import { createFileRoute, redirect } from '@tanstack/react-router';
|
||||
import { z } from 'zod';
|
||||
import { Route as MetricRoute } from './metrics.$metricId';
|
||||
import { createFileRoute } from '@tanstack/react-router';
|
||||
import * as metricServerContext from '@/context/BusterAssets/metric-server/metricIndexServerAssetContext';
|
||||
|
||||
export const Route = createFileRoute('/app/_app/_asset/dashboards/$dashboardId/metrics/$metricId')({
|
||||
staticData: {
|
||||
assetType: 'metric',
|
||||
},
|
||||
component: RouteComponent,
|
||||
...metricServerContext,
|
||||
});
|
||||
|
||||
function RouteComponent() {
|
||||
return <div>Hello "/app/_app/dashboards/$dashboardId/metrics/$metricId"!</div>;
|
||||
}
|
||||
|
|
|
@ -3,4 +3,5 @@ import * as metricServerContext from '@/context/BusterAssets/metric-server/metri
|
|||
|
||||
export const Route = createFileRoute('/app/_app/_asset/metrics/$metricId')({
|
||||
...metricServerContext,
|
||||
component: Outlet,
|
||||
});
|
||||
|
|
|
@ -13,6 +13,6 @@ export const Route = createFileRoute('/auth/logout')({
|
|||
preload: false,
|
||||
loader: async () => {
|
||||
await signOut();
|
||||
redirect({ to: '/auth/login' });
|
||||
throw redirect({ to: '/auth/login' });
|
||||
},
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue