diff --git a/web/src/app/app/_layouts/ChatLayout/ChatContainer/ChatContainer.tsx b/web/src/app/app/_layouts/ChatLayout/ChatContainer/ChatContainer.tsx index 5959ae2ca..d5c861ceb 100644 --- a/web/src/app/app/_layouts/ChatLayout/ChatContainer/ChatContainer.tsx +++ b/web/src/app/app/_layouts/ChatLayout/ChatContainer/ChatContainer.tsx @@ -1,36 +1,27 @@ import React, { useMemo, useRef } from 'react'; import type { ChatSplitterProps } from '../ChatLayout'; import { ChatHeader } from './ChatHeader'; -import { SelectedFile } from '../interfaces'; import { ChatContent } from './ChatContent'; import { useScroll } from 'ahooks'; -interface ChatContainerProps { - chatContent: ChatSplitterProps['chatContent']; - selectedFile: SelectedFile | undefined; - isPureFile: boolean; -} +interface ChatContainerProps {} -export const ChatContainer: React.FC = React.memo( - ({ chatContent, selectedFile, isPureFile }) => { - const chatContentRef = useRef(null); - const scroll = useScroll(chatContentRef); +export const ChatContainer: React.FC = React.memo(({}) => { + const chatContentRef = useRef(null); + const scroll = useScroll(chatContentRef); - const showScrollOverflow = useMemo(() => { - if (!chatContentRef.current || !scroll) return false; - const trigger = 50; - return scroll.top > trigger; - }, [chatContentRef, scroll?.top]); + const showScrollOverflow = useMemo(() => { + if (!chatContentRef.current || !scroll) return false; + const trigger = 50; + return scroll.top > trigger; + }, [chatContentRef, scroll?.top]); - if (isPureFile) return null; - - return ( -
- - -
- ); - } -); + return ( +
+ + +
+ ); +}); ChatContainer.displayName = 'ChatContainer'; diff --git a/web/src/app/app/_layouts/ChatLayout/ChatContainer/ChatContent/ChatContent.tsx b/web/src/app/app/_layouts/ChatLayout/ChatContainer/ChatContent/ChatContent.tsx index b3dea89dc..11c4f7982 100644 --- a/web/src/app/app/_layouts/ChatLayout/ChatContainer/ChatContent/ChatContent.tsx +++ b/web/src/app/app/_layouts/ChatLayout/ChatContainer/ChatContent/ChatContent.tsx @@ -21,12 +21,10 @@ const colors = [ export const ChatContent: React.FC<{ chatContentRef: React.RefObject }> = ({ chatContentRef }) => { - const hasFile = useChatSplitterContextSelector((state) => state.hasFile); - return (
- {Array.from({ length: 350 }).map((_, index) => ( + {Array.from({ length: 150 }).map((_, index) => ( ))}
diff --git a/web/src/app/app/_layouts/ChatLayout/ChatContainer/ChatHeader/ChatHeader.tsx b/web/src/app/app/_layouts/ChatLayout/ChatContainer/ChatHeader/ChatHeader.tsx index cd82eb8ef..45ff892ba 100644 --- a/web/src/app/app/_layouts/ChatLayout/ChatContainer/ChatHeader/ChatHeader.tsx +++ b/web/src/app/app/_layouts/ChatLayout/ChatContainer/ChatHeader/ChatHeader.tsx @@ -7,9 +7,8 @@ import { ChatHeaderOptions } from './ChatHeaderOptions'; import { ChatHeaderTitle } from './ChatHeaderTitle'; export const ChatHeader: React.FC<{ - selectedFile: SelectedFile | undefined; showScrollOverflow: boolean; -}> = React.memo(({ selectedFile, showScrollOverflow }) => { +}> = React.memo(({ showScrollOverflow }) => { const { cx, styles } = useStyles(); const hasFile = useChatSplitterContextSelector((state) => state.hasFile); diff --git a/web/src/app/app/_layouts/ChatLayout/ChatContainer/ChatHeader/ChatHeaderOptions/ChatHeaderDropdown.tsx b/web/src/app/app/_layouts/ChatLayout/ChatContainer/ChatHeader/ChatHeaderOptions/ChatHeaderDropdown.tsx index 329755859..4f71ab804 100644 --- a/web/src/app/app/_layouts/ChatLayout/ChatContainer/ChatHeader/ChatHeaderOptions/ChatHeaderDropdown.tsx +++ b/web/src/app/app/_layouts/ChatLayout/ChatContainer/ChatHeader/ChatHeaderOptions/ChatHeaderDropdown.tsx @@ -9,7 +9,8 @@ export const ChatContainerHeaderDropdown: React.FC<{ const selectedFileType = useChatSplitterContextSelector((state) => state.selectedFileType); const menuItem: MenuProps['items'] = useMemo(() => { - if (!selectedFileType) return [] as MenuProps['items']; + if (!selectedFileType || !(selectedFileType in HeaderOptionsRecord)) + return [] as MenuProps['items']; return HeaderOptionsRecord[selectedFileType](); }, [selectedFileType]); diff --git a/web/src/app/app/_layouts/ChatLayout/ChatContainer/ChatHeader/ChatHeaderOptions/config.tsx b/web/src/app/app/_layouts/ChatLayout/ChatContainer/ChatHeader/ChatHeaderOptions/config.tsx index fdbdfdf28..f67e2a437 100644 --- a/web/src/app/app/_layouts/ChatLayout/ChatContainer/ChatHeader/ChatHeaderOptions/config.tsx +++ b/web/src/app/app/_layouts/ChatLayout/ChatContainer/ChatHeader/ChatHeaderOptions/config.tsx @@ -30,12 +30,5 @@ export const HeaderOptionsRecord: Record MenuProps key: 'delete', icon: } - ], - chat: () => [ - { - label: 'Delete', - key: 'delete', - icon: - } ] }; diff --git a/web/src/app/app/_layouts/ChatLayout/ChatLayout.tsx b/web/src/app/app/_layouts/ChatLayout/ChatLayout.tsx index c20385e55..174332081 100644 --- a/web/src/app/app/_layouts/ChatLayout/ChatLayout.tsx +++ b/web/src/app/app/_layouts/ChatLayout/ChatLayout.tsx @@ -10,56 +10,52 @@ import { SelectedFile } from './interfaces'; import { useUpdateEffect, useUpdateLayoutEffect } from 'ahooks'; export interface ChatSplitterProps { - chatContent?: React.ReactNode; showChatCollapse?: boolean; - defaultShowLayout?: 'chat' | 'file' | 'both'; - defaultSelectedFile?: SelectedFile; + selectedLayout?: 'chat' | 'file' | 'both'; + selectedFile?: SelectedFile; } export const ChatLayout: React.FC = React.memo( - ({ defaultSelectedFile, defaultShowLayout = 'chat', chatContent }) => { + ({ selectedFile, selectedLayout = 'chat' }) => { const appSplitterRef = useRef(null); - const [isPureFile, setIsPureFile] = useState(defaultShowLayout === 'file'); + const [isPureFile, setIsPureFile] = useState(selectedLayout === 'file'); const defaultSplitterLayout = useMemo(() => { - if (defaultShowLayout === 'chat') return ['100%', '0%']; - if (defaultShowLayout === 'file') return ['0%', '100%']; + if (selectedLayout === 'chat') return ['100%', '0%']; + if (selectedLayout === 'file') return ['0%', '100%']; return ['325px', 'auto']; - }, [defaultShowLayout]); + }, [selectedLayout]); - const useChatSplitterProps = useChatLayout({ defaultSelectedFile }); - const { onSetSelectedFile, selectedFile, hasFile } = useChatSplitterProps; + const useChatSplitterProps = useChatLayout({ selectedFile }); + const { onSetSelectedFile, hasFile, selectedFileId } = useChatSplitterProps; useUpdateEffect(() => { - if (defaultSelectedFile && appSplitterRef.current) { - if (defaultShowLayout === 'chat') { + if (appSplitterRef.current) { + if (selectedLayout === 'chat') { appSplitterRef.current?.animateWidth('100%', 'left'); - } else if (defaultShowLayout === 'file') { + } else if (selectedLayout === 'file') { appSplitterRef.current?.animateWidth('100%', 'right'); - } else if (appSplitterRef.current.isRightClosed || appSplitterRef.current.isLeftClosed) { + } else if ( + selectedLayout === 'both' && + (appSplitterRef.current.isRightClosed || appSplitterRef.current.isLeftClosed) + ) { appSplitterRef.current?.animateWidth('320px', 'left'); } } - if (defaultSelectedFile) onSetSelectedFile(defaultSelectedFile); - }, [defaultSelectedFile, defaultShowLayout]); + if (selectedFile) onSetSelectedFile(selectedFile); + }, [selectedFile, selectedLayout]); useUpdateLayoutEffect(() => { - if (isPureFile === true) setIsPureFile(defaultShowLayout === 'file'); - }, [defaultShowLayout]); + if (isPureFile === true) setIsPureFile(selectedLayout === 'file'); + }, [selectedLayout]); return ( - } - rightChildren={} + leftChildren={isPureFile ? null : } + rightChildren={!selectedFileId ? null : } autoSaveId="chat-splitter" defaultLayout={defaultSplitterLayout} preserveSide="left" diff --git a/web/src/app/app/_layouts/ChatLayout/ChatLayoutContext/ChatLayoutContext.tsx b/web/src/app/app/_layouts/ChatLayout/ChatLayoutContext/ChatLayoutContext.tsx index c4ab0be85..56f37762c 100644 --- a/web/src/app/app/_layouts/ChatLayout/ChatLayoutContext/ChatLayoutContext.tsx +++ b/web/src/app/app/_layouts/ChatLayout/ChatLayoutContext/ChatLayoutContext.tsx @@ -7,31 +7,31 @@ import React, { PropsWithChildren, useMemo, useState } from 'react'; import { SelectedFile } from '../interfaces'; interface UseChatSplitterProps { - defaultSelectedFile: SelectedFile | undefined; + selectedFile: SelectedFile | undefined; } -export const useChatLayout = ({ defaultSelectedFile }: UseChatSplitterProps) => { - const [selectedFile, setSelectedFile] = - useState(defaultSelectedFile); +export const useChatLayout = ({ selectedFile: selectedFileProp }: UseChatSplitterProps) => { + const [selectedFileId, setSelectedFileId] = useState(selectedFileProp?.id); - const hasFile = !!selectedFile; + const hasFile = !!selectedFileId; const selectedFileTitle: string = useMemo(() => { - if (!selectedFile) return ''; - return selectedFile.type; - }, [selectedFile]); + console.log('selectedFileId', selectedFileId); + if (!selectedFileId) return ''; + return 'test'; + }, [selectedFileId]); - const selectedFileType = selectedFile?.type || null; + const selectedFileType = selectedFileProp?.type; const onSetSelectedFile = (file: SelectedFile) => { - setSelectedFile(file); + // setSelectedFileId(file.id); }; return { selectedFileTitle, selectedFileType, + selectedFileId, hasFile, - selectedFile, onSetSelectedFile }; }; diff --git a/web/src/app/app/_layouts/ChatLayout/FileContainer/FileContainer.tsx b/web/src/app/app/_layouts/ChatLayout/FileContainer/FileContainer.tsx index f7a38d9e8..229d3f11b 100644 --- a/web/src/app/app/_layouts/ChatLayout/FileContainer/FileContainer.tsx +++ b/web/src/app/app/_layouts/ChatLayout/FileContainer/FileContainer.tsx @@ -2,11 +2,9 @@ import React from 'react'; import type { ChatSplitterProps } from '../ChatLayout'; import { SelectedFile } from '../interfaces'; -interface FileContainerProps { - selectedFile: SelectedFile | undefined; -} +interface FileContainerProps {} -export const FileContainer: React.FC = React.memo(({ selectedFile }) => { +export const FileContainer: React.FC = React.memo(({}) => { return
FileContainer
; }); diff --git a/web/src/app/app/_layouts/ChatLayout/hooks/useDefaultFile.ts b/web/src/app/app/_layouts/ChatLayout/hooks/useDefaultFile.ts index 8af3803d6..5bec243fe 100644 --- a/web/src/app/app/_layouts/ChatLayout/hooks/useDefaultFile.ts +++ b/web/src/app/app/_layouts/ChatLayout/hooks/useDefaultFile.ts @@ -6,7 +6,7 @@ import { useParams } from 'next/navigation'; import { AppChatMessageFileType } from '@/components/messages/AppChatMessageContainer'; import { ChatSplitterProps } from '../ChatLayout'; -export const useDefaultFile = () => { +export const useSelectedFileByParams = () => { const { metricId, collectionId, datasetId, dashboardId, chatId } = useParams() as { metricId?: string; collectionId?: string; @@ -15,15 +15,14 @@ export const useDefaultFile = () => { chatId?: string; }; - const defaultFile: SelectedFile | undefined = useMemo(() => { + const selectedFile: SelectedFile | undefined = useMemo(() => { if (metricId) return { id: metricId, type: AppChatMessageFileType.Metric }; if (collectionId) return { id: collectionId, type: AppChatMessageFileType.Collection }; if (datasetId) return { id: datasetId, type: AppChatMessageFileType.Dataset }; if (dashboardId) return { id: dashboardId, type: AppChatMessageFileType.Dashboard }; - if (chatId) return { id: chatId, type: AppChatMessageFileType.Chat }; }, [metricId, collectionId, datasetId, dashboardId, chatId]); - const defaultLayout: ChatSplitterProps['defaultShowLayout'] = useMemo(() => { + const selectedLayout: ChatSplitterProps['selectedLayout'] = useMemo(() => { const hasFileId = metricId || collectionId || datasetId || dashboardId; if (chatId) { @@ -36,5 +35,5 @@ export const useDefaultFile = () => { return 'chat'; }, [metricId, collectionId, datasetId, dashboardId, chatId]); - return { defaultFile, defaultLayout }; + return { selectedFile, selectedLayout }; }; diff --git a/web/src/app/app/collections/[collectionId]/metrics/[threadId]/page.tsx b/web/src/app/app/collections/[collectionId]/metrics/[threadId]/page.tsx index 174f81f29..cdff80275 100644 --- a/web/src/app/app/collections/[collectionId]/metrics/[threadId]/page.tsx +++ b/web/src/app/app/collections/[collectionId]/metrics/[threadId]/page.tsx @@ -1,5 +1,5 @@ import { ThreadContentController } from '@/app/app/_controllers/ThreadController'; -import { AppAssetCheckLayout } from '@/app/app/_layouts'; +import { AppAssetCheckLayout } from '../../../../_layouts/AppAssetCheckLayout'; import { getAppSplitterLayout } from '@/components/layout'; import React from 'react'; diff --git a/web/src/app/app/dashboards/[dashboardId]/metrics/[threadId]/page.tsx b/web/src/app/app/dashboards/[dashboardId]/metrics/[threadId]/page.tsx index f3cb1ace4..56c9f0648 100644 --- a/web/src/app/app/dashboards/[dashboardId]/metrics/[threadId]/page.tsx +++ b/web/src/app/app/dashboards/[dashboardId]/metrics/[threadId]/page.tsx @@ -1,5 +1,5 @@ import { ThreadContentController } from '@/app/app/_controllers/ThreadController'; -import { AppAssetCheckLayout } from '@/app/app/_layouts'; +import { AppAssetCheckLayout } from '../../../../_layouts/AppAssetCheckLayout'; import { getAppSplitterLayout } from '@/components/layout'; import React from 'react'; diff --git a/web/src/app/app/dashboards/[dashboardId]/page.tsx b/web/src/app/app/dashboards/[dashboardId]/page.tsx index 7954e66ac..e71b9dc98 100644 --- a/web/src/app/app/dashboards/[dashboardId]/page.tsx +++ b/web/src/app/app/dashboards/[dashboardId]/page.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { DashboardIndividualHeader } from './_DashboardIndividualHeader'; import { DashboardIndividualContent } from './_DashboardIndividualContent'; -import { AppAssetCheckLayout } from '../../_layouts'; +import { AppAssetCheckLayout } from '../../_layouts/AppAssetCheckLayout'; export default function DashboardPage({ params: { dashboardId } diff --git a/web/src/app/test/splitter/layout.tsx b/web/src/app/test/splitter/layout.tsx index 415b14c72..b459d9291 100644 --- a/web/src/app/test/splitter/layout.tsx +++ b/web/src/app/test/splitter/layout.tsx @@ -1,12 +1,12 @@ 'use client'; -import { ChatLayout, useDefaultFile } from '@chatLayout/index'; +import { ChatLayout, useSelectedFileByParams } from '@chatLayout/index'; import { AppChatMessageFileType } from '@/components/messages/AppChatMessageContainer'; import { useRouter } from 'next/navigation'; import { useHotkeys } from 'react-hotkeys-hook'; export default function Layout({}: {}) { - const { defaultFile, defaultLayout } = useDefaultFile(); + const { selectedFile, selectedLayout } = useSelectedFileByParams(); const router = useRouter(); useHotkeys('m', () => { @@ -31,7 +31,7 @@ export default function Layout({}: {}) { return (
- +
); } diff --git a/web/src/components/messages/AppChatMessageContainer/interfaces.ts b/web/src/components/messages/AppChatMessageContainer/interfaces.ts index 8b101deb0..4a723f4d4 100644 --- a/web/src/components/messages/AppChatMessageContainer/interfaces.ts +++ b/web/src/components/messages/AppChatMessageContainer/interfaces.ts @@ -34,8 +34,7 @@ export enum AppChatMessageFileType { Dataset = 'dataset', Collection = 'collection', Metric = 'metric', - Dashboard = 'dashboard', - Chat = 'chat' + Dashboard = 'dashboard' } export type AppChatMessageFile = {