diff --git a/web/src/api/buster_socket/chats/chatResponses.ts b/web/src/api/buster_socket/chats/chatResponses.ts index a3145968a..8e38f5a19 100644 --- a/web/src/api/buster_socket/chats/chatResponses.ts +++ b/web/src/api/buster_socket/chats/chatResponses.ts @@ -7,7 +7,7 @@ import { } from './eventInterfaces'; export enum ChatsResponses { - '/chats/list:getChatsList' = '/chats/list:getChatsList', + '/chats/list:getThreadsList' = '/chats/list:getThreadsList', '/chats/unsubscribe:unsubscribe' = '/chats/unsubscribe:unsubscribe', '/chats/get:getChat' = '/chats/get:getChat', '/chats/post:initializeChat' = '/chats/post:initializeChat', @@ -20,7 +20,7 @@ export enum ChatsResponses { } export type ChatList_getChatsList = { - route: '/chats/list:getChatsList'; + route: '/chats/list:getThreadsList'; callback: (d: BusterChatListItem[]) => void; onError?: (d: unknown | RustApiError) => void; }; diff --git a/web/src/api/buster_socket_query/useSocketQueryEmitOn.tsx b/web/src/api/buster_socket_query/useSocketQueryEmitOn.tsx index 14062fc90..be41f0eee 100644 --- a/web/src/api/buster_socket_query/useSocketQueryEmitOn.tsx +++ b/web/src/api/buster_socket_query/useSocketQueryEmitOn.tsx @@ -56,7 +56,10 @@ export const useSocketQueryEmitOn = < } as UseQueryOptions; }, [options.queryKey, enabledTrigger]); - const queryResult = useSocketQueryOn({ responseEvent, options: emitOptions, callback }); - - return { ...queryResult }; + return useSocketQueryOn({ + responseEvent, + options: emitOptions, + callback, + isEmitOn: true + }); }; diff --git a/web/src/api/buster_socket_query/useSocketQueryOn.tsx b/web/src/api/buster_socket_query/useSocketQueryOn.tsx index e55703821..05d2e615d 100644 --- a/web/src/api/buster_socket_query/useSocketQueryOn.tsx +++ b/web/src/api/buster_socket_query/useSocketQueryOn.tsx @@ -23,7 +23,8 @@ export const useSocketQueryOn = < >({ responseEvent, options, - callback + callback, + isEmitOn }: { responseEvent: TRoute; options?: UseQueryOptions | null; @@ -33,6 +34,7 @@ export const useSocketQueryOn = < newData: InferBusterSocketResponseData ) => TData | undefined | void) | null; + isEmitOn?: boolean; }): UseSocketQueryOnResult => { const busterSocket = useBusterWebSocket(); const queryClient = useQueryClient(); @@ -63,7 +65,7 @@ export const useSocketQueryOn = < useMount(() => { const hasCallbacks = busterSocket.getCurrentListeners(responseEvent).length > 0; - if (!hasCallbacks) busterSocket.on(socketConfig); + if (!hasCallbacks || isEmitOn) busterSocket.on(socketConfig); }); useUnmount(() => { diff --git a/web/src/api/query_keys/terms.ts b/web/src/api/query_keys/terms.ts index 4d87be92a..1c152609f 100644 --- a/web/src/api/query_keys/terms.ts +++ b/web/src/api/query_keys/terms.ts @@ -13,6 +13,6 @@ export const termsGetTerm = (termId: string) => }); export const termsQueryKeys = { - '/terms/list:getTermsList': termsGetList, - '/terms/get:getTerm': termsGetTerm + termsGetList, + termsGetTerm }; diff --git a/web/src/app/app/(chat_experience)/chat/[chatId]/collection/[collectionId]/page.tsx b/web/src/app/app/(chat_experience)/chats/[chatId]/collection/[collectionId]/page.tsx similarity index 100% rename from web/src/app/app/(chat_experience)/chat/[chatId]/collection/[collectionId]/page.tsx rename to web/src/app/app/(chat_experience)/chats/[chatId]/collection/[collectionId]/page.tsx diff --git a/web/src/app/app/(chat_experience)/chat/[chatId]/dashboard/[dashboardId]/page.tsx b/web/src/app/app/(chat_experience)/chats/[chatId]/dashboard/[dashboardId]/page.tsx similarity index 100% rename from web/src/app/app/(chat_experience)/chat/[chatId]/dashboard/[dashboardId]/page.tsx rename to web/src/app/app/(chat_experience)/chats/[chatId]/dashboard/[dashboardId]/page.tsx diff --git a/web/src/app/app/(chat_experience)/chat/[chatId]/dataset/[datasetId]/page.tsx b/web/src/app/app/(chat_experience)/chats/[chatId]/dataset/[datasetId]/page.tsx similarity index 100% rename from web/src/app/app/(chat_experience)/chat/[chatId]/dataset/[datasetId]/page.tsx rename to web/src/app/app/(chat_experience)/chats/[chatId]/dataset/[datasetId]/page.tsx diff --git a/web/src/app/app/(chat_experience)/chat/[chatId]/metric/[metricId]/page.tsx b/web/src/app/app/(chat_experience)/chats/[chatId]/metric/[metricId]/page.tsx similarity index 100% rename from web/src/app/app/(chat_experience)/chat/[chatId]/metric/[metricId]/page.tsx rename to web/src/app/app/(chat_experience)/chats/[chatId]/metric/[metricId]/page.tsx diff --git a/web/src/app/app/(chat_experience)/chat/[chatId]/page.tsx b/web/src/app/app/(chat_experience)/chats/[chatId]/page.tsx similarity index 100% rename from web/src/app/app/(chat_experience)/chat/[chatId]/page.tsx rename to web/src/app/app/(chat_experience)/chats/[chatId]/page.tsx diff --git a/web/src/app/app/(chat_experience)/chat/[chatId]/reasoning/[messageId]/page.tsx b/web/src/app/app/(chat_experience)/chats/[chatId]/reasoning/[messageId]/page.tsx similarity index 100% rename from web/src/app/app/(chat_experience)/chat/[chatId]/reasoning/[messageId]/page.tsx rename to web/src/app/app/(chat_experience)/chats/[chatId]/reasoning/[messageId]/page.tsx diff --git a/web/src/app/app/_controllers/MetricController/MetricController.tsx b/web/src/app/app/_controllers/MetricController/MetricController.tsx index fe25d4350..3c5a8662a 100644 --- a/web/src/app/app/_controllers/MetricController/MetricController.tsx +++ b/web/src/app/app/_controllers/MetricController/MetricController.tsx @@ -14,7 +14,6 @@ export const MetricController: React.FC<{ }> = React.memo(({ metricId }) => { const { metric, isFetchedMetricData } = useMetricIndividual({ metricId }); const selectedFileView = useChatLayoutContextSelector((x) => x.selectedFileView) || 'chart'; - const isFetchedConfig = metric.fetched; const showLoader = !isFetchedConfig || !isFetchedMetricData; diff --git a/web/src/app/app/_layouts/ChatLayout/ChatContext/useFileFallback.ts b/web/src/app/app/_layouts/ChatLayout/ChatContext/useFileFallback.ts index 910331d00..bc844deea 100644 --- a/web/src/app/app/_layouts/ChatLayout/ChatContext/useFileFallback.ts +++ b/web/src/app/app/_layouts/ChatLayout/ChatContext/useFileFallback.ts @@ -1,6 +1,6 @@ import { SelectedFile } from '@appLayouts/ChatLayout'; import { useBusterDashboardContextSelector } from '@/context/Dashboards'; -import { useMetricIndividual } from '@/context/Metrics'; +import { useBusterMetricsIndividualContextSelector, useMetricIndividual } from '@/context/Metrics'; import { useEffect, useMemo } from 'react'; import { FileType } from '@/api/asset_interfaces'; import { @@ -16,9 +16,14 @@ export const useFileFallback = ({ defaultSelectedFile?: SelectedFile; }) => { const fileId = defaultSelectedFile?.id || ''; + const onUpdateChatMessage = useBusterChatContextSelector((x) => x.onUpdateChatMessage); - const { metricTitle, metricVersionNumber } = useMetricParams(fileId); - const { dashboardTitle, dashboardVersionNumber } = useDashboardParams(fileId); + const { metricTitle, metricVersionNumber } = useMetricParams( + defaultSelectedFile?.type === 'metric' ? fileId : '' + ); + const { dashboardTitle, dashboardVersionNumber } = useDashboardParams( + defaultSelectedFile?.type === 'dashboard' ? fileId : '' + ); const fileType: FileType = useMemo(() => { if (defaultSelectedFile?.type === 'metric') { @@ -133,17 +138,18 @@ const fallbackToFileChatMessage = ({ }; }; -const useMetricParams = (fileId: string) => { - const { metric } = useMetricIndividual({ metricId: fileId }); +const useMetricParams = (metricId: string) => { + const getMetricMemoized = useBusterMetricsIndividualContextSelector((x) => x.getMetricMemoized); + const metric = getMetricMemoized({ metricId }); const metricTitle = metric?.title; const metricVersionNumber = metric?.version_number; return { metricTitle, metricVersionNumber }; }; -const useDashboardParams = (fileId: string) => { +const useDashboardParams = (dashboardId: string) => { const getDashboardMemoized = useBusterDashboardContextSelector((x) => x.getDashboardMemoized); - const dashboard = getDashboardMemoized(fileId); + const dashboard = getDashboardMemoized(dashboardId); const dashboardTitle = dashboard?.dashboard?.name; const dashboardVersionNumber = dashboard?.dashboard?.version_number; diff --git a/web/src/app/app/chats/_ChatsListContainer/ChatItemsContainer.tsx b/web/src/app/app/chats/_ChatsListContainer/ChatItemsContainer.tsx index 9843e664b..250b6a5ff 100644 --- a/web/src/app/app/chats/_ChatsListContainer/ChatItemsContainer.tsx +++ b/web/src/app/app/chats/_ChatsListContainer/ChatItemsContainer.tsx @@ -30,13 +30,13 @@ export const ChatItemsContainer: React.FC<{ const logsRecord = useCreateListByDate({ data: chats }); const chatsByDate: BusterListRow[] = useMemo(() => { - return Object.entries(logsRecord).flatMap(([key, metrics]) => { - const records = metrics.map((metric) => ({ - id: metric.id, - data: metric, + return Object.entries(logsRecord).flatMap(([key, chats]) => { + const records = chats.map((chat) => ({ + id: chat.id, + data: chat, link: createBusterRoute({ - route: BusterRoutes.APP_METRIC_ID, - metricId: metric.id + route: BusterRoutes.APP_CHAT_ID, + chatId: chat.id }) })); const hasRecords = records.length > 0; @@ -63,7 +63,7 @@ export const ChatItemsContainer: React.FC<{ dataIndex: 'title', title: 'Title', render: (title, record) => ( - + ) }, { @@ -105,8 +105,6 @@ export const ChatItemsContainer: React.FC<{ [] ); - console.log(chatsByDate, loading); - return (
( - ({ title, status, metricId }) => { +const TitleCell = React.memo<{ title: string; status: VerificationStatus; chatId: string }>( + ({ title, status, chatId }) => { const onFavoriteDivClick = useMemoizedFn((e: React.MouseEvent) => { e.stopPropagation(); }); @@ -167,7 +165,7 @@ const TitleCell = React.memo<{ title: string; status: VerificationStatus; metric {title}
; export const useCollectionLists = () => { const [collectionListFilters, setCollectionListFilters] = useState({}); + const currentSegment = useAppLayoutContextSelector((x) => x.currentSegment); + const enabled = currentSegment === 'collections'; const payload = useMemo(() => { return { page: 0, page_size: 1000, ...collectionListFilters }; @@ -27,7 +30,8 @@ export const useCollectionLists = () => { payload }, responseEvent: '/collections/list:listCollections', - options: queryKeys.collectionsGetList(payload) + options: queryKeys.collectionsGetList(payload), + enabledTrigger: enabled }); return { diff --git a/web/src/context/Terms/BusterTermsIndividualProvider/useBusterTermsCreate.tsx b/web/src/context/Terms/BusterTermsIndividualProvider/useBusterTermsCreate.tsx index 20b030552..a144255f0 100644 --- a/web/src/context/Terms/BusterTermsIndividualProvider/useBusterTermsCreate.tsx +++ b/web/src/context/Terms/BusterTermsIndividualProvider/useBusterTermsCreate.tsx @@ -27,7 +27,7 @@ export const useBusterTermsCreate = () => { const { mutate: deleteTermMutation } = useSocketQueryMutation({ emitEvent: '/terms/delete', responseEvent: '/terms/delete:DeleteTerm', - options: queryKeys['/terms/list:getTermsList'], + options: queryKeys.termsGetList, preCallback: (currentData, variables) => { return (currentData || []).filter((term) => !variables.ids.includes(term.id)); } diff --git a/web/src/context/Terms/BusterTermsIndividualProvider/useBusterTermsIndividual.tsx b/web/src/context/Terms/BusterTermsIndividualProvider/useBusterTermsIndividual.tsx index 8734714e0..2edf02779 100644 --- a/web/src/context/Terms/BusterTermsIndividualProvider/useBusterTermsIndividual.tsx +++ b/web/src/context/Terms/BusterTermsIndividualProvider/useBusterTermsIndividual.tsx @@ -9,7 +9,7 @@ export const useBusterTermsIndividual = ({ termId }: { termId: string }) => { } = useSocketQueryEmitOn({ emitEvent: { route: '/terms/get', payload: { id: termId } }, responseEvent: '/terms/get:GetTerm', - options: queryKeys['/terms/get:getTerm'](termId), + options: queryKeys.termsGetTerm(termId), enabledTrigger: termId }); diff --git a/web/src/context/Terms/BusterTermsListProvider.tsx b/web/src/context/Terms/BusterTermsListProvider.tsx index d39e42c7e..269b1ad87 100644 --- a/web/src/context/Terms/BusterTermsListProvider.tsx +++ b/web/src/context/Terms/BusterTermsListProvider.tsx @@ -6,8 +6,11 @@ import { useContextSelector, ContextSelector } from '@fluentui/react-context-selector'; +import { useAppLayoutContextSelector } from '../BusterAppLayout'; export const useBusterTermsList = () => { + const currentSegment = useAppLayoutContextSelector((x) => x.currentSegment); + const enabled = currentSegment === 'terms'; const { data: termsList, refetch: refetchTermsList, @@ -15,7 +18,8 @@ export const useBusterTermsList = () => { } = useSocketQueryEmitOn({ emitEvent: { route: '/terms/list', payload: { page: 0, page_size: 3000 } }, responseEvent: '/terms/list:ListTerms', - options: queryKeys['/terms/list:getTermsList'] + options: queryKeys.termsGetList, + enabledTrigger: enabled }); return { diff --git a/web/temp.md b/web/temp.md index 6f0e32942..678af4834 100644 --- a/web/temp.md +++ b/web/temp.md @@ -66,7 +66,7 @@ This example demonstrates: ```typescript // Example of required response routes enum export enum ChatsResponses { - '/chats/list:getChatsList' = '/chats/list:getChatsList', + '/chats/list:getThreadsList' = '/chats/list:getThreadsList', '/chats/unsubscribe:unsubscribe' = '/chats/unsubscribe:unsubscribe', '/chats/get:getChat' = '/chats/get:getChat', '/chats/post:initializeChat' = '/chats/post:initializeChat', @@ -79,7 +79,7 @@ export enum ChatsResponses { */ export type ChatList_getChatsList = { /** The route identifier for getting the chats list */ - route: '/chats/list:getChatsList'; + route: '/chats/list:getThreadsList'; /** Callback function that receives the chat list data */ callback: (chats: ChatListItem[]) => void; /** Optional error handler for when the request fails */