buster/web/src/layouts/ChatLayout/hooks/useSelectedFileAndLayout/initializeSelectedFile.ts

30 lines
578 B
TypeScript

import type { SelectedFile } from '../../interfaces';
import type { ChatURLParsed } from './parsePathnameSegments';
export const initializeSelectedFile = (params: ChatURLParsed): SelectedFile | null => {
const { metricId, collectionId, datasetId, dashboardId, chatId, messageId } = params;
if (metricId) {
return {
id: metricId,
type: 'metric'
};
}
if (dashboardId) {
return {
id: dashboardId,
type: 'dashboard'
};
}
if (messageId) {
return {
id: messageId,
type: 'reasoning'
};
}
return null;
};