mirror of https://github.com/buster-so/buster.git
embedded route check
This commit is contained in:
parent
88e3e1e6c5
commit
68b8fc4b4b
|
@ -1,9 +1,11 @@
|
|||
import { useMatch, useMatches } from '@tanstack/react-router';
|
||||
import { useMatch, useMatches, useMatchRoute } from '@tanstack/react-router';
|
||||
import { Route as EmbedRoute } from '@/routes/embed';
|
||||
|
||||
export const useIsEmbed = () => {
|
||||
const match = useMatch({
|
||||
from: '/embed',
|
||||
const matchRoute = useMatchRoute();
|
||||
const matches = matchRoute({
|
||||
to: EmbedRoute.id,
|
||||
fuzzy: true,
|
||||
});
|
||||
console.log(match);
|
||||
return !!match?.id;
|
||||
return !!matches;
|
||||
};
|
||||
|
|
|
@ -8,9 +8,12 @@ import {
|
|||
import findLast from 'lodash/findLast';
|
||||
|
||||
export const useSelectedAssetType = (): NonNullable<StaticDataRouteOption['assetType']> => {
|
||||
const matches = useMatches();
|
||||
const lastMatch = useMatches({
|
||||
select: (matches) => {
|
||||
return findLast(matches, (match) => match.staticData?.assetType);
|
||||
},
|
||||
});
|
||||
|
||||
const lastMatch = findLast(matches, (match) => match.staticData?.assetType);
|
||||
if (typeof lastMatch === 'number') {
|
||||
return 'chat';
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import React, { useCallback, useMemo } from 'react';
|
||||
import type { BusterChatMessage, BusterChatResponseMessage_file } from '@/api/asset_interfaces';
|
||||
import { useGetChatMessage } from '@/api/buster_rest/chats';
|
||||
import { useIsEmbed } from '@/context/BusterAssets/useIsEmbed';
|
||||
import { createChatAssetRoute } from '@/lib/routes/createSimpleAssetRoute';
|
||||
import type { ILinkProps } from '@/types/routes';
|
||||
import type { ChatResponseMessageProps } from '../ChatResponseMessageSelector';
|
||||
|
@ -21,12 +22,14 @@ export const ChatResponseMessage_File: React.FC<ChatResponseMessageProps> = Reac
|
|||
const { file_type } = responseMessage;
|
||||
|
||||
const { isSelectedFile } = useGetIsSelectedFile({ responseMessage });
|
||||
const isEmbed = useIsEmbed();
|
||||
|
||||
const linkParams = createChatAssetRoute({
|
||||
asset_type: file_type,
|
||||
id: responseMessage.id,
|
||||
chatId,
|
||||
versionNumber: responseMessage.version_number,
|
||||
isEmbed,
|
||||
}) as unknown as ILinkProps;
|
||||
|
||||
const SelectedComponent = useMemo(() => {
|
||||
|
|
|
@ -59,8 +59,16 @@ export const createChatAssetRoute = (asset: {
|
|||
id: string | undefined;
|
||||
chatId: string;
|
||||
versionNumber?: number;
|
||||
isEmbed: boolean;
|
||||
}) => {
|
||||
if (asset.asset_type === 'chat' || !asset.asset_type || !asset.id) {
|
||||
if (asset.isEmbed) {
|
||||
return defineLink({
|
||||
to: '/embed/chats/$chatId',
|
||||
params: { chatId: asset.chatId },
|
||||
});
|
||||
}
|
||||
|
||||
return defineLink({
|
||||
to: '/app/chats/$chatId',
|
||||
params: { chatId: asset.chatId },
|
||||
|
@ -68,6 +76,13 @@ export const createChatAssetRoute = (asset: {
|
|||
}
|
||||
|
||||
if (asset.asset_type === 'metric_file') {
|
||||
if (asset.isEmbed) {
|
||||
return defineLink({
|
||||
to: '/embed/chats/$chatId/metrics/$metricId',
|
||||
params: { metricId: asset.id || '', chatId: asset.chatId },
|
||||
search: { metric_version_number: asset.versionNumber },
|
||||
});
|
||||
}
|
||||
return defineLink({
|
||||
to: '/app/chats/$chatId/metrics/$metricId',
|
||||
params: { metricId: asset.id || '', chatId: asset.chatId },
|
||||
|
@ -76,6 +91,13 @@ export const createChatAssetRoute = (asset: {
|
|||
}
|
||||
|
||||
if (asset.asset_type === 'dashboard_file') {
|
||||
if (asset.isEmbed) {
|
||||
return defineLink({
|
||||
to: '/embed/chats/$chatId/dashboards/$dashboardId',
|
||||
params: { dashboardId: asset.id || '', chatId: asset.chatId },
|
||||
search: { dashboard_version_number: asset.versionNumber },
|
||||
});
|
||||
}
|
||||
return defineLink({
|
||||
to: '/app/chats/$chatId/dashboards/$dashboardId',
|
||||
params: { dashboardId: asset.id || '', chatId: asset.chatId },
|
||||
|
@ -84,6 +106,13 @@ export const createChatAssetRoute = (asset: {
|
|||
}
|
||||
|
||||
if (asset.asset_type === 'report_file') {
|
||||
if (asset.isEmbed) {
|
||||
return defineLink({
|
||||
to: '/embed/chats/$chatId/reports/$reportId',
|
||||
params: { reportId: asset.id || '', chatId: asset.chatId },
|
||||
search: { report_version_number: asset.versionNumber },
|
||||
});
|
||||
}
|
||||
return defineLink({
|
||||
to: '/app/chats/$chatId/reports/$reportId',
|
||||
params: { reportId: asset.id || '', chatId: asset.chatId },
|
||||
|
@ -92,6 +121,12 @@ export const createChatAssetRoute = (asset: {
|
|||
}
|
||||
|
||||
if (asset.asset_type === 'reasoning') {
|
||||
if (asset.isEmbed) {
|
||||
return defineLink({
|
||||
to: '/embed/chats/$chatId/reasoning/$messageId',
|
||||
params: { messageId: asset.id || '', chatId: asset.chatId },
|
||||
});
|
||||
}
|
||||
return defineLink({
|
||||
to: '/app/chats/$chatId/reasoning/$messageId',
|
||||
params: { chatId: asset.chatId, messageId: asset.id || '' },
|
||||
|
@ -99,6 +134,12 @@ export const createChatAssetRoute = (asset: {
|
|||
}
|
||||
|
||||
if (asset.asset_type === 'collection') {
|
||||
if (asset.isEmbed) {
|
||||
console.warn('collection is actually not supported for embeds...', asset.id);
|
||||
return defineLink({
|
||||
to: '/auth/login',
|
||||
});
|
||||
}
|
||||
return defineLink({
|
||||
to: '/app/collections/$collectionId',
|
||||
params: { collectionId: asset.id || '' },
|
||||
|
|
Loading…
Reference in New Issue