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
|
// Get the dashboard_version_number query param from the route
|
||||||
const paramVersionNumber = useSearch({
|
const paramVersionNumber = useSearch({
|
||||||
from: '/app/_app/_asset/dashboards/$dashboardId',
|
from: '/app/_app/_asset/dashboards/$dashboardId/',
|
||||||
shouldThrow: false,
|
shouldThrow: false,
|
||||||
select: stableVersionSearchSelector,
|
select: stableVersionSearchSelector,
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,25 +3,43 @@ import type { OptionsTo } from '@/types/routes';
|
||||||
|
|
||||||
export const getFavoriteRoute = (favorite: Pick<UserFavorite, 'asset_type' | 'id'>): OptionsTo => {
|
export const getFavoriteRoute = (favorite: Pick<UserFavorite, 'asset_type' | 'id'>): OptionsTo => {
|
||||||
if (favorite.asset_type === 'chat') {
|
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') {
|
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') {
|
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') {
|
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') {
|
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;
|
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 {
|
import type { LinkProps, RegisteredRouter } from '@tanstack/react-router';
|
||||||
ActiveOptions,
|
|
||||||
LinkProps,
|
|
||||||
RegisteredRouter,
|
|
||||||
ValidateLinkOptions,
|
|
||||||
} from '@tanstack/react-router';
|
|
||||||
import type React from 'react';
|
import type React from 'react';
|
||||||
import type { LinkOptionsTo, OptionsTo } from '@/types/routes';
|
import type { LinkOptionsTo, OptionsTo } from '@/types/routes';
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,6 @@
|
||||||
import type { AssetType } from '@buster/server-shared/assets';
|
import type { AssetType } from '@buster/server-shared/assets';
|
||||||
import type { QueryClient } from '@tanstack/react-query';
|
import type { QueryClient } from '@tanstack/react-query';
|
||||||
import {
|
import { MatchRoute, redirect } from '@tanstack/react-router';
|
||||||
type AnyRoute,
|
|
||||||
type BeforeLoadContextOptions,
|
|
||||||
type BeforeLoadContextParameter,
|
|
||||||
type BeforeLoadFn,
|
|
||||||
redirect,
|
|
||||||
} from '@tanstack/react-router';
|
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import { prefetchGetMetric } from '@/api/buster_rest/metrics';
|
import { prefetchGetMetric } from '@/api/buster_rest/metrics';
|
||||||
import type { AppRouterContext } from '@/router';
|
import type { AppRouterContext } from '@/router';
|
||||||
|
@ -26,7 +20,7 @@ export const beforeLoad: any = async ({
|
||||||
params,
|
params,
|
||||||
search,
|
search,
|
||||||
}: {
|
}: {
|
||||||
matches: { routeId: FileRouteTypes['id'] }[];
|
matches: { routeId: FileRouteTypes['id']; fullPath: FileRouteTypes['fullPaths'] }[];
|
||||||
params: {
|
params: {
|
||||||
metricId: string;
|
metricId: string;
|
||||||
};
|
};
|
||||||
|
@ -40,7 +34,8 @@ export const beforeLoad: any = async ({
|
||||||
if (isIndexRoute) {
|
if (isIndexRoute) {
|
||||||
throw redirect({
|
throw redirect({
|
||||||
//relative path required the use of as...
|
//relative path required the use of as...
|
||||||
to: './chart' as '/app/metrics/$metricId/chart',
|
from: lastMatch.fullPath,
|
||||||
|
to: './chart',
|
||||||
params,
|
params,
|
||||||
search,
|
search,
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,14 +1,6 @@
|
||||||
import { createFileRoute, redirect } from '@tanstack/react-router';
|
import { createFileRoute } from '@tanstack/react-router';
|
||||||
import { z } from 'zod';
|
import * as metricServerContext from '@/context/BusterAssets/metric-server/metricIndexServerAssetContext';
|
||||||
import { Route as MetricRoute } from './metrics.$metricId';
|
|
||||||
|
|
||||||
export const Route = createFileRoute('/app/_app/_asset/dashboards/$dashboardId/metrics/$metricId')({
|
export const Route = createFileRoute('/app/_app/_asset/dashboards/$dashboardId/metrics/$metricId')({
|
||||||
staticData: {
|
...metricServerContext,
|
||||||
assetType: 'metric',
|
|
||||||
},
|
|
||||||
component: RouteComponent,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
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')({
|
export const Route = createFileRoute('/app/_app/_asset/metrics/$metricId')({
|
||||||
...metricServerContext,
|
...metricServerContext,
|
||||||
|
component: Outlet,
|
||||||
});
|
});
|
||||||
|
|
|
@ -13,6 +13,6 @@ export const Route = createFileRoute('/auth/logout')({
|
||||||
preload: false,
|
preload: false,
|
||||||
loader: async () => {
|
loader: async () => {
|
||||||
await signOut();
|
await signOut();
|
||||||
redirect({ to: '/auth/login' });
|
throw redirect({ to: '/auth/login' });
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue